]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.11.1-201309151124.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.11.1-201309151124.patch
CommitLineData
85da0c18
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b89a739..79768fb 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,19 +101,24 @@ 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@@ -115,9 +129,11 @@ devlist.h*
90 dnotify_test
91 docproc
92 dslm
93+dtc-lexer.lex.c
94 elf2ecoff
95 elfconfig.h*
96 evergreen_reg_safe.h
97+exception_policy.conf
98 fixdep
99 flask.h
100 fore200e_mkfirm
101@@ -125,12 +141,15 @@ fore200e_pca_fw.c*
102 gconf
103 gconf.glade.h
104 gen-devlist
105+gen-kdb_cmds.c
106 gen_crc32table
107 gen_init_cpio
108 generated
109 genheaders
110 genksyms
111 *_gray256.c
112+hash
113+hid-example
114 hpet_example
115 hugepage-mmap
116 hugepage-shm
117@@ -145,14 +164,14 @@ int32.c
118 int4.c
119 int8.c
120 kallsyms
121-kconfig
122+kern_constants.h
123 keywords.c
124 ksym.c*
125 ksym.h*
126 kxgettext
127 lex.c
128 lex.*.c
129-linux
130+lib1funcs.S
131 logo_*.c
132 logo_*_clut224.c
133 logo_*_mono.c
134@@ -162,14 +181,15 @@ mach-types.h
135 machtypes.h
136 map
137 map_hugetlb
138-media
139 mconf
140+mdp
141 miboot*
142 mk_elfconfig
143 mkboot
144 mkbugboot
145 mkcpustr
146 mkdep
147+mkpiggy
148 mkprep
149 mkregtable
150 mktables
151@@ -185,6 +205,8 @@ oui.c*
152 page-types
153 parse.c
154 parse.h
155+parse-events*
156+pasyms.h
157 patches*
158 pca200e.bin
159 pca200e_ecd.bin2
160@@ -194,6 +216,7 @@ perf-archive
161 piggyback
162 piggy.gzip
163 piggy.S
164+pmu-*
165 pnmtologo
166 ppc_defs.h*
167 pss_boot.h
168@@ -203,7 +226,10 @@ r200_reg_safe.h
169 r300_reg_safe.h
170 r420_reg_safe.h
171 r600_reg_safe.h
172+realmode.lds
173+realmode.relocs
174 recordmcount
175+regdb.c
176 relocs
177 rlim_names.h
178 rn50_reg_safe.h
179@@ -213,8 +239,12 @@ series
180 setup
181 setup.bin
182 setup.elf
183+signing_key*
184+size_overflow_hash.h
185 sImage
186+slabinfo
187 sm_tbl*
188+sortextable
189 split-include
190 syscalltab.h
191 tables.c
192@@ -224,6 +254,7 @@ tftpboot.img
193 timeconst.h
194 times.h*
195 trix_boot.h
196+user_constants.h
197 utsrelease.h*
198 vdso-syms.lds
199 vdso.lds
200@@ -235,13 +266,17 @@ vdso32.lds
201 vdso32.so.dbg
202 vdso64.lds
203 vdso64.so.dbg
204+vdsox32.lds
205+vdsox32-syms.lds
206 version.h*
207 vmImage
208 vmlinux
209 vmlinux-*
210 vmlinux.aout
211 vmlinux.bin.all
212+vmlinux.bin.bz2
213 vmlinux.lds
214+vmlinux.relocs
215 vmlinuz
216 voffset.h
217 vsyscall.lds
218@@ -249,9 +284,12 @@ vsyscall_32.lds
219 wanxlfw.inc
220 uImage
221 unifdef
222+utsrelease.h
223 wakeup.bin
224 wakeup.elf
225 wakeup.lds
226+x509*
227 zImage*
228 zconf.hash.c
229+zconf.lex.c
230 zoffset.h
231diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
232index 7f9d4f5..6d1afd6 100644
233--- a/Documentation/kernel-parameters.txt
234+++ b/Documentation/kernel-parameters.txt
235@@ -976,6 +976,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
236 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
237 Default: 1024
238
239+ grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
240+ ignore grsecurity's /proc restrictions
241+
242+
243 hashdist= [KNL,NUMA] Large hashes allocated during boot
244 are distributed across NUMA nodes. Defaults on
245 for 64-bit NUMA, off otherwise.
246@@ -1932,6 +1936,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
247 noexec=on: enable non-executable mappings (default)
248 noexec=off: disable non-executable mappings
249
250+ nopcid [X86-64]
251+ Disable PCID (Process-Context IDentifier) even if it
252+ is supported by the processor.
253+
254 nosmap [X86]
255 Disable SMAP (Supervisor Mode Access Prevention)
256 even if it is supported by processor.
257@@ -2199,6 +2207,25 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
258 the specified number of seconds. This is to be used if
259 your oopses keep scrolling off the screen.
260
261+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
262+ virtualization environments that don't cope well with the
263+ expand down segment used by UDEREF on X86-32 or the frequent
264+ page table updates on X86-64.
265+
266+ pax_sanitize_slab=
267+ 0/1 to disable/enable slab object sanitization (enabled by
268+ default).
269+
270+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
271+
272+ pax_extra_latent_entropy
273+ Enable a very simple form of latent entropy extraction
274+ from the first 4GB of memory as the bootmem allocator
275+ passes the memory pages to the buddy allocator.
276+
277+ pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
278+ when the processor supports PCID.
279+
280 pcbit= [HW,ISDN]
281
282 pcd. [PARIDE]
283diff --git a/Makefile b/Makefile
284index efd2396..682975d 100644
285--- a/Makefile
286+++ b/Makefile
287@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
288
289 HOSTCC = gcc
290 HOSTCXX = g++
291-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
292-HOSTCXXFLAGS = -O2
293+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
294+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
295+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
296
297 # Decide whether to build built-in, modular, or both.
298 # Normally, just do built-in.
299@@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
300 # Rules shared between *config targets and build targets
301
302 # Basic helpers built in scripts/
303-PHONY += scripts_basic
304-scripts_basic:
305+PHONY += scripts_basic gcc-plugins
306+scripts_basic: gcc-plugins
307 $(Q)$(MAKE) $(build)=scripts/basic
308 $(Q)rm -f .tmp_quiet_recordmcount
309
310@@ -576,6 +577,65 @@ else
311 KBUILD_CFLAGS += -O2
312 endif
313
314+ifndef DISABLE_PAX_PLUGINS
315+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
316+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
317+else
318+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
319+endif
320+ifneq ($(PLUGINCC),)
321+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
322+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
323+endif
324+ifdef CONFIG_PAX_MEMORY_STACKLEAK
325+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
326+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
327+endif
328+ifdef CONFIG_KALLOCSTAT_PLUGIN
329+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
330+endif
331+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
332+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
333+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
334+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
335+endif
336+ifdef CONFIG_CHECKER_PLUGIN
337+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
338+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
339+endif
340+endif
341+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
342+ifdef CONFIG_PAX_SIZE_OVERFLOW
343+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
344+endif
345+ifdef CONFIG_PAX_LATENT_ENTROPY
346+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
347+endif
348+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
349+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
350+endif
351+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
352+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
353+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
354+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
355+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
356+ifeq ($(KBUILD_EXTMOD),)
357+gcc-plugins:
358+ $(Q)$(MAKE) $(build)=tools/gcc
359+else
360+gcc-plugins: ;
361+endif
362+else
363+gcc-plugins:
364+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
365+ $(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.))
366+else
367+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
368+endif
369+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
370+endif
371+endif
372+
373 include $(srctree)/arch/$(SRCARCH)/Makefile
374
375 ifdef CONFIG_READABLE_ASM
376@@ -733,7 +793,7 @@ export mod_sign_cmd
377
378
379 ifeq ($(KBUILD_EXTMOD),)
380-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
381+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
382
383 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
384 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
385@@ -782,6 +842,8 @@ endif
386
387 # The actual objects are generated when descending,
388 # make sure no implicit rule kicks in
389+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
390+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
391 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
392
393 # Handle descending into subdirectories listed in $(vmlinux-dirs)
394@@ -791,7 +853,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
395 # Error messages still appears in the original language
396
397 PHONY += $(vmlinux-dirs)
398-$(vmlinux-dirs): prepare scripts
399+$(vmlinux-dirs): gcc-plugins prepare scripts
400 $(Q)$(MAKE) $(build)=$@
401
402 # Store (new) KERNELRELEASE string in include/config/kernel.release
403@@ -835,6 +897,7 @@ prepare0: archprepare FORCE
404 $(Q)$(MAKE) $(build)=.
405
406 # All the preparing..
407+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
408 prepare: prepare0
409
410 # Generate some files
411@@ -942,6 +1005,8 @@ all: modules
412 # using awk while concatenating to the final file.
413
414 PHONY += modules
415+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
416+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
417 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
418 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
419 @$(kecho) ' Building modules, stage 2.';
420@@ -957,7 +1022,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
421
422 # Target to prepare building external modules
423 PHONY += modules_prepare
424-modules_prepare: prepare scripts
425+modules_prepare: gcc-plugins prepare scripts
426
427 # Target to install modules
428 PHONY += modules_install
429@@ -1023,7 +1088,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
430 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
431 signing_key.priv signing_key.x509 x509.genkey \
432 extra_certificates signing_key.x509.keyid \
433- signing_key.x509.signer
434+ signing_key.x509.signer tools/gcc/size_overflow_hash.h
435
436 # clean - Delete most, but leave enough to build external modules
437 #
438@@ -1063,6 +1128,7 @@ distclean: mrproper
439 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
440 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
441 -o -name '.*.rej' \
442+ -o -name '.*.rej' -o -name '*.so' \
443 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
444 -type f -print | xargs rm -f
445
446@@ -1224,6 +1290,8 @@ PHONY += $(module-dirs) modules
447 $(module-dirs): crmodverdir $(objtree)/Module.symvers
448 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
449
450+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
451+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
452 modules: $(module-dirs)
453 @$(kecho) ' Building modules, stage 2.';
454 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
455@@ -1363,17 +1431,21 @@ else
456 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
457 endif
458
459-%.s: %.c prepare scripts FORCE
460+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
461+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
462+%.s: %.c gcc-plugins prepare scripts FORCE
463 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
464 %.i: %.c prepare scripts FORCE
465 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
466-%.o: %.c prepare scripts FORCE
467+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
468+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
469+%.o: %.c gcc-plugins prepare scripts FORCE
470 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
471 %.lst: %.c prepare scripts FORCE
472 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
473-%.s: %.S prepare scripts FORCE
474+%.s: %.S gcc-plugins prepare scripts FORCE
475 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
476-%.o: %.S prepare scripts FORCE
477+%.o: %.S gcc-plugins prepare scripts FORCE
478 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
479 %.symtypes: %.c prepare scripts FORCE
480 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
481@@ -1383,11 +1455,15 @@ endif
482 $(cmd_crmodverdir)
483 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
484 $(build)=$(build-dir)
485-%/: prepare scripts FORCE
486+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
487+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
488+%/: gcc-plugins prepare scripts FORCE
489 $(cmd_crmodverdir)
490 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
491 $(build)=$(build-dir)
492-%.ko: prepare scripts FORCE
493+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
494+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
495+%.ko: gcc-plugins prepare scripts FORCE
496 $(cmd_crmodverdir)
497 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
498 $(build)=$(build-dir) $(@:.ko=.o)
499diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
500index 78b03ef..da28a51 100644
501--- a/arch/alpha/include/asm/atomic.h
502+++ b/arch/alpha/include/asm/atomic.h
503@@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
504 #define atomic_dec(v) atomic_sub(1,(v))
505 #define atomic64_dec(v) atomic64_sub(1,(v))
506
507+#define atomic64_read_unchecked(v) atomic64_read(v)
508+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
509+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
510+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
511+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
512+#define atomic64_inc_unchecked(v) atomic64_inc(v)
513+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
514+#define atomic64_dec_unchecked(v) atomic64_dec(v)
515+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
516+
517 #define smp_mb__before_atomic_dec() smp_mb()
518 #define smp_mb__after_atomic_dec() smp_mb()
519 #define smp_mb__before_atomic_inc() smp_mb()
520diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
521index ad368a9..fbe0f25 100644
522--- a/arch/alpha/include/asm/cache.h
523+++ b/arch/alpha/include/asm/cache.h
524@@ -4,19 +4,19 @@
525 #ifndef __ARCH_ALPHA_CACHE_H
526 #define __ARCH_ALPHA_CACHE_H
527
528+#include <linux/const.h>
529
530 /* Bytes per L1 (data) cache line. */
531 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
532-# define L1_CACHE_BYTES 64
533 # define L1_CACHE_SHIFT 6
534 #else
535 /* Both EV4 and EV5 are write-through, read-allocate,
536 direct-mapped, physical.
537 */
538-# define L1_CACHE_BYTES 32
539 # define L1_CACHE_SHIFT 5
540 #endif
541
542+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
543 #define SMP_CACHE_BYTES L1_CACHE_BYTES
544
545 #endif
546diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
547index 968d999..d36b2df 100644
548--- a/arch/alpha/include/asm/elf.h
549+++ b/arch/alpha/include/asm/elf.h
550@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
551
552 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
553
554+#ifdef CONFIG_PAX_ASLR
555+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
556+
557+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
558+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
559+#endif
560+
561 /* $0 is set by ld.so to a pointer to a function which might be
562 registered using atexit. This provides a mean for the dynamic
563 linker to call DT_FINI functions for shared libraries that have
564diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
565index bc2a0da..8ad11ee 100644
566--- a/arch/alpha/include/asm/pgalloc.h
567+++ b/arch/alpha/include/asm/pgalloc.h
568@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
569 pgd_set(pgd, pmd);
570 }
571
572+static inline void
573+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
574+{
575+ pgd_populate(mm, pgd, pmd);
576+}
577+
578 extern pgd_t *pgd_alloc(struct mm_struct *mm);
579
580 static inline void
581diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
582index d8f9b7e..f6222fa 100644
583--- a/arch/alpha/include/asm/pgtable.h
584+++ b/arch/alpha/include/asm/pgtable.h
585@@ -102,6 +102,17 @@ struct vm_area_struct;
586 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
587 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
588 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
589+
590+#ifdef CONFIG_PAX_PAGEEXEC
591+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
592+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
593+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
594+#else
595+# define PAGE_SHARED_NOEXEC PAGE_SHARED
596+# define PAGE_COPY_NOEXEC PAGE_COPY
597+# define PAGE_READONLY_NOEXEC PAGE_READONLY
598+#endif
599+
600 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
601
602 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
603diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
604index 2fd00b7..cfd5069 100644
605--- a/arch/alpha/kernel/module.c
606+++ b/arch/alpha/kernel/module.c
607@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
608
609 /* The small sections were sorted to the end of the segment.
610 The following should definitely cover them. */
611- gp = (u64)me->module_core + me->core_size - 0x8000;
612+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
613 got = sechdrs[me->arch.gotsecindex].sh_addr;
614
615 for (i = 0; i < n; i++) {
616diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
617index 1402fcc..0b1abd2 100644
618--- a/arch/alpha/kernel/osf_sys.c
619+++ b/arch/alpha/kernel/osf_sys.c
620@@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
621 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
622
623 static unsigned long
624-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
625- unsigned long limit)
626+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
627+ unsigned long limit, unsigned long flags)
628 {
629 struct vm_unmapped_area_info info;
630+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
631
632 info.flags = 0;
633 info.length = len;
634@@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
635 info.high_limit = limit;
636 info.align_mask = 0;
637 info.align_offset = 0;
638+ info.threadstack_offset = offset;
639 return vm_unmapped_area(&info);
640 }
641
642@@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
643 merely specific addresses, but regions of memory -- perhaps
644 this feature should be incorporated into all ports? */
645
646+#ifdef CONFIG_PAX_RANDMMAP
647+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
648+#endif
649+
650 if (addr) {
651- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
652+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
653 if (addr != (unsigned long) -ENOMEM)
654 return addr;
655 }
656
657 /* Next, try allocating at TASK_UNMAPPED_BASE. */
658- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
659- len, limit);
660+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
661+
662 if (addr != (unsigned long) -ENOMEM)
663 return addr;
664
665 /* Finally, try allocating in low memory. */
666- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
667+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
668
669 return addr;
670 }
671diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
672index 0c4132d..88f0d53 100644
673--- a/arch/alpha/mm/fault.c
674+++ b/arch/alpha/mm/fault.c
675@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
676 __reload_thread(pcb);
677 }
678
679+#ifdef CONFIG_PAX_PAGEEXEC
680+/*
681+ * PaX: decide what to do with offenders (regs->pc = fault address)
682+ *
683+ * returns 1 when task should be killed
684+ * 2 when patched PLT trampoline was detected
685+ * 3 when unpatched PLT trampoline was detected
686+ */
687+static int pax_handle_fetch_fault(struct pt_regs *regs)
688+{
689+
690+#ifdef CONFIG_PAX_EMUPLT
691+ int err;
692+
693+ do { /* PaX: patched PLT emulation #1 */
694+ unsigned int ldah, ldq, jmp;
695+
696+ err = get_user(ldah, (unsigned int *)regs->pc);
697+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
698+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
699+
700+ if (err)
701+ break;
702+
703+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
704+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
705+ jmp == 0x6BFB0000U)
706+ {
707+ unsigned long r27, addr;
708+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
709+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
710+
711+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
712+ err = get_user(r27, (unsigned long *)addr);
713+ if (err)
714+ break;
715+
716+ regs->r27 = r27;
717+ regs->pc = r27;
718+ return 2;
719+ }
720+ } while (0);
721+
722+ do { /* PaX: patched PLT emulation #2 */
723+ unsigned int ldah, lda, br;
724+
725+ err = get_user(ldah, (unsigned int *)regs->pc);
726+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
727+ err |= get_user(br, (unsigned int *)(regs->pc+8));
728+
729+ if (err)
730+ break;
731+
732+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
733+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
734+ (br & 0xFFE00000U) == 0xC3E00000U)
735+ {
736+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
737+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
738+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
739+
740+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
741+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
742+ return 2;
743+ }
744+ } while (0);
745+
746+ do { /* PaX: unpatched PLT emulation */
747+ unsigned int br;
748+
749+ err = get_user(br, (unsigned int *)regs->pc);
750+
751+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
752+ unsigned int br2, ldq, nop, jmp;
753+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
754+
755+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
756+ err = get_user(br2, (unsigned int *)addr);
757+ err |= get_user(ldq, (unsigned int *)(addr+4));
758+ err |= get_user(nop, (unsigned int *)(addr+8));
759+ err |= get_user(jmp, (unsigned int *)(addr+12));
760+ err |= get_user(resolver, (unsigned long *)(addr+16));
761+
762+ if (err)
763+ break;
764+
765+ if (br2 == 0xC3600000U &&
766+ ldq == 0xA77B000CU &&
767+ nop == 0x47FF041FU &&
768+ jmp == 0x6B7B0000U)
769+ {
770+ regs->r28 = regs->pc+4;
771+ regs->r27 = addr+16;
772+ regs->pc = resolver;
773+ return 3;
774+ }
775+ }
776+ } while (0);
777+#endif
778+
779+ return 1;
780+}
781+
782+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
783+{
784+ unsigned long i;
785+
786+ printk(KERN_ERR "PAX: bytes at PC: ");
787+ for (i = 0; i < 5; i++) {
788+ unsigned int c;
789+ if (get_user(c, (unsigned int *)pc+i))
790+ printk(KERN_CONT "???????? ");
791+ else
792+ printk(KERN_CONT "%08x ", c);
793+ }
794+ printk("\n");
795+}
796+#endif
797
798 /*
799 * This routine handles page faults. It determines the address,
800@@ -133,8 +251,29 @@ retry:
801 good_area:
802 si_code = SEGV_ACCERR;
803 if (cause < 0) {
804- if (!(vma->vm_flags & VM_EXEC))
805+ if (!(vma->vm_flags & VM_EXEC)) {
806+
807+#ifdef CONFIG_PAX_PAGEEXEC
808+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
809+ goto bad_area;
810+
811+ up_read(&mm->mmap_sem);
812+ switch (pax_handle_fetch_fault(regs)) {
813+
814+#ifdef CONFIG_PAX_EMUPLT
815+ case 2:
816+ case 3:
817+ return;
818+#endif
819+
820+ }
821+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
822+ do_group_exit(SIGKILL);
823+#else
824 goto bad_area;
825+#endif
826+
827+ }
828 } else if (!cause) {
829 /* Allow reads even for write-only mappings */
830 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
831diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
832index 43594d5..da71e62 100644
833--- a/arch/arm/Kconfig
834+++ b/arch/arm/Kconfig
835@@ -1791,7 +1791,7 @@ config ALIGNMENT_TRAP
836
837 config UACCESS_WITH_MEMCPY
838 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
839- depends on MMU
840+ depends on MMU && !PAX_MEMORY_UDEREF
841 default y if CPU_FEROCEON
842 help
843 Implement faster copy_to_user and clear_user methods for CPU
844diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
845index da1c77d..2ee6056 100644
846--- a/arch/arm/include/asm/atomic.h
847+++ b/arch/arm/include/asm/atomic.h
848@@ -17,17 +17,35 @@
849 #include <asm/barrier.h>
850 #include <asm/cmpxchg.h>
851
852+#ifdef CONFIG_GENERIC_ATOMIC64
853+#include <asm-generic/atomic64.h>
854+#endif
855+
856 #define ATOMIC_INIT(i) { (i) }
857
858 #ifdef __KERNEL__
859
860+#define _ASM_EXTABLE(from, to) \
861+" .pushsection __ex_table,\"a\"\n"\
862+" .align 3\n" \
863+" .long " #from ", " #to"\n" \
864+" .popsection"
865+
866 /*
867 * On ARM, ordinary assignment (str instruction) doesn't clear the local
868 * strex/ldrex monitor on some implementations. The reason we can use it for
869 * atomic_set() is the clrex or dummy strex done on every exception return.
870 */
871 #define atomic_read(v) (*(volatile int *)&(v)->counter)
872+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
873+{
874+ return v->counter;
875+}
876 #define atomic_set(v,i) (((v)->counter) = (i))
877+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
878+{
879+ v->counter = i;
880+}
881
882 #if __LINUX_ARM_ARCH__ >= 6
883
884@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
885 int result;
886
887 __asm__ __volatile__("@ atomic_add\n"
888+"1: ldrex %1, [%3]\n"
889+" adds %0, %1, %4\n"
890+
891+#ifdef CONFIG_PAX_REFCOUNT
892+" bvc 3f\n"
893+"2: bkpt 0xf103\n"
894+"3:\n"
895+#endif
896+
897+" strex %1, %0, [%3]\n"
898+" teq %1, #0\n"
899+" bne 1b"
900+
901+#ifdef CONFIG_PAX_REFCOUNT
902+"\n4:\n"
903+ _ASM_EXTABLE(2b, 4b)
904+#endif
905+
906+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
907+ : "r" (&v->counter), "Ir" (i)
908+ : "cc");
909+}
910+
911+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
912+{
913+ unsigned long tmp;
914+ int result;
915+
916+ __asm__ __volatile__("@ atomic_add_unchecked\n"
917 "1: ldrex %0, [%3]\n"
918 " add %0, %0, %4\n"
919 " strex %1, %0, [%3]\n"
920@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
921 smp_mb();
922
923 __asm__ __volatile__("@ atomic_add_return\n"
924+"1: ldrex %1, [%3]\n"
925+" adds %0, %1, %4\n"
926+
927+#ifdef CONFIG_PAX_REFCOUNT
928+" bvc 3f\n"
929+" mov %0, %1\n"
930+"2: bkpt 0xf103\n"
931+"3:\n"
932+#endif
933+
934+" strex %1, %0, [%3]\n"
935+" teq %1, #0\n"
936+" bne 1b"
937+
938+#ifdef CONFIG_PAX_REFCOUNT
939+"\n4:\n"
940+ _ASM_EXTABLE(2b, 4b)
941+#endif
942+
943+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
944+ : "r" (&v->counter), "Ir" (i)
945+ : "cc");
946+
947+ smp_mb();
948+
949+ return result;
950+}
951+
952+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
953+{
954+ unsigned long tmp;
955+ int result;
956+
957+ smp_mb();
958+
959+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
960 "1: ldrex %0, [%3]\n"
961 " add %0, %0, %4\n"
962 " strex %1, %0, [%3]\n"
963@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
964 int result;
965
966 __asm__ __volatile__("@ atomic_sub\n"
967+"1: ldrex %1, [%3]\n"
968+" subs %0, %1, %4\n"
969+
970+#ifdef CONFIG_PAX_REFCOUNT
971+" bvc 3f\n"
972+"2: bkpt 0xf103\n"
973+"3:\n"
974+#endif
975+
976+" strex %1, %0, [%3]\n"
977+" teq %1, #0\n"
978+" bne 1b"
979+
980+#ifdef CONFIG_PAX_REFCOUNT
981+"\n4:\n"
982+ _ASM_EXTABLE(2b, 4b)
983+#endif
984+
985+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
986+ : "r" (&v->counter), "Ir" (i)
987+ : "cc");
988+}
989+
990+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
991+{
992+ unsigned long tmp;
993+ int result;
994+
995+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
996 "1: ldrex %0, [%3]\n"
997 " sub %0, %0, %4\n"
998 " strex %1, %0, [%3]\n"
999@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1000 smp_mb();
1001
1002 __asm__ __volatile__("@ atomic_sub_return\n"
1003-"1: ldrex %0, [%3]\n"
1004-" sub %0, %0, %4\n"
1005+"1: ldrex %1, [%3]\n"
1006+" subs %0, %1, %4\n"
1007+
1008+#ifdef CONFIG_PAX_REFCOUNT
1009+" bvc 3f\n"
1010+" mov %0, %1\n"
1011+"2: bkpt 0xf103\n"
1012+"3:\n"
1013+#endif
1014+
1015 " strex %1, %0, [%3]\n"
1016 " teq %1, #0\n"
1017 " bne 1b"
1018+
1019+#ifdef CONFIG_PAX_REFCOUNT
1020+"\n4:\n"
1021+ _ASM_EXTABLE(2b, 4b)
1022+#endif
1023+
1024 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1025 : "r" (&v->counter), "Ir" (i)
1026 : "cc");
1027@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1028 return oldval;
1029 }
1030
1031+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1032+{
1033+ unsigned long oldval, res;
1034+
1035+ smp_mb();
1036+
1037+ do {
1038+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1039+ "ldrex %1, [%3]\n"
1040+ "mov %0, #0\n"
1041+ "teq %1, %4\n"
1042+ "strexeq %0, %5, [%3]\n"
1043+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1044+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1045+ : "cc");
1046+ } while (res);
1047+
1048+ smp_mb();
1049+
1050+ return oldval;
1051+}
1052+
1053 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1054 {
1055 unsigned long tmp, tmp2;
1056@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1057
1058 return val;
1059 }
1060+
1061+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1062+{
1063+ return atomic_add_return(i, v);
1064+}
1065+
1066 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1067+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1068+{
1069+ (void) atomic_add_return(i, v);
1070+}
1071
1072 static inline int atomic_sub_return(int i, atomic_t *v)
1073 {
1074@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1075 return val;
1076 }
1077 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1078+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1079+{
1080+ (void) atomic_sub_return(i, v);
1081+}
1082
1083 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1084 {
1085@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1086 return ret;
1087 }
1088
1089+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1090+{
1091+ return atomic_cmpxchg(v, old, new);
1092+}
1093+
1094 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1095 {
1096 unsigned long flags;
1097@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1098 #endif /* __LINUX_ARM_ARCH__ */
1099
1100 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1101+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1102+{
1103+ return xchg(&v->counter, new);
1104+}
1105
1106 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1107 {
1108@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1109 }
1110
1111 #define atomic_inc(v) atomic_add(1, v)
1112+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1113+{
1114+ atomic_add_unchecked(1, v);
1115+}
1116 #define atomic_dec(v) atomic_sub(1, v)
1117+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1118+{
1119+ atomic_sub_unchecked(1, v);
1120+}
1121
1122 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1123+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1124+{
1125+ return atomic_add_return_unchecked(1, v) == 0;
1126+}
1127 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1128 #define atomic_inc_return(v) (atomic_add_return(1, v))
1129+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1130+{
1131+ return atomic_add_return_unchecked(1, v);
1132+}
1133 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1134 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1135
1136@@ -241,6 +428,14 @@ typedef struct {
1137 u64 __aligned(8) counter;
1138 } atomic64_t;
1139
1140+#ifdef CONFIG_PAX_REFCOUNT
1141+typedef struct {
1142+ u64 __aligned(8) counter;
1143+} atomic64_unchecked_t;
1144+#else
1145+typedef atomic64_t atomic64_unchecked_t;
1146+#endif
1147+
1148 #define ATOMIC64_INIT(i) { (i) }
1149
1150 #ifdef CONFIG_ARM_LPAE
1151@@ -257,6 +452,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1152 return result;
1153 }
1154
1155+static inline u64 atomic64_read_unchecked(const atomic64_unchecked_t *v)
1156+{
1157+ u64 result;
1158+
1159+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1160+" ldrd %0, %H0, [%1]"
1161+ : "=&r" (result)
1162+ : "r" (&v->counter), "Qo" (v->counter)
1163+ );
1164+
1165+ return result;
1166+}
1167+
1168 static inline void atomic64_set(atomic64_t *v, u64 i)
1169 {
1170 __asm__ __volatile__("@ atomic64_set\n"
1171@@ -265,6 +473,15 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1172 : "r" (&v->counter), "r" (i)
1173 );
1174 }
1175+
1176+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1177+{
1178+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1179+" strd %2, %H2, [%1]"
1180+ : "=Qo" (v->counter)
1181+ : "r" (&v->counter), "r" (i)
1182+ );
1183+}
1184 #else
1185 static inline u64 atomic64_read(const atomic64_t *v)
1186 {
1187@@ -279,6 +496,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1188 return result;
1189 }
1190
1191+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1192+{
1193+ u64 result;
1194+
1195+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1196+" ldrexd %0, %H0, [%1]"
1197+ : "=&r" (result)
1198+ : "r" (&v->counter), "Qo" (v->counter)
1199+ );
1200+
1201+ return result;
1202+}
1203+
1204 static inline void atomic64_set(atomic64_t *v, u64 i)
1205 {
1206 u64 tmp;
1207@@ -292,6 +522,21 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1208 : "r" (&v->counter), "r" (i)
1209 : "cc");
1210 }
1211+
1212+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1213+{
1214+ u64 tmp;
1215+
1216+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1217+"1: ldrexd %0, %H0, [%2]\n"
1218+" strexd %0, %3, %H3, [%2]\n"
1219+" teq %0, #0\n"
1220+" bne 1b"
1221+ : "=&r" (tmp), "=Qo" (v->counter)
1222+ : "r" (&v->counter), "r" (i)
1223+ : "cc");
1224+}
1225+
1226 #endif
1227
1228 static inline void atomic64_add(u64 i, atomic64_t *v)
1229@@ -302,6 +547,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1230 __asm__ __volatile__("@ atomic64_add\n"
1231 "1: ldrexd %0, %H0, [%3]\n"
1232 " adds %0, %0, %4\n"
1233+" adcs %H0, %H0, %H4\n"
1234+
1235+#ifdef CONFIG_PAX_REFCOUNT
1236+" bvc 3f\n"
1237+"2: bkpt 0xf103\n"
1238+"3:\n"
1239+#endif
1240+
1241+" strexd %1, %0, %H0, [%3]\n"
1242+" teq %1, #0\n"
1243+" bne 1b"
1244+
1245+#ifdef CONFIG_PAX_REFCOUNT
1246+"\n4:\n"
1247+ _ASM_EXTABLE(2b, 4b)
1248+#endif
1249+
1250+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1251+ : "r" (&v->counter), "r" (i)
1252+ : "cc");
1253+}
1254+
1255+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1256+{
1257+ u64 result;
1258+ unsigned long tmp;
1259+
1260+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1261+"1: ldrexd %0, %H0, [%3]\n"
1262+" adds %0, %0, %4\n"
1263 " adc %H0, %H0, %H4\n"
1264 " strexd %1, %0, %H0, [%3]\n"
1265 " teq %1, #0\n"
1266@@ -313,12 +588,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1267
1268 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1269 {
1270- u64 result;
1271- unsigned long tmp;
1272+ u64 result, tmp;
1273
1274 smp_mb();
1275
1276 __asm__ __volatile__("@ atomic64_add_return\n"
1277+"1: ldrexd %1, %H1, [%3]\n"
1278+" adds %0, %1, %4\n"
1279+" adcs %H0, %H1, %H4\n"
1280+
1281+#ifdef CONFIG_PAX_REFCOUNT
1282+" bvc 3f\n"
1283+" mov %0, %1\n"
1284+" mov %H0, %H1\n"
1285+"2: bkpt 0xf103\n"
1286+"3:\n"
1287+#endif
1288+
1289+" strexd %1, %0, %H0, [%3]\n"
1290+" teq %1, #0\n"
1291+" bne 1b"
1292+
1293+#ifdef CONFIG_PAX_REFCOUNT
1294+"\n4:\n"
1295+ _ASM_EXTABLE(2b, 4b)
1296+#endif
1297+
1298+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1299+ : "r" (&v->counter), "r" (i)
1300+ : "cc");
1301+
1302+ smp_mb();
1303+
1304+ return result;
1305+}
1306+
1307+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1308+{
1309+ u64 result;
1310+ unsigned long tmp;
1311+
1312+ smp_mb();
1313+
1314+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1315 "1: ldrexd %0, %H0, [%3]\n"
1316 " adds %0, %0, %4\n"
1317 " adc %H0, %H0, %H4\n"
1318@@ -342,6 +654,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1319 __asm__ __volatile__("@ atomic64_sub\n"
1320 "1: ldrexd %0, %H0, [%3]\n"
1321 " subs %0, %0, %4\n"
1322+" sbcs %H0, %H0, %H4\n"
1323+
1324+#ifdef CONFIG_PAX_REFCOUNT
1325+" bvc 3f\n"
1326+"2: bkpt 0xf103\n"
1327+"3:\n"
1328+#endif
1329+
1330+" strexd %1, %0, %H0, [%3]\n"
1331+" teq %1, #0\n"
1332+" bne 1b"
1333+
1334+#ifdef CONFIG_PAX_REFCOUNT
1335+"\n4:\n"
1336+ _ASM_EXTABLE(2b, 4b)
1337+#endif
1338+
1339+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1340+ : "r" (&v->counter), "r" (i)
1341+ : "cc");
1342+}
1343+
1344+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1345+{
1346+ u64 result;
1347+ unsigned long tmp;
1348+
1349+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1350+"1: ldrexd %0, %H0, [%3]\n"
1351+" subs %0, %0, %4\n"
1352 " sbc %H0, %H0, %H4\n"
1353 " strexd %1, %0, %H0, [%3]\n"
1354 " teq %1, #0\n"
1355@@ -353,18 +695,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1356
1357 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1358 {
1359- u64 result;
1360- unsigned long tmp;
1361+ u64 result, tmp;
1362
1363 smp_mb();
1364
1365 __asm__ __volatile__("@ atomic64_sub_return\n"
1366-"1: ldrexd %0, %H0, [%3]\n"
1367-" subs %0, %0, %4\n"
1368-" sbc %H0, %H0, %H4\n"
1369+"1: ldrexd %1, %H1, [%3]\n"
1370+" subs %0, %1, %4\n"
1371+" sbcs %H0, %H1, %H4\n"
1372+
1373+#ifdef CONFIG_PAX_REFCOUNT
1374+" bvc 3f\n"
1375+" mov %0, %1\n"
1376+" mov %H0, %H1\n"
1377+"2: bkpt 0xf103\n"
1378+"3:\n"
1379+#endif
1380+
1381 " strexd %1, %0, %H0, [%3]\n"
1382 " teq %1, #0\n"
1383 " bne 1b"
1384+
1385+#ifdef CONFIG_PAX_REFCOUNT
1386+"\n4:\n"
1387+ _ASM_EXTABLE(2b, 4b)
1388+#endif
1389+
1390 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1391 : "r" (&v->counter), "r" (i)
1392 : "cc");
1393@@ -398,6 +754,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1394 return oldval;
1395 }
1396
1397+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1398+{
1399+ u64 oldval;
1400+ unsigned long res;
1401+
1402+ smp_mb();
1403+
1404+ do {
1405+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1406+ "ldrexd %1, %H1, [%3]\n"
1407+ "mov %0, #0\n"
1408+ "teq %1, %4\n"
1409+ "teqeq %H1, %H4\n"
1410+ "strexdeq %0, %5, %H5, [%3]"
1411+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1412+ : "r" (&ptr->counter), "r" (old), "r" (new)
1413+ : "cc");
1414+ } while (res);
1415+
1416+ smp_mb();
1417+
1418+ return oldval;
1419+}
1420+
1421 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1422 {
1423 u64 result;
1424@@ -421,21 +801,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1425
1426 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1427 {
1428- u64 result;
1429- unsigned long tmp;
1430+ u64 result, tmp;
1431
1432 smp_mb();
1433
1434 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1435-"1: ldrexd %0, %H0, [%3]\n"
1436-" subs %0, %0, #1\n"
1437-" sbc %H0, %H0, #0\n"
1438+"1: ldrexd %1, %H1, [%3]\n"
1439+" subs %0, %1, #1\n"
1440+" sbcs %H0, %H1, #0\n"
1441+
1442+#ifdef CONFIG_PAX_REFCOUNT
1443+" bvc 3f\n"
1444+" mov %0, %1\n"
1445+" mov %H0, %H1\n"
1446+"2: bkpt 0xf103\n"
1447+"3:\n"
1448+#endif
1449+
1450 " teq %H0, #0\n"
1451-" bmi 2f\n"
1452+" bmi 4f\n"
1453 " strexd %1, %0, %H0, [%3]\n"
1454 " teq %1, #0\n"
1455 " bne 1b\n"
1456-"2:"
1457+"4:\n"
1458+
1459+#ifdef CONFIG_PAX_REFCOUNT
1460+ _ASM_EXTABLE(2b, 4b)
1461+#endif
1462+
1463 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1464 : "r" (&v->counter)
1465 : "cc");
1466@@ -458,13 +851,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1467 " teq %0, %5\n"
1468 " teqeq %H0, %H5\n"
1469 " moveq %1, #0\n"
1470-" beq 2f\n"
1471+" beq 4f\n"
1472 " adds %0, %0, %6\n"
1473-" adc %H0, %H0, %H6\n"
1474+" adcs %H0, %H0, %H6\n"
1475+
1476+#ifdef CONFIG_PAX_REFCOUNT
1477+" bvc 3f\n"
1478+"2: bkpt 0xf103\n"
1479+"3:\n"
1480+#endif
1481+
1482 " strexd %2, %0, %H0, [%4]\n"
1483 " teq %2, #0\n"
1484 " bne 1b\n"
1485-"2:"
1486+"4:\n"
1487+
1488+#ifdef CONFIG_PAX_REFCOUNT
1489+ _ASM_EXTABLE(2b, 4b)
1490+#endif
1491+
1492 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1493 : "r" (&v->counter), "r" (u), "r" (a)
1494 : "cc");
1495@@ -477,10 +882,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1496
1497 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1498 #define atomic64_inc(v) atomic64_add(1LL, (v))
1499+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1500 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1501+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1502 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1503 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1504 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1505+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1506 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1507 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1508 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1509diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1510index 75fe66b..ba3dee4 100644
1511--- a/arch/arm/include/asm/cache.h
1512+++ b/arch/arm/include/asm/cache.h
1513@@ -4,8 +4,10 @@
1514 #ifndef __ASMARM_CACHE_H
1515 #define __ASMARM_CACHE_H
1516
1517+#include <linux/const.h>
1518+
1519 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1520-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1521+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1522
1523 /*
1524 * Memory returned by kmalloc() may be used for DMA, so we must make
1525@@ -24,5 +26,6 @@
1526 #endif
1527
1528 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1529+#define __read_only __attribute__ ((__section__(".data..read_only")))
1530
1531 #endif
1532diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1533index 17d0ae8..014e350 100644
1534--- a/arch/arm/include/asm/cacheflush.h
1535+++ b/arch/arm/include/asm/cacheflush.h
1536@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1537 void (*dma_unmap_area)(const void *, size_t, int);
1538
1539 void (*dma_flush_range)(const void *, const void *);
1540-};
1541+} __no_const;
1542
1543 /*
1544 * Select the calling method
1545diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1546index 6dcc164..b14d917 100644
1547--- a/arch/arm/include/asm/checksum.h
1548+++ b/arch/arm/include/asm/checksum.h
1549@@ -37,7 +37,19 @@ __wsum
1550 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1551
1552 __wsum
1553-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1554+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1555+
1556+static inline __wsum
1557+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1558+{
1559+ __wsum ret;
1560+ pax_open_userland();
1561+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1562+ pax_close_userland();
1563+ return ret;
1564+}
1565+
1566+
1567
1568 /*
1569 * Fold a partial checksum without adding pseudo headers
1570diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1571index 4f009c1..466c59b 100644
1572--- a/arch/arm/include/asm/cmpxchg.h
1573+++ b/arch/arm/include/asm/cmpxchg.h
1574@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1575
1576 #define xchg(ptr,x) \
1577 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1578+#define xchg_unchecked(ptr,x) \
1579+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1580
1581 #include <asm-generic/cmpxchg-local.h>
1582
1583diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1584index 6ddbe44..b5e38b1 100644
1585--- a/arch/arm/include/asm/domain.h
1586+++ b/arch/arm/include/asm/domain.h
1587@@ -48,18 +48,37 @@
1588 * Domain types
1589 */
1590 #define DOMAIN_NOACCESS 0
1591-#define DOMAIN_CLIENT 1
1592 #ifdef CONFIG_CPU_USE_DOMAINS
1593+#define DOMAIN_USERCLIENT 1
1594+#define DOMAIN_KERNELCLIENT 1
1595 #define DOMAIN_MANAGER 3
1596+#define DOMAIN_VECTORS DOMAIN_USER
1597 #else
1598+
1599+#ifdef CONFIG_PAX_KERNEXEC
1600 #define DOMAIN_MANAGER 1
1601+#define DOMAIN_KERNEXEC 3
1602+#else
1603+#define DOMAIN_MANAGER 1
1604+#endif
1605+
1606+#ifdef CONFIG_PAX_MEMORY_UDEREF
1607+#define DOMAIN_USERCLIENT 0
1608+#define DOMAIN_UDEREF 1
1609+#define DOMAIN_VECTORS DOMAIN_KERNEL
1610+#else
1611+#define DOMAIN_USERCLIENT 1
1612+#define DOMAIN_VECTORS DOMAIN_USER
1613+#endif
1614+#define DOMAIN_KERNELCLIENT 1
1615+
1616 #endif
1617
1618 #define domain_val(dom,type) ((type) << (2*(dom)))
1619
1620 #ifndef __ASSEMBLY__
1621
1622-#ifdef CONFIG_CPU_USE_DOMAINS
1623+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1624 static inline void set_domain(unsigned val)
1625 {
1626 asm volatile(
1627@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1628 isb();
1629 }
1630
1631-#define modify_domain(dom,type) \
1632- do { \
1633- struct thread_info *thread = current_thread_info(); \
1634- unsigned int domain = thread->cpu_domain; \
1635- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1636- thread->cpu_domain = domain | domain_val(dom, type); \
1637- set_domain(thread->cpu_domain); \
1638- } while (0)
1639-
1640+extern void modify_domain(unsigned int dom, unsigned int type);
1641 #else
1642 static inline void set_domain(unsigned val) { }
1643 static inline void modify_domain(unsigned dom, unsigned type) { }
1644diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1645index 56211f2..17e8a25 100644
1646--- a/arch/arm/include/asm/elf.h
1647+++ b/arch/arm/include/asm/elf.h
1648@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1649 the loader. We need to make sure that it is out of the way of the program
1650 that it will "exec", and that there is sufficient room for the brk. */
1651
1652-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1653+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1654+
1655+#ifdef CONFIG_PAX_ASLR
1656+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1657+
1658+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1659+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1660+#endif
1661
1662 /* When the program starts, a1 contains a pointer to a function to be
1663 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1664@@ -126,10 +133,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1665 extern void elf_set_personality(const struct elf32_hdr *);
1666 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1667
1668-struct mm_struct;
1669-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1670-#define arch_randomize_brk arch_randomize_brk
1671-
1672 #ifdef CONFIG_MMU
1673 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1674 struct linux_binprm;
1675diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1676index de53547..52b9a28 100644
1677--- a/arch/arm/include/asm/fncpy.h
1678+++ b/arch/arm/include/asm/fncpy.h
1679@@ -81,7 +81,9 @@
1680 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1681 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1682 \
1683+ pax_open_kernel(); \
1684 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1685+ pax_close_kernel(); \
1686 flush_icache_range((unsigned long)(dest_buf), \
1687 (unsigned long)(dest_buf) + (size)); \
1688 \
1689diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1690index e42cf59..7b94b8f 100644
1691--- a/arch/arm/include/asm/futex.h
1692+++ b/arch/arm/include/asm/futex.h
1693@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1694 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1695 return -EFAULT;
1696
1697+ pax_open_userland();
1698+
1699 smp_mb();
1700 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1701 "1: ldrex %1, [%4]\n"
1702@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1703 : "cc", "memory");
1704 smp_mb();
1705
1706+ pax_close_userland();
1707+
1708 *uval = val;
1709 return ret;
1710 }
1711@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1712 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1713 return -EFAULT;
1714
1715+ pax_open_userland();
1716+
1717 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1718 "1: " TUSER(ldr) " %1, [%4]\n"
1719 " teq %1, %2\n"
1720@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1721 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1722 : "cc", "memory");
1723
1724+ pax_close_userland();
1725+
1726 *uval = val;
1727 return ret;
1728 }
1729@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1730 return -EFAULT;
1731
1732 pagefault_disable(); /* implies preempt_disable() */
1733+ pax_open_userland();
1734
1735 switch (op) {
1736 case FUTEX_OP_SET:
1737@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1738 ret = -ENOSYS;
1739 }
1740
1741+ pax_close_userland();
1742 pagefault_enable(); /* subsumes preempt_enable() */
1743
1744 if (!ret) {
1745diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1746index 83eb2f7..ed77159 100644
1747--- a/arch/arm/include/asm/kmap_types.h
1748+++ b/arch/arm/include/asm/kmap_types.h
1749@@ -4,6 +4,6 @@
1750 /*
1751 * This is the "bare minimum". AIO seems to require this.
1752 */
1753-#define KM_TYPE_NR 16
1754+#define KM_TYPE_NR 17
1755
1756 #endif
1757diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1758index 9e614a1..3302cca 100644
1759--- a/arch/arm/include/asm/mach/dma.h
1760+++ b/arch/arm/include/asm/mach/dma.h
1761@@ -22,7 +22,7 @@ struct dma_ops {
1762 int (*residue)(unsigned int, dma_t *); /* optional */
1763 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1764 const char *type;
1765-};
1766+} __do_const;
1767
1768 struct dma_struct {
1769 void *addr; /* single DMA address */
1770diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1771index 2fe141f..192dc01 100644
1772--- a/arch/arm/include/asm/mach/map.h
1773+++ b/arch/arm/include/asm/mach/map.h
1774@@ -27,13 +27,16 @@ struct map_desc {
1775 #define MT_MINICLEAN 6
1776 #define MT_LOW_VECTORS 7
1777 #define MT_HIGH_VECTORS 8
1778-#define MT_MEMORY 9
1779+#define MT_MEMORY_RWX 9
1780 #define MT_ROM 10
1781-#define MT_MEMORY_NONCACHED 11
1782+#define MT_MEMORY_NONCACHED_RX 11
1783 #define MT_MEMORY_DTCM 12
1784 #define MT_MEMORY_ITCM 13
1785 #define MT_MEMORY_SO 14
1786 #define MT_MEMORY_DMA_READY 15
1787+#define MT_MEMORY_RW 16
1788+#define MT_MEMORY_RX 17
1789+#define MT_MEMORY_NONCACHED_RW 18
1790
1791 #ifdef CONFIG_MMU
1792 extern void iotable_init(struct map_desc *, int);
1793diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1794index 12f71a1..04e063c 100644
1795--- a/arch/arm/include/asm/outercache.h
1796+++ b/arch/arm/include/asm/outercache.h
1797@@ -35,7 +35,7 @@ struct outer_cache_fns {
1798 #endif
1799 void (*set_debug)(unsigned long);
1800 void (*resume)(void);
1801-};
1802+} __no_const;
1803
1804 #ifdef CONFIG_OUTER_CACHE
1805
1806diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1807index 4355f0e..c229913 100644
1808--- a/arch/arm/include/asm/page.h
1809+++ b/arch/arm/include/asm/page.h
1810@@ -114,7 +114,7 @@ struct cpu_user_fns {
1811 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1812 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1813 unsigned long vaddr, struct vm_area_struct *vma);
1814-};
1815+} __no_const;
1816
1817 #ifdef MULTI_USER
1818 extern struct cpu_user_fns cpu_user;
1819diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1820index 943504f..c37a730 100644
1821--- a/arch/arm/include/asm/pgalloc.h
1822+++ b/arch/arm/include/asm/pgalloc.h
1823@@ -17,6 +17,7 @@
1824 #include <asm/processor.h>
1825 #include <asm/cacheflush.h>
1826 #include <asm/tlbflush.h>
1827+#include <asm/system_info.h>
1828
1829 #define check_pgt_cache() do { } while (0)
1830
1831@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1832 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1833 }
1834
1835+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1836+{
1837+ pud_populate(mm, pud, pmd);
1838+}
1839+
1840 #else /* !CONFIG_ARM_LPAE */
1841
1842 /*
1843@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1844 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1845 #define pmd_free(mm, pmd) do { } while (0)
1846 #define pud_populate(mm,pmd,pte) BUG()
1847+#define pud_populate_kernel(mm,pmd,pte) BUG()
1848
1849 #endif /* CONFIG_ARM_LPAE */
1850
1851@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1852 __free_page(pte);
1853 }
1854
1855+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1856+{
1857+#ifdef CONFIG_ARM_LPAE
1858+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1859+#else
1860+ if (addr & SECTION_SIZE)
1861+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1862+ else
1863+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1864+#endif
1865+ flush_pmd_entry(pmdp);
1866+}
1867+
1868 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1869 pmdval_t prot)
1870 {
1871@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1872 static inline void
1873 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1874 {
1875- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1876+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1877 }
1878 #define pmd_pgtable(pmd) pmd_page(pmd)
1879
1880diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1881index 5cfba15..f415e1a 100644
1882--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1883+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1884@@ -20,12 +20,15 @@
1885 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1886 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1887 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1888+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1889 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1890 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1891 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1892+
1893 /*
1894 * - section
1895 */
1896+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1897 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1898 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1899 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1900@@ -37,6 +40,7 @@
1901 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1902 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1903 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1904+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1905
1906 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1907 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1908@@ -66,6 +70,7 @@
1909 * - extended small page/tiny page
1910 */
1911 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1912+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1913 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1914 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1915 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1916diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1917index f97ee02..cc9fe9e 100644
1918--- a/arch/arm/include/asm/pgtable-2level.h
1919+++ b/arch/arm/include/asm/pgtable-2level.h
1920@@ -126,6 +126,9 @@
1921 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1922 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1923
1924+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1925+#define L_PTE_PXN (_AT(pteval_t, 0))
1926+
1927 /*
1928 * These are the memory types, defined to be compatible with
1929 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1930diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1931index 626989f..9d67a33 100644
1932--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1933+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1934@@ -75,6 +75,7 @@
1935 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1936 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1937 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1938+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1939 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1940
1941 /*
1942diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1943index 5689c18..eea12f9 100644
1944--- a/arch/arm/include/asm/pgtable-3level.h
1945+++ b/arch/arm/include/asm/pgtable-3level.h
1946@@ -82,6 +82,7 @@
1947 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1948 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1949 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1950+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1951 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1952 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1953 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1954@@ -95,6 +96,7 @@
1955 /*
1956 * To be used in assembly code with the upper page attributes.
1957 */
1958+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1959 #define L_PTE_XN_HIGH (1 << (54 - 32))
1960 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1961
1962diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1963index 04aeb02..73b70dd 100644
1964--- a/arch/arm/include/asm/pgtable.h
1965+++ b/arch/arm/include/asm/pgtable.h
1966@@ -33,6 +33,9 @@
1967 #include <asm/pgtable-2level.h>
1968 #endif
1969
1970+#define ktla_ktva(addr) (addr)
1971+#define ktva_ktla(addr) (addr)
1972+
1973 /*
1974 * Just any arbitrary offset to the start of the vmalloc VM area: the
1975 * current 8MB value just means that there will be a 8MB "hole" after the
1976@@ -48,6 +51,9 @@
1977 #define LIBRARY_TEXT_START 0x0c000000
1978
1979 #ifndef __ASSEMBLY__
1980+extern pteval_t __supported_pte_mask;
1981+extern pmdval_t __supported_pmd_mask;
1982+
1983 extern void __pte_error(const char *file, int line, pte_t);
1984 extern void __pmd_error(const char *file, int line, pmd_t);
1985 extern void __pgd_error(const char *file, int line, pgd_t);
1986@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1987 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1988 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1989
1990+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1991+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1992+
1993+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1994+#include <asm/domain.h>
1995+#include <linux/thread_info.h>
1996+#include <linux/preempt.h>
1997+
1998+static inline int test_domain(int domain, int domaintype)
1999+{
2000+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2001+}
2002+#endif
2003+
2004+#ifdef CONFIG_PAX_KERNEXEC
2005+static inline unsigned long pax_open_kernel(void) {
2006+#ifdef CONFIG_ARM_LPAE
2007+ /* TODO */
2008+#else
2009+ preempt_disable();
2010+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2011+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2012+#endif
2013+ return 0;
2014+}
2015+
2016+static inline unsigned long pax_close_kernel(void) {
2017+#ifdef CONFIG_ARM_LPAE
2018+ /* TODO */
2019+#else
2020+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2021+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2022+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2023+ preempt_enable_no_resched();
2024+#endif
2025+ return 0;
2026+}
2027+#else
2028+static inline unsigned long pax_open_kernel(void) { return 0; }
2029+static inline unsigned long pax_close_kernel(void) { return 0; }
2030+#endif
2031+
2032 /*
2033 * This is the lowest virtual address we can permit any user space
2034 * mapping to be mapped at. This is particularly important for
2035@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2036 /*
2037 * The pgprot_* and protection_map entries will be fixed up in runtime
2038 * to include the cachable and bufferable bits based on memory policy,
2039- * as well as any architecture dependent bits like global/ASID and SMP
2040- * shared mapping bits.
2041+ * as well as any architecture dependent bits like global/ASID, PXN,
2042+ * and SMP shared mapping bits.
2043 */
2044 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2045
2046@@ -260,7 +308,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2047 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2048 {
2049 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2050- L_PTE_NONE | L_PTE_VALID;
2051+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2052 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2053 return pte;
2054 }
2055diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2056index 5324c11..bcae5f0 100644
2057--- a/arch/arm/include/asm/proc-fns.h
2058+++ b/arch/arm/include/asm/proc-fns.h
2059@@ -75,7 +75,7 @@ extern struct processor {
2060 unsigned int suspend_size;
2061 void (*do_suspend)(void *);
2062 void (*do_resume)(void *);
2063-} processor;
2064+} __do_const processor;
2065
2066 #ifndef MULTI_CPU
2067 extern void cpu_proc_init(void);
2068diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2069index c4ae171..ea0c0c2 100644
2070--- a/arch/arm/include/asm/psci.h
2071+++ b/arch/arm/include/asm/psci.h
2072@@ -29,7 +29,7 @@ struct psci_operations {
2073 int (*cpu_off)(struct psci_power_state state);
2074 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2075 int (*migrate)(unsigned long cpuid);
2076-};
2077+} __no_const;
2078
2079 extern struct psci_operations psci_ops;
2080 extern struct smp_operations psci_smp_ops;
2081diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2082index a8cae71c..65dd797 100644
2083--- a/arch/arm/include/asm/smp.h
2084+++ b/arch/arm/include/asm/smp.h
2085@@ -110,7 +110,7 @@ struct smp_operations {
2086 int (*cpu_disable)(unsigned int cpu);
2087 #endif
2088 #endif
2089-};
2090+} __no_const;
2091
2092 /*
2093 * set platform specific SMP operations
2094diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2095index 2b8114f..8fe9bcf 100644
2096--- a/arch/arm/include/asm/thread_info.h
2097+++ b/arch/arm/include/asm/thread_info.h
2098@@ -77,9 +77,9 @@ struct thread_info {
2099 .flags = 0, \
2100 .preempt_count = INIT_PREEMPT_COUNT, \
2101 .addr_limit = KERNEL_DS, \
2102- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2103- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2104- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2105+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2106+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2107+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2108 .restart_block = { \
2109 .fn = do_no_restart_syscall, \
2110 }, \
2111@@ -152,7 +152,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2112 #define TIF_SYSCALL_AUDIT 9
2113 #define TIF_SYSCALL_TRACEPOINT 10
2114 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2115-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2116+/* within 8 bits of TIF_SYSCALL_TRACE
2117+ * to meet flexible second operand requirements
2118+ */
2119+#define TIF_GRSEC_SETXID 12
2120+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2121 #define TIF_USING_IWMMXT 17
2122 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2123 #define TIF_RESTORE_SIGMASK 20
2124@@ -165,10 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2125 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2126 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2127 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2128+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2129
2130 /* Checks for any syscall work in entry-common.S */
2131 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2132- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2133+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2134
2135 /*
2136 * Change these and you break ASM code in entry-common.S
2137diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2138index 7e1f760..de33b13 100644
2139--- a/arch/arm/include/asm/uaccess.h
2140+++ b/arch/arm/include/asm/uaccess.h
2141@@ -18,6 +18,7 @@
2142 #include <asm/domain.h>
2143 #include <asm/unified.h>
2144 #include <asm/compiler.h>
2145+#include <asm/pgtable.h>
2146
2147 #define VERIFY_READ 0
2148 #define VERIFY_WRITE 1
2149@@ -63,11 +64,38 @@ extern int __put_user_bad(void);
2150 static inline void set_fs(mm_segment_t fs)
2151 {
2152 current_thread_info()->addr_limit = fs;
2153- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2154+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2155 }
2156
2157 #define segment_eq(a,b) ((a) == (b))
2158
2159+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2160+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2161+
2162+static inline void pax_open_userland(void)
2163+{
2164+
2165+#ifdef CONFIG_PAX_MEMORY_UDEREF
2166+ if (segment_eq(get_fs(), USER_DS)) {
2167+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2168+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2169+ }
2170+#endif
2171+
2172+}
2173+
2174+static inline void pax_close_userland(void)
2175+{
2176+
2177+#ifdef CONFIG_PAX_MEMORY_UDEREF
2178+ if (segment_eq(get_fs(), USER_DS)) {
2179+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2180+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2181+ }
2182+#endif
2183+
2184+}
2185+
2186 #define __addr_ok(addr) ({ \
2187 unsigned long flag; \
2188 __asm__("cmp %2, %0; movlo %0, #0" \
2189@@ -143,8 +171,12 @@ extern int __get_user_4(void *);
2190
2191 #define get_user(x,p) \
2192 ({ \
2193+ int __e; \
2194 might_fault(); \
2195- __get_user_check(x,p); \
2196+ pax_open_userland(); \
2197+ __e = __get_user_check(x,p); \
2198+ pax_close_userland(); \
2199+ __e; \
2200 })
2201
2202 extern int __put_user_1(void *, unsigned int);
2203@@ -188,8 +220,12 @@ extern int __put_user_8(void *, unsigned long long);
2204
2205 #define put_user(x,p) \
2206 ({ \
2207+ int __e; \
2208 might_fault(); \
2209- __put_user_check(x,p); \
2210+ pax_open_userland(); \
2211+ __e = __put_user_check(x,p); \
2212+ pax_close_userland(); \
2213+ __e; \
2214 })
2215
2216 #else /* CONFIG_MMU */
2217@@ -230,13 +266,17 @@ static inline void set_fs(mm_segment_t fs)
2218 #define __get_user(x,ptr) \
2219 ({ \
2220 long __gu_err = 0; \
2221+ pax_open_userland(); \
2222 __get_user_err((x),(ptr),__gu_err); \
2223+ pax_close_userland(); \
2224 __gu_err; \
2225 })
2226
2227 #define __get_user_error(x,ptr,err) \
2228 ({ \
2229+ pax_open_userland(); \
2230 __get_user_err((x),(ptr),err); \
2231+ pax_close_userland(); \
2232 (void) 0; \
2233 })
2234
2235@@ -312,13 +352,17 @@ do { \
2236 #define __put_user(x,ptr) \
2237 ({ \
2238 long __pu_err = 0; \
2239+ pax_open_userland(); \
2240 __put_user_err((x),(ptr),__pu_err); \
2241+ pax_close_userland(); \
2242 __pu_err; \
2243 })
2244
2245 #define __put_user_error(x,ptr,err) \
2246 ({ \
2247+ pax_open_userland(); \
2248 __put_user_err((x),(ptr),err); \
2249+ pax_close_userland(); \
2250 (void) 0; \
2251 })
2252
2253@@ -418,11 +462,44 @@ do { \
2254
2255
2256 #ifdef CONFIG_MMU
2257-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2258-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2259+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2260+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2261+
2262+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2263+{
2264+ unsigned long ret;
2265+
2266+ check_object_size(to, n, false);
2267+ pax_open_userland();
2268+ ret = ___copy_from_user(to, from, n);
2269+ pax_close_userland();
2270+ return ret;
2271+}
2272+
2273+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2274+{
2275+ unsigned long ret;
2276+
2277+ check_object_size(from, n, true);
2278+ pax_open_userland();
2279+ ret = ___copy_to_user(to, from, n);
2280+ pax_close_userland();
2281+ return ret;
2282+}
2283+
2284 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2285-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2286+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2287 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2288+
2289+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2290+{
2291+ unsigned long ret;
2292+ pax_open_userland();
2293+ ret = ___clear_user(addr, n);
2294+ pax_close_userland();
2295+ return ret;
2296+}
2297+
2298 #else
2299 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2300 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2301@@ -431,6 +508,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2302
2303 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2304 {
2305+ if ((long)n < 0)
2306+ return n;
2307+
2308 if (access_ok(VERIFY_READ, from, n))
2309 n = __copy_from_user(to, from, n);
2310 else /* security hole - plug it */
2311@@ -440,6 +520,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2312
2313 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2314 {
2315+ if ((long)n < 0)
2316+ return n;
2317+
2318 if (access_ok(VERIFY_WRITE, to, n))
2319 n = __copy_to_user(to, from, n);
2320 return n;
2321diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2322index 5af0ed1..cea83883 100644
2323--- a/arch/arm/include/uapi/asm/ptrace.h
2324+++ b/arch/arm/include/uapi/asm/ptrace.h
2325@@ -92,7 +92,7 @@
2326 * ARMv7 groups of PSR bits
2327 */
2328 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2329-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2330+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2331 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2332 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2333
2334diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2335index 60d3b73..e5a0f22 100644
2336--- a/arch/arm/kernel/armksyms.c
2337+++ b/arch/arm/kernel/armksyms.c
2338@@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2339
2340 /* networking */
2341 EXPORT_SYMBOL(csum_partial);
2342-EXPORT_SYMBOL(csum_partial_copy_from_user);
2343+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2344 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2345 EXPORT_SYMBOL(__csum_ipv6_magic);
2346
2347@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2348 #ifdef CONFIG_MMU
2349 EXPORT_SYMBOL(copy_page);
2350
2351-EXPORT_SYMBOL(__copy_from_user);
2352-EXPORT_SYMBOL(__copy_to_user);
2353-EXPORT_SYMBOL(__clear_user);
2354+EXPORT_SYMBOL(___copy_from_user);
2355+EXPORT_SYMBOL(___copy_to_user);
2356+EXPORT_SYMBOL(___clear_user);
2357
2358 EXPORT_SYMBOL(__get_user_1);
2359 EXPORT_SYMBOL(__get_user_2);
2360diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2361index 9cbe70c..a7b5e34 100644
2362--- a/arch/arm/kernel/entry-armv.S
2363+++ b/arch/arm/kernel/entry-armv.S
2364@@ -47,6 +47,87 @@
2365 9997:
2366 .endm
2367
2368+ .macro pax_enter_kernel
2369+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2370+ @ make aligned space for saved DACR
2371+ sub sp, sp, #8
2372+ @ save regs
2373+ stmdb sp!, {r1, r2}
2374+ @ read DACR from cpu_domain into r1
2375+ mov r2, sp
2376+ @ assume 8K pages, since we have to split the immediate in two
2377+ bic r2, r2, #(0x1fc0)
2378+ bic r2, r2, #(0x3f)
2379+ ldr r1, [r2, #TI_CPU_DOMAIN]
2380+ @ store old DACR on stack
2381+ str r1, [sp, #8]
2382+#ifdef CONFIG_PAX_KERNEXEC
2383+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2384+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2385+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2386+#endif
2387+#ifdef CONFIG_PAX_MEMORY_UDEREF
2388+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2389+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2390+#endif
2391+ @ write r1 to current_thread_info()->cpu_domain
2392+ str r1, [r2, #TI_CPU_DOMAIN]
2393+ @ write r1 to DACR
2394+ mcr p15, 0, r1, c3, c0, 0
2395+ @ instruction sync
2396+ instr_sync
2397+ @ restore regs
2398+ ldmia sp!, {r1, r2}
2399+#endif
2400+ .endm
2401+
2402+ .macro pax_open_userland
2403+#ifdef CONFIG_PAX_MEMORY_UDEREF
2404+ @ save regs
2405+ stmdb sp!, {r0, r1}
2406+ @ read DACR from cpu_domain into r1
2407+ mov r0, sp
2408+ @ assume 8K pages, since we have to split the immediate in two
2409+ bic r0, r0, #(0x1fc0)
2410+ bic r0, r0, #(0x3f)
2411+ ldr r1, [r0, #TI_CPU_DOMAIN]
2412+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2413+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2414+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2415+ @ write r1 to current_thread_info()->cpu_domain
2416+ str r1, [r0, #TI_CPU_DOMAIN]
2417+ @ write r1 to DACR
2418+ mcr p15, 0, r1, c3, c0, 0
2419+ @ instruction sync
2420+ instr_sync
2421+ @ restore regs
2422+ ldmia sp!, {r0, r1}
2423+#endif
2424+ .endm
2425+
2426+ .macro pax_close_userland
2427+#ifdef CONFIG_PAX_MEMORY_UDEREF
2428+ @ save regs
2429+ stmdb sp!, {r0, r1}
2430+ @ read DACR from cpu_domain into r1
2431+ mov r0, sp
2432+ @ assume 8K pages, since we have to split the immediate in two
2433+ bic r0, r0, #(0x1fc0)
2434+ bic r0, r0, #(0x3f)
2435+ ldr r1, [r0, #TI_CPU_DOMAIN]
2436+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2437+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2438+ @ write r1 to current_thread_info()->cpu_domain
2439+ str r1, [r0, #TI_CPU_DOMAIN]
2440+ @ write r1 to DACR
2441+ mcr p15, 0, r1, c3, c0, 0
2442+ @ instruction sync
2443+ instr_sync
2444+ @ restore regs
2445+ ldmia sp!, {r0, r1}
2446+#endif
2447+ .endm
2448+
2449 .macro pabt_helper
2450 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2451 #ifdef MULTI_PABORT
2452@@ -89,11 +170,15 @@
2453 * Invalid mode handlers
2454 */
2455 .macro inv_entry, reason
2456+
2457+ pax_enter_kernel
2458+
2459 sub sp, sp, #S_FRAME_SIZE
2460 ARM( stmib sp, {r1 - lr} )
2461 THUMB( stmia sp, {r0 - r12} )
2462 THUMB( str sp, [sp, #S_SP] )
2463 THUMB( str lr, [sp, #S_LR] )
2464+
2465 mov r1, #\reason
2466 .endm
2467
2468@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2469 .macro svc_entry, stack_hole=0
2470 UNWIND(.fnstart )
2471 UNWIND(.save {r0 - pc} )
2472+
2473+ pax_enter_kernel
2474+
2475 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2476+
2477 #ifdef CONFIG_THUMB2_KERNEL
2478 SPFIX( str r0, [sp] ) @ temporarily saved
2479 SPFIX( mov r0, sp )
2480@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2481 ldmia r0, {r3 - r5}
2482 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2483 mov r6, #-1 @ "" "" "" ""
2484+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2485+ @ offset sp by 8 as done in pax_enter_kernel
2486+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2487+#else
2488 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2489+#endif
2490 SPFIX( addeq r2, r2, #4 )
2491 str r3, [sp, #-4]! @ save the "real" r0 copied
2492 @ from the exception stack
2493@@ -316,6 +410,9 @@ ENDPROC(__pabt_svc)
2494 .macro usr_entry
2495 UNWIND(.fnstart )
2496 UNWIND(.cantunwind ) @ don't unwind the user space
2497+
2498+ pax_enter_kernel_user
2499+
2500 sub sp, sp, #S_FRAME_SIZE
2501 ARM( stmib sp, {r1 - r12} )
2502 THUMB( stmia sp, {r0 - r12} )
2503@@ -415,7 +512,9 @@ __und_usr:
2504 tst r3, #PSR_T_BIT @ Thumb mode?
2505 bne __und_usr_thumb
2506 sub r4, r2, #4 @ ARM instr at LR - 4
2507+ pax_open_userland
2508 1: ldrt r0, [r4]
2509+ pax_close_userland
2510 #ifdef CONFIG_CPU_ENDIAN_BE8
2511 rev r0, r0 @ little endian instruction
2512 #endif
2513@@ -450,10 +549,14 @@ __und_usr_thumb:
2514 */
2515 .arch armv6t2
2516 #endif
2517+ pax_open_userland
2518 2: ldrht r5, [r4]
2519+ pax_close_userland
2520 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2521 blo __und_usr_fault_16 @ 16bit undefined instruction
2522+ pax_open_userland
2523 3: ldrht r0, [r2]
2524+ pax_close_userland
2525 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2526 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2527 orr r0, r0, r5, lsl #16
2528@@ -482,7 +585,8 @@ ENDPROC(__und_usr)
2529 */
2530 .pushsection .fixup, "ax"
2531 .align 2
2532-4: mov pc, r9
2533+4: pax_close_userland
2534+ mov pc, r9
2535 .popsection
2536 .pushsection __ex_table,"a"
2537 .long 1b, 4b
2538@@ -692,7 +796,7 @@ ENTRY(__switch_to)
2539 THUMB( str lr, [ip], #4 )
2540 ldr r4, [r2, #TI_TP_VALUE]
2541 ldr r5, [r2, #TI_TP_VALUE + 4]
2542-#ifdef CONFIG_CPU_USE_DOMAINS
2543+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2544 ldr r6, [r2, #TI_CPU_DOMAIN]
2545 #endif
2546 switch_tls r1, r4, r5, r3, r7
2547@@ -701,7 +805,7 @@ ENTRY(__switch_to)
2548 ldr r8, =__stack_chk_guard
2549 ldr r7, [r7, #TSK_STACK_CANARY]
2550 #endif
2551-#ifdef CONFIG_CPU_USE_DOMAINS
2552+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2553 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2554 #endif
2555 mov r5, r0
2556diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2557index 94104bf..9732b1c 100644
2558--- a/arch/arm/kernel/entry-common.S
2559+++ b/arch/arm/kernel/entry-common.S
2560@@ -10,18 +10,46 @@
2561
2562 #include <asm/unistd.h>
2563 #include <asm/ftrace.h>
2564+#include <asm/domain.h>
2565 #include <asm/unwind.h>
2566
2567+#include "entry-header.S"
2568+
2569 #ifdef CONFIG_NEED_RET_TO_USER
2570 #include <mach/entry-macro.S>
2571 #else
2572 .macro arch_ret_to_user, tmp1, tmp2
2573+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2574+ @ save regs
2575+ stmdb sp!, {r1, r2}
2576+ @ read DACR from cpu_domain into r1
2577+ mov r2, sp
2578+ @ assume 8K pages, since we have to split the immediate in two
2579+ bic r2, r2, #(0x1fc0)
2580+ bic r2, r2, #(0x3f)
2581+ ldr r1, [r2, #TI_CPU_DOMAIN]
2582+#ifdef CONFIG_PAX_KERNEXEC
2583+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2584+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2585+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2586+#endif
2587+#ifdef CONFIG_PAX_MEMORY_UDEREF
2588+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2589+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2590+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2591+#endif
2592+ @ write r1 to current_thread_info()->cpu_domain
2593+ str r1, [r2, #TI_CPU_DOMAIN]
2594+ @ write r1 to DACR
2595+ mcr p15, 0, r1, c3, c0, 0
2596+ @ instruction sync
2597+ instr_sync
2598+ @ restore regs
2599+ ldmia sp!, {r1, r2}
2600+#endif
2601 .endm
2602 #endif
2603
2604-#include "entry-header.S"
2605-
2606-
2607 .align 5
2608 /*
2609 * This is the fast syscall return path. We do as little as
2610@@ -366,6 +394,12 @@ ENTRY(vector_swi)
2611 #endif
2612 zero_fp
2613
2614+ /*
2615+ * do this here to avoid a performance hit of wrapping the code above
2616+ * that directly dereferences userland to parse the SWI instruction
2617+ */
2618+ pax_enter_kernel_user
2619+
2620 #ifdef CONFIG_ALIGNMENT_TRAP
2621 ldr ip, __cr_alignment
2622 ldr ip, [ip]
2623diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2624index de23a9b..94c37c4 100644
2625--- a/arch/arm/kernel/entry-header.S
2626+++ b/arch/arm/kernel/entry-header.S
2627@@ -184,6 +184,60 @@
2628 msr cpsr_c, \rtemp @ switch back to the SVC mode
2629 .endm
2630
2631+ .macro pax_enter_kernel_user
2632+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2633+ @ save regs
2634+ stmdb sp!, {r0, r1}
2635+ @ read DACR from cpu_domain into r1
2636+ mov r0, sp
2637+ @ assume 8K pages, since we have to split the immediate in two
2638+ bic r0, r0, #(0x1fc0)
2639+ bic r0, r0, #(0x3f)
2640+ ldr r1, [r0, #TI_CPU_DOMAIN]
2641+#ifdef CONFIG_PAX_MEMORY_UDEREF
2642+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2643+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2644+#endif
2645+#ifdef CONFIG_PAX_KERNEXEC
2646+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2647+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2648+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2649+#endif
2650+ @ write r1 to current_thread_info()->cpu_domain
2651+ str r1, [r0, #TI_CPU_DOMAIN]
2652+ @ write r1 to DACR
2653+ mcr p15, 0, r1, c3, c0, 0
2654+ @ instruction sync
2655+ instr_sync
2656+ @ restore regs
2657+ ldmia sp!, {r0, r1}
2658+#endif
2659+ .endm
2660+
2661+ .macro pax_exit_kernel
2662+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2663+ @ save regs
2664+ stmdb sp!, {r0, r1}
2665+ @ read old DACR from stack into r1
2666+ ldr r1, [sp, #(8 + S_SP)]
2667+ sub r1, r1, #8
2668+ ldr r1, [r1]
2669+
2670+ @ write r1 to current_thread_info()->cpu_domain
2671+ mov r0, sp
2672+ @ assume 8K pages, since we have to split the immediate in two
2673+ bic r0, r0, #(0x1fc0)
2674+ bic r0, r0, #(0x3f)
2675+ str r1, [r0, #TI_CPU_DOMAIN]
2676+ @ write r1 to DACR
2677+ mcr p15, 0, r1, c3, c0, 0
2678+ @ instruction sync
2679+ instr_sync
2680+ @ restore regs
2681+ ldmia sp!, {r0, r1}
2682+#endif
2683+ .endm
2684+
2685 #ifndef CONFIG_THUMB2_KERNEL
2686 .macro svc_exit, rpsr, irq = 0
2687 .if \irq != 0
2688@@ -203,6 +257,9 @@
2689 blne trace_hardirqs_off
2690 #endif
2691 .endif
2692+
2693+ pax_exit_kernel
2694+
2695 msr spsr_cxsf, \rpsr
2696 #if defined(CONFIG_CPU_V6)
2697 ldr r0, [sp]
2698@@ -266,6 +323,9 @@
2699 blne trace_hardirqs_off
2700 #endif
2701 .endif
2702+
2703+ pax_exit_kernel
2704+
2705 ldr lr, [sp, #S_SP] @ top of the stack
2706 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2707 clrex @ clear the exclusive monitor
2708diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2709index 918875d..cd5fa27 100644
2710--- a/arch/arm/kernel/fiq.c
2711+++ b/arch/arm/kernel/fiq.c
2712@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2713 void *base = vectors_page;
2714 unsigned offset = FIQ_OFFSET;
2715
2716+ pax_open_kernel();
2717 memcpy(base + offset, start, length);
2718+ pax_close_kernel();
2719+
2720 if (!cache_is_vipt_nonaliasing())
2721 flush_icache_range((unsigned long)base + offset, offset +
2722 length);
2723diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2724index 2c7cc1e..ab2e911 100644
2725--- a/arch/arm/kernel/head.S
2726+++ b/arch/arm/kernel/head.S
2727@@ -52,7 +52,9 @@
2728 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2729
2730 .macro pgtbl, rd, phys
2731- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2732+ mov \rd, #TEXT_OFFSET
2733+ sub \rd, #PG_DIR_SIZE
2734+ add \rd, \rd, \phys
2735 .endm
2736
2737 /*
2738@@ -432,7 +434,7 @@ __enable_mmu:
2739 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2740 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2741 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2742- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2743+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2744 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2745 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2746 #endif
2747diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2748index 85c3fb6..b3068b1 100644
2749--- a/arch/arm/kernel/module.c
2750+++ b/arch/arm/kernel/module.c
2751@@ -37,12 +37,37 @@
2752 #endif
2753
2754 #ifdef CONFIG_MMU
2755-void *module_alloc(unsigned long size)
2756+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2757 {
2758+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2759+ return NULL;
2760 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2761- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2762+ GFP_KERNEL, prot, -1,
2763 __builtin_return_address(0));
2764 }
2765+
2766+void *module_alloc(unsigned long size)
2767+{
2768+
2769+#ifdef CONFIG_PAX_KERNEXEC
2770+ return __module_alloc(size, PAGE_KERNEL);
2771+#else
2772+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2773+#endif
2774+
2775+}
2776+
2777+#ifdef CONFIG_PAX_KERNEXEC
2778+void module_free_exec(struct module *mod, void *module_region)
2779+{
2780+ module_free(mod, module_region);
2781+}
2782+
2783+void *module_alloc_exec(unsigned long size)
2784+{
2785+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2786+}
2787+#endif
2788 #endif
2789
2790 int
2791diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2792index 07314af..c46655c 100644
2793--- a/arch/arm/kernel/patch.c
2794+++ b/arch/arm/kernel/patch.c
2795@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2796 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2797 int size;
2798
2799+ pax_open_kernel();
2800 if (thumb2 && __opcode_is_thumb16(insn)) {
2801 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2802 size = sizeof(u16);
2803@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2804 *(u32 *)addr = insn;
2805 size = sizeof(u32);
2806 }
2807+ pax_close_kernel();
2808
2809 flush_icache_range((uintptr_t)(addr),
2810 (uintptr_t)(addr) + size);
2811diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2812index 94f6b05..efd7312 100644
2813--- a/arch/arm/kernel/process.c
2814+++ b/arch/arm/kernel/process.c
2815@@ -217,6 +217,7 @@ void machine_power_off(void)
2816
2817 if (pm_power_off)
2818 pm_power_off();
2819+ BUG();
2820 }
2821
2822 /*
2823@@ -230,7 +231,7 @@ void machine_power_off(void)
2824 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2825 * to use. Implementing such co-ordination would be essentially impossible.
2826 */
2827-void machine_restart(char *cmd)
2828+__noreturn void machine_restart(char *cmd)
2829 {
2830 local_irq_disable();
2831 smp_send_stop();
2832@@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2833
2834 show_regs_print_info(KERN_DEFAULT);
2835
2836- print_symbol("PC is at %s\n", instruction_pointer(regs));
2837- print_symbol("LR is at %s\n", regs->ARM_lr);
2838+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2839+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2840 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2841 "sp : %08lx ip : %08lx fp : %08lx\n",
2842 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2843@@ -422,12 +423,6 @@ unsigned long get_wchan(struct task_struct *p)
2844 return 0;
2845 }
2846
2847-unsigned long arch_randomize_brk(struct mm_struct *mm)
2848-{
2849- unsigned long range_end = mm->brk + 0x02000000;
2850- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2851-}
2852-
2853 #ifdef CONFIG_MMU
2854 #ifdef CONFIG_KUSER_HELPERS
2855 /*
2856@@ -443,7 +438,7 @@ static struct vm_area_struct gate_vma = {
2857
2858 static int __init gate_vma_init(void)
2859 {
2860- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2861+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2862 return 0;
2863 }
2864 arch_initcall(gate_vma_init);
2865@@ -469,41 +464,16 @@ int in_gate_area_no_mm(unsigned long addr)
2866
2867 const char *arch_vma_name(struct vm_area_struct *vma)
2868 {
2869- return is_gate_vma(vma) ? "[vectors]" :
2870- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2871- "[sigpage]" : NULL;
2872+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2873 }
2874
2875-static struct page *signal_page;
2876-extern struct page *get_signal_page(void);
2877-
2878 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2879 {
2880 struct mm_struct *mm = current->mm;
2881- unsigned long addr;
2882- int ret;
2883-
2884- if (!signal_page)
2885- signal_page = get_signal_page();
2886- if (!signal_page)
2887- return -ENOMEM;
2888
2889 down_write(&mm->mmap_sem);
2890- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2891- if (IS_ERR_VALUE(addr)) {
2892- ret = addr;
2893- goto up_fail;
2894- }
2895-
2896- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2897- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2898- &signal_page);
2899-
2900- if (ret == 0)
2901- mm->context.sigpage = addr;
2902-
2903- up_fail:
2904+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2905 up_write(&mm->mmap_sem);
2906- return ret;
2907+ return 0;
2908 }
2909 #endif
2910diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2911index 4693188..4596c5e 100644
2912--- a/arch/arm/kernel/psci.c
2913+++ b/arch/arm/kernel/psci.c
2914@@ -24,7 +24,7 @@
2915 #include <asm/opcodes-virt.h>
2916 #include <asm/psci.h>
2917
2918-struct psci_operations psci_ops;
2919+struct psci_operations psci_ops __read_only;
2920
2921 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2922
2923diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2924index 0dd3b79..e018f64 100644
2925--- a/arch/arm/kernel/ptrace.c
2926+++ b/arch/arm/kernel/ptrace.c
2927@@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2928 return current_thread_info()->syscall;
2929 }
2930
2931+#ifdef CONFIG_GRKERNSEC_SETXID
2932+extern void gr_delayed_cred_worker(void);
2933+#endif
2934+
2935 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2936 {
2937 current_thread_info()->syscall = scno;
2938
2939+#ifdef CONFIG_GRKERNSEC_SETXID
2940+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2941+ gr_delayed_cred_worker();
2942+#endif
2943+
2944 /* Do the secure computing check first; failures should be fast. */
2945 if (secure_computing(scno) == -1)
2946 return -1;
2947diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2948index afc2489..6372bc8 100644
2949--- a/arch/arm/kernel/setup.c
2950+++ b/arch/arm/kernel/setup.c
2951@@ -98,21 +98,23 @@ EXPORT_SYMBOL(system_serial_high);
2952 unsigned int elf_hwcap __read_mostly;
2953 EXPORT_SYMBOL(elf_hwcap);
2954
2955+pteval_t __supported_pte_mask __read_only;
2956+pmdval_t __supported_pmd_mask __read_only;
2957
2958 #ifdef MULTI_CPU
2959-struct processor processor __read_mostly;
2960+struct processor processor;
2961 #endif
2962 #ifdef MULTI_TLB
2963-struct cpu_tlb_fns cpu_tlb __read_mostly;
2964+struct cpu_tlb_fns cpu_tlb __read_only;
2965 #endif
2966 #ifdef MULTI_USER
2967-struct cpu_user_fns cpu_user __read_mostly;
2968+struct cpu_user_fns cpu_user __read_only;
2969 #endif
2970 #ifdef MULTI_CACHE
2971-struct cpu_cache_fns cpu_cache __read_mostly;
2972+struct cpu_cache_fns cpu_cache __read_only;
2973 #endif
2974 #ifdef CONFIG_OUTER_CACHE
2975-struct outer_cache_fns outer_cache __read_mostly;
2976+struct outer_cache_fns outer_cache __read_only;
2977 EXPORT_SYMBOL(outer_cache);
2978 #endif
2979
2980@@ -245,9 +247,13 @@ static int __get_cpu_architecture(void)
2981 asm("mrc p15, 0, %0, c0, c1, 4"
2982 : "=r" (mmfr0));
2983 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2984- (mmfr0 & 0x000000f0) >= 0x00000030)
2985+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2986 cpu_arch = CPU_ARCH_ARMv7;
2987- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2988+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2989+ __supported_pte_mask |= L_PTE_PXN;
2990+ __supported_pmd_mask |= PMD_PXNTABLE;
2991+ }
2992+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2993 (mmfr0 & 0x000000f0) == 0x00000020)
2994 cpu_arch = CPU_ARCH_ARMv6;
2995 else
2996@@ -571,7 +577,7 @@ static void __init setup_processor(void)
2997 __cpu_architecture = __get_cpu_architecture();
2998
2999 #ifdef MULTI_CPU
3000- processor = *list->proc;
3001+ memcpy((void *)&processor, list->proc, sizeof processor);
3002 #endif
3003 #ifdef MULTI_TLB
3004 cpu_tlb = *list->tlb;
3005diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3006index ab33042..11248a8 100644
3007--- a/arch/arm/kernel/signal.c
3008+++ b/arch/arm/kernel/signal.c
3009@@ -45,8 +45,6 @@ static const unsigned long sigreturn_codes[7] = {
3010 MOV_R7_NR_RT_SIGRETURN, SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN,
3011 };
3012
3013-static unsigned long signal_return_offset;
3014-
3015 #ifdef CONFIG_CRUNCH
3016 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3017 {
3018@@ -411,8 +409,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3019 * except when the MPU has protected the vectors
3020 * page from PL0
3021 */
3022- retcode = mm->context.sigpage + signal_return_offset +
3023- (idx << 2) + thumb;
3024+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3025 } else
3026 #endif
3027 {
3028@@ -616,33 +613,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3029 } while (thread_flags & _TIF_WORK_MASK);
3030 return 0;
3031 }
3032-
3033-struct page *get_signal_page(void)
3034-{
3035- unsigned long ptr;
3036- unsigned offset;
3037- struct page *page;
3038- void *addr;
3039-
3040- page = alloc_pages(GFP_KERNEL, 0);
3041-
3042- if (!page)
3043- return NULL;
3044-
3045- addr = page_address(page);
3046-
3047- /* Give the signal return code some randomness */
3048- offset = 0x200 + (get_random_int() & 0x7fc);
3049- signal_return_offset = offset;
3050-
3051- /*
3052- * Copy signal return handlers into the vector page, and
3053- * set sigreturn to be a pointer to these.
3054- */
3055- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3056-
3057- ptr = (unsigned long)addr + offset;
3058- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3059-
3060- return page;
3061-}
3062diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3063index 2dc1934..ecf0e21 100644
3064--- a/arch/arm/kernel/smp.c
3065+++ b/arch/arm/kernel/smp.c
3066@@ -71,7 +71,7 @@ enum ipi_msg_type {
3067
3068 static DECLARE_COMPLETION(cpu_running);
3069
3070-static struct smp_operations smp_ops;
3071+static struct smp_operations smp_ops __read_only;
3072
3073 void __init smp_set_ops(struct smp_operations *ops)
3074 {
3075diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3076index ab517fc..9adf2fa 100644
3077--- a/arch/arm/kernel/traps.c
3078+++ b/arch/arm/kernel/traps.c
3079@@ -55,7 +55,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3080 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3081 {
3082 #ifdef CONFIG_KALLSYMS
3083- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3084+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3085 #else
3086 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3087 #endif
3088@@ -257,6 +257,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3089 static int die_owner = -1;
3090 static unsigned int die_nest_count;
3091
3092+extern void gr_handle_kernel_exploit(void);
3093+
3094 static unsigned long oops_begin(void)
3095 {
3096 int cpu;
3097@@ -299,6 +301,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3098 panic("Fatal exception in interrupt");
3099 if (panic_on_oops)
3100 panic("Fatal exception");
3101+
3102+ gr_handle_kernel_exploit();
3103+
3104 if (signr)
3105 do_exit(signr);
3106 }
3107@@ -592,7 +597,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3108 * The user helper at 0xffff0fe0 must be used instead.
3109 * (see entry-armv.S for details)
3110 */
3111+ pax_open_kernel();
3112 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3113+ pax_close_kernel();
3114 }
3115 return 0;
3116
3117@@ -849,7 +856,11 @@ void __init early_trap_init(void *vectors_base)
3118 kuser_init(vectors_base);
3119
3120 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3121- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3122+
3123+#ifndef CONFIG_PAX_MEMORY_UDEREF
3124+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3125+#endif
3126+
3127 #else /* ifndef CONFIG_CPU_V7M */
3128 /*
3129 * on V7-M there is no need to copy the vector table to a dedicated
3130diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3131index 7bcee5c..64c9c5f 100644
3132--- a/arch/arm/kernel/vmlinux.lds.S
3133+++ b/arch/arm/kernel/vmlinux.lds.S
3134@@ -8,7 +8,11 @@
3135 #include <asm/thread_info.h>
3136 #include <asm/memory.h>
3137 #include <asm/page.h>
3138-
3139+
3140+#ifdef CONFIG_PAX_KERNEXEC
3141+#include <asm/pgtable.h>
3142+#endif
3143+
3144 #define PROC_INFO \
3145 . = ALIGN(4); \
3146 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3147@@ -90,6 +94,11 @@ SECTIONS
3148 _text = .;
3149 HEAD_TEXT
3150 }
3151+
3152+#ifdef CONFIG_PAX_KERNEXEC
3153+ . = ALIGN(1<<SECTION_SHIFT);
3154+#endif
3155+
3156 .text : { /* Real text segment */
3157 _stext = .; /* Text and read-only data */
3158 __exception_text_start = .;
3159@@ -112,6 +121,8 @@ SECTIONS
3160 ARM_CPU_KEEP(PROC_INFO)
3161 }
3162
3163+ _etext = .; /* End of text section */
3164+
3165 RO_DATA(PAGE_SIZE)
3166
3167 . = ALIGN(4);
3168@@ -142,7 +153,9 @@ SECTIONS
3169
3170 NOTES
3171
3172- _etext = .; /* End of text and rodata section */
3173+#ifdef CONFIG_PAX_KERNEXEC
3174+ . = ALIGN(1<<SECTION_SHIFT);
3175+#endif
3176
3177 #ifndef CONFIG_XIP_KERNEL
3178 . = ALIGN(PAGE_SIZE);
3179@@ -220,6 +233,11 @@ SECTIONS
3180 . = PAGE_OFFSET + TEXT_OFFSET;
3181 #else
3182 __init_end = .;
3183+
3184+#ifdef CONFIG_PAX_KERNEXEC
3185+ . = ALIGN(1<<SECTION_SHIFT);
3186+#endif
3187+
3188 . = ALIGN(THREAD_SIZE);
3189 __data_loc = .;
3190 #endif
3191diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3192index 741f66a..8a5615c 100644
3193--- a/arch/arm/kvm/arm.c
3194+++ b/arch/arm/kvm/arm.c
3195@@ -56,7 +56,7 @@ static unsigned long hyp_default_vectors;
3196 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3197
3198 /* The VMID used in the VTTBR */
3199-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3200+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3201 static u8 kvm_next_vmid;
3202 static DEFINE_SPINLOCK(kvm_vmid_lock);
3203
3204@@ -392,7 +392,7 @@ void force_vm_exit(const cpumask_t *mask)
3205 */
3206 static bool need_new_vmid_gen(struct kvm *kvm)
3207 {
3208- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3209+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3210 }
3211
3212 /**
3213@@ -425,7 +425,7 @@ static void update_vttbr(struct kvm *kvm)
3214
3215 /* First user of a new VMID generation? */
3216 if (unlikely(kvm_next_vmid == 0)) {
3217- atomic64_inc(&kvm_vmid_gen);
3218+ atomic64_inc_unchecked(&kvm_vmid_gen);
3219 kvm_next_vmid = 1;
3220
3221 /*
3222@@ -442,7 +442,7 @@ static void update_vttbr(struct kvm *kvm)
3223 kvm_call_hyp(__kvm_flush_vm_context);
3224 }
3225
3226- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3227+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3228 kvm->arch.vmid = kvm_next_vmid;
3229 kvm_next_vmid++;
3230
3231diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3232index 14a0d98..7771a7d 100644
3233--- a/arch/arm/lib/clear_user.S
3234+++ b/arch/arm/lib/clear_user.S
3235@@ -12,14 +12,14 @@
3236
3237 .text
3238
3239-/* Prototype: int __clear_user(void *addr, size_t sz)
3240+/* Prototype: int ___clear_user(void *addr, size_t sz)
3241 * Purpose : clear some user memory
3242 * Params : addr - user memory address to clear
3243 * : sz - number of bytes to clear
3244 * Returns : number of bytes NOT cleared
3245 */
3246 ENTRY(__clear_user_std)
3247-WEAK(__clear_user)
3248+WEAK(___clear_user)
3249 stmfd sp!, {r1, lr}
3250 mov r2, #0
3251 cmp r1, #4
3252@@ -44,7 +44,7 @@ WEAK(__clear_user)
3253 USER( strnebt r2, [r0])
3254 mov r0, #0
3255 ldmfd sp!, {r1, pc}
3256-ENDPROC(__clear_user)
3257+ENDPROC(___clear_user)
3258 ENDPROC(__clear_user_std)
3259
3260 .pushsection .fixup,"ax"
3261diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3262index 66a477a..bee61d3 100644
3263--- a/arch/arm/lib/copy_from_user.S
3264+++ b/arch/arm/lib/copy_from_user.S
3265@@ -16,7 +16,7 @@
3266 /*
3267 * Prototype:
3268 *
3269- * size_t __copy_from_user(void *to, const void *from, size_t n)
3270+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3271 *
3272 * Purpose:
3273 *
3274@@ -84,11 +84,11 @@
3275
3276 .text
3277
3278-ENTRY(__copy_from_user)
3279+ENTRY(___copy_from_user)
3280
3281 #include "copy_template.S"
3282
3283-ENDPROC(__copy_from_user)
3284+ENDPROC(___copy_from_user)
3285
3286 .pushsection .fixup,"ax"
3287 .align 0
3288diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3289index 6ee2f67..d1cce76 100644
3290--- a/arch/arm/lib/copy_page.S
3291+++ b/arch/arm/lib/copy_page.S
3292@@ -10,6 +10,7 @@
3293 * ASM optimised string functions
3294 */
3295 #include <linux/linkage.h>
3296+#include <linux/const.h>
3297 #include <asm/assembler.h>
3298 #include <asm/asm-offsets.h>
3299 #include <asm/cache.h>
3300diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3301index d066df6..df28194 100644
3302--- a/arch/arm/lib/copy_to_user.S
3303+++ b/arch/arm/lib/copy_to_user.S
3304@@ -16,7 +16,7 @@
3305 /*
3306 * Prototype:
3307 *
3308- * size_t __copy_to_user(void *to, const void *from, size_t n)
3309+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3310 *
3311 * Purpose:
3312 *
3313@@ -88,11 +88,11 @@
3314 .text
3315
3316 ENTRY(__copy_to_user_std)
3317-WEAK(__copy_to_user)
3318+WEAK(___copy_to_user)
3319
3320 #include "copy_template.S"
3321
3322-ENDPROC(__copy_to_user)
3323+ENDPROC(___copy_to_user)
3324 ENDPROC(__copy_to_user_std)
3325
3326 .pushsection .fixup,"ax"
3327diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3328index 7d08b43..f7ca7ea 100644
3329--- a/arch/arm/lib/csumpartialcopyuser.S
3330+++ b/arch/arm/lib/csumpartialcopyuser.S
3331@@ -57,8 +57,8 @@
3332 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3333 */
3334
3335-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3336-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3337+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3338+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3339
3340 #include "csumpartialcopygeneric.S"
3341
3342diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3343index 5306de3..aed6d03 100644
3344--- a/arch/arm/lib/delay.c
3345+++ b/arch/arm/lib/delay.c
3346@@ -28,7 +28,7 @@
3347 /*
3348 * Default to the loop-based delay implementation.
3349 */
3350-struct arm_delay_ops arm_delay_ops = {
3351+struct arm_delay_ops arm_delay_ops __read_only = {
3352 .delay = __loop_delay,
3353 .const_udelay = __loop_const_udelay,
3354 .udelay = __loop_udelay,
3355diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3356index 025f742..8432b08 100644
3357--- a/arch/arm/lib/uaccess_with_memcpy.c
3358+++ b/arch/arm/lib/uaccess_with_memcpy.c
3359@@ -104,7 +104,7 @@ out:
3360 }
3361
3362 unsigned long
3363-__copy_to_user(void __user *to, const void *from, unsigned long n)
3364+___copy_to_user(void __user *to, const void *from, unsigned long n)
3365 {
3366 /*
3367 * This test is stubbed out of the main function above to keep
3368diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3369index e9238b5..6ed904a 100644
3370--- a/arch/arm/mach-kirkwood/common.c
3371+++ b/arch/arm/mach-kirkwood/common.c
3372@@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3373 clk_gate_ops.disable(hw);
3374 }
3375
3376-static struct clk_ops clk_gate_fn_ops;
3377+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3378+{
3379+ return clk_gate_ops.is_enabled(hw);
3380+}
3381+
3382+static struct clk_ops clk_gate_fn_ops = {
3383+ .enable = clk_gate_fn_enable,
3384+ .disable = clk_gate_fn_disable,
3385+ .is_enabled = clk_gate_fn_is_enabled,
3386+};
3387
3388 static struct clk __init *clk_register_gate_fn(struct device *dev,
3389 const char *name,
3390@@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3391 gate_fn->fn_en = fn_en;
3392 gate_fn->fn_dis = fn_dis;
3393
3394- /* ops is the gate ops, but with our enable/disable functions */
3395- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3396- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3397- clk_gate_fn_ops = clk_gate_ops;
3398- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3399- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3400- }
3401-
3402 clk = clk_register(dev, &gate_fn->gate.hw);
3403
3404 if (IS_ERR(clk))
3405diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3406index 827d1500..2885dc6 100644
3407--- a/arch/arm/mach-omap2/board-n8x0.c
3408+++ b/arch/arm/mach-omap2/board-n8x0.c
3409@@ -627,7 +627,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3410 }
3411 #endif
3412
3413-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3414+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3415 .late_init = n8x0_menelaus_late_init,
3416 };
3417
3418diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3419index f3fdd6a..3564800 100644
3420--- a/arch/arm/mach-omap2/gpmc.c
3421+++ b/arch/arm/mach-omap2/gpmc.c
3422@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3423 };
3424
3425 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3426-static struct irq_chip gpmc_irq_chip;
3427 static unsigned gpmc_irq_start;
3428
3429 static struct resource gpmc_mem_root;
3430@@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3431
3432 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3433
3434+static struct irq_chip gpmc_irq_chip = {
3435+ .name = "gpmc",
3436+ .irq_startup = gpmc_irq_noop_ret,
3437+ .irq_enable = gpmc_irq_enable,
3438+ .irq_disable = gpmc_irq_disable,
3439+ .irq_shutdown = gpmc_irq_noop,
3440+ .irq_ack = gpmc_irq_noop,
3441+ .irq_mask = gpmc_irq_noop,
3442+ .irq_unmask = gpmc_irq_noop,
3443+
3444+};
3445+
3446 static int gpmc_setup_irq(void)
3447 {
3448 int i;
3449@@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3450 return gpmc_irq_start;
3451 }
3452
3453- gpmc_irq_chip.name = "gpmc";
3454- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3455- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3456- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3457- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3458- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3459- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3460- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3461-
3462 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3463 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3464
3465diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3466index 813c615..ce467c6 100644
3467--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3468+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3469@@ -339,7 +339,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3470 return NOTIFY_OK;
3471 }
3472
3473-static struct notifier_block __refdata irq_hotplug_notifier = {
3474+static struct notifier_block irq_hotplug_notifier = {
3475 .notifier_call = irq_cpu_hotplug_notify,
3476 };
3477
3478diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3479index f99f68e..e573e20 100644
3480--- a/arch/arm/mach-omap2/omap_device.c
3481+++ b/arch/arm/mach-omap2/omap_device.c
3482@@ -504,7 +504,7 @@ void omap_device_delete(struct omap_device *od)
3483 struct platform_device __init *omap_device_build(const char *pdev_name,
3484 int pdev_id,
3485 struct omap_hwmod *oh,
3486- void *pdata, int pdata_len)
3487+ const void *pdata, int pdata_len)
3488 {
3489 struct omap_hwmod *ohs[] = { oh };
3490
3491@@ -532,7 +532,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3492 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3493 int pdev_id,
3494 struct omap_hwmod **ohs,
3495- int oh_cnt, void *pdata,
3496+ int oh_cnt, const void *pdata,
3497 int pdata_len)
3498 {
3499 int ret = -ENOMEM;
3500diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3501index 17ca1ae..beba869 100644
3502--- a/arch/arm/mach-omap2/omap_device.h
3503+++ b/arch/arm/mach-omap2/omap_device.h
3504@@ -71,12 +71,12 @@ int omap_device_idle(struct platform_device *pdev);
3505 /* Core code interface */
3506
3507 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3508- struct omap_hwmod *oh, void *pdata,
3509+ struct omap_hwmod *oh, const void *pdata,
3510 int pdata_len);
3511
3512 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3513 struct omap_hwmod **oh, int oh_cnt,
3514- void *pdata, int pdata_len);
3515+ const void *pdata, int pdata_len);
3516
3517 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3518 struct omap_hwmod **ohs, int oh_cnt);
3519diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3520index 7f4db12..0243012 100644
3521--- a/arch/arm/mach-omap2/omap_hwmod.c
3522+++ b/arch/arm/mach-omap2/omap_hwmod.c
3523@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3524 int (*init_clkdm)(struct omap_hwmod *oh);
3525 void (*update_context_lost)(struct omap_hwmod *oh);
3526 int (*get_context_lost)(struct omap_hwmod *oh);
3527-};
3528+} __no_const;
3529
3530 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3531-static struct omap_hwmod_soc_ops soc_ops;
3532+static struct omap_hwmod_soc_ops soc_ops __read_only;
3533
3534 /* omap_hwmod_list contains all registered struct omap_hwmods */
3535 static LIST_HEAD(omap_hwmod_list);
3536diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3537index d15c7bb..b2d1f0c 100644
3538--- a/arch/arm/mach-omap2/wd_timer.c
3539+++ b/arch/arm/mach-omap2/wd_timer.c
3540@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3541 struct omap_hwmod *oh;
3542 char *oh_name = "wd_timer2";
3543 char *dev_name = "omap_wdt";
3544- struct omap_wd_timer_platform_data pdata;
3545+ static struct omap_wd_timer_platform_data pdata = {
3546+ .read_reset_sources = prm_read_reset_sources
3547+ };
3548
3549 if (!cpu_class_is_omap2() || of_have_populated_dt())
3550 return 0;
3551@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3552 return -EINVAL;
3553 }
3554
3555- pdata.read_reset_sources = prm_read_reset_sources;
3556-
3557 pdev = omap_device_build(dev_name, id, oh, &pdata,
3558 sizeof(struct omap_wd_timer_platform_data));
3559 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3560diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3561index 706aa42..f85e9131 100644
3562--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3563+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3564@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3565 bool entered_lp2 = false;
3566
3567 if (tegra_pending_sgi())
3568- ACCESS_ONCE(abort_flag) = true;
3569+ ACCESS_ONCE_RW(abort_flag) = true;
3570
3571 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3572
3573diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3574index cad3ca86..1d79e0f 100644
3575--- a/arch/arm/mach-ux500/setup.h
3576+++ b/arch/arm/mach-ux500/setup.h
3577@@ -37,13 +37,6 @@ extern void ux500_timer_init(void);
3578 .type = MT_DEVICE, \
3579 }
3580
3581-#define __MEM_DEV_DESC(x, sz) { \
3582- .virtual = IO_ADDRESS(x), \
3583- .pfn = __phys_to_pfn(x), \
3584- .length = sz, \
3585- .type = MT_MEMORY, \
3586-}
3587-
3588 extern struct smp_operations ux500_smp_ops;
3589 extern void ux500_cpu_die(unsigned int cpu);
3590
3591diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3592index cd2c88e..7430282 100644
3593--- a/arch/arm/mm/Kconfig
3594+++ b/arch/arm/mm/Kconfig
3595@@ -446,7 +446,7 @@ config CPU_32v5
3596
3597 config CPU_32v6
3598 bool
3599- select CPU_USE_DOMAINS if CPU_V6 && MMU
3600+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3601 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3602
3603 config CPU_32v6K
3604@@ -601,6 +601,7 @@ config CPU_CP15_MPU
3605
3606 config CPU_USE_DOMAINS
3607 bool
3608+ depends on !ARM_LPAE && !PAX_KERNEXEC
3609 help
3610 This option enables or disables the use of domain switching
3611 via the set_fs() function.
3612@@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3613 config KUSER_HELPERS
3614 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3615 default y
3616+ depends on !(CPU_V6 || CPU_V6K || CPU_V7)
3617 help
3618 Warning: disabling this option may break user programs.
3619
3620@@ -812,7 +814,7 @@ config KUSER_HELPERS
3621 See Documentation/arm/kernel_user_helpers.txt for details.
3622
3623 However, the fixed address nature of these helpers can be used
3624- by ROP (return orientated programming) authors when creating
3625+ by ROP (Return Oriented Programming) authors when creating
3626 exploits.
3627
3628 If all of the binaries and libraries which run on your platform
3629diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3630index 6f4585b..7b6f52b 100644
3631--- a/arch/arm/mm/alignment.c
3632+++ b/arch/arm/mm/alignment.c
3633@@ -211,10 +211,12 @@ union offset_union {
3634 #define __get16_unaligned_check(ins,val,addr) \
3635 do { \
3636 unsigned int err = 0, v, a = addr; \
3637+ pax_open_userland(); \
3638 __get8_unaligned_check(ins,v,a,err); \
3639 val = v << ((BE) ? 8 : 0); \
3640 __get8_unaligned_check(ins,v,a,err); \
3641 val |= v << ((BE) ? 0 : 8); \
3642+ pax_close_userland(); \
3643 if (err) \
3644 goto fault; \
3645 } while (0)
3646@@ -228,6 +230,7 @@ union offset_union {
3647 #define __get32_unaligned_check(ins,val,addr) \
3648 do { \
3649 unsigned int err = 0, v, a = addr; \
3650+ pax_open_userland(); \
3651 __get8_unaligned_check(ins,v,a,err); \
3652 val = v << ((BE) ? 24 : 0); \
3653 __get8_unaligned_check(ins,v,a,err); \
3654@@ -236,6 +239,7 @@ union offset_union {
3655 val |= v << ((BE) ? 8 : 16); \
3656 __get8_unaligned_check(ins,v,a,err); \
3657 val |= v << ((BE) ? 0 : 24); \
3658+ pax_close_userland(); \
3659 if (err) \
3660 goto fault; \
3661 } while (0)
3662@@ -249,6 +253,7 @@ union offset_union {
3663 #define __put16_unaligned_check(ins,val,addr) \
3664 do { \
3665 unsigned int err = 0, v = val, a = addr; \
3666+ pax_open_userland(); \
3667 __asm__( FIRST_BYTE_16 \
3668 ARM( "1: "ins" %1, [%2], #1\n" ) \
3669 THUMB( "1: "ins" %1, [%2]\n" ) \
3670@@ -268,6 +273,7 @@ union offset_union {
3671 " .popsection\n" \
3672 : "=r" (err), "=&r" (v), "=&r" (a) \
3673 : "0" (err), "1" (v), "2" (a)); \
3674+ pax_close_userland(); \
3675 if (err) \
3676 goto fault; \
3677 } while (0)
3678@@ -281,6 +287,7 @@ union offset_union {
3679 #define __put32_unaligned_check(ins,val,addr) \
3680 do { \
3681 unsigned int err = 0, v = val, a = addr; \
3682+ pax_open_userland(); \
3683 __asm__( FIRST_BYTE_32 \
3684 ARM( "1: "ins" %1, [%2], #1\n" ) \
3685 THUMB( "1: "ins" %1, [%2]\n" ) \
3686@@ -310,6 +317,7 @@ union offset_union {
3687 " .popsection\n" \
3688 : "=r" (err), "=&r" (v), "=&r" (a) \
3689 : "0" (err), "1" (v), "2" (a)); \
3690+ pax_close_userland(); \
3691 if (err) \
3692 goto fault; \
3693 } while (0)
3694diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3695index 4a05444..d21968c 100644
3696--- a/arch/arm/mm/context.c
3697+++ b/arch/arm/mm/context.c
3698@@ -43,7 +43,7 @@
3699 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3700
3701 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3702-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3703+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3704 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3705
3706 static DEFINE_PER_CPU(atomic64_t, active_asids);
3707@@ -183,7 +183,7 @@ static int is_reserved_asid(u64 asid)
3708 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3709 {
3710 u64 asid = atomic64_read(&mm->context.id);
3711- u64 generation = atomic64_read(&asid_generation);
3712+ u64 generation = atomic64_read_unchecked(&asid_generation);
3713
3714 if (asid != 0 && is_reserved_asid(asid)) {
3715 /*
3716@@ -201,7 +201,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3717 */
3718 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3719 if (asid == NUM_USER_ASIDS) {
3720- generation = atomic64_add_return(ASID_FIRST_VERSION,
3721+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3722 &asid_generation);
3723 flush_context(cpu);
3724 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3725@@ -230,14 +230,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3726 cpu_set_reserved_ttbr0();
3727
3728 asid = atomic64_read(&mm->context.id);
3729- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3730+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3731 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3732 goto switch_mm_fastpath;
3733
3734 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3735 /* Check that our ASID belongs to the current generation. */
3736 asid = atomic64_read(&mm->context.id);
3737- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3738+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3739 asid = new_context(mm, cpu);
3740 atomic64_set(&mm->context.id, asid);
3741 }
3742diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3743index c97f794..e5aeea5 100644
3744--- a/arch/arm/mm/fault.c
3745+++ b/arch/arm/mm/fault.c
3746@@ -25,6 +25,7 @@
3747 #include <asm/system_misc.h>
3748 #include <asm/system_info.h>
3749 #include <asm/tlbflush.h>
3750+#include <asm/sections.h>
3751
3752 #include "fault.h"
3753
3754@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3755 if (fixup_exception(regs))
3756 return;
3757
3758+#ifdef CONFIG_PAX_KERNEXEC
3759+ if ((fsr & FSR_WRITE) &&
3760+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3761+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3762+ {
3763+ if (current->signal->curr_ip)
3764+ 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),
3765+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3766+ else
3767+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3768+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3769+ }
3770+#endif
3771+
3772 /*
3773 * No handler, we'll have to terminate things with extreme prejudice.
3774 */
3775@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3776 }
3777 #endif
3778
3779+#ifdef CONFIG_PAX_PAGEEXEC
3780+ if (fsr & FSR_LNX_PF) {
3781+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3782+ do_group_exit(SIGKILL);
3783+ }
3784+#endif
3785+
3786 tsk->thread.address = addr;
3787 tsk->thread.error_code = fsr;
3788 tsk->thread.trap_no = 14;
3789@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3790 }
3791 #endif /* CONFIG_MMU */
3792
3793+#ifdef CONFIG_PAX_PAGEEXEC
3794+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3795+{
3796+ long i;
3797+
3798+ printk(KERN_ERR "PAX: bytes at PC: ");
3799+ for (i = 0; i < 20; i++) {
3800+ unsigned char c;
3801+ if (get_user(c, (__force unsigned char __user *)pc+i))
3802+ printk(KERN_CONT "?? ");
3803+ else
3804+ printk(KERN_CONT "%02x ", c);
3805+ }
3806+ printk("\n");
3807+
3808+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3809+ for (i = -1; i < 20; i++) {
3810+ unsigned long c;
3811+ if (get_user(c, (__force unsigned long __user *)sp+i))
3812+ printk(KERN_CONT "???????? ");
3813+ else
3814+ printk(KERN_CONT "%08lx ", c);
3815+ }
3816+ printk("\n");
3817+}
3818+#endif
3819+
3820 /*
3821 * First Level Translation Fault Handler
3822 *
3823@@ -545,9 +594,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3824 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3825 struct siginfo info;
3826
3827+#ifdef CONFIG_PAX_MEMORY_UDEREF
3828+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3829+ if (current->signal->curr_ip)
3830+ 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),
3831+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3832+ else
3833+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3834+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3835+ goto die;
3836+ }
3837+#endif
3838+
3839 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3840 return;
3841
3842+die:
3843 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3844 inf->name, fsr, addr);
3845
3846@@ -571,15 +633,68 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3847 ifsr_info[nr].name = name;
3848 }
3849
3850+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3851+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3852+
3853 asmlinkage void __exception
3854 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3855 {
3856 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3857 struct siginfo info;
3858+ unsigned long pc = instruction_pointer(regs);
3859+
3860+ if (user_mode(regs)) {
3861+ unsigned long sigpage = current->mm->context.sigpage;
3862+
3863+ if (sigpage <= pc && pc < sigpage + 7*4) {
3864+ if (pc < sigpage + 3*4)
3865+ sys_sigreturn(regs);
3866+ else
3867+ sys_rt_sigreturn(regs);
3868+ return;
3869+ }
3870+ if (pc == 0xffff0fe0UL) {
3871+ /*
3872+ * PaX: __kuser_get_tls emulation
3873+ */
3874+ regs->ARM_r0 = current_thread_info()->tp_value;
3875+ regs->ARM_pc = regs->ARM_lr;
3876+ return;
3877+ }
3878+ }
3879+
3880+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3881+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3882+ if (current->signal->curr_ip)
3883+ 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),
3884+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3885+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3886+ else
3887+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3888+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3889+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3890+ goto die;
3891+ }
3892+#endif
3893+
3894+#ifdef CONFIG_PAX_REFCOUNT
3895+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3896+ unsigned int bkpt;
3897+
3898+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
3899+ current->thread.error_code = ifsr;
3900+ current->thread.trap_no = 0;
3901+ pax_report_refcount_overflow(regs);
3902+ fixup_exception(regs);
3903+ return;
3904+ }
3905+ }
3906+#endif
3907
3908 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3909 return;
3910
3911+die:
3912 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3913 inf->name, ifsr, addr);
3914
3915diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3916index cf08bdf..772656c 100644
3917--- a/arch/arm/mm/fault.h
3918+++ b/arch/arm/mm/fault.h
3919@@ -3,6 +3,7 @@
3920
3921 /*
3922 * Fault status register encodings. We steal bit 31 for our own purposes.
3923+ * Set when the FSR value is from an instruction fault.
3924 */
3925 #define FSR_LNX_PF (1 << 31)
3926 #define FSR_WRITE (1 << 11)
3927@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3928 }
3929 #endif
3930
3931+/* valid for LPAE and !LPAE */
3932+static inline int is_xn_fault(unsigned int fsr)
3933+{
3934+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
3935+}
3936+
3937+static inline int is_domain_fault(unsigned int fsr)
3938+{
3939+ return ((fsr_fs(fsr) & 0xD) == 0x9);
3940+}
3941+
3942 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3943 unsigned long search_exception_table(unsigned long addr);
3944
3945diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3946index 15225d8..25e2e3c 100644
3947--- a/arch/arm/mm/init.c
3948+++ b/arch/arm/mm/init.c
3949@@ -30,6 +30,8 @@
3950 #include <asm/setup.h>
3951 #include <asm/tlb.h>
3952 #include <asm/fixmap.h>
3953+#include <asm/system_info.h>
3954+#include <asm/cp15.h>
3955
3956 #include <asm/mach/arch.h>
3957 #include <asm/mach/map.h>
3958@@ -683,7 +685,46 @@ void free_initmem(void)
3959 {
3960 #ifdef CONFIG_HAVE_TCM
3961 extern char __tcm_start, __tcm_end;
3962+#endif
3963
3964+#ifdef CONFIG_PAX_KERNEXEC
3965+ unsigned long addr;
3966+ pgd_t *pgd;
3967+ pud_t *pud;
3968+ pmd_t *pmd;
3969+ int cpu_arch = cpu_architecture();
3970+ unsigned int cr = get_cr();
3971+
3972+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
3973+ /* make pages tables, etc before .text NX */
3974+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
3975+ pgd = pgd_offset_k(addr);
3976+ pud = pud_offset(pgd, addr);
3977+ pmd = pmd_offset(pud, addr);
3978+ __section_update(pmd, addr, PMD_SECT_XN);
3979+ }
3980+ /* make init NX */
3981+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
3982+ pgd = pgd_offset_k(addr);
3983+ pud = pud_offset(pgd, addr);
3984+ pmd = pmd_offset(pud, addr);
3985+ __section_update(pmd, addr, PMD_SECT_XN);
3986+ }
3987+ /* make kernel code/rodata RX */
3988+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
3989+ pgd = pgd_offset_k(addr);
3990+ pud = pud_offset(pgd, addr);
3991+ pmd = pmd_offset(pud, addr);
3992+#ifdef CONFIG_ARM_LPAE
3993+ __section_update(pmd, addr, PMD_SECT_RDONLY);
3994+#else
3995+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
3996+#endif
3997+ }
3998+ }
3999+#endif
4000+
4001+#ifdef CONFIG_HAVE_TCM
4002 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4003 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4004 #endif
4005diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4006index f123d6e..04bf569 100644
4007--- a/arch/arm/mm/ioremap.c
4008+++ b/arch/arm/mm/ioremap.c
4009@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4010 unsigned int mtype;
4011
4012 if (cached)
4013- mtype = MT_MEMORY;
4014+ mtype = MT_MEMORY_RX;
4015 else
4016- mtype = MT_MEMORY_NONCACHED;
4017+ mtype = MT_MEMORY_NONCACHED_RX;
4018
4019 return __arm_ioremap_caller(phys_addr, size, mtype,
4020 __builtin_return_address(0));
4021diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4022index 0c63562..7128a90 100644
4023--- a/arch/arm/mm/mmap.c
4024+++ b/arch/arm/mm/mmap.c
4025@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4026 struct vm_area_struct *vma;
4027 int do_align = 0;
4028 int aliasing = cache_is_vipt_aliasing();
4029+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4030 struct vm_unmapped_area_info info;
4031
4032 /*
4033@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4034 if (len > TASK_SIZE)
4035 return -ENOMEM;
4036
4037+#ifdef CONFIG_PAX_RANDMMAP
4038+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4039+#endif
4040+
4041 if (addr) {
4042 if (do_align)
4043 addr = COLOUR_ALIGN(addr, pgoff);
4044@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4045 addr = PAGE_ALIGN(addr);
4046
4047 vma = find_vma(mm, addr);
4048- if (TASK_SIZE - len >= addr &&
4049- (!vma || addr + len <= vma->vm_start))
4050+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4051 return addr;
4052 }
4053
4054@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4055 info.high_limit = TASK_SIZE;
4056 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4057 info.align_offset = pgoff << PAGE_SHIFT;
4058+ info.threadstack_offset = offset;
4059 return vm_unmapped_area(&info);
4060 }
4061
4062@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4063 unsigned long addr = addr0;
4064 int do_align = 0;
4065 int aliasing = cache_is_vipt_aliasing();
4066+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4067 struct vm_unmapped_area_info info;
4068
4069 /*
4070@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4071 return addr;
4072 }
4073
4074+#ifdef CONFIG_PAX_RANDMMAP
4075+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4076+#endif
4077+
4078 /* requesting a specific address */
4079 if (addr) {
4080 if (do_align)
4081@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4082 else
4083 addr = PAGE_ALIGN(addr);
4084 vma = find_vma(mm, addr);
4085- if (TASK_SIZE - len >= addr &&
4086- (!vma || addr + len <= vma->vm_start))
4087+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4088 return addr;
4089 }
4090
4091@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4092 info.high_limit = mm->mmap_base;
4093 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4094 info.align_offset = pgoff << PAGE_SHIFT;
4095+ info.threadstack_offset = offset;
4096 addr = vm_unmapped_area(&info);
4097
4098 /*
4099@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4100 {
4101 unsigned long random_factor = 0UL;
4102
4103+#ifdef CONFIG_PAX_RANDMMAP
4104+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4105+#endif
4106+
4107 /* 8 bits of randomness in 20 address space bits */
4108 if ((current->flags & PF_RANDOMIZE) &&
4109 !(current->personality & ADDR_NO_RANDOMIZE))
4110@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4111
4112 if (mmap_is_legacy()) {
4113 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4114+
4115+#ifdef CONFIG_PAX_RANDMMAP
4116+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4117+ mm->mmap_base += mm->delta_mmap;
4118+#endif
4119+
4120 mm->get_unmapped_area = arch_get_unmapped_area;
4121 } else {
4122 mm->mmap_base = mmap_base(random_factor);
4123+
4124+#ifdef CONFIG_PAX_RANDMMAP
4125+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4126+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4127+#endif
4128+
4129 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4130 }
4131 }
4132diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4133index 53cdbd3..670f177 100644
4134--- a/arch/arm/mm/mmu.c
4135+++ b/arch/arm/mm/mmu.c
4136@@ -36,6 +36,22 @@
4137 #include "mm.h"
4138 #include "tcm.h"
4139
4140+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4141+void modify_domain(unsigned int dom, unsigned int type)
4142+{
4143+ struct thread_info *thread = current_thread_info();
4144+ unsigned int domain = thread->cpu_domain;
4145+ /*
4146+ * DOMAIN_MANAGER might be defined to some other value,
4147+ * use the arch-defined constant
4148+ */
4149+ domain &= ~domain_val(dom, 3);
4150+ thread->cpu_domain = domain | domain_val(dom, type);
4151+ set_domain(thread->cpu_domain);
4152+}
4153+EXPORT_SYMBOL(modify_domain);
4154+#endif
4155+
4156 /*
4157 * empty_zero_page is a special page that is used for
4158 * zero-initialized data and COW.
4159@@ -228,10 +244,18 @@ __setup("noalign", noalign_setup);
4160
4161 #endif /* ifdef CONFIG_CPU_CP15 / else */
4162
4163-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4164+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4165 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4166
4167-static struct mem_type mem_types[] = {
4168+#ifdef CONFIG_PAX_KERNEXEC
4169+#define L_PTE_KERNEXEC L_PTE_RDONLY
4170+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4171+#else
4172+#define L_PTE_KERNEXEC L_PTE_DIRTY
4173+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4174+#endif
4175+
4176+static struct mem_type mem_types[] __read_only = {
4177 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4178 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4179 L_PTE_SHARED,
4180@@ -260,16 +284,16 @@ static struct mem_type mem_types[] = {
4181 [MT_UNCACHED] = {
4182 .prot_pte = PROT_PTE_DEVICE,
4183 .prot_l1 = PMD_TYPE_TABLE,
4184- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4185+ .prot_sect = PROT_SECT_DEVICE,
4186 .domain = DOMAIN_IO,
4187 },
4188 [MT_CACHECLEAN] = {
4189- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4190+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4191 .domain = DOMAIN_KERNEL,
4192 },
4193 #ifndef CONFIG_ARM_LPAE
4194 [MT_MINICLEAN] = {
4195- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4196+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4197 .domain = DOMAIN_KERNEL,
4198 },
4199 #endif
4200@@ -277,36 +301,54 @@ static struct mem_type mem_types[] = {
4201 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4202 L_PTE_RDONLY,
4203 .prot_l1 = PMD_TYPE_TABLE,
4204- .domain = DOMAIN_USER,
4205+ .domain = DOMAIN_VECTORS,
4206 },
4207 [MT_HIGH_VECTORS] = {
4208 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4209 L_PTE_USER | L_PTE_RDONLY,
4210 .prot_l1 = PMD_TYPE_TABLE,
4211- .domain = DOMAIN_USER,
4212+ .domain = DOMAIN_VECTORS,
4213 },
4214- [MT_MEMORY] = {
4215+ [MT_MEMORY_RWX] = {
4216 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4217 .prot_l1 = PMD_TYPE_TABLE,
4218 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4219 .domain = DOMAIN_KERNEL,
4220 },
4221+ [MT_MEMORY_RW] = {
4222+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4223+ .prot_l1 = PMD_TYPE_TABLE,
4224+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4225+ .domain = DOMAIN_KERNEL,
4226+ },
4227+ [MT_MEMORY_RX] = {
4228+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4229+ .prot_l1 = PMD_TYPE_TABLE,
4230+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4231+ .domain = DOMAIN_KERNEL,
4232+ },
4233 [MT_ROM] = {
4234- .prot_sect = PMD_TYPE_SECT,
4235+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4236 .domain = DOMAIN_KERNEL,
4237 },
4238- [MT_MEMORY_NONCACHED] = {
4239+ [MT_MEMORY_NONCACHED_RW] = {
4240 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4241 L_PTE_MT_BUFFERABLE,
4242 .prot_l1 = PMD_TYPE_TABLE,
4243 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4244 .domain = DOMAIN_KERNEL,
4245 },
4246+ [MT_MEMORY_NONCACHED_RX] = {
4247+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4248+ L_PTE_MT_BUFFERABLE,
4249+ .prot_l1 = PMD_TYPE_TABLE,
4250+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4251+ .domain = DOMAIN_KERNEL,
4252+ },
4253 [MT_MEMORY_DTCM] = {
4254- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4255- L_PTE_XN,
4256+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4257 .prot_l1 = PMD_TYPE_TABLE,
4258- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4259+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4260 .domain = DOMAIN_KERNEL,
4261 },
4262 [MT_MEMORY_ITCM] = {
4263@@ -316,10 +358,10 @@ static struct mem_type mem_types[] = {
4264 },
4265 [MT_MEMORY_SO] = {
4266 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4267- L_PTE_MT_UNCACHED | L_PTE_XN,
4268+ L_PTE_MT_UNCACHED,
4269 .prot_l1 = PMD_TYPE_TABLE,
4270 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4271- PMD_SECT_UNCACHED | PMD_SECT_XN,
4272+ PMD_SECT_UNCACHED,
4273 .domain = DOMAIN_KERNEL,
4274 },
4275 [MT_MEMORY_DMA_READY] = {
4276@@ -405,9 +447,35 @@ static void __init build_mem_type_table(void)
4277 * to prevent speculative instruction fetches.
4278 */
4279 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4280+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4281 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4282+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4283 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4284+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4285 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4286+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4287+
4288+ /* Mark other regions on ARMv6+ as execute-never */
4289+
4290+#ifdef CONFIG_PAX_KERNEXEC
4291+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4292+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4293+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4294+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4295+#ifndef CONFIG_ARM_LPAE
4296+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4297+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4298+#endif
4299+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4300+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4301+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4302+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4303+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4304+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4305+#endif
4306+
4307+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4308+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4309 }
4310 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4311 /*
4312@@ -468,6 +536,9 @@ static void __init build_mem_type_table(void)
4313 * from SVC mode and no access from userspace.
4314 */
4315 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4316+#ifdef CONFIG_PAX_KERNEXEC
4317+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4318+#endif
4319 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4320 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4321 #endif
4322@@ -485,11 +556,17 @@ static void __init build_mem_type_table(void)
4323 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4324 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4325 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4326- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4327- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4328+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4329+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4330+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4331+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4332+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4333+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4334 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4335- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4336- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4337+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4338+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4339+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4340+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4341 }
4342 }
4343
4344@@ -500,15 +577,20 @@ static void __init build_mem_type_table(void)
4345 if (cpu_arch >= CPU_ARCH_ARMv6) {
4346 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4347 /* Non-cacheable Normal is XCB = 001 */
4348- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4349+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4350+ PMD_SECT_BUFFERED;
4351+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4352 PMD_SECT_BUFFERED;
4353 } else {
4354 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4355- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4356+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4357+ PMD_SECT_TEX(1);
4358+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4359 PMD_SECT_TEX(1);
4360 }
4361 } else {
4362- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4363+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4364+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4365 }
4366
4367 #ifdef CONFIG_ARM_LPAE
4368@@ -524,6 +606,8 @@ static void __init build_mem_type_table(void)
4369 vecs_pgprot |= PTE_EXT_AF;
4370 #endif
4371
4372+ user_pgprot |= __supported_pte_mask;
4373+
4374 for (i = 0; i < 16; i++) {
4375 pteval_t v = pgprot_val(protection_map[i]);
4376 protection_map[i] = __pgprot(v | user_pgprot);
4377@@ -541,10 +625,15 @@ static void __init build_mem_type_table(void)
4378
4379 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4380 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4381- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4382- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4383+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4384+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4385+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4386+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4387+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4388+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4389 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4390- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4391+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4392+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4393 mem_types[MT_ROM].prot_sect |= cp->pmd;
4394
4395 switch (cp->pmd) {
4396@@ -1186,18 +1275,15 @@ void __init arm_mm_memblock_reserve(void)
4397 * called function. This means you can't use any function or debugging
4398 * method which may touch any device, otherwise the kernel _will_ crash.
4399 */
4400+
4401+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4402+
4403 static void __init devicemaps_init(struct machine_desc *mdesc)
4404 {
4405 struct map_desc map;
4406 unsigned long addr;
4407- void *vectors;
4408
4409- /*
4410- * Allocate the vector page early.
4411- */
4412- vectors = early_alloc(PAGE_SIZE * 2);
4413-
4414- early_trap_init(vectors);
4415+ early_trap_init(&vectors);
4416
4417 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4418 pmd_clear(pmd_off_k(addr));
4419@@ -1237,7 +1323,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4420 * location (0xffff0000). If we aren't using high-vectors, also
4421 * create a mapping at the low-vectors virtual address.
4422 */
4423- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4424+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4425 map.virtual = 0xffff0000;
4426 map.length = PAGE_SIZE;
4427 #ifdef CONFIG_KUSER_HELPERS
4428@@ -1309,8 +1395,39 @@ static void __init map_lowmem(void)
4429 map.pfn = __phys_to_pfn(start);
4430 map.virtual = __phys_to_virt(start);
4431 map.length = end - start;
4432- map.type = MT_MEMORY;
4433
4434+#ifdef CONFIG_PAX_KERNEXEC
4435+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4436+ struct map_desc kernel;
4437+ struct map_desc initmap;
4438+
4439+ /* when freeing initmem we will make this RW */
4440+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4441+ initmap.virtual = (unsigned long)__init_begin;
4442+ initmap.length = _sdata - __init_begin;
4443+ initmap.type = MT_MEMORY_RWX;
4444+ create_mapping(&initmap);
4445+
4446+ /* when freeing initmem we will make this RX */
4447+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4448+ kernel.virtual = (unsigned long)_stext;
4449+ kernel.length = __init_begin - _stext;
4450+ kernel.type = MT_MEMORY_RWX;
4451+ create_mapping(&kernel);
4452+
4453+ if (map.virtual < (unsigned long)_stext) {
4454+ map.length = (unsigned long)_stext - map.virtual;
4455+ map.type = MT_MEMORY_RWX;
4456+ create_mapping(&map);
4457+ }
4458+
4459+ map.pfn = __phys_to_pfn(__pa(_sdata));
4460+ map.virtual = (unsigned long)_sdata;
4461+ map.length = end - __pa(_sdata);
4462+ }
4463+#endif
4464+
4465+ map.type = MT_MEMORY_RW;
4466 create_mapping(&map);
4467 }
4468 }
4469diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4470index a5bc92d..0bb4730 100644
4471--- a/arch/arm/plat-omap/sram.c
4472+++ b/arch/arm/plat-omap/sram.c
4473@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4474 * Looks like we need to preserve some bootloader code at the
4475 * beginning of SRAM for jumping to flash for reboot to work...
4476 */
4477+ pax_open_kernel();
4478 memset_io(omap_sram_base + omap_sram_skip, 0,
4479 omap_sram_size - omap_sram_skip);
4480+ pax_close_kernel();
4481 }
4482diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4483index ce6d763..cfea917 100644
4484--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4485+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4486@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4487 int (*started)(unsigned ch);
4488 int (*flush)(unsigned ch);
4489 int (*stop)(unsigned ch);
4490-};
4491+} __no_const;
4492
4493 extern void *samsung_dmadev_get_ops(void);
4494 extern void *s3c_dma_get_ops(void);
4495diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4496index c3a58a1..78fbf54 100644
4497--- a/arch/avr32/include/asm/cache.h
4498+++ b/arch/avr32/include/asm/cache.h
4499@@ -1,8 +1,10 @@
4500 #ifndef __ASM_AVR32_CACHE_H
4501 #define __ASM_AVR32_CACHE_H
4502
4503+#include <linux/const.h>
4504+
4505 #define L1_CACHE_SHIFT 5
4506-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4507+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4508
4509 /*
4510 * Memory returned by kmalloc() may be used for DMA, so we must make
4511diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4512index d232888..87c8df1 100644
4513--- a/arch/avr32/include/asm/elf.h
4514+++ b/arch/avr32/include/asm/elf.h
4515@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4516 the loader. We need to make sure that it is out of the way of the program
4517 that it will "exec", and that there is sufficient room for the brk. */
4518
4519-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4520+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4521
4522+#ifdef CONFIG_PAX_ASLR
4523+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4524+
4525+#define PAX_DELTA_MMAP_LEN 15
4526+#define PAX_DELTA_STACK_LEN 15
4527+#endif
4528
4529 /* This yields a mask that user programs can use to figure out what
4530 instruction set this CPU supports. This could be done in user space,
4531diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4532index 479330b..53717a8 100644
4533--- a/arch/avr32/include/asm/kmap_types.h
4534+++ b/arch/avr32/include/asm/kmap_types.h
4535@@ -2,9 +2,9 @@
4536 #define __ASM_AVR32_KMAP_TYPES_H
4537
4538 #ifdef CONFIG_DEBUG_HIGHMEM
4539-# define KM_TYPE_NR 29
4540+# define KM_TYPE_NR 30
4541 #else
4542-# define KM_TYPE_NR 14
4543+# define KM_TYPE_NR 15
4544 #endif
4545
4546 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4547diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4548index b2f2d2d..d1c85cb 100644
4549--- a/arch/avr32/mm/fault.c
4550+++ b/arch/avr32/mm/fault.c
4551@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4552
4553 int exception_trace = 1;
4554
4555+#ifdef CONFIG_PAX_PAGEEXEC
4556+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4557+{
4558+ unsigned long i;
4559+
4560+ printk(KERN_ERR "PAX: bytes at PC: ");
4561+ for (i = 0; i < 20; i++) {
4562+ unsigned char c;
4563+ if (get_user(c, (unsigned char *)pc+i))
4564+ printk(KERN_CONT "???????? ");
4565+ else
4566+ printk(KERN_CONT "%02x ", c);
4567+ }
4568+ printk("\n");
4569+}
4570+#endif
4571+
4572 /*
4573 * This routine handles page faults. It determines the address and the
4574 * problem, and then passes it off to one of the appropriate routines.
4575@@ -174,6 +191,16 @@ bad_area:
4576 up_read(&mm->mmap_sem);
4577
4578 if (user_mode(regs)) {
4579+
4580+#ifdef CONFIG_PAX_PAGEEXEC
4581+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4582+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4583+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4584+ do_group_exit(SIGKILL);
4585+ }
4586+ }
4587+#endif
4588+
4589 if (exception_trace && printk_ratelimit())
4590 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4591 "sp %08lx ecr %lu\n",
4592diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4593index 568885a..f8008df 100644
4594--- a/arch/blackfin/include/asm/cache.h
4595+++ b/arch/blackfin/include/asm/cache.h
4596@@ -7,6 +7,7 @@
4597 #ifndef __ARCH_BLACKFIN_CACHE_H
4598 #define __ARCH_BLACKFIN_CACHE_H
4599
4600+#include <linux/const.h>
4601 #include <linux/linkage.h> /* for asmlinkage */
4602
4603 /*
4604@@ -14,7 +15,7 @@
4605 * Blackfin loads 32 bytes for cache
4606 */
4607 #define L1_CACHE_SHIFT 5
4608-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4609+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4610 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4611
4612 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4613diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4614index aea2718..3639a60 100644
4615--- a/arch/cris/include/arch-v10/arch/cache.h
4616+++ b/arch/cris/include/arch-v10/arch/cache.h
4617@@ -1,8 +1,9 @@
4618 #ifndef _ASM_ARCH_CACHE_H
4619 #define _ASM_ARCH_CACHE_H
4620
4621+#include <linux/const.h>
4622 /* Etrax 100LX have 32-byte cache-lines. */
4623-#define L1_CACHE_BYTES 32
4624 #define L1_CACHE_SHIFT 5
4625+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4626
4627 #endif /* _ASM_ARCH_CACHE_H */
4628diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4629index 7caf25d..ee65ac5 100644
4630--- a/arch/cris/include/arch-v32/arch/cache.h
4631+++ b/arch/cris/include/arch-v32/arch/cache.h
4632@@ -1,11 +1,12 @@
4633 #ifndef _ASM_CRIS_ARCH_CACHE_H
4634 #define _ASM_CRIS_ARCH_CACHE_H
4635
4636+#include <linux/const.h>
4637 #include <arch/hwregs/dma.h>
4638
4639 /* A cache-line is 32 bytes. */
4640-#define L1_CACHE_BYTES 32
4641 #define L1_CACHE_SHIFT 5
4642+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4643
4644 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4645
4646diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4647index b86329d..6709906 100644
4648--- a/arch/frv/include/asm/atomic.h
4649+++ b/arch/frv/include/asm/atomic.h
4650@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4651 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4652 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4653
4654+#define atomic64_read_unchecked(v) atomic64_read(v)
4655+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4656+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4657+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4658+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4659+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4660+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4661+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4662+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4663+
4664 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4665 {
4666 int c, old;
4667diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4668index 2797163..c2a401d 100644
4669--- a/arch/frv/include/asm/cache.h
4670+++ b/arch/frv/include/asm/cache.h
4671@@ -12,10 +12,11 @@
4672 #ifndef __ASM_CACHE_H
4673 #define __ASM_CACHE_H
4674
4675+#include <linux/const.h>
4676
4677 /* bytes per L1 cache line */
4678 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4679-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4680+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4681
4682 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4683 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4684diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4685index 43901f2..0d8b865 100644
4686--- a/arch/frv/include/asm/kmap_types.h
4687+++ b/arch/frv/include/asm/kmap_types.h
4688@@ -2,6 +2,6 @@
4689 #ifndef _ASM_KMAP_TYPES_H
4690 #define _ASM_KMAP_TYPES_H
4691
4692-#define KM_TYPE_NR 17
4693+#define KM_TYPE_NR 18
4694
4695 #endif
4696diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4697index 836f147..4cf23f5 100644
4698--- a/arch/frv/mm/elf-fdpic.c
4699+++ b/arch/frv/mm/elf-fdpic.c
4700@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4701 {
4702 struct vm_area_struct *vma;
4703 struct vm_unmapped_area_info info;
4704+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4705
4706 if (len > TASK_SIZE)
4707 return -ENOMEM;
4708@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4709 if (addr) {
4710 addr = PAGE_ALIGN(addr);
4711 vma = find_vma(current->mm, addr);
4712- if (TASK_SIZE - len >= addr &&
4713- (!vma || addr + len <= vma->vm_start))
4714+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4715 goto success;
4716 }
4717
4718@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4719 info.high_limit = (current->mm->start_stack - 0x00200000);
4720 info.align_mask = 0;
4721 info.align_offset = 0;
4722+ info.threadstack_offset = offset;
4723 addr = vm_unmapped_area(&info);
4724 if (!(addr & ~PAGE_MASK))
4725 goto success;
4726diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4727index f4ca594..adc72fd6 100644
4728--- a/arch/hexagon/include/asm/cache.h
4729+++ b/arch/hexagon/include/asm/cache.h
4730@@ -21,9 +21,11 @@
4731 #ifndef __ASM_CACHE_H
4732 #define __ASM_CACHE_H
4733
4734+#include <linux/const.h>
4735+
4736 /* Bytes per L1 cache line */
4737-#define L1_CACHE_SHIFT (5)
4738-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4739+#define L1_CACHE_SHIFT 5
4740+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4741
4742 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4743 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4744diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4745index 6e6fe18..a6ae668 100644
4746--- a/arch/ia64/include/asm/atomic.h
4747+++ b/arch/ia64/include/asm/atomic.h
4748@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4749 #define atomic64_inc(v) atomic64_add(1, (v))
4750 #define atomic64_dec(v) atomic64_sub(1, (v))
4751
4752+#define atomic64_read_unchecked(v) atomic64_read(v)
4753+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4754+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4755+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4756+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4757+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4758+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4759+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4760+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4761+
4762 /* Atomic operations are already serializing */
4763 #define smp_mb__before_atomic_dec() barrier()
4764 #define smp_mb__after_atomic_dec() barrier()
4765diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4766index 988254a..e1ee885 100644
4767--- a/arch/ia64/include/asm/cache.h
4768+++ b/arch/ia64/include/asm/cache.h
4769@@ -1,6 +1,7 @@
4770 #ifndef _ASM_IA64_CACHE_H
4771 #define _ASM_IA64_CACHE_H
4772
4773+#include <linux/const.h>
4774
4775 /*
4776 * Copyright (C) 1998-2000 Hewlett-Packard Co
4777@@ -9,7 +10,7 @@
4778
4779 /* Bytes per L1 (data) cache line. */
4780 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4781-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4782+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4783
4784 #ifdef CONFIG_SMP
4785 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4786diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4787index 5a83c5c..4d7f553 100644
4788--- a/arch/ia64/include/asm/elf.h
4789+++ b/arch/ia64/include/asm/elf.h
4790@@ -42,6 +42,13 @@
4791 */
4792 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4793
4794+#ifdef CONFIG_PAX_ASLR
4795+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4796+
4797+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4798+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4799+#endif
4800+
4801 #define PT_IA_64_UNWIND 0x70000001
4802
4803 /* IA-64 relocations: */
4804diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4805index 96a8d92..617a1cf 100644
4806--- a/arch/ia64/include/asm/pgalloc.h
4807+++ b/arch/ia64/include/asm/pgalloc.h
4808@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4809 pgd_val(*pgd_entry) = __pa(pud);
4810 }
4811
4812+static inline void
4813+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4814+{
4815+ pgd_populate(mm, pgd_entry, pud);
4816+}
4817+
4818 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4819 {
4820 return quicklist_alloc(0, GFP_KERNEL, NULL);
4821@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4822 pud_val(*pud_entry) = __pa(pmd);
4823 }
4824
4825+static inline void
4826+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4827+{
4828+ pud_populate(mm, pud_entry, pmd);
4829+}
4830+
4831 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4832 {
4833 return quicklist_alloc(0, GFP_KERNEL, NULL);
4834diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4835index 7935115..c0eca6a 100644
4836--- a/arch/ia64/include/asm/pgtable.h
4837+++ b/arch/ia64/include/asm/pgtable.h
4838@@ -12,7 +12,7 @@
4839 * David Mosberger-Tang <davidm@hpl.hp.com>
4840 */
4841
4842-
4843+#include <linux/const.h>
4844 #include <asm/mman.h>
4845 #include <asm/page.h>
4846 #include <asm/processor.h>
4847@@ -142,6 +142,17 @@
4848 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4849 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4850 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4851+
4852+#ifdef CONFIG_PAX_PAGEEXEC
4853+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4854+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4855+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4856+#else
4857+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4858+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4859+# define PAGE_COPY_NOEXEC PAGE_COPY
4860+#endif
4861+
4862 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4863 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4864 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4865diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4866index 54ff557..70c88b7 100644
4867--- a/arch/ia64/include/asm/spinlock.h
4868+++ b/arch/ia64/include/asm/spinlock.h
4869@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4870 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4871
4872 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4873- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4874+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4875 }
4876
4877 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4878diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4879index 449c8c0..18965fb 100644
4880--- a/arch/ia64/include/asm/uaccess.h
4881+++ b/arch/ia64/include/asm/uaccess.h
4882@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4883 static inline unsigned long
4884 __copy_to_user (void __user *to, const void *from, unsigned long count)
4885 {
4886+ if (count > INT_MAX)
4887+ return count;
4888+
4889+ if (!__builtin_constant_p(count))
4890+ check_object_size(from, count, true);
4891+
4892 return __copy_user(to, (__force void __user *) from, count);
4893 }
4894
4895 static inline unsigned long
4896 __copy_from_user (void *to, const void __user *from, unsigned long count)
4897 {
4898+ if (count > INT_MAX)
4899+ return count;
4900+
4901+ if (!__builtin_constant_p(count))
4902+ check_object_size(to, count, false);
4903+
4904 return __copy_user((__force void __user *) to, from, count);
4905 }
4906
4907@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4908 ({ \
4909 void __user *__cu_to = (to); \
4910 const void *__cu_from = (from); \
4911- long __cu_len = (n); \
4912+ unsigned long __cu_len = (n); \
4913 \
4914- if (__access_ok(__cu_to, __cu_len, get_fs())) \
4915+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4916+ if (!__builtin_constant_p(n)) \
4917+ check_object_size(__cu_from, __cu_len, true); \
4918 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4919+ } \
4920 __cu_len; \
4921 })
4922
4923@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4924 ({ \
4925 void *__cu_to = (to); \
4926 const void __user *__cu_from = (from); \
4927- long __cu_len = (n); \
4928+ unsigned long __cu_len = (n); \
4929 \
4930 __chk_user_ptr(__cu_from); \
4931- if (__access_ok(__cu_from, __cu_len, get_fs())) \
4932+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4933+ if (!__builtin_constant_p(n)) \
4934+ check_object_size(__cu_to, __cu_len, false); \
4935 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4936+ } \
4937 __cu_len; \
4938 })
4939
4940diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4941index 24603be..948052d 100644
4942--- a/arch/ia64/kernel/module.c
4943+++ b/arch/ia64/kernel/module.c
4944@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
4945 void
4946 module_free (struct module *mod, void *module_region)
4947 {
4948- if (mod && mod->arch.init_unw_table &&
4949- module_region == mod->module_init) {
4950+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
4951 unw_remove_unwind_table(mod->arch.init_unw_table);
4952 mod->arch.init_unw_table = NULL;
4953 }
4954@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
4955 }
4956
4957 static inline int
4958+in_init_rx (const struct module *mod, uint64_t addr)
4959+{
4960+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
4961+}
4962+
4963+static inline int
4964+in_init_rw (const struct module *mod, uint64_t addr)
4965+{
4966+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
4967+}
4968+
4969+static inline int
4970 in_init (const struct module *mod, uint64_t addr)
4971 {
4972- return addr - (uint64_t) mod->module_init < mod->init_size;
4973+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
4974+}
4975+
4976+static inline int
4977+in_core_rx (const struct module *mod, uint64_t addr)
4978+{
4979+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
4980+}
4981+
4982+static inline int
4983+in_core_rw (const struct module *mod, uint64_t addr)
4984+{
4985+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
4986 }
4987
4988 static inline int
4989 in_core (const struct module *mod, uint64_t addr)
4990 {
4991- return addr - (uint64_t) mod->module_core < mod->core_size;
4992+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
4993 }
4994
4995 static inline int
4996@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
4997 break;
4998
4999 case RV_BDREL:
5000- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5001+ if (in_init_rx(mod, val))
5002+ val -= (uint64_t) mod->module_init_rx;
5003+ else if (in_init_rw(mod, val))
5004+ val -= (uint64_t) mod->module_init_rw;
5005+ else if (in_core_rx(mod, val))
5006+ val -= (uint64_t) mod->module_core_rx;
5007+ else if (in_core_rw(mod, val))
5008+ val -= (uint64_t) mod->module_core_rw;
5009 break;
5010
5011 case RV_LTV:
5012@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5013 * addresses have been selected...
5014 */
5015 uint64_t gp;
5016- if (mod->core_size > MAX_LTOFF)
5017+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5018 /*
5019 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5020 * at the end of the module.
5021 */
5022- gp = mod->core_size - MAX_LTOFF / 2;
5023+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5024 else
5025- gp = mod->core_size / 2;
5026- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5027+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5028+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5029 mod->arch.gp = gp;
5030 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5031 }
5032diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5033index ab33328..f39506c 100644
5034--- a/arch/ia64/kernel/palinfo.c
5035+++ b/arch/ia64/kernel/palinfo.c
5036@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5037 return NOTIFY_OK;
5038 }
5039
5040-static struct notifier_block __refdata palinfo_cpu_notifier =
5041+static struct notifier_block palinfo_cpu_notifier =
5042 {
5043 .notifier_call = palinfo_cpu_callback,
5044 .priority = 0,
5045diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5046index 41e33f8..65180b2 100644
5047--- a/arch/ia64/kernel/sys_ia64.c
5048+++ b/arch/ia64/kernel/sys_ia64.c
5049@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5050 unsigned long align_mask = 0;
5051 struct mm_struct *mm = current->mm;
5052 struct vm_unmapped_area_info info;
5053+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5054
5055 if (len > RGN_MAP_LIMIT)
5056 return -ENOMEM;
5057@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5058 if (REGION_NUMBER(addr) == RGN_HPAGE)
5059 addr = 0;
5060 #endif
5061+
5062+#ifdef CONFIG_PAX_RANDMMAP
5063+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5064+ addr = mm->free_area_cache;
5065+ else
5066+#endif
5067+
5068 if (!addr)
5069 addr = TASK_UNMAPPED_BASE;
5070
5071@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5072 info.high_limit = TASK_SIZE;
5073 info.align_mask = align_mask;
5074 info.align_offset = 0;
5075+ info.threadstack_offset = offset;
5076 return vm_unmapped_area(&info);
5077 }
5078
5079diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5080index 0ccb28f..8992469 100644
5081--- a/arch/ia64/kernel/vmlinux.lds.S
5082+++ b/arch/ia64/kernel/vmlinux.lds.S
5083@@ -198,7 +198,7 @@ SECTIONS {
5084 /* Per-cpu data: */
5085 . = ALIGN(PERCPU_PAGE_SIZE);
5086 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5087- __phys_per_cpu_start = __per_cpu_load;
5088+ __phys_per_cpu_start = per_cpu_load;
5089 /*
5090 * ensure percpu data fits
5091 * into percpu page size
5092diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5093index 6cf0341..d352594 100644
5094--- a/arch/ia64/mm/fault.c
5095+++ b/arch/ia64/mm/fault.c
5096@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5097 return pte_present(pte);
5098 }
5099
5100+#ifdef CONFIG_PAX_PAGEEXEC
5101+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5102+{
5103+ unsigned long i;
5104+
5105+ printk(KERN_ERR "PAX: bytes at PC: ");
5106+ for (i = 0; i < 8; i++) {
5107+ unsigned int c;
5108+ if (get_user(c, (unsigned int *)pc+i))
5109+ printk(KERN_CONT "???????? ");
5110+ else
5111+ printk(KERN_CONT "%08x ", c);
5112+ }
5113+ printk("\n");
5114+}
5115+#endif
5116+
5117 # define VM_READ_BIT 0
5118 # define VM_WRITE_BIT 1
5119 # define VM_EXEC_BIT 2
5120@@ -149,8 +166,21 @@ retry:
5121 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5122 goto bad_area;
5123
5124- if ((vma->vm_flags & mask) != mask)
5125+ if ((vma->vm_flags & mask) != mask) {
5126+
5127+#ifdef CONFIG_PAX_PAGEEXEC
5128+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5129+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5130+ goto bad_area;
5131+
5132+ up_read(&mm->mmap_sem);
5133+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5134+ do_group_exit(SIGKILL);
5135+ }
5136+#endif
5137+
5138 goto bad_area;
5139+ }
5140
5141 /*
5142 * If for any reason at all we couldn't handle the fault, make
5143diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5144index 76069c1..c2aa816 100644
5145--- a/arch/ia64/mm/hugetlbpage.c
5146+++ b/arch/ia64/mm/hugetlbpage.c
5147@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5148 unsigned long pgoff, unsigned long flags)
5149 {
5150 struct vm_unmapped_area_info info;
5151+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5152
5153 if (len > RGN_MAP_LIMIT)
5154 return -ENOMEM;
5155@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5156 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5157 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5158 info.align_offset = 0;
5159+ info.threadstack_offset = offset;
5160 return vm_unmapped_area(&info);
5161 }
5162
5163diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5164index b6f7f43..c04320d 100644
5165--- a/arch/ia64/mm/init.c
5166+++ b/arch/ia64/mm/init.c
5167@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5168 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5169 vma->vm_end = vma->vm_start + PAGE_SIZE;
5170 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5171+
5172+#ifdef CONFIG_PAX_PAGEEXEC
5173+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5174+ vma->vm_flags &= ~VM_EXEC;
5175+
5176+#ifdef CONFIG_PAX_MPROTECT
5177+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5178+ vma->vm_flags &= ~VM_MAYEXEC;
5179+#endif
5180+
5181+ }
5182+#endif
5183+
5184 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5185 down_write(&current->mm->mmap_sem);
5186 if (insert_vm_struct(current->mm, vma)) {
5187diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5188index 40b3ee9..8c2c112 100644
5189--- a/arch/m32r/include/asm/cache.h
5190+++ b/arch/m32r/include/asm/cache.h
5191@@ -1,8 +1,10 @@
5192 #ifndef _ASM_M32R_CACHE_H
5193 #define _ASM_M32R_CACHE_H
5194
5195+#include <linux/const.h>
5196+
5197 /* L1 cache line size */
5198 #define L1_CACHE_SHIFT 4
5199-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5200+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5201
5202 #endif /* _ASM_M32R_CACHE_H */
5203diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5204index 82abd15..d95ae5d 100644
5205--- a/arch/m32r/lib/usercopy.c
5206+++ b/arch/m32r/lib/usercopy.c
5207@@ -14,6 +14,9 @@
5208 unsigned long
5209 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5210 {
5211+ if ((long)n < 0)
5212+ return n;
5213+
5214 prefetch(from);
5215 if (access_ok(VERIFY_WRITE, to, n))
5216 __copy_user(to,from,n);
5217@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5218 unsigned long
5219 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5220 {
5221+ if ((long)n < 0)
5222+ return n;
5223+
5224 prefetchw(to);
5225 if (access_ok(VERIFY_READ, from, n))
5226 __copy_user_zeroing(to,from,n);
5227diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5228index 0395c51..5f26031 100644
5229--- a/arch/m68k/include/asm/cache.h
5230+++ b/arch/m68k/include/asm/cache.h
5231@@ -4,9 +4,11 @@
5232 #ifndef __ARCH_M68K_CACHE_H
5233 #define __ARCH_M68K_CACHE_H
5234
5235+#include <linux/const.h>
5236+
5237 /* bytes per L1 cache line */
5238 #define L1_CACHE_SHIFT 4
5239-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5240+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5241
5242 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5243
5244diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5245index 3c52fa6..11b2ad8 100644
5246--- a/arch/metag/mm/hugetlbpage.c
5247+++ b/arch/metag/mm/hugetlbpage.c
5248@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5249 info.high_limit = TASK_SIZE;
5250 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5251 info.align_offset = 0;
5252+ info.threadstack_offset = 0;
5253 return vm_unmapped_area(&info);
5254 }
5255
5256diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5257index 4efe96a..60e8699 100644
5258--- a/arch/microblaze/include/asm/cache.h
5259+++ b/arch/microblaze/include/asm/cache.h
5260@@ -13,11 +13,12 @@
5261 #ifndef _ASM_MICROBLAZE_CACHE_H
5262 #define _ASM_MICROBLAZE_CACHE_H
5263
5264+#include <linux/const.h>
5265 #include <asm/registers.h>
5266
5267 #define L1_CACHE_SHIFT 5
5268 /* word-granular cache in microblaze */
5269-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5270+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5271
5272 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5273
5274diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5275index 08b6079..8b554d2 100644
5276--- a/arch/mips/include/asm/atomic.h
5277+++ b/arch/mips/include/asm/atomic.h
5278@@ -21,15 +21,39 @@
5279 #include <asm/cmpxchg.h>
5280 #include <asm/war.h>
5281
5282+#ifdef CONFIG_GENERIC_ATOMIC64
5283+#include <asm-generic/atomic64.h>
5284+#endif
5285+
5286 #define ATOMIC_INIT(i) { (i) }
5287
5288+#ifdef CONFIG_64BIT
5289+#define _ASM_EXTABLE(from, to) \
5290+" .section __ex_table,\"a\"\n" \
5291+" .dword " #from ", " #to"\n" \
5292+" .previous\n"
5293+#else
5294+#define _ASM_EXTABLE(from, to) \
5295+" .section __ex_table,\"a\"\n" \
5296+" .word " #from ", " #to"\n" \
5297+" .previous\n"
5298+#endif
5299+
5300 /*
5301 * atomic_read - read atomic variable
5302 * @v: pointer of type atomic_t
5303 *
5304 * Atomically reads the value of @v.
5305 */
5306-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5307+static inline int atomic_read(const atomic_t *v)
5308+{
5309+ return (*(volatile const int *) &v->counter);
5310+}
5311+
5312+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5313+{
5314+ return (*(volatile const int *) &v->counter);
5315+}
5316
5317 /*
5318 * atomic_set - set atomic variable
5319@@ -38,7 +62,15 @@
5320 *
5321 * Atomically sets the value of @v to @i.
5322 */
5323-#define atomic_set(v, i) ((v)->counter = (i))
5324+static inline void atomic_set(atomic_t *v, int i)
5325+{
5326+ v->counter = i;
5327+}
5328+
5329+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5330+{
5331+ v->counter = i;
5332+}
5333
5334 /*
5335 * atomic_add - add integer to atomic variable
5336@@ -47,7 +79,67 @@
5337 *
5338 * Atomically adds @i to @v.
5339 */
5340-static __inline__ void atomic_add(int i, atomic_t * v)
5341+static __inline__ void atomic_add(int i, atomic_t *v)
5342+{
5343+ int temp;
5344+
5345+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5346+ __asm__ __volatile__(
5347+ " .set mips3 \n"
5348+ "1: ll %0, %1 # atomic_add \n"
5349+#ifdef CONFIG_PAX_REFCOUNT
5350+ /* Exception on overflow. */
5351+ "2: add %0, %2 \n"
5352+#else
5353+ " addu %0, %2 \n"
5354+#endif
5355+ " sc %0, %1 \n"
5356+ " beqzl %0, 1b \n"
5357+#ifdef CONFIG_PAX_REFCOUNT
5358+ "3: \n"
5359+ _ASM_EXTABLE(2b, 3b)
5360+#endif
5361+ " .set mips0 \n"
5362+ : "=&r" (temp), "+m" (v->counter)
5363+ : "Ir" (i));
5364+ } else if (kernel_uses_llsc) {
5365+ __asm__ __volatile__(
5366+ " .set mips3 \n"
5367+ "1: ll %0, %1 # atomic_add \n"
5368+#ifdef CONFIG_PAX_REFCOUNT
5369+ /* Exception on overflow. */
5370+ "2: add %0, %2 \n"
5371+#else
5372+ " addu %0, %2 \n"
5373+#endif
5374+ " sc %0, %1 \n"
5375+ " beqz %0, 1b \n"
5376+#ifdef CONFIG_PAX_REFCOUNT
5377+ "3: \n"
5378+ _ASM_EXTABLE(2b, 3b)
5379+#endif
5380+ " .set mips0 \n"
5381+ : "=&r" (temp), "+m" (v->counter)
5382+ : "Ir" (i));
5383+ } else {
5384+ unsigned long flags;
5385+
5386+ raw_local_irq_save(flags);
5387+ __asm__ __volatile__(
5388+#ifdef CONFIG_PAX_REFCOUNT
5389+ /* Exception on overflow. */
5390+ "1: add %0, %1 \n"
5391+ "2: \n"
5392+ _ASM_EXTABLE(1b, 2b)
5393+#else
5394+ " addu %0, %1 \n"
5395+#endif
5396+ : "+r" (v->counter) : "Ir" (i));
5397+ raw_local_irq_restore(flags);
5398+ }
5399+}
5400+
5401+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5402 {
5403 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5404 int temp;
5405@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5406 *
5407 * Atomically subtracts @i from @v.
5408 */
5409-static __inline__ void atomic_sub(int i, atomic_t * v)
5410+static __inline__ void atomic_sub(int i, atomic_t *v)
5411+{
5412+ int temp;
5413+
5414+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5415+ __asm__ __volatile__(
5416+ " .set mips3 \n"
5417+ "1: ll %0, %1 # atomic64_sub \n"
5418+#ifdef CONFIG_PAX_REFCOUNT
5419+ /* Exception on overflow. */
5420+ "2: sub %0, %2 \n"
5421+#else
5422+ " subu %0, %2 \n"
5423+#endif
5424+ " sc %0, %1 \n"
5425+ " beqzl %0, 1b \n"
5426+#ifdef CONFIG_PAX_REFCOUNT
5427+ "3: \n"
5428+ _ASM_EXTABLE(2b, 3b)
5429+#endif
5430+ " .set mips0 \n"
5431+ : "=&r" (temp), "+m" (v->counter)
5432+ : "Ir" (i));
5433+ } else if (kernel_uses_llsc) {
5434+ __asm__ __volatile__(
5435+ " .set mips3 \n"
5436+ "1: ll %0, %1 # atomic64_sub \n"
5437+#ifdef CONFIG_PAX_REFCOUNT
5438+ /* Exception on overflow. */
5439+ "2: sub %0, %2 \n"
5440+#else
5441+ " subu %0, %2 \n"
5442+#endif
5443+ " sc %0, %1 \n"
5444+ " beqz %0, 1b \n"
5445+#ifdef CONFIG_PAX_REFCOUNT
5446+ "3: \n"
5447+ _ASM_EXTABLE(2b, 3b)
5448+#endif
5449+ " .set mips0 \n"
5450+ : "=&r" (temp), "+m" (v->counter)
5451+ : "Ir" (i));
5452+ } else {
5453+ unsigned long flags;
5454+
5455+ raw_local_irq_save(flags);
5456+ __asm__ __volatile__(
5457+#ifdef CONFIG_PAX_REFCOUNT
5458+ /* Exception on overflow. */
5459+ "1: sub %0, %1 \n"
5460+ "2: \n"
5461+ _ASM_EXTABLE(1b, 2b)
5462+#else
5463+ " subu %0, %1 \n"
5464+#endif
5465+ : "+r" (v->counter) : "Ir" (i));
5466+ raw_local_irq_restore(flags);
5467+ }
5468+}
5469+
5470+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5471 {
5472 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5473 int temp;
5474@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5475 /*
5476 * Same as above, but return the result value
5477 */
5478-static __inline__ int atomic_add_return(int i, atomic_t * v)
5479+static __inline__ int atomic_add_return(int i, atomic_t *v)
5480+{
5481+ int result;
5482+ int temp;
5483+
5484+ smp_mb__before_llsc();
5485+
5486+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5487+ __asm__ __volatile__(
5488+ " .set mips3 \n"
5489+ "1: ll %1, %2 # atomic_add_return \n"
5490+#ifdef CONFIG_PAX_REFCOUNT
5491+ "2: add %0, %1, %3 \n"
5492+#else
5493+ " addu %0, %1, %3 \n"
5494+#endif
5495+ " sc %0, %2 \n"
5496+ " beqzl %0, 1b \n"
5497+#ifdef CONFIG_PAX_REFCOUNT
5498+ " b 4f \n"
5499+ " .set noreorder \n"
5500+ "3: b 5f \n"
5501+ " move %0, %1 \n"
5502+ " .set reorder \n"
5503+ _ASM_EXTABLE(2b, 3b)
5504+#endif
5505+ "4: addu %0, %1, %3 \n"
5506+#ifdef CONFIG_PAX_REFCOUNT
5507+ "5: \n"
5508+#endif
5509+ " .set mips0 \n"
5510+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5511+ : "Ir" (i));
5512+ } else if (kernel_uses_llsc) {
5513+ __asm__ __volatile__(
5514+ " .set mips3 \n"
5515+ "1: ll %1, %2 # atomic_add_return \n"
5516+#ifdef CONFIG_PAX_REFCOUNT
5517+ "2: add %0, %1, %3 \n"
5518+#else
5519+ " addu %0, %1, %3 \n"
5520+#endif
5521+ " sc %0, %2 \n"
5522+ " bnez %0, 4f \n"
5523+ " b 1b \n"
5524+#ifdef CONFIG_PAX_REFCOUNT
5525+ " .set noreorder \n"
5526+ "3: b 5f \n"
5527+ " move %0, %1 \n"
5528+ " .set reorder \n"
5529+ _ASM_EXTABLE(2b, 3b)
5530+#endif
5531+ "4: addu %0, %1, %3 \n"
5532+#ifdef CONFIG_PAX_REFCOUNT
5533+ "5: \n"
5534+#endif
5535+ " .set mips0 \n"
5536+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5537+ : "Ir" (i));
5538+ } else {
5539+ unsigned long flags;
5540+
5541+ raw_local_irq_save(flags);
5542+ __asm__ __volatile__(
5543+ " lw %0, %1 \n"
5544+#ifdef CONFIG_PAX_REFCOUNT
5545+ /* Exception on overflow. */
5546+ "1: add %0, %2 \n"
5547+#else
5548+ " addu %0, %2 \n"
5549+#endif
5550+ " sw %0, %1 \n"
5551+#ifdef CONFIG_PAX_REFCOUNT
5552+ /* Note: Dest reg is not modified on overflow */
5553+ "2: \n"
5554+ _ASM_EXTABLE(1b, 2b)
5555+#endif
5556+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5557+ raw_local_irq_restore(flags);
5558+ }
5559+
5560+ smp_llsc_mb();
5561+
5562+ return result;
5563+}
5564+
5565+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5566 {
5567 int result;
5568
5569@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5570 return result;
5571 }
5572
5573-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5574+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5575+{
5576+ int result;
5577+ int temp;
5578+
5579+ smp_mb__before_llsc();
5580+
5581+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5582+ __asm__ __volatile__(
5583+ " .set mips3 \n"
5584+ "1: ll %1, %2 # atomic_sub_return \n"
5585+#ifdef CONFIG_PAX_REFCOUNT
5586+ "2: sub %0, %1, %3 \n"
5587+#else
5588+ " subu %0, %1, %3 \n"
5589+#endif
5590+ " sc %0, %2 \n"
5591+ " beqzl %0, 1b \n"
5592+#ifdef CONFIG_PAX_REFCOUNT
5593+ " b 4f \n"
5594+ " .set noreorder \n"
5595+ "3: b 5f \n"
5596+ " move %0, %1 \n"
5597+ " .set reorder \n"
5598+ _ASM_EXTABLE(2b, 3b)
5599+#endif
5600+ "4: subu %0, %1, %3 \n"
5601+#ifdef CONFIG_PAX_REFCOUNT
5602+ "5: \n"
5603+#endif
5604+ " .set mips0 \n"
5605+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5606+ : "Ir" (i), "m" (v->counter)
5607+ : "memory");
5608+ } else if (kernel_uses_llsc) {
5609+ __asm__ __volatile__(
5610+ " .set mips3 \n"
5611+ "1: ll %1, %2 # atomic_sub_return \n"
5612+#ifdef CONFIG_PAX_REFCOUNT
5613+ "2: sub %0, %1, %3 \n"
5614+#else
5615+ " subu %0, %1, %3 \n"
5616+#endif
5617+ " sc %0, %2 \n"
5618+ " bnez %0, 4f \n"
5619+ " b 1b \n"
5620+#ifdef CONFIG_PAX_REFCOUNT
5621+ " .set noreorder \n"
5622+ "3: b 5f \n"
5623+ " move %0, %1 \n"
5624+ " .set reorder \n"
5625+ _ASM_EXTABLE(2b, 3b)
5626+#endif
5627+ "4: subu %0, %1, %3 \n"
5628+#ifdef CONFIG_PAX_REFCOUNT
5629+ "5: \n"
5630+#endif
5631+ " .set mips0 \n"
5632+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5633+ : "Ir" (i));
5634+ } else {
5635+ unsigned long flags;
5636+
5637+ raw_local_irq_save(flags);
5638+ __asm__ __volatile__(
5639+ " lw %0, %1 \n"
5640+#ifdef CONFIG_PAX_REFCOUNT
5641+ /* Exception on overflow. */
5642+ "1: sub %0, %2 \n"
5643+#else
5644+ " subu %0, %2 \n"
5645+#endif
5646+ " sw %0, %1 \n"
5647+#ifdef CONFIG_PAX_REFCOUNT
5648+ /* Note: Dest reg is not modified on overflow */
5649+ "2: \n"
5650+ _ASM_EXTABLE(1b, 2b)
5651+#endif
5652+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5653+ raw_local_irq_restore(flags);
5654+ }
5655+
5656+ smp_llsc_mb();
5657+
5658+ return result;
5659+}
5660+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5661 {
5662 int result;
5663
5664@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5665 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5666 * The function returns the old value of @v minus @i.
5667 */
5668-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5669+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5670 {
5671 int result;
5672
5673@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5674 return result;
5675 }
5676
5677-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5678-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5679+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5680+{
5681+ return cmpxchg(&v->counter, old, new);
5682+}
5683+
5684+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5685+ int new)
5686+{
5687+ return cmpxchg(&(v->counter), old, new);
5688+}
5689+
5690+static inline int atomic_xchg(atomic_t *v, int new)
5691+{
5692+ return xchg(&v->counter, new);
5693+}
5694+
5695+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5696+{
5697+ return xchg(&(v->counter), new);
5698+}
5699
5700 /**
5701 * __atomic_add_unless - add unless the number is a given value
5702@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5703
5704 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5705 #define atomic_inc_return(v) atomic_add_return(1, (v))
5706+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5707+{
5708+ return atomic_add_return_unchecked(1, v);
5709+}
5710
5711 /*
5712 * atomic_sub_and_test - subtract value from variable and test result
5713@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5714 * other cases.
5715 */
5716 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5717+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5718+{
5719+ return atomic_add_return_unchecked(1, v) == 0;
5720+}
5721
5722 /*
5723 * atomic_dec_and_test - decrement by 1 and test
5724@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5725 * Atomically increments @v by 1.
5726 */
5727 #define atomic_inc(v) atomic_add(1, (v))
5728+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5729+{
5730+ atomic_add_unchecked(1, v);
5731+}
5732
5733 /*
5734 * atomic_dec - decrement and test
5735@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5736 * Atomically decrements @v by 1.
5737 */
5738 #define atomic_dec(v) atomic_sub(1, (v))
5739+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5740+{
5741+ atomic_sub_unchecked(1, v);
5742+}
5743
5744 /*
5745 * atomic_add_negative - add and test if negative
5746@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5747 * @v: pointer of type atomic64_t
5748 *
5749 */
5750-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5751+static inline long atomic64_read(const atomic64_t *v)
5752+{
5753+ return (*(volatile const long *) &v->counter);
5754+}
5755+
5756+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5757+{
5758+ return (*(volatile const long *) &v->counter);
5759+}
5760
5761 /*
5762 * atomic64_set - set atomic variable
5763 * @v: pointer of type atomic64_t
5764 * @i: required value
5765 */
5766-#define atomic64_set(v, i) ((v)->counter = (i))
5767+static inline void atomic64_set(atomic64_t *v, long i)
5768+{
5769+ v->counter = i;
5770+}
5771+
5772+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5773+{
5774+ v->counter = i;
5775+}
5776
5777 /*
5778 * atomic64_add - add integer to atomic variable
5779@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5780 *
5781 * Atomically adds @i to @v.
5782 */
5783-static __inline__ void atomic64_add(long i, atomic64_t * v)
5784+static __inline__ void atomic64_add(long i, atomic64_t *v)
5785+{
5786+ long temp;
5787+
5788+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5789+ __asm__ __volatile__(
5790+ " .set mips3 \n"
5791+ "1: lld %0, %1 # atomic64_add \n"
5792+#ifdef CONFIG_PAX_REFCOUNT
5793+ /* Exception on overflow. */
5794+ "2: dadd %0, %2 \n"
5795+#else
5796+ " daddu %0, %2 \n"
5797+#endif
5798+ " scd %0, %1 \n"
5799+ " beqzl %0, 1b \n"
5800+#ifdef CONFIG_PAX_REFCOUNT
5801+ "3: \n"
5802+ _ASM_EXTABLE(2b, 3b)
5803+#endif
5804+ " .set mips0 \n"
5805+ : "=&r" (temp), "+m" (v->counter)
5806+ : "Ir" (i));
5807+ } else if (kernel_uses_llsc) {
5808+ __asm__ __volatile__(
5809+ " .set mips3 \n"
5810+ "1: lld %0, %1 # atomic64_add \n"
5811+#ifdef CONFIG_PAX_REFCOUNT
5812+ /* Exception on overflow. */
5813+ "2: dadd %0, %2 \n"
5814+#else
5815+ " daddu %0, %2 \n"
5816+#endif
5817+ " scd %0, %1 \n"
5818+ " beqz %0, 1b \n"
5819+#ifdef CONFIG_PAX_REFCOUNT
5820+ "3: \n"
5821+ _ASM_EXTABLE(2b, 3b)
5822+#endif
5823+ " .set mips0 \n"
5824+ : "=&r" (temp), "+m" (v->counter)
5825+ : "Ir" (i));
5826+ } else {
5827+ unsigned long flags;
5828+
5829+ raw_local_irq_save(flags);
5830+ __asm__ __volatile__(
5831+#ifdef CONFIG_PAX_REFCOUNT
5832+ /* Exception on overflow. */
5833+ "1: dadd %0, %1 \n"
5834+ "2: \n"
5835+ _ASM_EXTABLE(1b, 2b)
5836+#else
5837+ " daddu %0, %1 \n"
5838+#endif
5839+ : "+r" (v->counter) : "Ir" (i));
5840+ raw_local_irq_restore(flags);
5841+ }
5842+}
5843+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
5844 {
5845 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5846 long temp;
5847@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
5848 *
5849 * Atomically subtracts @i from @v.
5850 */
5851-static __inline__ void atomic64_sub(long i, atomic64_t * v)
5852+static __inline__ void atomic64_sub(long i, atomic64_t *v)
5853+{
5854+ long temp;
5855+
5856+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5857+ __asm__ __volatile__(
5858+ " .set mips3 \n"
5859+ "1: lld %0, %1 # atomic64_sub \n"
5860+#ifdef CONFIG_PAX_REFCOUNT
5861+ /* Exception on overflow. */
5862+ "2: dsub %0, %2 \n"
5863+#else
5864+ " dsubu %0, %2 \n"
5865+#endif
5866+ " scd %0, %1 \n"
5867+ " beqzl %0, 1b \n"
5868+#ifdef CONFIG_PAX_REFCOUNT
5869+ "3: \n"
5870+ _ASM_EXTABLE(2b, 3b)
5871+#endif
5872+ " .set mips0 \n"
5873+ : "=&r" (temp), "+m" (v->counter)
5874+ : "Ir" (i));
5875+ } else if (kernel_uses_llsc) {
5876+ __asm__ __volatile__(
5877+ " .set mips3 \n"
5878+ "1: lld %0, %1 # atomic64_sub \n"
5879+#ifdef CONFIG_PAX_REFCOUNT
5880+ /* Exception on overflow. */
5881+ "2: dsub %0, %2 \n"
5882+#else
5883+ " dsubu %0, %2 \n"
5884+#endif
5885+ " scd %0, %1 \n"
5886+ " beqz %0, 1b \n"
5887+#ifdef CONFIG_PAX_REFCOUNT
5888+ "3: \n"
5889+ _ASM_EXTABLE(2b, 3b)
5890+#endif
5891+ " .set mips0 \n"
5892+ : "=&r" (temp), "+m" (v->counter)
5893+ : "Ir" (i));
5894+ } else {
5895+ unsigned long flags;
5896+
5897+ raw_local_irq_save(flags);
5898+ __asm__ __volatile__(
5899+#ifdef CONFIG_PAX_REFCOUNT
5900+ /* Exception on overflow. */
5901+ "1: dsub %0, %1 \n"
5902+ "2: \n"
5903+ _ASM_EXTABLE(1b, 2b)
5904+#else
5905+ " dsubu %0, %1 \n"
5906+#endif
5907+ : "+r" (v->counter) : "Ir" (i));
5908+ raw_local_irq_restore(flags);
5909+ }
5910+}
5911+
5912+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
5913 {
5914 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5915 long temp;
5916@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
5917 /*
5918 * Same as above, but return the result value
5919 */
5920-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
5921+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
5922+{
5923+ long result;
5924+ long temp;
5925+
5926+ smp_mb__before_llsc();
5927+
5928+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5929+ __asm__ __volatile__(
5930+ " .set mips3 \n"
5931+ "1: lld %1, %2 # atomic64_add_return \n"
5932+#ifdef CONFIG_PAX_REFCOUNT
5933+ "2: dadd %0, %1, %3 \n"
5934+#else
5935+ " daddu %0, %1, %3 \n"
5936+#endif
5937+ " scd %0, %2 \n"
5938+ " beqzl %0, 1b \n"
5939+#ifdef CONFIG_PAX_REFCOUNT
5940+ " b 4f \n"
5941+ " .set noreorder \n"
5942+ "3: b 5f \n"
5943+ " move %0, %1 \n"
5944+ " .set reorder \n"
5945+ _ASM_EXTABLE(2b, 3b)
5946+#endif
5947+ "4: daddu %0, %1, %3 \n"
5948+#ifdef CONFIG_PAX_REFCOUNT
5949+ "5: \n"
5950+#endif
5951+ " .set mips0 \n"
5952+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5953+ : "Ir" (i));
5954+ } else if (kernel_uses_llsc) {
5955+ __asm__ __volatile__(
5956+ " .set mips3 \n"
5957+ "1: lld %1, %2 # atomic64_add_return \n"
5958+#ifdef CONFIG_PAX_REFCOUNT
5959+ "2: dadd %0, %1, %3 \n"
5960+#else
5961+ " daddu %0, %1, %3 \n"
5962+#endif
5963+ " scd %0, %2 \n"
5964+ " bnez %0, 4f \n"
5965+ " b 1b \n"
5966+#ifdef CONFIG_PAX_REFCOUNT
5967+ " .set noreorder \n"
5968+ "3: b 5f \n"
5969+ " move %0, %1 \n"
5970+ " .set reorder \n"
5971+ _ASM_EXTABLE(2b, 3b)
5972+#endif
5973+ "4: daddu %0, %1, %3 \n"
5974+#ifdef CONFIG_PAX_REFCOUNT
5975+ "5: \n"
5976+#endif
5977+ " .set mips0 \n"
5978+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5979+ : "Ir" (i), "m" (v->counter)
5980+ : "memory");
5981+ } else {
5982+ unsigned long flags;
5983+
5984+ raw_local_irq_save(flags);
5985+ __asm__ __volatile__(
5986+ " ld %0, %1 \n"
5987+#ifdef CONFIG_PAX_REFCOUNT
5988+ /* Exception on overflow. */
5989+ "1: dadd %0, %2 \n"
5990+#else
5991+ " daddu %0, %2 \n"
5992+#endif
5993+ " sd %0, %1 \n"
5994+#ifdef CONFIG_PAX_REFCOUNT
5995+ /* Note: Dest reg is not modified on overflow */
5996+ "2: \n"
5997+ _ASM_EXTABLE(1b, 2b)
5998+#endif
5999+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6000+ raw_local_irq_restore(flags);
6001+ }
6002+
6003+ smp_llsc_mb();
6004+
6005+ return result;
6006+}
6007+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6008 {
6009 long result;
6010
6011@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6012 return result;
6013 }
6014
6015-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6016+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6017+{
6018+ long result;
6019+ long temp;
6020+
6021+ smp_mb__before_llsc();
6022+
6023+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6024+ long temp;
6025+
6026+ __asm__ __volatile__(
6027+ " .set mips3 \n"
6028+ "1: lld %1, %2 # atomic64_sub_return \n"
6029+#ifdef CONFIG_PAX_REFCOUNT
6030+ "2: dsub %0, %1, %3 \n"
6031+#else
6032+ " dsubu %0, %1, %3 \n"
6033+#endif
6034+ " scd %0, %2 \n"
6035+ " beqzl %0, 1b \n"
6036+#ifdef CONFIG_PAX_REFCOUNT
6037+ " b 4f \n"
6038+ " .set noreorder \n"
6039+ "3: b 5f \n"
6040+ " move %0, %1 \n"
6041+ " .set reorder \n"
6042+ _ASM_EXTABLE(2b, 3b)
6043+#endif
6044+ "4: dsubu %0, %1, %3 \n"
6045+#ifdef CONFIG_PAX_REFCOUNT
6046+ "5: \n"
6047+#endif
6048+ " .set mips0 \n"
6049+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6050+ : "Ir" (i), "m" (v->counter)
6051+ : "memory");
6052+ } else if (kernel_uses_llsc) {
6053+ __asm__ __volatile__(
6054+ " .set mips3 \n"
6055+ "1: lld %1, %2 # atomic64_sub_return \n"
6056+#ifdef CONFIG_PAX_REFCOUNT
6057+ "2: dsub %0, %1, %3 \n"
6058+#else
6059+ " dsubu %0, %1, %3 \n"
6060+#endif
6061+ " scd %0, %2 \n"
6062+ " bnez %0, 4f \n"
6063+ " b 1b \n"
6064+#ifdef CONFIG_PAX_REFCOUNT
6065+ " .set noreorder \n"
6066+ "3: b 5f \n"
6067+ " move %0, %1 \n"
6068+ " .set reorder \n"
6069+ _ASM_EXTABLE(2b, 3b)
6070+#endif
6071+ "4: dsubu %0, %1, %3 \n"
6072+#ifdef CONFIG_PAX_REFCOUNT
6073+ "5: \n"
6074+#endif
6075+ " .set mips0 \n"
6076+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6077+ : "Ir" (i), "m" (v->counter)
6078+ : "memory");
6079+ } else {
6080+ unsigned long flags;
6081+
6082+ raw_local_irq_save(flags);
6083+ __asm__ __volatile__(
6084+ " ld %0, %1 \n"
6085+#ifdef CONFIG_PAX_REFCOUNT
6086+ /* Exception on overflow. */
6087+ "1: dsub %0, %2 \n"
6088+#else
6089+ " dsubu %0, %2 \n"
6090+#endif
6091+ " sd %0, %1 \n"
6092+#ifdef CONFIG_PAX_REFCOUNT
6093+ /* Note: Dest reg is not modified on overflow */
6094+ "2: \n"
6095+ _ASM_EXTABLE(1b, 2b)
6096+#endif
6097+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6098+ raw_local_irq_restore(flags);
6099+ }
6100+
6101+ smp_llsc_mb();
6102+
6103+ return result;
6104+}
6105+
6106+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6107 {
6108 long result;
6109
6110@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6111 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6112 * The function returns the old value of @v minus @i.
6113 */
6114-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6115+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6116 {
6117 long result;
6118
6119@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6120 return result;
6121 }
6122
6123-#define atomic64_cmpxchg(v, o, n) \
6124- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6125-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6126+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6127+{
6128+ return cmpxchg(&v->counter, old, new);
6129+}
6130+
6131+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6132+ long new)
6133+{
6134+ return cmpxchg(&(v->counter), old, new);
6135+}
6136+
6137+static inline long atomic64_xchg(atomic64_t *v, long new)
6138+{
6139+ return xchg(&v->counter, new);
6140+}
6141+
6142+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6143+{
6144+ return xchg(&(v->counter), new);
6145+}
6146
6147 /**
6148 * atomic64_add_unless - add unless the number is a given value
6149@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6150
6151 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6152 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6153+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6154
6155 /*
6156 * atomic64_sub_and_test - subtract value from variable and test result
6157@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6158 * other cases.
6159 */
6160 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6161+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6162
6163 /*
6164 * atomic64_dec_and_test - decrement by 1 and test
6165@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6166 * Atomically increments @v by 1.
6167 */
6168 #define atomic64_inc(v) atomic64_add(1, (v))
6169+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6170
6171 /*
6172 * atomic64_dec - decrement and test
6173@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6174 * Atomically decrements @v by 1.
6175 */
6176 #define atomic64_dec(v) atomic64_sub(1, (v))
6177+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6178
6179 /*
6180 * atomic64_add_negative - add and test if negative
6181diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6182index b4db69f..8f3b093 100644
6183--- a/arch/mips/include/asm/cache.h
6184+++ b/arch/mips/include/asm/cache.h
6185@@ -9,10 +9,11 @@
6186 #ifndef _ASM_CACHE_H
6187 #define _ASM_CACHE_H
6188
6189+#include <linux/const.h>
6190 #include <kmalloc.h>
6191
6192 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6193-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6194+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6195
6196 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6197 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6198diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6199index cf3ae24..238d22f 100644
6200--- a/arch/mips/include/asm/elf.h
6201+++ b/arch/mips/include/asm/elf.h
6202@@ -372,13 +372,16 @@ extern const char *__elf_platform;
6203 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6204 #endif
6205
6206+#ifdef CONFIG_PAX_ASLR
6207+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6208+
6209+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6210+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6211+#endif
6212+
6213 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6214 struct linux_binprm;
6215 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6216 int uses_interp);
6217
6218-struct mm_struct;
6219-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6220-#define arch_randomize_brk arch_randomize_brk
6221-
6222 #endif /* _ASM_ELF_H */
6223diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6224index c1f6afa..38cc6e9 100644
6225--- a/arch/mips/include/asm/exec.h
6226+++ b/arch/mips/include/asm/exec.h
6227@@ -12,6 +12,6 @@
6228 #ifndef _ASM_EXEC_H
6229 #define _ASM_EXEC_H
6230
6231-extern unsigned long arch_align_stack(unsigned long sp);
6232+#define arch_align_stack(x) ((x) & ~0xfUL)
6233
6234 #endif /* _ASM_EXEC_H */
6235diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6236index d44622c..64990d2 100644
6237--- a/arch/mips/include/asm/local.h
6238+++ b/arch/mips/include/asm/local.h
6239@@ -12,15 +12,25 @@ typedef struct
6240 atomic_long_t a;
6241 } local_t;
6242
6243+typedef struct {
6244+ atomic_long_unchecked_t a;
6245+} local_unchecked_t;
6246+
6247 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6248
6249 #define local_read(l) atomic_long_read(&(l)->a)
6250+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6251 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6252+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6253
6254 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6255+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6256 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6257+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6258 #define local_inc(l) atomic_long_inc(&(l)->a)
6259+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6260 #define local_dec(l) atomic_long_dec(&(l)->a)
6261+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6262
6263 /*
6264 * Same as above, but return the result value
6265@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6266 return result;
6267 }
6268
6269+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6270+{
6271+ unsigned long result;
6272+
6273+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6274+ unsigned long temp;
6275+
6276+ __asm__ __volatile__(
6277+ " .set mips3 \n"
6278+ "1:" __LL "%1, %2 # local_add_return \n"
6279+ " addu %0, %1, %3 \n"
6280+ __SC "%0, %2 \n"
6281+ " beqzl %0, 1b \n"
6282+ " addu %0, %1, %3 \n"
6283+ " .set mips0 \n"
6284+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6285+ : "Ir" (i), "m" (l->a.counter)
6286+ : "memory");
6287+ } else if (kernel_uses_llsc) {
6288+ unsigned long temp;
6289+
6290+ __asm__ __volatile__(
6291+ " .set mips3 \n"
6292+ "1:" __LL "%1, %2 # local_add_return \n"
6293+ " addu %0, %1, %3 \n"
6294+ __SC "%0, %2 \n"
6295+ " beqz %0, 1b \n"
6296+ " addu %0, %1, %3 \n"
6297+ " .set mips0 \n"
6298+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6299+ : "Ir" (i), "m" (l->a.counter)
6300+ : "memory");
6301+ } else {
6302+ unsigned long flags;
6303+
6304+ local_irq_save(flags);
6305+ result = l->a.counter;
6306+ result += i;
6307+ l->a.counter = result;
6308+ local_irq_restore(flags);
6309+ }
6310+
6311+ return result;
6312+}
6313+
6314 static __inline__ long local_sub_return(long i, local_t * l)
6315 {
6316 unsigned long result;
6317@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6318
6319 #define local_cmpxchg(l, o, n) \
6320 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6321+#define local_cmpxchg_unchecked(l, o, n) \
6322+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6323 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6324
6325 /**
6326diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6327index f6be474..12ad554 100644
6328--- a/arch/mips/include/asm/page.h
6329+++ b/arch/mips/include/asm/page.h
6330@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6331 #ifdef CONFIG_CPU_MIPS32
6332 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6333 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6334- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6335+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6336 #else
6337 typedef struct { unsigned long long pte; } pte_t;
6338 #define pte_val(x) ((x).pte)
6339diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6340index 881d18b..cea38bc 100644
6341--- a/arch/mips/include/asm/pgalloc.h
6342+++ b/arch/mips/include/asm/pgalloc.h
6343@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6344 {
6345 set_pud(pud, __pud((unsigned long)pmd));
6346 }
6347+
6348+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6349+{
6350+ pud_populate(mm, pud, pmd);
6351+}
6352 #endif
6353
6354 /*
6355diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6356index 25da651..ae2a259 100644
6357--- a/arch/mips/include/asm/smtc_proc.h
6358+++ b/arch/mips/include/asm/smtc_proc.h
6359@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6360
6361 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6362
6363-extern atomic_t smtc_fpu_recoveries;
6364+extern atomic_unchecked_t smtc_fpu_recoveries;
6365
6366 #endif /* __ASM_SMTC_PROC_H */
6367diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6368index 61215a3..213ee0e 100644
6369--- a/arch/mips/include/asm/thread_info.h
6370+++ b/arch/mips/include/asm/thread_info.h
6371@@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
6372 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
6373 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6374 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6375+/* li takes a 32bit immediate */
6376+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6377 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6378
6379 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6380@@ -132,20 +134,18 @@ static inline struct thread_info *current_thread_info(void)
6381 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
6382 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6383 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6384+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6385
6386-#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6387- _TIF_SYSCALL_AUDIT)
6388+#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6389
6390 /* work to do in syscall_trace_leave() */
6391-#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6392- _TIF_SYSCALL_AUDIT)
6393+#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6394
6395 /* work to do on interrupt/exception return */
6396 #define _TIF_WORK_MASK \
6397 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
6398 /* work to do on any return to u-space */
6399-#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6400- _TIF_WORK_SYSCALL_EXIT)
6401+#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
6402
6403 #endif /* __KERNEL__ */
6404
6405diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6406index 1188e00..41cf144 100644
6407--- a/arch/mips/kernel/binfmt_elfn32.c
6408+++ b/arch/mips/kernel/binfmt_elfn32.c
6409@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6410 #undef ELF_ET_DYN_BASE
6411 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6412
6413+#ifdef CONFIG_PAX_ASLR
6414+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6415+
6416+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6417+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6418+#endif
6419+
6420 #include <asm/processor.h>
6421 #include <linux/module.h>
6422 #include <linux/elfcore.h>
6423diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6424index 202e581..689ca79 100644
6425--- a/arch/mips/kernel/binfmt_elfo32.c
6426+++ b/arch/mips/kernel/binfmt_elfo32.c
6427@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6428 #undef ELF_ET_DYN_BASE
6429 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6430
6431+#ifdef CONFIG_PAX_ASLR
6432+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6433+
6434+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6435+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6436+#endif
6437+
6438 #include <asm/processor.h>
6439
6440 /*
6441diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6442index d1fea7a..45602ea 100644
6443--- a/arch/mips/kernel/irq.c
6444+++ b/arch/mips/kernel/irq.c
6445@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6446 printk("unexpected IRQ # %d\n", irq);
6447 }
6448
6449-atomic_t irq_err_count;
6450+atomic_unchecked_t irq_err_count;
6451
6452 int arch_show_interrupts(struct seq_file *p, int prec)
6453 {
6454- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6455+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6456 return 0;
6457 }
6458
6459 asmlinkage void spurious_interrupt(void)
6460 {
6461- atomic_inc(&irq_err_count);
6462+ atomic_inc_unchecked(&irq_err_count);
6463 }
6464
6465 void __init init_IRQ(void)
6466diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6467index ddc7610..8c58f17 100644
6468--- a/arch/mips/kernel/process.c
6469+++ b/arch/mips/kernel/process.c
6470@@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6471 out:
6472 return pc;
6473 }
6474-
6475-/*
6476- * Don't forget that the stack pointer must be aligned on a 8 bytes
6477- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6478- */
6479-unsigned long arch_align_stack(unsigned long sp)
6480-{
6481- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6482- sp -= get_random_int() & ~PAGE_MASK;
6483-
6484- return sp & ALMASK;
6485-}
6486diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6487index 8ae1ebe..1bcbf47 100644
6488--- a/arch/mips/kernel/ptrace.c
6489+++ b/arch/mips/kernel/ptrace.c
6490@@ -529,6 +529,10 @@ static inline int audit_arch(void)
6491 return arch;
6492 }
6493
6494+#ifdef CONFIG_GRKERNSEC_SETXID
6495+extern void gr_delayed_cred_worker(void);
6496+#endif
6497+
6498 /*
6499 * Notification of system call entry/exit
6500 * - triggered by current->work.syscall_trace
6501@@ -540,6 +544,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6502 /* do the secure computing check first */
6503 secure_computing_strict(regs->regs[2]);
6504
6505+#ifdef CONFIG_GRKERNSEC_SETXID
6506+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6507+ gr_delayed_cred_worker();
6508+#endif
6509+
6510 if (!(current->ptrace & PT_PTRACED))
6511 goto out;
6512
6513diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6514index c10aa84..9ec2e60 100644
6515--- a/arch/mips/kernel/smtc-proc.c
6516+++ b/arch/mips/kernel/smtc-proc.c
6517@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6518
6519 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6520
6521-atomic_t smtc_fpu_recoveries;
6522+atomic_unchecked_t smtc_fpu_recoveries;
6523
6524 static int smtc_proc_show(struct seq_file *m, void *v)
6525 {
6526@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6527 for(i = 0; i < NR_CPUS; i++)
6528 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6529 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6530- atomic_read(&smtc_fpu_recoveries));
6531+ atomic_read_unchecked(&smtc_fpu_recoveries));
6532 return 0;
6533 }
6534
6535@@ -73,7 +73,7 @@ void init_smtc_stats(void)
6536 smtc_cpu_stats[i].selfipis = 0;
6537 }
6538
6539- atomic_set(&smtc_fpu_recoveries, 0);
6540+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6541
6542 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6543 }
6544diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6545index dfc1b91..11a2c07 100644
6546--- a/arch/mips/kernel/smtc.c
6547+++ b/arch/mips/kernel/smtc.c
6548@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6549 }
6550 smtc_ipi_qdump();
6551 printk("%d Recoveries of \"stolen\" FPU\n",
6552- atomic_read(&smtc_fpu_recoveries));
6553+ atomic_read_unchecked(&smtc_fpu_recoveries));
6554 }
6555
6556
6557diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6558index 84536bf..79caa4d 100644
6559--- a/arch/mips/kernel/sync-r4k.c
6560+++ b/arch/mips/kernel/sync-r4k.c
6561@@ -21,8 +21,8 @@
6562 #include <asm/mipsregs.h>
6563
6564 static atomic_t count_start_flag = ATOMIC_INIT(0);
6565-static atomic_t count_count_start = ATOMIC_INIT(0);
6566-static atomic_t count_count_stop = ATOMIC_INIT(0);
6567+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6568+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6569 static atomic_t count_reference = ATOMIC_INIT(0);
6570
6571 #define COUNTON 100
6572@@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
6573
6574 for (i = 0; i < NR_LOOPS; i++) {
6575 /* slaves loop on '!= 2' */
6576- while (atomic_read(&count_count_start) != 1)
6577+ while (atomic_read_unchecked(&count_count_start) != 1)
6578 mb();
6579- atomic_set(&count_count_stop, 0);
6580+ atomic_set_unchecked(&count_count_stop, 0);
6581 smp_wmb();
6582
6583 /* this lets the slaves write their count register */
6584- atomic_inc(&count_count_start);
6585+ atomic_inc_unchecked(&count_count_start);
6586
6587 /*
6588 * Everyone initialises count in the last loop:
6589@@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
6590 /*
6591 * Wait for all slaves to leave the synchronization point:
6592 */
6593- while (atomic_read(&count_count_stop) != 1)
6594+ while (atomic_read_unchecked(&count_count_stop) != 1)
6595 mb();
6596- atomic_set(&count_count_start, 0);
6597+ atomic_set_unchecked(&count_count_start, 0);
6598 smp_wmb();
6599- atomic_inc(&count_count_stop);
6600+ atomic_inc_unchecked(&count_count_stop);
6601 }
6602 /* Arrange for an interrupt in a short while */
6603 write_c0_compare(read_c0_count() + COUNTON);
6604@@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
6605 initcount = atomic_read(&count_reference);
6606
6607 for (i = 0; i < NR_LOOPS; i++) {
6608- atomic_inc(&count_count_start);
6609- while (atomic_read(&count_count_start) != 2)
6610+ atomic_inc_unchecked(&count_count_start);
6611+ while (atomic_read_unchecked(&count_count_start) != 2)
6612 mb();
6613
6614 /*
6615@@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
6616 if (i == NR_LOOPS-1)
6617 write_c0_count(initcount);
6618
6619- atomic_inc(&count_count_stop);
6620- while (atomic_read(&count_count_stop) != 2)
6621+ atomic_inc_unchecked(&count_count_stop);
6622+ while (atomic_read_unchecked(&count_count_stop) != 2)
6623 mb();
6624 }
6625 /* Arrange for an interrupt in a short while */
6626diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6627index aec3408..74d79d3 100644
6628--- a/arch/mips/kernel/traps.c
6629+++ b/arch/mips/kernel/traps.c
6630@@ -683,7 +683,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6631 siginfo_t info;
6632
6633 prev_state = exception_enter();
6634- die_if_kernel("Integer overflow", regs);
6635+ if (unlikely(!user_mode(regs))) {
6636+
6637+#ifdef CONFIG_PAX_REFCOUNT
6638+ if (fixup_exception(regs)) {
6639+ pax_report_refcount_overflow(regs);
6640+ exception_exit(prev_state);
6641+ return;
6642+ }
6643+#endif
6644+
6645+ die("Integer overflow", regs);
6646+ }
6647
6648 info.si_code = FPE_INTOVF;
6649 info.si_signo = SIGFPE;
6650diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6651index 85df1cd..4f0a4de 100644
6652--- a/arch/mips/mm/fault.c
6653+++ b/arch/mips/mm/fault.c
6654@@ -28,6 +28,23 @@
6655 #include <asm/highmem.h> /* For VMALLOC_END */
6656 #include <linux/kdebug.h>
6657
6658+#ifdef CONFIG_PAX_PAGEEXEC
6659+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6660+{
6661+ unsigned long i;
6662+
6663+ printk(KERN_ERR "PAX: bytes at PC: ");
6664+ for (i = 0; i < 5; i++) {
6665+ unsigned int c;
6666+ if (get_user(c, (unsigned int *)pc+i))
6667+ printk(KERN_CONT "???????? ");
6668+ else
6669+ printk(KERN_CONT "%08x ", c);
6670+ }
6671+ printk("\n");
6672+}
6673+#endif
6674+
6675 /*
6676 * This routine handles page faults. It determines the address,
6677 * and the problem, and then passes it off to one of the appropriate
6678@@ -197,6 +214,14 @@ bad_area:
6679 bad_area_nosemaphore:
6680 /* User mode accesses just cause a SIGSEGV */
6681 if (user_mode(regs)) {
6682+
6683+#ifdef CONFIG_PAX_PAGEEXEC
6684+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6685+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6686+ do_group_exit(SIGKILL);
6687+ }
6688+#endif
6689+
6690 tsk->thread.cp0_badvaddr = address;
6691 tsk->thread.error_code = write;
6692 #if 0
6693diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6694index f1baadd..8537544 100644
6695--- a/arch/mips/mm/mmap.c
6696+++ b/arch/mips/mm/mmap.c
6697@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6698 struct vm_area_struct *vma;
6699 unsigned long addr = addr0;
6700 int do_color_align;
6701+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6702 struct vm_unmapped_area_info info;
6703
6704 if (unlikely(len > TASK_SIZE))
6705@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6706 do_color_align = 1;
6707
6708 /* requesting a specific address */
6709+
6710+#ifdef CONFIG_PAX_RANDMMAP
6711+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6712+#endif
6713+
6714 if (addr) {
6715 if (do_color_align)
6716 addr = COLOUR_ALIGN(addr, pgoff);
6717@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6718 addr = PAGE_ALIGN(addr);
6719
6720 vma = find_vma(mm, addr);
6721- if (TASK_SIZE - len >= addr &&
6722- (!vma || addr + len <= vma->vm_start))
6723+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
6724 return addr;
6725 }
6726
6727 info.length = len;
6728 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6729 info.align_offset = pgoff << PAGE_SHIFT;
6730+ info.threadstack_offset = offset;
6731
6732 if (dir == DOWN) {
6733 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6734@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6735 {
6736 unsigned long random_factor = 0UL;
6737
6738+#ifdef CONFIG_PAX_RANDMMAP
6739+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6740+#endif
6741+
6742 if (current->flags & PF_RANDOMIZE) {
6743 random_factor = get_random_int();
6744 random_factor = random_factor << PAGE_SHIFT;
6745@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6746
6747 if (mmap_is_legacy()) {
6748 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6749+
6750+#ifdef CONFIG_PAX_RANDMMAP
6751+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6752+ mm->mmap_base += mm->delta_mmap;
6753+#endif
6754+
6755 mm->get_unmapped_area = arch_get_unmapped_area;
6756 } else {
6757 mm->mmap_base = mmap_base(random_factor);
6758+
6759+#ifdef CONFIG_PAX_RANDMMAP
6760+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6761+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6762+#endif
6763+
6764 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6765 }
6766 }
6767
6768-static inline unsigned long brk_rnd(void)
6769-{
6770- unsigned long rnd = get_random_int();
6771-
6772- rnd = rnd << PAGE_SHIFT;
6773- /* 8MB for 32bit, 256MB for 64bit */
6774- if (TASK_IS_32BIT_ADDR)
6775- rnd = rnd & 0x7ffffful;
6776- else
6777- rnd = rnd & 0xffffffful;
6778-
6779- return rnd;
6780-}
6781-
6782-unsigned long arch_randomize_brk(struct mm_struct *mm)
6783-{
6784- unsigned long base = mm->brk;
6785- unsigned long ret;
6786-
6787- ret = PAGE_ALIGN(base + brk_rnd());
6788-
6789- if (ret < mm->brk)
6790- return mm->brk;
6791-
6792- return ret;
6793-}
6794-
6795 int __virt_addr_valid(const volatile void *kaddr)
6796 {
6797 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
6798diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
6799index a2358b4..7cead4f 100644
6800--- a/arch/mips/sgi-ip27/ip27-nmi.c
6801+++ b/arch/mips/sgi-ip27/ip27-nmi.c
6802@@ -187,9 +187,9 @@ void
6803 cont_nmi_dump(void)
6804 {
6805 #ifndef REAL_NMI_SIGNAL
6806- static atomic_t nmied_cpus = ATOMIC_INIT(0);
6807+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
6808
6809- atomic_inc(&nmied_cpus);
6810+ atomic_inc_unchecked(&nmied_cpus);
6811 #endif
6812 /*
6813 * Only allow 1 cpu to proceed
6814@@ -233,7 +233,7 @@ cont_nmi_dump(void)
6815 udelay(10000);
6816 }
6817 #else
6818- while (atomic_read(&nmied_cpus) != num_online_cpus());
6819+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
6820 #endif
6821
6822 /*
6823diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6824index 967d144..db12197 100644
6825--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
6826+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6827@@ -11,12 +11,14 @@
6828 #ifndef _ASM_PROC_CACHE_H
6829 #define _ASM_PROC_CACHE_H
6830
6831+#include <linux/const.h>
6832+
6833 /* L1 cache */
6834
6835 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6836 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
6837-#define L1_CACHE_BYTES 16 /* bytes per entry */
6838 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
6839+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6840 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
6841
6842 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6843diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6844index bcb5df2..84fabd2 100644
6845--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6846+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6847@@ -16,13 +16,15 @@
6848 #ifndef _ASM_PROC_CACHE_H
6849 #define _ASM_PROC_CACHE_H
6850
6851+#include <linux/const.h>
6852+
6853 /*
6854 * L1 cache
6855 */
6856 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6857 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
6858-#define L1_CACHE_BYTES 32 /* bytes per entry */
6859 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
6860+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6861 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
6862
6863 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6864diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
6865index 4ce7a01..449202a 100644
6866--- a/arch/openrisc/include/asm/cache.h
6867+++ b/arch/openrisc/include/asm/cache.h
6868@@ -19,11 +19,13 @@
6869 #ifndef __ASM_OPENRISC_CACHE_H
6870 #define __ASM_OPENRISC_CACHE_H
6871
6872+#include <linux/const.h>
6873+
6874 /* FIXME: How can we replace these with values from the CPU...
6875 * they shouldn't be hard-coded!
6876 */
6877
6878-#define L1_CACHE_BYTES 16
6879 #define L1_CACHE_SHIFT 4
6880+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6881
6882 #endif /* __ASM_OPENRISC_CACHE_H */
6883diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
6884index 472886c..00e7df9 100644
6885--- a/arch/parisc/include/asm/atomic.h
6886+++ b/arch/parisc/include/asm/atomic.h
6887@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
6888 return dec;
6889 }
6890
6891+#define atomic64_read_unchecked(v) atomic64_read(v)
6892+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6893+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6894+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6895+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6896+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6897+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6898+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6899+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6900+
6901 #endif /* !CONFIG_64BIT */
6902
6903
6904diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
6905index 47f11c7..3420df2 100644
6906--- a/arch/parisc/include/asm/cache.h
6907+++ b/arch/parisc/include/asm/cache.h
6908@@ -5,6 +5,7 @@
6909 #ifndef __ARCH_PARISC_CACHE_H
6910 #define __ARCH_PARISC_CACHE_H
6911
6912+#include <linux/const.h>
6913
6914 /*
6915 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
6916@@ -15,13 +16,13 @@
6917 * just ruin performance.
6918 */
6919 #ifdef CONFIG_PA20
6920-#define L1_CACHE_BYTES 64
6921 #define L1_CACHE_SHIFT 6
6922 #else
6923-#define L1_CACHE_BYTES 32
6924 #define L1_CACHE_SHIFT 5
6925 #endif
6926
6927+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6928+
6929 #ifndef __ASSEMBLY__
6930
6931 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6932diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
6933index ad2b503..bdf1651 100644
6934--- a/arch/parisc/include/asm/elf.h
6935+++ b/arch/parisc/include/asm/elf.h
6936@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
6937
6938 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
6939
6940+#ifdef CONFIG_PAX_ASLR
6941+#define PAX_ELF_ET_DYN_BASE 0x10000UL
6942+
6943+#define PAX_DELTA_MMAP_LEN 16
6944+#define PAX_DELTA_STACK_LEN 16
6945+#endif
6946+
6947 /* This yields a mask that user programs can use to figure out what
6948 instruction set this CPU supports. This could be done in user space,
6949 but it's not easy, and we've already done it here. */
6950diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
6951index fc987a1..6e068ef 100644
6952--- a/arch/parisc/include/asm/pgalloc.h
6953+++ b/arch/parisc/include/asm/pgalloc.h
6954@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
6955 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
6956 }
6957
6958+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
6959+{
6960+ pgd_populate(mm, pgd, pmd);
6961+}
6962+
6963 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
6964 {
6965 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
6966@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
6967 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
6968 #define pmd_free(mm, x) do { } while (0)
6969 #define pgd_populate(mm, pmd, pte) BUG()
6970+#define pgd_populate_kernel(mm, pmd, pte) BUG()
6971
6972 #endif
6973
6974diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
6975index 34899b5..02dd060 100644
6976--- a/arch/parisc/include/asm/pgtable.h
6977+++ b/arch/parisc/include/asm/pgtable.h
6978@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
6979 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
6980 #define PAGE_COPY PAGE_EXECREAD
6981 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
6982+
6983+#ifdef CONFIG_PAX_PAGEEXEC
6984+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
6985+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
6986+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
6987+#else
6988+# define PAGE_SHARED_NOEXEC PAGE_SHARED
6989+# define PAGE_COPY_NOEXEC PAGE_COPY
6990+# define PAGE_READONLY_NOEXEC PAGE_READONLY
6991+#endif
6992+
6993 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
6994 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
6995 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
6996diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
6997index e0a8235..ce2f1e1 100644
6998--- a/arch/parisc/include/asm/uaccess.h
6999+++ b/arch/parisc/include/asm/uaccess.h
7000@@ -245,10 +245,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7001 const void __user *from,
7002 unsigned long n)
7003 {
7004- int sz = __compiletime_object_size(to);
7005+ size_t sz = __compiletime_object_size(to);
7006 int ret = -EFAULT;
7007
7008- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7009+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7010 ret = __copy_from_user(to, from, n);
7011 else
7012 copy_from_user_overflow();
7013diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7014index 2a625fb..9908930 100644
7015--- a/arch/parisc/kernel/module.c
7016+++ b/arch/parisc/kernel/module.c
7017@@ -98,16 +98,38 @@
7018
7019 /* three functions to determine where in the module core
7020 * or init pieces the location is */
7021+static inline int in_init_rx(struct module *me, void *loc)
7022+{
7023+ return (loc >= me->module_init_rx &&
7024+ loc < (me->module_init_rx + me->init_size_rx));
7025+}
7026+
7027+static inline int in_init_rw(struct module *me, void *loc)
7028+{
7029+ return (loc >= me->module_init_rw &&
7030+ loc < (me->module_init_rw + me->init_size_rw));
7031+}
7032+
7033 static inline int in_init(struct module *me, void *loc)
7034 {
7035- return (loc >= me->module_init &&
7036- loc <= (me->module_init + me->init_size));
7037+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7038+}
7039+
7040+static inline int in_core_rx(struct module *me, void *loc)
7041+{
7042+ return (loc >= me->module_core_rx &&
7043+ loc < (me->module_core_rx + me->core_size_rx));
7044+}
7045+
7046+static inline int in_core_rw(struct module *me, void *loc)
7047+{
7048+ return (loc >= me->module_core_rw &&
7049+ loc < (me->module_core_rw + me->core_size_rw));
7050 }
7051
7052 static inline int in_core(struct module *me, void *loc)
7053 {
7054- return (loc >= me->module_core &&
7055- loc <= (me->module_core + me->core_size));
7056+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7057 }
7058
7059 static inline int in_local(struct module *me, void *loc)
7060@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7061 }
7062
7063 /* align things a bit */
7064- me->core_size = ALIGN(me->core_size, 16);
7065- me->arch.got_offset = me->core_size;
7066- me->core_size += gots * sizeof(struct got_entry);
7067+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7068+ me->arch.got_offset = me->core_size_rw;
7069+ me->core_size_rw += gots * sizeof(struct got_entry);
7070
7071- me->core_size = ALIGN(me->core_size, 16);
7072- me->arch.fdesc_offset = me->core_size;
7073- me->core_size += fdescs * sizeof(Elf_Fdesc);
7074+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7075+ me->arch.fdesc_offset = me->core_size_rw;
7076+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7077
7078 me->arch.got_max = gots;
7079 me->arch.fdesc_max = fdescs;
7080@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7081
7082 BUG_ON(value == 0);
7083
7084- got = me->module_core + me->arch.got_offset;
7085+ got = me->module_core_rw + me->arch.got_offset;
7086 for (i = 0; got[i].addr; i++)
7087 if (got[i].addr == value)
7088 goto out;
7089@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7090 #ifdef CONFIG_64BIT
7091 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7092 {
7093- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7094+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7095
7096 if (!value) {
7097 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7098@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7099
7100 /* Create new one */
7101 fdesc->addr = value;
7102- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7103+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7104 return (Elf_Addr)fdesc;
7105 }
7106 #endif /* CONFIG_64BIT */
7107@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7108
7109 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7110 end = table + sechdrs[me->arch.unwind_section].sh_size;
7111- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7112+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7113
7114 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7115 me->arch.unwind_section, table, end, gp);
7116diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7117index 5dfd248..64914ac 100644
7118--- a/arch/parisc/kernel/sys_parisc.c
7119+++ b/arch/parisc/kernel/sys_parisc.c
7120@@ -33,9 +33,11 @@
7121 #include <linux/utsname.h>
7122 #include <linux/personality.h>
7123
7124-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7125+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
7126+ unsigned long flags)
7127 {
7128 struct vm_unmapped_area_info info;
7129+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7130
7131 info.flags = 0;
7132 info.length = len;
7133@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7134 info.high_limit = TASK_SIZE;
7135 info.align_mask = 0;
7136 info.align_offset = 0;
7137+ info.threadstack_offset = offset;
7138 return vm_unmapped_area(&info);
7139 }
7140
7141@@ -61,10 +64,11 @@ static int get_offset(struct address_space *mapping)
7142 return (unsigned long) mapping >> 8;
7143 }
7144
7145-static unsigned long get_shared_area(struct address_space *mapping,
7146- unsigned long addr, unsigned long len, unsigned long pgoff)
7147+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
7148+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
7149 {
7150 struct vm_unmapped_area_info info;
7151+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7152
7153 info.flags = 0;
7154 info.length = len;
7155@@ -72,6 +76,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
7156 info.high_limit = TASK_SIZE;
7157 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7158 info.align_offset = (get_offset(mapping) + pgoff) << PAGE_SHIFT;
7159+ info.threadstack_offset = offset;
7160 return vm_unmapped_area(&info);
7161 }
7162
7163@@ -86,15 +91,22 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7164 return -EINVAL;
7165 return addr;
7166 }
7167- if (!addr)
7168+ if (!addr) {
7169 addr = TASK_UNMAPPED_BASE;
7170
7171+#ifdef CONFIG_PAX_RANDMMAP
7172+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7173+ addr += current->mm->delta_mmap;
7174+#endif
7175+
7176+ }
7177+
7178 if (filp) {
7179- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
7180+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
7181 } else if(flags & MAP_SHARED) {
7182- addr = get_shared_area(NULL, addr, len, pgoff);
7183+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
7184 } else {
7185- addr = get_unshared_area(addr, len);
7186+ addr = get_unshared_area(filp, addr, len, flags);
7187 }
7188 return addr;
7189 }
7190diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7191index 04e47c6..7a8faf6 100644
7192--- a/arch/parisc/kernel/traps.c
7193+++ b/arch/parisc/kernel/traps.c
7194@@ -727,9 +727,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7195
7196 down_read(&current->mm->mmap_sem);
7197 vma = find_vma(current->mm,regs->iaoq[0]);
7198- if (vma && (regs->iaoq[0] >= vma->vm_start)
7199- && (vma->vm_flags & VM_EXEC)) {
7200-
7201+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7202 fault_address = regs->iaoq[0];
7203 fault_space = regs->iasq[0];
7204
7205diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7206index f247a34..dc0f219 100644
7207--- a/arch/parisc/mm/fault.c
7208+++ b/arch/parisc/mm/fault.c
7209@@ -15,6 +15,7 @@
7210 #include <linux/sched.h>
7211 #include <linux/interrupt.h>
7212 #include <linux/module.h>
7213+#include <linux/unistd.h>
7214
7215 #include <asm/uaccess.h>
7216 #include <asm/traps.h>
7217@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7218 static unsigned long
7219 parisc_acctyp(unsigned long code, unsigned int inst)
7220 {
7221- if (code == 6 || code == 16)
7222+ if (code == 6 || code == 7 || code == 16)
7223 return VM_EXEC;
7224
7225 switch (inst & 0xf0000000) {
7226@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7227 }
7228 #endif
7229
7230+#ifdef CONFIG_PAX_PAGEEXEC
7231+/*
7232+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7233+ *
7234+ * returns 1 when task should be killed
7235+ * 2 when rt_sigreturn trampoline was detected
7236+ * 3 when unpatched PLT trampoline was detected
7237+ */
7238+static int pax_handle_fetch_fault(struct pt_regs *regs)
7239+{
7240+
7241+#ifdef CONFIG_PAX_EMUPLT
7242+ int err;
7243+
7244+ do { /* PaX: unpatched PLT emulation */
7245+ unsigned int bl, depwi;
7246+
7247+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7248+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7249+
7250+ if (err)
7251+ break;
7252+
7253+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7254+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7255+
7256+ err = get_user(ldw, (unsigned int *)addr);
7257+ err |= get_user(bv, (unsigned int *)(addr+4));
7258+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7259+
7260+ if (err)
7261+ break;
7262+
7263+ if (ldw == 0x0E801096U &&
7264+ bv == 0xEAC0C000U &&
7265+ ldw2 == 0x0E881095U)
7266+ {
7267+ unsigned int resolver, map;
7268+
7269+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7270+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7271+ if (err)
7272+ break;
7273+
7274+ regs->gr[20] = instruction_pointer(regs)+8;
7275+ regs->gr[21] = map;
7276+ regs->gr[22] = resolver;
7277+ regs->iaoq[0] = resolver | 3UL;
7278+ regs->iaoq[1] = regs->iaoq[0] + 4;
7279+ return 3;
7280+ }
7281+ }
7282+ } while (0);
7283+#endif
7284+
7285+#ifdef CONFIG_PAX_EMUTRAMP
7286+
7287+#ifndef CONFIG_PAX_EMUSIGRT
7288+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7289+ return 1;
7290+#endif
7291+
7292+ do { /* PaX: rt_sigreturn emulation */
7293+ unsigned int ldi1, ldi2, bel, nop;
7294+
7295+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7296+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7297+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7298+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7299+
7300+ if (err)
7301+ break;
7302+
7303+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7304+ ldi2 == 0x3414015AU &&
7305+ bel == 0xE4008200U &&
7306+ nop == 0x08000240U)
7307+ {
7308+ regs->gr[25] = (ldi1 & 2) >> 1;
7309+ regs->gr[20] = __NR_rt_sigreturn;
7310+ regs->gr[31] = regs->iaoq[1] + 16;
7311+ regs->sr[0] = regs->iasq[1];
7312+ regs->iaoq[0] = 0x100UL;
7313+ regs->iaoq[1] = regs->iaoq[0] + 4;
7314+ regs->iasq[0] = regs->sr[2];
7315+ regs->iasq[1] = regs->sr[2];
7316+ return 2;
7317+ }
7318+ } while (0);
7319+#endif
7320+
7321+ return 1;
7322+}
7323+
7324+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7325+{
7326+ unsigned long i;
7327+
7328+ printk(KERN_ERR "PAX: bytes at PC: ");
7329+ for (i = 0; i < 5; i++) {
7330+ unsigned int c;
7331+ if (get_user(c, (unsigned int *)pc+i))
7332+ printk(KERN_CONT "???????? ");
7333+ else
7334+ printk(KERN_CONT "%08x ", c);
7335+ }
7336+ printk("\n");
7337+}
7338+#endif
7339+
7340 int fixup_exception(struct pt_regs *regs)
7341 {
7342 const struct exception_table_entry *fix;
7343@@ -194,8 +305,33 @@ good_area:
7344
7345 acc_type = parisc_acctyp(code,regs->iir);
7346
7347- if ((vma->vm_flags & acc_type) != acc_type)
7348+ if ((vma->vm_flags & acc_type) != acc_type) {
7349+
7350+#ifdef CONFIG_PAX_PAGEEXEC
7351+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7352+ (address & ~3UL) == instruction_pointer(regs))
7353+ {
7354+ up_read(&mm->mmap_sem);
7355+ switch (pax_handle_fetch_fault(regs)) {
7356+
7357+#ifdef CONFIG_PAX_EMUPLT
7358+ case 3:
7359+ return;
7360+#endif
7361+
7362+#ifdef CONFIG_PAX_EMUTRAMP
7363+ case 2:
7364+ return;
7365+#endif
7366+
7367+ }
7368+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7369+ do_group_exit(SIGKILL);
7370+ }
7371+#endif
7372+
7373 goto bad_area;
7374+ }
7375
7376 /*
7377 * If for any reason at all we couldn't handle the fault, make
7378diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7379index e3b1d41..8e81edf 100644
7380--- a/arch/powerpc/include/asm/atomic.h
7381+++ b/arch/powerpc/include/asm/atomic.h
7382@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7383 return t1;
7384 }
7385
7386+#define atomic64_read_unchecked(v) atomic64_read(v)
7387+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7388+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7389+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7390+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7391+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7392+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7393+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7394+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7395+
7396 #endif /* __powerpc64__ */
7397
7398 #endif /* __KERNEL__ */
7399diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7400index 9e495c9..b6878e5 100644
7401--- a/arch/powerpc/include/asm/cache.h
7402+++ b/arch/powerpc/include/asm/cache.h
7403@@ -3,6 +3,7 @@
7404
7405 #ifdef __KERNEL__
7406
7407+#include <linux/const.h>
7408
7409 /* bytes per L1 cache line */
7410 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7411@@ -22,7 +23,7 @@
7412 #define L1_CACHE_SHIFT 7
7413 #endif
7414
7415-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7416+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7417
7418 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7419
7420diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7421index cc0655a..13eac2e 100644
7422--- a/arch/powerpc/include/asm/elf.h
7423+++ b/arch/powerpc/include/asm/elf.h
7424@@ -28,8 +28,19 @@
7425 the loader. We need to make sure that it is out of the way of the program
7426 that it will "exec", and that there is sufficient room for the brk. */
7427
7428-extern unsigned long randomize_et_dyn(unsigned long base);
7429-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7430+#define ELF_ET_DYN_BASE (0x20000000)
7431+
7432+#ifdef CONFIG_PAX_ASLR
7433+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7434+
7435+#ifdef __powerpc64__
7436+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7437+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7438+#else
7439+#define PAX_DELTA_MMAP_LEN 15
7440+#define PAX_DELTA_STACK_LEN 15
7441+#endif
7442+#endif
7443
7444 /*
7445 * Our registers are always unsigned longs, whether we're a 32 bit
7446@@ -123,10 +134,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7447 (0x7ff >> (PAGE_SHIFT - 12)) : \
7448 (0x3ffff >> (PAGE_SHIFT - 12)))
7449
7450-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7451-#define arch_randomize_brk arch_randomize_brk
7452-
7453-
7454 #ifdef CONFIG_SPU_BASE
7455 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7456 #define NT_SPU 1
7457diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7458index 8196e9c..d83a9f3 100644
7459--- a/arch/powerpc/include/asm/exec.h
7460+++ b/arch/powerpc/include/asm/exec.h
7461@@ -4,6 +4,6 @@
7462 #ifndef _ASM_POWERPC_EXEC_H
7463 #define _ASM_POWERPC_EXEC_H
7464
7465-extern unsigned long arch_align_stack(unsigned long sp);
7466+#define arch_align_stack(x) ((x) & ~0xfUL)
7467
7468 #endif /* _ASM_POWERPC_EXEC_H */
7469diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7470index 5acabbd..7ea14fa 100644
7471--- a/arch/powerpc/include/asm/kmap_types.h
7472+++ b/arch/powerpc/include/asm/kmap_types.h
7473@@ -10,7 +10,7 @@
7474 * 2 of the License, or (at your option) any later version.
7475 */
7476
7477-#define KM_TYPE_NR 16
7478+#define KM_TYPE_NR 17
7479
7480 #endif /* __KERNEL__ */
7481 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7482diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
7483index 8565c25..2865190 100644
7484--- a/arch/powerpc/include/asm/mman.h
7485+++ b/arch/powerpc/include/asm/mman.h
7486@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
7487 }
7488 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
7489
7490-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
7491+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
7492 {
7493 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
7494 }
7495diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
7496index b9f4262..dcf04f7 100644
7497--- a/arch/powerpc/include/asm/page.h
7498+++ b/arch/powerpc/include/asm/page.h
7499@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
7500 * and needs to be executable. This means the whole heap ends
7501 * up being executable.
7502 */
7503-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7504- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7505+#define VM_DATA_DEFAULT_FLAGS32 \
7506+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7507+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7508
7509 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7510 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7511@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
7512 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
7513 #endif
7514
7515+#define ktla_ktva(addr) (addr)
7516+#define ktva_ktla(addr) (addr)
7517+
7518 #ifndef CONFIG_PPC_BOOK3S_64
7519 /*
7520 * Use the top bit of the higher-level page table entries to indicate whether
7521diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
7522index 88693ce..ac6f9ab 100644
7523--- a/arch/powerpc/include/asm/page_64.h
7524+++ b/arch/powerpc/include/asm/page_64.h
7525@@ -153,15 +153,18 @@ do { \
7526 * stack by default, so in the absence of a PT_GNU_STACK program header
7527 * we turn execute permission off.
7528 */
7529-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7530- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7531+#define VM_STACK_DEFAULT_FLAGS32 \
7532+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7533+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7534
7535 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7536 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7537
7538+#ifndef CONFIG_PAX_PAGEEXEC
7539 #define VM_STACK_DEFAULT_FLAGS \
7540 (is_32bit_task() ? \
7541 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
7542+#endif
7543
7544 #include <asm-generic/getorder.h>
7545
7546diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
7547index f65e27b..23ffb5b 100644
7548--- a/arch/powerpc/include/asm/pgalloc-64.h
7549+++ b/arch/powerpc/include/asm/pgalloc-64.h
7550@@ -53,6 +53,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7551 #ifndef CONFIG_PPC_64K_PAGES
7552
7553 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
7554+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
7555
7556 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
7557 {
7558@@ -70,6 +71,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7559 pud_set(pud, (unsigned long)pmd);
7560 }
7561
7562+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7563+{
7564+ pud_populate(mm, pud, pmd);
7565+}
7566+
7567 #define pmd_populate(mm, pmd, pte_page) \
7568 pmd_populate_kernel(mm, pmd, page_address(pte_page))
7569 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
7570@@ -171,6 +177,7 @@ extern void __tlb_remove_table(void *_table);
7571 #endif
7572
7573 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
7574+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7575
7576 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
7577 pte_t *pte)
7578diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
7579index 7d6eacf..14c0240 100644
7580--- a/arch/powerpc/include/asm/pgtable.h
7581+++ b/arch/powerpc/include/asm/pgtable.h
7582@@ -2,6 +2,7 @@
7583 #define _ASM_POWERPC_PGTABLE_H
7584 #ifdef __KERNEL__
7585
7586+#include <linux/const.h>
7587 #ifndef __ASSEMBLY__
7588 #include <asm/processor.h> /* For TASK_SIZE */
7589 #include <asm/mmu.h>
7590diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
7591index 4aad413..85d86bf 100644
7592--- a/arch/powerpc/include/asm/pte-hash32.h
7593+++ b/arch/powerpc/include/asm/pte-hash32.h
7594@@ -21,6 +21,7 @@
7595 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
7596 #define _PAGE_USER 0x004 /* usermode access allowed */
7597 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
7598+#define _PAGE_EXEC _PAGE_GUARDED
7599 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
7600 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
7601 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
7602diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
7603index 99222e2..f629aef 100644
7604--- a/arch/powerpc/include/asm/reg.h
7605+++ b/arch/powerpc/include/asm/reg.h
7606@@ -234,6 +234,7 @@
7607 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
7608 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
7609 #define DSISR_NOHPTE 0x40000000 /* no translation found */
7610+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
7611 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
7612 #define DSISR_ISSTORE 0x02000000 /* access was a store */
7613 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
7614diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
7615index 48cfc85..891382f 100644
7616--- a/arch/powerpc/include/asm/smp.h
7617+++ b/arch/powerpc/include/asm/smp.h
7618@@ -50,7 +50,7 @@ struct smp_ops_t {
7619 int (*cpu_disable)(void);
7620 void (*cpu_die)(unsigned int nr);
7621 int (*cpu_bootable)(unsigned int nr);
7622-};
7623+} __no_const;
7624
7625 extern void smp_send_debugger_break(void);
7626 extern void start_secondary_resume(void);
7627diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
7628index ba7b197..d292e26 100644
7629--- a/arch/powerpc/include/asm/thread_info.h
7630+++ b/arch/powerpc/include/asm/thread_info.h
7631@@ -93,7 +93,6 @@ static inline struct thread_info *current_thread_info(void)
7632 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
7633 TIF_NEED_RESCHED */
7634 #define TIF_32BIT 4 /* 32 bit binary */
7635-#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
7636 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
7637 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
7638 #define TIF_SINGLESTEP 8 /* singlestepping active */
7639@@ -107,6 +106,9 @@ static inline struct thread_info *current_thread_info(void)
7640 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
7641 for stack store? */
7642 #define TIF_MEMDIE 17 /* is terminating due to OOM killer */
7643+#define TIF_PERFMON_WORK 18 /* work for pfm_handle_work() */
7644+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
7645+#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
7646
7647 /* as above, but as bit values */
7648 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
7649@@ -126,9 +128,10 @@ static inline struct thread_info *current_thread_info(void)
7650 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7651 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
7652 #define _TIF_NOHZ (1<<TIF_NOHZ)
7653+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7654 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
7655 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
7656- _TIF_NOHZ)
7657+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
7658
7659 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
7660 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
7661diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
7662index 9485b43..4718d50 100644
7663--- a/arch/powerpc/include/asm/uaccess.h
7664+++ b/arch/powerpc/include/asm/uaccess.h
7665@@ -318,52 +318,6 @@ do { \
7666 extern unsigned long __copy_tofrom_user(void __user *to,
7667 const void __user *from, unsigned long size);
7668
7669-#ifndef __powerpc64__
7670-
7671-static inline unsigned long copy_from_user(void *to,
7672- const void __user *from, unsigned long n)
7673-{
7674- unsigned long over;
7675-
7676- if (access_ok(VERIFY_READ, from, n))
7677- return __copy_tofrom_user((__force void __user *)to, from, n);
7678- if ((unsigned long)from < TASK_SIZE) {
7679- over = (unsigned long)from + n - TASK_SIZE;
7680- return __copy_tofrom_user((__force void __user *)to, from,
7681- n - over) + over;
7682- }
7683- return n;
7684-}
7685-
7686-static inline unsigned long copy_to_user(void __user *to,
7687- const void *from, unsigned long n)
7688-{
7689- unsigned long over;
7690-
7691- if (access_ok(VERIFY_WRITE, to, n))
7692- return __copy_tofrom_user(to, (__force void __user *)from, n);
7693- if ((unsigned long)to < TASK_SIZE) {
7694- over = (unsigned long)to + n - TASK_SIZE;
7695- return __copy_tofrom_user(to, (__force void __user *)from,
7696- n - over) + over;
7697- }
7698- return n;
7699-}
7700-
7701-#else /* __powerpc64__ */
7702-
7703-#define __copy_in_user(to, from, size) \
7704- __copy_tofrom_user((to), (from), (size))
7705-
7706-extern unsigned long copy_from_user(void *to, const void __user *from,
7707- unsigned long n);
7708-extern unsigned long copy_to_user(void __user *to, const void *from,
7709- unsigned long n);
7710-extern unsigned long copy_in_user(void __user *to, const void __user *from,
7711- unsigned long n);
7712-
7713-#endif /* __powerpc64__ */
7714-
7715 static inline unsigned long __copy_from_user_inatomic(void *to,
7716 const void __user *from, unsigned long n)
7717 {
7718@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
7719 if (ret == 0)
7720 return 0;
7721 }
7722+
7723+ if (!__builtin_constant_p(n))
7724+ check_object_size(to, n, false);
7725+
7726 return __copy_tofrom_user((__force void __user *)to, from, n);
7727 }
7728
7729@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
7730 if (ret == 0)
7731 return 0;
7732 }
7733+
7734+ if (!__builtin_constant_p(n))
7735+ check_object_size(from, n, true);
7736+
7737 return __copy_tofrom_user(to, (__force const void __user *)from, n);
7738 }
7739
7740@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
7741 return __copy_to_user_inatomic(to, from, size);
7742 }
7743
7744+#ifndef __powerpc64__
7745+
7746+static inline unsigned long __must_check copy_from_user(void *to,
7747+ const void __user *from, unsigned long n)
7748+{
7749+ unsigned long over;
7750+
7751+ if ((long)n < 0)
7752+ return n;
7753+
7754+ if (access_ok(VERIFY_READ, from, n)) {
7755+ if (!__builtin_constant_p(n))
7756+ check_object_size(to, n, false);
7757+ return __copy_tofrom_user((__force void __user *)to, from, n);
7758+ }
7759+ if ((unsigned long)from < TASK_SIZE) {
7760+ over = (unsigned long)from + n - TASK_SIZE;
7761+ if (!__builtin_constant_p(n - over))
7762+ check_object_size(to, n - over, false);
7763+ return __copy_tofrom_user((__force void __user *)to, from,
7764+ n - over) + over;
7765+ }
7766+ return n;
7767+}
7768+
7769+static inline unsigned long __must_check copy_to_user(void __user *to,
7770+ const void *from, unsigned long n)
7771+{
7772+ unsigned long over;
7773+
7774+ if ((long)n < 0)
7775+ return n;
7776+
7777+ if (access_ok(VERIFY_WRITE, to, n)) {
7778+ if (!__builtin_constant_p(n))
7779+ check_object_size(from, n, true);
7780+ return __copy_tofrom_user(to, (__force void __user *)from, n);
7781+ }
7782+ if ((unsigned long)to < TASK_SIZE) {
7783+ over = (unsigned long)to + n - TASK_SIZE;
7784+ if (!__builtin_constant_p(n))
7785+ check_object_size(from, n - over, true);
7786+ return __copy_tofrom_user(to, (__force void __user *)from,
7787+ n - over) + over;
7788+ }
7789+ return n;
7790+}
7791+
7792+#else /* __powerpc64__ */
7793+
7794+#define __copy_in_user(to, from, size) \
7795+ __copy_tofrom_user((to), (from), (size))
7796+
7797+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
7798+{
7799+ if ((long)n < 0 || n > INT_MAX)
7800+ return n;
7801+
7802+ if (!__builtin_constant_p(n))
7803+ check_object_size(to, n, false);
7804+
7805+ if (likely(access_ok(VERIFY_READ, from, n)))
7806+ n = __copy_from_user(to, from, n);
7807+ else
7808+ memset(to, 0, n);
7809+ return n;
7810+}
7811+
7812+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
7813+{
7814+ if ((long)n < 0 || n > INT_MAX)
7815+ return n;
7816+
7817+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
7818+ if (!__builtin_constant_p(n))
7819+ check_object_size(from, n, true);
7820+ n = __copy_to_user(to, from, n);
7821+ }
7822+ return n;
7823+}
7824+
7825+extern unsigned long copy_in_user(void __user *to, const void __user *from,
7826+ unsigned long n);
7827+
7828+#endif /* __powerpc64__ */
7829+
7830 extern unsigned long __clear_user(void __user *addr, unsigned long size);
7831
7832 static inline unsigned long clear_user(void __user *addr, unsigned long size)
7833diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
7834index 645170a..6cf0271 100644
7835--- a/arch/powerpc/kernel/exceptions-64e.S
7836+++ b/arch/powerpc/kernel/exceptions-64e.S
7837@@ -757,6 +757,7 @@ storage_fault_common:
7838 std r14,_DAR(r1)
7839 std r15,_DSISR(r1)
7840 addi r3,r1,STACK_FRAME_OVERHEAD
7841+ bl .save_nvgprs
7842 mr r4,r14
7843 mr r5,r15
7844 ld r14,PACA_EXGEN+EX_R14(r13)
7845@@ -765,8 +766,7 @@ storage_fault_common:
7846 cmpdi r3,0
7847 bne- 1f
7848 b .ret_from_except_lite
7849-1: bl .save_nvgprs
7850- mr r5,r3
7851+1: mr r5,r3
7852 addi r3,r1,STACK_FRAME_OVERHEAD
7853 ld r4,_DAR(r1)
7854 bl .bad_page_fault
7855diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
7856index 902ca3c..e942155 100644
7857--- a/arch/powerpc/kernel/exceptions-64s.S
7858+++ b/arch/powerpc/kernel/exceptions-64s.S
7859@@ -1357,10 +1357,10 @@ handle_page_fault:
7860 11: ld r4,_DAR(r1)
7861 ld r5,_DSISR(r1)
7862 addi r3,r1,STACK_FRAME_OVERHEAD
7863+ bl .save_nvgprs
7864 bl .do_page_fault
7865 cmpdi r3,0
7866 beq+ 12f
7867- bl .save_nvgprs
7868 mr r5,r3
7869 addi r3,r1,STACK_FRAME_OVERHEAD
7870 lwz r4,_DAR(r1)
7871diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
7872index 2e3200c..72095ce 100644
7873--- a/arch/powerpc/kernel/module_32.c
7874+++ b/arch/powerpc/kernel/module_32.c
7875@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
7876 me->arch.core_plt_section = i;
7877 }
7878 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
7879- printk("Module doesn't contain .plt or .init.plt sections.\n");
7880+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
7881 return -ENOEXEC;
7882 }
7883
7884@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
7885
7886 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
7887 /* Init, or core PLT? */
7888- if (location >= mod->module_core
7889- && location < mod->module_core + mod->core_size)
7890+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
7891+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
7892 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
7893- else
7894+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
7895+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
7896 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
7897+ else {
7898+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
7899+ return ~0UL;
7900+ }
7901
7902 /* Find this entry, or if that fails, the next avail. entry */
7903 while (entry->jump[0]) {
7904diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
7905index 8083be2..10aa352 100644
7906--- a/arch/powerpc/kernel/process.c
7907+++ b/arch/powerpc/kernel/process.c
7908@@ -884,8 +884,8 @@ void show_regs(struct pt_regs * regs)
7909 * Lookup NIP late so we have the best change of getting the
7910 * above info out without failing
7911 */
7912- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
7913- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
7914+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
7915+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
7916 #endif
7917 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
7918 printk("PACATMSCRATCH [%llx]\n", get_paca()->tm_scratch);
7919@@ -1349,10 +1349,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
7920 newsp = stack[0];
7921 ip = stack[STACK_FRAME_LR_SAVE];
7922 if (!firstframe || ip != lr) {
7923- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
7924+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
7925 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
7926 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
7927- printk(" (%pS)",
7928+ printk(" (%pA)",
7929 (void *)current->ret_stack[curr_frame].ret);
7930 curr_frame--;
7931 }
7932@@ -1372,7 +1372,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
7933 struct pt_regs *regs = (struct pt_regs *)
7934 (sp + STACK_FRAME_OVERHEAD);
7935 lr = regs->link;
7936- printk("--- Exception: %lx at %pS\n LR = %pS\n",
7937+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
7938 regs->trap, (void *)regs->nip, (void *)lr);
7939 firstframe = 1;
7940 }
7941@@ -1408,58 +1408,3 @@ void notrace __ppc64_runlatch_off(void)
7942 mtspr(SPRN_CTRLT, ctrl);
7943 }
7944 #endif /* CONFIG_PPC64 */
7945-
7946-unsigned long arch_align_stack(unsigned long sp)
7947-{
7948- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7949- sp -= get_random_int() & ~PAGE_MASK;
7950- return sp & ~0xf;
7951-}
7952-
7953-static inline unsigned long brk_rnd(void)
7954-{
7955- unsigned long rnd = 0;
7956-
7957- /* 8MB for 32bit, 1GB for 64bit */
7958- if (is_32bit_task())
7959- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
7960- else
7961- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
7962-
7963- return rnd << PAGE_SHIFT;
7964-}
7965-
7966-unsigned long arch_randomize_brk(struct mm_struct *mm)
7967-{
7968- unsigned long base = mm->brk;
7969- unsigned long ret;
7970-
7971-#ifdef CONFIG_PPC_STD_MMU_64
7972- /*
7973- * If we are using 1TB segments and we are allowed to randomise
7974- * the heap, we can put it above 1TB so it is backed by a 1TB
7975- * segment. Otherwise the heap will be in the bottom 1TB
7976- * which always uses 256MB segments and this may result in a
7977- * performance penalty.
7978- */
7979- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
7980- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
7981-#endif
7982-
7983- ret = PAGE_ALIGN(base + brk_rnd());
7984-
7985- if (ret < mm->brk)
7986- return mm->brk;
7987-
7988- return ret;
7989-}
7990-
7991-unsigned long randomize_et_dyn(unsigned long base)
7992-{
7993- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7994-
7995- if (ret < base)
7996- return base;
7997-
7998- return ret;
7999-}
8000diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8001index 9a0d24c..e7fbedf 100644
8002--- a/arch/powerpc/kernel/ptrace.c
8003+++ b/arch/powerpc/kernel/ptrace.c
8004@@ -1761,6 +1761,10 @@ long arch_ptrace(struct task_struct *child, long request,
8005 return ret;
8006 }
8007
8008+#ifdef CONFIG_GRKERNSEC_SETXID
8009+extern void gr_delayed_cred_worker(void);
8010+#endif
8011+
8012 /*
8013 * We must return the syscall number to actually look up in the table.
8014 * This can be -1L to skip running any syscall at all.
8015@@ -1773,6 +1777,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8016
8017 secure_computing_strict(regs->gpr[0]);
8018
8019+#ifdef CONFIG_GRKERNSEC_SETXID
8020+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8021+ gr_delayed_cred_worker();
8022+#endif
8023+
8024 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8025 tracehook_report_syscall_entry(regs))
8026 /*
8027@@ -1807,6 +1816,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8028 {
8029 int step;
8030
8031+#ifdef CONFIG_GRKERNSEC_SETXID
8032+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8033+ gr_delayed_cred_worker();
8034+#endif
8035+
8036 audit_syscall_exit(regs);
8037
8038 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8039diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8040index 0f83122..c0aca6a 100644
8041--- a/arch/powerpc/kernel/signal_32.c
8042+++ b/arch/powerpc/kernel/signal_32.c
8043@@ -987,7 +987,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8044 /* Save user registers on the stack */
8045 frame = &rt_sf->uc.uc_mcontext;
8046 addr = frame;
8047- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8048+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8049 sigret = 0;
8050 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8051 } else {
8052diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8053index 887e99d..310bc11 100644
8054--- a/arch/powerpc/kernel/signal_64.c
8055+++ b/arch/powerpc/kernel/signal_64.c
8056@@ -751,7 +751,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8057 #endif
8058
8059 /* Set up to return from userspace. */
8060- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8061+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8062 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8063 } else {
8064 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8065diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8066index e435bc0..41c2964 100644
8067--- a/arch/powerpc/kernel/traps.c
8068+++ b/arch/powerpc/kernel/traps.c
8069@@ -141,6 +141,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8070 return flags;
8071 }
8072
8073+extern void gr_handle_kernel_exploit(void);
8074+
8075 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8076 int signr)
8077 {
8078@@ -190,6 +192,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8079 panic("Fatal exception in interrupt");
8080 if (panic_on_oops)
8081 panic("Fatal exception");
8082+
8083+ gr_handle_kernel_exploit();
8084+
8085 do_exit(signr);
8086 }
8087
8088diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8089index 1d9c926..25f4741 100644
8090--- a/arch/powerpc/kernel/vdso.c
8091+++ b/arch/powerpc/kernel/vdso.c
8092@@ -34,6 +34,7 @@
8093 #include <asm/firmware.h>
8094 #include <asm/vdso.h>
8095 #include <asm/vdso_datapage.h>
8096+#include <asm/mman.h>
8097
8098 #include "setup.h"
8099
8100@@ -222,7 +223,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8101 vdso_base = VDSO32_MBASE;
8102 #endif
8103
8104- current->mm->context.vdso_base = 0;
8105+ current->mm->context.vdso_base = ~0UL;
8106
8107 /* vDSO has a problem and was disabled, just don't "enable" it for the
8108 * process
8109@@ -242,7 +243,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8110 vdso_base = get_unmapped_area(NULL, vdso_base,
8111 (vdso_pages << PAGE_SHIFT) +
8112 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8113- 0, 0);
8114+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8115 if (IS_ERR_VALUE(vdso_base)) {
8116 rc = vdso_base;
8117 goto fail_mmapsem;
8118diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8119index 5eea6f3..5d10396 100644
8120--- a/arch/powerpc/lib/usercopy_64.c
8121+++ b/arch/powerpc/lib/usercopy_64.c
8122@@ -9,22 +9,6 @@
8123 #include <linux/module.h>
8124 #include <asm/uaccess.h>
8125
8126-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8127-{
8128- if (likely(access_ok(VERIFY_READ, from, n)))
8129- n = __copy_from_user(to, from, n);
8130- else
8131- memset(to, 0, n);
8132- return n;
8133-}
8134-
8135-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8136-{
8137- if (likely(access_ok(VERIFY_WRITE, to, n)))
8138- n = __copy_to_user(to, from, n);
8139- return n;
8140-}
8141-
8142 unsigned long copy_in_user(void __user *to, const void __user *from,
8143 unsigned long n)
8144 {
8145@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8146 return n;
8147 }
8148
8149-EXPORT_SYMBOL(copy_from_user);
8150-EXPORT_SYMBOL(copy_to_user);
8151 EXPORT_SYMBOL(copy_in_user);
8152
8153diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8154index 8726779..a33c512 100644
8155--- a/arch/powerpc/mm/fault.c
8156+++ b/arch/powerpc/mm/fault.c
8157@@ -33,6 +33,10 @@
8158 #include <linux/magic.h>
8159 #include <linux/ratelimit.h>
8160 #include <linux/context_tracking.h>
8161+#include <linux/slab.h>
8162+#include <linux/pagemap.h>
8163+#include <linux/compiler.h>
8164+#include <linux/unistd.h>
8165
8166 #include <asm/firmware.h>
8167 #include <asm/page.h>
8168@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8169 }
8170 #endif
8171
8172+#ifdef CONFIG_PAX_PAGEEXEC
8173+/*
8174+ * PaX: decide what to do with offenders (regs->nip = fault address)
8175+ *
8176+ * returns 1 when task should be killed
8177+ */
8178+static int pax_handle_fetch_fault(struct pt_regs *regs)
8179+{
8180+ return 1;
8181+}
8182+
8183+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8184+{
8185+ unsigned long i;
8186+
8187+ printk(KERN_ERR "PAX: bytes at PC: ");
8188+ for (i = 0; i < 5; i++) {
8189+ unsigned int c;
8190+ if (get_user(c, (unsigned int __user *)pc+i))
8191+ printk(KERN_CONT "???????? ");
8192+ else
8193+ printk(KERN_CONT "%08x ", c);
8194+ }
8195+ printk("\n");
8196+}
8197+#endif
8198+
8199 /*
8200 * Check whether the instruction at regs->nip is a store using
8201 * an update addressing form which will update r1.
8202@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8203 * indicate errors in DSISR but can validly be set in SRR1.
8204 */
8205 if (trap == 0x400)
8206- error_code &= 0x48200000;
8207+ error_code &= 0x58200000;
8208 else
8209 is_write = error_code & DSISR_ISSTORE;
8210 #else
8211@@ -371,7 +402,7 @@ good_area:
8212 * "undefined". Of those that can be set, this is the only
8213 * one which seems bad.
8214 */
8215- if (error_code & 0x10000000)
8216+ if (error_code & DSISR_GUARDED)
8217 /* Guarded storage error. */
8218 goto bad_area;
8219 #endif /* CONFIG_8xx */
8220@@ -386,7 +417,7 @@ good_area:
8221 * processors use the same I/D cache coherency mechanism
8222 * as embedded.
8223 */
8224- if (error_code & DSISR_PROTFAULT)
8225+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8226 goto bad_area;
8227 #endif /* CONFIG_PPC_STD_MMU */
8228
8229@@ -471,6 +502,23 @@ bad_area:
8230 bad_area_nosemaphore:
8231 /* User mode accesses cause a SIGSEGV */
8232 if (user_mode(regs)) {
8233+
8234+#ifdef CONFIG_PAX_PAGEEXEC
8235+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8236+#ifdef CONFIG_PPC_STD_MMU
8237+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8238+#else
8239+ if (is_exec && regs->nip == address) {
8240+#endif
8241+ switch (pax_handle_fetch_fault(regs)) {
8242+ }
8243+
8244+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8245+ do_group_exit(SIGKILL);
8246+ }
8247+ }
8248+#endif
8249+
8250 _exception(SIGSEGV, regs, code, address);
8251 goto bail;
8252 }
8253diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8254index cb8bdbe..d770680 100644
8255--- a/arch/powerpc/mm/mmap.c
8256+++ b/arch/powerpc/mm/mmap.c
8257@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
8258 {
8259 unsigned long rnd = 0;
8260
8261+#ifdef CONFIG_PAX_RANDMMAP
8262+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8263+#endif
8264+
8265 if (current->flags & PF_RANDOMIZE) {
8266 /* 8MB for 32bit, 1GB for 64bit */
8267 if (is_32bit_task())
8268@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8269 */
8270 if (mmap_is_legacy()) {
8271 mm->mmap_base = TASK_UNMAPPED_BASE;
8272+
8273+#ifdef CONFIG_PAX_RANDMMAP
8274+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8275+ mm->mmap_base += mm->delta_mmap;
8276+#endif
8277+
8278 mm->get_unmapped_area = arch_get_unmapped_area;
8279 } else {
8280 mm->mmap_base = mmap_base();
8281+
8282+#ifdef CONFIG_PAX_RANDMMAP
8283+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8284+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8285+#endif
8286+
8287 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8288 }
8289 }
8290diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8291index 3e99c14..f00953c 100644
8292--- a/arch/powerpc/mm/slice.c
8293+++ b/arch/powerpc/mm/slice.c
8294@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8295 if ((mm->task_size - len) < addr)
8296 return 0;
8297 vma = find_vma(mm, addr);
8298- return (!vma || (addr + len) <= vma->vm_start);
8299+ return check_heap_stack_gap(vma, addr, len, 0);
8300 }
8301
8302 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8303@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8304 info.align_offset = 0;
8305
8306 addr = TASK_UNMAPPED_BASE;
8307+
8308+#ifdef CONFIG_PAX_RANDMMAP
8309+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8310+ addr += mm->delta_mmap;
8311+#endif
8312+
8313 while (addr < TASK_SIZE) {
8314 info.low_limit = addr;
8315 if (!slice_scan_available(addr, available, 1, &addr))
8316@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8317 if (fixed && addr > (mm->task_size - len))
8318 return -EINVAL;
8319
8320+#ifdef CONFIG_PAX_RANDMMAP
8321+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8322+ addr = 0;
8323+#endif
8324+
8325 /* If hint, make sure it matches our alignment restrictions */
8326 if (!fixed && addr) {
8327 addr = _ALIGN_UP(addr, 1ul << pshift);
8328diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8329index 9098692..3d54cd1 100644
8330--- a/arch/powerpc/platforms/cell/spufs/file.c
8331+++ b/arch/powerpc/platforms/cell/spufs/file.c
8332@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8333 return VM_FAULT_NOPAGE;
8334 }
8335
8336-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8337+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8338 unsigned long address,
8339- void *buf, int len, int write)
8340+ void *buf, size_t len, int write)
8341 {
8342 struct spu_context *ctx = vma->vm_file->private_data;
8343 unsigned long offset = address - vma->vm_start;
8344diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8345index c797832..ce575c8 100644
8346--- a/arch/s390/include/asm/atomic.h
8347+++ b/arch/s390/include/asm/atomic.h
8348@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8349 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8350 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8351
8352+#define atomic64_read_unchecked(v) atomic64_read(v)
8353+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8354+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8355+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8356+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8357+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8358+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8359+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8360+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8361+
8362 #define smp_mb__before_atomic_dec() smp_mb()
8363 #define smp_mb__after_atomic_dec() smp_mb()
8364 #define smp_mb__before_atomic_inc() smp_mb()
8365diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8366index 4d7ccac..d03d0ad 100644
8367--- a/arch/s390/include/asm/cache.h
8368+++ b/arch/s390/include/asm/cache.h
8369@@ -9,8 +9,10 @@
8370 #ifndef __ARCH_S390_CACHE_H
8371 #define __ARCH_S390_CACHE_H
8372
8373-#define L1_CACHE_BYTES 256
8374+#include <linux/const.h>
8375+
8376 #define L1_CACHE_SHIFT 8
8377+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8378 #define NET_SKB_PAD 32
8379
8380 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8381diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
8382index 78f4f87..598ce39 100644
8383--- a/arch/s390/include/asm/elf.h
8384+++ b/arch/s390/include/asm/elf.h
8385@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
8386 the loader. We need to make sure that it is out of the way of the program
8387 that it will "exec", and that there is sufficient room for the brk. */
8388
8389-extern unsigned long randomize_et_dyn(unsigned long base);
8390-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
8391+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
8392+
8393+#ifdef CONFIG_PAX_ASLR
8394+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
8395+
8396+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8397+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8398+#endif
8399
8400 /* This yields a mask that user programs can use to figure out what
8401 instruction set this CPU supports. */
8402@@ -222,9 +228,6 @@ struct linux_binprm;
8403 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
8404 int arch_setup_additional_pages(struct linux_binprm *, int);
8405
8406-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8407-#define arch_randomize_brk arch_randomize_brk
8408-
8409 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
8410
8411 #endif
8412diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
8413index c4a93d6..4d2a9b4 100644
8414--- a/arch/s390/include/asm/exec.h
8415+++ b/arch/s390/include/asm/exec.h
8416@@ -7,6 +7,6 @@
8417 #ifndef __ASM_EXEC_H
8418 #define __ASM_EXEC_H
8419
8420-extern unsigned long arch_align_stack(unsigned long sp);
8421+#define arch_align_stack(x) ((x) & ~0xfUL)
8422
8423 #endif /* __ASM_EXEC_H */
8424diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
8425index 9c33ed4..e40cbef 100644
8426--- a/arch/s390/include/asm/uaccess.h
8427+++ b/arch/s390/include/asm/uaccess.h
8428@@ -252,6 +252,10 @@ static inline unsigned long __must_check
8429 copy_to_user(void __user *to, const void *from, unsigned long n)
8430 {
8431 might_fault();
8432+
8433+ if ((long)n < 0)
8434+ return n;
8435+
8436 return __copy_to_user(to, from, n);
8437 }
8438
8439@@ -275,6 +279,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
8440 static inline unsigned long __must_check
8441 __copy_from_user(void *to, const void __user *from, unsigned long n)
8442 {
8443+ if ((long)n < 0)
8444+ return n;
8445+
8446 if (__builtin_constant_p(n) && (n <= 256))
8447 return uaccess.copy_from_user_small(n, from, to);
8448 else
8449@@ -306,10 +313,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
8450 static inline unsigned long __must_check
8451 copy_from_user(void *to, const void __user *from, unsigned long n)
8452 {
8453- unsigned int sz = __compiletime_object_size(to);
8454+ size_t sz = __compiletime_object_size(to);
8455
8456 might_fault();
8457- if (unlikely(sz != -1 && sz < n)) {
8458+
8459+ if ((long)n < 0)
8460+ return n;
8461+
8462+ if (unlikely(sz != (size_t)-1 && sz < n)) {
8463 copy_from_user_overflow();
8464 return n;
8465 }
8466diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
8467index 7845e15..59c4353 100644
8468--- a/arch/s390/kernel/module.c
8469+++ b/arch/s390/kernel/module.c
8470@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
8471
8472 /* Increase core size by size of got & plt and set start
8473 offsets for got and plt. */
8474- me->core_size = ALIGN(me->core_size, 4);
8475- me->arch.got_offset = me->core_size;
8476- me->core_size += me->arch.got_size;
8477- me->arch.plt_offset = me->core_size;
8478- me->core_size += me->arch.plt_size;
8479+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
8480+ me->arch.got_offset = me->core_size_rw;
8481+ me->core_size_rw += me->arch.got_size;
8482+ me->arch.plt_offset = me->core_size_rx;
8483+ me->core_size_rx += me->arch.plt_size;
8484 return 0;
8485 }
8486
8487@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8488 if (info->got_initialized == 0) {
8489 Elf_Addr *gotent;
8490
8491- gotent = me->module_core + me->arch.got_offset +
8492+ gotent = me->module_core_rw + me->arch.got_offset +
8493 info->got_offset;
8494 *gotent = val;
8495 info->got_initialized = 1;
8496@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8497 rc = apply_rela_bits(loc, val, 0, 64, 0);
8498 else if (r_type == R_390_GOTENT ||
8499 r_type == R_390_GOTPLTENT) {
8500- val += (Elf_Addr) me->module_core - loc;
8501+ val += (Elf_Addr) me->module_core_rw - loc;
8502 rc = apply_rela_bits(loc, val, 1, 32, 1);
8503 }
8504 break;
8505@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8506 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
8507 if (info->plt_initialized == 0) {
8508 unsigned int *ip;
8509- ip = me->module_core + me->arch.plt_offset +
8510+ ip = me->module_core_rx + me->arch.plt_offset +
8511 info->plt_offset;
8512 #ifndef CONFIG_64BIT
8513 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
8514@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8515 val - loc + 0xffffUL < 0x1ffffeUL) ||
8516 (r_type == R_390_PLT32DBL &&
8517 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
8518- val = (Elf_Addr) me->module_core +
8519+ val = (Elf_Addr) me->module_core_rx +
8520 me->arch.plt_offset +
8521 info->plt_offset;
8522 val += rela->r_addend - loc;
8523@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8524 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
8525 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
8526 val = val + rela->r_addend -
8527- ((Elf_Addr) me->module_core + me->arch.got_offset);
8528+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
8529 if (r_type == R_390_GOTOFF16)
8530 rc = apply_rela_bits(loc, val, 0, 16, 0);
8531 else if (r_type == R_390_GOTOFF32)
8532@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8533 break;
8534 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
8535 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
8536- val = (Elf_Addr) me->module_core + me->arch.got_offset +
8537+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
8538 rela->r_addend - loc;
8539 if (r_type == R_390_GOTPC)
8540 rc = apply_rela_bits(loc, val, 1, 32, 0);
8541diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
8542index 2bc3edd..ab9d598 100644
8543--- a/arch/s390/kernel/process.c
8544+++ b/arch/s390/kernel/process.c
8545@@ -236,39 +236,3 @@ unsigned long get_wchan(struct task_struct *p)
8546 }
8547 return 0;
8548 }
8549-
8550-unsigned long arch_align_stack(unsigned long sp)
8551-{
8552- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8553- sp -= get_random_int() & ~PAGE_MASK;
8554- return sp & ~0xf;
8555-}
8556-
8557-static inline unsigned long brk_rnd(void)
8558-{
8559- /* 8MB for 32bit, 1GB for 64bit */
8560- if (is_32bit_task())
8561- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
8562- else
8563- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
8564-}
8565-
8566-unsigned long arch_randomize_brk(struct mm_struct *mm)
8567-{
8568- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
8569-
8570- if (ret < mm->brk)
8571- return mm->brk;
8572- return ret;
8573-}
8574-
8575-unsigned long randomize_et_dyn(unsigned long base)
8576-{
8577- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8578-
8579- if (!(current->flags & PF_RANDOMIZE))
8580- return base;
8581- if (ret < base)
8582- return base;
8583- return ret;
8584-}
8585diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
8586index 4002329..99b67cb 100644
8587--- a/arch/s390/mm/mmap.c
8588+++ b/arch/s390/mm/mmap.c
8589@@ -90,9 +90,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8590 */
8591 if (mmap_is_legacy()) {
8592 mm->mmap_base = TASK_UNMAPPED_BASE;
8593+
8594+#ifdef CONFIG_PAX_RANDMMAP
8595+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8596+ mm->mmap_base += mm->delta_mmap;
8597+#endif
8598+
8599 mm->get_unmapped_area = arch_get_unmapped_area;
8600 } else {
8601 mm->mmap_base = mmap_base();
8602+
8603+#ifdef CONFIG_PAX_RANDMMAP
8604+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8605+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8606+#endif
8607+
8608 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8609 }
8610 }
8611@@ -173,9 +185,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8612 */
8613 if (mmap_is_legacy()) {
8614 mm->mmap_base = TASK_UNMAPPED_BASE;
8615+
8616+#ifdef CONFIG_PAX_RANDMMAP
8617+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8618+ mm->mmap_base += mm->delta_mmap;
8619+#endif
8620+
8621 mm->get_unmapped_area = s390_get_unmapped_area;
8622 } else {
8623 mm->mmap_base = mmap_base();
8624+
8625+#ifdef CONFIG_PAX_RANDMMAP
8626+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8627+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8628+#endif
8629+
8630 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
8631 }
8632 }
8633diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
8634index ae3d59f..f65f075 100644
8635--- a/arch/score/include/asm/cache.h
8636+++ b/arch/score/include/asm/cache.h
8637@@ -1,7 +1,9 @@
8638 #ifndef _ASM_SCORE_CACHE_H
8639 #define _ASM_SCORE_CACHE_H
8640
8641+#include <linux/const.h>
8642+
8643 #define L1_CACHE_SHIFT 4
8644-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8645+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8646
8647 #endif /* _ASM_SCORE_CACHE_H */
8648diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
8649index f9f3cd5..58ff438 100644
8650--- a/arch/score/include/asm/exec.h
8651+++ b/arch/score/include/asm/exec.h
8652@@ -1,6 +1,6 @@
8653 #ifndef _ASM_SCORE_EXEC_H
8654 #define _ASM_SCORE_EXEC_H
8655
8656-extern unsigned long arch_align_stack(unsigned long sp);
8657+#define arch_align_stack(x) (x)
8658
8659 #endif /* _ASM_SCORE_EXEC_H */
8660diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
8661index f4c6d02..e9355c3 100644
8662--- a/arch/score/kernel/process.c
8663+++ b/arch/score/kernel/process.c
8664@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
8665
8666 return task_pt_regs(task)->cp0_epc;
8667 }
8668-
8669-unsigned long arch_align_stack(unsigned long sp)
8670-{
8671- return sp;
8672-}
8673diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
8674index ef9e555..331bd29 100644
8675--- a/arch/sh/include/asm/cache.h
8676+++ b/arch/sh/include/asm/cache.h
8677@@ -9,10 +9,11 @@
8678 #define __ASM_SH_CACHE_H
8679 #ifdef __KERNEL__
8680
8681+#include <linux/const.h>
8682 #include <linux/init.h>
8683 #include <cpu/cache.h>
8684
8685-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8686+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8687
8688 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8689
8690diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
8691index 6777177..cb5e44f 100644
8692--- a/arch/sh/mm/mmap.c
8693+++ b/arch/sh/mm/mmap.c
8694@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8695 struct mm_struct *mm = current->mm;
8696 struct vm_area_struct *vma;
8697 int do_colour_align;
8698+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8699 struct vm_unmapped_area_info info;
8700
8701 if (flags & MAP_FIXED) {
8702@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8703 if (filp || (flags & MAP_SHARED))
8704 do_colour_align = 1;
8705
8706+#ifdef CONFIG_PAX_RANDMMAP
8707+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8708+#endif
8709+
8710 if (addr) {
8711 if (do_colour_align)
8712 addr = COLOUR_ALIGN(addr, pgoff);
8713@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8714 addr = PAGE_ALIGN(addr);
8715
8716 vma = find_vma(mm, addr);
8717- if (TASK_SIZE - len >= addr &&
8718- (!vma || addr + len <= vma->vm_start))
8719+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8720 return addr;
8721 }
8722
8723 info.flags = 0;
8724 info.length = len;
8725- info.low_limit = TASK_UNMAPPED_BASE;
8726+ info.low_limit = mm->mmap_base;
8727 info.high_limit = TASK_SIZE;
8728 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
8729 info.align_offset = pgoff << PAGE_SHIFT;
8730@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8731 struct mm_struct *mm = current->mm;
8732 unsigned long addr = addr0;
8733 int do_colour_align;
8734+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8735 struct vm_unmapped_area_info info;
8736
8737 if (flags & MAP_FIXED) {
8738@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8739 if (filp || (flags & MAP_SHARED))
8740 do_colour_align = 1;
8741
8742+#ifdef CONFIG_PAX_RANDMMAP
8743+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8744+#endif
8745+
8746 /* requesting a specific address */
8747 if (addr) {
8748 if (do_colour_align)
8749@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8750 addr = PAGE_ALIGN(addr);
8751
8752 vma = find_vma(mm, addr);
8753- if (TASK_SIZE - len >= addr &&
8754- (!vma || addr + len <= vma->vm_start))
8755+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8756 return addr;
8757 }
8758
8759@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8760 VM_BUG_ON(addr != -ENOMEM);
8761 info.flags = 0;
8762 info.low_limit = TASK_UNMAPPED_BASE;
8763+
8764+#ifdef CONFIG_PAX_RANDMMAP
8765+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8766+ info.low_limit += mm->delta_mmap;
8767+#endif
8768+
8769 info.high_limit = TASK_SIZE;
8770 addr = vm_unmapped_area(&info);
8771 }
8772diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
8773index be56a24..443328f 100644
8774--- a/arch/sparc/include/asm/atomic_64.h
8775+++ b/arch/sparc/include/asm/atomic_64.h
8776@@ -14,18 +14,40 @@
8777 #define ATOMIC64_INIT(i) { (i) }
8778
8779 #define atomic_read(v) (*(volatile int *)&(v)->counter)
8780+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8781+{
8782+ return v->counter;
8783+}
8784 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
8785+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8786+{
8787+ return v->counter;
8788+}
8789
8790 #define atomic_set(v, i) (((v)->counter) = i)
8791+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8792+{
8793+ v->counter = i;
8794+}
8795 #define atomic64_set(v, i) (((v)->counter) = i)
8796+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8797+{
8798+ v->counter = i;
8799+}
8800
8801 extern void atomic_add(int, atomic_t *);
8802+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
8803 extern void atomic64_add(long, atomic64_t *);
8804+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
8805 extern void atomic_sub(int, atomic_t *);
8806+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
8807 extern void atomic64_sub(long, atomic64_t *);
8808+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
8809
8810 extern int atomic_add_ret(int, atomic_t *);
8811+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
8812 extern long atomic64_add_ret(long, atomic64_t *);
8813+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
8814 extern int atomic_sub_ret(int, atomic_t *);
8815 extern long atomic64_sub_ret(long, atomic64_t *);
8816
8817@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8818 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
8819
8820 #define atomic_inc_return(v) atomic_add_ret(1, v)
8821+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8822+{
8823+ return atomic_add_ret_unchecked(1, v);
8824+}
8825 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
8826+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8827+{
8828+ return atomic64_add_ret_unchecked(1, v);
8829+}
8830
8831 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
8832 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
8833
8834 #define atomic_add_return(i, v) atomic_add_ret(i, v)
8835+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8836+{
8837+ return atomic_add_ret_unchecked(i, v);
8838+}
8839 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
8840+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8841+{
8842+ return atomic64_add_ret_unchecked(i, v);
8843+}
8844
8845 /*
8846 * atomic_inc_and_test - increment and test
8847@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8848 * other cases.
8849 */
8850 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
8851+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8852+{
8853+ return atomic_inc_return_unchecked(v) == 0;
8854+}
8855 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8856
8857 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
8858@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8859 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
8860
8861 #define atomic_inc(v) atomic_add(1, v)
8862+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8863+{
8864+ atomic_add_unchecked(1, v);
8865+}
8866 #define atomic64_inc(v) atomic64_add(1, v)
8867+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8868+{
8869+ atomic64_add_unchecked(1, v);
8870+}
8871
8872 #define atomic_dec(v) atomic_sub(1, v)
8873+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8874+{
8875+ atomic_sub_unchecked(1, v);
8876+}
8877 #define atomic64_dec(v) atomic64_sub(1, v)
8878+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8879+{
8880+ atomic64_sub_unchecked(1, v);
8881+}
8882
8883 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
8884 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
8885
8886 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8887+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8888+{
8889+ return cmpxchg(&v->counter, old, new);
8890+}
8891 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
8892+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8893+{
8894+ return xchg(&v->counter, new);
8895+}
8896
8897 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
8898 {
8899- int c, old;
8900+ int c, old, new;
8901 c = atomic_read(v);
8902 for (;;) {
8903- if (unlikely(c == (u)))
8904+ if (unlikely(c == u))
8905 break;
8906- old = atomic_cmpxchg((v), c, c + (a));
8907+
8908+ asm volatile("addcc %2, %0, %0\n"
8909+
8910+#ifdef CONFIG_PAX_REFCOUNT
8911+ "tvs %%icc, 6\n"
8912+#endif
8913+
8914+ : "=r" (new)
8915+ : "0" (c), "ir" (a)
8916+ : "cc");
8917+
8918+ old = atomic_cmpxchg(v, c, new);
8919 if (likely(old == c))
8920 break;
8921 c = old;
8922@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
8923 #define atomic64_cmpxchg(v, o, n) \
8924 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
8925 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
8926+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8927+{
8928+ return xchg(&v->counter, new);
8929+}
8930
8931 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
8932 {
8933- long c, old;
8934+ long c, old, new;
8935 c = atomic64_read(v);
8936 for (;;) {
8937- if (unlikely(c == (u)))
8938+ if (unlikely(c == u))
8939 break;
8940- old = atomic64_cmpxchg((v), c, c + (a));
8941+
8942+ asm volatile("addcc %2, %0, %0\n"
8943+
8944+#ifdef CONFIG_PAX_REFCOUNT
8945+ "tvs %%xcc, 6\n"
8946+#endif
8947+
8948+ : "=r" (new)
8949+ : "0" (c), "ir" (a)
8950+ : "cc");
8951+
8952+ old = atomic64_cmpxchg(v, c, new);
8953 if (likely(old == c))
8954 break;
8955 c = old;
8956 }
8957- return c != (u);
8958+ return c != u;
8959 }
8960
8961 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8962diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
8963index 5bb6991..5c2132e 100644
8964--- a/arch/sparc/include/asm/cache.h
8965+++ b/arch/sparc/include/asm/cache.h
8966@@ -7,10 +7,12 @@
8967 #ifndef _SPARC_CACHE_H
8968 #define _SPARC_CACHE_H
8969
8970+#include <linux/const.h>
8971+
8972 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
8973
8974 #define L1_CACHE_SHIFT 5
8975-#define L1_CACHE_BYTES 32
8976+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8977
8978 #ifdef CONFIG_SPARC32
8979 #define SMP_CACHE_BYTES_SHIFT 5
8980diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
8981index a24e41f..47677ff 100644
8982--- a/arch/sparc/include/asm/elf_32.h
8983+++ b/arch/sparc/include/asm/elf_32.h
8984@@ -114,6 +114,13 @@ typedef struct {
8985
8986 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
8987
8988+#ifdef CONFIG_PAX_ASLR
8989+#define PAX_ELF_ET_DYN_BASE 0x10000UL
8990+
8991+#define PAX_DELTA_MMAP_LEN 16
8992+#define PAX_DELTA_STACK_LEN 16
8993+#endif
8994+
8995 /* This yields a mask that user programs can use to figure out what
8996 instruction set this cpu supports. This can NOT be done in userspace
8997 on Sparc. */
8998diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
8999index 370ca1e..d4f4a98 100644
9000--- a/arch/sparc/include/asm/elf_64.h
9001+++ b/arch/sparc/include/asm/elf_64.h
9002@@ -189,6 +189,13 @@ typedef struct {
9003 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9004 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9005
9006+#ifdef CONFIG_PAX_ASLR
9007+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9008+
9009+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9010+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9011+#endif
9012+
9013 extern unsigned long sparc64_elf_hwcap;
9014 #define ELF_HWCAP sparc64_elf_hwcap
9015
9016diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9017index 9b1c36d..209298b 100644
9018--- a/arch/sparc/include/asm/pgalloc_32.h
9019+++ b/arch/sparc/include/asm/pgalloc_32.h
9020@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9021 }
9022
9023 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9024+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9025
9026 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9027 unsigned long address)
9028diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9029index bcfe063..b333142 100644
9030--- a/arch/sparc/include/asm/pgalloc_64.h
9031+++ b/arch/sparc/include/asm/pgalloc_64.h
9032@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9033 }
9034
9035 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9036+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9037
9038 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9039 {
9040diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9041index 502f632..da1917f 100644
9042--- a/arch/sparc/include/asm/pgtable_32.h
9043+++ b/arch/sparc/include/asm/pgtable_32.h
9044@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9045 #define PAGE_SHARED SRMMU_PAGE_SHARED
9046 #define PAGE_COPY SRMMU_PAGE_COPY
9047 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9048+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9049+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9050+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9051 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9052
9053 /* Top-level page directory - dummy used by init-mm.
9054@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9055
9056 /* xwr */
9057 #define __P000 PAGE_NONE
9058-#define __P001 PAGE_READONLY
9059-#define __P010 PAGE_COPY
9060-#define __P011 PAGE_COPY
9061+#define __P001 PAGE_READONLY_NOEXEC
9062+#define __P010 PAGE_COPY_NOEXEC
9063+#define __P011 PAGE_COPY_NOEXEC
9064 #define __P100 PAGE_READONLY
9065 #define __P101 PAGE_READONLY
9066 #define __P110 PAGE_COPY
9067 #define __P111 PAGE_COPY
9068
9069 #define __S000 PAGE_NONE
9070-#define __S001 PAGE_READONLY
9071-#define __S010 PAGE_SHARED
9072-#define __S011 PAGE_SHARED
9073+#define __S001 PAGE_READONLY_NOEXEC
9074+#define __S010 PAGE_SHARED_NOEXEC
9075+#define __S011 PAGE_SHARED_NOEXEC
9076 #define __S100 PAGE_READONLY
9077 #define __S101 PAGE_READONLY
9078 #define __S110 PAGE_SHARED
9079diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9080index 79da178..c2eede8 100644
9081--- a/arch/sparc/include/asm/pgtsrmmu.h
9082+++ b/arch/sparc/include/asm/pgtsrmmu.h
9083@@ -115,6 +115,11 @@
9084 SRMMU_EXEC | SRMMU_REF)
9085 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9086 SRMMU_EXEC | SRMMU_REF)
9087+
9088+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9089+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9090+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9091+
9092 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9093 SRMMU_DIRTY | SRMMU_REF)
9094
9095diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9096index 9689176..63c18ea 100644
9097--- a/arch/sparc/include/asm/spinlock_64.h
9098+++ b/arch/sparc/include/asm/spinlock_64.h
9099@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9100
9101 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9102
9103-static void inline arch_read_lock(arch_rwlock_t *lock)
9104+static inline void arch_read_lock(arch_rwlock_t *lock)
9105 {
9106 unsigned long tmp1, tmp2;
9107
9108 __asm__ __volatile__ (
9109 "1: ldsw [%2], %0\n"
9110 " brlz,pn %0, 2f\n"
9111-"4: add %0, 1, %1\n"
9112+"4: addcc %0, 1, %1\n"
9113+
9114+#ifdef CONFIG_PAX_REFCOUNT
9115+" tvs %%icc, 6\n"
9116+#endif
9117+
9118 " cas [%2], %0, %1\n"
9119 " cmp %0, %1\n"
9120 " bne,pn %%icc, 1b\n"
9121@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9122 " .previous"
9123 : "=&r" (tmp1), "=&r" (tmp2)
9124 : "r" (lock)
9125- : "memory");
9126+ : "memory", "cc");
9127 }
9128
9129-static int inline arch_read_trylock(arch_rwlock_t *lock)
9130+static inline int arch_read_trylock(arch_rwlock_t *lock)
9131 {
9132 int tmp1, tmp2;
9133
9134@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9135 "1: ldsw [%2], %0\n"
9136 " brlz,a,pn %0, 2f\n"
9137 " mov 0, %0\n"
9138-" add %0, 1, %1\n"
9139+" addcc %0, 1, %1\n"
9140+
9141+#ifdef CONFIG_PAX_REFCOUNT
9142+" tvs %%icc, 6\n"
9143+#endif
9144+
9145 " cas [%2], %0, %1\n"
9146 " cmp %0, %1\n"
9147 " bne,pn %%icc, 1b\n"
9148@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9149 return tmp1;
9150 }
9151
9152-static void inline arch_read_unlock(arch_rwlock_t *lock)
9153+static inline void arch_read_unlock(arch_rwlock_t *lock)
9154 {
9155 unsigned long tmp1, tmp2;
9156
9157 __asm__ __volatile__(
9158 "1: lduw [%2], %0\n"
9159-" sub %0, 1, %1\n"
9160+" subcc %0, 1, %1\n"
9161+
9162+#ifdef CONFIG_PAX_REFCOUNT
9163+" tvs %%icc, 6\n"
9164+#endif
9165+
9166 " cas [%2], %0, %1\n"
9167 " cmp %0, %1\n"
9168 " bne,pn %%xcc, 1b\n"
9169@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9170 : "memory");
9171 }
9172
9173-static void inline arch_write_lock(arch_rwlock_t *lock)
9174+static inline void arch_write_lock(arch_rwlock_t *lock)
9175 {
9176 unsigned long mask, tmp1, tmp2;
9177
9178@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9179 : "memory");
9180 }
9181
9182-static void inline arch_write_unlock(arch_rwlock_t *lock)
9183+static inline void arch_write_unlock(arch_rwlock_t *lock)
9184 {
9185 __asm__ __volatile__(
9186 " stw %%g0, [%0]"
9187@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9188 : "memory");
9189 }
9190
9191-static int inline arch_write_trylock(arch_rwlock_t *lock)
9192+static inline int arch_write_trylock(arch_rwlock_t *lock)
9193 {
9194 unsigned long mask, tmp1, tmp2, result;
9195
9196diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9197index dd38075..e7cac83 100644
9198--- a/arch/sparc/include/asm/thread_info_32.h
9199+++ b/arch/sparc/include/asm/thread_info_32.h
9200@@ -49,6 +49,8 @@ struct thread_info {
9201 unsigned long w_saved;
9202
9203 struct restart_block restart_block;
9204+
9205+ unsigned long lowest_stack;
9206 };
9207
9208 /*
9209diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9210index d5e5042..9bfee76 100644
9211--- a/arch/sparc/include/asm/thread_info_64.h
9212+++ b/arch/sparc/include/asm/thread_info_64.h
9213@@ -63,6 +63,8 @@ struct thread_info {
9214 struct pt_regs *kern_una_regs;
9215 unsigned int kern_una_insn;
9216
9217+ unsigned long lowest_stack;
9218+
9219 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9220 };
9221
9222@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
9223 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9224 /* flag bit 6 is available */
9225 #define TIF_32BIT 7 /* 32-bit binary */
9226-/* flag bit 8 is available */
9227+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
9228 #define TIF_SECCOMP 9 /* secure computing */
9229 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9230 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9231+
9232 /* NOTE: Thread flags >= 12 should be ones we have no interest
9233 * in using in assembly, else we can't use the mask as
9234 * an immediate value in instructions such as andcc.
9235@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9236 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9237 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9238 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9239+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9240
9241 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9242 _TIF_DO_NOTIFY_RESUME_MASK | \
9243 _TIF_NEED_RESCHED)
9244 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9245
9246+#define _TIF_WORK_SYSCALL \
9247+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9248+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
9249+
9250+
9251 /*
9252 * Thread-synchronous status.
9253 *
9254diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9255index 0167d26..767bb0c 100644
9256--- a/arch/sparc/include/asm/uaccess.h
9257+++ b/arch/sparc/include/asm/uaccess.h
9258@@ -1,5 +1,6 @@
9259 #ifndef ___ASM_SPARC_UACCESS_H
9260 #define ___ASM_SPARC_UACCESS_H
9261+
9262 #if defined(__sparc__) && defined(__arch64__)
9263 #include <asm/uaccess_64.h>
9264 #else
9265diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9266index 53a28dd..50c38c3 100644
9267--- a/arch/sparc/include/asm/uaccess_32.h
9268+++ b/arch/sparc/include/asm/uaccess_32.h
9269@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9270
9271 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9272 {
9273- if (n && __access_ok((unsigned long) to, n))
9274+ if ((long)n < 0)
9275+ return n;
9276+
9277+ if (n && __access_ok((unsigned long) to, n)) {
9278+ if (!__builtin_constant_p(n))
9279+ check_object_size(from, n, true);
9280 return __copy_user(to, (__force void __user *) from, n);
9281- else
9282+ } else
9283 return n;
9284 }
9285
9286 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9287 {
9288+ if ((long)n < 0)
9289+ return n;
9290+
9291+ if (!__builtin_constant_p(n))
9292+ check_object_size(from, n, true);
9293+
9294 return __copy_user(to, (__force void __user *) from, n);
9295 }
9296
9297 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9298 {
9299- if (n && __access_ok((unsigned long) from, n))
9300+ if ((long)n < 0)
9301+ return n;
9302+
9303+ if (n && __access_ok((unsigned long) from, n)) {
9304+ if (!__builtin_constant_p(n))
9305+ check_object_size(to, n, false);
9306 return __copy_user((__force void __user *) to, from, n);
9307- else
9308+ } else
9309 return n;
9310 }
9311
9312 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9313 {
9314+ if ((long)n < 0)
9315+ return n;
9316+
9317 return __copy_user((__force void __user *) to, from, n);
9318 }
9319
9320diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9321index e562d3c..191f176 100644
9322--- a/arch/sparc/include/asm/uaccess_64.h
9323+++ b/arch/sparc/include/asm/uaccess_64.h
9324@@ -10,6 +10,7 @@
9325 #include <linux/compiler.h>
9326 #include <linux/string.h>
9327 #include <linux/thread_info.h>
9328+#include <linux/kernel.h>
9329 #include <asm/asi.h>
9330 #include <asm/spitfire.h>
9331 #include <asm-generic/uaccess-unaligned.h>
9332@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9333 static inline unsigned long __must_check
9334 copy_from_user(void *to, const void __user *from, unsigned long size)
9335 {
9336- unsigned long ret = ___copy_from_user(to, from, size);
9337+ unsigned long ret;
9338
9339+ if ((long)size < 0 || size > INT_MAX)
9340+ return size;
9341+
9342+ if (!__builtin_constant_p(size))
9343+ check_object_size(to, size, false);
9344+
9345+ ret = ___copy_from_user(to, from, size);
9346 if (unlikely(ret))
9347 ret = copy_from_user_fixup(to, from, size);
9348
9349@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9350 static inline unsigned long __must_check
9351 copy_to_user(void __user *to, const void *from, unsigned long size)
9352 {
9353- unsigned long ret = ___copy_to_user(to, from, size);
9354+ unsigned long ret;
9355
9356+ if ((long)size < 0 || size > INT_MAX)
9357+ return size;
9358+
9359+ if (!__builtin_constant_p(size))
9360+ check_object_size(from, size, true);
9361+
9362+ ret = ___copy_to_user(to, from, size);
9363 if (unlikely(ret))
9364 ret = copy_to_user_fixup(to, from, size);
9365 return ret;
9366diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
9367index d432fb2..6056af1 100644
9368--- a/arch/sparc/kernel/Makefile
9369+++ b/arch/sparc/kernel/Makefile
9370@@ -3,7 +3,7 @@
9371 #
9372
9373 asflags-y := -ansi
9374-ccflags-y := -Werror
9375+#ccflags-y := -Werror
9376
9377 extra-y := head_$(BITS).o
9378
9379diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
9380index fdd819d..5af08c8 100644
9381--- a/arch/sparc/kernel/process_32.c
9382+++ b/arch/sparc/kernel/process_32.c
9383@@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
9384
9385 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
9386 r->psr, r->pc, r->npc, r->y, print_tainted());
9387- printk("PC: <%pS>\n", (void *) r->pc);
9388+ printk("PC: <%pA>\n", (void *) r->pc);
9389 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9390 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
9391 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
9392 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9393 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
9394 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
9395- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
9396+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
9397
9398 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9399 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
9400@@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9401 rw = (struct reg_window32 *) fp;
9402 pc = rw->ins[7];
9403 printk("[%08lx : ", pc);
9404- printk("%pS ] ", (void *) pc);
9405+ printk("%pA ] ", (void *) pc);
9406 fp = rw->ins[6];
9407 } while (++count < 16);
9408 printk("\n");
9409diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
9410index baebab2..9cd13b1 100644
9411--- a/arch/sparc/kernel/process_64.c
9412+++ b/arch/sparc/kernel/process_64.c
9413@@ -158,7 +158,7 @@ static void show_regwindow(struct pt_regs *regs)
9414 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
9415 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
9416 if (regs->tstate & TSTATE_PRIV)
9417- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
9418+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
9419 }
9420
9421 void show_regs(struct pt_regs *regs)
9422@@ -167,7 +167,7 @@ void show_regs(struct pt_regs *regs)
9423
9424 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
9425 regs->tpc, regs->tnpc, regs->y, print_tainted());
9426- printk("TPC: <%pS>\n", (void *) regs->tpc);
9427+ printk("TPC: <%pA>\n", (void *) regs->tpc);
9428 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
9429 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
9430 regs->u_regs[3]);
9431@@ -180,7 +180,7 @@ void show_regs(struct pt_regs *regs)
9432 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
9433 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
9434 regs->u_regs[15]);
9435- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
9436+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
9437 show_regwindow(regs);
9438 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
9439 }
9440@@ -269,7 +269,7 @@ void arch_trigger_all_cpu_backtrace(void)
9441 ((tp && tp->task) ? tp->task->pid : -1));
9442
9443 if (gp->tstate & TSTATE_PRIV) {
9444- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
9445+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
9446 (void *) gp->tpc,
9447 (void *) gp->o7,
9448 (void *) gp->i7,
9449diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
9450index 79cc0d1..ec62734 100644
9451--- a/arch/sparc/kernel/prom_common.c
9452+++ b/arch/sparc/kernel/prom_common.c
9453@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
9454
9455 unsigned int prom_early_allocated __initdata;
9456
9457-static struct of_pdt_ops prom_sparc_ops __initdata = {
9458+static struct of_pdt_ops prom_sparc_ops __initconst = {
9459 .nextprop = prom_common_nextprop,
9460 .getproplen = prom_getproplen,
9461 .getproperty = prom_getproperty,
9462diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
9463index 7ff45e4..a58f271 100644
9464--- a/arch/sparc/kernel/ptrace_64.c
9465+++ b/arch/sparc/kernel/ptrace_64.c
9466@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
9467 return ret;
9468 }
9469
9470+#ifdef CONFIG_GRKERNSEC_SETXID
9471+extern void gr_delayed_cred_worker(void);
9472+#endif
9473+
9474 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9475 {
9476 int ret = 0;
9477@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9478 /* do the secure computing check first */
9479 secure_computing_strict(regs->u_regs[UREG_G1]);
9480
9481+#ifdef CONFIG_GRKERNSEC_SETXID
9482+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9483+ gr_delayed_cred_worker();
9484+#endif
9485+
9486 if (test_thread_flag(TIF_SYSCALL_TRACE))
9487 ret = tracehook_report_syscall_entry(regs);
9488
9489@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9490
9491 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
9492 {
9493+#ifdef CONFIG_GRKERNSEC_SETXID
9494+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9495+ gr_delayed_cred_worker();
9496+#endif
9497+
9498 audit_syscall_exit(regs);
9499
9500 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9501diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
9502index e142545..fd29654 100644
9503--- a/arch/sparc/kernel/smp_64.c
9504+++ b/arch/sparc/kernel/smp_64.c
9505@@ -869,8 +869,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
9506 extern unsigned long xcall_flush_dcache_page_spitfire;
9507
9508 #ifdef CONFIG_DEBUG_DCFLUSH
9509-extern atomic_t dcpage_flushes;
9510-extern atomic_t dcpage_flushes_xcall;
9511+extern atomic_unchecked_t dcpage_flushes;
9512+extern atomic_unchecked_t dcpage_flushes_xcall;
9513 #endif
9514
9515 static inline void __local_flush_dcache_page(struct page *page)
9516@@ -894,7 +894,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9517 return;
9518
9519 #ifdef CONFIG_DEBUG_DCFLUSH
9520- atomic_inc(&dcpage_flushes);
9521+ atomic_inc_unchecked(&dcpage_flushes);
9522 #endif
9523
9524 this_cpu = get_cpu();
9525@@ -918,7 +918,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9526 xcall_deliver(data0, __pa(pg_addr),
9527 (u64) pg_addr, cpumask_of(cpu));
9528 #ifdef CONFIG_DEBUG_DCFLUSH
9529- atomic_inc(&dcpage_flushes_xcall);
9530+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9531 #endif
9532 }
9533 }
9534@@ -937,7 +937,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9535 preempt_disable();
9536
9537 #ifdef CONFIG_DEBUG_DCFLUSH
9538- atomic_inc(&dcpage_flushes);
9539+ atomic_inc_unchecked(&dcpage_flushes);
9540 #endif
9541 data0 = 0;
9542 pg_addr = page_address(page);
9543@@ -954,7 +954,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9544 xcall_deliver(data0, __pa(pg_addr),
9545 (u64) pg_addr, cpu_online_mask);
9546 #ifdef CONFIG_DEBUG_DCFLUSH
9547- atomic_inc(&dcpage_flushes_xcall);
9548+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9549 #endif
9550 }
9551 __local_flush_dcache_page(page);
9552diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
9553index 3a8d184..49498a8 100644
9554--- a/arch/sparc/kernel/sys_sparc_32.c
9555+++ b/arch/sparc/kernel/sys_sparc_32.c
9556@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9557 if (len > TASK_SIZE - PAGE_SIZE)
9558 return -ENOMEM;
9559 if (!addr)
9560- addr = TASK_UNMAPPED_BASE;
9561+ addr = current->mm->mmap_base;
9562
9563 info.flags = 0;
9564 info.length = len;
9565diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
9566index 51561b8..8256764 100644
9567--- a/arch/sparc/kernel/sys_sparc_64.c
9568+++ b/arch/sparc/kernel/sys_sparc_64.c
9569@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9570 struct vm_area_struct * vma;
9571 unsigned long task_size = TASK_SIZE;
9572 int do_color_align;
9573+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9574 struct vm_unmapped_area_info info;
9575
9576 if (flags & MAP_FIXED) {
9577 /* We do not accept a shared mapping if it would violate
9578 * cache aliasing constraints.
9579 */
9580- if ((flags & MAP_SHARED) &&
9581+ if ((filp || (flags & MAP_SHARED)) &&
9582 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9583 return -EINVAL;
9584 return addr;
9585@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9586 if (filp || (flags & MAP_SHARED))
9587 do_color_align = 1;
9588
9589+#ifdef CONFIG_PAX_RANDMMAP
9590+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9591+#endif
9592+
9593 if (addr) {
9594 if (do_color_align)
9595 addr = COLOR_ALIGN(addr, pgoff);
9596@@ -118,22 +123,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9597 addr = PAGE_ALIGN(addr);
9598
9599 vma = find_vma(mm, addr);
9600- if (task_size - len >= addr &&
9601- (!vma || addr + len <= vma->vm_start))
9602+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9603 return addr;
9604 }
9605
9606 info.flags = 0;
9607 info.length = len;
9608- info.low_limit = TASK_UNMAPPED_BASE;
9609+ info.low_limit = mm->mmap_base;
9610 info.high_limit = min(task_size, VA_EXCLUDE_START);
9611 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9612 info.align_offset = pgoff << PAGE_SHIFT;
9613+ info.threadstack_offset = offset;
9614 addr = vm_unmapped_area(&info);
9615
9616 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9617 VM_BUG_ON(addr != -ENOMEM);
9618 info.low_limit = VA_EXCLUDE_END;
9619+
9620+#ifdef CONFIG_PAX_RANDMMAP
9621+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9622+ info.low_limit += mm->delta_mmap;
9623+#endif
9624+
9625 info.high_limit = task_size;
9626 addr = vm_unmapped_area(&info);
9627 }
9628@@ -151,6 +162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9629 unsigned long task_size = STACK_TOP32;
9630 unsigned long addr = addr0;
9631 int do_color_align;
9632+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9633 struct vm_unmapped_area_info info;
9634
9635 /* This should only ever run for 32-bit processes. */
9636@@ -160,7 +172,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9637 /* We do not accept a shared mapping if it would violate
9638 * cache aliasing constraints.
9639 */
9640- if ((flags & MAP_SHARED) &&
9641+ if ((filp || (flags & MAP_SHARED)) &&
9642 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9643 return -EINVAL;
9644 return addr;
9645@@ -173,6 +185,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9646 if (filp || (flags & MAP_SHARED))
9647 do_color_align = 1;
9648
9649+#ifdef CONFIG_PAX_RANDMMAP
9650+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9651+#endif
9652+
9653 /* requesting a specific address */
9654 if (addr) {
9655 if (do_color_align)
9656@@ -181,8 +197,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9657 addr = PAGE_ALIGN(addr);
9658
9659 vma = find_vma(mm, addr);
9660- if (task_size - len >= addr &&
9661- (!vma || addr + len <= vma->vm_start))
9662+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9663 return addr;
9664 }
9665
9666@@ -192,6 +207,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9667 info.high_limit = mm->mmap_base;
9668 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9669 info.align_offset = pgoff << PAGE_SHIFT;
9670+ info.threadstack_offset = offset;
9671 addr = vm_unmapped_area(&info);
9672
9673 /*
9674@@ -204,6 +220,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9675 VM_BUG_ON(addr != -ENOMEM);
9676 info.flags = 0;
9677 info.low_limit = TASK_UNMAPPED_BASE;
9678+
9679+#ifdef CONFIG_PAX_RANDMMAP
9680+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9681+ info.low_limit += mm->delta_mmap;
9682+#endif
9683+
9684 info.high_limit = STACK_TOP32;
9685 addr = vm_unmapped_area(&info);
9686 }
9687@@ -260,10 +282,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
9688 EXPORT_SYMBOL(get_fb_unmapped_area);
9689
9690 /* Essentially the same as PowerPC. */
9691-static unsigned long mmap_rnd(void)
9692+static unsigned long mmap_rnd(struct mm_struct *mm)
9693 {
9694 unsigned long rnd = 0UL;
9695
9696+#ifdef CONFIG_PAX_RANDMMAP
9697+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9698+#endif
9699+
9700 if (current->flags & PF_RANDOMIZE) {
9701 unsigned long val = get_random_int();
9702 if (test_thread_flag(TIF_32BIT))
9703@@ -276,7 +302,7 @@ static unsigned long mmap_rnd(void)
9704
9705 void arch_pick_mmap_layout(struct mm_struct *mm)
9706 {
9707- unsigned long random_factor = mmap_rnd();
9708+ unsigned long random_factor = mmap_rnd(mm);
9709 unsigned long gap;
9710
9711 /*
9712@@ -289,6 +315,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9713 gap == RLIM_INFINITY ||
9714 sysctl_legacy_va_layout) {
9715 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
9716+
9717+#ifdef CONFIG_PAX_RANDMMAP
9718+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9719+ mm->mmap_base += mm->delta_mmap;
9720+#endif
9721+
9722 mm->get_unmapped_area = arch_get_unmapped_area;
9723 } else {
9724 /* We know it's 32-bit */
9725@@ -300,6 +332,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9726 gap = (task_size / 6 * 5);
9727
9728 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
9729+
9730+#ifdef CONFIG_PAX_RANDMMAP
9731+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9732+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9733+#endif
9734+
9735 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9736 }
9737 }
9738diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
9739index 22a1098..6255eb9 100644
9740--- a/arch/sparc/kernel/syscalls.S
9741+++ b/arch/sparc/kernel/syscalls.S
9742@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
9743 #endif
9744 .align 32
9745 1: ldx [%g6 + TI_FLAGS], %l5
9746- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9747+ andcc %l5, _TIF_WORK_SYSCALL, %g0
9748 be,pt %icc, rtrap
9749 nop
9750 call syscall_trace_leave
9751@@ -184,7 +184,7 @@ linux_sparc_syscall32:
9752
9753 srl %i5, 0, %o5 ! IEU1
9754 srl %i2, 0, %o2 ! IEU0 Group
9755- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9756+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9757 bne,pn %icc, linux_syscall_trace32 ! CTI
9758 mov %i0, %l5 ! IEU1
9759 call %l7 ! CTI Group brk forced
9760@@ -207,7 +207,7 @@ linux_sparc_syscall:
9761
9762 mov %i3, %o3 ! IEU1
9763 mov %i4, %o4 ! IEU0 Group
9764- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9765+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9766 bne,pn %icc, linux_syscall_trace ! CTI Group
9767 mov %i0, %l5 ! IEU0
9768 2: call %l7 ! CTI Group brk forced
9769@@ -223,7 +223,7 @@ ret_sys_call:
9770
9771 cmp %o0, -ERESTART_RESTARTBLOCK
9772 bgeu,pn %xcc, 1f
9773- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9774+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9775 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
9776
9777 2:
9778diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
9779index 6629829..036032d 100644
9780--- a/arch/sparc/kernel/traps_32.c
9781+++ b/arch/sparc/kernel/traps_32.c
9782@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
9783 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
9784 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
9785
9786+extern void gr_handle_kernel_exploit(void);
9787+
9788 void die_if_kernel(char *str, struct pt_regs *regs)
9789 {
9790 static int die_counter;
9791@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9792 count++ < 30 &&
9793 (((unsigned long) rw) >= PAGE_OFFSET) &&
9794 !(((unsigned long) rw) & 0x7)) {
9795- printk("Caller[%08lx]: %pS\n", rw->ins[7],
9796+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
9797 (void *) rw->ins[7]);
9798 rw = (struct reg_window32 *)rw->ins[6];
9799 }
9800 }
9801 printk("Instruction DUMP:");
9802 instruction_dump ((unsigned long *) regs->pc);
9803- if(regs->psr & PSR_PS)
9804+ if(regs->psr & PSR_PS) {
9805+ gr_handle_kernel_exploit();
9806 do_exit(SIGKILL);
9807+ }
9808 do_exit(SIGSEGV);
9809 }
9810
9811diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
9812index b3f833a..f485f80 100644
9813--- a/arch/sparc/kernel/traps_64.c
9814+++ b/arch/sparc/kernel/traps_64.c
9815@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
9816 i + 1,
9817 p->trapstack[i].tstate, p->trapstack[i].tpc,
9818 p->trapstack[i].tnpc, p->trapstack[i].tt);
9819- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
9820+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
9821 }
9822 }
9823
9824@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
9825
9826 lvl -= 0x100;
9827 if (regs->tstate & TSTATE_PRIV) {
9828+
9829+#ifdef CONFIG_PAX_REFCOUNT
9830+ if (lvl == 6)
9831+ pax_report_refcount_overflow(regs);
9832+#endif
9833+
9834 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
9835 die_if_kernel(buffer, regs);
9836 }
9837@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
9838 void bad_trap_tl1(struct pt_regs *regs, long lvl)
9839 {
9840 char buffer[32];
9841-
9842+
9843 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
9844 0, lvl, SIGTRAP) == NOTIFY_STOP)
9845 return;
9846
9847+#ifdef CONFIG_PAX_REFCOUNT
9848+ if (lvl == 6)
9849+ pax_report_refcount_overflow(regs);
9850+#endif
9851+
9852 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
9853
9854 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
9855@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
9856 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
9857 printk("%s" "ERROR(%d): ",
9858 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
9859- printk("TPC<%pS>\n", (void *) regs->tpc);
9860+ printk("TPC<%pA>\n", (void *) regs->tpc);
9861 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
9862 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
9863 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
9864@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9865 smp_processor_id(),
9866 (type & 0x1) ? 'I' : 'D',
9867 regs->tpc);
9868- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
9869+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
9870 panic("Irrecoverable Cheetah+ parity error.");
9871 }
9872
9873@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9874 smp_processor_id(),
9875 (type & 0x1) ? 'I' : 'D',
9876 regs->tpc);
9877- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
9878+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
9879 }
9880
9881 struct sun4v_error_entry {
9882@@ -1830,8 +1841,8 @@ struct sun4v_error_entry {
9883 /*0x38*/u64 reserved_5;
9884 };
9885
9886-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
9887-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
9888+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
9889+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
9890
9891 static const char *sun4v_err_type_to_str(u8 type)
9892 {
9893@@ -1923,7 +1934,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
9894 }
9895
9896 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
9897- int cpu, const char *pfx, atomic_t *ocnt)
9898+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
9899 {
9900 u64 *raw_ptr = (u64 *) ent;
9901 u32 attrs;
9902@@ -1981,8 +1992,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
9903
9904 show_regs(regs);
9905
9906- if ((cnt = atomic_read(ocnt)) != 0) {
9907- atomic_set(ocnt, 0);
9908+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
9909+ atomic_set_unchecked(ocnt, 0);
9910 wmb();
9911 printk("%s: Queue overflowed %d times.\n",
9912 pfx, cnt);
9913@@ -2036,7 +2047,7 @@ void sun4v_resum_error(struct pt_regs *regs, unsigned long offset)
9914 */
9915 void sun4v_resum_overflow(struct pt_regs *regs)
9916 {
9917- atomic_inc(&sun4v_resum_oflow_cnt);
9918+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
9919 }
9920
9921 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
9922@@ -2089,7 +2100,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
9923 /* XXX Actually even this can make not that much sense. Perhaps
9924 * XXX we should just pull the plug and panic directly from here?
9925 */
9926- atomic_inc(&sun4v_nonresum_oflow_cnt);
9927+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
9928 }
9929
9930 unsigned long sun4v_err_itlb_vaddr;
9931@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
9932
9933 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
9934 regs->tpc, tl);
9935- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
9936+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
9937 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
9938- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
9939+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
9940 (void *) regs->u_regs[UREG_I7]);
9941 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
9942 "pte[%lx] error[%lx]\n",
9943@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
9944
9945 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
9946 regs->tpc, tl);
9947- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
9948+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
9949 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
9950- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
9951+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
9952 (void *) regs->u_regs[UREG_I7]);
9953 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
9954 "pte[%lx] error[%lx]\n",
9955@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9956 fp = (unsigned long)sf->fp + STACK_BIAS;
9957 }
9958
9959- printk(" [%016lx] %pS\n", pc, (void *) pc);
9960+ printk(" [%016lx] %pA\n", pc, (void *) pc);
9961 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
9962 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
9963 int index = tsk->curr_ret_stack;
9964 if (tsk->ret_stack && index >= graph) {
9965 pc = tsk->ret_stack[index - graph].ret;
9966- printk(" [%016lx] %pS\n", pc, (void *) pc);
9967+ printk(" [%016lx] %pA\n", pc, (void *) pc);
9968 graph++;
9969 }
9970 }
9971@@ -2360,6 +2371,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
9972 return (struct reg_window *) (fp + STACK_BIAS);
9973 }
9974
9975+extern void gr_handle_kernel_exploit(void);
9976+
9977 void die_if_kernel(char *str, struct pt_regs *regs)
9978 {
9979 static int die_counter;
9980@@ -2388,7 +2401,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9981 while (rw &&
9982 count++ < 30 &&
9983 kstack_valid(tp, (unsigned long) rw)) {
9984- printk("Caller[%016lx]: %pS\n", rw->ins[7],
9985+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
9986 (void *) rw->ins[7]);
9987
9988 rw = kernel_stack_up(rw);
9989@@ -2401,8 +2414,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9990 }
9991 user_instruction_dump ((unsigned int __user *) regs->tpc);
9992 }
9993- if (regs->tstate & TSTATE_PRIV)
9994+ if (regs->tstate & TSTATE_PRIV) {
9995+ gr_handle_kernel_exploit();
9996 do_exit(SIGKILL);
9997+ }
9998 do_exit(SIGSEGV);
9999 }
10000 EXPORT_SYMBOL(die_if_kernel);
10001diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10002index 8201c25e..072a2a7 100644
10003--- a/arch/sparc/kernel/unaligned_64.c
10004+++ b/arch/sparc/kernel/unaligned_64.c
10005@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
10006 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10007
10008 if (__ratelimit(&ratelimit)) {
10009- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10010+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10011 regs->tpc, (void *) regs->tpc);
10012 }
10013 }
10014diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10015index dbe119b..089c7c1 100644
10016--- a/arch/sparc/lib/Makefile
10017+++ b/arch/sparc/lib/Makefile
10018@@ -2,7 +2,7 @@
10019 #
10020
10021 asflags-y := -ansi -DST_DIV0=0x02
10022-ccflags-y := -Werror
10023+#ccflags-y := -Werror
10024
10025 lib-$(CONFIG_SPARC32) += ashrdi3.o
10026 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10027diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10028index 85c233d..68500e0 100644
10029--- a/arch/sparc/lib/atomic_64.S
10030+++ b/arch/sparc/lib/atomic_64.S
10031@@ -17,7 +17,12 @@
10032 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10033 BACKOFF_SETUP(%o2)
10034 1: lduw [%o1], %g1
10035- add %g1, %o0, %g7
10036+ addcc %g1, %o0, %g7
10037+
10038+#ifdef CONFIG_PAX_REFCOUNT
10039+ tvs %icc, 6
10040+#endif
10041+
10042 cas [%o1], %g1, %g7
10043 cmp %g1, %g7
10044 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10045@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10046 2: BACKOFF_SPIN(%o2, %o3, 1b)
10047 ENDPROC(atomic_add)
10048
10049+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10050+ BACKOFF_SETUP(%o2)
10051+1: lduw [%o1], %g1
10052+ add %g1, %o0, %g7
10053+ cas [%o1], %g1, %g7
10054+ cmp %g1, %g7
10055+ bne,pn %icc, 2f
10056+ nop
10057+ retl
10058+ nop
10059+2: BACKOFF_SPIN(%o2, %o3, 1b)
10060+ENDPROC(atomic_add_unchecked)
10061+
10062 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10063 BACKOFF_SETUP(%o2)
10064 1: lduw [%o1], %g1
10065- sub %g1, %o0, %g7
10066+ subcc %g1, %o0, %g7
10067+
10068+#ifdef CONFIG_PAX_REFCOUNT
10069+ tvs %icc, 6
10070+#endif
10071+
10072 cas [%o1], %g1, %g7
10073 cmp %g1, %g7
10074 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10075@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10076 2: BACKOFF_SPIN(%o2, %o3, 1b)
10077 ENDPROC(atomic_sub)
10078
10079+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10080+ BACKOFF_SETUP(%o2)
10081+1: lduw [%o1], %g1
10082+ sub %g1, %o0, %g7
10083+ cas [%o1], %g1, %g7
10084+ cmp %g1, %g7
10085+ bne,pn %icc, 2f
10086+ nop
10087+ retl
10088+ nop
10089+2: BACKOFF_SPIN(%o2, %o3, 1b)
10090+ENDPROC(atomic_sub_unchecked)
10091+
10092 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10093 BACKOFF_SETUP(%o2)
10094 1: lduw [%o1], %g1
10095- add %g1, %o0, %g7
10096+ addcc %g1, %o0, %g7
10097+
10098+#ifdef CONFIG_PAX_REFCOUNT
10099+ tvs %icc, 6
10100+#endif
10101+
10102 cas [%o1], %g1, %g7
10103 cmp %g1, %g7
10104 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10105@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10106 2: BACKOFF_SPIN(%o2, %o3, 1b)
10107 ENDPROC(atomic_add_ret)
10108
10109+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10110+ BACKOFF_SETUP(%o2)
10111+1: lduw [%o1], %g1
10112+ addcc %g1, %o0, %g7
10113+ cas [%o1], %g1, %g7
10114+ cmp %g1, %g7
10115+ bne,pn %icc, 2f
10116+ add %g7, %o0, %g7
10117+ sra %g7, 0, %o0
10118+ retl
10119+ nop
10120+2: BACKOFF_SPIN(%o2, %o3, 1b)
10121+ENDPROC(atomic_add_ret_unchecked)
10122+
10123 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10124 BACKOFF_SETUP(%o2)
10125 1: lduw [%o1], %g1
10126- sub %g1, %o0, %g7
10127+ subcc %g1, %o0, %g7
10128+
10129+#ifdef CONFIG_PAX_REFCOUNT
10130+ tvs %icc, 6
10131+#endif
10132+
10133 cas [%o1], %g1, %g7
10134 cmp %g1, %g7
10135 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10136@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10137 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10138 BACKOFF_SETUP(%o2)
10139 1: ldx [%o1], %g1
10140- add %g1, %o0, %g7
10141+ addcc %g1, %o0, %g7
10142+
10143+#ifdef CONFIG_PAX_REFCOUNT
10144+ tvs %xcc, 6
10145+#endif
10146+
10147 casx [%o1], %g1, %g7
10148 cmp %g1, %g7
10149 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10150@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10151 2: BACKOFF_SPIN(%o2, %o3, 1b)
10152 ENDPROC(atomic64_add)
10153
10154+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10155+ BACKOFF_SETUP(%o2)
10156+1: ldx [%o1], %g1
10157+ addcc %g1, %o0, %g7
10158+ casx [%o1], %g1, %g7
10159+ cmp %g1, %g7
10160+ bne,pn %xcc, 2f
10161+ nop
10162+ retl
10163+ nop
10164+2: BACKOFF_SPIN(%o2, %o3, 1b)
10165+ENDPROC(atomic64_add_unchecked)
10166+
10167 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10168 BACKOFF_SETUP(%o2)
10169 1: ldx [%o1], %g1
10170- sub %g1, %o0, %g7
10171+ subcc %g1, %o0, %g7
10172+
10173+#ifdef CONFIG_PAX_REFCOUNT
10174+ tvs %xcc, 6
10175+#endif
10176+
10177 casx [%o1], %g1, %g7
10178 cmp %g1, %g7
10179 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10180@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10181 2: BACKOFF_SPIN(%o2, %o3, 1b)
10182 ENDPROC(atomic64_sub)
10183
10184+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10185+ BACKOFF_SETUP(%o2)
10186+1: ldx [%o1], %g1
10187+ subcc %g1, %o0, %g7
10188+ casx [%o1], %g1, %g7
10189+ cmp %g1, %g7
10190+ bne,pn %xcc, 2f
10191+ nop
10192+ retl
10193+ nop
10194+2: BACKOFF_SPIN(%o2, %o3, 1b)
10195+ENDPROC(atomic64_sub_unchecked)
10196+
10197 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10198 BACKOFF_SETUP(%o2)
10199 1: ldx [%o1], %g1
10200- add %g1, %o0, %g7
10201+ addcc %g1, %o0, %g7
10202+
10203+#ifdef CONFIG_PAX_REFCOUNT
10204+ tvs %xcc, 6
10205+#endif
10206+
10207 casx [%o1], %g1, %g7
10208 cmp %g1, %g7
10209 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10210@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10211 2: BACKOFF_SPIN(%o2, %o3, 1b)
10212 ENDPROC(atomic64_add_ret)
10213
10214+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10215+ BACKOFF_SETUP(%o2)
10216+1: ldx [%o1], %g1
10217+ addcc %g1, %o0, %g7
10218+ casx [%o1], %g1, %g7
10219+ cmp %g1, %g7
10220+ bne,pn %xcc, 2f
10221+ add %g7, %o0, %g7
10222+ mov %g7, %o0
10223+ retl
10224+ nop
10225+2: BACKOFF_SPIN(%o2, %o3, 1b)
10226+ENDPROC(atomic64_add_ret_unchecked)
10227+
10228 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10229 BACKOFF_SETUP(%o2)
10230 1: ldx [%o1], %g1
10231- sub %g1, %o0, %g7
10232+ subcc %g1, %o0, %g7
10233+
10234+#ifdef CONFIG_PAX_REFCOUNT
10235+ tvs %xcc, 6
10236+#endif
10237+
10238 casx [%o1], %g1, %g7
10239 cmp %g1, %g7
10240 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10241diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10242index 0c4e35e..745d3e4 100644
10243--- a/arch/sparc/lib/ksyms.c
10244+++ b/arch/sparc/lib/ksyms.c
10245@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
10246
10247 /* Atomic counter implementation. */
10248 EXPORT_SYMBOL(atomic_add);
10249+EXPORT_SYMBOL(atomic_add_unchecked);
10250 EXPORT_SYMBOL(atomic_add_ret);
10251+EXPORT_SYMBOL(atomic_add_ret_unchecked);
10252 EXPORT_SYMBOL(atomic_sub);
10253+EXPORT_SYMBOL(atomic_sub_unchecked);
10254 EXPORT_SYMBOL(atomic_sub_ret);
10255 EXPORT_SYMBOL(atomic64_add);
10256+EXPORT_SYMBOL(atomic64_add_unchecked);
10257 EXPORT_SYMBOL(atomic64_add_ret);
10258+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10259 EXPORT_SYMBOL(atomic64_sub);
10260+EXPORT_SYMBOL(atomic64_sub_unchecked);
10261 EXPORT_SYMBOL(atomic64_sub_ret);
10262 EXPORT_SYMBOL(atomic64_dec_if_positive);
10263
10264diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10265index 30c3ecc..736f015 100644
10266--- a/arch/sparc/mm/Makefile
10267+++ b/arch/sparc/mm/Makefile
10268@@ -2,7 +2,7 @@
10269 #
10270
10271 asflags-y := -ansi
10272-ccflags-y := -Werror
10273+#ccflags-y := -Werror
10274
10275 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10276 obj-y += fault_$(BITS).o
10277diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10278index e98bfda..ea8d221 100644
10279--- a/arch/sparc/mm/fault_32.c
10280+++ b/arch/sparc/mm/fault_32.c
10281@@ -21,6 +21,9 @@
10282 #include <linux/perf_event.h>
10283 #include <linux/interrupt.h>
10284 #include <linux/kdebug.h>
10285+#include <linux/slab.h>
10286+#include <linux/pagemap.h>
10287+#include <linux/compiler.h>
10288
10289 #include <asm/page.h>
10290 #include <asm/pgtable.h>
10291@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10292 return safe_compute_effective_address(regs, insn);
10293 }
10294
10295+#ifdef CONFIG_PAX_PAGEEXEC
10296+#ifdef CONFIG_PAX_DLRESOLVE
10297+static void pax_emuplt_close(struct vm_area_struct *vma)
10298+{
10299+ vma->vm_mm->call_dl_resolve = 0UL;
10300+}
10301+
10302+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10303+{
10304+ unsigned int *kaddr;
10305+
10306+ vmf->page = alloc_page(GFP_HIGHUSER);
10307+ if (!vmf->page)
10308+ return VM_FAULT_OOM;
10309+
10310+ kaddr = kmap(vmf->page);
10311+ memset(kaddr, 0, PAGE_SIZE);
10312+ kaddr[0] = 0x9DE3BFA8U; /* save */
10313+ flush_dcache_page(vmf->page);
10314+ kunmap(vmf->page);
10315+ return VM_FAULT_MAJOR;
10316+}
10317+
10318+static const struct vm_operations_struct pax_vm_ops = {
10319+ .close = pax_emuplt_close,
10320+ .fault = pax_emuplt_fault
10321+};
10322+
10323+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10324+{
10325+ int ret;
10326+
10327+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10328+ vma->vm_mm = current->mm;
10329+ vma->vm_start = addr;
10330+ vma->vm_end = addr + PAGE_SIZE;
10331+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10332+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10333+ vma->vm_ops = &pax_vm_ops;
10334+
10335+ ret = insert_vm_struct(current->mm, vma);
10336+ if (ret)
10337+ return ret;
10338+
10339+ ++current->mm->total_vm;
10340+ return 0;
10341+}
10342+#endif
10343+
10344+/*
10345+ * PaX: decide what to do with offenders (regs->pc = fault address)
10346+ *
10347+ * returns 1 when task should be killed
10348+ * 2 when patched PLT trampoline was detected
10349+ * 3 when unpatched PLT trampoline was detected
10350+ */
10351+static int pax_handle_fetch_fault(struct pt_regs *regs)
10352+{
10353+
10354+#ifdef CONFIG_PAX_EMUPLT
10355+ int err;
10356+
10357+ do { /* PaX: patched PLT emulation #1 */
10358+ unsigned int sethi1, sethi2, jmpl;
10359+
10360+ err = get_user(sethi1, (unsigned int *)regs->pc);
10361+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
10362+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
10363+
10364+ if (err)
10365+ break;
10366+
10367+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10368+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10369+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10370+ {
10371+ unsigned int addr;
10372+
10373+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10374+ addr = regs->u_regs[UREG_G1];
10375+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10376+ regs->pc = addr;
10377+ regs->npc = addr+4;
10378+ return 2;
10379+ }
10380+ } while (0);
10381+
10382+ do { /* PaX: patched PLT emulation #2 */
10383+ unsigned int ba;
10384+
10385+ err = get_user(ba, (unsigned int *)regs->pc);
10386+
10387+ if (err)
10388+ break;
10389+
10390+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10391+ unsigned int addr;
10392+
10393+ if ((ba & 0xFFC00000U) == 0x30800000U)
10394+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10395+ else
10396+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10397+ regs->pc = addr;
10398+ regs->npc = addr+4;
10399+ return 2;
10400+ }
10401+ } while (0);
10402+
10403+ do { /* PaX: patched PLT emulation #3 */
10404+ unsigned int sethi, bajmpl, nop;
10405+
10406+ err = get_user(sethi, (unsigned int *)regs->pc);
10407+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
10408+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10409+
10410+ if (err)
10411+ break;
10412+
10413+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10414+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10415+ nop == 0x01000000U)
10416+ {
10417+ unsigned int addr;
10418+
10419+ addr = (sethi & 0x003FFFFFU) << 10;
10420+ regs->u_regs[UREG_G1] = addr;
10421+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10422+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10423+ else
10424+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10425+ regs->pc = addr;
10426+ regs->npc = addr+4;
10427+ return 2;
10428+ }
10429+ } while (0);
10430+
10431+ do { /* PaX: unpatched PLT emulation step 1 */
10432+ unsigned int sethi, ba, nop;
10433+
10434+ err = get_user(sethi, (unsigned int *)regs->pc);
10435+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
10436+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10437+
10438+ if (err)
10439+ break;
10440+
10441+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10442+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10443+ nop == 0x01000000U)
10444+ {
10445+ unsigned int addr, save, call;
10446+
10447+ if ((ba & 0xFFC00000U) == 0x30800000U)
10448+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10449+ else
10450+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10451+
10452+ err = get_user(save, (unsigned int *)addr);
10453+ err |= get_user(call, (unsigned int *)(addr+4));
10454+ err |= get_user(nop, (unsigned int *)(addr+8));
10455+ if (err)
10456+ break;
10457+
10458+#ifdef CONFIG_PAX_DLRESOLVE
10459+ if (save == 0x9DE3BFA8U &&
10460+ (call & 0xC0000000U) == 0x40000000U &&
10461+ nop == 0x01000000U)
10462+ {
10463+ struct vm_area_struct *vma;
10464+ unsigned long call_dl_resolve;
10465+
10466+ down_read(&current->mm->mmap_sem);
10467+ call_dl_resolve = current->mm->call_dl_resolve;
10468+ up_read(&current->mm->mmap_sem);
10469+ if (likely(call_dl_resolve))
10470+ goto emulate;
10471+
10472+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10473+
10474+ down_write(&current->mm->mmap_sem);
10475+ if (current->mm->call_dl_resolve) {
10476+ call_dl_resolve = current->mm->call_dl_resolve;
10477+ up_write(&current->mm->mmap_sem);
10478+ if (vma)
10479+ kmem_cache_free(vm_area_cachep, vma);
10480+ goto emulate;
10481+ }
10482+
10483+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10484+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10485+ up_write(&current->mm->mmap_sem);
10486+ if (vma)
10487+ kmem_cache_free(vm_area_cachep, vma);
10488+ return 1;
10489+ }
10490+
10491+ if (pax_insert_vma(vma, call_dl_resolve)) {
10492+ up_write(&current->mm->mmap_sem);
10493+ kmem_cache_free(vm_area_cachep, vma);
10494+ return 1;
10495+ }
10496+
10497+ current->mm->call_dl_resolve = call_dl_resolve;
10498+ up_write(&current->mm->mmap_sem);
10499+
10500+emulate:
10501+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10502+ regs->pc = call_dl_resolve;
10503+ regs->npc = addr+4;
10504+ return 3;
10505+ }
10506+#endif
10507+
10508+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10509+ if ((save & 0xFFC00000U) == 0x05000000U &&
10510+ (call & 0xFFFFE000U) == 0x85C0A000U &&
10511+ nop == 0x01000000U)
10512+ {
10513+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10514+ regs->u_regs[UREG_G2] = addr + 4;
10515+ addr = (save & 0x003FFFFFU) << 10;
10516+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10517+ regs->pc = addr;
10518+ regs->npc = addr+4;
10519+ return 3;
10520+ }
10521+ }
10522+ } while (0);
10523+
10524+ do { /* PaX: unpatched PLT emulation step 2 */
10525+ unsigned int save, call, nop;
10526+
10527+ err = get_user(save, (unsigned int *)(regs->pc-4));
10528+ err |= get_user(call, (unsigned int *)regs->pc);
10529+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
10530+ if (err)
10531+ break;
10532+
10533+ if (save == 0x9DE3BFA8U &&
10534+ (call & 0xC0000000U) == 0x40000000U &&
10535+ nop == 0x01000000U)
10536+ {
10537+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
10538+
10539+ regs->u_regs[UREG_RETPC] = regs->pc;
10540+ regs->pc = dl_resolve;
10541+ regs->npc = dl_resolve+4;
10542+ return 3;
10543+ }
10544+ } while (0);
10545+#endif
10546+
10547+ return 1;
10548+}
10549+
10550+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
10551+{
10552+ unsigned long i;
10553+
10554+ printk(KERN_ERR "PAX: bytes at PC: ");
10555+ for (i = 0; i < 8; i++) {
10556+ unsigned int c;
10557+ if (get_user(c, (unsigned int *)pc+i))
10558+ printk(KERN_CONT "???????? ");
10559+ else
10560+ printk(KERN_CONT "%08x ", c);
10561+ }
10562+ printk("\n");
10563+}
10564+#endif
10565+
10566 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
10567 int text_fault)
10568 {
10569@@ -230,6 +504,24 @@ good_area:
10570 if (!(vma->vm_flags & VM_WRITE))
10571 goto bad_area;
10572 } else {
10573+
10574+#ifdef CONFIG_PAX_PAGEEXEC
10575+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
10576+ up_read(&mm->mmap_sem);
10577+ switch (pax_handle_fetch_fault(regs)) {
10578+
10579+#ifdef CONFIG_PAX_EMUPLT
10580+ case 2:
10581+ case 3:
10582+ return;
10583+#endif
10584+
10585+ }
10586+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
10587+ do_group_exit(SIGKILL);
10588+ }
10589+#endif
10590+
10591 /* Allow reads even for write-only mappings */
10592 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
10593 goto bad_area;
10594diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
10595index 5062ff3..e0b75f3 100644
10596--- a/arch/sparc/mm/fault_64.c
10597+++ b/arch/sparc/mm/fault_64.c
10598@@ -21,6 +21,9 @@
10599 #include <linux/kprobes.h>
10600 #include <linux/kdebug.h>
10601 #include <linux/percpu.h>
10602+#include <linux/slab.h>
10603+#include <linux/pagemap.h>
10604+#include <linux/compiler.h>
10605
10606 #include <asm/page.h>
10607 #include <asm/pgtable.h>
10608@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
10609 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
10610 regs->tpc);
10611 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
10612- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
10613+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
10614 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
10615 dump_stack();
10616 unhandled_fault(regs->tpc, current, regs);
10617@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
10618 show_regs(regs);
10619 }
10620
10621+#ifdef CONFIG_PAX_PAGEEXEC
10622+#ifdef CONFIG_PAX_DLRESOLVE
10623+static void pax_emuplt_close(struct vm_area_struct *vma)
10624+{
10625+ vma->vm_mm->call_dl_resolve = 0UL;
10626+}
10627+
10628+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10629+{
10630+ unsigned int *kaddr;
10631+
10632+ vmf->page = alloc_page(GFP_HIGHUSER);
10633+ if (!vmf->page)
10634+ return VM_FAULT_OOM;
10635+
10636+ kaddr = kmap(vmf->page);
10637+ memset(kaddr, 0, PAGE_SIZE);
10638+ kaddr[0] = 0x9DE3BFA8U; /* save */
10639+ flush_dcache_page(vmf->page);
10640+ kunmap(vmf->page);
10641+ return VM_FAULT_MAJOR;
10642+}
10643+
10644+static const struct vm_operations_struct pax_vm_ops = {
10645+ .close = pax_emuplt_close,
10646+ .fault = pax_emuplt_fault
10647+};
10648+
10649+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10650+{
10651+ int ret;
10652+
10653+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10654+ vma->vm_mm = current->mm;
10655+ vma->vm_start = addr;
10656+ vma->vm_end = addr + PAGE_SIZE;
10657+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10658+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10659+ vma->vm_ops = &pax_vm_ops;
10660+
10661+ ret = insert_vm_struct(current->mm, vma);
10662+ if (ret)
10663+ return ret;
10664+
10665+ ++current->mm->total_vm;
10666+ return 0;
10667+}
10668+#endif
10669+
10670+/*
10671+ * PaX: decide what to do with offenders (regs->tpc = fault address)
10672+ *
10673+ * returns 1 when task should be killed
10674+ * 2 when patched PLT trampoline was detected
10675+ * 3 when unpatched PLT trampoline was detected
10676+ */
10677+static int pax_handle_fetch_fault(struct pt_regs *regs)
10678+{
10679+
10680+#ifdef CONFIG_PAX_EMUPLT
10681+ int err;
10682+
10683+ do { /* PaX: patched PLT emulation #1 */
10684+ unsigned int sethi1, sethi2, jmpl;
10685+
10686+ err = get_user(sethi1, (unsigned int *)regs->tpc);
10687+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
10688+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
10689+
10690+ if (err)
10691+ break;
10692+
10693+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10694+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10695+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10696+ {
10697+ unsigned long addr;
10698+
10699+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10700+ addr = regs->u_regs[UREG_G1];
10701+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10702+
10703+ if (test_thread_flag(TIF_32BIT))
10704+ addr &= 0xFFFFFFFFUL;
10705+
10706+ regs->tpc = addr;
10707+ regs->tnpc = addr+4;
10708+ return 2;
10709+ }
10710+ } while (0);
10711+
10712+ do { /* PaX: patched PLT emulation #2 */
10713+ unsigned int ba;
10714+
10715+ err = get_user(ba, (unsigned int *)regs->tpc);
10716+
10717+ if (err)
10718+ break;
10719+
10720+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10721+ unsigned long addr;
10722+
10723+ if ((ba & 0xFFC00000U) == 0x30800000U)
10724+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10725+ else
10726+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10727+
10728+ if (test_thread_flag(TIF_32BIT))
10729+ addr &= 0xFFFFFFFFUL;
10730+
10731+ regs->tpc = addr;
10732+ regs->tnpc = addr+4;
10733+ return 2;
10734+ }
10735+ } while (0);
10736+
10737+ do { /* PaX: patched PLT emulation #3 */
10738+ unsigned int sethi, bajmpl, nop;
10739+
10740+ err = get_user(sethi, (unsigned int *)regs->tpc);
10741+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
10742+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10743+
10744+ if (err)
10745+ break;
10746+
10747+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10748+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10749+ nop == 0x01000000U)
10750+ {
10751+ unsigned long addr;
10752+
10753+ addr = (sethi & 0x003FFFFFU) << 10;
10754+ regs->u_regs[UREG_G1] = addr;
10755+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10756+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10757+ else
10758+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10759+
10760+ if (test_thread_flag(TIF_32BIT))
10761+ addr &= 0xFFFFFFFFUL;
10762+
10763+ regs->tpc = addr;
10764+ regs->tnpc = addr+4;
10765+ return 2;
10766+ }
10767+ } while (0);
10768+
10769+ do { /* PaX: patched PLT emulation #4 */
10770+ unsigned int sethi, mov1, call, mov2;
10771+
10772+ err = get_user(sethi, (unsigned int *)regs->tpc);
10773+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
10774+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
10775+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
10776+
10777+ if (err)
10778+ break;
10779+
10780+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10781+ mov1 == 0x8210000FU &&
10782+ (call & 0xC0000000U) == 0x40000000U &&
10783+ mov2 == 0x9E100001U)
10784+ {
10785+ unsigned long addr;
10786+
10787+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
10788+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10789+
10790+ if (test_thread_flag(TIF_32BIT))
10791+ addr &= 0xFFFFFFFFUL;
10792+
10793+ regs->tpc = addr;
10794+ regs->tnpc = addr+4;
10795+ return 2;
10796+ }
10797+ } while (0);
10798+
10799+ do { /* PaX: patched PLT emulation #5 */
10800+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
10801+
10802+ err = get_user(sethi, (unsigned int *)regs->tpc);
10803+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10804+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10805+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
10806+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
10807+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
10808+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
10809+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
10810+
10811+ if (err)
10812+ break;
10813+
10814+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10815+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10816+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10817+ (or1 & 0xFFFFE000U) == 0x82106000U &&
10818+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
10819+ sllx == 0x83287020U &&
10820+ jmpl == 0x81C04005U &&
10821+ nop == 0x01000000U)
10822+ {
10823+ unsigned long addr;
10824+
10825+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
10826+ regs->u_regs[UREG_G1] <<= 32;
10827+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
10828+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10829+ regs->tpc = addr;
10830+ regs->tnpc = addr+4;
10831+ return 2;
10832+ }
10833+ } while (0);
10834+
10835+ do { /* PaX: patched PLT emulation #6 */
10836+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
10837+
10838+ err = get_user(sethi, (unsigned int *)regs->tpc);
10839+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10840+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10841+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
10842+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
10843+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
10844+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
10845+
10846+ if (err)
10847+ break;
10848+
10849+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10850+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10851+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10852+ sllx == 0x83287020U &&
10853+ (or & 0xFFFFE000U) == 0x8A116000U &&
10854+ jmpl == 0x81C04005U &&
10855+ nop == 0x01000000U)
10856+ {
10857+ unsigned long addr;
10858+
10859+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
10860+ regs->u_regs[UREG_G1] <<= 32;
10861+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
10862+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10863+ regs->tpc = addr;
10864+ regs->tnpc = addr+4;
10865+ return 2;
10866+ }
10867+ } while (0);
10868+
10869+ do { /* PaX: unpatched PLT emulation step 1 */
10870+ unsigned int sethi, ba, nop;
10871+
10872+ err = get_user(sethi, (unsigned int *)regs->tpc);
10873+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
10874+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10875+
10876+ if (err)
10877+ break;
10878+
10879+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10880+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10881+ nop == 0x01000000U)
10882+ {
10883+ unsigned long addr;
10884+ unsigned int save, call;
10885+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
10886+
10887+ if ((ba & 0xFFC00000U) == 0x30800000U)
10888+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10889+ else
10890+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10891+
10892+ if (test_thread_flag(TIF_32BIT))
10893+ addr &= 0xFFFFFFFFUL;
10894+
10895+ err = get_user(save, (unsigned int *)addr);
10896+ err |= get_user(call, (unsigned int *)(addr+4));
10897+ err |= get_user(nop, (unsigned int *)(addr+8));
10898+ if (err)
10899+ break;
10900+
10901+#ifdef CONFIG_PAX_DLRESOLVE
10902+ if (save == 0x9DE3BFA8U &&
10903+ (call & 0xC0000000U) == 0x40000000U &&
10904+ nop == 0x01000000U)
10905+ {
10906+ struct vm_area_struct *vma;
10907+ unsigned long call_dl_resolve;
10908+
10909+ down_read(&current->mm->mmap_sem);
10910+ call_dl_resolve = current->mm->call_dl_resolve;
10911+ up_read(&current->mm->mmap_sem);
10912+ if (likely(call_dl_resolve))
10913+ goto emulate;
10914+
10915+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10916+
10917+ down_write(&current->mm->mmap_sem);
10918+ if (current->mm->call_dl_resolve) {
10919+ call_dl_resolve = current->mm->call_dl_resolve;
10920+ up_write(&current->mm->mmap_sem);
10921+ if (vma)
10922+ kmem_cache_free(vm_area_cachep, vma);
10923+ goto emulate;
10924+ }
10925+
10926+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10927+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10928+ up_write(&current->mm->mmap_sem);
10929+ if (vma)
10930+ kmem_cache_free(vm_area_cachep, vma);
10931+ return 1;
10932+ }
10933+
10934+ if (pax_insert_vma(vma, call_dl_resolve)) {
10935+ up_write(&current->mm->mmap_sem);
10936+ kmem_cache_free(vm_area_cachep, vma);
10937+ return 1;
10938+ }
10939+
10940+ current->mm->call_dl_resolve = call_dl_resolve;
10941+ up_write(&current->mm->mmap_sem);
10942+
10943+emulate:
10944+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10945+ regs->tpc = call_dl_resolve;
10946+ regs->tnpc = addr+4;
10947+ return 3;
10948+ }
10949+#endif
10950+
10951+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10952+ if ((save & 0xFFC00000U) == 0x05000000U &&
10953+ (call & 0xFFFFE000U) == 0x85C0A000U &&
10954+ nop == 0x01000000U)
10955+ {
10956+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10957+ regs->u_regs[UREG_G2] = addr + 4;
10958+ addr = (save & 0x003FFFFFU) << 10;
10959+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10960+
10961+ if (test_thread_flag(TIF_32BIT))
10962+ addr &= 0xFFFFFFFFUL;
10963+
10964+ regs->tpc = addr;
10965+ regs->tnpc = addr+4;
10966+ return 3;
10967+ }
10968+
10969+ /* PaX: 64-bit PLT stub */
10970+ err = get_user(sethi1, (unsigned int *)addr);
10971+ err |= get_user(sethi2, (unsigned int *)(addr+4));
10972+ err |= get_user(or1, (unsigned int *)(addr+8));
10973+ err |= get_user(or2, (unsigned int *)(addr+12));
10974+ err |= get_user(sllx, (unsigned int *)(addr+16));
10975+ err |= get_user(add, (unsigned int *)(addr+20));
10976+ err |= get_user(jmpl, (unsigned int *)(addr+24));
10977+ err |= get_user(nop, (unsigned int *)(addr+28));
10978+ if (err)
10979+ break;
10980+
10981+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
10982+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10983+ (or1 & 0xFFFFE000U) == 0x88112000U &&
10984+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
10985+ sllx == 0x89293020U &&
10986+ add == 0x8A010005U &&
10987+ jmpl == 0x89C14000U &&
10988+ nop == 0x01000000U)
10989+ {
10990+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10991+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
10992+ regs->u_regs[UREG_G4] <<= 32;
10993+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
10994+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
10995+ regs->u_regs[UREG_G4] = addr + 24;
10996+ addr = regs->u_regs[UREG_G5];
10997+ regs->tpc = addr;
10998+ regs->tnpc = addr+4;
10999+ return 3;
11000+ }
11001+ }
11002+ } while (0);
11003+
11004+#ifdef CONFIG_PAX_DLRESOLVE
11005+ do { /* PaX: unpatched PLT emulation step 2 */
11006+ unsigned int save, call, nop;
11007+
11008+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11009+ err |= get_user(call, (unsigned int *)regs->tpc);
11010+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11011+ if (err)
11012+ break;
11013+
11014+ if (save == 0x9DE3BFA8U &&
11015+ (call & 0xC0000000U) == 0x40000000U &&
11016+ nop == 0x01000000U)
11017+ {
11018+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11019+
11020+ if (test_thread_flag(TIF_32BIT))
11021+ dl_resolve &= 0xFFFFFFFFUL;
11022+
11023+ regs->u_regs[UREG_RETPC] = regs->tpc;
11024+ regs->tpc = dl_resolve;
11025+ regs->tnpc = dl_resolve+4;
11026+ return 3;
11027+ }
11028+ } while (0);
11029+#endif
11030+
11031+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11032+ unsigned int sethi, ba, nop;
11033+
11034+ err = get_user(sethi, (unsigned int *)regs->tpc);
11035+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11036+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11037+
11038+ if (err)
11039+ break;
11040+
11041+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11042+ (ba & 0xFFF00000U) == 0x30600000U &&
11043+ nop == 0x01000000U)
11044+ {
11045+ unsigned long addr;
11046+
11047+ addr = (sethi & 0x003FFFFFU) << 10;
11048+ regs->u_regs[UREG_G1] = addr;
11049+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11050+
11051+ if (test_thread_flag(TIF_32BIT))
11052+ addr &= 0xFFFFFFFFUL;
11053+
11054+ regs->tpc = addr;
11055+ regs->tnpc = addr+4;
11056+ return 2;
11057+ }
11058+ } while (0);
11059+
11060+#endif
11061+
11062+ return 1;
11063+}
11064+
11065+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11066+{
11067+ unsigned long i;
11068+
11069+ printk(KERN_ERR "PAX: bytes at PC: ");
11070+ for (i = 0; i < 8; i++) {
11071+ unsigned int c;
11072+ if (get_user(c, (unsigned int *)pc+i))
11073+ printk(KERN_CONT "???????? ");
11074+ else
11075+ printk(KERN_CONT "%08x ", c);
11076+ }
11077+ printk("\n");
11078+}
11079+#endif
11080+
11081 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11082 {
11083 struct mm_struct *mm = current->mm;
11084@@ -341,6 +804,29 @@ retry:
11085 if (!vma)
11086 goto bad_area;
11087
11088+#ifdef CONFIG_PAX_PAGEEXEC
11089+ /* PaX: detect ITLB misses on non-exec pages */
11090+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11091+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11092+ {
11093+ if (address != regs->tpc)
11094+ goto good_area;
11095+
11096+ up_read(&mm->mmap_sem);
11097+ switch (pax_handle_fetch_fault(regs)) {
11098+
11099+#ifdef CONFIG_PAX_EMUPLT
11100+ case 2:
11101+ case 3:
11102+ return;
11103+#endif
11104+
11105+ }
11106+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11107+ do_group_exit(SIGKILL);
11108+ }
11109+#endif
11110+
11111 /* Pure DTLB misses do not tell us whether the fault causing
11112 * load/store/atomic was a write or not, it only says that there
11113 * was no match. So in such a case we (carefully) read the
11114diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11115index d2b5944..d878f3c 100644
11116--- a/arch/sparc/mm/hugetlbpage.c
11117+++ b/arch/sparc/mm/hugetlbpage.c
11118@@ -28,7 +28,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11119 unsigned long addr,
11120 unsigned long len,
11121 unsigned long pgoff,
11122- unsigned long flags)
11123+ unsigned long flags,
11124+ unsigned long offset)
11125 {
11126 unsigned long task_size = TASK_SIZE;
11127 struct vm_unmapped_area_info info;
11128@@ -38,15 +39,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11129
11130 info.flags = 0;
11131 info.length = len;
11132- info.low_limit = TASK_UNMAPPED_BASE;
11133+ info.low_limit = mm->mmap_base;
11134 info.high_limit = min(task_size, VA_EXCLUDE_START);
11135 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11136 info.align_offset = 0;
11137+ info.threadstack_offset = offset;
11138 addr = vm_unmapped_area(&info);
11139
11140 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11141 VM_BUG_ON(addr != -ENOMEM);
11142 info.low_limit = VA_EXCLUDE_END;
11143+
11144+#ifdef CONFIG_PAX_RANDMMAP
11145+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11146+ info.low_limit += mm->delta_mmap;
11147+#endif
11148+
11149 info.high_limit = task_size;
11150 addr = vm_unmapped_area(&info);
11151 }
11152@@ -58,7 +66,8 @@ static unsigned long
11153 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11154 const unsigned long len,
11155 const unsigned long pgoff,
11156- const unsigned long flags)
11157+ const unsigned long flags,
11158+ const unsigned long offset)
11159 {
11160 struct mm_struct *mm = current->mm;
11161 unsigned long addr = addr0;
11162@@ -73,6 +82,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11163 info.high_limit = mm->mmap_base;
11164 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11165 info.align_offset = 0;
11166+ info.threadstack_offset = offset;
11167 addr = vm_unmapped_area(&info);
11168
11169 /*
11170@@ -85,6 +95,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11171 VM_BUG_ON(addr != -ENOMEM);
11172 info.flags = 0;
11173 info.low_limit = TASK_UNMAPPED_BASE;
11174+
11175+#ifdef CONFIG_PAX_RANDMMAP
11176+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11177+ info.low_limit += mm->delta_mmap;
11178+#endif
11179+
11180 info.high_limit = STACK_TOP32;
11181 addr = vm_unmapped_area(&info);
11182 }
11183@@ -99,6 +115,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11184 struct mm_struct *mm = current->mm;
11185 struct vm_area_struct *vma;
11186 unsigned long task_size = TASK_SIZE;
11187+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11188
11189 if (test_thread_flag(TIF_32BIT))
11190 task_size = STACK_TOP32;
11191@@ -114,19 +131,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11192 return addr;
11193 }
11194
11195+#ifdef CONFIG_PAX_RANDMMAP
11196+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11197+#endif
11198+
11199 if (addr) {
11200 addr = ALIGN(addr, HPAGE_SIZE);
11201 vma = find_vma(mm, addr);
11202- if (task_size - len >= addr &&
11203- (!vma || addr + len <= vma->vm_start))
11204+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11205 return addr;
11206 }
11207 if (mm->get_unmapped_area == arch_get_unmapped_area)
11208 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11209- pgoff, flags);
11210+ pgoff, flags, offset);
11211 else
11212 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11213- pgoff, flags);
11214+ pgoff, flags, offset);
11215 }
11216
11217 pte_t *huge_pte_alloc(struct mm_struct *mm,
11218diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11219index ed82eda..0d80e77 100644
11220--- a/arch/sparc/mm/init_64.c
11221+++ b/arch/sparc/mm/init_64.c
11222@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11223 int num_kernel_image_mappings;
11224
11225 #ifdef CONFIG_DEBUG_DCFLUSH
11226-atomic_t dcpage_flushes = ATOMIC_INIT(0);
11227+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11228 #ifdef CONFIG_SMP
11229-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11230+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11231 #endif
11232 #endif
11233
11234@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11235 {
11236 BUG_ON(tlb_type == hypervisor);
11237 #ifdef CONFIG_DEBUG_DCFLUSH
11238- atomic_inc(&dcpage_flushes);
11239+ atomic_inc_unchecked(&dcpage_flushes);
11240 #endif
11241
11242 #ifdef DCACHE_ALIASING_POSSIBLE
11243@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11244
11245 #ifdef CONFIG_DEBUG_DCFLUSH
11246 seq_printf(m, "DCPageFlushes\t: %d\n",
11247- atomic_read(&dcpage_flushes));
11248+ atomic_read_unchecked(&dcpage_flushes));
11249 #ifdef CONFIG_SMP
11250 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11251- atomic_read(&dcpage_flushes_xcall));
11252+ atomic_read_unchecked(&dcpage_flushes_xcall));
11253 #endif /* CONFIG_SMP */
11254 #endif /* CONFIG_DEBUG_DCFLUSH */
11255 }
11256diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11257index f4500c6..889656c 100644
11258--- a/arch/tile/include/asm/atomic_64.h
11259+++ b/arch/tile/include/asm/atomic_64.h
11260@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11261
11262 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11263
11264+#define atomic64_read_unchecked(v) atomic64_read(v)
11265+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11266+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11267+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11268+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11269+#define atomic64_inc_unchecked(v) atomic64_inc(v)
11270+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11271+#define atomic64_dec_unchecked(v) atomic64_dec(v)
11272+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11273+
11274 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11275 #define smp_mb__before_atomic_dec() smp_mb()
11276 #define smp_mb__after_atomic_dec() smp_mb()
11277diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11278index a9a5299..0fce79e 100644
11279--- a/arch/tile/include/asm/cache.h
11280+++ b/arch/tile/include/asm/cache.h
11281@@ -15,11 +15,12 @@
11282 #ifndef _ASM_TILE_CACHE_H
11283 #define _ASM_TILE_CACHE_H
11284
11285+#include <linux/const.h>
11286 #include <arch/chip.h>
11287
11288 /* bytes per L1 data cache line */
11289 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11290-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11291+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11292
11293 /* bytes per L2 cache line */
11294 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11295diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11296index e4d44bd..99927a3 100644
11297--- a/arch/tile/include/asm/uaccess.h
11298+++ b/arch/tile/include/asm/uaccess.h
11299@@ -408,9 +408,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11300 const void __user *from,
11301 unsigned long n)
11302 {
11303- int sz = __compiletime_object_size(to);
11304+ size_t sz = __compiletime_object_size(to);
11305
11306- if (likely(sz == -1 || sz >= n))
11307+ if (likely(sz == (size_t)-1 || sz >= n))
11308 n = _copy_from_user(to, from, n);
11309 else
11310 copy_from_user_overflow();
11311diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11312index 650ccff..45fe2d6 100644
11313--- a/arch/tile/mm/hugetlbpage.c
11314+++ b/arch/tile/mm/hugetlbpage.c
11315@@ -239,6 +239,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11316 info.high_limit = TASK_SIZE;
11317 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11318 info.align_offset = 0;
11319+ info.threadstack_offset = 0;
11320 return vm_unmapped_area(&info);
11321 }
11322
11323@@ -256,6 +257,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11324 info.high_limit = current->mm->mmap_base;
11325 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11326 info.align_offset = 0;
11327+ info.threadstack_offset = 0;
11328 addr = vm_unmapped_area(&info);
11329
11330 /*
11331diff --git a/arch/um/Makefile b/arch/um/Makefile
11332index 133f7de..1d6f2f1 100644
11333--- a/arch/um/Makefile
11334+++ b/arch/um/Makefile
11335@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11336 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
11337 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
11338
11339+ifdef CONSTIFY_PLUGIN
11340+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11341+endif
11342+
11343 #This will adjust *FLAGS accordingly to the platform.
11344 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
11345
11346diff --git a/arch/um/defconfig b/arch/um/defconfig
11347index 08107a7..ab22afe 100644
11348--- a/arch/um/defconfig
11349+++ b/arch/um/defconfig
11350@@ -51,7 +51,6 @@ CONFIG_X86_CMPXCHG=y
11351 CONFIG_X86_L1_CACHE_SHIFT=5
11352 CONFIG_X86_XADD=y
11353 CONFIG_X86_PPRO_FENCE=y
11354-CONFIG_X86_WP_WORKS_OK=y
11355 CONFIG_X86_INVLPG=y
11356 CONFIG_X86_BSWAP=y
11357 CONFIG_X86_POPAD_OK=y
11358diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
11359index 19e1bdd..3665b77 100644
11360--- a/arch/um/include/asm/cache.h
11361+++ b/arch/um/include/asm/cache.h
11362@@ -1,6 +1,7 @@
11363 #ifndef __UM_CACHE_H
11364 #define __UM_CACHE_H
11365
11366+#include <linux/const.h>
11367
11368 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
11369 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11370@@ -12,6 +13,6 @@
11371 # define L1_CACHE_SHIFT 5
11372 #endif
11373
11374-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11375+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11376
11377 #endif
11378diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
11379index 2e0a6b1..a64d0f5 100644
11380--- a/arch/um/include/asm/kmap_types.h
11381+++ b/arch/um/include/asm/kmap_types.h
11382@@ -8,6 +8,6 @@
11383
11384 /* No more #include "asm/arch/kmap_types.h" ! */
11385
11386-#define KM_TYPE_NR 14
11387+#define KM_TYPE_NR 15
11388
11389 #endif
11390diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
11391index 5ff53d9..5850cdf 100644
11392--- a/arch/um/include/asm/page.h
11393+++ b/arch/um/include/asm/page.h
11394@@ -14,6 +14,9 @@
11395 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
11396 #define PAGE_MASK (~(PAGE_SIZE-1))
11397
11398+#define ktla_ktva(addr) (addr)
11399+#define ktva_ktla(addr) (addr)
11400+
11401 #ifndef __ASSEMBLY__
11402
11403 struct page;
11404diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
11405index 0032f92..cd151e0 100644
11406--- a/arch/um/include/asm/pgtable-3level.h
11407+++ b/arch/um/include/asm/pgtable-3level.h
11408@@ -58,6 +58,7 @@
11409 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
11410 #define pud_populate(mm, pud, pmd) \
11411 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
11412+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
11413
11414 #ifdef CONFIG_64BIT
11415 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
11416diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
11417index bbcef52..6a2a483 100644
11418--- a/arch/um/kernel/process.c
11419+++ b/arch/um/kernel/process.c
11420@@ -367,22 +367,6 @@ int singlestepping(void * t)
11421 return 2;
11422 }
11423
11424-/*
11425- * Only x86 and x86_64 have an arch_align_stack().
11426- * All other arches have "#define arch_align_stack(x) (x)"
11427- * in their asm/system.h
11428- * As this is included in UML from asm-um/system-generic.h,
11429- * we can use it to behave as the subarch does.
11430- */
11431-#ifndef arch_align_stack
11432-unsigned long arch_align_stack(unsigned long sp)
11433-{
11434- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
11435- sp -= get_random_int() % 8192;
11436- return sp & ~0xf;
11437-}
11438-#endif
11439-
11440 unsigned long get_wchan(struct task_struct *p)
11441 {
11442 unsigned long stack_page, sp, ip;
11443diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
11444index ad8f795..2c7eec6 100644
11445--- a/arch/unicore32/include/asm/cache.h
11446+++ b/arch/unicore32/include/asm/cache.h
11447@@ -12,8 +12,10 @@
11448 #ifndef __UNICORE_CACHE_H__
11449 #define __UNICORE_CACHE_H__
11450
11451-#define L1_CACHE_SHIFT (5)
11452-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11453+#include <linux/const.h>
11454+
11455+#define L1_CACHE_SHIFT 5
11456+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11457
11458 /*
11459 * Memory returned by kmalloc() may be used for DMA, so we must make
11460diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
11461index b32ebf9..5704f98 100644
11462--- a/arch/x86/Kconfig
11463+++ b/arch/x86/Kconfig
11464@@ -248,7 +248,7 @@ config X86_HT
11465
11466 config X86_32_LAZY_GS
11467 def_bool y
11468- depends on X86_32 && !CC_STACKPROTECTOR
11469+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
11470
11471 config ARCH_HWEIGHT_CFLAGS
11472 string
11473@@ -1088,6 +1088,7 @@ config MICROCODE_EARLY
11474
11475 config X86_MSR
11476 tristate "/dev/cpu/*/msr - Model-specific register support"
11477+ depends on !GRKERNSEC_KMEM
11478 ---help---
11479 This device gives privileged processes access to the x86
11480 Model-Specific Registers (MSRs). It is a character device with
11481@@ -1111,7 +1112,7 @@ choice
11482
11483 config NOHIGHMEM
11484 bool "off"
11485- depends on !X86_NUMAQ
11486+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11487 ---help---
11488 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
11489 However, the address space of 32-bit x86 processors is only 4
11490@@ -1148,7 +1149,7 @@ config NOHIGHMEM
11491
11492 config HIGHMEM4G
11493 bool "4GB"
11494- depends on !X86_NUMAQ
11495+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11496 ---help---
11497 Select this if you have a 32-bit processor and between 1 and 4
11498 gigabytes of physical RAM.
11499@@ -1201,7 +1202,7 @@ config PAGE_OFFSET
11500 hex
11501 default 0xB0000000 if VMSPLIT_3G_OPT
11502 default 0x80000000 if VMSPLIT_2G
11503- default 0x78000000 if VMSPLIT_2G_OPT
11504+ default 0x70000000 if VMSPLIT_2G_OPT
11505 default 0x40000000 if VMSPLIT_1G
11506 default 0xC0000000
11507 depends on X86_32
11508@@ -1599,6 +1600,7 @@ config SECCOMP
11509
11510 config CC_STACKPROTECTOR
11511 bool "Enable -fstack-protector buffer overflow detection"
11512+ depends on X86_64 || !PAX_MEMORY_UDEREF
11513 ---help---
11514 This option turns on the -fstack-protector GCC feature. This
11515 feature puts, at the beginning of functions, a canary value on
11516@@ -1718,6 +1720,8 @@ config X86_NEED_RELOCS
11517 config PHYSICAL_ALIGN
11518 hex "Alignment value to which kernel should be aligned" if X86_32
11519 default "0x1000000"
11520+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
11521+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
11522 range 0x2000 0x1000000
11523 ---help---
11524 This value puts the alignment restrictions on physical address
11525@@ -1793,9 +1797,10 @@ config DEBUG_HOTPLUG_CPU0
11526 If unsure, say N.
11527
11528 config COMPAT_VDSO
11529- def_bool y
11530+ def_bool n
11531 prompt "Compat VDSO support"
11532 depends on X86_32 || IA32_EMULATION
11533+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
11534 ---help---
11535 Map the 32-bit VDSO to the predictable old-style address too.
11536
11537diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
11538index c026cca..14657ae 100644
11539--- a/arch/x86/Kconfig.cpu
11540+++ b/arch/x86/Kconfig.cpu
11541@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
11542
11543 config X86_F00F_BUG
11544 def_bool y
11545- depends on M586MMX || M586TSC || M586 || M486
11546+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
11547
11548 config X86_INVD_BUG
11549 def_bool y
11550@@ -327,7 +327,7 @@ config X86_INVD_BUG
11551
11552 config X86_ALIGNMENT_16
11553 def_bool y
11554- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11555+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11556
11557 config X86_INTEL_USERCOPY
11558 def_bool y
11559@@ -373,7 +373,7 @@ config X86_CMPXCHG64
11560 # generates cmov.
11561 config X86_CMOV
11562 def_bool y
11563- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11564+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11565
11566 config X86_MINIMUM_CPU_FAMILY
11567 int
11568diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
11569index 78d91af..8ceb94b 100644
11570--- a/arch/x86/Kconfig.debug
11571+++ b/arch/x86/Kconfig.debug
11572@@ -74,7 +74,7 @@ config X86_PTDUMP
11573 config DEBUG_RODATA
11574 bool "Write protect kernel read-only data structures"
11575 default y
11576- depends on DEBUG_KERNEL
11577+ depends on DEBUG_KERNEL && BROKEN
11578 ---help---
11579 Mark the kernel read-only data as write-protected in the pagetables,
11580 in order to catch accidental (and incorrect) writes to such const
11581@@ -92,7 +92,7 @@ config DEBUG_RODATA_TEST
11582
11583 config DEBUG_SET_MODULE_RONX
11584 bool "Set loadable kernel module data as NX and text as RO"
11585- depends on MODULES
11586+ depends on MODULES && BROKEN
11587 ---help---
11588 This option helps catch unintended modifications to loadable
11589 kernel module's text and read-only data. It also prevents execution
11590diff --git a/arch/x86/Makefile b/arch/x86/Makefile
11591index 07639c6..6f2c901 100644
11592--- a/arch/x86/Makefile
11593+++ b/arch/x86/Makefile
11594@@ -54,6 +54,7 @@ else
11595 UTS_MACHINE := x86_64
11596 CHECKFLAGS += -D__x86_64__ -m64
11597
11598+ biarch := $(call cc-option,-m64)
11599 KBUILD_AFLAGS += -m64
11600 KBUILD_CFLAGS += -m64
11601
11602@@ -241,3 +242,12 @@ define archhelp
11603 echo ' FDINITRD=file initrd for the booted kernel'
11604 echo ' kvmconfig - Enable additional options for guest kernel support'
11605 endef
11606+
11607+define OLD_LD
11608+
11609+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
11610+*** Please upgrade your binutils to 2.18 or newer
11611+endef
11612+
11613+archprepare:
11614+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
11615diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
11616index 379814b..add62ce 100644
11617--- a/arch/x86/boot/Makefile
11618+++ b/arch/x86/boot/Makefile
11619@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
11620 $(call cc-option, -fno-stack-protector) \
11621 $(call cc-option, -mpreferred-stack-boundary=2)
11622 KBUILD_CFLAGS += $(call cc-option, -m32)
11623+ifdef CONSTIFY_PLUGIN
11624+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11625+endif
11626 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11627 GCOV_PROFILE := n
11628
11629diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
11630index 878e4b9..20537ab 100644
11631--- a/arch/x86/boot/bitops.h
11632+++ b/arch/x86/boot/bitops.h
11633@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11634 u8 v;
11635 const u32 *p = (const u32 *)addr;
11636
11637- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11638+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11639 return v;
11640 }
11641
11642@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11643
11644 static inline void set_bit(int nr, void *addr)
11645 {
11646- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11647+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11648 }
11649
11650 #endif /* BOOT_BITOPS_H */
11651diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
11652index 5b75319..331a4ca 100644
11653--- a/arch/x86/boot/boot.h
11654+++ b/arch/x86/boot/boot.h
11655@@ -85,7 +85,7 @@ static inline void io_delay(void)
11656 static inline u16 ds(void)
11657 {
11658 u16 seg;
11659- asm("movw %%ds,%0" : "=rm" (seg));
11660+ asm volatile("movw %%ds,%0" : "=rm" (seg));
11661 return seg;
11662 }
11663
11664@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
11665 static inline int memcmp(const void *s1, const void *s2, size_t len)
11666 {
11667 u8 diff;
11668- asm("repe; cmpsb; setnz %0"
11669+ asm volatile("repe; cmpsb; setnz %0"
11670 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
11671 return diff;
11672 }
11673diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
11674index dcd90df..c830d7d 100644
11675--- a/arch/x86/boot/compressed/Makefile
11676+++ b/arch/x86/boot/compressed/Makefile
11677@@ -15,6 +15,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
11678 KBUILD_CFLAGS += $(cflags-y)
11679 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
11680 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
11681+ifdef CONSTIFY_PLUGIN
11682+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11683+endif
11684
11685 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11686 GCOV_PROFILE := n
11687diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
11688index b7388a4..03844ec 100644
11689--- a/arch/x86/boot/compressed/eboot.c
11690+++ b/arch/x86/boot/compressed/eboot.c
11691@@ -150,7 +150,6 @@ again:
11692 *addr = max_addr;
11693 }
11694
11695-free_pool:
11696 efi_call_phys1(sys_table->boottime->free_pool, map);
11697
11698 fail:
11699@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
11700 if (i == map_size / desc_size)
11701 status = EFI_NOT_FOUND;
11702
11703-free_pool:
11704 efi_call_phys1(sys_table->boottime->free_pool, map);
11705 fail:
11706 return status;
11707diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
11708index a53440e..c3dbf1e 100644
11709--- a/arch/x86/boot/compressed/efi_stub_32.S
11710+++ b/arch/x86/boot/compressed/efi_stub_32.S
11711@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
11712 * parameter 2, ..., param n. To make things easy, we save the return
11713 * address of efi_call_phys in a global variable.
11714 */
11715- popl %ecx
11716- movl %ecx, saved_return_addr(%edx)
11717- /* get the function pointer into ECX*/
11718- popl %ecx
11719- movl %ecx, efi_rt_function_ptr(%edx)
11720+ popl saved_return_addr(%edx)
11721+ popl efi_rt_function_ptr(%edx)
11722
11723 /*
11724 * 3. Call the physical function.
11725 */
11726- call *%ecx
11727+ call *efi_rt_function_ptr(%edx)
11728
11729 /*
11730 * 4. Balance the stack. And because EAX contain the return value,
11731@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
11732 1: popl %edx
11733 subl $1b, %edx
11734
11735- movl efi_rt_function_ptr(%edx), %ecx
11736- pushl %ecx
11737+ pushl efi_rt_function_ptr(%edx)
11738
11739 /*
11740 * 10. Push the saved return address onto the stack and return.
11741 */
11742- movl saved_return_addr(%edx), %ecx
11743- pushl %ecx
11744- ret
11745+ jmpl *saved_return_addr(%edx)
11746 ENDPROC(efi_call_phys)
11747 .previous
11748
11749diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
11750index 1e3184f..0d11e2e 100644
11751--- a/arch/x86/boot/compressed/head_32.S
11752+++ b/arch/x86/boot/compressed/head_32.S
11753@@ -118,7 +118,7 @@ preferred_addr:
11754 notl %eax
11755 andl %eax, %ebx
11756 #else
11757- movl $LOAD_PHYSICAL_ADDR, %ebx
11758+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11759 #endif
11760
11761 /* Target address to relocate to for decompression */
11762@@ -204,7 +204,7 @@ relocated:
11763 * and where it was actually loaded.
11764 */
11765 movl %ebp, %ebx
11766- subl $LOAD_PHYSICAL_ADDR, %ebx
11767+ subl $____LOAD_PHYSICAL_ADDR, %ebx
11768 jz 2f /* Nothing to be done if loaded at compiled addr. */
11769 /*
11770 * Process relocations.
11771@@ -212,8 +212,7 @@ relocated:
11772
11773 1: subl $4, %edi
11774 movl (%edi), %ecx
11775- testl %ecx, %ecx
11776- jz 2f
11777+ jecxz 2f
11778 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
11779 jmp 1b
11780 2:
11781diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
11782index 06e71c2..88a98264 100644
11783--- a/arch/x86/boot/compressed/head_64.S
11784+++ b/arch/x86/boot/compressed/head_64.S
11785@@ -95,7 +95,7 @@ ENTRY(startup_32)
11786 notl %eax
11787 andl %eax, %ebx
11788 #else
11789- movl $LOAD_PHYSICAL_ADDR, %ebx
11790+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11791 #endif
11792
11793 /* Target address to relocate to for decompression */
11794@@ -270,7 +270,7 @@ preferred_addr:
11795 notq %rax
11796 andq %rax, %rbp
11797 #else
11798- movq $LOAD_PHYSICAL_ADDR, %rbp
11799+ movq $____LOAD_PHYSICAL_ADDR, %rbp
11800 #endif
11801
11802 /* Target address to relocate to for decompression */
11803@@ -361,8 +361,8 @@ gdt:
11804 .long gdt
11805 .word 0
11806 .quad 0x0000000000000000 /* NULL descriptor */
11807- .quad 0x00af9a000000ffff /* __KERNEL_CS */
11808- .quad 0x00cf92000000ffff /* __KERNEL_DS */
11809+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
11810+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
11811 .quad 0x0080890000000000 /* TS descriptor */
11812 .quad 0x0000000000000000 /* TS continued */
11813 gdt_end:
11814diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
11815index 0319c88..7c1931f 100644
11816--- a/arch/x86/boot/compressed/misc.c
11817+++ b/arch/x86/boot/compressed/misc.c
11818@@ -307,7 +307,7 @@ static void parse_elf(void *output)
11819 case PT_LOAD:
11820 #ifdef CONFIG_RELOCATABLE
11821 dest = output;
11822- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
11823+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
11824 #else
11825 dest = (void *)(phdr->p_paddr);
11826 #endif
11827@@ -358,7 +358,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
11828 error("Destination address too large");
11829 #endif
11830 #ifndef CONFIG_RELOCATABLE
11831- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
11832+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
11833 error("Wrong destination address");
11834 #endif
11835
11836diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
11837index 4d3ff03..e4972ff 100644
11838--- a/arch/x86/boot/cpucheck.c
11839+++ b/arch/x86/boot/cpucheck.c
11840@@ -74,7 +74,7 @@ static int has_fpu(void)
11841 u16 fcw = -1, fsw = -1;
11842 u32 cr0;
11843
11844- asm("movl %%cr0,%0" : "=r" (cr0));
11845+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
11846 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
11847 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
11848 asm volatile("movl %0,%%cr0" : : "r" (cr0));
11849@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
11850 {
11851 u32 f0, f1;
11852
11853- asm("pushfl ; "
11854+ asm volatile("pushfl ; "
11855 "pushfl ; "
11856 "popl %0 ; "
11857 "movl %0,%1 ; "
11858@@ -115,7 +115,7 @@ static void get_flags(void)
11859 set_bit(X86_FEATURE_FPU, cpu.flags);
11860
11861 if (has_eflag(X86_EFLAGS_ID)) {
11862- asm("cpuid"
11863+ asm volatile("cpuid"
11864 : "=a" (max_intel_level),
11865 "=b" (cpu_vendor[0]),
11866 "=d" (cpu_vendor[1]),
11867@@ -124,7 +124,7 @@ static void get_flags(void)
11868
11869 if (max_intel_level >= 0x00000001 &&
11870 max_intel_level <= 0x0000ffff) {
11871- asm("cpuid"
11872+ asm volatile("cpuid"
11873 : "=a" (tfms),
11874 "=c" (cpu.flags[4]),
11875 "=d" (cpu.flags[0])
11876@@ -136,7 +136,7 @@ static void get_flags(void)
11877 cpu.model += ((tfms >> 16) & 0xf) << 4;
11878 }
11879
11880- asm("cpuid"
11881+ asm volatile("cpuid"
11882 : "=a" (max_amd_level)
11883 : "a" (0x80000000)
11884 : "ebx", "ecx", "edx");
11885@@ -144,7 +144,7 @@ static void get_flags(void)
11886 if (max_amd_level >= 0x80000001 &&
11887 max_amd_level <= 0x8000ffff) {
11888 u32 eax = 0x80000001;
11889- asm("cpuid"
11890+ asm volatile("cpuid"
11891 : "+a" (eax),
11892 "=c" (cpu.flags[6]),
11893 "=d" (cpu.flags[1])
11894@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11895 u32 ecx = MSR_K7_HWCR;
11896 u32 eax, edx;
11897
11898- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11899+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11900 eax &= ~(1 << 15);
11901- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11902+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11903
11904 get_flags(); /* Make sure it really did something */
11905 err = check_flags();
11906@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11907 u32 ecx = MSR_VIA_FCR;
11908 u32 eax, edx;
11909
11910- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11911+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11912 eax |= (1<<1)|(1<<7);
11913- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11914+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11915
11916 set_bit(X86_FEATURE_CX8, cpu.flags);
11917 err = check_flags();
11918@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11919 u32 eax, edx;
11920 u32 level = 1;
11921
11922- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11923- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
11924- asm("cpuid"
11925+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11926+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
11927+ asm volatile("cpuid"
11928 : "+a" (level), "=d" (cpu.flags[0])
11929 : : "ecx", "ebx");
11930- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11931+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11932
11933 err = check_flags();
11934 }
11935diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
11936index 9ec06a1..2c25e79 100644
11937--- a/arch/x86/boot/header.S
11938+++ b/arch/x86/boot/header.S
11939@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
11940 # single linked list of
11941 # struct setup_data
11942
11943-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
11944+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
11945
11946 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
11947+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
11948+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
11949+#else
11950 #define VO_INIT_SIZE (VO__end - VO__text)
11951+#endif
11952 #if ZO_INIT_SIZE > VO_INIT_SIZE
11953 #define INIT_SIZE ZO_INIT_SIZE
11954 #else
11955diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
11956index db75d07..8e6d0af 100644
11957--- a/arch/x86/boot/memory.c
11958+++ b/arch/x86/boot/memory.c
11959@@ -19,7 +19,7 @@
11960
11961 static int detect_memory_e820(void)
11962 {
11963- int count = 0;
11964+ unsigned int count = 0;
11965 struct biosregs ireg, oreg;
11966 struct e820entry *desc = boot_params.e820_map;
11967 static struct e820entry buf; /* static so it is zeroed */
11968diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
11969index 11e8c6e..fdbb1ed 100644
11970--- a/arch/x86/boot/video-vesa.c
11971+++ b/arch/x86/boot/video-vesa.c
11972@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
11973
11974 boot_params.screen_info.vesapm_seg = oreg.es;
11975 boot_params.screen_info.vesapm_off = oreg.di;
11976+ boot_params.screen_info.vesapm_size = oreg.cx;
11977 }
11978
11979 /*
11980diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
11981index 43eda28..5ab5fdb 100644
11982--- a/arch/x86/boot/video.c
11983+++ b/arch/x86/boot/video.c
11984@@ -96,7 +96,7 @@ static void store_mode_params(void)
11985 static unsigned int get_entry(void)
11986 {
11987 char entry_buf[4];
11988- int i, len = 0;
11989+ unsigned int i, len = 0;
11990 int key;
11991 unsigned int v;
11992
11993diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
11994index 9105655..5e37f27 100644
11995--- a/arch/x86/crypto/aes-x86_64-asm_64.S
11996+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
11997@@ -8,6 +8,8 @@
11998 * including this sentence is retained in full.
11999 */
12000
12001+#include <asm/alternative-asm.h>
12002+
12003 .extern crypto_ft_tab
12004 .extern crypto_it_tab
12005 .extern crypto_fl_tab
12006@@ -70,6 +72,8 @@
12007 je B192; \
12008 leaq 32(r9),r9;
12009
12010+#define ret pax_force_retaddr 0, 1; ret
12011+
12012 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12013 movq r1,r2; \
12014 movq r3,r4; \
12015diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12016index 477e9d7..3ab339f 100644
12017--- a/arch/x86/crypto/aesni-intel_asm.S
12018+++ b/arch/x86/crypto/aesni-intel_asm.S
12019@@ -31,6 +31,7 @@
12020
12021 #include <linux/linkage.h>
12022 #include <asm/inst.h>
12023+#include <asm/alternative-asm.h>
12024
12025 #ifdef __x86_64__
12026 .data
12027@@ -1441,6 +1442,7 @@ _return_T_done_decrypt:
12028 pop %r14
12029 pop %r13
12030 pop %r12
12031+ pax_force_retaddr 0, 1
12032 ret
12033 ENDPROC(aesni_gcm_dec)
12034
12035@@ -1705,6 +1707,7 @@ _return_T_done_encrypt:
12036 pop %r14
12037 pop %r13
12038 pop %r12
12039+ pax_force_retaddr 0, 1
12040 ret
12041 ENDPROC(aesni_gcm_enc)
12042
12043@@ -1722,6 +1725,7 @@ _key_expansion_256a:
12044 pxor %xmm1, %xmm0
12045 movaps %xmm0, (TKEYP)
12046 add $0x10, TKEYP
12047+ pax_force_retaddr_bts
12048 ret
12049 ENDPROC(_key_expansion_128)
12050 ENDPROC(_key_expansion_256a)
12051@@ -1748,6 +1752,7 @@ _key_expansion_192a:
12052 shufps $0b01001110, %xmm2, %xmm1
12053 movaps %xmm1, 0x10(TKEYP)
12054 add $0x20, TKEYP
12055+ pax_force_retaddr_bts
12056 ret
12057 ENDPROC(_key_expansion_192a)
12058
12059@@ -1768,6 +1773,7 @@ _key_expansion_192b:
12060
12061 movaps %xmm0, (TKEYP)
12062 add $0x10, TKEYP
12063+ pax_force_retaddr_bts
12064 ret
12065 ENDPROC(_key_expansion_192b)
12066
12067@@ -1781,6 +1787,7 @@ _key_expansion_256b:
12068 pxor %xmm1, %xmm2
12069 movaps %xmm2, (TKEYP)
12070 add $0x10, TKEYP
12071+ pax_force_retaddr_bts
12072 ret
12073 ENDPROC(_key_expansion_256b)
12074
12075@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12076 #ifndef __x86_64__
12077 popl KEYP
12078 #endif
12079+ pax_force_retaddr 0, 1
12080 ret
12081 ENDPROC(aesni_set_key)
12082
12083@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12084 popl KLEN
12085 popl KEYP
12086 #endif
12087+ pax_force_retaddr 0, 1
12088 ret
12089 ENDPROC(aesni_enc)
12090
12091@@ -1974,6 +1983,7 @@ _aesni_enc1:
12092 AESENC KEY STATE
12093 movaps 0x70(TKEYP), KEY
12094 AESENCLAST KEY STATE
12095+ pax_force_retaddr_bts
12096 ret
12097 ENDPROC(_aesni_enc1)
12098
12099@@ -2083,6 +2093,7 @@ _aesni_enc4:
12100 AESENCLAST KEY STATE2
12101 AESENCLAST KEY STATE3
12102 AESENCLAST KEY STATE4
12103+ pax_force_retaddr_bts
12104 ret
12105 ENDPROC(_aesni_enc4)
12106
12107@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12108 popl KLEN
12109 popl KEYP
12110 #endif
12111+ pax_force_retaddr 0, 1
12112 ret
12113 ENDPROC(aesni_dec)
12114
12115@@ -2164,6 +2176,7 @@ _aesni_dec1:
12116 AESDEC KEY STATE
12117 movaps 0x70(TKEYP), KEY
12118 AESDECLAST KEY STATE
12119+ pax_force_retaddr_bts
12120 ret
12121 ENDPROC(_aesni_dec1)
12122
12123@@ -2273,6 +2286,7 @@ _aesni_dec4:
12124 AESDECLAST KEY STATE2
12125 AESDECLAST KEY STATE3
12126 AESDECLAST KEY STATE4
12127+ pax_force_retaddr_bts
12128 ret
12129 ENDPROC(_aesni_dec4)
12130
12131@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12132 popl KEYP
12133 popl LEN
12134 #endif
12135+ pax_force_retaddr 0, 1
12136 ret
12137 ENDPROC(aesni_ecb_enc)
12138
12139@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12140 popl KEYP
12141 popl LEN
12142 #endif
12143+ pax_force_retaddr 0, 1
12144 ret
12145 ENDPROC(aesni_ecb_dec)
12146
12147@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12148 popl LEN
12149 popl IVP
12150 #endif
12151+ pax_force_retaddr 0, 1
12152 ret
12153 ENDPROC(aesni_cbc_enc)
12154
12155@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
12156 popl LEN
12157 popl IVP
12158 #endif
12159+ pax_force_retaddr 0, 1
12160 ret
12161 ENDPROC(aesni_cbc_dec)
12162
12163@@ -2550,6 +2568,7 @@ _aesni_inc_init:
12164 mov $1, TCTR_LOW
12165 MOVQ_R64_XMM TCTR_LOW INC
12166 MOVQ_R64_XMM CTR TCTR_LOW
12167+ pax_force_retaddr_bts
12168 ret
12169 ENDPROC(_aesni_inc_init)
12170
12171@@ -2579,6 +2598,7 @@ _aesni_inc:
12172 .Linc_low:
12173 movaps CTR, IV
12174 PSHUFB_XMM BSWAP_MASK IV
12175+ pax_force_retaddr_bts
12176 ret
12177 ENDPROC(_aesni_inc)
12178
12179@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
12180 .Lctr_enc_ret:
12181 movups IV, (IVP)
12182 .Lctr_enc_just_ret:
12183+ pax_force_retaddr 0, 1
12184 ret
12185 ENDPROC(aesni_ctr_enc)
12186
12187@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
12188 pxor INC, STATE4
12189 movdqu STATE4, 0x70(OUTP)
12190
12191+ pax_force_retaddr 0, 1
12192 ret
12193 ENDPROC(aesni_xts_crypt8)
12194
12195diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12196index 246c670..4d1ed00 100644
12197--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
12198+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12199@@ -21,6 +21,7 @@
12200 */
12201
12202 #include <linux/linkage.h>
12203+#include <asm/alternative-asm.h>
12204
12205 .file "blowfish-x86_64-asm.S"
12206 .text
12207@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
12208 jnz .L__enc_xor;
12209
12210 write_block();
12211+ pax_force_retaddr 0, 1
12212 ret;
12213 .L__enc_xor:
12214 xor_block();
12215+ pax_force_retaddr 0, 1
12216 ret;
12217 ENDPROC(__blowfish_enc_blk)
12218
12219@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
12220
12221 movq %r11, %rbp;
12222
12223+ pax_force_retaddr 0, 1
12224 ret;
12225 ENDPROC(blowfish_dec_blk)
12226
12227@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
12228
12229 popq %rbx;
12230 popq %rbp;
12231+ pax_force_retaddr 0, 1
12232 ret;
12233
12234 .L__enc_xor4:
12235@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
12236
12237 popq %rbx;
12238 popq %rbp;
12239+ pax_force_retaddr 0, 1
12240 ret;
12241 ENDPROC(__blowfish_enc_blk_4way)
12242
12243@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
12244 popq %rbx;
12245 popq %rbp;
12246
12247+ pax_force_retaddr 0, 1
12248 ret;
12249 ENDPROC(blowfish_dec_blk_4way)
12250diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12251index ce71f92..2dd5b1e 100644
12252--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12253+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12254@@ -16,6 +16,7 @@
12255 */
12256
12257 #include <linux/linkage.h>
12258+#include <asm/alternative-asm.h>
12259
12260 #define CAMELLIA_TABLE_BYTE_LEN 272
12261
12262@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12263 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
12264 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
12265 %rcx, (%r9));
12266+ pax_force_retaddr_bts
12267 ret;
12268 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12269
12270@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12271 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
12272 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
12273 %rax, (%r9));
12274+ pax_force_retaddr_bts
12275 ret;
12276 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12277
12278@@ -780,6 +783,7 @@ __camellia_enc_blk16:
12279 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12280 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
12281
12282+ pax_force_retaddr_bts
12283 ret;
12284
12285 .align 8
12286@@ -865,6 +869,7 @@ __camellia_dec_blk16:
12287 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12288 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
12289
12290+ pax_force_retaddr_bts
12291 ret;
12292
12293 .align 8
12294@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
12295 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12296 %xmm8, %rsi);
12297
12298+ pax_force_retaddr 0, 1
12299 ret;
12300 ENDPROC(camellia_ecb_enc_16way)
12301
12302@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
12303 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12304 %xmm8, %rsi);
12305
12306+ pax_force_retaddr 0, 1
12307 ret;
12308 ENDPROC(camellia_ecb_dec_16way)
12309
12310@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
12311 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12312 %xmm8, %rsi);
12313
12314+ pax_force_retaddr 0, 1
12315 ret;
12316 ENDPROC(camellia_cbc_dec_16way)
12317
12318@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
12319 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12320 %xmm8, %rsi);
12321
12322+ pax_force_retaddr 0, 1
12323 ret;
12324 ENDPROC(camellia_ctr_16way)
12325
12326@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
12327 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12328 %xmm8, %rsi);
12329
12330+ pax_force_retaddr 0, 1
12331 ret;
12332 ENDPROC(camellia_xts_crypt_16way)
12333
12334diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12335index 0e0b886..8fc756a 100644
12336--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12337+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12338@@ -11,6 +11,7 @@
12339 */
12340
12341 #include <linux/linkage.h>
12342+#include <asm/alternative-asm.h>
12343
12344 #define CAMELLIA_TABLE_BYTE_LEN 272
12345
12346@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12347 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
12348 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
12349 %rcx, (%r9));
12350+ pax_force_retaddr_bts
12351 ret;
12352 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12353
12354@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12355 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
12356 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
12357 %rax, (%r9));
12358+ pax_force_retaddr_bts
12359 ret;
12360 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12361
12362@@ -820,6 +823,7 @@ __camellia_enc_blk32:
12363 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12364 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
12365
12366+ pax_force_retaddr_bts
12367 ret;
12368
12369 .align 8
12370@@ -905,6 +909,7 @@ __camellia_dec_blk32:
12371 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12372 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
12373
12374+ pax_force_retaddr_bts
12375 ret;
12376
12377 .align 8
12378@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
12379
12380 vzeroupper;
12381
12382+ pax_force_retaddr 0, 1
12383 ret;
12384 ENDPROC(camellia_ecb_enc_32way)
12385
12386@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
12387
12388 vzeroupper;
12389
12390+ pax_force_retaddr 0, 1
12391 ret;
12392 ENDPROC(camellia_ecb_dec_32way)
12393
12394@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
12395
12396 vzeroupper;
12397
12398+ pax_force_retaddr 0, 1
12399 ret;
12400 ENDPROC(camellia_cbc_dec_32way)
12401
12402@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
12403
12404 vzeroupper;
12405
12406+ pax_force_retaddr 0, 1
12407 ret;
12408 ENDPROC(camellia_ctr_32way)
12409
12410@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
12411
12412 vzeroupper;
12413
12414+ pax_force_retaddr 0, 1
12415 ret;
12416 ENDPROC(camellia_xts_crypt_32way)
12417
12418diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
12419index 310319c..ce174a4 100644
12420--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
12421+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
12422@@ -21,6 +21,7 @@
12423 */
12424
12425 #include <linux/linkage.h>
12426+#include <asm/alternative-asm.h>
12427
12428 .file "camellia-x86_64-asm_64.S"
12429 .text
12430@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
12431 enc_outunpack(mov, RT1);
12432
12433 movq RRBP, %rbp;
12434+ pax_force_retaddr 0, 1
12435 ret;
12436
12437 .L__enc_xor:
12438 enc_outunpack(xor, RT1);
12439
12440 movq RRBP, %rbp;
12441+ pax_force_retaddr 0, 1
12442 ret;
12443 ENDPROC(__camellia_enc_blk)
12444
12445@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
12446 dec_outunpack();
12447
12448 movq RRBP, %rbp;
12449+ pax_force_retaddr 0, 1
12450 ret;
12451 ENDPROC(camellia_dec_blk)
12452
12453@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
12454
12455 movq RRBP, %rbp;
12456 popq %rbx;
12457+ pax_force_retaddr 0, 1
12458 ret;
12459
12460 .L__enc2_xor:
12461@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
12462
12463 movq RRBP, %rbp;
12464 popq %rbx;
12465+ pax_force_retaddr 0, 1
12466 ret;
12467 ENDPROC(__camellia_enc_blk_2way)
12468
12469@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
12470
12471 movq RRBP, %rbp;
12472 movq RXOR, %rbx;
12473+ pax_force_retaddr 0, 1
12474 ret;
12475 ENDPROC(camellia_dec_blk_2way)
12476diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12477index c35fd5d..c1ee236 100644
12478--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12479+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12480@@ -24,6 +24,7 @@
12481 */
12482
12483 #include <linux/linkage.h>
12484+#include <asm/alternative-asm.h>
12485
12486 .file "cast5-avx-x86_64-asm_64.S"
12487
12488@@ -281,6 +282,7 @@ __cast5_enc_blk16:
12489 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12490 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12491
12492+ pax_force_retaddr 0, 1
12493 ret;
12494 ENDPROC(__cast5_enc_blk16)
12495
12496@@ -352,6 +354,7 @@ __cast5_dec_blk16:
12497 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12498 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12499
12500+ pax_force_retaddr 0, 1
12501 ret;
12502
12503 .L__skip_dec:
12504@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
12505 vmovdqu RR4, (6*4*4)(%r11);
12506 vmovdqu RL4, (7*4*4)(%r11);
12507
12508+ pax_force_retaddr
12509 ret;
12510 ENDPROC(cast5_ecb_enc_16way)
12511
12512@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
12513 vmovdqu RR4, (6*4*4)(%r11);
12514 vmovdqu RL4, (7*4*4)(%r11);
12515
12516+ pax_force_retaddr
12517 ret;
12518 ENDPROC(cast5_ecb_dec_16way)
12519
12520@@ -469,6 +474,7 @@ ENTRY(cast5_cbc_dec_16way)
12521
12522 popq %r12;
12523
12524+ pax_force_retaddr
12525 ret;
12526 ENDPROC(cast5_cbc_dec_16way)
12527
12528@@ -542,5 +548,6 @@ ENTRY(cast5_ctr_16way)
12529
12530 popq %r12;
12531
12532+ pax_force_retaddr
12533 ret;
12534 ENDPROC(cast5_ctr_16way)
12535diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12536index e3531f8..18ded3a 100644
12537--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12538+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12539@@ -24,6 +24,7 @@
12540 */
12541
12542 #include <linux/linkage.h>
12543+#include <asm/alternative-asm.h>
12544 #include "glue_helper-asm-avx.S"
12545
12546 .file "cast6-avx-x86_64-asm_64.S"
12547@@ -295,6 +296,7 @@ __cast6_enc_blk8:
12548 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
12549 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
12550
12551+ pax_force_retaddr 0, 1
12552 ret;
12553 ENDPROC(__cast6_enc_blk8)
12554
12555@@ -340,6 +342,7 @@ __cast6_dec_blk8:
12556 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
12557 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
12558
12559+ pax_force_retaddr 0, 1
12560 ret;
12561 ENDPROC(__cast6_dec_blk8)
12562
12563@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
12564
12565 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12566
12567+ pax_force_retaddr
12568 ret;
12569 ENDPROC(cast6_ecb_enc_8way)
12570
12571@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
12572
12573 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12574
12575+ pax_force_retaddr
12576 ret;
12577 ENDPROC(cast6_ecb_dec_8way)
12578
12579@@ -399,6 +404,7 @@ ENTRY(cast6_cbc_dec_8way)
12580
12581 popq %r12;
12582
12583+ pax_force_retaddr
12584 ret;
12585 ENDPROC(cast6_cbc_dec_8way)
12586
12587@@ -424,6 +430,7 @@ ENTRY(cast6_ctr_8way)
12588
12589 popq %r12;
12590
12591+ pax_force_retaddr
12592 ret;
12593 ENDPROC(cast6_ctr_8way)
12594
12595@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
12596 /* dst <= regs xor IVs(in dst) */
12597 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12598
12599+ pax_force_retaddr
12600 ret;
12601 ENDPROC(cast6_xts_enc_8way)
12602
12603@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
12604 /* dst <= regs xor IVs(in dst) */
12605 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12606
12607+ pax_force_retaddr
12608 ret;
12609 ENDPROC(cast6_xts_dec_8way)
12610diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12611index dbc4339..3d868c5 100644
12612--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12613+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12614@@ -45,6 +45,7 @@
12615
12616 #include <asm/inst.h>
12617 #include <linux/linkage.h>
12618+#include <asm/alternative-asm.h>
12619
12620 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
12621
12622@@ -312,6 +313,7 @@ do_return:
12623 popq %rsi
12624 popq %rdi
12625 popq %rbx
12626+ pax_force_retaddr 0, 1
12627 ret
12628
12629 ################################################################
12630diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
12631index 586f41a..d02851e 100644
12632--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
12633+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
12634@@ -18,6 +18,7 @@
12635
12636 #include <linux/linkage.h>
12637 #include <asm/inst.h>
12638+#include <asm/alternative-asm.h>
12639
12640 .data
12641
12642@@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
12643 psrlq $1, T2
12644 pxor T2, T1
12645 pxor T1, DATA
12646+ pax_force_retaddr
12647 ret
12648 ENDPROC(__clmul_gf128mul_ble)
12649
12650@@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
12651 call __clmul_gf128mul_ble
12652 PSHUFB_XMM BSWAP DATA
12653 movups DATA, (%rdi)
12654+ pax_force_retaddr
12655 ret
12656 ENDPROC(clmul_ghash_mul)
12657
12658@@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
12659 PSHUFB_XMM BSWAP DATA
12660 movups DATA, (%rdi)
12661 .Lupdate_just_ret:
12662+ pax_force_retaddr
12663 ret
12664 ENDPROC(clmul_ghash_update)
12665
12666@@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
12667 pand .Lpoly, %xmm1
12668 pxor %xmm1, %xmm0
12669 movups %xmm0, (%rdi)
12670+ pax_force_retaddr
12671 ret
12672 ENDPROC(clmul_ghash_setkey)
12673diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
12674index 9279e0b..9270820 100644
12675--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
12676+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
12677@@ -1,4 +1,5 @@
12678 #include <linux/linkage.h>
12679+#include <asm/alternative-asm.h>
12680
12681 # enter salsa20_encrypt_bytes
12682 ENTRY(salsa20_encrypt_bytes)
12683@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
12684 add %r11,%rsp
12685 mov %rdi,%rax
12686 mov %rsi,%rdx
12687+ pax_force_retaddr 0, 1
12688 ret
12689 # bytesatleast65:
12690 ._bytesatleast65:
12691@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
12692 add %r11,%rsp
12693 mov %rdi,%rax
12694 mov %rsi,%rdx
12695+ pax_force_retaddr
12696 ret
12697 ENDPROC(salsa20_keysetup)
12698
12699@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
12700 add %r11,%rsp
12701 mov %rdi,%rax
12702 mov %rsi,%rdx
12703+ pax_force_retaddr
12704 ret
12705 ENDPROC(salsa20_ivsetup)
12706diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12707index 2f202f4..d9164d6 100644
12708--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12709+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12710@@ -24,6 +24,7 @@
12711 */
12712
12713 #include <linux/linkage.h>
12714+#include <asm/alternative-asm.h>
12715 #include "glue_helper-asm-avx.S"
12716
12717 .file "serpent-avx-x86_64-asm_64.S"
12718@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
12719 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12720 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12721
12722+ pax_force_retaddr
12723 ret;
12724 ENDPROC(__serpent_enc_blk8_avx)
12725
12726@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
12727 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12728 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12729
12730+ pax_force_retaddr
12731 ret;
12732 ENDPROC(__serpent_dec_blk8_avx)
12733
12734@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
12735
12736 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12737
12738+ pax_force_retaddr
12739 ret;
12740 ENDPROC(serpent_ecb_enc_8way_avx)
12741
12742@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
12743
12744 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12745
12746+ pax_force_retaddr
12747 ret;
12748 ENDPROC(serpent_ecb_dec_8way_avx)
12749
12750@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
12751
12752 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12753
12754+ pax_force_retaddr
12755 ret;
12756 ENDPROC(serpent_cbc_dec_8way_avx)
12757
12758@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
12759
12760 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12761
12762+ pax_force_retaddr
12763 ret;
12764 ENDPROC(serpent_ctr_8way_avx)
12765
12766@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
12767 /* dst <= regs xor IVs(in dst) */
12768 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12769
12770+ pax_force_retaddr
12771 ret;
12772 ENDPROC(serpent_xts_enc_8way_avx)
12773
12774@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
12775 /* dst <= regs xor IVs(in dst) */
12776 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12777
12778+ pax_force_retaddr
12779 ret;
12780 ENDPROC(serpent_xts_dec_8way_avx)
12781diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
12782index b222085..abd483c 100644
12783--- a/arch/x86/crypto/serpent-avx2-asm_64.S
12784+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
12785@@ -15,6 +15,7 @@
12786 */
12787
12788 #include <linux/linkage.h>
12789+#include <asm/alternative-asm.h>
12790 #include "glue_helper-asm-avx2.S"
12791
12792 .file "serpent-avx2-asm_64.S"
12793@@ -610,6 +611,7 @@ __serpent_enc_blk16:
12794 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12795 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12796
12797+ pax_force_retaddr
12798 ret;
12799 ENDPROC(__serpent_enc_blk16)
12800
12801@@ -664,6 +666,7 @@ __serpent_dec_blk16:
12802 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12803 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12804
12805+ pax_force_retaddr
12806 ret;
12807 ENDPROC(__serpent_dec_blk16)
12808
12809@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
12810
12811 vzeroupper;
12812
12813+ pax_force_retaddr
12814 ret;
12815 ENDPROC(serpent_ecb_enc_16way)
12816
12817@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
12818
12819 vzeroupper;
12820
12821+ pax_force_retaddr
12822 ret;
12823 ENDPROC(serpent_ecb_dec_16way)
12824
12825@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
12826
12827 vzeroupper;
12828
12829+ pax_force_retaddr
12830 ret;
12831 ENDPROC(serpent_cbc_dec_16way)
12832
12833@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
12834
12835 vzeroupper;
12836
12837+ pax_force_retaddr
12838 ret;
12839 ENDPROC(serpent_ctr_16way)
12840
12841@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
12842
12843 vzeroupper;
12844
12845+ pax_force_retaddr
12846 ret;
12847 ENDPROC(serpent_xts_enc_16way)
12848
12849@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
12850
12851 vzeroupper;
12852
12853+ pax_force_retaddr
12854 ret;
12855 ENDPROC(serpent_xts_dec_16way)
12856diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12857index acc066c..1559cc4 100644
12858--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12859+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12860@@ -25,6 +25,7 @@
12861 */
12862
12863 #include <linux/linkage.h>
12864+#include <asm/alternative-asm.h>
12865
12866 .file "serpent-sse2-x86_64-asm_64.S"
12867 .text
12868@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
12869 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12870 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12871
12872+ pax_force_retaddr
12873 ret;
12874
12875 .L__enc_xor8:
12876 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12877 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12878
12879+ pax_force_retaddr
12880 ret;
12881 ENDPROC(__serpent_enc_blk_8way)
12882
12883@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
12884 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12885 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12886
12887+ pax_force_retaddr
12888 ret;
12889 ENDPROC(serpent_dec_blk_8way)
12890diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
12891index a410950..3356d42 100644
12892--- a/arch/x86/crypto/sha1_ssse3_asm.S
12893+++ b/arch/x86/crypto/sha1_ssse3_asm.S
12894@@ -29,6 +29,7 @@
12895 */
12896
12897 #include <linux/linkage.h>
12898+#include <asm/alternative-asm.h>
12899
12900 #define CTX %rdi // arg1
12901 #define BUF %rsi // arg2
12902@@ -104,6 +105,7 @@
12903 pop %r12
12904 pop %rbp
12905 pop %rbx
12906+ pax_force_retaddr 0, 1
12907 ret
12908
12909 ENDPROC(\name)
12910diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
12911index 642f156..4ab07b9 100644
12912--- a/arch/x86/crypto/sha256-avx-asm.S
12913+++ b/arch/x86/crypto/sha256-avx-asm.S
12914@@ -49,6 +49,7 @@
12915
12916 #ifdef CONFIG_AS_AVX
12917 #include <linux/linkage.h>
12918+#include <asm/alternative-asm.h>
12919
12920 ## assume buffers not aligned
12921 #define VMOVDQ vmovdqu
12922@@ -460,6 +461,7 @@ done_hash:
12923 popq %r13
12924 popq %rbp
12925 popq %rbx
12926+ pax_force_retaddr 0, 1
12927 ret
12928 ENDPROC(sha256_transform_avx)
12929
12930diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
12931index 9e86944..2e7f95a 100644
12932--- a/arch/x86/crypto/sha256-avx2-asm.S
12933+++ b/arch/x86/crypto/sha256-avx2-asm.S
12934@@ -50,6 +50,7 @@
12935
12936 #ifdef CONFIG_AS_AVX2
12937 #include <linux/linkage.h>
12938+#include <asm/alternative-asm.h>
12939
12940 ## assume buffers not aligned
12941 #define VMOVDQ vmovdqu
12942@@ -720,6 +721,7 @@ done_hash:
12943 popq %r12
12944 popq %rbp
12945 popq %rbx
12946+ pax_force_retaddr 0, 1
12947 ret
12948 ENDPROC(sha256_transform_rorx)
12949
12950diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
12951index f833b74..c36ed14 100644
12952--- a/arch/x86/crypto/sha256-ssse3-asm.S
12953+++ b/arch/x86/crypto/sha256-ssse3-asm.S
12954@@ -47,6 +47,7 @@
12955 ########################################################################
12956
12957 #include <linux/linkage.h>
12958+#include <asm/alternative-asm.h>
12959
12960 ## assume buffers not aligned
12961 #define MOVDQ movdqu
12962@@ -471,6 +472,7 @@ done_hash:
12963 popq %rbp
12964 popq %rbx
12965
12966+ pax_force_retaddr 0, 1
12967 ret
12968 ENDPROC(sha256_transform_ssse3)
12969
12970diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
12971index 974dde9..4533d34 100644
12972--- a/arch/x86/crypto/sha512-avx-asm.S
12973+++ b/arch/x86/crypto/sha512-avx-asm.S
12974@@ -49,6 +49,7 @@
12975
12976 #ifdef CONFIG_AS_AVX
12977 #include <linux/linkage.h>
12978+#include <asm/alternative-asm.h>
12979
12980 .text
12981
12982@@ -364,6 +365,7 @@ updateblock:
12983 mov frame_RSPSAVE(%rsp), %rsp
12984
12985 nowork:
12986+ pax_force_retaddr 0, 1
12987 ret
12988 ENDPROC(sha512_transform_avx)
12989
12990diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
12991index 568b961..061ef1d 100644
12992--- a/arch/x86/crypto/sha512-avx2-asm.S
12993+++ b/arch/x86/crypto/sha512-avx2-asm.S
12994@@ -51,6 +51,7 @@
12995
12996 #ifdef CONFIG_AS_AVX2
12997 #include <linux/linkage.h>
12998+#include <asm/alternative-asm.h>
12999
13000 .text
13001
13002@@ -678,6 +679,7 @@ done_hash:
13003
13004 # Restore Stack Pointer
13005 mov frame_RSPSAVE(%rsp), %rsp
13006+ pax_force_retaddr 0, 1
13007 ret
13008 ENDPROC(sha512_transform_rorx)
13009
13010diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13011index fb56855..e23914f 100644
13012--- a/arch/x86/crypto/sha512-ssse3-asm.S
13013+++ b/arch/x86/crypto/sha512-ssse3-asm.S
13014@@ -48,6 +48,7 @@
13015 ########################################################################
13016
13017 #include <linux/linkage.h>
13018+#include <asm/alternative-asm.h>
13019
13020 .text
13021
13022@@ -363,6 +364,7 @@ updateblock:
13023 mov frame_RSPSAVE(%rsp), %rsp
13024
13025 nowork:
13026+ pax_force_retaddr 0, 1
13027 ret
13028 ENDPROC(sha512_transform_ssse3)
13029
13030diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13031index 0505813..63b1d00 100644
13032--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13033+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13034@@ -24,6 +24,7 @@
13035 */
13036
13037 #include <linux/linkage.h>
13038+#include <asm/alternative-asm.h>
13039 #include "glue_helper-asm-avx.S"
13040
13041 .file "twofish-avx-x86_64-asm_64.S"
13042@@ -284,6 +285,7 @@ __twofish_enc_blk8:
13043 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
13044 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
13045
13046+ pax_force_retaddr 0, 1
13047 ret;
13048 ENDPROC(__twofish_enc_blk8)
13049
13050@@ -324,6 +326,7 @@ __twofish_dec_blk8:
13051 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
13052 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
13053
13054+ pax_force_retaddr 0, 1
13055 ret;
13056 ENDPROC(__twofish_dec_blk8)
13057
13058@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
13059
13060 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13061
13062+ pax_force_retaddr 0, 1
13063 ret;
13064 ENDPROC(twofish_ecb_enc_8way)
13065
13066@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
13067
13068 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13069
13070+ pax_force_retaddr 0, 1
13071 ret;
13072 ENDPROC(twofish_ecb_dec_8way)
13073
13074@@ -383,6 +388,7 @@ ENTRY(twofish_cbc_dec_8way)
13075
13076 popq %r12;
13077
13078+ pax_force_retaddr 0, 1
13079 ret;
13080 ENDPROC(twofish_cbc_dec_8way)
13081
13082@@ -408,6 +414,7 @@ ENTRY(twofish_ctr_8way)
13083
13084 popq %r12;
13085
13086+ pax_force_retaddr 0, 1
13087 ret;
13088 ENDPROC(twofish_ctr_8way)
13089
13090@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
13091 /* dst <= regs xor IVs(in dst) */
13092 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13093
13094+ pax_force_retaddr 0, 1
13095 ret;
13096 ENDPROC(twofish_xts_enc_8way)
13097
13098@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
13099 /* dst <= regs xor IVs(in dst) */
13100 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13101
13102+ pax_force_retaddr 0, 1
13103 ret;
13104 ENDPROC(twofish_xts_dec_8way)
13105diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13106index 1c3b7ce..b365c5e 100644
13107--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13108+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13109@@ -21,6 +21,7 @@
13110 */
13111
13112 #include <linux/linkage.h>
13113+#include <asm/alternative-asm.h>
13114
13115 .file "twofish-x86_64-asm-3way.S"
13116 .text
13117@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
13118 popq %r13;
13119 popq %r14;
13120 popq %r15;
13121+ pax_force_retaddr 0, 1
13122 ret;
13123
13124 .L__enc_xor3:
13125@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
13126 popq %r13;
13127 popq %r14;
13128 popq %r15;
13129+ pax_force_retaddr 0, 1
13130 ret;
13131 ENDPROC(__twofish_enc_blk_3way)
13132
13133@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
13134 popq %r13;
13135 popq %r14;
13136 popq %r15;
13137+ pax_force_retaddr 0, 1
13138 ret;
13139 ENDPROC(twofish_dec_blk_3way)
13140diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
13141index a039d21..29e7615 100644
13142--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
13143+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
13144@@ -22,6 +22,7 @@
13145
13146 #include <linux/linkage.h>
13147 #include <asm/asm-offsets.h>
13148+#include <asm/alternative-asm.h>
13149
13150 #define a_offset 0
13151 #define b_offset 4
13152@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
13153
13154 popq R1
13155 movq $1,%rax
13156+ pax_force_retaddr 0, 1
13157 ret
13158 ENDPROC(twofish_enc_blk)
13159
13160@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
13161
13162 popq R1
13163 movq $1,%rax
13164+ pax_force_retaddr 0, 1
13165 ret
13166 ENDPROC(twofish_dec_blk)
13167diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
13168index bae3aba..c1788c1 100644
13169--- a/arch/x86/ia32/ia32_aout.c
13170+++ b/arch/x86/ia32/ia32_aout.c
13171@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
13172 unsigned long dump_start, dump_size;
13173 struct user32 dump;
13174
13175+ memset(&dump, 0, sizeof(dump));
13176+
13177 fs = get_fs();
13178 set_fs(KERNEL_DS);
13179 has_dumped = 1;
13180diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
13181index bccfca6..a312009 100644
13182--- a/arch/x86/ia32/ia32_signal.c
13183+++ b/arch/x86/ia32/ia32_signal.c
13184@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
13185 sp -= frame_size;
13186 /* Align the stack pointer according to the i386 ABI,
13187 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
13188- sp = ((sp + 4) & -16ul) - 4;
13189+ sp = ((sp - 12) & -16ul) - 4;
13190 return (void __user *) sp;
13191 }
13192
13193@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13194 * These are actually not used anymore, but left because some
13195 * gdb versions depend on them as a marker.
13196 */
13197- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13198+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13199 } put_user_catch(err);
13200
13201 if (err)
13202@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13203 0xb8,
13204 __NR_ia32_rt_sigreturn,
13205 0x80cd,
13206- 0,
13207+ 0
13208 };
13209
13210 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
13211@@ -457,20 +457,22 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13212 else
13213 put_user_ex(0, &frame->uc.uc_flags);
13214 put_user_ex(0, &frame->uc.uc_link);
13215- err |= __compat_save_altstack(&frame->uc.uc_stack, regs->sp);
13216+ __compat_save_altstack_ex(&frame->uc.uc_stack, regs->sp);
13217
13218 if (ksig->ka.sa.sa_flags & SA_RESTORER)
13219 restorer = ksig->ka.sa.sa_restorer;
13220+ else if (current->mm->context.vdso)
13221+ /* Return stub is in 32bit vsyscall page */
13222+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13223 else
13224- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13225- rt_sigreturn);
13226+ restorer = &frame->retcode;
13227 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
13228
13229 /*
13230 * Not actually used anymore, but left because some gdb
13231 * versions need it.
13232 */
13233- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13234+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13235 } put_user_catch(err);
13236
13237 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
13238diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
13239index 474dc1b..9297c58 100644
13240--- a/arch/x86/ia32/ia32entry.S
13241+++ b/arch/x86/ia32/ia32entry.S
13242@@ -15,8 +15,10 @@
13243 #include <asm/irqflags.h>
13244 #include <asm/asm.h>
13245 #include <asm/smap.h>
13246+#include <asm/pgtable.h>
13247 #include <linux/linkage.h>
13248 #include <linux/err.h>
13249+#include <asm/alternative-asm.h>
13250
13251 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13252 #include <linux/elf-em.h>
13253@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
13254 ENDPROC(native_irq_enable_sysexit)
13255 #endif
13256
13257+ .macro pax_enter_kernel_user
13258+ pax_set_fptr_mask
13259+#ifdef CONFIG_PAX_MEMORY_UDEREF
13260+ call pax_enter_kernel_user
13261+#endif
13262+ .endm
13263+
13264+ .macro pax_exit_kernel_user
13265+#ifdef CONFIG_PAX_MEMORY_UDEREF
13266+ call pax_exit_kernel_user
13267+#endif
13268+#ifdef CONFIG_PAX_RANDKSTACK
13269+ pushq %rax
13270+ pushq %r11
13271+ call pax_randomize_kstack
13272+ popq %r11
13273+ popq %rax
13274+#endif
13275+ .endm
13276+
13277+ .macro pax_erase_kstack
13278+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13279+ call pax_erase_kstack
13280+#endif
13281+ .endm
13282+
13283 /*
13284 * 32bit SYSENTER instruction entry.
13285 *
13286@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
13287 CFI_REGISTER rsp,rbp
13288 SWAPGS_UNSAFE_STACK
13289 movq PER_CPU_VAR(kernel_stack), %rsp
13290- addq $(KERNEL_STACK_OFFSET),%rsp
13291- /*
13292- * No need to follow this irqs on/off section: the syscall
13293- * disabled irqs, here we enable it straight after entry:
13294- */
13295- ENABLE_INTERRUPTS(CLBR_NONE)
13296 movl %ebp,%ebp /* zero extension */
13297 pushq_cfi $__USER32_DS
13298 /*CFI_REL_OFFSET ss,0*/
13299@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
13300 CFI_REL_OFFSET rsp,0
13301 pushfq_cfi
13302 /*CFI_REL_OFFSET rflags,0*/
13303- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
13304- CFI_REGISTER rip,r10
13305+ orl $X86_EFLAGS_IF,(%rsp)
13306+ GET_THREAD_INFO(%r11)
13307+ movl TI_sysenter_return(%r11), %r11d
13308+ CFI_REGISTER rip,r11
13309 pushq_cfi $__USER32_CS
13310 /*CFI_REL_OFFSET cs,0*/
13311 movl %eax, %eax
13312- pushq_cfi %r10
13313+ pushq_cfi %r11
13314 CFI_REL_OFFSET rip,0
13315 pushq_cfi %rax
13316 cld
13317 SAVE_ARGS 0,1,0
13318+ pax_enter_kernel_user
13319+
13320+#ifdef CONFIG_PAX_RANDKSTACK
13321+ pax_erase_kstack
13322+#endif
13323+
13324+ /*
13325+ * No need to follow this irqs on/off section: the syscall
13326+ * disabled irqs, here we enable it straight after entry:
13327+ */
13328+ ENABLE_INTERRUPTS(CLBR_NONE)
13329 /* no need to do an access_ok check here because rbp has been
13330 32bit zero extended */
13331+
13332+#ifdef CONFIG_PAX_MEMORY_UDEREF
13333+ addq pax_user_shadow_base,%rbp
13334+ ASM_PAX_OPEN_USERLAND
13335+#endif
13336+
13337 ASM_STAC
13338 1: movl (%rbp),%ebp
13339 _ASM_EXTABLE(1b,ia32_badarg)
13340 ASM_CLAC
13341- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13342- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13343+
13344+#ifdef CONFIG_PAX_MEMORY_UDEREF
13345+ ASM_PAX_CLOSE_USERLAND
13346+#endif
13347+
13348+ GET_THREAD_INFO(%r11)
13349+ orl $TS_COMPAT,TI_status(%r11)
13350+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13351 CFI_REMEMBER_STATE
13352 jnz sysenter_tracesys
13353 cmpq $(IA32_NR_syscalls-1),%rax
13354@@ -162,12 +209,15 @@ sysenter_do_call:
13355 sysenter_dispatch:
13356 call *ia32_sys_call_table(,%rax,8)
13357 movq %rax,RAX-ARGOFFSET(%rsp)
13358+ GET_THREAD_INFO(%r11)
13359 DISABLE_INTERRUPTS(CLBR_NONE)
13360 TRACE_IRQS_OFF
13361- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13362+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13363 jnz sysexit_audit
13364 sysexit_from_sys_call:
13365- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13366+ pax_exit_kernel_user
13367+ pax_erase_kstack
13368+ andl $~TS_COMPAT,TI_status(%r11)
13369 /* clear IF, that popfq doesn't enable interrupts early */
13370 andl $~0x200,EFLAGS-R11(%rsp)
13371 movl RIP-R11(%rsp),%edx /* User %eip */
13372@@ -193,6 +243,9 @@ sysexit_from_sys_call:
13373 movl %eax,%esi /* 2nd arg: syscall number */
13374 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
13375 call __audit_syscall_entry
13376+
13377+ pax_erase_kstack
13378+
13379 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
13380 cmpq $(IA32_NR_syscalls-1),%rax
13381 ja ia32_badsys
13382@@ -204,7 +257,7 @@ sysexit_from_sys_call:
13383 .endm
13384
13385 .macro auditsys_exit exit
13386- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13387+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13388 jnz ia32_ret_from_sys_call
13389 TRACE_IRQS_ON
13390 ENABLE_INTERRUPTS(CLBR_NONE)
13391@@ -215,11 +268,12 @@ sysexit_from_sys_call:
13392 1: setbe %al /* 1 if error, 0 if not */
13393 movzbl %al,%edi /* zero-extend that into %edi */
13394 call __audit_syscall_exit
13395+ GET_THREAD_INFO(%r11)
13396 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
13397 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
13398 DISABLE_INTERRUPTS(CLBR_NONE)
13399 TRACE_IRQS_OFF
13400- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13401+ testl %edi,TI_flags(%r11)
13402 jz \exit
13403 CLEAR_RREGS -ARGOFFSET
13404 jmp int_with_check
13405@@ -237,7 +291,7 @@ sysexit_audit:
13406
13407 sysenter_tracesys:
13408 #ifdef CONFIG_AUDITSYSCALL
13409- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13410+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13411 jz sysenter_auditsys
13412 #endif
13413 SAVE_REST
13414@@ -249,6 +303,9 @@ sysenter_tracesys:
13415 RESTORE_REST
13416 cmpq $(IA32_NR_syscalls-1),%rax
13417 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
13418+
13419+ pax_erase_kstack
13420+
13421 jmp sysenter_do_call
13422 CFI_ENDPROC
13423 ENDPROC(ia32_sysenter_target)
13424@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
13425 ENTRY(ia32_cstar_target)
13426 CFI_STARTPROC32 simple
13427 CFI_SIGNAL_FRAME
13428- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
13429+ CFI_DEF_CFA rsp,0
13430 CFI_REGISTER rip,rcx
13431 /*CFI_REGISTER rflags,r11*/
13432 SWAPGS_UNSAFE_STACK
13433 movl %esp,%r8d
13434 CFI_REGISTER rsp,r8
13435 movq PER_CPU_VAR(kernel_stack),%rsp
13436+ SAVE_ARGS 8*6,0,0
13437+ pax_enter_kernel_user
13438+
13439+#ifdef CONFIG_PAX_RANDKSTACK
13440+ pax_erase_kstack
13441+#endif
13442+
13443 /*
13444 * No need to follow this irqs on/off section: the syscall
13445 * disabled irqs and here we enable it straight after entry:
13446 */
13447 ENABLE_INTERRUPTS(CLBR_NONE)
13448- SAVE_ARGS 8,0,0
13449 movl %eax,%eax /* zero extension */
13450 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
13451 movq %rcx,RIP-ARGOFFSET(%rsp)
13452@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
13453 /* no need to do an access_ok check here because r8 has been
13454 32bit zero extended */
13455 /* hardware stack frame is complete now */
13456+
13457+#ifdef CONFIG_PAX_MEMORY_UDEREF
13458+ ASM_PAX_OPEN_USERLAND
13459+ movq pax_user_shadow_base,%r8
13460+ addq RSP-ARGOFFSET(%rsp),%r8
13461+#endif
13462+
13463 ASM_STAC
13464 1: movl (%r8),%r9d
13465 _ASM_EXTABLE(1b,ia32_badarg)
13466 ASM_CLAC
13467- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13468- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13469+
13470+#ifdef CONFIG_PAX_MEMORY_UDEREF
13471+ ASM_PAX_CLOSE_USERLAND
13472+#endif
13473+
13474+ GET_THREAD_INFO(%r11)
13475+ orl $TS_COMPAT,TI_status(%r11)
13476+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13477 CFI_REMEMBER_STATE
13478 jnz cstar_tracesys
13479 cmpq $IA32_NR_syscalls-1,%rax
13480@@ -319,12 +395,15 @@ cstar_do_call:
13481 cstar_dispatch:
13482 call *ia32_sys_call_table(,%rax,8)
13483 movq %rax,RAX-ARGOFFSET(%rsp)
13484+ GET_THREAD_INFO(%r11)
13485 DISABLE_INTERRUPTS(CLBR_NONE)
13486 TRACE_IRQS_OFF
13487- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13488+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13489 jnz sysretl_audit
13490 sysretl_from_sys_call:
13491- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13492+ pax_exit_kernel_user
13493+ pax_erase_kstack
13494+ andl $~TS_COMPAT,TI_status(%r11)
13495 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
13496 movl RIP-ARGOFFSET(%rsp),%ecx
13497 CFI_REGISTER rip,rcx
13498@@ -352,7 +431,7 @@ sysretl_audit:
13499
13500 cstar_tracesys:
13501 #ifdef CONFIG_AUDITSYSCALL
13502- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13503+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13504 jz cstar_auditsys
13505 #endif
13506 xchgl %r9d,%ebp
13507@@ -366,11 +445,19 @@ cstar_tracesys:
13508 xchgl %ebp,%r9d
13509 cmpq $(IA32_NR_syscalls-1),%rax
13510 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
13511+
13512+ pax_erase_kstack
13513+
13514 jmp cstar_do_call
13515 END(ia32_cstar_target)
13516
13517 ia32_badarg:
13518 ASM_CLAC
13519+
13520+#ifdef CONFIG_PAX_MEMORY_UDEREF
13521+ ASM_PAX_CLOSE_USERLAND
13522+#endif
13523+
13524 movq $-EFAULT,%rax
13525 jmp ia32_sysret
13526 CFI_ENDPROC
13527@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
13528 CFI_REL_OFFSET rip,RIP-RIP
13529 PARAVIRT_ADJUST_EXCEPTION_FRAME
13530 SWAPGS
13531- /*
13532- * No need to follow this irqs on/off section: the syscall
13533- * disabled irqs and here we enable it straight after entry:
13534- */
13535- ENABLE_INTERRUPTS(CLBR_NONE)
13536 movl %eax,%eax
13537 pushq_cfi %rax
13538 cld
13539 /* note the registers are not zero extended to the sf.
13540 this could be a problem. */
13541 SAVE_ARGS 0,1,0
13542- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13543- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13544+ pax_enter_kernel_user
13545+
13546+#ifdef CONFIG_PAX_RANDKSTACK
13547+ pax_erase_kstack
13548+#endif
13549+
13550+ /*
13551+ * No need to follow this irqs on/off section: the syscall
13552+ * disabled irqs and here we enable it straight after entry:
13553+ */
13554+ ENABLE_INTERRUPTS(CLBR_NONE)
13555+ GET_THREAD_INFO(%r11)
13556+ orl $TS_COMPAT,TI_status(%r11)
13557+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13558 jnz ia32_tracesys
13559 cmpq $(IA32_NR_syscalls-1),%rax
13560 ja ia32_badsys
13561@@ -442,6 +536,9 @@ ia32_tracesys:
13562 RESTORE_REST
13563 cmpq $(IA32_NR_syscalls-1),%rax
13564 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
13565+
13566+ pax_erase_kstack
13567+
13568 jmp ia32_do_call
13569 END(ia32_syscall)
13570
13571diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
13572index 8e0ceec..af13504 100644
13573--- a/arch/x86/ia32/sys_ia32.c
13574+++ b/arch/x86/ia32/sys_ia32.c
13575@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
13576 */
13577 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
13578 {
13579- typeof(ubuf->st_uid) uid = 0;
13580- typeof(ubuf->st_gid) gid = 0;
13581+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
13582+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
13583 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
13584 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
13585 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
13586diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
13587index 372231c..a5aa1a1 100644
13588--- a/arch/x86/include/asm/alternative-asm.h
13589+++ b/arch/x86/include/asm/alternative-asm.h
13590@@ -18,6 +18,45 @@
13591 .endm
13592 #endif
13593
13594+#ifdef KERNEXEC_PLUGIN
13595+ .macro pax_force_retaddr_bts rip=0
13596+ btsq $63,\rip(%rsp)
13597+ .endm
13598+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13599+ .macro pax_force_retaddr rip=0, reload=0
13600+ btsq $63,\rip(%rsp)
13601+ .endm
13602+ .macro pax_force_fptr ptr
13603+ btsq $63,\ptr
13604+ .endm
13605+ .macro pax_set_fptr_mask
13606+ .endm
13607+#endif
13608+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
13609+ .macro pax_force_retaddr rip=0, reload=0
13610+ .if \reload
13611+ pax_set_fptr_mask
13612+ .endif
13613+ orq %r10,\rip(%rsp)
13614+ .endm
13615+ .macro pax_force_fptr ptr
13616+ orq %r10,\ptr
13617+ .endm
13618+ .macro pax_set_fptr_mask
13619+ movabs $0x8000000000000000,%r10
13620+ .endm
13621+#endif
13622+#else
13623+ .macro pax_force_retaddr rip=0, reload=0
13624+ .endm
13625+ .macro pax_force_fptr ptr
13626+ .endm
13627+ .macro pax_force_retaddr_bts rip=0
13628+ .endm
13629+ .macro pax_set_fptr_mask
13630+ .endm
13631+#endif
13632+
13633 .macro altinstruction_entry orig alt feature orig_len alt_len
13634 .long \orig - .
13635 .long \alt - .
13636diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
13637index 58ed6d9..f1cbe58 100644
13638--- a/arch/x86/include/asm/alternative.h
13639+++ b/arch/x86/include/asm/alternative.h
13640@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
13641 ".pushsection .discard,\"aw\",@progbits\n" \
13642 DISCARD_ENTRY(1) \
13643 ".popsection\n" \
13644- ".pushsection .altinstr_replacement, \"ax\"\n" \
13645+ ".pushsection .altinstr_replacement, \"a\"\n" \
13646 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
13647 ".popsection"
13648
13649@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
13650 DISCARD_ENTRY(1) \
13651 DISCARD_ENTRY(2) \
13652 ".popsection\n" \
13653- ".pushsection .altinstr_replacement, \"ax\"\n" \
13654+ ".pushsection .altinstr_replacement, \"a\"\n" \
13655 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
13656 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
13657 ".popsection"
13658diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
13659index f8119b5..7209d5b 100644
13660--- a/arch/x86/include/asm/apic.h
13661+++ b/arch/x86/include/asm/apic.h
13662@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
13663
13664 #ifdef CONFIG_X86_LOCAL_APIC
13665
13666-extern unsigned int apic_verbosity;
13667+extern int apic_verbosity;
13668 extern int local_apic_timer_c2_ok;
13669
13670 extern int disable_apic;
13671diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
13672index 20370c6..a2eb9b0 100644
13673--- a/arch/x86/include/asm/apm.h
13674+++ b/arch/x86/include/asm/apm.h
13675@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
13676 __asm__ __volatile__(APM_DO_ZERO_SEGS
13677 "pushl %%edi\n\t"
13678 "pushl %%ebp\n\t"
13679- "lcall *%%cs:apm_bios_entry\n\t"
13680+ "lcall *%%ss:apm_bios_entry\n\t"
13681 "setc %%al\n\t"
13682 "popl %%ebp\n\t"
13683 "popl %%edi\n\t"
13684@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
13685 __asm__ __volatile__(APM_DO_ZERO_SEGS
13686 "pushl %%edi\n\t"
13687 "pushl %%ebp\n\t"
13688- "lcall *%%cs:apm_bios_entry\n\t"
13689+ "lcall *%%ss:apm_bios_entry\n\t"
13690 "setc %%bl\n\t"
13691 "popl %%ebp\n\t"
13692 "popl %%edi\n\t"
13693diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
13694index 722aa3b..3a0bb27 100644
13695--- a/arch/x86/include/asm/atomic.h
13696+++ b/arch/x86/include/asm/atomic.h
13697@@ -22,7 +22,18 @@
13698 */
13699 static inline int atomic_read(const atomic_t *v)
13700 {
13701- return (*(volatile int *)&(v)->counter);
13702+ return (*(volatile const int *)&(v)->counter);
13703+}
13704+
13705+/**
13706+ * atomic_read_unchecked - read atomic variable
13707+ * @v: pointer of type atomic_unchecked_t
13708+ *
13709+ * Atomically reads the value of @v.
13710+ */
13711+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
13712+{
13713+ return (*(volatile const int *)&(v)->counter);
13714 }
13715
13716 /**
13717@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
13718 }
13719
13720 /**
13721+ * atomic_set_unchecked - set atomic variable
13722+ * @v: pointer of type atomic_unchecked_t
13723+ * @i: required value
13724+ *
13725+ * Atomically sets the value of @v to @i.
13726+ */
13727+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
13728+{
13729+ v->counter = i;
13730+}
13731+
13732+/**
13733 * atomic_add - add integer to atomic variable
13734 * @i: integer value to add
13735 * @v: pointer of type atomic_t
13736@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
13737 */
13738 static inline void atomic_add(int i, atomic_t *v)
13739 {
13740- asm volatile(LOCK_PREFIX "addl %1,%0"
13741+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
13742+
13743+#ifdef CONFIG_PAX_REFCOUNT
13744+ "jno 0f\n"
13745+ LOCK_PREFIX "subl %1,%0\n"
13746+ "int $4\n0:\n"
13747+ _ASM_EXTABLE(0b, 0b)
13748+#endif
13749+
13750+ : "+m" (v->counter)
13751+ : "ir" (i));
13752+}
13753+
13754+/**
13755+ * atomic_add_unchecked - add integer to atomic variable
13756+ * @i: integer value to add
13757+ * @v: pointer of type atomic_unchecked_t
13758+ *
13759+ * Atomically adds @i to @v.
13760+ */
13761+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
13762+{
13763+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
13764 : "+m" (v->counter)
13765 : "ir" (i));
13766 }
13767@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
13768 */
13769 static inline void atomic_sub(int i, atomic_t *v)
13770 {
13771- asm volatile(LOCK_PREFIX "subl %1,%0"
13772+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
13773+
13774+#ifdef CONFIG_PAX_REFCOUNT
13775+ "jno 0f\n"
13776+ LOCK_PREFIX "addl %1,%0\n"
13777+ "int $4\n0:\n"
13778+ _ASM_EXTABLE(0b, 0b)
13779+#endif
13780+
13781+ : "+m" (v->counter)
13782+ : "ir" (i));
13783+}
13784+
13785+/**
13786+ * atomic_sub_unchecked - subtract integer from atomic variable
13787+ * @i: integer value to subtract
13788+ * @v: pointer of type atomic_unchecked_t
13789+ *
13790+ * Atomically subtracts @i from @v.
13791+ */
13792+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
13793+{
13794+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
13795 : "+m" (v->counter)
13796 : "ir" (i));
13797 }
13798@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
13799 {
13800 unsigned char c;
13801
13802- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
13803+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
13804+
13805+#ifdef CONFIG_PAX_REFCOUNT
13806+ "jno 0f\n"
13807+ LOCK_PREFIX "addl %2,%0\n"
13808+ "int $4\n0:\n"
13809+ _ASM_EXTABLE(0b, 0b)
13810+#endif
13811+
13812+ "sete %1\n"
13813 : "+m" (v->counter), "=qm" (c)
13814 : "ir" (i) : "memory");
13815 return c;
13816@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
13817 */
13818 static inline void atomic_inc(atomic_t *v)
13819 {
13820- asm volatile(LOCK_PREFIX "incl %0"
13821+ asm volatile(LOCK_PREFIX "incl %0\n"
13822+
13823+#ifdef CONFIG_PAX_REFCOUNT
13824+ "jno 0f\n"
13825+ LOCK_PREFIX "decl %0\n"
13826+ "int $4\n0:\n"
13827+ _ASM_EXTABLE(0b, 0b)
13828+#endif
13829+
13830+ : "+m" (v->counter));
13831+}
13832+
13833+/**
13834+ * atomic_inc_unchecked - increment atomic variable
13835+ * @v: pointer of type atomic_unchecked_t
13836+ *
13837+ * Atomically increments @v by 1.
13838+ */
13839+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
13840+{
13841+ asm volatile(LOCK_PREFIX "incl %0\n"
13842 : "+m" (v->counter));
13843 }
13844
13845@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
13846 */
13847 static inline void atomic_dec(atomic_t *v)
13848 {
13849- asm volatile(LOCK_PREFIX "decl %0"
13850+ asm volatile(LOCK_PREFIX "decl %0\n"
13851+
13852+#ifdef CONFIG_PAX_REFCOUNT
13853+ "jno 0f\n"
13854+ LOCK_PREFIX "incl %0\n"
13855+ "int $4\n0:\n"
13856+ _ASM_EXTABLE(0b, 0b)
13857+#endif
13858+
13859+ : "+m" (v->counter));
13860+}
13861+
13862+/**
13863+ * atomic_dec_unchecked - decrement atomic variable
13864+ * @v: pointer of type atomic_unchecked_t
13865+ *
13866+ * Atomically decrements @v by 1.
13867+ */
13868+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
13869+{
13870+ asm volatile(LOCK_PREFIX "decl %0\n"
13871 : "+m" (v->counter));
13872 }
13873
13874@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
13875 {
13876 unsigned char c;
13877
13878- asm volatile(LOCK_PREFIX "decl %0; sete %1"
13879+ asm volatile(LOCK_PREFIX "decl %0\n"
13880+
13881+#ifdef CONFIG_PAX_REFCOUNT
13882+ "jno 0f\n"
13883+ LOCK_PREFIX "incl %0\n"
13884+ "int $4\n0:\n"
13885+ _ASM_EXTABLE(0b, 0b)
13886+#endif
13887+
13888+ "sete %1\n"
13889 : "+m" (v->counter), "=qm" (c)
13890 : : "memory");
13891 return c != 0;
13892@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
13893 {
13894 unsigned char c;
13895
13896- asm volatile(LOCK_PREFIX "incl %0; sete %1"
13897+ asm volatile(LOCK_PREFIX "incl %0\n"
13898+
13899+#ifdef CONFIG_PAX_REFCOUNT
13900+ "jno 0f\n"
13901+ LOCK_PREFIX "decl %0\n"
13902+ "int $4\n0:\n"
13903+ _ASM_EXTABLE(0b, 0b)
13904+#endif
13905+
13906+ "sete %1\n"
13907+ : "+m" (v->counter), "=qm" (c)
13908+ : : "memory");
13909+ return c != 0;
13910+}
13911+
13912+/**
13913+ * atomic_inc_and_test_unchecked - increment and test
13914+ * @v: pointer of type atomic_unchecked_t
13915+ *
13916+ * Atomically increments @v by 1
13917+ * and returns true if the result is zero, or false for all
13918+ * other cases.
13919+ */
13920+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
13921+{
13922+ unsigned char c;
13923+
13924+ asm volatile(LOCK_PREFIX "incl %0\n"
13925+ "sete %1\n"
13926 : "+m" (v->counter), "=qm" (c)
13927 : : "memory");
13928 return c != 0;
13929@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
13930 {
13931 unsigned char c;
13932
13933- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
13934+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
13935+
13936+#ifdef CONFIG_PAX_REFCOUNT
13937+ "jno 0f\n"
13938+ LOCK_PREFIX "subl %2,%0\n"
13939+ "int $4\n0:\n"
13940+ _ASM_EXTABLE(0b, 0b)
13941+#endif
13942+
13943+ "sets %1\n"
13944 : "+m" (v->counter), "=qm" (c)
13945 : "ir" (i) : "memory");
13946 return c;
13947@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
13948 */
13949 static inline int atomic_add_return(int i, atomic_t *v)
13950 {
13951+ return i + xadd_check_overflow(&v->counter, i);
13952+}
13953+
13954+/**
13955+ * atomic_add_return_unchecked - add integer and return
13956+ * @i: integer value to add
13957+ * @v: pointer of type atomic_unchecked_t
13958+ *
13959+ * Atomically adds @i to @v and returns @i + @v
13960+ */
13961+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
13962+{
13963 return i + xadd(&v->counter, i);
13964 }
13965
13966@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
13967 }
13968
13969 #define atomic_inc_return(v) (atomic_add_return(1, v))
13970+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
13971+{
13972+ return atomic_add_return_unchecked(1, v);
13973+}
13974 #define atomic_dec_return(v) (atomic_sub_return(1, v))
13975
13976 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
13977@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
13978 return cmpxchg(&v->counter, old, new);
13979 }
13980
13981+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
13982+{
13983+ return cmpxchg(&v->counter, old, new);
13984+}
13985+
13986 static inline int atomic_xchg(atomic_t *v, int new)
13987 {
13988 return xchg(&v->counter, new);
13989 }
13990
13991+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
13992+{
13993+ return xchg(&v->counter, new);
13994+}
13995+
13996 /**
13997 * __atomic_add_unless - add unless the number is already a given value
13998 * @v: pointer of type atomic_t
13999@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
14000 */
14001 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14002 {
14003- int c, old;
14004+ int c, old, new;
14005 c = atomic_read(v);
14006 for (;;) {
14007- if (unlikely(c == (u)))
14008+ if (unlikely(c == u))
14009 break;
14010- old = atomic_cmpxchg((v), c, c + (a));
14011+
14012+ asm volatile("addl %2,%0\n"
14013+
14014+#ifdef CONFIG_PAX_REFCOUNT
14015+ "jno 0f\n"
14016+ "subl %2,%0\n"
14017+ "int $4\n0:\n"
14018+ _ASM_EXTABLE(0b, 0b)
14019+#endif
14020+
14021+ : "=r" (new)
14022+ : "0" (c), "ir" (a));
14023+
14024+ old = atomic_cmpxchg(v, c, new);
14025 if (likely(old == c))
14026 break;
14027 c = old;
14028@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14029 }
14030
14031 /**
14032+ * atomic_inc_not_zero_hint - increment if not null
14033+ * @v: pointer of type atomic_t
14034+ * @hint: probable value of the atomic before the increment
14035+ *
14036+ * This version of atomic_inc_not_zero() gives a hint of probable
14037+ * value of the atomic. This helps processor to not read the memory
14038+ * before doing the atomic read/modify/write cycle, lowering
14039+ * number of bus transactions on some arches.
14040+ *
14041+ * Returns: 0 if increment was not done, 1 otherwise.
14042+ */
14043+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
14044+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
14045+{
14046+ int val, c = hint, new;
14047+
14048+ /* sanity test, should be removed by compiler if hint is a constant */
14049+ if (!hint)
14050+ return __atomic_add_unless(v, 1, 0);
14051+
14052+ do {
14053+ asm volatile("incl %0\n"
14054+
14055+#ifdef CONFIG_PAX_REFCOUNT
14056+ "jno 0f\n"
14057+ "decl %0\n"
14058+ "int $4\n0:\n"
14059+ _ASM_EXTABLE(0b, 0b)
14060+#endif
14061+
14062+ : "=r" (new)
14063+ : "0" (c));
14064+
14065+ val = atomic_cmpxchg(v, c, new);
14066+ if (val == c)
14067+ return 1;
14068+ c = val;
14069+ } while (c);
14070+
14071+ return 0;
14072+}
14073+
14074+/**
14075 * atomic_inc_short - increment of a short integer
14076 * @v: pointer to type int
14077 *
14078@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
14079 #endif
14080
14081 /* These are x86-specific, used by some header files */
14082-#define atomic_clear_mask(mask, addr) \
14083- asm volatile(LOCK_PREFIX "andl %0,%1" \
14084- : : "r" (~(mask)), "m" (*(addr)) : "memory")
14085+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
14086+{
14087+ asm volatile(LOCK_PREFIX "andl %1,%0"
14088+ : "+m" (v->counter)
14089+ : "r" (~(mask))
14090+ : "memory");
14091+}
14092
14093-#define atomic_set_mask(mask, addr) \
14094- asm volatile(LOCK_PREFIX "orl %0,%1" \
14095- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
14096- : "memory")
14097+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14098+{
14099+ asm volatile(LOCK_PREFIX "andl %1,%0"
14100+ : "+m" (v->counter)
14101+ : "r" (~(mask))
14102+ : "memory");
14103+}
14104+
14105+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
14106+{
14107+ asm volatile(LOCK_PREFIX "orl %1,%0"
14108+ : "+m" (v->counter)
14109+ : "r" (mask)
14110+ : "memory");
14111+}
14112+
14113+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14114+{
14115+ asm volatile(LOCK_PREFIX "orl %1,%0"
14116+ : "+m" (v->counter)
14117+ : "r" (mask)
14118+ : "memory");
14119+}
14120
14121 /* Atomic operations are already serializing on x86 */
14122 #define smp_mb__before_atomic_dec() barrier()
14123diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
14124index b154de7..aadebd8 100644
14125--- a/arch/x86/include/asm/atomic64_32.h
14126+++ b/arch/x86/include/asm/atomic64_32.h
14127@@ -12,6 +12,14 @@ typedef struct {
14128 u64 __aligned(8) counter;
14129 } atomic64_t;
14130
14131+#ifdef CONFIG_PAX_REFCOUNT
14132+typedef struct {
14133+ u64 __aligned(8) counter;
14134+} atomic64_unchecked_t;
14135+#else
14136+typedef atomic64_t atomic64_unchecked_t;
14137+#endif
14138+
14139 #define ATOMIC64_INIT(val) { (val) }
14140
14141 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
14142@@ -37,21 +45,31 @@ typedef struct {
14143 ATOMIC64_DECL_ONE(sym##_386)
14144
14145 ATOMIC64_DECL_ONE(add_386);
14146+ATOMIC64_DECL_ONE(add_unchecked_386);
14147 ATOMIC64_DECL_ONE(sub_386);
14148+ATOMIC64_DECL_ONE(sub_unchecked_386);
14149 ATOMIC64_DECL_ONE(inc_386);
14150+ATOMIC64_DECL_ONE(inc_unchecked_386);
14151 ATOMIC64_DECL_ONE(dec_386);
14152+ATOMIC64_DECL_ONE(dec_unchecked_386);
14153 #endif
14154
14155 #define alternative_atomic64(f, out, in...) \
14156 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
14157
14158 ATOMIC64_DECL(read);
14159+ATOMIC64_DECL(read_unchecked);
14160 ATOMIC64_DECL(set);
14161+ATOMIC64_DECL(set_unchecked);
14162 ATOMIC64_DECL(xchg);
14163 ATOMIC64_DECL(add_return);
14164+ATOMIC64_DECL(add_return_unchecked);
14165 ATOMIC64_DECL(sub_return);
14166+ATOMIC64_DECL(sub_return_unchecked);
14167 ATOMIC64_DECL(inc_return);
14168+ATOMIC64_DECL(inc_return_unchecked);
14169 ATOMIC64_DECL(dec_return);
14170+ATOMIC64_DECL(dec_return_unchecked);
14171 ATOMIC64_DECL(dec_if_positive);
14172 ATOMIC64_DECL(inc_not_zero);
14173 ATOMIC64_DECL(add_unless);
14174@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
14175 }
14176
14177 /**
14178+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
14179+ * @p: pointer to type atomic64_unchecked_t
14180+ * @o: expected value
14181+ * @n: new value
14182+ *
14183+ * Atomically sets @v to @n if it was equal to @o and returns
14184+ * the old value.
14185+ */
14186+
14187+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
14188+{
14189+ return cmpxchg64(&v->counter, o, n);
14190+}
14191+
14192+/**
14193 * atomic64_xchg - xchg atomic64 variable
14194 * @v: pointer to type atomic64_t
14195 * @n: value to assign
14196@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
14197 }
14198
14199 /**
14200+ * atomic64_set_unchecked - set atomic64 variable
14201+ * @v: pointer to type atomic64_unchecked_t
14202+ * @n: value to assign
14203+ *
14204+ * Atomically sets the value of @v to @n.
14205+ */
14206+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
14207+{
14208+ unsigned high = (unsigned)(i >> 32);
14209+ unsigned low = (unsigned)i;
14210+ alternative_atomic64(set, /* no output */,
14211+ "S" (v), "b" (low), "c" (high)
14212+ : "eax", "edx", "memory");
14213+}
14214+
14215+/**
14216 * atomic64_read - read atomic64 variable
14217 * @v: pointer to type atomic64_t
14218 *
14219@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
14220 }
14221
14222 /**
14223+ * atomic64_read_unchecked - read atomic64 variable
14224+ * @v: pointer to type atomic64_unchecked_t
14225+ *
14226+ * Atomically reads the value of @v and returns it.
14227+ */
14228+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
14229+{
14230+ long long r;
14231+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
14232+ return r;
14233+ }
14234+
14235+/**
14236 * atomic64_add_return - add and return
14237 * @i: integer value to add
14238 * @v: pointer to type atomic64_t
14239@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
14240 return i;
14241 }
14242
14243+/**
14244+ * atomic64_add_return_unchecked - add and return
14245+ * @i: integer value to add
14246+ * @v: pointer to type atomic64_unchecked_t
14247+ *
14248+ * Atomically adds @i to @v and returns @i + *@v
14249+ */
14250+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
14251+{
14252+ alternative_atomic64(add_return_unchecked,
14253+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14254+ ASM_NO_INPUT_CLOBBER("memory"));
14255+ return i;
14256+}
14257+
14258 /*
14259 * Other variants with different arithmetic operators:
14260 */
14261@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
14262 return a;
14263 }
14264
14265+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14266+{
14267+ long long a;
14268+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
14269+ "S" (v) : "memory", "ecx");
14270+ return a;
14271+}
14272+
14273 static inline long long atomic64_dec_return(atomic64_t *v)
14274 {
14275 long long a;
14276@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
14277 }
14278
14279 /**
14280+ * atomic64_add_unchecked - add integer to atomic64 variable
14281+ * @i: integer value to add
14282+ * @v: pointer to type atomic64_unchecked_t
14283+ *
14284+ * Atomically adds @i to @v.
14285+ */
14286+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
14287+{
14288+ __alternative_atomic64(add_unchecked, add_return_unchecked,
14289+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14290+ ASM_NO_INPUT_CLOBBER("memory"));
14291+ return i;
14292+}
14293+
14294+/**
14295 * atomic64_sub - subtract the atomic64 variable
14296 * @i: integer value to subtract
14297 * @v: pointer to type atomic64_t
14298diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
14299index 0e1cbfc..5623683 100644
14300--- a/arch/x86/include/asm/atomic64_64.h
14301+++ b/arch/x86/include/asm/atomic64_64.h
14302@@ -18,7 +18,19 @@
14303 */
14304 static inline long atomic64_read(const atomic64_t *v)
14305 {
14306- return (*(volatile long *)&(v)->counter);
14307+ return (*(volatile const long *)&(v)->counter);
14308+}
14309+
14310+/**
14311+ * atomic64_read_unchecked - read atomic64 variable
14312+ * @v: pointer of type atomic64_unchecked_t
14313+ *
14314+ * Atomically reads the value of @v.
14315+ * Doesn't imply a read memory barrier.
14316+ */
14317+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
14318+{
14319+ return (*(volatile const long *)&(v)->counter);
14320 }
14321
14322 /**
14323@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
14324 }
14325
14326 /**
14327+ * atomic64_set_unchecked - set atomic64 variable
14328+ * @v: pointer to type atomic64_unchecked_t
14329+ * @i: required value
14330+ *
14331+ * Atomically sets the value of @v to @i.
14332+ */
14333+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
14334+{
14335+ v->counter = i;
14336+}
14337+
14338+/**
14339 * atomic64_add - add integer to atomic64 variable
14340 * @i: integer value to add
14341 * @v: pointer to type atomic64_t
14342@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
14343 */
14344 static inline void atomic64_add(long i, atomic64_t *v)
14345 {
14346+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
14347+
14348+#ifdef CONFIG_PAX_REFCOUNT
14349+ "jno 0f\n"
14350+ LOCK_PREFIX "subq %1,%0\n"
14351+ "int $4\n0:\n"
14352+ _ASM_EXTABLE(0b, 0b)
14353+#endif
14354+
14355+ : "=m" (v->counter)
14356+ : "er" (i), "m" (v->counter));
14357+}
14358+
14359+/**
14360+ * atomic64_add_unchecked - add integer to atomic64 variable
14361+ * @i: integer value to add
14362+ * @v: pointer to type atomic64_unchecked_t
14363+ *
14364+ * Atomically adds @i to @v.
14365+ */
14366+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
14367+{
14368 asm volatile(LOCK_PREFIX "addq %1,%0"
14369 : "=m" (v->counter)
14370 : "er" (i), "m" (v->counter));
14371@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
14372 */
14373 static inline void atomic64_sub(long i, atomic64_t *v)
14374 {
14375- asm volatile(LOCK_PREFIX "subq %1,%0"
14376+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14377+
14378+#ifdef CONFIG_PAX_REFCOUNT
14379+ "jno 0f\n"
14380+ LOCK_PREFIX "addq %1,%0\n"
14381+ "int $4\n0:\n"
14382+ _ASM_EXTABLE(0b, 0b)
14383+#endif
14384+
14385+ : "=m" (v->counter)
14386+ : "er" (i), "m" (v->counter));
14387+}
14388+
14389+/**
14390+ * atomic64_sub_unchecked - subtract the atomic64 variable
14391+ * @i: integer value to subtract
14392+ * @v: pointer to type atomic64_unchecked_t
14393+ *
14394+ * Atomically subtracts @i from @v.
14395+ */
14396+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
14397+{
14398+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14399 : "=m" (v->counter)
14400 : "er" (i), "m" (v->counter));
14401 }
14402@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14403 {
14404 unsigned char c;
14405
14406- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
14407+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
14408+
14409+#ifdef CONFIG_PAX_REFCOUNT
14410+ "jno 0f\n"
14411+ LOCK_PREFIX "addq %2,%0\n"
14412+ "int $4\n0:\n"
14413+ _ASM_EXTABLE(0b, 0b)
14414+#endif
14415+
14416+ "sete %1\n"
14417 : "=m" (v->counter), "=qm" (c)
14418 : "er" (i), "m" (v->counter) : "memory");
14419 return c;
14420@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14421 */
14422 static inline void atomic64_inc(atomic64_t *v)
14423 {
14424+ asm volatile(LOCK_PREFIX "incq %0\n"
14425+
14426+#ifdef CONFIG_PAX_REFCOUNT
14427+ "jno 0f\n"
14428+ LOCK_PREFIX "decq %0\n"
14429+ "int $4\n0:\n"
14430+ _ASM_EXTABLE(0b, 0b)
14431+#endif
14432+
14433+ : "=m" (v->counter)
14434+ : "m" (v->counter));
14435+}
14436+
14437+/**
14438+ * atomic64_inc_unchecked - increment atomic64 variable
14439+ * @v: pointer to type atomic64_unchecked_t
14440+ *
14441+ * Atomically increments @v by 1.
14442+ */
14443+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
14444+{
14445 asm volatile(LOCK_PREFIX "incq %0"
14446 : "=m" (v->counter)
14447 : "m" (v->counter));
14448@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
14449 */
14450 static inline void atomic64_dec(atomic64_t *v)
14451 {
14452- asm volatile(LOCK_PREFIX "decq %0"
14453+ asm volatile(LOCK_PREFIX "decq %0\n"
14454+
14455+#ifdef CONFIG_PAX_REFCOUNT
14456+ "jno 0f\n"
14457+ LOCK_PREFIX "incq %0\n"
14458+ "int $4\n0:\n"
14459+ _ASM_EXTABLE(0b, 0b)
14460+#endif
14461+
14462+ : "=m" (v->counter)
14463+ : "m" (v->counter));
14464+}
14465+
14466+/**
14467+ * atomic64_dec_unchecked - decrement atomic64 variable
14468+ * @v: pointer to type atomic64_t
14469+ *
14470+ * Atomically decrements @v by 1.
14471+ */
14472+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
14473+{
14474+ asm volatile(LOCK_PREFIX "decq %0\n"
14475 : "=m" (v->counter)
14476 : "m" (v->counter));
14477 }
14478@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
14479 {
14480 unsigned char c;
14481
14482- asm volatile(LOCK_PREFIX "decq %0; sete %1"
14483+ asm volatile(LOCK_PREFIX "decq %0\n"
14484+
14485+#ifdef CONFIG_PAX_REFCOUNT
14486+ "jno 0f\n"
14487+ LOCK_PREFIX "incq %0\n"
14488+ "int $4\n0:\n"
14489+ _ASM_EXTABLE(0b, 0b)
14490+#endif
14491+
14492+ "sete %1\n"
14493 : "=m" (v->counter), "=qm" (c)
14494 : "m" (v->counter) : "memory");
14495 return c != 0;
14496@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
14497 {
14498 unsigned char c;
14499
14500- asm volatile(LOCK_PREFIX "incq %0; sete %1"
14501+ asm volatile(LOCK_PREFIX "incq %0\n"
14502+
14503+#ifdef CONFIG_PAX_REFCOUNT
14504+ "jno 0f\n"
14505+ LOCK_PREFIX "decq %0\n"
14506+ "int $4\n0:\n"
14507+ _ASM_EXTABLE(0b, 0b)
14508+#endif
14509+
14510+ "sete %1\n"
14511 : "=m" (v->counter), "=qm" (c)
14512 : "m" (v->counter) : "memory");
14513 return c != 0;
14514@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
14515 {
14516 unsigned char c;
14517
14518- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
14519+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
14520+
14521+#ifdef CONFIG_PAX_REFCOUNT
14522+ "jno 0f\n"
14523+ LOCK_PREFIX "subq %2,%0\n"
14524+ "int $4\n0:\n"
14525+ _ASM_EXTABLE(0b, 0b)
14526+#endif
14527+
14528+ "sets %1\n"
14529 : "=m" (v->counter), "=qm" (c)
14530 : "er" (i), "m" (v->counter) : "memory");
14531 return c;
14532@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
14533 */
14534 static inline long atomic64_add_return(long i, atomic64_t *v)
14535 {
14536+ return i + xadd_check_overflow(&v->counter, i);
14537+}
14538+
14539+/**
14540+ * atomic64_add_return_unchecked - add and return
14541+ * @i: integer value to add
14542+ * @v: pointer to type atomic64_unchecked_t
14543+ *
14544+ * Atomically adds @i to @v and returns @i + @v
14545+ */
14546+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
14547+{
14548 return i + xadd(&v->counter, i);
14549 }
14550
14551@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
14552 }
14553
14554 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
14555+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14556+{
14557+ return atomic64_add_return_unchecked(1, v);
14558+}
14559 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
14560
14561 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
14562@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
14563 return cmpxchg(&v->counter, old, new);
14564 }
14565
14566+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
14567+{
14568+ return cmpxchg(&v->counter, old, new);
14569+}
14570+
14571 static inline long atomic64_xchg(atomic64_t *v, long new)
14572 {
14573 return xchg(&v->counter, new);
14574@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
14575 */
14576 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
14577 {
14578- long c, old;
14579+ long c, old, new;
14580 c = atomic64_read(v);
14581 for (;;) {
14582- if (unlikely(c == (u)))
14583+ if (unlikely(c == u))
14584 break;
14585- old = atomic64_cmpxchg((v), c, c + (a));
14586+
14587+ asm volatile("add %2,%0\n"
14588+
14589+#ifdef CONFIG_PAX_REFCOUNT
14590+ "jno 0f\n"
14591+ "sub %2,%0\n"
14592+ "int $4\n0:\n"
14593+ _ASM_EXTABLE(0b, 0b)
14594+#endif
14595+
14596+ : "=r" (new)
14597+ : "0" (c), "ir" (a));
14598+
14599+ old = atomic64_cmpxchg(v, c, new);
14600 if (likely(old == c))
14601 break;
14602 c = old;
14603 }
14604- return c != (u);
14605+ return c != u;
14606 }
14607
14608 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
14609diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
14610index 6dfd019..28e188d 100644
14611--- a/arch/x86/include/asm/bitops.h
14612+++ b/arch/x86/include/asm/bitops.h
14613@@ -40,7 +40,7 @@
14614 * a mask operation on a byte.
14615 */
14616 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
14617-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
14618+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
14619 #define CONST_MASK(nr) (1 << ((nr) & 7))
14620
14621 /**
14622@@ -486,7 +486,7 @@ static inline int fls(int x)
14623 * at position 64.
14624 */
14625 #ifdef CONFIG_X86_64
14626-static __always_inline int fls64(__u64 x)
14627+static __always_inline long fls64(__u64 x)
14628 {
14629 int bitpos = -1;
14630 /*
14631diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
14632index 4fa687a..60f2d39 100644
14633--- a/arch/x86/include/asm/boot.h
14634+++ b/arch/x86/include/asm/boot.h
14635@@ -6,10 +6,15 @@
14636 #include <uapi/asm/boot.h>
14637
14638 /* Physical address where kernel should be loaded. */
14639-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
14640+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
14641 + (CONFIG_PHYSICAL_ALIGN - 1)) \
14642 & ~(CONFIG_PHYSICAL_ALIGN - 1))
14643
14644+#ifndef __ASSEMBLY__
14645+extern unsigned char __LOAD_PHYSICAL_ADDR[];
14646+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
14647+#endif
14648+
14649 /* Minimum kernel alignment, as a power of two */
14650 #ifdef CONFIG_X86_64
14651 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
14652diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
14653index 48f99f1..d78ebf9 100644
14654--- a/arch/x86/include/asm/cache.h
14655+++ b/arch/x86/include/asm/cache.h
14656@@ -5,12 +5,13 @@
14657
14658 /* L1 cache line size */
14659 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
14660-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
14661+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
14662
14663 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
14664+#define __read_only __attribute__((__section__(".data..read_only")))
14665
14666 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
14667-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
14668+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
14669
14670 #ifdef CONFIG_X86_VSMP
14671 #ifdef CONFIG_SMP
14672diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
14673index 9863ee3..4a1f8e1 100644
14674--- a/arch/x86/include/asm/cacheflush.h
14675+++ b/arch/x86/include/asm/cacheflush.h
14676@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
14677 unsigned long pg_flags = pg->flags & _PGMT_MASK;
14678
14679 if (pg_flags == _PGMT_DEFAULT)
14680- return -1;
14681+ return ~0UL;
14682 else if (pg_flags == _PGMT_WC)
14683 return _PAGE_CACHE_WC;
14684 else if (pg_flags == _PGMT_UC_MINUS)
14685diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
14686index 46fc474..b02b0f9 100644
14687--- a/arch/x86/include/asm/checksum_32.h
14688+++ b/arch/x86/include/asm/checksum_32.h
14689@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
14690 int len, __wsum sum,
14691 int *src_err_ptr, int *dst_err_ptr);
14692
14693+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
14694+ int len, __wsum sum,
14695+ int *src_err_ptr, int *dst_err_ptr);
14696+
14697+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
14698+ int len, __wsum sum,
14699+ int *src_err_ptr, int *dst_err_ptr);
14700+
14701 /*
14702 * Note: when you get a NULL pointer exception here this means someone
14703 * passed in an incorrect kernel address to one of these functions.
14704@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
14705 int *err_ptr)
14706 {
14707 might_sleep();
14708- return csum_partial_copy_generic((__force void *)src, dst,
14709+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
14710 len, sum, err_ptr, NULL);
14711 }
14712
14713@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
14714 {
14715 might_sleep();
14716 if (access_ok(VERIFY_WRITE, dst, len))
14717- return csum_partial_copy_generic(src, (__force void *)dst,
14718+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
14719 len, sum, NULL, err_ptr);
14720
14721 if (len)
14722diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
14723index d47786a..ce1b05d 100644
14724--- a/arch/x86/include/asm/cmpxchg.h
14725+++ b/arch/x86/include/asm/cmpxchg.h
14726@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
14727 __compiletime_error("Bad argument size for cmpxchg");
14728 extern void __xadd_wrong_size(void)
14729 __compiletime_error("Bad argument size for xadd");
14730+extern void __xadd_check_overflow_wrong_size(void)
14731+ __compiletime_error("Bad argument size for xadd_check_overflow");
14732 extern void __add_wrong_size(void)
14733 __compiletime_error("Bad argument size for add");
14734+extern void __add_check_overflow_wrong_size(void)
14735+ __compiletime_error("Bad argument size for add_check_overflow");
14736
14737 /*
14738 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
14739@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
14740 __ret; \
14741 })
14742
14743+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
14744+ ({ \
14745+ __typeof__ (*(ptr)) __ret = (arg); \
14746+ switch (sizeof(*(ptr))) { \
14747+ case __X86_CASE_L: \
14748+ asm volatile (lock #op "l %0, %1\n" \
14749+ "jno 0f\n" \
14750+ "mov %0,%1\n" \
14751+ "int $4\n0:\n" \
14752+ _ASM_EXTABLE(0b, 0b) \
14753+ : "+r" (__ret), "+m" (*(ptr)) \
14754+ : : "memory", "cc"); \
14755+ break; \
14756+ case __X86_CASE_Q: \
14757+ asm volatile (lock #op "q %q0, %1\n" \
14758+ "jno 0f\n" \
14759+ "mov %0,%1\n" \
14760+ "int $4\n0:\n" \
14761+ _ASM_EXTABLE(0b, 0b) \
14762+ : "+r" (__ret), "+m" (*(ptr)) \
14763+ : : "memory", "cc"); \
14764+ break; \
14765+ default: \
14766+ __ ## op ## _check_overflow_wrong_size(); \
14767+ } \
14768+ __ret; \
14769+ })
14770+
14771 /*
14772 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
14773 * Since this is generally used to protect other memory information, we
14774@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
14775 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
14776 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
14777
14778+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
14779+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
14780+
14781 #define __add(ptr, inc, lock) \
14782 ({ \
14783 __typeof__ (*(ptr)) __ret = (inc); \
14784diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
14785index 59c6c40..5e0b22c 100644
14786--- a/arch/x86/include/asm/compat.h
14787+++ b/arch/x86/include/asm/compat.h
14788@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
14789 typedef u32 compat_uint_t;
14790 typedef u32 compat_ulong_t;
14791 typedef u64 __attribute__((aligned(4))) compat_u64;
14792-typedef u32 compat_uptr_t;
14793+typedef u32 __user compat_uptr_t;
14794
14795 struct compat_timespec {
14796 compat_time_t tv_sec;
14797diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
14798index 47538a6..44902d1 100644
14799--- a/arch/x86/include/asm/cpufeature.h
14800+++ b/arch/x86/include/asm/cpufeature.h
14801@@ -203,7 +203,7 @@
14802 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
14803 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
14804 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
14805-
14806+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
14807
14808 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
14809 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
14810@@ -211,7 +211,7 @@
14811 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
14812 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
14813 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
14814-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
14815+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
14816 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
14817 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
14818 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
14819@@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
14820 #undef cpu_has_centaur_mcr
14821 #define cpu_has_centaur_mcr 0
14822
14823+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
14824 #endif /* CONFIG_X86_64 */
14825
14826 #if __GNUC__ >= 4
14827@@ -403,7 +404,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
14828
14829 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
14830 t_warn:
14831- warn_pre_alternatives();
14832+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
14833+ warn_pre_alternatives();
14834 return false;
14835 #endif
14836 #else /* GCC_VERSION >= 40500 */
14837@@ -421,7 +423,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
14838 ".section .discard,\"aw\",@progbits\n"
14839 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
14840 ".previous\n"
14841- ".section .altinstr_replacement,\"ax\"\n"
14842+ ".section .altinstr_replacement,\"a\"\n"
14843 "3: movb $1,%0\n"
14844 "4:\n"
14845 ".previous\n"
14846@@ -457,7 +459,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14847 " .byte 2b - 1b\n" /* src len */
14848 " .byte 4f - 3f\n" /* repl len */
14849 ".previous\n"
14850- ".section .altinstr_replacement,\"ax\"\n"
14851+ ".section .altinstr_replacement,\"a\"\n"
14852 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
14853 "4:\n"
14854 ".previous\n"
14855@@ -490,7 +492,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14856 ".section .discard,\"aw\",@progbits\n"
14857 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
14858 ".previous\n"
14859- ".section .altinstr_replacement,\"ax\"\n"
14860+ ".section .altinstr_replacement,\"a\"\n"
14861 "3: movb $0,%0\n"
14862 "4:\n"
14863 ".previous\n"
14864@@ -504,7 +506,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14865 ".section .discard,\"aw\",@progbits\n"
14866 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
14867 ".previous\n"
14868- ".section .altinstr_replacement,\"ax\"\n"
14869+ ".section .altinstr_replacement,\"a\"\n"
14870 "5: movb $1,%0\n"
14871 "6:\n"
14872 ".previous\n"
14873diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
14874index b90e5df..b462c91 100644
14875--- a/arch/x86/include/asm/desc.h
14876+++ b/arch/x86/include/asm/desc.h
14877@@ -4,6 +4,7 @@
14878 #include <asm/desc_defs.h>
14879 #include <asm/ldt.h>
14880 #include <asm/mmu.h>
14881+#include <asm/pgtable.h>
14882
14883 #include <linux/smp.h>
14884 #include <linux/percpu.h>
14885@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
14886
14887 desc->type = (info->read_exec_only ^ 1) << 1;
14888 desc->type |= info->contents << 2;
14889+ desc->type |= info->seg_not_present ^ 1;
14890
14891 desc->s = 1;
14892 desc->dpl = 0x3;
14893@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
14894 }
14895
14896 extern struct desc_ptr idt_descr;
14897-extern gate_desc idt_table[];
14898-extern struct desc_ptr debug_idt_descr;
14899-extern gate_desc debug_idt_table[];
14900-
14901-struct gdt_page {
14902- struct desc_struct gdt[GDT_ENTRIES];
14903-} __attribute__((aligned(PAGE_SIZE)));
14904-
14905-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
14906+extern gate_desc idt_table[IDT_ENTRIES];
14907+extern const struct desc_ptr debug_idt_descr;
14908+extern gate_desc debug_idt_table[IDT_ENTRIES];
14909
14910+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
14911 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
14912 {
14913- return per_cpu(gdt_page, cpu).gdt;
14914+ return cpu_gdt_table[cpu];
14915 }
14916
14917 #ifdef CONFIG_X86_64
14918@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
14919 unsigned long base, unsigned dpl, unsigned flags,
14920 unsigned short seg)
14921 {
14922- gate->a = (seg << 16) | (base & 0xffff);
14923- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
14924+ gate->gate.offset_low = base;
14925+ gate->gate.seg = seg;
14926+ gate->gate.reserved = 0;
14927+ gate->gate.type = type;
14928+ gate->gate.s = 0;
14929+ gate->gate.dpl = dpl;
14930+ gate->gate.p = 1;
14931+ gate->gate.offset_high = base >> 16;
14932 }
14933
14934 #endif
14935@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
14936
14937 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
14938 {
14939+ pax_open_kernel();
14940 memcpy(&idt[entry], gate, sizeof(*gate));
14941+ pax_close_kernel();
14942 }
14943
14944 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
14945 {
14946+ pax_open_kernel();
14947 memcpy(&ldt[entry], desc, 8);
14948+ pax_close_kernel();
14949 }
14950
14951 static inline void
14952@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
14953 default: size = sizeof(*gdt); break;
14954 }
14955
14956+ pax_open_kernel();
14957 memcpy(&gdt[entry], desc, size);
14958+ pax_close_kernel();
14959 }
14960
14961 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
14962@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
14963
14964 static inline void native_load_tr_desc(void)
14965 {
14966+ pax_open_kernel();
14967 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
14968+ pax_close_kernel();
14969 }
14970
14971 static inline void native_load_gdt(const struct desc_ptr *dtr)
14972@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
14973 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
14974 unsigned int i;
14975
14976+ pax_open_kernel();
14977 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
14978 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
14979+ pax_close_kernel();
14980 }
14981
14982 #define _LDT_empty(info) \
14983@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
14984 preempt_enable();
14985 }
14986
14987-static inline unsigned long get_desc_base(const struct desc_struct *desc)
14988+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
14989 {
14990 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
14991 }
14992@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
14993 }
14994
14995 #ifdef CONFIG_X86_64
14996-static inline void set_nmi_gate(int gate, void *addr)
14997+static inline void set_nmi_gate(int gate, const void *addr)
14998 {
14999 gate_desc s;
15000
15001@@ -321,8 +334,8 @@ static inline void set_nmi_gate(int gate, void *addr)
15002 #endif
15003
15004 #ifdef CONFIG_TRACING
15005-extern struct desc_ptr trace_idt_descr;
15006-extern gate_desc trace_idt_table[];
15007+extern const struct desc_ptr trace_idt_descr;
15008+extern gate_desc trace_idt_table[IDT_ENTRIES];
15009 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15010 {
15011 write_idt_entry(trace_idt_table, entry, gate);
15012@@ -333,7 +346,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15013 }
15014 #endif
15015
15016-static inline void _set_gate(int gate, unsigned type, void *addr,
15017+static inline void _set_gate(int gate, unsigned type, const void *addr,
15018 unsigned dpl, unsigned ist, unsigned seg)
15019 {
15020 gate_desc s;
15021@@ -353,7 +366,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
15022 * Pentium F0 0F bugfix can have resulted in the mapped
15023 * IDT being write-protected.
15024 */
15025-static inline void set_intr_gate(unsigned int n, void *addr)
15026+static inline void set_intr_gate(unsigned int n, const void *addr)
15027 {
15028 BUG_ON((unsigned)n > 0xFF);
15029 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
15030@@ -410,19 +423,19 @@ static inline void __alloc_intr_gate(unsigned int n, void *addr)
15031 /*
15032 * This routine sets up an interrupt gate at directory privilege level 3.
15033 */
15034-static inline void set_system_intr_gate(unsigned int n, void *addr)
15035+static inline void set_system_intr_gate(unsigned int n, const void *addr)
15036 {
15037 BUG_ON((unsigned)n > 0xFF);
15038 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
15039 }
15040
15041-static inline void set_system_trap_gate(unsigned int n, void *addr)
15042+static inline void set_system_trap_gate(unsigned int n, const void *addr)
15043 {
15044 BUG_ON((unsigned)n > 0xFF);
15045 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
15046 }
15047
15048-static inline void set_trap_gate(unsigned int n, void *addr)
15049+static inline void set_trap_gate(unsigned int n, const void *addr)
15050 {
15051 BUG_ON((unsigned)n > 0xFF);
15052 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
15053@@ -431,16 +444,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
15054 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
15055 {
15056 BUG_ON((unsigned)n > 0xFF);
15057- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
15058+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
15059 }
15060
15061-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
15062+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
15063 {
15064 BUG_ON((unsigned)n > 0xFF);
15065 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
15066 }
15067
15068-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
15069+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
15070 {
15071 BUG_ON((unsigned)n > 0xFF);
15072 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
15073@@ -512,4 +525,17 @@ static inline void load_current_idt(void)
15074 else
15075 load_idt((const struct desc_ptr *)&idt_descr);
15076 }
15077+
15078+#ifdef CONFIG_X86_32
15079+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
15080+{
15081+ struct desc_struct d;
15082+
15083+ if (likely(limit))
15084+ limit = (limit - 1UL) >> PAGE_SHIFT;
15085+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
15086+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
15087+}
15088+#endif
15089+
15090 #endif /* _ASM_X86_DESC_H */
15091diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
15092index 278441f..b95a174 100644
15093--- a/arch/x86/include/asm/desc_defs.h
15094+++ b/arch/x86/include/asm/desc_defs.h
15095@@ -31,6 +31,12 @@ struct desc_struct {
15096 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
15097 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
15098 };
15099+ struct {
15100+ u16 offset_low;
15101+ u16 seg;
15102+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
15103+ unsigned offset_high: 16;
15104+ } gate;
15105 };
15106 } __attribute__((packed));
15107
15108diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
15109index ced283a..ffe04cc 100644
15110--- a/arch/x86/include/asm/div64.h
15111+++ b/arch/x86/include/asm/div64.h
15112@@ -39,7 +39,7 @@
15113 __mod; \
15114 })
15115
15116-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15117+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15118 {
15119 union {
15120 u64 v64;
15121diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
15122index 9c999c1..3860cb8 100644
15123--- a/arch/x86/include/asm/elf.h
15124+++ b/arch/x86/include/asm/elf.h
15125@@ -243,7 +243,25 @@ extern int force_personality32;
15126 the loader. We need to make sure that it is out of the way of the program
15127 that it will "exec", and that there is sufficient room for the brk. */
15128
15129+#ifdef CONFIG_PAX_SEGMEXEC
15130+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
15131+#else
15132 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
15133+#endif
15134+
15135+#ifdef CONFIG_PAX_ASLR
15136+#ifdef CONFIG_X86_32
15137+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
15138+
15139+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15140+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15141+#else
15142+#define PAX_ELF_ET_DYN_BASE 0x400000UL
15143+
15144+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15145+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15146+#endif
15147+#endif
15148
15149 /* This yields a mask that user programs can use to figure out what
15150 instruction set this CPU supports. This could be done in user space,
15151@@ -296,16 +314,12 @@ do { \
15152
15153 #define ARCH_DLINFO \
15154 do { \
15155- if (vdso_enabled) \
15156- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15157- (unsigned long)current->mm->context.vdso); \
15158+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15159 } while (0)
15160
15161 #define ARCH_DLINFO_X32 \
15162 do { \
15163- if (vdso_enabled) \
15164- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15165- (unsigned long)current->mm->context.vdso); \
15166+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15167 } while (0)
15168
15169 #define AT_SYSINFO 32
15170@@ -320,7 +334,7 @@ else \
15171
15172 #endif /* !CONFIG_X86_32 */
15173
15174-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
15175+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
15176
15177 #define VDSO_ENTRY \
15178 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
15179@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
15180 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
15181 #define compat_arch_setup_additional_pages syscall32_setup_pages
15182
15183-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
15184-#define arch_randomize_brk arch_randomize_brk
15185-
15186 /*
15187 * True on X86_32 or when emulating IA32 on X86_64
15188 */
15189diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
15190index 77a99ac..39ff7f5 100644
15191--- a/arch/x86/include/asm/emergency-restart.h
15192+++ b/arch/x86/include/asm/emergency-restart.h
15193@@ -1,6 +1,6 @@
15194 #ifndef _ASM_X86_EMERGENCY_RESTART_H
15195 #define _ASM_X86_EMERGENCY_RESTART_H
15196
15197-extern void machine_emergency_restart(void);
15198+extern void machine_emergency_restart(void) __noreturn;
15199
15200 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
15201diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
15202index 4d0bda7..221da4d 100644
15203--- a/arch/x86/include/asm/fpu-internal.h
15204+++ b/arch/x86/include/asm/fpu-internal.h
15205@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15206 #define user_insn(insn, output, input...) \
15207 ({ \
15208 int err; \
15209+ pax_open_userland(); \
15210 asm volatile(ASM_STAC "\n" \
15211- "1:" #insn "\n\t" \
15212+ "1:" \
15213+ __copyuser_seg \
15214+ #insn "\n\t" \
15215 "2: " ASM_CLAC "\n" \
15216 ".section .fixup,\"ax\"\n" \
15217 "3: movl $-1,%[err]\n" \
15218@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15219 _ASM_EXTABLE(1b, 3b) \
15220 : [err] "=r" (err), output \
15221 : "0"(0), input); \
15222+ pax_close_userland(); \
15223 err; \
15224 })
15225
15226@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
15227 "emms\n\t" /* clear stack tags */
15228 "fildl %P[addr]", /* set F?P to defined value */
15229 X86_FEATURE_FXSAVE_LEAK,
15230- [addr] "m" (tsk->thread.fpu.has_fpu));
15231+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
15232
15233 return fpu_restore_checking(&tsk->thread.fpu);
15234 }
15235diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
15236index be27ba1..04a8801 100644
15237--- a/arch/x86/include/asm/futex.h
15238+++ b/arch/x86/include/asm/futex.h
15239@@ -12,6 +12,7 @@
15240 #include <asm/smap.h>
15241
15242 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
15243+ typecheck(u32 __user *, uaddr); \
15244 asm volatile("\t" ASM_STAC "\n" \
15245 "1:\t" insn "\n" \
15246 "2:\t" ASM_CLAC "\n" \
15247@@ -20,15 +21,16 @@
15248 "\tjmp\t2b\n" \
15249 "\t.previous\n" \
15250 _ASM_EXTABLE(1b, 3b) \
15251- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
15252+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
15253 : "i" (-EFAULT), "0" (oparg), "1" (0))
15254
15255 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
15256+ typecheck(u32 __user *, uaddr); \
15257 asm volatile("\t" ASM_STAC "\n" \
15258 "1:\tmovl %2, %0\n" \
15259 "\tmovl\t%0, %3\n" \
15260 "\t" insn "\n" \
15261- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
15262+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
15263 "\tjnz\t1b\n" \
15264 "3:\t" ASM_CLAC "\n" \
15265 "\t.section .fixup,\"ax\"\n" \
15266@@ -38,7 +40,7 @@
15267 _ASM_EXTABLE(1b, 4b) \
15268 _ASM_EXTABLE(2b, 4b) \
15269 : "=&a" (oldval), "=&r" (ret), \
15270- "+m" (*uaddr), "=&r" (tem) \
15271+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
15272 : "r" (oparg), "i" (-EFAULT), "1" (0))
15273
15274 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15275@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15276
15277 pagefault_disable();
15278
15279+ pax_open_userland();
15280 switch (op) {
15281 case FUTEX_OP_SET:
15282- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
15283+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
15284 break;
15285 case FUTEX_OP_ADD:
15286- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
15287+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
15288 uaddr, oparg);
15289 break;
15290 case FUTEX_OP_OR:
15291@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15292 default:
15293 ret = -ENOSYS;
15294 }
15295+ pax_close_userland();
15296
15297 pagefault_enable();
15298
15299@@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
15300 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
15301 return -EFAULT;
15302
15303+ pax_open_userland();
15304 asm volatile("\t" ASM_STAC "\n"
15305- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
15306+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
15307 "2:\t" ASM_CLAC "\n"
15308 "\t.section .fixup, \"ax\"\n"
15309 "3:\tmov %3, %0\n"
15310 "\tjmp 2b\n"
15311 "\t.previous\n"
15312 _ASM_EXTABLE(1b, 3b)
15313- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
15314+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
15315 : "i" (-EFAULT), "r" (newval), "1" (oldval)
15316 : "memory"
15317 );
15318+ pax_close_userland();
15319
15320 *uval = oldval;
15321 return ret;
15322diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
15323index e4ac559..c1c0c87 100644
15324--- a/arch/x86/include/asm/hw_irq.h
15325+++ b/arch/x86/include/asm/hw_irq.h
15326@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
15327 extern void enable_IO_APIC(void);
15328
15329 /* Statistics */
15330-extern atomic_t irq_err_count;
15331-extern atomic_t irq_mis_count;
15332+extern atomic_unchecked_t irq_err_count;
15333+extern atomic_unchecked_t irq_mis_count;
15334
15335 /* EISA */
15336 extern void eisa_set_level_irq(unsigned int irq);
15337diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
15338index a203659..9889f1c 100644
15339--- a/arch/x86/include/asm/i8259.h
15340+++ b/arch/x86/include/asm/i8259.h
15341@@ -62,7 +62,7 @@ struct legacy_pic {
15342 void (*init)(int auto_eoi);
15343 int (*irq_pending)(unsigned int irq);
15344 void (*make_irq)(unsigned int irq);
15345-};
15346+} __do_const;
15347
15348 extern struct legacy_pic *legacy_pic;
15349 extern struct legacy_pic null_legacy_pic;
15350diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
15351index 34f69cb..6d95446 100644
15352--- a/arch/x86/include/asm/io.h
15353+++ b/arch/x86/include/asm/io.h
15354@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
15355 "m" (*(volatile type __force *)addr) barrier); }
15356
15357 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
15358-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
15359-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
15360+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
15361+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
15362
15363 build_mmio_read(__readb, "b", unsigned char, "=q", )
15364-build_mmio_read(__readw, "w", unsigned short, "=r", )
15365-build_mmio_read(__readl, "l", unsigned int, "=r", )
15366+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
15367+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
15368
15369 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
15370 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
15371@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
15372 return ioremap_nocache(offset, size);
15373 }
15374
15375-extern void iounmap(volatile void __iomem *addr);
15376+extern void iounmap(const volatile void __iomem *addr);
15377
15378 extern void set_iounmap_nonlazy(void);
15379
15380@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
15381
15382 #include <linux/vmalloc.h>
15383
15384+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
15385+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
15386+{
15387+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
15388+}
15389+
15390+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
15391+{
15392+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
15393+}
15394+
15395 /*
15396 * Convert a virtual cached pointer to an uncached pointer
15397 */
15398diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
15399index bba3cf8..06bc8da 100644
15400--- a/arch/x86/include/asm/irqflags.h
15401+++ b/arch/x86/include/asm/irqflags.h
15402@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
15403 sti; \
15404 sysexit
15405
15406+#define GET_CR0_INTO_RDI mov %cr0, %rdi
15407+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
15408+#define GET_CR3_INTO_RDI mov %cr3, %rdi
15409+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
15410+
15411 #else
15412 #define INTERRUPT_RETURN iret
15413 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
15414diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
15415index 5a6d287..f815789 100644
15416--- a/arch/x86/include/asm/kprobes.h
15417+++ b/arch/x86/include/asm/kprobes.h
15418@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
15419 #define RELATIVEJUMP_SIZE 5
15420 #define RELATIVECALL_OPCODE 0xe8
15421 #define RELATIVE_ADDR_SIZE 4
15422-#define MAX_STACK_SIZE 64
15423-#define MIN_STACK_SIZE(ADDR) \
15424- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
15425- THREAD_SIZE - (unsigned long)(ADDR))) \
15426- ? (MAX_STACK_SIZE) \
15427- : (((unsigned long)current_thread_info()) + \
15428- THREAD_SIZE - (unsigned long)(ADDR)))
15429+#define MAX_STACK_SIZE 64UL
15430+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
15431
15432 #define flush_insn_slot(p) do { } while (0)
15433
15434diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
15435index 2d89e39..baee879 100644
15436--- a/arch/x86/include/asm/local.h
15437+++ b/arch/x86/include/asm/local.h
15438@@ -10,33 +10,97 @@ typedef struct {
15439 atomic_long_t a;
15440 } local_t;
15441
15442+typedef struct {
15443+ atomic_long_unchecked_t a;
15444+} local_unchecked_t;
15445+
15446 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
15447
15448 #define local_read(l) atomic_long_read(&(l)->a)
15449+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
15450 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
15451+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
15452
15453 static inline void local_inc(local_t *l)
15454 {
15455- asm volatile(_ASM_INC "%0"
15456+ asm volatile(_ASM_INC "%0\n"
15457+
15458+#ifdef CONFIG_PAX_REFCOUNT
15459+ "jno 0f\n"
15460+ _ASM_DEC "%0\n"
15461+ "int $4\n0:\n"
15462+ _ASM_EXTABLE(0b, 0b)
15463+#endif
15464+
15465+ : "+m" (l->a.counter));
15466+}
15467+
15468+static inline void local_inc_unchecked(local_unchecked_t *l)
15469+{
15470+ asm volatile(_ASM_INC "%0\n"
15471 : "+m" (l->a.counter));
15472 }
15473
15474 static inline void local_dec(local_t *l)
15475 {
15476- asm volatile(_ASM_DEC "%0"
15477+ asm volatile(_ASM_DEC "%0\n"
15478+
15479+#ifdef CONFIG_PAX_REFCOUNT
15480+ "jno 0f\n"
15481+ _ASM_INC "%0\n"
15482+ "int $4\n0:\n"
15483+ _ASM_EXTABLE(0b, 0b)
15484+#endif
15485+
15486+ : "+m" (l->a.counter));
15487+}
15488+
15489+static inline void local_dec_unchecked(local_unchecked_t *l)
15490+{
15491+ asm volatile(_ASM_DEC "%0\n"
15492 : "+m" (l->a.counter));
15493 }
15494
15495 static inline void local_add(long i, local_t *l)
15496 {
15497- asm volatile(_ASM_ADD "%1,%0"
15498+ asm volatile(_ASM_ADD "%1,%0\n"
15499+
15500+#ifdef CONFIG_PAX_REFCOUNT
15501+ "jno 0f\n"
15502+ _ASM_SUB "%1,%0\n"
15503+ "int $4\n0:\n"
15504+ _ASM_EXTABLE(0b, 0b)
15505+#endif
15506+
15507+ : "+m" (l->a.counter)
15508+ : "ir" (i));
15509+}
15510+
15511+static inline void local_add_unchecked(long i, local_unchecked_t *l)
15512+{
15513+ asm volatile(_ASM_ADD "%1,%0\n"
15514 : "+m" (l->a.counter)
15515 : "ir" (i));
15516 }
15517
15518 static inline void local_sub(long i, local_t *l)
15519 {
15520- asm volatile(_ASM_SUB "%1,%0"
15521+ asm volatile(_ASM_SUB "%1,%0\n"
15522+
15523+#ifdef CONFIG_PAX_REFCOUNT
15524+ "jno 0f\n"
15525+ _ASM_ADD "%1,%0\n"
15526+ "int $4\n0:\n"
15527+ _ASM_EXTABLE(0b, 0b)
15528+#endif
15529+
15530+ : "+m" (l->a.counter)
15531+ : "ir" (i));
15532+}
15533+
15534+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
15535+{
15536+ asm volatile(_ASM_SUB "%1,%0\n"
15537 : "+m" (l->a.counter)
15538 : "ir" (i));
15539 }
15540@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
15541 {
15542 unsigned char c;
15543
15544- asm volatile(_ASM_SUB "%2,%0; sete %1"
15545+ asm volatile(_ASM_SUB "%2,%0\n"
15546+
15547+#ifdef CONFIG_PAX_REFCOUNT
15548+ "jno 0f\n"
15549+ _ASM_ADD "%2,%0\n"
15550+ "int $4\n0:\n"
15551+ _ASM_EXTABLE(0b, 0b)
15552+#endif
15553+
15554+ "sete %1\n"
15555 : "+m" (l->a.counter), "=qm" (c)
15556 : "ir" (i) : "memory");
15557 return c;
15558@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
15559 {
15560 unsigned char c;
15561
15562- asm volatile(_ASM_DEC "%0; sete %1"
15563+ asm volatile(_ASM_DEC "%0\n"
15564+
15565+#ifdef CONFIG_PAX_REFCOUNT
15566+ "jno 0f\n"
15567+ _ASM_INC "%0\n"
15568+ "int $4\n0:\n"
15569+ _ASM_EXTABLE(0b, 0b)
15570+#endif
15571+
15572+ "sete %1\n"
15573 : "+m" (l->a.counter), "=qm" (c)
15574 : : "memory");
15575 return c != 0;
15576@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
15577 {
15578 unsigned char c;
15579
15580- asm volatile(_ASM_INC "%0; sete %1"
15581+ asm volatile(_ASM_INC "%0\n"
15582+
15583+#ifdef CONFIG_PAX_REFCOUNT
15584+ "jno 0f\n"
15585+ _ASM_DEC "%0\n"
15586+ "int $4\n0:\n"
15587+ _ASM_EXTABLE(0b, 0b)
15588+#endif
15589+
15590+ "sete %1\n"
15591 : "+m" (l->a.counter), "=qm" (c)
15592 : : "memory");
15593 return c != 0;
15594@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
15595 {
15596 unsigned char c;
15597
15598- asm volatile(_ASM_ADD "%2,%0; sets %1"
15599+ asm volatile(_ASM_ADD "%2,%0\n"
15600+
15601+#ifdef CONFIG_PAX_REFCOUNT
15602+ "jno 0f\n"
15603+ _ASM_SUB "%2,%0\n"
15604+ "int $4\n0:\n"
15605+ _ASM_EXTABLE(0b, 0b)
15606+#endif
15607+
15608+ "sets %1\n"
15609 : "+m" (l->a.counter), "=qm" (c)
15610 : "ir" (i) : "memory");
15611 return c;
15612@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
15613 static inline long local_add_return(long i, local_t *l)
15614 {
15615 long __i = i;
15616+ asm volatile(_ASM_XADD "%0, %1\n"
15617+
15618+#ifdef CONFIG_PAX_REFCOUNT
15619+ "jno 0f\n"
15620+ _ASM_MOV "%0,%1\n"
15621+ "int $4\n0:\n"
15622+ _ASM_EXTABLE(0b, 0b)
15623+#endif
15624+
15625+ : "+r" (i), "+m" (l->a.counter)
15626+ : : "memory");
15627+ return i + __i;
15628+}
15629+
15630+/**
15631+ * local_add_return_unchecked - add and return
15632+ * @i: integer value to add
15633+ * @l: pointer to type local_unchecked_t
15634+ *
15635+ * Atomically adds @i to @l and returns @i + @l
15636+ */
15637+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
15638+{
15639+ long __i = i;
15640 asm volatile(_ASM_XADD "%0, %1;"
15641 : "+r" (i), "+m" (l->a.counter)
15642 : : "memory");
15643@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
15644
15645 #define local_cmpxchg(l, o, n) \
15646 (cmpxchg_local(&((l)->a.counter), (o), (n)))
15647+#define local_cmpxchg_unchecked(l, o, n) \
15648+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
15649 /* Always has a lock prefix */
15650 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
15651
15652diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
15653new file mode 100644
15654index 0000000..2bfd3ba
15655--- /dev/null
15656+++ b/arch/x86/include/asm/mman.h
15657@@ -0,0 +1,15 @@
15658+#ifndef _X86_MMAN_H
15659+#define _X86_MMAN_H
15660+
15661+#include <uapi/asm/mman.h>
15662+
15663+#ifdef __KERNEL__
15664+#ifndef __ASSEMBLY__
15665+#ifdef CONFIG_X86_32
15666+#define arch_mmap_check i386_mmap_check
15667+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
15668+#endif
15669+#endif
15670+#endif
15671+
15672+#endif /* X86_MMAN_H */
15673diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
15674index 5f55e69..e20bfb1 100644
15675--- a/arch/x86/include/asm/mmu.h
15676+++ b/arch/x86/include/asm/mmu.h
15677@@ -9,7 +9,7 @@
15678 * we put the segment information here.
15679 */
15680 typedef struct {
15681- void *ldt;
15682+ struct desc_struct *ldt;
15683 int size;
15684
15685 #ifdef CONFIG_X86_64
15686@@ -18,7 +18,19 @@ typedef struct {
15687 #endif
15688
15689 struct mutex lock;
15690- void *vdso;
15691+ unsigned long vdso;
15692+
15693+#ifdef CONFIG_X86_32
15694+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15695+ unsigned long user_cs_base;
15696+ unsigned long user_cs_limit;
15697+
15698+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15699+ cpumask_t cpu_user_cs_mask;
15700+#endif
15701+
15702+#endif
15703+#endif
15704 } mm_context_t;
15705
15706 #ifdef CONFIG_SMP
15707diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
15708index cdbf367..ce8f82b 100644
15709--- a/arch/x86/include/asm/mmu_context.h
15710+++ b/arch/x86/include/asm/mmu_context.h
15711@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
15712
15713 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
15714 {
15715+
15716+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15717+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
15718+ unsigned int i;
15719+ pgd_t *pgd;
15720+
15721+ pax_open_kernel();
15722+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
15723+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
15724+ set_pgd_batched(pgd+i, native_make_pgd(0));
15725+ pax_close_kernel();
15726+ }
15727+#endif
15728+
15729 #ifdef CONFIG_SMP
15730 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
15731 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
15732@@ -34,16 +48,55 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15733 struct task_struct *tsk)
15734 {
15735 unsigned cpu = smp_processor_id();
15736+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15737+ int tlbstate = TLBSTATE_OK;
15738+#endif
15739
15740 if (likely(prev != next)) {
15741 #ifdef CONFIG_SMP
15742+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15743+ tlbstate = this_cpu_read(cpu_tlbstate.state);
15744+#endif
15745 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
15746 this_cpu_write(cpu_tlbstate.active_mm, next);
15747 #endif
15748 cpumask_set_cpu(cpu, mm_cpumask(next));
15749
15750 /* Re-load page tables */
15751+#ifdef CONFIG_PAX_PER_CPU_PGD
15752+ pax_open_kernel();
15753+
15754+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15755+ if (static_cpu_has(X86_FEATURE_PCID))
15756+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
15757+ else
15758+#endif
15759+
15760+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
15761+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
15762+ pax_close_kernel();
15763+ 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));
15764+
15765+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15766+ if (static_cpu_has(X86_FEATURE_PCID)) {
15767+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
15768+ u64 descriptor[2];
15769+ descriptor[0] = PCID_USER;
15770+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15771+ } else {
15772+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
15773+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
15774+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
15775+ else
15776+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
15777+ }
15778+ } else
15779+#endif
15780+
15781+ load_cr3(get_cpu_pgd(cpu, kernel));
15782+#else
15783 load_cr3(next->pgd);
15784+#endif
15785
15786 /* stop flush ipis for the previous mm */
15787 cpumask_clear_cpu(cpu, mm_cpumask(prev));
15788@@ -53,9 +106,63 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15789 */
15790 if (unlikely(prev->context.ldt != next->context.ldt))
15791 load_LDT_nolock(&next->context);
15792- }
15793+
15794+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15795+ if (!(__supported_pte_mask & _PAGE_NX)) {
15796+ smp_mb__before_clear_bit();
15797+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
15798+ smp_mb__after_clear_bit();
15799+ cpu_set(cpu, next->context.cpu_user_cs_mask);
15800+ }
15801+#endif
15802+
15803+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15804+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
15805+ prev->context.user_cs_limit != next->context.user_cs_limit))
15806+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15807 #ifdef CONFIG_SMP
15808+ else if (unlikely(tlbstate != TLBSTATE_OK))
15809+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15810+#endif
15811+#endif
15812+
15813+ }
15814 else {
15815+
15816+#ifdef CONFIG_PAX_PER_CPU_PGD
15817+ pax_open_kernel();
15818+
15819+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15820+ if (static_cpu_has(X86_FEATURE_PCID))
15821+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
15822+ else
15823+#endif
15824+
15825+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
15826+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
15827+ pax_close_kernel();
15828+ 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));
15829+
15830+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15831+ if (static_cpu_has(X86_FEATURE_PCID)) {
15832+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
15833+ u64 descriptor[2];
15834+ descriptor[0] = PCID_USER;
15835+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15836+ } else {
15837+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
15838+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
15839+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
15840+ else
15841+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
15842+ }
15843+ } else
15844+#endif
15845+
15846+ load_cr3(get_cpu_pgd(cpu, kernel));
15847+#endif
15848+
15849+#ifdef CONFIG_SMP
15850 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
15851 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
15852
15853@@ -64,11 +171,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15854 * tlb flush IPI delivery. We must reload CR3
15855 * to make sure to use no freed page tables.
15856 */
15857+
15858+#ifndef CONFIG_PAX_PER_CPU_PGD
15859 load_cr3(next->pgd);
15860+#endif
15861+
15862 load_LDT_nolock(&next->context);
15863+
15864+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
15865+ if (!(__supported_pte_mask & _PAGE_NX))
15866+ cpu_set(cpu, next->context.cpu_user_cs_mask);
15867+#endif
15868+
15869+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15870+#ifdef CONFIG_PAX_PAGEEXEC
15871+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
15872+#endif
15873+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15874+#endif
15875+
15876 }
15877+#endif
15878 }
15879-#endif
15880 }
15881
15882 #define activate_mm(prev, next) \
15883diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
15884index e3b7819..b257c64 100644
15885--- a/arch/x86/include/asm/module.h
15886+++ b/arch/x86/include/asm/module.h
15887@@ -5,6 +5,7 @@
15888
15889 #ifdef CONFIG_X86_64
15890 /* X86_64 does not define MODULE_PROC_FAMILY */
15891+#define MODULE_PROC_FAMILY ""
15892 #elif defined CONFIG_M486
15893 #define MODULE_PROC_FAMILY "486 "
15894 #elif defined CONFIG_M586
15895@@ -57,8 +58,20 @@
15896 #error unknown processor family
15897 #endif
15898
15899-#ifdef CONFIG_X86_32
15900-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
15901+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15902+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
15903+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
15904+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
15905+#else
15906+#define MODULE_PAX_KERNEXEC ""
15907 #endif
15908
15909+#ifdef CONFIG_PAX_MEMORY_UDEREF
15910+#define MODULE_PAX_UDEREF "UDEREF "
15911+#else
15912+#define MODULE_PAX_UDEREF ""
15913+#endif
15914+
15915+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
15916+
15917 #endif /* _ASM_X86_MODULE_H */
15918diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
15919index 86f9301..b365cda 100644
15920--- a/arch/x86/include/asm/nmi.h
15921+++ b/arch/x86/include/asm/nmi.h
15922@@ -40,11 +40,11 @@ struct nmiaction {
15923 nmi_handler_t handler;
15924 unsigned long flags;
15925 const char *name;
15926-};
15927+} __do_const;
15928
15929 #define register_nmi_handler(t, fn, fg, n, init...) \
15930 ({ \
15931- static struct nmiaction init fn##_na = { \
15932+ static const struct nmiaction init fn##_na = { \
15933 .handler = (fn), \
15934 .name = (n), \
15935 .flags = (fg), \
15936@@ -52,7 +52,7 @@ struct nmiaction {
15937 __register_nmi_handler((t), &fn##_na); \
15938 })
15939
15940-int __register_nmi_handler(unsigned int, struct nmiaction *);
15941+int __register_nmi_handler(unsigned int, const struct nmiaction *);
15942
15943 void unregister_nmi_handler(unsigned int, const char *);
15944
15945diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
15946index c878924..21f4889 100644
15947--- a/arch/x86/include/asm/page.h
15948+++ b/arch/x86/include/asm/page.h
15949@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
15950 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
15951
15952 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
15953+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
15954
15955 #define __boot_va(x) __va(x)
15956 #define __boot_pa(x) __pa(x)
15957diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
15958index 0f1ddee..e2fc3d1 100644
15959--- a/arch/x86/include/asm/page_64.h
15960+++ b/arch/x86/include/asm/page_64.h
15961@@ -7,9 +7,9 @@
15962
15963 /* duplicated to the one in bootmem.h */
15964 extern unsigned long max_pfn;
15965-extern unsigned long phys_base;
15966+extern const unsigned long phys_base;
15967
15968-static inline unsigned long __phys_addr_nodebug(unsigned long x)
15969+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
15970 {
15971 unsigned long y = x - __START_KERNEL_map;
15972
15973diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
15974index cfdc9ee..3f7b5d6 100644
15975--- a/arch/x86/include/asm/paravirt.h
15976+++ b/arch/x86/include/asm/paravirt.h
15977@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
15978 return (pmd_t) { ret };
15979 }
15980
15981-static inline pmdval_t pmd_val(pmd_t pmd)
15982+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
15983 {
15984 pmdval_t ret;
15985
15986@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
15987 val);
15988 }
15989
15990+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
15991+{
15992+ pgdval_t val = native_pgd_val(pgd);
15993+
15994+ if (sizeof(pgdval_t) > sizeof(long))
15995+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
15996+ val, (u64)val >> 32);
15997+ else
15998+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
15999+ val);
16000+}
16001+
16002 static inline void pgd_clear(pgd_t *pgdp)
16003 {
16004 set_pgd(pgdp, __pgd(0));
16005@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
16006 pv_mmu_ops.set_fixmap(idx, phys, flags);
16007 }
16008
16009+#ifdef CONFIG_PAX_KERNEXEC
16010+static inline unsigned long pax_open_kernel(void)
16011+{
16012+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
16013+}
16014+
16015+static inline unsigned long pax_close_kernel(void)
16016+{
16017+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
16018+}
16019+#else
16020+static inline unsigned long pax_open_kernel(void) { return 0; }
16021+static inline unsigned long pax_close_kernel(void) { return 0; }
16022+#endif
16023+
16024 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
16025
16026 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
16027@@ -926,7 +953,7 @@ extern void default_banner(void);
16028
16029 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
16030 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
16031-#define PARA_INDIRECT(addr) *%cs:addr
16032+#define PARA_INDIRECT(addr) *%ss:addr
16033 #endif
16034
16035 #define INTERRUPT_RETURN \
16036@@ -1001,6 +1028,21 @@ extern void default_banner(void);
16037 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
16038 CLBR_NONE, \
16039 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
16040+
16041+#define GET_CR0_INTO_RDI \
16042+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
16043+ mov %rax,%rdi
16044+
16045+#define SET_RDI_INTO_CR0 \
16046+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16047+
16048+#define GET_CR3_INTO_RDI \
16049+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
16050+ mov %rax,%rdi
16051+
16052+#define SET_RDI_INTO_CR3 \
16053+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
16054+
16055 #endif /* CONFIG_X86_32 */
16056
16057 #endif /* __ASSEMBLY__ */
16058diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
16059index 0db1fca..52310cc 100644
16060--- a/arch/x86/include/asm/paravirt_types.h
16061+++ b/arch/x86/include/asm/paravirt_types.h
16062@@ -84,7 +84,7 @@ struct pv_init_ops {
16063 */
16064 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
16065 unsigned long addr, unsigned len);
16066-};
16067+} __no_const;
16068
16069
16070 struct pv_lazy_ops {
16071@@ -98,7 +98,7 @@ struct pv_time_ops {
16072 unsigned long long (*sched_clock)(void);
16073 unsigned long long (*steal_clock)(int cpu);
16074 unsigned long (*get_tsc_khz)(void);
16075-};
16076+} __no_const;
16077
16078 struct pv_cpu_ops {
16079 /* hooks for various privileged instructions */
16080@@ -192,7 +192,7 @@ struct pv_cpu_ops {
16081
16082 void (*start_context_switch)(struct task_struct *prev);
16083 void (*end_context_switch)(struct task_struct *next);
16084-};
16085+} __no_const;
16086
16087 struct pv_irq_ops {
16088 /*
16089@@ -223,7 +223,7 @@ struct pv_apic_ops {
16090 unsigned long start_eip,
16091 unsigned long start_esp);
16092 #endif
16093-};
16094+} __no_const;
16095
16096 struct pv_mmu_ops {
16097 unsigned long (*read_cr2)(void);
16098@@ -313,6 +313,7 @@ struct pv_mmu_ops {
16099 struct paravirt_callee_save make_pud;
16100
16101 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
16102+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
16103 #endif /* PAGETABLE_LEVELS == 4 */
16104 #endif /* PAGETABLE_LEVELS >= 3 */
16105
16106@@ -324,6 +325,12 @@ struct pv_mmu_ops {
16107 an mfn. We can tell which is which from the index. */
16108 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
16109 phys_addr_t phys, pgprot_t flags);
16110+
16111+#ifdef CONFIG_PAX_KERNEXEC
16112+ unsigned long (*pax_open_kernel)(void);
16113+ unsigned long (*pax_close_kernel)(void);
16114+#endif
16115+
16116 };
16117
16118 struct arch_spinlock;
16119@@ -334,7 +341,7 @@ struct pv_lock_ops {
16120 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
16121 int (*spin_trylock)(struct arch_spinlock *lock);
16122 void (*spin_unlock)(struct arch_spinlock *lock);
16123-};
16124+} __no_const;
16125
16126 /* This contains all the paravirt structures: we get a convenient
16127 * number for each function using the offset which we use to indicate
16128diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
16129index b4389a4..7024269 100644
16130--- a/arch/x86/include/asm/pgalloc.h
16131+++ b/arch/x86/include/asm/pgalloc.h
16132@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
16133 pmd_t *pmd, pte_t *pte)
16134 {
16135 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16136+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
16137+}
16138+
16139+static inline void pmd_populate_user(struct mm_struct *mm,
16140+ pmd_t *pmd, pte_t *pte)
16141+{
16142+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16143 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
16144 }
16145
16146@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
16147
16148 #ifdef CONFIG_X86_PAE
16149 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
16150+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
16151+{
16152+ pud_populate(mm, pudp, pmd);
16153+}
16154 #else /* !CONFIG_X86_PAE */
16155 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16156 {
16157 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16158 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
16159 }
16160+
16161+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16162+{
16163+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16164+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
16165+}
16166 #endif /* CONFIG_X86_PAE */
16167
16168 #if PAGETABLE_LEVELS > 3
16169@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16170 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
16171 }
16172
16173+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16174+{
16175+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
16176+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
16177+}
16178+
16179 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
16180 {
16181 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
16182diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
16183index 3bf2dd0..23d2a9f 100644
16184--- a/arch/x86/include/asm/pgtable-2level.h
16185+++ b/arch/x86/include/asm/pgtable-2level.h
16186@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
16187
16188 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16189 {
16190+ pax_open_kernel();
16191 *pmdp = pmd;
16192+ pax_close_kernel();
16193 }
16194
16195 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16196diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
16197index 81bb91b..9392125 100644
16198--- a/arch/x86/include/asm/pgtable-3level.h
16199+++ b/arch/x86/include/asm/pgtable-3level.h
16200@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16201
16202 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16203 {
16204+ pax_open_kernel();
16205 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
16206+ pax_close_kernel();
16207 }
16208
16209 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16210 {
16211+ pax_open_kernel();
16212 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
16213+ pax_close_kernel();
16214 }
16215
16216 /*
16217diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
16218index 1c00631..845f898 100644
16219--- a/arch/x86/include/asm/pgtable.h
16220+++ b/arch/x86/include/asm/pgtable.h
16221@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
16222
16223 #ifndef __PAGETABLE_PUD_FOLDED
16224 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
16225+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
16226 #define pgd_clear(pgd) native_pgd_clear(pgd)
16227 #endif
16228
16229@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
16230
16231 #define arch_end_context_switch(prev) do {} while(0)
16232
16233+#define pax_open_kernel() native_pax_open_kernel()
16234+#define pax_close_kernel() native_pax_close_kernel()
16235 #endif /* CONFIG_PARAVIRT */
16236
16237+#define __HAVE_ARCH_PAX_OPEN_KERNEL
16238+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
16239+
16240+#ifdef CONFIG_PAX_KERNEXEC
16241+static inline unsigned long native_pax_open_kernel(void)
16242+{
16243+ unsigned long cr0;
16244+
16245+ preempt_disable();
16246+ barrier();
16247+ cr0 = read_cr0() ^ X86_CR0_WP;
16248+ BUG_ON(cr0 & X86_CR0_WP);
16249+ write_cr0(cr0);
16250+ return cr0 ^ X86_CR0_WP;
16251+}
16252+
16253+static inline unsigned long native_pax_close_kernel(void)
16254+{
16255+ unsigned long cr0;
16256+
16257+ cr0 = read_cr0() ^ X86_CR0_WP;
16258+ BUG_ON(!(cr0 & X86_CR0_WP));
16259+ write_cr0(cr0);
16260+ barrier();
16261+ preempt_enable_no_resched();
16262+ return cr0 ^ X86_CR0_WP;
16263+}
16264+#else
16265+static inline unsigned long native_pax_open_kernel(void) { return 0; }
16266+static inline unsigned long native_pax_close_kernel(void) { return 0; }
16267+#endif
16268+
16269 /*
16270 * The following only work if pte_present() is true.
16271 * Undefined behaviour if not..
16272 */
16273+static inline int pte_user(pte_t pte)
16274+{
16275+ return pte_val(pte) & _PAGE_USER;
16276+}
16277+
16278 static inline int pte_dirty(pte_t pte)
16279 {
16280 return pte_flags(pte) & _PAGE_DIRTY;
16281@@ -147,6 +187,11 @@ static inline unsigned long pud_pfn(pud_t pud)
16282 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
16283 }
16284
16285+static inline unsigned long pgd_pfn(pgd_t pgd)
16286+{
16287+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
16288+}
16289+
16290 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
16291
16292 static inline int pmd_large(pmd_t pte)
16293@@ -200,9 +245,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
16294 return pte_clear_flags(pte, _PAGE_RW);
16295 }
16296
16297+static inline pte_t pte_mkread(pte_t pte)
16298+{
16299+ return __pte(pte_val(pte) | _PAGE_USER);
16300+}
16301+
16302 static inline pte_t pte_mkexec(pte_t pte)
16303 {
16304- return pte_clear_flags(pte, _PAGE_NX);
16305+#ifdef CONFIG_X86_PAE
16306+ if (__supported_pte_mask & _PAGE_NX)
16307+ return pte_clear_flags(pte, _PAGE_NX);
16308+ else
16309+#endif
16310+ return pte_set_flags(pte, _PAGE_USER);
16311+}
16312+
16313+static inline pte_t pte_exprotect(pte_t pte)
16314+{
16315+#ifdef CONFIG_X86_PAE
16316+ if (__supported_pte_mask & _PAGE_NX)
16317+ return pte_set_flags(pte, _PAGE_NX);
16318+ else
16319+#endif
16320+ return pte_clear_flags(pte, _PAGE_USER);
16321 }
16322
16323 static inline pte_t pte_mkdirty(pte_t pte)
16324@@ -444,6 +509,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
16325 #endif
16326
16327 #ifndef __ASSEMBLY__
16328+
16329+#ifdef CONFIG_PAX_PER_CPU_PGD
16330+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
16331+enum cpu_pgd_type {kernel = 0, user = 1};
16332+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
16333+{
16334+ return cpu_pgd[cpu][type];
16335+}
16336+#endif
16337+
16338 #include <linux/mm_types.h>
16339 #include <linux/log2.h>
16340
16341@@ -576,7 +651,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
16342 * Currently stuck as a macro due to indirect forward reference to
16343 * linux/mmzone.h's __section_mem_map_addr() definition:
16344 */
16345-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
16346+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
16347
16348 /* Find an entry in the second-level page table.. */
16349 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
16350@@ -616,7 +691,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
16351 * Currently stuck as a macro due to indirect forward reference to
16352 * linux/mmzone.h's __section_mem_map_addr() definition:
16353 */
16354-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
16355+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
16356
16357 /* to find an entry in a page-table-directory. */
16358 static inline unsigned long pud_index(unsigned long address)
16359@@ -631,7 +706,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
16360
16361 static inline int pgd_bad(pgd_t pgd)
16362 {
16363- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
16364+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
16365 }
16366
16367 static inline int pgd_none(pgd_t pgd)
16368@@ -654,7 +729,12 @@ static inline int pgd_none(pgd_t pgd)
16369 * pgd_offset() returns a (pgd_t *)
16370 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
16371 */
16372-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
16373+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
16374+
16375+#ifdef CONFIG_PAX_PER_CPU_PGD
16376+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
16377+#endif
16378+
16379 /*
16380 * a shortcut which implies the use of the kernel's pgd, instead
16381 * of a process's
16382@@ -665,6 +745,23 @@ static inline int pgd_none(pgd_t pgd)
16383 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
16384 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
16385
16386+#ifdef CONFIG_X86_32
16387+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
16388+#else
16389+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
16390+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
16391+
16392+#ifdef CONFIG_PAX_MEMORY_UDEREF
16393+#ifdef __ASSEMBLY__
16394+#define pax_user_shadow_base pax_user_shadow_base(%rip)
16395+#else
16396+extern unsigned long pax_user_shadow_base;
16397+extern pgdval_t clone_pgd_mask;
16398+#endif
16399+#endif
16400+
16401+#endif
16402+
16403 #ifndef __ASSEMBLY__
16404
16405 extern int direct_gbpages;
16406@@ -831,11 +928,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
16407 * dst and src can be on the same page, but the range must not overlap,
16408 * and must not cross a page boundary.
16409 */
16410-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
16411+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
16412 {
16413- memcpy(dst, src, count * sizeof(pgd_t));
16414+ pax_open_kernel();
16415+ while (count--)
16416+ *dst++ = *src++;
16417+ pax_close_kernel();
16418 }
16419
16420+#ifdef CONFIG_PAX_PER_CPU_PGD
16421+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
16422+#endif
16423+
16424+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16425+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
16426+#else
16427+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
16428+#endif
16429+
16430 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
16431 static inline int page_level_shift(enum pg_level level)
16432 {
16433diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
16434index 9ee3221..b979c6b 100644
16435--- a/arch/x86/include/asm/pgtable_32.h
16436+++ b/arch/x86/include/asm/pgtable_32.h
16437@@ -25,9 +25,6 @@
16438 struct mm_struct;
16439 struct vm_area_struct;
16440
16441-extern pgd_t swapper_pg_dir[1024];
16442-extern pgd_t initial_page_table[1024];
16443-
16444 static inline void pgtable_cache_init(void) { }
16445 static inline void check_pgt_cache(void) { }
16446 void paging_init(void);
16447@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
16448 # include <asm/pgtable-2level.h>
16449 #endif
16450
16451+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
16452+extern pgd_t initial_page_table[PTRS_PER_PGD];
16453+#ifdef CONFIG_X86_PAE
16454+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
16455+#endif
16456+
16457 #if defined(CONFIG_HIGHPTE)
16458 #define pte_offset_map(dir, address) \
16459 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
16460@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
16461 /* Clear a kernel PTE and flush it from the TLB */
16462 #define kpte_clear_flush(ptep, vaddr) \
16463 do { \
16464+ pax_open_kernel(); \
16465 pte_clear(&init_mm, (vaddr), (ptep)); \
16466+ pax_close_kernel(); \
16467 __flush_tlb_one((vaddr)); \
16468 } while (0)
16469
16470 #endif /* !__ASSEMBLY__ */
16471
16472+#define HAVE_ARCH_UNMAPPED_AREA
16473+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
16474+
16475 /*
16476 * kern_addr_valid() is (1) for FLATMEM and (0) for
16477 * SPARSEMEM and DISCONTIGMEM
16478diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
16479index ed5903b..c7fe163 100644
16480--- a/arch/x86/include/asm/pgtable_32_types.h
16481+++ b/arch/x86/include/asm/pgtable_32_types.h
16482@@ -8,7 +8,7 @@
16483 */
16484 #ifdef CONFIG_X86_PAE
16485 # include <asm/pgtable-3level_types.h>
16486-# define PMD_SIZE (1UL << PMD_SHIFT)
16487+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
16488 # define PMD_MASK (~(PMD_SIZE - 1))
16489 #else
16490 # include <asm/pgtable-2level_types.h>
16491@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
16492 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
16493 #endif
16494
16495+#ifdef CONFIG_PAX_KERNEXEC
16496+#ifndef __ASSEMBLY__
16497+extern unsigned char MODULES_EXEC_VADDR[];
16498+extern unsigned char MODULES_EXEC_END[];
16499+#endif
16500+#include <asm/boot.h>
16501+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
16502+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
16503+#else
16504+#define ktla_ktva(addr) (addr)
16505+#define ktva_ktla(addr) (addr)
16506+#endif
16507+
16508 #define MODULES_VADDR VMALLOC_START
16509 #define MODULES_END VMALLOC_END
16510 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
16511diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
16512index e22c1db..23a625a 100644
16513--- a/arch/x86/include/asm/pgtable_64.h
16514+++ b/arch/x86/include/asm/pgtable_64.h
16515@@ -16,10 +16,14 @@
16516
16517 extern pud_t level3_kernel_pgt[512];
16518 extern pud_t level3_ident_pgt[512];
16519+extern pud_t level3_vmalloc_start_pgt[512];
16520+extern pud_t level3_vmalloc_end_pgt[512];
16521+extern pud_t level3_vmemmap_pgt[512];
16522+extern pud_t level2_vmemmap_pgt[512];
16523 extern pmd_t level2_kernel_pgt[512];
16524 extern pmd_t level2_fixmap_pgt[512];
16525-extern pmd_t level2_ident_pgt[512];
16526-extern pgd_t init_level4_pgt[];
16527+extern pmd_t level2_ident_pgt[512*2];
16528+extern pgd_t init_level4_pgt[512];
16529
16530 #define swapper_pg_dir init_level4_pgt
16531
16532@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16533
16534 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16535 {
16536+ pax_open_kernel();
16537 *pmdp = pmd;
16538+ pax_close_kernel();
16539 }
16540
16541 static inline void native_pmd_clear(pmd_t *pmd)
16542@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
16543
16544 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16545 {
16546+ pax_open_kernel();
16547 *pudp = pud;
16548+ pax_close_kernel();
16549 }
16550
16551 static inline void native_pud_clear(pud_t *pud)
16552@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
16553
16554 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
16555 {
16556+ pax_open_kernel();
16557+ *pgdp = pgd;
16558+ pax_close_kernel();
16559+}
16560+
16561+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16562+{
16563 *pgdp = pgd;
16564 }
16565
16566diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
16567index 2d88344..4679fc3 100644
16568--- a/arch/x86/include/asm/pgtable_64_types.h
16569+++ b/arch/x86/include/asm/pgtable_64_types.h
16570@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
16571 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
16572 #define MODULES_END _AC(0xffffffffff000000, UL)
16573 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
16574+#define MODULES_EXEC_VADDR MODULES_VADDR
16575+#define MODULES_EXEC_END MODULES_END
16576+
16577+#define ktla_ktva(addr) (addr)
16578+#define ktva_ktla(addr) (addr)
16579
16580 #define EARLY_DYNAMIC_PAGE_TABLES 64
16581
16582diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
16583index f4843e0..a2526f8 100644
16584--- a/arch/x86/include/asm/pgtable_types.h
16585+++ b/arch/x86/include/asm/pgtable_types.h
16586@@ -16,13 +16,12 @@
16587 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
16588 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
16589 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
16590-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
16591+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
16592 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
16593 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
16594 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
16595-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
16596-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
16597-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
16598+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
16599+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
16600 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
16601
16602 /* If _PAGE_BIT_PRESENT is clear, we use these: */
16603@@ -40,7 +39,6 @@
16604 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
16605 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
16606 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
16607-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
16608 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
16609 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
16610 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
16611@@ -84,8 +82,10 @@
16612
16613 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
16614 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
16615-#else
16616+#elif defined(CONFIG_KMEMCHECK)
16617 #define _PAGE_NX (_AT(pteval_t, 0))
16618+#else
16619+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
16620 #endif
16621
16622 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
16623@@ -143,6 +143,9 @@
16624 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
16625 _PAGE_ACCESSED)
16626
16627+#define PAGE_READONLY_NOEXEC PAGE_READONLY
16628+#define PAGE_SHARED_NOEXEC PAGE_SHARED
16629+
16630 #define __PAGE_KERNEL_EXEC \
16631 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
16632 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
16633@@ -153,7 +156,7 @@
16634 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
16635 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
16636 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
16637-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
16638+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
16639 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
16640 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
16641 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
16642@@ -215,8 +218,8 @@
16643 * bits are combined, this will alow user to access the high address mapped
16644 * VDSO in the presence of CONFIG_COMPAT_VDSO
16645 */
16646-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
16647-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
16648+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
16649+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
16650 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
16651 #endif
16652
16653@@ -254,7 +257,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
16654 {
16655 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
16656 }
16657+#endif
16658
16659+#if PAGETABLE_LEVELS == 3
16660+#include <asm-generic/pgtable-nopud.h>
16661+#endif
16662+
16663+#if PAGETABLE_LEVELS == 2
16664+#include <asm-generic/pgtable-nopmd.h>
16665+#endif
16666+
16667+#ifndef __ASSEMBLY__
16668 #if PAGETABLE_LEVELS > 3
16669 typedef struct { pudval_t pud; } pud_t;
16670
16671@@ -268,8 +281,6 @@ static inline pudval_t native_pud_val(pud_t pud)
16672 return pud.pud;
16673 }
16674 #else
16675-#include <asm-generic/pgtable-nopud.h>
16676-
16677 static inline pudval_t native_pud_val(pud_t pud)
16678 {
16679 return native_pgd_val(pud.pgd);
16680@@ -289,8 +300,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
16681 return pmd.pmd;
16682 }
16683 #else
16684-#include <asm-generic/pgtable-nopmd.h>
16685-
16686 static inline pmdval_t native_pmd_val(pmd_t pmd)
16687 {
16688 return native_pgd_val(pmd.pud.pgd);
16689@@ -330,7 +339,6 @@ typedef struct page *pgtable_t;
16690
16691 extern pteval_t __supported_pte_mask;
16692 extern void set_nx(void);
16693-extern int nx_enabled;
16694
16695 #define pgprot_writecombine pgprot_writecombine
16696 extern pgprot_t pgprot_writecombine(pgprot_t prot);
16697diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
16698index 24cf5ae..4d9fa2d 100644
16699--- a/arch/x86/include/asm/processor.h
16700+++ b/arch/x86/include/asm/processor.h
16701@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
16702 : "memory");
16703 }
16704
16705+/* invpcid (%rdx),%rax */
16706+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
16707+
16708+#define INVPCID_SINGLE_ADDRESS 0UL
16709+#define INVPCID_SINGLE_CONTEXT 1UL
16710+#define INVPCID_ALL_GLOBAL 2UL
16711+#define INVPCID_ALL_MONGLOBAL 3UL
16712+
16713+#define PCID_KERNEL 0UL
16714+#define PCID_USER 1UL
16715+#define PCID_NOFLUSH (1UL << 63)
16716+
16717 static inline void load_cr3(pgd_t *pgdir)
16718 {
16719- write_cr3(__pa(pgdir));
16720+ write_cr3(__pa(pgdir) | PCID_KERNEL);
16721 }
16722
16723 #ifdef CONFIG_X86_32
16724@@ -283,7 +295,7 @@ struct tss_struct {
16725
16726 } ____cacheline_aligned;
16727
16728-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
16729+extern struct tss_struct init_tss[NR_CPUS];
16730
16731 /*
16732 * Save the original ist values for checking stack pointers during debugging
16733@@ -453,6 +465,7 @@ struct thread_struct {
16734 unsigned short ds;
16735 unsigned short fsindex;
16736 unsigned short gsindex;
16737+ unsigned short ss;
16738 #endif
16739 #ifdef CONFIG_X86_32
16740 unsigned long ip;
16741@@ -553,29 +566,8 @@ static inline void load_sp0(struct tss_struct *tss,
16742 extern unsigned long mmu_cr4_features;
16743 extern u32 *trampoline_cr4_features;
16744
16745-static inline void set_in_cr4(unsigned long mask)
16746-{
16747- unsigned long cr4;
16748-
16749- mmu_cr4_features |= mask;
16750- if (trampoline_cr4_features)
16751- *trampoline_cr4_features = mmu_cr4_features;
16752- cr4 = read_cr4();
16753- cr4 |= mask;
16754- write_cr4(cr4);
16755-}
16756-
16757-static inline void clear_in_cr4(unsigned long mask)
16758-{
16759- unsigned long cr4;
16760-
16761- mmu_cr4_features &= ~mask;
16762- if (trampoline_cr4_features)
16763- *trampoline_cr4_features = mmu_cr4_features;
16764- cr4 = read_cr4();
16765- cr4 &= ~mask;
16766- write_cr4(cr4);
16767-}
16768+extern void set_in_cr4(unsigned long mask);
16769+extern void clear_in_cr4(unsigned long mask);
16770
16771 typedef struct {
16772 unsigned long seg;
16773@@ -824,11 +816,18 @@ static inline void spin_lock_prefetch(const void *x)
16774 */
16775 #define TASK_SIZE PAGE_OFFSET
16776 #define TASK_SIZE_MAX TASK_SIZE
16777+
16778+#ifdef CONFIG_PAX_SEGMEXEC
16779+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
16780+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
16781+#else
16782 #define STACK_TOP TASK_SIZE
16783-#define STACK_TOP_MAX STACK_TOP
16784+#endif
16785+
16786+#define STACK_TOP_MAX TASK_SIZE
16787
16788 #define INIT_THREAD { \
16789- .sp0 = sizeof(init_stack) + (long)&init_stack, \
16790+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
16791 .vm86_info = NULL, \
16792 .sysenter_cs = __KERNEL_CS, \
16793 .io_bitmap_ptr = NULL, \
16794@@ -842,7 +841,7 @@ static inline void spin_lock_prefetch(const void *x)
16795 */
16796 #define INIT_TSS { \
16797 .x86_tss = { \
16798- .sp0 = sizeof(init_stack) + (long)&init_stack, \
16799+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
16800 .ss0 = __KERNEL_DS, \
16801 .ss1 = __KERNEL_CS, \
16802 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
16803@@ -853,11 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
16804 extern unsigned long thread_saved_pc(struct task_struct *tsk);
16805
16806 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
16807-#define KSTK_TOP(info) \
16808-({ \
16809- unsigned long *__ptr = (unsigned long *)(info); \
16810- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
16811-})
16812+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
16813
16814 /*
16815 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
16816@@ -872,7 +867,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16817 #define task_pt_regs(task) \
16818 ({ \
16819 struct pt_regs *__regs__; \
16820- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
16821+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
16822 __regs__ - 1; \
16823 })
16824
16825@@ -882,13 +877,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16826 /*
16827 * User space process size. 47bits minus one guard page.
16828 */
16829-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
16830+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
16831
16832 /* This decides where the kernel will search for a free chunk of vm
16833 * space during mmap's.
16834 */
16835 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
16836- 0xc0000000 : 0xFFFFe000)
16837+ 0xc0000000 : 0xFFFFf000)
16838
16839 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
16840 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
16841@@ -899,11 +894,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16842 #define STACK_TOP_MAX TASK_SIZE_MAX
16843
16844 #define INIT_THREAD { \
16845- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
16846+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
16847 }
16848
16849 #define INIT_TSS { \
16850- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
16851+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
16852 }
16853
16854 /*
16855@@ -931,6 +926,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
16856 */
16857 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
16858
16859+#ifdef CONFIG_PAX_SEGMEXEC
16860+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
16861+#endif
16862+
16863 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
16864
16865 /* Get/set a process' ability to use the timestamp counter instruction */
16866@@ -943,7 +942,8 @@ extern int set_tsc_mode(unsigned int val);
16867 extern u16 amd_get_nb_id(int cpu);
16868
16869 struct aperfmperf {
16870- u64 aperf, mperf;
16871+ u64 aperf __intentional_overflow(0);
16872+ u64 mperf __intentional_overflow(0);
16873 };
16874
16875 static inline void get_aperfmperf(struct aperfmperf *am)
16876@@ -971,7 +971,7 @@ unsigned long calc_aperfmperf_ratio(struct aperfmperf *old,
16877 return ratio;
16878 }
16879
16880-extern unsigned long arch_align_stack(unsigned long sp);
16881+#define arch_align_stack(x) ((x) & ~0xfUL)
16882 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
16883
16884 void default_idle(void);
16885@@ -981,6 +981,6 @@ bool xen_set_default_idle(void);
16886 #define xen_set_default_idle 0
16887 #endif
16888
16889-void stop_this_cpu(void *dummy);
16890+void stop_this_cpu(void *dummy) __noreturn;
16891 void df_debug(struct pt_regs *regs, long error_code);
16892 #endif /* _ASM_X86_PROCESSOR_H */
16893diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
16894index 942a086..6c26446 100644
16895--- a/arch/x86/include/asm/ptrace.h
16896+++ b/arch/x86/include/asm/ptrace.h
16897@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
16898 }
16899
16900 /*
16901- * user_mode_vm(regs) determines whether a register set came from user mode.
16902+ * user_mode(regs) determines whether a register set came from user mode.
16903 * This is true if V8086 mode was enabled OR if the register set was from
16904 * protected mode with RPL-3 CS value. This tricky test checks that with
16905 * one comparison. Many places in the kernel can bypass this full check
16906- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
16907+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
16908+ * be used.
16909 */
16910-static inline int user_mode(struct pt_regs *regs)
16911+static inline int user_mode_novm(struct pt_regs *regs)
16912 {
16913 #ifdef CONFIG_X86_32
16914 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
16915 #else
16916- return !!(regs->cs & 3);
16917+ return !!(regs->cs & SEGMENT_RPL_MASK);
16918 #endif
16919 }
16920
16921-static inline int user_mode_vm(struct pt_regs *regs)
16922+static inline int user_mode(struct pt_regs *regs)
16923 {
16924 #ifdef CONFIG_X86_32
16925 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
16926 USER_RPL;
16927 #else
16928- return user_mode(regs);
16929+ return user_mode_novm(regs);
16930 #endif
16931 }
16932
16933@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
16934 #ifdef CONFIG_X86_64
16935 static inline bool user_64bit_mode(struct pt_regs *regs)
16936 {
16937+ unsigned long cs = regs->cs & 0xffff;
16938 #ifndef CONFIG_PARAVIRT
16939 /*
16940 * On non-paravirt systems, this is the only long mode CPL 3
16941 * selector. We do not allow long mode selectors in the LDT.
16942 */
16943- return regs->cs == __USER_CS;
16944+ return cs == __USER_CS;
16945 #else
16946 /* Headers are too twisted for this to go in paravirt.h. */
16947- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
16948+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
16949 #endif
16950 }
16951
16952@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
16953 * Traps from the kernel do not save sp and ss.
16954 * Use the helper function to retrieve sp.
16955 */
16956- if (offset == offsetof(struct pt_regs, sp) &&
16957- regs->cs == __KERNEL_CS)
16958- return kernel_stack_pointer(regs);
16959+ if (offset == offsetof(struct pt_regs, sp)) {
16960+ unsigned long cs = regs->cs & 0xffff;
16961+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
16962+ return kernel_stack_pointer(regs);
16963+ }
16964 #endif
16965 return *(unsigned long *)((unsigned long)regs + offset);
16966 }
16967diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
16968index 9c6b890..5305f53 100644
16969--- a/arch/x86/include/asm/realmode.h
16970+++ b/arch/x86/include/asm/realmode.h
16971@@ -22,16 +22,14 @@ struct real_mode_header {
16972 #endif
16973 /* APM/BIOS reboot */
16974 u32 machine_real_restart_asm;
16975-#ifdef CONFIG_X86_64
16976 u32 machine_real_restart_seg;
16977-#endif
16978 };
16979
16980 /* This must match data at trampoline_32/64.S */
16981 struct trampoline_header {
16982 #ifdef CONFIG_X86_32
16983 u32 start;
16984- u16 gdt_pad;
16985+ u16 boot_cs;
16986 u16 gdt_limit;
16987 u32 gdt_base;
16988 #else
16989diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
16990index a82c4f1..ac45053 100644
16991--- a/arch/x86/include/asm/reboot.h
16992+++ b/arch/x86/include/asm/reboot.h
16993@@ -6,13 +6,13 @@
16994 struct pt_regs;
16995
16996 struct machine_ops {
16997- void (*restart)(char *cmd);
16998- void (*halt)(void);
16999- void (*power_off)(void);
17000+ void (* __noreturn restart)(char *cmd);
17001+ void (* __noreturn halt)(void);
17002+ void (* __noreturn power_off)(void);
17003 void (*shutdown)(void);
17004 void (*crash_shutdown)(struct pt_regs *);
17005- void (*emergency_restart)(void);
17006-};
17007+ void (* __noreturn emergency_restart)(void);
17008+} __no_const;
17009
17010 extern struct machine_ops machine_ops;
17011
17012diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
17013index cad82c9..2e5c5c1 100644
17014--- a/arch/x86/include/asm/rwsem.h
17015+++ b/arch/x86/include/asm/rwsem.h
17016@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
17017 {
17018 asm volatile("# beginning down_read\n\t"
17019 LOCK_PREFIX _ASM_INC "(%1)\n\t"
17020+
17021+#ifdef CONFIG_PAX_REFCOUNT
17022+ "jno 0f\n"
17023+ LOCK_PREFIX _ASM_DEC "(%1)\n"
17024+ "int $4\n0:\n"
17025+ _ASM_EXTABLE(0b, 0b)
17026+#endif
17027+
17028 /* adds 0x00000001 */
17029 " jns 1f\n"
17030 " call call_rwsem_down_read_failed\n"
17031@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
17032 "1:\n\t"
17033 " mov %1,%2\n\t"
17034 " add %3,%2\n\t"
17035+
17036+#ifdef CONFIG_PAX_REFCOUNT
17037+ "jno 0f\n"
17038+ "sub %3,%2\n"
17039+ "int $4\n0:\n"
17040+ _ASM_EXTABLE(0b, 0b)
17041+#endif
17042+
17043 " jle 2f\n\t"
17044 LOCK_PREFIX " cmpxchg %2,%0\n\t"
17045 " jnz 1b\n\t"
17046@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
17047 long tmp;
17048 asm volatile("# beginning down_write\n\t"
17049 LOCK_PREFIX " xadd %1,(%2)\n\t"
17050+
17051+#ifdef CONFIG_PAX_REFCOUNT
17052+ "jno 0f\n"
17053+ "mov %1,(%2)\n"
17054+ "int $4\n0:\n"
17055+ _ASM_EXTABLE(0b, 0b)
17056+#endif
17057+
17058 /* adds 0xffff0001, returns the old value */
17059 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
17060 /* was the active mask 0 before? */
17061@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
17062 long tmp;
17063 asm volatile("# beginning __up_read\n\t"
17064 LOCK_PREFIX " xadd %1,(%2)\n\t"
17065+
17066+#ifdef CONFIG_PAX_REFCOUNT
17067+ "jno 0f\n"
17068+ "mov %1,(%2)\n"
17069+ "int $4\n0:\n"
17070+ _ASM_EXTABLE(0b, 0b)
17071+#endif
17072+
17073 /* subtracts 1, returns the old value */
17074 " jns 1f\n\t"
17075 " call call_rwsem_wake\n" /* expects old value in %edx */
17076@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
17077 long tmp;
17078 asm volatile("# beginning __up_write\n\t"
17079 LOCK_PREFIX " xadd %1,(%2)\n\t"
17080+
17081+#ifdef CONFIG_PAX_REFCOUNT
17082+ "jno 0f\n"
17083+ "mov %1,(%2)\n"
17084+ "int $4\n0:\n"
17085+ _ASM_EXTABLE(0b, 0b)
17086+#endif
17087+
17088 /* subtracts 0xffff0001, returns the old value */
17089 " jns 1f\n\t"
17090 " call call_rwsem_wake\n" /* expects old value in %edx */
17091@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17092 {
17093 asm volatile("# beginning __downgrade_write\n\t"
17094 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
17095+
17096+#ifdef CONFIG_PAX_REFCOUNT
17097+ "jno 0f\n"
17098+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
17099+ "int $4\n0:\n"
17100+ _ASM_EXTABLE(0b, 0b)
17101+#endif
17102+
17103 /*
17104 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
17105 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
17106@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17107 */
17108 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17109 {
17110- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
17111+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
17112+
17113+#ifdef CONFIG_PAX_REFCOUNT
17114+ "jno 0f\n"
17115+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
17116+ "int $4\n0:\n"
17117+ _ASM_EXTABLE(0b, 0b)
17118+#endif
17119+
17120 : "+m" (sem->count)
17121 : "er" (delta));
17122 }
17123@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17124 */
17125 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
17126 {
17127- return delta + xadd(&sem->count, delta);
17128+ return delta + xadd_check_overflow(&sem->count, delta);
17129 }
17130
17131 #endif /* __KERNEL__ */
17132diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
17133index c48a950..bc40804 100644
17134--- a/arch/x86/include/asm/segment.h
17135+++ b/arch/x86/include/asm/segment.h
17136@@ -64,10 +64,15 @@
17137 * 26 - ESPFIX small SS
17138 * 27 - per-cpu [ offset to per-cpu data area ]
17139 * 28 - stack_canary-20 [ for stack protector ]
17140- * 29 - unused
17141- * 30 - unused
17142+ * 29 - PCI BIOS CS
17143+ * 30 - PCI BIOS DS
17144 * 31 - TSS for double fault handler
17145 */
17146+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
17147+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
17148+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
17149+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
17150+
17151 #define GDT_ENTRY_TLS_MIN 6
17152 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
17153
17154@@ -79,6 +84,8 @@
17155
17156 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
17157
17158+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
17159+
17160 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
17161
17162 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
17163@@ -104,6 +111,12 @@
17164 #define __KERNEL_STACK_CANARY 0
17165 #endif
17166
17167+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
17168+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
17169+
17170+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
17171+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
17172+
17173 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
17174
17175 /*
17176@@ -141,7 +154,7 @@
17177 */
17178
17179 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
17180-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
17181+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
17182
17183
17184 #else
17185@@ -165,6 +178,8 @@
17186 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
17187 #define __USER32_DS __USER_DS
17188
17189+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
17190+
17191 #define GDT_ENTRY_TSS 8 /* needs two entries */
17192 #define GDT_ENTRY_LDT 10 /* needs two entries */
17193 #define GDT_ENTRY_TLS_MIN 12
17194@@ -173,6 +188,8 @@
17195 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
17196 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
17197
17198+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
17199+
17200 /* TLS indexes for 64bit - hardcoded in arch_prctl */
17201 #define FS_TLS 0
17202 #define GS_TLS 1
17203@@ -180,12 +197,14 @@
17204 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
17205 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
17206
17207-#define GDT_ENTRIES 16
17208+#define GDT_ENTRIES 17
17209
17210 #endif
17211
17212 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
17213+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
17214 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
17215+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
17216 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
17217 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
17218 #ifndef CONFIG_PARAVIRT
17219@@ -265,7 +284,7 @@ static inline unsigned long get_limit(unsigned long segment)
17220 {
17221 unsigned long __limit;
17222 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
17223- return __limit + 1;
17224+ return __limit;
17225 }
17226
17227 #endif /* !__ASSEMBLY__ */
17228diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
17229index 8d3120f..352b440 100644
17230--- a/arch/x86/include/asm/smap.h
17231+++ b/arch/x86/include/asm/smap.h
17232@@ -25,11 +25,40 @@
17233
17234 #include <asm/alternative-asm.h>
17235
17236+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17237+#define ASM_PAX_OPEN_USERLAND \
17238+ 661: jmp 663f; \
17239+ .pushsection .altinstr_replacement, "a" ; \
17240+ 662: pushq %rax; nop; \
17241+ .popsection ; \
17242+ .pushsection .altinstructions, "a" ; \
17243+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
17244+ .popsection ; \
17245+ call __pax_open_userland; \
17246+ popq %rax; \
17247+ 663:
17248+
17249+#define ASM_PAX_CLOSE_USERLAND \
17250+ 661: jmp 663f; \
17251+ .pushsection .altinstr_replacement, "a" ; \
17252+ 662: pushq %rax; nop; \
17253+ .popsection; \
17254+ .pushsection .altinstructions, "a" ; \
17255+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
17256+ .popsection; \
17257+ call __pax_close_userland; \
17258+ popq %rax; \
17259+ 663:
17260+#else
17261+#define ASM_PAX_OPEN_USERLAND
17262+#define ASM_PAX_CLOSE_USERLAND
17263+#endif
17264+
17265 #ifdef CONFIG_X86_SMAP
17266
17267 #define ASM_CLAC \
17268 661: ASM_NOP3 ; \
17269- .pushsection .altinstr_replacement, "ax" ; \
17270+ .pushsection .altinstr_replacement, "a" ; \
17271 662: __ASM_CLAC ; \
17272 .popsection ; \
17273 .pushsection .altinstructions, "a" ; \
17274@@ -38,7 +67,7 @@
17275
17276 #define ASM_STAC \
17277 661: ASM_NOP3 ; \
17278- .pushsection .altinstr_replacement, "ax" ; \
17279+ .pushsection .altinstr_replacement, "a" ; \
17280 662: __ASM_STAC ; \
17281 .popsection ; \
17282 .pushsection .altinstructions, "a" ; \
17283@@ -56,6 +85,37 @@
17284
17285 #include <asm/alternative.h>
17286
17287+#define __HAVE_ARCH_PAX_OPEN_USERLAND
17288+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
17289+
17290+extern void __pax_open_userland(void);
17291+static __always_inline unsigned long pax_open_userland(void)
17292+{
17293+
17294+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17295+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
17296+ :
17297+ : [open] "i" (__pax_open_userland)
17298+ : "memory", "rax");
17299+#endif
17300+
17301+ return 0;
17302+}
17303+
17304+extern void __pax_close_userland(void);
17305+static __always_inline unsigned long pax_close_userland(void)
17306+{
17307+
17308+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17309+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
17310+ :
17311+ : [close] "i" (__pax_close_userland)
17312+ : "memory", "rax");
17313+#endif
17314+
17315+ return 0;
17316+}
17317+
17318 #ifdef CONFIG_X86_SMAP
17319
17320 static __always_inline void clac(void)
17321diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
17322index 4137890..03fa172 100644
17323--- a/arch/x86/include/asm/smp.h
17324+++ b/arch/x86/include/asm/smp.h
17325@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
17326 /* cpus sharing the last level cache: */
17327 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
17328 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
17329-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
17330+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
17331
17332 static inline struct cpumask *cpu_sibling_mask(int cpu)
17333 {
17334@@ -79,7 +79,7 @@ struct smp_ops {
17335
17336 void (*send_call_func_ipi)(const struct cpumask *mask);
17337 void (*send_call_func_single_ipi)(int cpu);
17338-};
17339+} __no_const;
17340
17341 /* Globals due to paravirt */
17342 extern void set_cpu_sibling_map(int cpu);
17343@@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
17344 extern int safe_smp_processor_id(void);
17345
17346 #elif defined(CONFIG_X86_64_SMP)
17347-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
17348-
17349-#define stack_smp_processor_id() \
17350-({ \
17351- struct thread_info *ti; \
17352- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
17353- ti->cpu; \
17354-})
17355+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
17356+#define stack_smp_processor_id() raw_smp_processor_id()
17357 #define safe_smp_processor_id() smp_processor_id()
17358
17359 #endif
17360diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
17361index e3ddd7d..3611fce 100644
17362--- a/arch/x86/include/asm/spinlock.h
17363+++ b/arch/x86/include/asm/spinlock.h
17364@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
17365 static inline void arch_read_lock(arch_rwlock_t *rw)
17366 {
17367 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
17368+
17369+#ifdef CONFIG_PAX_REFCOUNT
17370+ "jno 0f\n"
17371+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
17372+ "int $4\n0:\n"
17373+ _ASM_EXTABLE(0b, 0b)
17374+#endif
17375+
17376 "jns 1f\n"
17377 "call __read_lock_failed\n\t"
17378 "1:\n"
17379@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
17380 static inline void arch_write_lock(arch_rwlock_t *rw)
17381 {
17382 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
17383+
17384+#ifdef CONFIG_PAX_REFCOUNT
17385+ "jno 0f\n"
17386+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
17387+ "int $4\n0:\n"
17388+ _ASM_EXTABLE(0b, 0b)
17389+#endif
17390+
17391 "jz 1f\n"
17392 "call __write_lock_failed\n\t"
17393 "1:\n"
17394@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
17395
17396 static inline void arch_read_unlock(arch_rwlock_t *rw)
17397 {
17398- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
17399+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
17400+
17401+#ifdef CONFIG_PAX_REFCOUNT
17402+ "jno 0f\n"
17403+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
17404+ "int $4\n0:\n"
17405+ _ASM_EXTABLE(0b, 0b)
17406+#endif
17407+
17408 :"+m" (rw->lock) : : "memory");
17409 }
17410
17411 static inline void arch_write_unlock(arch_rwlock_t *rw)
17412 {
17413- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
17414+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
17415+
17416+#ifdef CONFIG_PAX_REFCOUNT
17417+ "jno 0f\n"
17418+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
17419+ "int $4\n0:\n"
17420+ _ASM_EXTABLE(0b, 0b)
17421+#endif
17422+
17423 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
17424 }
17425
17426diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
17427index 6a99859..03cb807 100644
17428--- a/arch/x86/include/asm/stackprotector.h
17429+++ b/arch/x86/include/asm/stackprotector.h
17430@@ -47,7 +47,7 @@
17431 * head_32 for boot CPU and setup_per_cpu_areas() for others.
17432 */
17433 #define GDT_STACK_CANARY_INIT \
17434- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
17435+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
17436
17437 /*
17438 * Initialize the stackprotector canary value.
17439@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
17440
17441 static inline void load_stack_canary_segment(void)
17442 {
17443-#ifdef CONFIG_X86_32
17444+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
17445 asm volatile ("mov %0, %%gs" : : "r" (0));
17446 #endif
17447 }
17448diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
17449index 70bbe39..4ae2bd4 100644
17450--- a/arch/x86/include/asm/stacktrace.h
17451+++ b/arch/x86/include/asm/stacktrace.h
17452@@ -11,28 +11,20 @@
17453
17454 extern int kstack_depth_to_print;
17455
17456-struct thread_info;
17457+struct task_struct;
17458 struct stacktrace_ops;
17459
17460-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
17461- unsigned long *stack,
17462- unsigned long bp,
17463- const struct stacktrace_ops *ops,
17464- void *data,
17465- unsigned long *end,
17466- int *graph);
17467+typedef unsigned long walk_stack_t(struct task_struct *task,
17468+ void *stack_start,
17469+ unsigned long *stack,
17470+ unsigned long bp,
17471+ const struct stacktrace_ops *ops,
17472+ void *data,
17473+ unsigned long *end,
17474+ int *graph);
17475
17476-extern unsigned long
17477-print_context_stack(struct thread_info *tinfo,
17478- unsigned long *stack, unsigned long bp,
17479- const struct stacktrace_ops *ops, void *data,
17480- unsigned long *end, int *graph);
17481-
17482-extern unsigned long
17483-print_context_stack_bp(struct thread_info *tinfo,
17484- unsigned long *stack, unsigned long bp,
17485- const struct stacktrace_ops *ops, void *data,
17486- unsigned long *end, int *graph);
17487+extern walk_stack_t print_context_stack;
17488+extern walk_stack_t print_context_stack_bp;
17489
17490 /* Generic stack tracer with callbacks */
17491
17492@@ -40,7 +32,7 @@ struct stacktrace_ops {
17493 void (*address)(void *data, unsigned long address, int reliable);
17494 /* On negative return stop dumping */
17495 int (*stack)(void *data, char *name);
17496- walk_stack_t walk_stack;
17497+ walk_stack_t *walk_stack;
17498 };
17499
17500 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
17501diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
17502index 4ec45b3..a4f0a8a 100644
17503--- a/arch/x86/include/asm/switch_to.h
17504+++ b/arch/x86/include/asm/switch_to.h
17505@@ -108,7 +108,7 @@ do { \
17506 "call __switch_to\n\t" \
17507 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
17508 __switch_canary \
17509- "movq %P[thread_info](%%rsi),%%r8\n\t" \
17510+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
17511 "movq %%rax,%%rdi\n\t" \
17512 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
17513 "jnz ret_from_fork\n\t" \
17514@@ -119,7 +119,7 @@ do { \
17515 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
17516 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
17517 [_tif_fork] "i" (_TIF_FORK), \
17518- [thread_info] "i" (offsetof(struct task_struct, stack)), \
17519+ [thread_info] "m" (current_tinfo), \
17520 [current_task] "m" (current_task) \
17521 __switch_canary_iparam \
17522 : "memory", "cc" __EXTRA_CLOBBER)
17523diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
17524index 2781119..618b59b 100644
17525--- a/arch/x86/include/asm/thread_info.h
17526+++ b/arch/x86/include/asm/thread_info.h
17527@@ -10,6 +10,7 @@
17528 #include <linux/compiler.h>
17529 #include <asm/page.h>
17530 #include <asm/types.h>
17531+#include <asm/percpu.h>
17532
17533 /*
17534 * low level task data that entry.S needs immediate access to
17535@@ -23,7 +24,6 @@ struct exec_domain;
17536 #include <linux/atomic.h>
17537
17538 struct thread_info {
17539- struct task_struct *task; /* main task structure */
17540 struct exec_domain *exec_domain; /* execution domain */
17541 __u32 flags; /* low level flags */
17542 __u32 status; /* thread synchronous flags */
17543@@ -33,19 +33,13 @@ struct thread_info {
17544 mm_segment_t addr_limit;
17545 struct restart_block restart_block;
17546 void __user *sysenter_return;
17547-#ifdef CONFIG_X86_32
17548- unsigned long previous_esp; /* ESP of the previous stack in
17549- case of nested (IRQ) stacks
17550- */
17551- __u8 supervisor_stack[0];
17552-#endif
17553+ unsigned long lowest_stack;
17554 unsigned int sig_on_uaccess_error:1;
17555 unsigned int uaccess_err:1; /* uaccess failed */
17556 };
17557
17558-#define INIT_THREAD_INFO(tsk) \
17559+#define INIT_THREAD_INFO \
17560 { \
17561- .task = &tsk, \
17562 .exec_domain = &default_exec_domain, \
17563 .flags = 0, \
17564 .cpu = 0, \
17565@@ -56,7 +50,7 @@ struct thread_info {
17566 }, \
17567 }
17568
17569-#define init_thread_info (init_thread_union.thread_info)
17570+#define init_thread_info (init_thread_union.stack)
17571 #define init_stack (init_thread_union.stack)
17572
17573 #else /* !__ASSEMBLY__ */
17574@@ -96,6 +90,7 @@ struct thread_info {
17575 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
17576 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
17577 #define TIF_X32 30 /* 32-bit native x86-64 binary */
17578+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
17579
17580 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
17581 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
17582@@ -119,17 +114,18 @@ struct thread_info {
17583 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
17584 #define _TIF_ADDR32 (1 << TIF_ADDR32)
17585 #define _TIF_X32 (1 << TIF_X32)
17586+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
17587
17588 /* work to do in syscall_trace_enter() */
17589 #define _TIF_WORK_SYSCALL_ENTRY \
17590 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
17591 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
17592- _TIF_NOHZ)
17593+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
17594
17595 /* work to do in syscall_trace_leave() */
17596 #define _TIF_WORK_SYSCALL_EXIT \
17597 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
17598- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
17599+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
17600
17601 /* work to do on interrupt/exception return */
17602 #define _TIF_WORK_MASK \
17603@@ -140,7 +136,7 @@ struct thread_info {
17604 /* work to do on any return to user space */
17605 #define _TIF_ALLWORK_MASK \
17606 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
17607- _TIF_NOHZ)
17608+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
17609
17610 /* Only used for 64 bit */
17611 #define _TIF_DO_NOTIFY_MASK \
17612@@ -156,45 +152,40 @@ struct thread_info {
17613
17614 #define PREEMPT_ACTIVE 0x10000000
17615
17616-#ifdef CONFIG_X86_32
17617-
17618-#define STACK_WARN (THREAD_SIZE/8)
17619-/*
17620- * macros/functions for gaining access to the thread information structure
17621- *
17622- * preempt_count needs to be 1 initially, until the scheduler is functional.
17623- */
17624-#ifndef __ASSEMBLY__
17625-
17626-
17627-/* how to get the current stack pointer from C */
17628-register unsigned long current_stack_pointer asm("esp") __used;
17629-
17630-/* how to get the thread information struct from C */
17631-static inline struct thread_info *current_thread_info(void)
17632-{
17633- return (struct thread_info *)
17634- (current_stack_pointer & ~(THREAD_SIZE - 1));
17635-}
17636-
17637-#else /* !__ASSEMBLY__ */
17638-
17639+#ifdef __ASSEMBLY__
17640 /* how to get the thread information struct from ASM */
17641 #define GET_THREAD_INFO(reg) \
17642- movl $-THREAD_SIZE, reg; \
17643- andl %esp, reg
17644+ mov PER_CPU_VAR(current_tinfo), reg
17645
17646 /* use this one if reg already contains %esp */
17647-#define GET_THREAD_INFO_WITH_ESP(reg) \
17648- andl $-THREAD_SIZE, reg
17649+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
17650+#else
17651+/* how to get the thread information struct from C */
17652+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
17653+
17654+static __always_inline struct thread_info *current_thread_info(void)
17655+{
17656+ return this_cpu_read_stable(current_tinfo);
17657+}
17658+#endif
17659+
17660+#ifdef CONFIG_X86_32
17661+
17662+#define STACK_WARN (THREAD_SIZE/8)
17663+/*
17664+ * macros/functions for gaining access to the thread information structure
17665+ *
17666+ * preempt_count needs to be 1 initially, until the scheduler is functional.
17667+ */
17668+#ifndef __ASSEMBLY__
17669+
17670+/* how to get the current stack pointer from C */
17671+register unsigned long current_stack_pointer asm("esp") __used;
17672
17673 #endif
17674
17675 #else /* X86_32 */
17676
17677-#include <asm/percpu.h>
17678-#define KERNEL_STACK_OFFSET (5*8)
17679-
17680 /*
17681 * macros/functions for gaining access to the thread information structure
17682 * preempt_count needs to be 1 initially, until the scheduler is functional.
17683@@ -202,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
17684 #ifndef __ASSEMBLY__
17685 DECLARE_PER_CPU(unsigned long, kernel_stack);
17686
17687-static inline struct thread_info *current_thread_info(void)
17688-{
17689- struct thread_info *ti;
17690- ti = (void *)(this_cpu_read_stable(kernel_stack) +
17691- KERNEL_STACK_OFFSET - THREAD_SIZE);
17692- return ti;
17693-}
17694-
17695-#else /* !__ASSEMBLY__ */
17696-
17697-/* how to get the thread information struct from ASM */
17698-#define GET_THREAD_INFO(reg) \
17699- movq PER_CPU_VAR(kernel_stack),reg ; \
17700- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
17701-
17702-/*
17703- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
17704- * a certain register (to be used in assembler memory operands).
17705- */
17706-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
17707-
17708+/* how to get the current stack pointer from C */
17709+register unsigned long current_stack_pointer asm("rsp") __used;
17710 #endif
17711
17712 #endif /* !X86_32 */
17713@@ -281,5 +253,12 @@ static inline bool is_ia32_task(void)
17714 extern void arch_task_cache_init(void);
17715 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
17716 extern void arch_release_task_struct(struct task_struct *tsk);
17717+
17718+#define __HAVE_THREAD_FUNCTIONS
17719+#define task_thread_info(task) (&(task)->tinfo)
17720+#define task_stack_page(task) ((task)->stack)
17721+#define setup_thread_stack(p, org) do {} while (0)
17722+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
17723+
17724 #endif
17725 #endif /* _ASM_X86_THREAD_INFO_H */
17726diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
17727index cf51200..63ff068 100644
17728--- a/arch/x86/include/asm/tlbflush.h
17729+++ b/arch/x86/include/asm/tlbflush.h
17730@@ -17,18 +17,44 @@
17731
17732 static inline void __native_flush_tlb(void)
17733 {
17734+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17735+ u64 descriptor[2];
17736+
17737+ descriptor[0] = PCID_KERNEL;
17738+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
17739+ return;
17740+ }
17741+
17742+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17743+ if (static_cpu_has(X86_FEATURE_PCID)) {
17744+ unsigned int cpu = raw_get_cpu();
17745+
17746+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17747+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17748+ raw_put_cpu_no_resched();
17749+ return;
17750+ }
17751+#endif
17752+
17753 native_write_cr3(native_read_cr3());
17754 }
17755
17756 static inline void __native_flush_tlb_global_irq_disabled(void)
17757 {
17758- unsigned long cr4;
17759+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17760+ u64 descriptor[2];
17761
17762- cr4 = native_read_cr4();
17763- /* clear PGE */
17764- native_write_cr4(cr4 & ~X86_CR4_PGE);
17765- /* write old PGE again and flush TLBs */
17766- native_write_cr4(cr4);
17767+ descriptor[0] = PCID_KERNEL;
17768+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
17769+ } else {
17770+ unsigned long cr4;
17771+
17772+ cr4 = native_read_cr4();
17773+ /* clear PGE */
17774+ native_write_cr4(cr4 & ~X86_CR4_PGE);
17775+ /* write old PGE again and flush TLBs */
17776+ native_write_cr4(cr4);
17777+ }
17778 }
17779
17780 static inline void __native_flush_tlb_global(void)
17781@@ -49,6 +75,42 @@ static inline void __native_flush_tlb_global(void)
17782
17783 static inline void __native_flush_tlb_single(unsigned long addr)
17784 {
17785+
17786+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17787+ u64 descriptor[2];
17788+
17789+ descriptor[0] = PCID_KERNEL;
17790+ descriptor[1] = addr;
17791+
17792+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17793+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
17794+ if (addr < TASK_SIZE_MAX)
17795+ descriptor[1] += pax_user_shadow_base;
17796+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
17797+ }
17798+
17799+ descriptor[0] = PCID_USER;
17800+ descriptor[1] = addr;
17801+#endif
17802+
17803+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
17804+ return;
17805+ }
17806+
17807+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17808+ if (static_cpu_has(X86_FEATURE_PCID)) {
17809+ unsigned int cpu = raw_get_cpu();
17810+
17811+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
17812+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
17813+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17814+ raw_put_cpu_no_resched();
17815+
17816+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
17817+ addr += pax_user_shadow_base;
17818+ }
17819+#endif
17820+
17821 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
17822 }
17823
17824diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
17825index 5ee2687..74590b9 100644
17826--- a/arch/x86/include/asm/uaccess.h
17827+++ b/arch/x86/include/asm/uaccess.h
17828@@ -7,6 +7,7 @@
17829 #include <linux/compiler.h>
17830 #include <linux/thread_info.h>
17831 #include <linux/string.h>
17832+#include <linux/sched.h>
17833 #include <asm/asm.h>
17834 #include <asm/page.h>
17835 #include <asm/smap.h>
17836@@ -29,7 +30,12 @@
17837
17838 #define get_ds() (KERNEL_DS)
17839 #define get_fs() (current_thread_info()->addr_limit)
17840+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
17841+void __set_fs(mm_segment_t x);
17842+void set_fs(mm_segment_t x);
17843+#else
17844 #define set_fs(x) (current_thread_info()->addr_limit = (x))
17845+#endif
17846
17847 #define segment_eq(a, b) ((a).seg == (b).seg)
17848
17849@@ -77,8 +83,33 @@
17850 * checks that the pointer is in the user space range - after calling
17851 * this function, memory access functions may still return -EFAULT.
17852 */
17853-#define access_ok(type, addr, size) \
17854- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
17855+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
17856+#define access_ok(type, addr, size) \
17857+({ \
17858+ long __size = size; \
17859+ unsigned long __addr = (unsigned long)addr; \
17860+ unsigned long __addr_ao = __addr & PAGE_MASK; \
17861+ unsigned long __end_ao = __addr + __size - 1; \
17862+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
17863+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
17864+ while(__addr_ao <= __end_ao) { \
17865+ char __c_ao; \
17866+ __addr_ao += PAGE_SIZE; \
17867+ if (__size > PAGE_SIZE) \
17868+ cond_resched(); \
17869+ if (__get_user(__c_ao, (char __user *)__addr)) \
17870+ break; \
17871+ if (type != VERIFY_WRITE) { \
17872+ __addr = __addr_ao; \
17873+ continue; \
17874+ } \
17875+ if (__put_user(__c_ao, (char __user *)__addr)) \
17876+ break; \
17877+ __addr = __addr_ao; \
17878+ } \
17879+ } \
17880+ __ret_ao; \
17881+})
17882
17883 /*
17884 * The exception table consists of pairs of addresses relative to the
17885@@ -165,10 +196,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17886 register __inttype(*(ptr)) __val_gu asm("%edx"); \
17887 __chk_user_ptr(ptr); \
17888 might_fault(); \
17889+ pax_open_userland(); \
17890 asm volatile("call __get_user_%P3" \
17891 : "=a" (__ret_gu), "=r" (__val_gu) \
17892 : "0" (ptr), "i" (sizeof(*(ptr)))); \
17893 (x) = (__typeof__(*(ptr))) __val_gu; \
17894+ pax_close_userland(); \
17895 __ret_gu; \
17896 })
17897
17898@@ -176,13 +209,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17899 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
17900 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
17901
17902-
17903+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
17904+#define __copyuser_seg "gs;"
17905+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
17906+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
17907+#else
17908+#define __copyuser_seg
17909+#define __COPYUSER_SET_ES
17910+#define __COPYUSER_RESTORE_ES
17911+#endif
17912
17913 #ifdef CONFIG_X86_32
17914 #define __put_user_asm_u64(x, addr, err, errret) \
17915 asm volatile(ASM_STAC "\n" \
17916- "1: movl %%eax,0(%2)\n" \
17917- "2: movl %%edx,4(%2)\n" \
17918+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
17919+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
17920 "3: " ASM_CLAC "\n" \
17921 ".section .fixup,\"ax\"\n" \
17922 "4: movl %3,%0\n" \
17923@@ -195,8 +236,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17924
17925 #define __put_user_asm_ex_u64(x, addr) \
17926 asm volatile(ASM_STAC "\n" \
17927- "1: movl %%eax,0(%1)\n" \
17928- "2: movl %%edx,4(%1)\n" \
17929+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
17930+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
17931 "3: " ASM_CLAC "\n" \
17932 _ASM_EXTABLE_EX(1b, 2b) \
17933 _ASM_EXTABLE_EX(2b, 3b) \
17934@@ -246,7 +287,8 @@ extern void __put_user_8(void);
17935 __typeof__(*(ptr)) __pu_val; \
17936 __chk_user_ptr(ptr); \
17937 might_fault(); \
17938- __pu_val = x; \
17939+ __pu_val = (x); \
17940+ pax_open_userland(); \
17941 switch (sizeof(*(ptr))) { \
17942 case 1: \
17943 __put_user_x(1, __pu_val, ptr, __ret_pu); \
17944@@ -264,6 +306,7 @@ extern void __put_user_8(void);
17945 __put_user_x(X, __pu_val, ptr, __ret_pu); \
17946 break; \
17947 } \
17948+ pax_close_userland(); \
17949 __ret_pu; \
17950 })
17951
17952@@ -344,8 +387,10 @@ do { \
17953 } while (0)
17954
17955 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
17956+do { \
17957+ pax_open_userland(); \
17958 asm volatile(ASM_STAC "\n" \
17959- "1: mov"itype" %2,%"rtype"1\n" \
17960+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
17961 "2: " ASM_CLAC "\n" \
17962 ".section .fixup,\"ax\"\n" \
17963 "3: mov %3,%0\n" \
17964@@ -353,8 +398,10 @@ do { \
17965 " jmp 2b\n" \
17966 ".previous\n" \
17967 _ASM_EXTABLE(1b, 3b) \
17968- : "=r" (err), ltype(x) \
17969- : "m" (__m(addr)), "i" (errret), "0" (err))
17970+ : "=r" (err), ltype (x) \
17971+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
17972+ pax_close_userland(); \
17973+} while (0)
17974
17975 #define __get_user_size_ex(x, ptr, size) \
17976 do { \
17977@@ -378,7 +425,7 @@ do { \
17978 } while (0)
17979
17980 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
17981- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
17982+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
17983 "2:\n" \
17984 _ASM_EXTABLE_EX(1b, 2b) \
17985 : ltype(x) : "m" (__m(addr)))
17986@@ -395,13 +442,24 @@ do { \
17987 int __gu_err; \
17988 unsigned long __gu_val; \
17989 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
17990- (x) = (__force __typeof__(*(ptr)))__gu_val; \
17991+ (x) = (__typeof__(*(ptr)))__gu_val; \
17992 __gu_err; \
17993 })
17994
17995 /* FIXME: this hack is definitely wrong -AK */
17996 struct __large_struct { unsigned long buf[100]; };
17997-#define __m(x) (*(struct __large_struct __user *)(x))
17998+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17999+#define ____m(x) \
18000+({ \
18001+ unsigned long ____x = (unsigned long)(x); \
18002+ if (____x < pax_user_shadow_base) \
18003+ ____x += pax_user_shadow_base; \
18004+ (typeof(x))____x; \
18005+})
18006+#else
18007+#define ____m(x) (x)
18008+#endif
18009+#define __m(x) (*(struct __large_struct __user *)____m(x))
18010
18011 /*
18012 * Tell gcc we read from memory instead of writing: this is because
18013@@ -409,8 +467,10 @@ struct __large_struct { unsigned long buf[100]; };
18014 * aliasing issues.
18015 */
18016 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18017+do { \
18018+ pax_open_userland(); \
18019 asm volatile(ASM_STAC "\n" \
18020- "1: mov"itype" %"rtype"1,%2\n" \
18021+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
18022 "2: " ASM_CLAC "\n" \
18023 ".section .fixup,\"ax\"\n" \
18024 "3: mov %3,%0\n" \
18025@@ -418,10 +478,12 @@ struct __large_struct { unsigned long buf[100]; };
18026 ".previous\n" \
18027 _ASM_EXTABLE(1b, 3b) \
18028 : "=r"(err) \
18029- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
18030+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
18031+ pax_close_userland(); \
18032+} while (0)
18033
18034 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
18035- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
18036+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
18037 "2:\n" \
18038 _ASM_EXTABLE_EX(1b, 2b) \
18039 : : ltype(x), "m" (__m(addr)))
18040@@ -431,11 +493,13 @@ struct __large_struct { unsigned long buf[100]; };
18041 */
18042 #define uaccess_try do { \
18043 current_thread_info()->uaccess_err = 0; \
18044+ pax_open_userland(); \
18045 stac(); \
18046 barrier();
18047
18048 #define uaccess_catch(err) \
18049 clac(); \
18050+ pax_close_userland(); \
18051 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
18052 } while (0)
18053
18054@@ -460,8 +524,12 @@ struct __large_struct { unsigned long buf[100]; };
18055 * On error, the variable @x is set to zero.
18056 */
18057
18058+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18059+#define __get_user(x, ptr) get_user((x), (ptr))
18060+#else
18061 #define __get_user(x, ptr) \
18062 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
18063+#endif
18064
18065 /**
18066 * __put_user: - Write a simple value into user space, with less checking.
18067@@ -483,8 +551,12 @@ struct __large_struct { unsigned long buf[100]; };
18068 * Returns zero on success, or -EFAULT on error.
18069 */
18070
18071+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18072+#define __put_user(x, ptr) put_user((x), (ptr))
18073+#else
18074 #define __put_user(x, ptr) \
18075 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
18076+#endif
18077
18078 #define __get_user_unaligned __get_user
18079 #define __put_user_unaligned __put_user
18080@@ -502,7 +574,7 @@ struct __large_struct { unsigned long buf[100]; };
18081 #define get_user_ex(x, ptr) do { \
18082 unsigned long __gue_val; \
18083 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
18084- (x) = (__force __typeof__(*(ptr)))__gue_val; \
18085+ (x) = (__typeof__(*(ptr)))__gue_val; \
18086 } while (0)
18087
18088 #define put_user_try uaccess_try
18089@@ -519,8 +591,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
18090 extern __must_check long strlen_user(const char __user *str);
18091 extern __must_check long strnlen_user(const char __user *str, long n);
18092
18093-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
18094-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
18095+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
18096+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
18097
18098 /*
18099 * movsl can be slow when source and dest are not both 8-byte aligned
18100diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
18101index 7f760a9..04b1c65 100644
18102--- a/arch/x86/include/asm/uaccess_32.h
18103+++ b/arch/x86/include/asm/uaccess_32.h
18104@@ -11,15 +11,15 @@
18105 #include <asm/page.h>
18106
18107 unsigned long __must_check __copy_to_user_ll
18108- (void __user *to, const void *from, unsigned long n);
18109+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
18110 unsigned long __must_check __copy_from_user_ll
18111- (void *to, const void __user *from, unsigned long n);
18112+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18113 unsigned long __must_check __copy_from_user_ll_nozero
18114- (void *to, const void __user *from, unsigned long n);
18115+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18116 unsigned long __must_check __copy_from_user_ll_nocache
18117- (void *to, const void __user *from, unsigned long n);
18118+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18119 unsigned long __must_check __copy_from_user_ll_nocache_nozero
18120- (void *to, const void __user *from, unsigned long n);
18121+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18122
18123 /**
18124 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
18125@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
18126 static __always_inline unsigned long __must_check
18127 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
18128 {
18129+ if ((long)n < 0)
18130+ return n;
18131+
18132+ check_object_size(from, n, true);
18133+
18134 if (__builtin_constant_p(n)) {
18135 unsigned long ret;
18136
18137@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
18138 __copy_to_user(void __user *to, const void *from, unsigned long n)
18139 {
18140 might_fault();
18141+
18142 return __copy_to_user_inatomic(to, from, n);
18143 }
18144
18145 static __always_inline unsigned long
18146 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
18147 {
18148+ if ((long)n < 0)
18149+ return n;
18150+
18151 /* Avoid zeroing the tail if the copy fails..
18152 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
18153 * but as the zeroing behaviour is only significant when n is not
18154@@ -137,6 +146,12 @@ static __always_inline unsigned long
18155 __copy_from_user(void *to, const void __user *from, unsigned long n)
18156 {
18157 might_fault();
18158+
18159+ if ((long)n < 0)
18160+ return n;
18161+
18162+ check_object_size(to, n, false);
18163+
18164 if (__builtin_constant_p(n)) {
18165 unsigned long ret;
18166
18167@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
18168 const void __user *from, unsigned long n)
18169 {
18170 might_fault();
18171+
18172+ if ((long)n < 0)
18173+ return n;
18174+
18175 if (__builtin_constant_p(n)) {
18176 unsigned long ret;
18177
18178@@ -181,15 +200,19 @@ static __always_inline unsigned long
18179 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
18180 unsigned long n)
18181 {
18182- return __copy_from_user_ll_nocache_nozero(to, from, n);
18183+ if ((long)n < 0)
18184+ return n;
18185+
18186+ return __copy_from_user_ll_nocache_nozero(to, from, n);
18187 }
18188
18189-unsigned long __must_check copy_to_user(void __user *to,
18190- const void *from, unsigned long n);
18191-unsigned long __must_check _copy_from_user(void *to,
18192- const void __user *from,
18193- unsigned long n);
18194-
18195+extern void copy_to_user_overflow(void)
18196+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18197+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18198+#else
18199+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18200+#endif
18201+;
18202
18203 extern void copy_from_user_overflow(void)
18204 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18205@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
18206 #endif
18207 ;
18208
18209-static inline unsigned long __must_check copy_from_user(void *to,
18210- const void __user *from,
18211- unsigned long n)
18212+/**
18213+ * copy_to_user: - Copy a block of data into user space.
18214+ * @to: Destination address, in user space.
18215+ * @from: Source address, in kernel space.
18216+ * @n: Number of bytes to copy.
18217+ *
18218+ * Context: User context only. This function may sleep.
18219+ *
18220+ * Copy data from kernel space to user space.
18221+ *
18222+ * Returns number of bytes that could not be copied.
18223+ * On success, this will be zero.
18224+ */
18225+static inline unsigned long __must_check
18226+copy_to_user(void __user *to, const void *from, unsigned long n)
18227 {
18228- int sz = __compiletime_object_size(to);
18229+ size_t sz = __compiletime_object_size(from);
18230
18231- if (likely(sz == -1 || sz >= n))
18232- n = _copy_from_user(to, from, n);
18233- else
18234+ if (unlikely(sz != (size_t)-1 && sz < n))
18235+ copy_to_user_overflow();
18236+ else if (access_ok(VERIFY_WRITE, to, n))
18237+ n = __copy_to_user(to, from, n);
18238+ return n;
18239+}
18240+
18241+/**
18242+ * copy_from_user: - Copy a block of data from user space.
18243+ * @to: Destination address, in kernel space.
18244+ * @from: Source address, in user space.
18245+ * @n: Number of bytes to copy.
18246+ *
18247+ * Context: User context only. This function may sleep.
18248+ *
18249+ * Copy data from user space to kernel space.
18250+ *
18251+ * Returns number of bytes that could not be copied.
18252+ * On success, this will be zero.
18253+ *
18254+ * If some data could not be copied, this function will pad the copied
18255+ * data to the requested size using zero bytes.
18256+ */
18257+static inline unsigned long __must_check
18258+copy_from_user(void *to, const void __user *from, unsigned long n)
18259+{
18260+ size_t sz = __compiletime_object_size(to);
18261+
18262+ check_object_size(to, n, false);
18263+
18264+ if (unlikely(sz != (size_t)-1 && sz < n))
18265 copy_from_user_overflow();
18266-
18267+ else if (access_ok(VERIFY_READ, from, n))
18268+ n = __copy_from_user(to, from, n);
18269+ else if ((long)n > 0)
18270+ memset(to, 0, n);
18271 return n;
18272 }
18273
18274diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
18275index 4f7923d..20cb24e 100644
18276--- a/arch/x86/include/asm/uaccess_64.h
18277+++ b/arch/x86/include/asm/uaccess_64.h
18278@@ -10,6 +10,9 @@
18279 #include <asm/alternative.h>
18280 #include <asm/cpufeature.h>
18281 #include <asm/page.h>
18282+#include <asm/pgtable.h>
18283+
18284+#define set_fs(x) (current_thread_info()->addr_limit = (x))
18285
18286 /*
18287 * Copy To/From Userspace
18288@@ -17,13 +20,13 @@
18289
18290 /* Handles exceptions in both to and from, but doesn't do access_ok */
18291 __must_check unsigned long
18292-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
18293+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
18294 __must_check unsigned long
18295-copy_user_generic_string(void *to, const void *from, unsigned len);
18296+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
18297 __must_check unsigned long
18298-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
18299+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
18300
18301-static __always_inline __must_check unsigned long
18302+static __always_inline __must_check __size_overflow(3) unsigned long
18303 copy_user_generic(void *to, const void *from, unsigned len)
18304 {
18305 unsigned ret;
18306@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
18307 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
18308 "=d" (len)),
18309 "1" (to), "2" (from), "3" (len)
18310- : "memory", "rcx", "r8", "r9", "r10", "r11");
18311+ : "memory", "rcx", "r8", "r9", "r11");
18312 return ret;
18313 }
18314
18315+static __always_inline __must_check unsigned long
18316+__copy_to_user(void __user *to, const void *from, unsigned long len);
18317+static __always_inline __must_check unsigned long
18318+__copy_from_user(void *to, const void __user *from, unsigned long len);
18319 __must_check unsigned long
18320-_copy_to_user(void __user *to, const void *from, unsigned len);
18321-__must_check unsigned long
18322-_copy_from_user(void *to, const void __user *from, unsigned len);
18323-__must_check unsigned long
18324-copy_in_user(void __user *to, const void __user *from, unsigned len);
18325+copy_in_user(void __user *to, const void __user *from, unsigned long len);
18326+
18327+extern void copy_to_user_overflow(void)
18328+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18329+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18330+#else
18331+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18332+#endif
18333+;
18334+
18335+extern void copy_from_user_overflow(void)
18336+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18337+ __compiletime_error("copy_from_user() buffer size is not provably correct")
18338+#else
18339+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
18340+#endif
18341+;
18342
18343 static inline unsigned long __must_check copy_from_user(void *to,
18344 const void __user *from,
18345 unsigned long n)
18346 {
18347- int sz = __compiletime_object_size(to);
18348-
18349 might_fault();
18350- if (likely(sz == -1 || sz >= n))
18351- n = _copy_from_user(to, from, n);
18352-#ifdef CONFIG_DEBUG_VM
18353- else
18354- WARN(1, "Buffer overflow detected!\n");
18355-#endif
18356+
18357+ check_object_size(to, n, false);
18358+
18359+ if (access_ok(VERIFY_READ, from, n))
18360+ n = __copy_from_user(to, from, n);
18361+ else if (n < INT_MAX)
18362+ memset(to, 0, n);
18363 return n;
18364 }
18365
18366 static __always_inline __must_check
18367-int copy_to_user(void __user *dst, const void *src, unsigned size)
18368+int copy_to_user(void __user *dst, const void *src, unsigned long size)
18369 {
18370 might_fault();
18371
18372- return _copy_to_user(dst, src, size);
18373+ if (access_ok(VERIFY_WRITE, dst, size))
18374+ size = __copy_to_user(dst, src, size);
18375+ return size;
18376 }
18377
18378 static __always_inline __must_check
18379-int __copy_from_user(void *dst, const void __user *src, unsigned size)
18380+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
18381 {
18382- int ret = 0;
18383+ size_t sz = __compiletime_object_size(dst);
18384+ unsigned ret = 0;
18385
18386 might_fault();
18387+
18388+ if (size > INT_MAX)
18389+ return size;
18390+
18391+ check_object_size(dst, size, false);
18392+
18393+#ifdef CONFIG_PAX_MEMORY_UDEREF
18394+ if (!__access_ok(VERIFY_READ, src, size))
18395+ return size;
18396+#endif
18397+
18398+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18399+ copy_from_user_overflow();
18400+ return size;
18401+ }
18402+
18403 if (!__builtin_constant_p(size))
18404- return copy_user_generic(dst, (__force void *)src, size);
18405+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18406 switch (size) {
18407- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
18408+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
18409 ret, "b", "b", "=q", 1);
18410 return ret;
18411- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
18412+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
18413 ret, "w", "w", "=r", 2);
18414 return ret;
18415- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
18416+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
18417 ret, "l", "k", "=r", 4);
18418 return ret;
18419- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
18420+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18421 ret, "q", "", "=r", 8);
18422 return ret;
18423 case 10:
18424- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18425+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18426 ret, "q", "", "=r", 10);
18427 if (unlikely(ret))
18428 return ret;
18429 __get_user_asm(*(u16 *)(8 + (char *)dst),
18430- (u16 __user *)(8 + (char __user *)src),
18431+ (const u16 __user *)(8 + (const char __user *)src),
18432 ret, "w", "w", "=r", 2);
18433 return ret;
18434 case 16:
18435- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18436+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18437 ret, "q", "", "=r", 16);
18438 if (unlikely(ret))
18439 return ret;
18440 __get_user_asm(*(u64 *)(8 + (char *)dst),
18441- (u64 __user *)(8 + (char __user *)src),
18442+ (const u64 __user *)(8 + (const char __user *)src),
18443 ret, "q", "", "=r", 8);
18444 return ret;
18445 default:
18446- return copy_user_generic(dst, (__force void *)src, size);
18447+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18448 }
18449 }
18450
18451 static __always_inline __must_check
18452-int __copy_to_user(void __user *dst, const void *src, unsigned size)
18453+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
18454 {
18455- int ret = 0;
18456+ size_t sz = __compiletime_object_size(src);
18457+ unsigned ret = 0;
18458
18459 might_fault();
18460+
18461+ if (size > INT_MAX)
18462+ return size;
18463+
18464+ check_object_size(src, size, true);
18465+
18466+#ifdef CONFIG_PAX_MEMORY_UDEREF
18467+ if (!__access_ok(VERIFY_WRITE, dst, size))
18468+ return size;
18469+#endif
18470+
18471+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18472+ copy_to_user_overflow();
18473+ return size;
18474+ }
18475+
18476 if (!__builtin_constant_p(size))
18477- return copy_user_generic((__force void *)dst, src, size);
18478+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18479 switch (size) {
18480- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
18481+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
18482 ret, "b", "b", "iq", 1);
18483 return ret;
18484- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
18485+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
18486 ret, "w", "w", "ir", 2);
18487 return ret;
18488- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
18489+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
18490 ret, "l", "k", "ir", 4);
18491 return ret;
18492- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
18493+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18494 ret, "q", "", "er", 8);
18495 return ret;
18496 case 10:
18497- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18498+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18499 ret, "q", "", "er", 10);
18500 if (unlikely(ret))
18501 return ret;
18502 asm("":::"memory");
18503- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
18504+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
18505 ret, "w", "w", "ir", 2);
18506 return ret;
18507 case 16:
18508- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18509+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18510 ret, "q", "", "er", 16);
18511 if (unlikely(ret))
18512 return ret;
18513 asm("":::"memory");
18514- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
18515+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
18516 ret, "q", "", "er", 8);
18517 return ret;
18518 default:
18519- return copy_user_generic((__force void *)dst, src, size);
18520+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18521 }
18522 }
18523
18524 static __always_inline __must_check
18525-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18526+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
18527 {
18528- int ret = 0;
18529+ unsigned ret = 0;
18530
18531 might_fault();
18532+
18533+ if (size > INT_MAX)
18534+ return size;
18535+
18536+#ifdef CONFIG_PAX_MEMORY_UDEREF
18537+ if (!__access_ok(VERIFY_READ, src, size))
18538+ return size;
18539+ if (!__access_ok(VERIFY_WRITE, dst, size))
18540+ return size;
18541+#endif
18542+
18543 if (!__builtin_constant_p(size))
18544- return copy_user_generic((__force void *)dst,
18545- (__force void *)src, size);
18546+ return copy_user_generic((__force_kernel void *)____m(dst),
18547+ (__force_kernel const void *)____m(src), size);
18548 switch (size) {
18549 case 1: {
18550 u8 tmp;
18551- __get_user_asm(tmp, (u8 __user *)src,
18552+ __get_user_asm(tmp, (const u8 __user *)src,
18553 ret, "b", "b", "=q", 1);
18554 if (likely(!ret))
18555 __put_user_asm(tmp, (u8 __user *)dst,
18556@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18557 }
18558 case 2: {
18559 u16 tmp;
18560- __get_user_asm(tmp, (u16 __user *)src,
18561+ __get_user_asm(tmp, (const u16 __user *)src,
18562 ret, "w", "w", "=r", 2);
18563 if (likely(!ret))
18564 __put_user_asm(tmp, (u16 __user *)dst,
18565@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18566
18567 case 4: {
18568 u32 tmp;
18569- __get_user_asm(tmp, (u32 __user *)src,
18570+ __get_user_asm(tmp, (const u32 __user *)src,
18571 ret, "l", "k", "=r", 4);
18572 if (likely(!ret))
18573 __put_user_asm(tmp, (u32 __user *)dst,
18574@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18575 }
18576 case 8: {
18577 u64 tmp;
18578- __get_user_asm(tmp, (u64 __user *)src,
18579+ __get_user_asm(tmp, (const u64 __user *)src,
18580 ret, "q", "", "=r", 8);
18581 if (likely(!ret))
18582 __put_user_asm(tmp, (u64 __user *)dst,
18583@@ -212,41 +277,74 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18584 return ret;
18585 }
18586 default:
18587- return copy_user_generic((__force void *)dst,
18588- (__force void *)src, size);
18589+ return copy_user_generic((__force_kernel void *)____m(dst),
18590+ (__force_kernel const void *)____m(src), size);
18591 }
18592 }
18593
18594-static __must_check __always_inline int
18595-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
18596+static __must_check __always_inline unsigned long
18597+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
18598 {
18599- return copy_user_generic(dst, (__force const void *)src, size);
18600+ if (size > INT_MAX)
18601+ return size;
18602+
18603+#ifdef CONFIG_PAX_MEMORY_UDEREF
18604+ if (!__access_ok(VERIFY_READ, src, size))
18605+ return size;
18606+#endif
18607+
18608+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18609 }
18610
18611-static __must_check __always_inline int
18612-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
18613+static __must_check __always_inline unsigned long
18614+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
18615 {
18616- return copy_user_generic((__force void *)dst, src, size);
18617+ if (size > INT_MAX)
18618+ return size;
18619+
18620+#ifdef CONFIG_PAX_MEMORY_UDEREF
18621+ if (!__access_ok(VERIFY_WRITE, dst, size))
18622+ return size;
18623+#endif
18624+
18625+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18626 }
18627
18628-extern long __copy_user_nocache(void *dst, const void __user *src,
18629- unsigned size, int zerorest);
18630+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
18631+ unsigned long size, int zerorest) __size_overflow(3);
18632
18633-static inline int
18634-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
18635+static inline unsigned long
18636+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
18637 {
18638 might_fault();
18639+
18640+ if (size > INT_MAX)
18641+ return size;
18642+
18643+#ifdef CONFIG_PAX_MEMORY_UDEREF
18644+ if (!__access_ok(VERIFY_READ, src, size))
18645+ return size;
18646+#endif
18647+
18648 return __copy_user_nocache(dst, src, size, 1);
18649 }
18650
18651-static inline int
18652+static inline unsigned long
18653 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
18654- unsigned size)
18655+ unsigned long size)
18656 {
18657+ if (size > INT_MAX)
18658+ return size;
18659+
18660+#ifdef CONFIG_PAX_MEMORY_UDEREF
18661+ if (!__access_ok(VERIFY_READ, src, size))
18662+ return size;
18663+#endif
18664+
18665 return __copy_user_nocache(dst, src, size, 0);
18666 }
18667
18668 unsigned long
18669-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
18670+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
18671
18672 #endif /* _ASM_X86_UACCESS_64_H */
18673diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
18674index 5b238981..77fdd78 100644
18675--- a/arch/x86/include/asm/word-at-a-time.h
18676+++ b/arch/x86/include/asm/word-at-a-time.h
18677@@ -11,7 +11,7 @@
18678 * and shift, for example.
18679 */
18680 struct word_at_a_time {
18681- const unsigned long one_bits, high_bits;
18682+ unsigned long one_bits, high_bits;
18683 };
18684
18685 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
18686diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
18687index 828a156..650e625 100644
18688--- a/arch/x86/include/asm/x86_init.h
18689+++ b/arch/x86/include/asm/x86_init.h
18690@@ -129,7 +129,7 @@ struct x86_init_ops {
18691 struct x86_init_timers timers;
18692 struct x86_init_iommu iommu;
18693 struct x86_init_pci pci;
18694-};
18695+} __no_const;
18696
18697 /**
18698 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
18699@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
18700 void (*setup_percpu_clockev)(void);
18701 void (*early_percpu_clock_init)(void);
18702 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
18703-};
18704+} __no_const;
18705
18706 struct timespec;
18707
18708@@ -168,7 +168,7 @@ struct x86_platform_ops {
18709 void (*save_sched_clock_state)(void);
18710 void (*restore_sched_clock_state)(void);
18711 void (*apic_post_init)(void);
18712-};
18713+} __no_const;
18714
18715 struct pci_dev;
18716 struct msi_msg;
18717@@ -182,7 +182,7 @@ struct x86_msi_ops {
18718 void (*teardown_msi_irqs)(struct pci_dev *dev);
18719 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
18720 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
18721-};
18722+} __no_const;
18723
18724 struct IO_APIC_route_entry;
18725 struct io_apic_irq_attr;
18726@@ -203,7 +203,7 @@ struct x86_io_apic_ops {
18727 unsigned int destination, int vector,
18728 struct io_apic_irq_attr *attr);
18729 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
18730-};
18731+} __no_const;
18732
18733 extern struct x86_init_ops x86_init;
18734 extern struct x86_cpuinit_ops x86_cpuinit;
18735diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
18736index 0415cda..3b22adc 100644
18737--- a/arch/x86/include/asm/xsave.h
18738+++ b/arch/x86/include/asm/xsave.h
18739@@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
18740 if (unlikely(err))
18741 return -EFAULT;
18742
18743+ pax_open_userland();
18744 __asm__ __volatile__(ASM_STAC "\n"
18745- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
18746+ "1:"
18747+ __copyuser_seg
18748+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
18749 "2: " ASM_CLAC "\n"
18750 ".section .fixup,\"ax\"\n"
18751 "3: movl $-1,%[err]\n"
18752@@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
18753 : [err] "=r" (err)
18754 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
18755 : "memory");
18756+ pax_close_userland();
18757 return err;
18758 }
18759
18760 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18761 {
18762 int err;
18763- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
18764+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
18765 u32 lmask = mask;
18766 u32 hmask = mask >> 32;
18767
18768+ pax_open_userland();
18769 __asm__ __volatile__(ASM_STAC "\n"
18770- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18771+ "1:"
18772+ __copyuser_seg
18773+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18774 "2: " ASM_CLAC "\n"
18775 ".section .fixup,\"ax\"\n"
18776 "3: movl $-1,%[err]\n"
18777@@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18778 : [err] "=r" (err)
18779 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
18780 : "memory"); /* memory required? */
18781+ pax_close_userland();
18782 return err;
18783 }
18784
18785diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
18786index bbae024..e1528f9 100644
18787--- a/arch/x86/include/uapi/asm/e820.h
18788+++ b/arch/x86/include/uapi/asm/e820.h
18789@@ -63,7 +63,7 @@ struct e820map {
18790 #define ISA_START_ADDRESS 0xa0000
18791 #define ISA_END_ADDRESS 0x100000
18792
18793-#define BIOS_BEGIN 0x000a0000
18794+#define BIOS_BEGIN 0x000c0000
18795 #define BIOS_END 0x00100000
18796
18797 #define BIOS_ROM_BASE 0xffe00000
18798diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
18799index 88d99ea..9fc7e17 100644
18800--- a/arch/x86/kernel/Makefile
18801+++ b/arch/x86/kernel/Makefile
18802@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
18803 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
18804 obj-$(CONFIG_IRQ_WORK) += irq_work.o
18805 obj-y += probe_roms.o
18806-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
18807+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
18808 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
18809 obj-y += syscall_$(BITS).o
18810 obj-$(CONFIG_X86_64) += vsyscall_64.o
18811diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
18812index 2627a81..cd8325e 100644
18813--- a/arch/x86/kernel/acpi/boot.c
18814+++ b/arch/x86/kernel/acpi/boot.c
18815@@ -1368,7 +1368,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
18816 * If your system is blacklisted here, but you find that acpi=force
18817 * works for you, please contact linux-acpi@vger.kernel.org
18818 */
18819-static struct dmi_system_id __initdata acpi_dmi_table[] = {
18820+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
18821 /*
18822 * Boxes that need ACPI disabled
18823 */
18824@@ -1443,7 +1443,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
18825 };
18826
18827 /* second table for DMI checks that should run after early-quirks */
18828-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
18829+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
18830 /*
18831 * HP laptops which use a DSDT reporting as HP/SB400/10000,
18832 * which includes some code which overrides all temperature
18833diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
18834index 3312010..a65ca7b 100644
18835--- a/arch/x86/kernel/acpi/sleep.c
18836+++ b/arch/x86/kernel/acpi/sleep.c
18837@@ -88,8 +88,12 @@ int x86_acpi_suspend_lowlevel(void)
18838 #else /* CONFIG_64BIT */
18839 #ifdef CONFIG_SMP
18840 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
18841+
18842+ pax_open_kernel();
18843 early_gdt_descr.address =
18844 (unsigned long)get_cpu_gdt_table(smp_processor_id());
18845+ pax_close_kernel();
18846+
18847 initial_gs = per_cpu_offset(smp_processor_id());
18848 #endif
18849 initial_code = (unsigned long)wakeup_long64;
18850diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
18851index d1daa66..59fecba 100644
18852--- a/arch/x86/kernel/acpi/wakeup_32.S
18853+++ b/arch/x86/kernel/acpi/wakeup_32.S
18854@@ -29,13 +29,11 @@ wakeup_pmode_return:
18855 # and restore the stack ... but you need gdt for this to work
18856 movl saved_context_esp, %esp
18857
18858- movl %cs:saved_magic, %eax
18859- cmpl $0x12345678, %eax
18860+ cmpl $0x12345678, saved_magic
18861 jne bogus_magic
18862
18863 # jump to place where we left off
18864- movl saved_eip, %eax
18865- jmp *%eax
18866+ jmp *(saved_eip)
18867
18868 bogus_magic:
18869 jmp bogus_magic
18870diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
18871index c15cf9a..0e63558 100644
18872--- a/arch/x86/kernel/alternative.c
18873+++ b/arch/x86/kernel/alternative.c
18874@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
18875 */
18876 for (a = start; a < end; a++) {
18877 instr = (u8 *)&a->instr_offset + a->instr_offset;
18878+
18879+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18880+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18881+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
18882+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18883+#endif
18884+
18885 replacement = (u8 *)&a->repl_offset + a->repl_offset;
18886 BUG_ON(a->replacementlen > a->instrlen);
18887 BUG_ON(a->instrlen > sizeof(insnbuf));
18888@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
18889 for (poff = start; poff < end; poff++) {
18890 u8 *ptr = (u8 *)poff + *poff;
18891
18892+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18893+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18894+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
18895+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18896+#endif
18897+
18898 if (!*poff || ptr < text || ptr >= text_end)
18899 continue;
18900 /* turn DS segment override prefix into lock prefix */
18901- if (*ptr == 0x3e)
18902+ if (*ktla_ktva(ptr) == 0x3e)
18903 text_poke(ptr, ((unsigned char []){0xf0}), 1);
18904 }
18905 mutex_unlock(&text_mutex);
18906@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
18907 for (poff = start; poff < end; poff++) {
18908 u8 *ptr = (u8 *)poff + *poff;
18909
18910+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18911+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18912+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
18913+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18914+#endif
18915+
18916 if (!*poff || ptr < text || ptr >= text_end)
18917 continue;
18918 /* turn lock prefix into DS segment override prefix */
18919- if (*ptr == 0xf0)
18920+ if (*ktla_ktva(ptr) == 0xf0)
18921 text_poke(ptr, ((unsigned char []){0x3E}), 1);
18922 }
18923 mutex_unlock(&text_mutex);
18924@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
18925
18926 BUG_ON(p->len > MAX_PATCH_LEN);
18927 /* prep the buffer with the original instructions */
18928- memcpy(insnbuf, p->instr, p->len);
18929+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
18930 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
18931 (unsigned long)p->instr, p->len);
18932
18933@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
18934 if (!uniproc_patched || num_possible_cpus() == 1)
18935 free_init_pages("SMP alternatives",
18936 (unsigned long)__smp_locks,
18937- (unsigned long)__smp_locks_end);
18938+ PAGE_ALIGN((unsigned long)__smp_locks_end));
18939 #endif
18940
18941 apply_paravirt(__parainstructions, __parainstructions_end);
18942@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
18943 * instructions. And on the local CPU you need to be protected again NMI or MCE
18944 * handlers seeing an inconsistent instruction while you patch.
18945 */
18946-void *__init_or_module text_poke_early(void *addr, const void *opcode,
18947+void *__kprobes text_poke_early(void *addr, const void *opcode,
18948 size_t len)
18949 {
18950 unsigned long flags;
18951 local_irq_save(flags);
18952- memcpy(addr, opcode, len);
18953+
18954+ pax_open_kernel();
18955+ memcpy(ktla_ktva(addr), opcode, len);
18956 sync_core();
18957+ pax_close_kernel();
18958+
18959 local_irq_restore(flags);
18960 /* Could also do a CLFLUSH here to speed up CPU recovery; but
18961 that causes hangs on some VIA CPUs. */
18962@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
18963 */
18964 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
18965 {
18966- unsigned long flags;
18967- char *vaddr;
18968+ unsigned char *vaddr = ktla_ktva(addr);
18969 struct page *pages[2];
18970- int i;
18971+ size_t i;
18972
18973 if (!core_kernel_text((unsigned long)addr)) {
18974- pages[0] = vmalloc_to_page(addr);
18975- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
18976+ pages[0] = vmalloc_to_page(vaddr);
18977+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
18978 } else {
18979- pages[0] = virt_to_page(addr);
18980+ pages[0] = virt_to_page(vaddr);
18981 WARN_ON(!PageReserved(pages[0]));
18982- pages[1] = virt_to_page(addr + PAGE_SIZE);
18983+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
18984 }
18985 BUG_ON(!pages[0]);
18986- local_irq_save(flags);
18987- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
18988- if (pages[1])
18989- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
18990- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
18991- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
18992- clear_fixmap(FIX_TEXT_POKE0);
18993- if (pages[1])
18994- clear_fixmap(FIX_TEXT_POKE1);
18995- local_flush_tlb();
18996- sync_core();
18997- /* Could also do a CLFLUSH here to speed up CPU recovery; but
18998- that causes hangs on some VIA CPUs. */
18999+ text_poke_early(addr, opcode, len);
19000 for (i = 0; i < len; i++)
19001- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
19002- local_irq_restore(flags);
19003+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
19004 return addr;
19005 }
19006
19007diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
19008index eca89c5..d566b78 100644
19009--- a/arch/x86/kernel/apic/apic.c
19010+++ b/arch/x86/kernel/apic/apic.c
19011@@ -190,7 +190,7 @@ int first_system_vector = 0xfe;
19012 /*
19013 * Debug level, exported for io_apic.c
19014 */
19015-unsigned int apic_verbosity;
19016+int apic_verbosity;
19017
19018 int pic_mode;
19019
19020@@ -1985,7 +1985,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
19021 apic_write(APIC_ESR, 0);
19022 v1 = apic_read(APIC_ESR);
19023 ack_APIC_irq();
19024- atomic_inc(&irq_err_count);
19025+ atomic_inc_unchecked(&irq_err_count);
19026
19027 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
19028 smp_processor_id(), v0 , v1);
19029diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
19030index 00c77cf..2dc6a2d 100644
19031--- a/arch/x86/kernel/apic/apic_flat_64.c
19032+++ b/arch/x86/kernel/apic/apic_flat_64.c
19033@@ -157,7 +157,7 @@ static int flat_probe(void)
19034 return 1;
19035 }
19036
19037-static struct apic apic_flat = {
19038+static struct apic apic_flat __read_only = {
19039 .name = "flat",
19040 .probe = flat_probe,
19041 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
19042@@ -271,7 +271,7 @@ static int physflat_probe(void)
19043 return 0;
19044 }
19045
19046-static struct apic apic_physflat = {
19047+static struct apic apic_physflat __read_only = {
19048
19049 .name = "physical flat",
19050 .probe = physflat_probe,
19051diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
19052index e145f28..2752888 100644
19053--- a/arch/x86/kernel/apic/apic_noop.c
19054+++ b/arch/x86/kernel/apic/apic_noop.c
19055@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
19056 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
19057 }
19058
19059-struct apic apic_noop = {
19060+struct apic apic_noop __read_only = {
19061 .name = "noop",
19062 .probe = noop_probe,
19063 .acpi_madt_oem_check = NULL,
19064diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
19065index d50e364..543bee3 100644
19066--- a/arch/x86/kernel/apic/bigsmp_32.c
19067+++ b/arch/x86/kernel/apic/bigsmp_32.c
19068@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
19069 return dmi_bigsmp;
19070 }
19071
19072-static struct apic apic_bigsmp = {
19073+static struct apic apic_bigsmp __read_only = {
19074
19075 .name = "bigsmp",
19076 .probe = probe_bigsmp,
19077diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
19078index c552247..587a316 100644
19079--- a/arch/x86/kernel/apic/es7000_32.c
19080+++ b/arch/x86/kernel/apic/es7000_32.c
19081@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
19082 return ret && es7000_apic_is_cluster();
19083 }
19084
19085-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
19086-static struct apic __refdata apic_es7000_cluster = {
19087+static struct apic apic_es7000_cluster __read_only = {
19088
19089 .name = "es7000",
19090 .probe = probe_es7000,
19091@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
19092 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
19093 };
19094
19095-static struct apic __refdata apic_es7000 = {
19096+static struct apic apic_es7000 __read_only = {
19097
19098 .name = "es7000",
19099 .probe = probe_es7000,
19100diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
19101index 9ed796c..e930fe4 100644
19102--- a/arch/x86/kernel/apic/io_apic.c
19103+++ b/arch/x86/kernel/apic/io_apic.c
19104@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
19105 }
19106 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
19107
19108-void lock_vector_lock(void)
19109+void lock_vector_lock(void) __acquires(vector_lock)
19110 {
19111 /* Used to the online set of cpus does not change
19112 * during assign_irq_vector.
19113@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
19114 raw_spin_lock(&vector_lock);
19115 }
19116
19117-void unlock_vector_lock(void)
19118+void unlock_vector_lock(void) __releases(vector_lock)
19119 {
19120 raw_spin_unlock(&vector_lock);
19121 }
19122@@ -2362,7 +2362,7 @@ static void ack_apic_edge(struct irq_data *data)
19123 ack_APIC_irq();
19124 }
19125
19126-atomic_t irq_mis_count;
19127+atomic_unchecked_t irq_mis_count;
19128
19129 #ifdef CONFIG_GENERIC_PENDING_IRQ
19130 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
19131@@ -2503,7 +2503,7 @@ static void ack_apic_level(struct irq_data *data)
19132 * at the cpu.
19133 */
19134 if (!(v & (1 << (i & 0x1f)))) {
19135- atomic_inc(&irq_mis_count);
19136+ atomic_inc_unchecked(&irq_mis_count);
19137
19138 eoi_ioapic_irq(irq, cfg);
19139 }
19140diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
19141index 1e42e8f..daacf44 100644
19142--- a/arch/x86/kernel/apic/numaq_32.c
19143+++ b/arch/x86/kernel/apic/numaq_32.c
19144@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
19145 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
19146 }
19147
19148-/* Use __refdata to keep false positive warning calm. */
19149-static struct apic __refdata apic_numaq = {
19150+static struct apic apic_numaq __read_only = {
19151
19152 .name = "NUMAQ",
19153 .probe = probe_numaq,
19154diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
19155index eb35ef9..f184a21 100644
19156--- a/arch/x86/kernel/apic/probe_32.c
19157+++ b/arch/x86/kernel/apic/probe_32.c
19158@@ -72,7 +72,7 @@ static int probe_default(void)
19159 return 1;
19160 }
19161
19162-static struct apic apic_default = {
19163+static struct apic apic_default __read_only = {
19164
19165 .name = "default",
19166 .probe = probe_default,
19167diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
19168index 77c95c0..434f8a4 100644
19169--- a/arch/x86/kernel/apic/summit_32.c
19170+++ b/arch/x86/kernel/apic/summit_32.c
19171@@ -486,7 +486,7 @@ void setup_summit(void)
19172 }
19173 #endif
19174
19175-static struct apic apic_summit = {
19176+static struct apic apic_summit __read_only = {
19177
19178 .name = "summit",
19179 .probe = probe_summit,
19180diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
19181index 140e29d..d88bc95 100644
19182--- a/arch/x86/kernel/apic/x2apic_cluster.c
19183+++ b/arch/x86/kernel/apic/x2apic_cluster.c
19184@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
19185 return notifier_from_errno(err);
19186 }
19187
19188-static struct notifier_block __refdata x2apic_cpu_notifier = {
19189+static struct notifier_block x2apic_cpu_notifier = {
19190 .notifier_call = update_clusterinfo,
19191 };
19192
19193@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
19194 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
19195 }
19196
19197-static struct apic apic_x2apic_cluster = {
19198+static struct apic apic_x2apic_cluster __read_only = {
19199
19200 .name = "cluster x2apic",
19201 .probe = x2apic_cluster_probe,
19202diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
19203index 562a76d..a003c0f 100644
19204--- a/arch/x86/kernel/apic/x2apic_phys.c
19205+++ b/arch/x86/kernel/apic/x2apic_phys.c
19206@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
19207 return apic == &apic_x2apic_phys;
19208 }
19209
19210-static struct apic apic_x2apic_phys = {
19211+static struct apic apic_x2apic_phys __read_only = {
19212
19213 .name = "physical x2apic",
19214 .probe = x2apic_phys_probe,
19215diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
19216index 1191ac1..2335fa4 100644
19217--- a/arch/x86/kernel/apic/x2apic_uv_x.c
19218+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
19219@@ -357,7 +357,7 @@ static int uv_probe(void)
19220 return apic == &apic_x2apic_uv_x;
19221 }
19222
19223-static struct apic __refdata apic_x2apic_uv_x = {
19224+static struct apic apic_x2apic_uv_x __read_only = {
19225
19226 .name = "UV large system",
19227 .probe = uv_probe,
19228diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
19229index 53a4e27..038760a 100644
19230--- a/arch/x86/kernel/apm_32.c
19231+++ b/arch/x86/kernel/apm_32.c
19232@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
19233 * This is for buggy BIOS's that refer to (real mode) segment 0x40
19234 * even though they are called in protected mode.
19235 */
19236-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
19237+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
19238 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
19239
19240 static const char driver_version[] = "1.16ac"; /* no spaces */
19241@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
19242 BUG_ON(cpu != 0);
19243 gdt = get_cpu_gdt_table(cpu);
19244 save_desc_40 = gdt[0x40 / 8];
19245+
19246+ pax_open_kernel();
19247 gdt[0x40 / 8] = bad_bios_desc;
19248+ pax_close_kernel();
19249
19250 apm_irq_save(flags);
19251 APM_DO_SAVE_SEGS;
19252@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
19253 &call->esi);
19254 APM_DO_RESTORE_SEGS;
19255 apm_irq_restore(flags);
19256+
19257+ pax_open_kernel();
19258 gdt[0x40 / 8] = save_desc_40;
19259+ pax_close_kernel();
19260+
19261 put_cpu();
19262
19263 return call->eax & 0xff;
19264@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
19265 BUG_ON(cpu != 0);
19266 gdt = get_cpu_gdt_table(cpu);
19267 save_desc_40 = gdt[0x40 / 8];
19268+
19269+ pax_open_kernel();
19270 gdt[0x40 / 8] = bad_bios_desc;
19271+ pax_close_kernel();
19272
19273 apm_irq_save(flags);
19274 APM_DO_SAVE_SEGS;
19275@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
19276 &call->eax);
19277 APM_DO_RESTORE_SEGS;
19278 apm_irq_restore(flags);
19279+
19280+ pax_open_kernel();
19281 gdt[0x40 / 8] = save_desc_40;
19282+ pax_close_kernel();
19283+
19284 put_cpu();
19285 return error;
19286 }
19287@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
19288 * code to that CPU.
19289 */
19290 gdt = get_cpu_gdt_table(0);
19291+
19292+ pax_open_kernel();
19293 set_desc_base(&gdt[APM_CS >> 3],
19294 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
19295 set_desc_base(&gdt[APM_CS_16 >> 3],
19296 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
19297 set_desc_base(&gdt[APM_DS >> 3],
19298 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
19299+ pax_close_kernel();
19300
19301 proc_create("apm", 0, NULL, &apm_file_ops);
19302
19303diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
19304index 2861082..6d4718e 100644
19305--- a/arch/x86/kernel/asm-offsets.c
19306+++ b/arch/x86/kernel/asm-offsets.c
19307@@ -33,6 +33,8 @@ void common(void) {
19308 OFFSET(TI_status, thread_info, status);
19309 OFFSET(TI_addr_limit, thread_info, addr_limit);
19310 OFFSET(TI_preempt_count, thread_info, preempt_count);
19311+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
19312+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
19313
19314 BLANK();
19315 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
19316@@ -53,8 +55,26 @@ void common(void) {
19317 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
19318 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
19319 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
19320+
19321+#ifdef CONFIG_PAX_KERNEXEC
19322+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
19323 #endif
19324
19325+#ifdef CONFIG_PAX_MEMORY_UDEREF
19326+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
19327+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
19328+#ifdef CONFIG_X86_64
19329+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
19330+#endif
19331+#endif
19332+
19333+#endif
19334+
19335+ BLANK();
19336+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
19337+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
19338+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
19339+
19340 #ifdef CONFIG_XEN
19341 BLANK();
19342 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
19343diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
19344index e7c798b..2b2019b 100644
19345--- a/arch/x86/kernel/asm-offsets_64.c
19346+++ b/arch/x86/kernel/asm-offsets_64.c
19347@@ -77,6 +77,7 @@ int main(void)
19348 BLANK();
19349 #undef ENTRY
19350
19351+ DEFINE(TSS_size, sizeof(struct tss_struct));
19352 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
19353 BLANK();
19354
19355diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
19356index 47b56a7..efc2bc6 100644
19357--- a/arch/x86/kernel/cpu/Makefile
19358+++ b/arch/x86/kernel/cpu/Makefile
19359@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
19360 CFLAGS_REMOVE_perf_event.o = -pg
19361 endif
19362
19363-# Make sure load_percpu_segment has no stackprotector
19364-nostackp := $(call cc-option, -fno-stack-protector)
19365-CFLAGS_common.o := $(nostackp)
19366-
19367 obj-y := intel_cacheinfo.o scattered.o topology.o
19368 obj-y += proc.o capflags.o powerflags.o common.o
19369 obj-y += rdrand.o
19370diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
19371index 08a0890..e557865 100644
19372--- a/arch/x86/kernel/cpu/amd.c
19373+++ b/arch/x86/kernel/cpu/amd.c
19374@@ -743,7 +743,7 @@ static void init_amd(struct cpuinfo_x86 *c)
19375 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
19376 {
19377 /* AMD errata T13 (order #21922) */
19378- if ((c->x86 == 6)) {
19379+ if (c->x86 == 6) {
19380 /* Duron Rev A0 */
19381 if (c->x86_model == 3 && c->x86_mask == 0)
19382 size = 64;
19383diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
19384index 25eb274..3a92d93 100644
19385--- a/arch/x86/kernel/cpu/common.c
19386+++ b/arch/x86/kernel/cpu/common.c
19387@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
19388
19389 static const struct cpu_dev *this_cpu = &default_cpu;
19390
19391-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
19392-#ifdef CONFIG_X86_64
19393- /*
19394- * We need valid kernel segments for data and code in long mode too
19395- * IRET will check the segment types kkeil 2000/10/28
19396- * Also sysret mandates a special GDT layout
19397- *
19398- * TLS descriptors are currently at a different place compared to i386.
19399- * Hopefully nobody expects them at a fixed place (Wine?)
19400- */
19401- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
19402- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
19403- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
19404- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
19405- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
19406- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
19407-#else
19408- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
19409- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19410- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
19411- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
19412- /*
19413- * Segments used for calling PnP BIOS have byte granularity.
19414- * They code segments and data segments have fixed 64k limits,
19415- * the transfer segment sizes are set at run time.
19416- */
19417- /* 32-bit code */
19418- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19419- /* 16-bit code */
19420- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19421- /* 16-bit data */
19422- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
19423- /* 16-bit data */
19424- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
19425- /* 16-bit data */
19426- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
19427- /*
19428- * The APM segments have byte granularity and their bases
19429- * are set at run time. All have 64k limits.
19430- */
19431- /* 32-bit code */
19432- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19433- /* 16-bit code */
19434- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19435- /* data */
19436- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
19437-
19438- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19439- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19440- GDT_STACK_CANARY_INIT
19441-#endif
19442-} };
19443-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
19444-
19445 static int __init x86_xsave_setup(char *s)
19446 {
19447 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
19448@@ -288,6 +234,57 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
19449 set_in_cr4(X86_CR4_SMAP);
19450 }
19451
19452+#ifdef CONFIG_X86_64
19453+static __init int setup_disable_pcid(char *arg)
19454+{
19455+ setup_clear_cpu_cap(X86_FEATURE_PCID);
19456+
19457+#ifdef CONFIG_PAX_MEMORY_UDEREF
19458+ if (clone_pgd_mask != ~(pgdval_t)0UL)
19459+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19460+#endif
19461+
19462+ return 1;
19463+}
19464+__setup("nopcid", setup_disable_pcid);
19465+
19466+static void setup_pcid(struct cpuinfo_x86 *c)
19467+{
19468+ if (!cpu_has(c, X86_FEATURE_PCID)) {
19469+
19470+#ifdef CONFIG_PAX_MEMORY_UDEREF
19471+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
19472+ pax_open_kernel();
19473+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19474+ pax_close_kernel();
19475+ printk("PAX: slow and weak UDEREF enabled\n");
19476+ } else
19477+ printk("PAX: UDEREF disabled\n");
19478+#endif
19479+
19480+ return;
19481+ }
19482+
19483+ printk("PAX: PCID detected\n");
19484+ set_in_cr4(X86_CR4_PCIDE);
19485+
19486+#ifdef CONFIG_PAX_MEMORY_UDEREF
19487+ pax_open_kernel();
19488+ clone_pgd_mask = ~(pgdval_t)0UL;
19489+ pax_close_kernel();
19490+ if (pax_user_shadow_base)
19491+ printk("PAX: weak UDEREF enabled\n");
19492+ else {
19493+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
19494+ printk("PAX: strong UDEREF enabled\n");
19495+ }
19496+#endif
19497+
19498+ if (cpu_has(c, X86_FEATURE_INVPCID))
19499+ printk("PAX: INVPCID detected\n");
19500+}
19501+#endif
19502+
19503 /*
19504 * Some CPU features depend on higher CPUID levels, which may not always
19505 * be available due to CPUID level capping or broken virtualization
19506@@ -386,7 +383,7 @@ void switch_to_new_gdt(int cpu)
19507 {
19508 struct desc_ptr gdt_descr;
19509
19510- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
19511+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19512 gdt_descr.size = GDT_SIZE - 1;
19513 load_gdt(&gdt_descr);
19514 /* Reload the per-cpu base */
19515@@ -875,6 +872,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19516 setup_smep(c);
19517 setup_smap(c);
19518
19519+#ifdef CONFIG_X86_64
19520+ setup_pcid(c);
19521+#endif
19522+
19523 /*
19524 * The vendor-specific functions might have changed features.
19525 * Now we do "generic changes."
19526@@ -883,6 +884,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19527 /* Filter out anything that depends on CPUID levels we don't have */
19528 filter_cpuid_features(c, true);
19529
19530+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
19531+ setup_clear_cpu_cap(X86_FEATURE_SEP);
19532+#endif
19533+
19534 /* If the model name is still unset, do table lookup. */
19535 if (!c->x86_model_id[0]) {
19536 const char *p;
19537@@ -1070,10 +1075,12 @@ static __init int setup_disablecpuid(char *arg)
19538 }
19539 __setup("clearcpuid=", setup_disablecpuid);
19540
19541+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
19542+EXPORT_PER_CPU_SYMBOL(current_tinfo);
19543+
19544 #ifdef CONFIG_X86_64
19545-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19546-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
19547- (unsigned long) debug_idt_table };
19548+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19549+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
19550
19551 DEFINE_PER_CPU_FIRST(union irq_stack_union,
19552 irq_stack_union) __aligned(PAGE_SIZE);
19553@@ -1087,7 +1094,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
19554 EXPORT_PER_CPU_SYMBOL(current_task);
19555
19556 DEFINE_PER_CPU(unsigned long, kernel_stack) =
19557- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
19558+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
19559 EXPORT_PER_CPU_SYMBOL(kernel_stack);
19560
19561 DEFINE_PER_CPU(char *, irq_stack_ptr) =
19562@@ -1232,7 +1239,7 @@ void cpu_init(void)
19563 load_ucode_ap();
19564
19565 cpu = stack_smp_processor_id();
19566- t = &per_cpu(init_tss, cpu);
19567+ t = init_tss + cpu;
19568 oist = &per_cpu(orig_ist, cpu);
19569
19570 #ifdef CONFIG_NUMA
19571@@ -1267,7 +1274,6 @@ void cpu_init(void)
19572 wrmsrl(MSR_KERNEL_GS_BASE, 0);
19573 barrier();
19574
19575- x86_configure_nx();
19576 enable_x2apic();
19577
19578 /*
19579@@ -1319,7 +1325,7 @@ void cpu_init(void)
19580 {
19581 int cpu = smp_processor_id();
19582 struct task_struct *curr = current;
19583- struct tss_struct *t = &per_cpu(init_tss, cpu);
19584+ struct tss_struct *t = init_tss + cpu;
19585 struct thread_struct *thread = &curr->thread;
19586
19587 show_ucode_info_early();
19588diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
19589index 1414c90..1159406 100644
19590--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
19591+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
19592@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
19593 };
19594
19595 #ifdef CONFIG_AMD_NB
19596+static struct attribute *default_attrs_amd_nb[] = {
19597+ &type.attr,
19598+ &level.attr,
19599+ &coherency_line_size.attr,
19600+ &physical_line_partition.attr,
19601+ &ways_of_associativity.attr,
19602+ &number_of_sets.attr,
19603+ &size.attr,
19604+ &shared_cpu_map.attr,
19605+ &shared_cpu_list.attr,
19606+ NULL,
19607+ NULL,
19608+ NULL,
19609+ NULL
19610+};
19611+
19612 static struct attribute **amd_l3_attrs(void)
19613 {
19614 static struct attribute **attrs;
19615@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
19616
19617 n = ARRAY_SIZE(default_attrs);
19618
19619- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
19620- n += 2;
19621-
19622- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
19623- n += 1;
19624-
19625- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
19626- if (attrs == NULL)
19627- return attrs = default_attrs;
19628-
19629- for (n = 0; default_attrs[n]; n++)
19630- attrs[n] = default_attrs[n];
19631+ attrs = default_attrs_amd_nb;
19632
19633 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
19634 attrs[n++] = &cache_disable_0.attr;
19635@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
19636 .default_attrs = default_attrs,
19637 };
19638
19639+#ifdef CONFIG_AMD_NB
19640+static struct kobj_type ktype_cache_amd_nb = {
19641+ .sysfs_ops = &sysfs_ops,
19642+ .default_attrs = default_attrs_amd_nb,
19643+};
19644+#endif
19645+
19646 static struct kobj_type ktype_percpu_entry = {
19647 .sysfs_ops = &sysfs_ops,
19648 };
19649@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
19650 return retval;
19651 }
19652
19653+#ifdef CONFIG_AMD_NB
19654+ amd_l3_attrs();
19655+#endif
19656+
19657 for (i = 0; i < num_cache_leaves; i++) {
19658+ struct kobj_type *ktype;
19659+
19660 this_object = INDEX_KOBJECT_PTR(cpu, i);
19661 this_object->cpu = cpu;
19662 this_object->index = i;
19663
19664 this_leaf = CPUID4_INFO_IDX(cpu, i);
19665
19666- ktype_cache.default_attrs = default_attrs;
19667+ ktype = &ktype_cache;
19668 #ifdef CONFIG_AMD_NB
19669 if (this_leaf->base.nb)
19670- ktype_cache.default_attrs = amd_l3_attrs();
19671+ ktype = &ktype_cache_amd_nb;
19672 #endif
19673 retval = kobject_init_and_add(&(this_object->kobj),
19674- &ktype_cache,
19675+ ktype,
19676 per_cpu(ici_cache_kobject, cpu),
19677 "index%1lu", i);
19678 if (unlikely(retval)) {
19679diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
19680index 87a65c9..92fcce6 100644
19681--- a/arch/x86/kernel/cpu/mcheck/mce.c
19682+++ b/arch/x86/kernel/cpu/mcheck/mce.c
19683@@ -45,6 +45,7 @@
19684 #include <asm/processor.h>
19685 #include <asm/mce.h>
19686 #include <asm/msr.h>
19687+#include <asm/local.h>
19688
19689 #include "mce-internal.h"
19690
19691@@ -249,7 +250,7 @@ static void print_mce(struct mce *m)
19692 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
19693 m->cs, m->ip);
19694
19695- if (m->cs == __KERNEL_CS)
19696+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
19697 print_symbol("{%s}", m->ip);
19698 pr_cont("\n");
19699 }
19700@@ -282,10 +283,10 @@ static void print_mce(struct mce *m)
19701
19702 #define PANIC_TIMEOUT 5 /* 5 seconds */
19703
19704-static atomic_t mce_paniced;
19705+static atomic_unchecked_t mce_paniced;
19706
19707 static int fake_panic;
19708-static atomic_t mce_fake_paniced;
19709+static atomic_unchecked_t mce_fake_paniced;
19710
19711 /* Panic in progress. Enable interrupts and wait for final IPI */
19712 static void wait_for_panic(void)
19713@@ -309,7 +310,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19714 /*
19715 * Make sure only one CPU runs in machine check panic
19716 */
19717- if (atomic_inc_return(&mce_paniced) > 1)
19718+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
19719 wait_for_panic();
19720 barrier();
19721
19722@@ -317,7 +318,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19723 console_verbose();
19724 } else {
19725 /* Don't log too much for fake panic */
19726- if (atomic_inc_return(&mce_fake_paniced) > 1)
19727+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
19728 return;
19729 }
19730 /* First print corrected ones that are still unlogged */
19731@@ -356,7 +357,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19732 if (!fake_panic) {
19733 if (panic_timeout == 0)
19734 panic_timeout = mca_cfg.panic_timeout;
19735- panic(msg);
19736+ panic("%s", msg);
19737 } else
19738 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
19739 }
19740@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
19741 * might have been modified by someone else.
19742 */
19743 rmb();
19744- if (atomic_read(&mce_paniced))
19745+ if (atomic_read_unchecked(&mce_paniced))
19746 wait_for_panic();
19747 if (!mca_cfg.monarch_timeout)
19748 goto out;
19749@@ -1657,7 +1658,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
19750 }
19751
19752 /* Call the installed machine check handler for this CPU setup. */
19753-void (*machine_check_vector)(struct pt_regs *, long error_code) =
19754+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
19755 unexpected_machine_check;
19756
19757 /*
19758@@ -1680,7 +1681,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
19759 return;
19760 }
19761
19762+ pax_open_kernel();
19763 machine_check_vector = do_machine_check;
19764+ pax_close_kernel();
19765
19766 __mcheck_cpu_init_generic();
19767 __mcheck_cpu_init_vendor(c);
19768@@ -1694,7 +1697,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
19769 */
19770
19771 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
19772-static int mce_chrdev_open_count; /* #times opened */
19773+static local_t mce_chrdev_open_count; /* #times opened */
19774 static int mce_chrdev_open_exclu; /* already open exclusive? */
19775
19776 static int mce_chrdev_open(struct inode *inode, struct file *file)
19777@@ -1702,7 +1705,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19778 spin_lock(&mce_chrdev_state_lock);
19779
19780 if (mce_chrdev_open_exclu ||
19781- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
19782+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
19783 spin_unlock(&mce_chrdev_state_lock);
19784
19785 return -EBUSY;
19786@@ -1710,7 +1713,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19787
19788 if (file->f_flags & O_EXCL)
19789 mce_chrdev_open_exclu = 1;
19790- mce_chrdev_open_count++;
19791+ local_inc(&mce_chrdev_open_count);
19792
19793 spin_unlock(&mce_chrdev_state_lock);
19794
19795@@ -1721,7 +1724,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
19796 {
19797 spin_lock(&mce_chrdev_state_lock);
19798
19799- mce_chrdev_open_count--;
19800+ local_dec(&mce_chrdev_open_count);
19801 mce_chrdev_open_exclu = 0;
19802
19803 spin_unlock(&mce_chrdev_state_lock);
19804@@ -2376,7 +2379,7 @@ static __init void mce_init_banks(void)
19805
19806 for (i = 0; i < mca_cfg.banks; i++) {
19807 struct mce_bank *b = &mce_banks[i];
19808- struct device_attribute *a = &b->attr;
19809+ device_attribute_no_const *a = &b->attr;
19810
19811 sysfs_attr_init(&a->attr);
19812 a->attr.name = b->attrname;
19813@@ -2444,7 +2447,7 @@ struct dentry *mce_get_debugfs_dir(void)
19814 static void mce_reset(void)
19815 {
19816 cpu_missing = 0;
19817- atomic_set(&mce_fake_paniced, 0);
19818+ atomic_set_unchecked(&mce_fake_paniced, 0);
19819 atomic_set(&mce_executing, 0);
19820 atomic_set(&mce_callin, 0);
19821 atomic_set(&global_nwo, 0);
19822diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
19823index 1c044b1..37a2a43 100644
19824--- a/arch/x86/kernel/cpu/mcheck/p5.c
19825+++ b/arch/x86/kernel/cpu/mcheck/p5.c
19826@@ -11,6 +11,7 @@
19827 #include <asm/processor.h>
19828 #include <asm/mce.h>
19829 #include <asm/msr.h>
19830+#include <asm/pgtable.h>
19831
19832 /* By default disabled */
19833 int mce_p5_enabled __read_mostly;
19834@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
19835 if (!cpu_has(c, X86_FEATURE_MCE))
19836 return;
19837
19838+ pax_open_kernel();
19839 machine_check_vector = pentium_machine_check;
19840+ pax_close_kernel();
19841 /* Make sure the vector pointer is visible before we enable MCEs: */
19842 wmb();
19843
19844diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
19845index e9a701a..35317d6 100644
19846--- a/arch/x86/kernel/cpu/mcheck/winchip.c
19847+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
19848@@ -10,6 +10,7 @@
19849 #include <asm/processor.h>
19850 #include <asm/mce.h>
19851 #include <asm/msr.h>
19852+#include <asm/pgtable.h>
19853
19854 /* Machine check handler for WinChip C6: */
19855 static void winchip_machine_check(struct pt_regs *regs, long error_code)
19856@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
19857 {
19858 u32 lo, hi;
19859
19860+ pax_open_kernel();
19861 machine_check_vector = winchip_machine_check;
19862+ pax_close_kernel();
19863 /* Make sure the vector pointer is visible before we enable MCEs: */
19864 wmb();
19865
19866diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
19867index f961de9..8a9d332 100644
19868--- a/arch/x86/kernel/cpu/mtrr/main.c
19869+++ b/arch/x86/kernel/cpu/mtrr/main.c
19870@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
19871 u64 size_or_mask, size_and_mask;
19872 static bool mtrr_aps_delayed_init;
19873
19874-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
19875+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
19876
19877 const struct mtrr_ops *mtrr_if;
19878
19879diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
19880index df5e41f..816c719 100644
19881--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
19882+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
19883@@ -25,7 +25,7 @@ struct mtrr_ops {
19884 int (*validate_add_page)(unsigned long base, unsigned long size,
19885 unsigned int type);
19886 int (*have_wrcomb)(void);
19887-};
19888+} __do_const;
19889
19890 extern int generic_get_free_region(unsigned long base, unsigned long size,
19891 int replace_reg);
19892diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
19893index a7c7305..b9705ab 100644
19894--- a/arch/x86/kernel/cpu/perf_event.c
19895+++ b/arch/x86/kernel/cpu/perf_event.c
19896@@ -1348,7 +1348,7 @@ static void __init pmu_check_apic(void)
19897 pr_info("no hardware sampling interrupt available.\n");
19898 }
19899
19900-static struct attribute_group x86_pmu_format_group = {
19901+static attribute_group_no_const x86_pmu_format_group = {
19902 .name = "format",
19903 .attrs = NULL,
19904 };
19905@@ -1447,7 +1447,7 @@ static struct attribute *events_attr[] = {
19906 NULL,
19907 };
19908
19909-static struct attribute_group x86_pmu_events_group = {
19910+static attribute_group_no_const x86_pmu_events_group = {
19911 .name = "events",
19912 .attrs = events_attr,
19913 };
19914@@ -1957,7 +1957,7 @@ static unsigned long get_segment_base(unsigned int segment)
19915 if (idx > GDT_ENTRIES)
19916 return 0;
19917
19918- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
19919+ desc = get_cpu_gdt_table(smp_processor_id());
19920 }
19921
19922 return get_desc_base(desc + idx);
19923@@ -2047,7 +2047,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
19924 break;
19925
19926 perf_callchain_store(entry, frame.return_address);
19927- fp = frame.next_frame;
19928+ fp = (const void __force_user *)frame.next_frame;
19929 }
19930 }
19931
19932diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
19933index 639d128..e92d7e5 100644
19934--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
19935+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
19936@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
19937 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
19938 {
19939 struct attribute **attrs;
19940- struct attribute_group *attr_group;
19941+ attribute_group_no_const *attr_group;
19942 int i = 0, j;
19943
19944 while (amd_iommu_v2_event_descs[i].attr.attr.name)
19945diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
19946index a45d8d4..8abd32c 100644
19947--- a/arch/x86/kernel/cpu/perf_event_intel.c
19948+++ b/arch/x86/kernel/cpu/perf_event_intel.c
19949@@ -2099,10 +2099,10 @@ __init int intel_pmu_init(void)
19950 * v2 and above have a perf capabilities MSR
19951 */
19952 if (version > 1) {
19953- u64 capabilities;
19954+ u64 capabilities = x86_pmu.intel_cap.capabilities;
19955
19956- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
19957- x86_pmu.intel_cap.capabilities = capabilities;
19958+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
19959+ x86_pmu.intel_cap.capabilities = capabilities;
19960 }
19961
19962 intel_ds_init();
19963diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
19964index 1fb6c72..f5fa2a3 100644
19965--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
19966+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
19967@@ -3095,7 +3095,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
19968 static int __init uncore_type_init(struct intel_uncore_type *type)
19969 {
19970 struct intel_uncore_pmu *pmus;
19971- struct attribute_group *attr_group;
19972+ attribute_group_no_const *attr_group;
19973 struct attribute **attrs;
19974 int i, j;
19975
19976diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
19977index 47b3d00c..2cf1751 100644
19978--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
19979+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
19980@@ -488,7 +488,7 @@ struct intel_uncore_box {
19981 struct uncore_event_desc {
19982 struct kobj_attribute attr;
19983 const char *config;
19984-};
19985+} __do_const;
19986
19987 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
19988 { \
19989diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
19990index 7d9481c..99c7e4b 100644
19991--- a/arch/x86/kernel/cpuid.c
19992+++ b/arch/x86/kernel/cpuid.c
19993@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
19994 return notifier_from_errno(err);
19995 }
19996
19997-static struct notifier_block __refdata cpuid_class_cpu_notifier =
19998+static struct notifier_block cpuid_class_cpu_notifier =
19999 {
20000 .notifier_call = cpuid_class_cpu_callback,
20001 };
20002diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
20003index 74467fe..18793d5 100644
20004--- a/arch/x86/kernel/crash.c
20005+++ b/arch/x86/kernel/crash.c
20006@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
20007 {
20008 #ifdef CONFIG_X86_32
20009 struct pt_regs fixed_regs;
20010-#endif
20011
20012-#ifdef CONFIG_X86_32
20013- if (!user_mode_vm(regs)) {
20014+ if (!user_mode(regs)) {
20015 crash_fixup_ss_esp(&fixed_regs, regs);
20016 regs = &fixed_regs;
20017 }
20018diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
20019index afa64ad..dce67dd 100644
20020--- a/arch/x86/kernel/crash_dump_64.c
20021+++ b/arch/x86/kernel/crash_dump_64.c
20022@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
20023 return -ENOMEM;
20024
20025 if (userbuf) {
20026- if (copy_to_user(buf, vaddr + offset, csize)) {
20027+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
20028 iounmap(vaddr);
20029 return -EFAULT;
20030 }
20031diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
20032index 5d3fe8d..02e1429 100644
20033--- a/arch/x86/kernel/doublefault.c
20034+++ b/arch/x86/kernel/doublefault.c
20035@@ -13,7 +13,7 @@
20036
20037 #define DOUBLEFAULT_STACKSIZE (1024)
20038 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
20039-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
20040+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
20041
20042 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
20043
20044@@ -23,7 +23,7 @@ static void doublefault_fn(void)
20045 unsigned long gdt, tss;
20046
20047 native_store_gdt(&gdt_desc);
20048- gdt = gdt_desc.address;
20049+ gdt = (unsigned long)gdt_desc.address;
20050
20051 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
20052
20053@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
20054 /* 0x2 bit is always set */
20055 .flags = X86_EFLAGS_SF | 0x2,
20056 .sp = STACK_START,
20057- .es = __USER_DS,
20058+ .es = __KERNEL_DS,
20059 .cs = __KERNEL_CS,
20060 .ss = __KERNEL_DS,
20061- .ds = __USER_DS,
20062+ .ds = __KERNEL_DS,
20063 .fs = __KERNEL_PERCPU,
20064
20065 .__cr3 = __pa_nodebug(swapper_pg_dir),
20066diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
20067index deb6421..76bbc12 100644
20068--- a/arch/x86/kernel/dumpstack.c
20069+++ b/arch/x86/kernel/dumpstack.c
20070@@ -2,6 +2,9 @@
20071 * Copyright (C) 1991, 1992 Linus Torvalds
20072 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
20073 */
20074+#ifdef CONFIG_GRKERNSEC_HIDESYM
20075+#define __INCLUDED_BY_HIDESYM 1
20076+#endif
20077 #include <linux/kallsyms.h>
20078 #include <linux/kprobes.h>
20079 #include <linux/uaccess.h>
20080@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
20081 static void
20082 print_ftrace_graph_addr(unsigned long addr, void *data,
20083 const struct stacktrace_ops *ops,
20084- struct thread_info *tinfo, int *graph)
20085+ struct task_struct *task, int *graph)
20086 {
20087- struct task_struct *task;
20088 unsigned long ret_addr;
20089 int index;
20090
20091 if (addr != (unsigned long)return_to_handler)
20092 return;
20093
20094- task = tinfo->task;
20095 index = task->curr_ret_stack;
20096
20097 if (!task->ret_stack || index < *graph)
20098@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20099 static inline void
20100 print_ftrace_graph_addr(unsigned long addr, void *data,
20101 const struct stacktrace_ops *ops,
20102- struct thread_info *tinfo, int *graph)
20103+ struct task_struct *task, int *graph)
20104 { }
20105 #endif
20106
20107@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20108 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
20109 */
20110
20111-static inline int valid_stack_ptr(struct thread_info *tinfo,
20112- void *p, unsigned int size, void *end)
20113+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
20114 {
20115- void *t = tinfo;
20116 if (end) {
20117 if (p < end && p >= (end-THREAD_SIZE))
20118 return 1;
20119@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
20120 }
20121
20122 unsigned long
20123-print_context_stack(struct thread_info *tinfo,
20124+print_context_stack(struct task_struct *task, void *stack_start,
20125 unsigned long *stack, unsigned long bp,
20126 const struct stacktrace_ops *ops, void *data,
20127 unsigned long *end, int *graph)
20128 {
20129 struct stack_frame *frame = (struct stack_frame *)bp;
20130
20131- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
20132+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
20133 unsigned long addr;
20134
20135 addr = *stack;
20136@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
20137 } else {
20138 ops->address(data, addr, 0);
20139 }
20140- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20141+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20142 }
20143 stack++;
20144 }
20145@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
20146 EXPORT_SYMBOL_GPL(print_context_stack);
20147
20148 unsigned long
20149-print_context_stack_bp(struct thread_info *tinfo,
20150+print_context_stack_bp(struct task_struct *task, void *stack_start,
20151 unsigned long *stack, unsigned long bp,
20152 const struct stacktrace_ops *ops, void *data,
20153 unsigned long *end, int *graph)
20154@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20155 struct stack_frame *frame = (struct stack_frame *)bp;
20156 unsigned long *ret_addr = &frame->return_address;
20157
20158- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
20159+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
20160 unsigned long addr = *ret_addr;
20161
20162 if (!__kernel_text_address(addr))
20163@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20164 ops->address(data, addr, 1);
20165 frame = frame->next_frame;
20166 ret_addr = &frame->return_address;
20167- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20168+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20169 }
20170
20171 return (unsigned long)frame;
20172@@ -150,7 +149,7 @@ static int print_trace_stack(void *data, char *name)
20173 static void print_trace_address(void *data, unsigned long addr, int reliable)
20174 {
20175 touch_nmi_watchdog();
20176- printk(data);
20177+ printk("%s", (char *)data);
20178 printk_address(addr, reliable);
20179 }
20180
20181@@ -219,6 +218,8 @@ unsigned __kprobes long oops_begin(void)
20182 }
20183 EXPORT_SYMBOL_GPL(oops_begin);
20184
20185+extern void gr_handle_kernel_exploit(void);
20186+
20187 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20188 {
20189 if (regs && kexec_should_crash(current))
20190@@ -240,7 +241,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20191 panic("Fatal exception in interrupt");
20192 if (panic_on_oops)
20193 panic("Fatal exception");
20194- do_exit(signr);
20195+
20196+ gr_handle_kernel_exploit();
20197+
20198+ do_group_exit(signr);
20199 }
20200
20201 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20202@@ -268,7 +272,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20203 print_modules();
20204 show_regs(regs);
20205 #ifdef CONFIG_X86_32
20206- if (user_mode_vm(regs)) {
20207+ if (user_mode(regs)) {
20208 sp = regs->sp;
20209 ss = regs->ss & 0xffff;
20210 } else {
20211@@ -296,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
20212 unsigned long flags = oops_begin();
20213 int sig = SIGSEGV;
20214
20215- if (!user_mode_vm(regs))
20216+ if (!user_mode(regs))
20217 report_bug(regs->ip, regs);
20218
20219 if (__die(str, regs, err))
20220diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
20221index f2a1770..540657f 100644
20222--- a/arch/x86/kernel/dumpstack_32.c
20223+++ b/arch/x86/kernel/dumpstack_32.c
20224@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20225 bp = stack_frame(task, regs);
20226
20227 for (;;) {
20228- struct thread_info *context;
20229+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20230
20231- context = (struct thread_info *)
20232- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
20233- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
20234+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20235
20236- stack = (unsigned long *)context->previous_esp;
20237- if (!stack)
20238+ if (stack_start == task_stack_page(task))
20239 break;
20240+ stack = *(unsigned long **)stack_start;
20241 if (ops->stack(data, "IRQ") < 0)
20242 break;
20243 touch_nmi_watchdog();
20244@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
20245 int i;
20246
20247 show_regs_print_info(KERN_EMERG);
20248- __show_regs(regs, !user_mode_vm(regs));
20249+ __show_regs(regs, !user_mode(regs));
20250
20251 /*
20252 * When in-kernel, we also print out the stack and code at the
20253 * time of the fault..
20254 */
20255- if (!user_mode_vm(regs)) {
20256+ if (!user_mode(regs)) {
20257 unsigned int code_prologue = code_bytes * 43 / 64;
20258 unsigned int code_len = code_bytes;
20259 unsigned char c;
20260 u8 *ip;
20261+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
20262
20263 pr_emerg("Stack:\n");
20264 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
20265
20266 pr_emerg("Code:");
20267
20268- ip = (u8 *)regs->ip - code_prologue;
20269+ ip = (u8 *)regs->ip - code_prologue + cs_base;
20270 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
20271 /* try starting at IP */
20272- ip = (u8 *)regs->ip;
20273+ ip = (u8 *)regs->ip + cs_base;
20274 code_len = code_len - code_prologue + 1;
20275 }
20276 for (i = 0; i < code_len; i++, ip++) {
20277@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
20278 pr_cont(" Bad EIP value.");
20279 break;
20280 }
20281- if (ip == (u8 *)regs->ip)
20282+ if (ip == (u8 *)regs->ip + cs_base)
20283 pr_cont(" <%02x>", c);
20284 else
20285 pr_cont(" %02x", c);
20286@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
20287 {
20288 unsigned short ud2;
20289
20290+ ip = ktla_ktva(ip);
20291 if (ip < PAGE_OFFSET)
20292 return 0;
20293 if (probe_kernel_address((unsigned short *)ip, ud2))
20294@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
20295
20296 return ud2 == 0x0b0f;
20297 }
20298+
20299+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20300+void pax_check_alloca(unsigned long size)
20301+{
20302+ unsigned long sp = (unsigned long)&sp, stack_left;
20303+
20304+ /* all kernel stacks are of the same size */
20305+ stack_left = sp & (THREAD_SIZE - 1);
20306+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20307+}
20308+EXPORT_SYMBOL(pax_check_alloca);
20309+#endif
20310diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
20311index addb207..99635fa 100644
20312--- a/arch/x86/kernel/dumpstack_64.c
20313+++ b/arch/x86/kernel/dumpstack_64.c
20314@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20315 unsigned long *irq_stack_end =
20316 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
20317 unsigned used = 0;
20318- struct thread_info *tinfo;
20319 int graph = 0;
20320 unsigned long dummy;
20321+ void *stack_start;
20322
20323 if (!task)
20324 task = current;
20325@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20326 * current stack address. If the stacks consist of nested
20327 * exceptions
20328 */
20329- tinfo = task_thread_info(task);
20330 for (;;) {
20331 char *id;
20332 unsigned long *estack_end;
20333+
20334 estack_end = in_exception_stack(cpu, (unsigned long)stack,
20335 &used, &id);
20336
20337@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20338 if (ops->stack(data, id) < 0)
20339 break;
20340
20341- bp = ops->walk_stack(tinfo, stack, bp, ops,
20342+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
20343 data, estack_end, &graph);
20344 ops->stack(data, "<EOE>");
20345 /*
20346@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20347 * second-to-last pointer (index -2 to end) in the
20348 * exception stack:
20349 */
20350+ if ((u16)estack_end[-1] != __KERNEL_DS)
20351+ goto out;
20352 stack = (unsigned long *) estack_end[-2];
20353 continue;
20354 }
20355@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20356 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
20357 if (ops->stack(data, "IRQ") < 0)
20358 break;
20359- bp = ops->walk_stack(tinfo, stack, bp,
20360+ bp = ops->walk_stack(task, irq_stack, stack, bp,
20361 ops, data, irq_stack_end, &graph);
20362 /*
20363 * We link to the next stack (which would be
20364@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20365 /*
20366 * This handles the process stack:
20367 */
20368- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
20369+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20370+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20371+out:
20372 put_cpu();
20373 }
20374 EXPORT_SYMBOL(dump_trace);
20375@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
20376
20377 return ud2 == 0x0b0f;
20378 }
20379+
20380+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20381+void pax_check_alloca(unsigned long size)
20382+{
20383+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
20384+ unsigned cpu, used;
20385+ char *id;
20386+
20387+ /* check the process stack first */
20388+ stack_start = (unsigned long)task_stack_page(current);
20389+ stack_end = stack_start + THREAD_SIZE;
20390+ if (likely(stack_start <= sp && sp < stack_end)) {
20391+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
20392+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20393+ return;
20394+ }
20395+
20396+ cpu = get_cpu();
20397+
20398+ /* check the irq stacks */
20399+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
20400+ stack_start = stack_end - IRQ_STACK_SIZE;
20401+ if (stack_start <= sp && sp < stack_end) {
20402+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
20403+ put_cpu();
20404+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20405+ return;
20406+ }
20407+
20408+ /* check the exception stacks */
20409+ used = 0;
20410+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
20411+ stack_start = stack_end - EXCEPTION_STKSZ;
20412+ if (stack_end && stack_start <= sp && sp < stack_end) {
20413+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
20414+ put_cpu();
20415+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20416+ return;
20417+ }
20418+
20419+ put_cpu();
20420+
20421+ /* unknown stack */
20422+ BUG();
20423+}
20424+EXPORT_SYMBOL(pax_check_alloca);
20425+#endif
20426diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
20427index d32abea..74daf4f 100644
20428--- a/arch/x86/kernel/e820.c
20429+++ b/arch/x86/kernel/e820.c
20430@@ -800,8 +800,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
20431
20432 static void early_panic(char *msg)
20433 {
20434- early_printk(msg);
20435- panic(msg);
20436+ early_printk("%s", msg);
20437+ panic("%s", msg);
20438 }
20439
20440 static int userdef __initdata;
20441diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
20442index d15f575..d692043 100644
20443--- a/arch/x86/kernel/early_printk.c
20444+++ b/arch/x86/kernel/early_printk.c
20445@@ -7,6 +7,7 @@
20446 #include <linux/pci_regs.h>
20447 #include <linux/pci_ids.h>
20448 #include <linux/errno.h>
20449+#include <linux/sched.h>
20450 #include <asm/io.h>
20451 #include <asm/processor.h>
20452 #include <asm/fcntl.h>
20453diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
20454index 2cfbc3a..b756682 100644
20455--- a/arch/x86/kernel/entry_32.S
20456+++ b/arch/x86/kernel/entry_32.S
20457@@ -177,13 +177,153 @@
20458 /*CFI_REL_OFFSET gs, PT_GS*/
20459 .endm
20460 .macro SET_KERNEL_GS reg
20461+
20462+#ifdef CONFIG_CC_STACKPROTECTOR
20463 movl $(__KERNEL_STACK_CANARY), \reg
20464+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20465+ movl $(__USER_DS), \reg
20466+#else
20467+ xorl \reg, \reg
20468+#endif
20469+
20470 movl \reg, %gs
20471 .endm
20472
20473 #endif /* CONFIG_X86_32_LAZY_GS */
20474
20475-.macro SAVE_ALL
20476+.macro pax_enter_kernel
20477+#ifdef CONFIG_PAX_KERNEXEC
20478+ call pax_enter_kernel
20479+#endif
20480+.endm
20481+
20482+.macro pax_exit_kernel
20483+#ifdef CONFIG_PAX_KERNEXEC
20484+ call pax_exit_kernel
20485+#endif
20486+.endm
20487+
20488+#ifdef CONFIG_PAX_KERNEXEC
20489+ENTRY(pax_enter_kernel)
20490+#ifdef CONFIG_PARAVIRT
20491+ pushl %eax
20492+ pushl %ecx
20493+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
20494+ mov %eax, %esi
20495+#else
20496+ mov %cr0, %esi
20497+#endif
20498+ bts $16, %esi
20499+ jnc 1f
20500+ mov %cs, %esi
20501+ cmp $__KERNEL_CS, %esi
20502+ jz 3f
20503+ ljmp $__KERNEL_CS, $3f
20504+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
20505+2:
20506+#ifdef CONFIG_PARAVIRT
20507+ mov %esi, %eax
20508+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
20509+#else
20510+ mov %esi, %cr0
20511+#endif
20512+3:
20513+#ifdef CONFIG_PARAVIRT
20514+ popl %ecx
20515+ popl %eax
20516+#endif
20517+ ret
20518+ENDPROC(pax_enter_kernel)
20519+
20520+ENTRY(pax_exit_kernel)
20521+#ifdef CONFIG_PARAVIRT
20522+ pushl %eax
20523+ pushl %ecx
20524+#endif
20525+ mov %cs, %esi
20526+ cmp $__KERNEXEC_KERNEL_CS, %esi
20527+ jnz 2f
20528+#ifdef CONFIG_PARAVIRT
20529+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
20530+ mov %eax, %esi
20531+#else
20532+ mov %cr0, %esi
20533+#endif
20534+ btr $16, %esi
20535+ ljmp $__KERNEL_CS, $1f
20536+1:
20537+#ifdef CONFIG_PARAVIRT
20538+ mov %esi, %eax
20539+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
20540+#else
20541+ mov %esi, %cr0
20542+#endif
20543+2:
20544+#ifdef CONFIG_PARAVIRT
20545+ popl %ecx
20546+ popl %eax
20547+#endif
20548+ ret
20549+ENDPROC(pax_exit_kernel)
20550+#endif
20551+
20552+ .macro pax_erase_kstack
20553+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20554+ call pax_erase_kstack
20555+#endif
20556+ .endm
20557+
20558+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20559+/*
20560+ * ebp: thread_info
20561+ */
20562+ENTRY(pax_erase_kstack)
20563+ pushl %edi
20564+ pushl %ecx
20565+ pushl %eax
20566+
20567+ mov TI_lowest_stack(%ebp), %edi
20568+ mov $-0xBEEF, %eax
20569+ std
20570+
20571+1: mov %edi, %ecx
20572+ and $THREAD_SIZE_asm - 1, %ecx
20573+ shr $2, %ecx
20574+ repne scasl
20575+ jecxz 2f
20576+
20577+ cmp $2*16, %ecx
20578+ jc 2f
20579+
20580+ mov $2*16, %ecx
20581+ repe scasl
20582+ jecxz 2f
20583+ jne 1b
20584+
20585+2: cld
20586+ mov %esp, %ecx
20587+ sub %edi, %ecx
20588+
20589+ cmp $THREAD_SIZE_asm, %ecx
20590+ jb 3f
20591+ ud2
20592+3:
20593+
20594+ shr $2, %ecx
20595+ rep stosl
20596+
20597+ mov TI_task_thread_sp0(%ebp), %edi
20598+ sub $128, %edi
20599+ mov %edi, TI_lowest_stack(%ebp)
20600+
20601+ popl %eax
20602+ popl %ecx
20603+ popl %edi
20604+ ret
20605+ENDPROC(pax_erase_kstack)
20606+#endif
20607+
20608+.macro __SAVE_ALL _DS
20609 cld
20610 PUSH_GS
20611 pushl_cfi %fs
20612@@ -206,7 +346,7 @@
20613 CFI_REL_OFFSET ecx, 0
20614 pushl_cfi %ebx
20615 CFI_REL_OFFSET ebx, 0
20616- movl $(__USER_DS), %edx
20617+ movl $\_DS, %edx
20618 movl %edx, %ds
20619 movl %edx, %es
20620 movl $(__KERNEL_PERCPU), %edx
20621@@ -214,6 +354,15 @@
20622 SET_KERNEL_GS %edx
20623 .endm
20624
20625+.macro SAVE_ALL
20626+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20627+ __SAVE_ALL __KERNEL_DS
20628+ pax_enter_kernel
20629+#else
20630+ __SAVE_ALL __USER_DS
20631+#endif
20632+.endm
20633+
20634 .macro RESTORE_INT_REGS
20635 popl_cfi %ebx
20636 CFI_RESTORE ebx
20637@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
20638 popfl_cfi
20639 jmp syscall_exit
20640 CFI_ENDPROC
20641-END(ret_from_fork)
20642+ENDPROC(ret_from_fork)
20643
20644 ENTRY(ret_from_kernel_thread)
20645 CFI_STARTPROC
20646@@ -344,7 +493,15 @@ ret_from_intr:
20647 andl $SEGMENT_RPL_MASK, %eax
20648 #endif
20649 cmpl $USER_RPL, %eax
20650+
20651+#ifdef CONFIG_PAX_KERNEXEC
20652+ jae resume_userspace
20653+
20654+ pax_exit_kernel
20655+ jmp resume_kernel
20656+#else
20657 jb resume_kernel # not returning to v8086 or userspace
20658+#endif
20659
20660 ENTRY(resume_userspace)
20661 LOCKDEP_SYS_EXIT
20662@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
20663 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
20664 # int/exception return?
20665 jne work_pending
20666- jmp restore_all
20667-END(ret_from_exception)
20668+ jmp restore_all_pax
20669+ENDPROC(ret_from_exception)
20670
20671 #ifdef CONFIG_PREEMPT
20672 ENTRY(resume_kernel)
20673@@ -372,7 +529,7 @@ need_resched:
20674 jz restore_all
20675 call preempt_schedule_irq
20676 jmp need_resched
20677-END(resume_kernel)
20678+ENDPROC(resume_kernel)
20679 #endif
20680 CFI_ENDPROC
20681 /*
20682@@ -406,30 +563,45 @@ sysenter_past_esp:
20683 /*CFI_REL_OFFSET cs, 0*/
20684 /*
20685 * Push current_thread_info()->sysenter_return to the stack.
20686- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
20687- * pushed above; +8 corresponds to copy_thread's esp0 setting.
20688 */
20689- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
20690+ pushl_cfi $0
20691 CFI_REL_OFFSET eip, 0
20692
20693 pushl_cfi %eax
20694 SAVE_ALL
20695+ GET_THREAD_INFO(%ebp)
20696+ movl TI_sysenter_return(%ebp),%ebp
20697+ movl %ebp,PT_EIP(%esp)
20698 ENABLE_INTERRUPTS(CLBR_NONE)
20699
20700 /*
20701 * Load the potential sixth argument from user stack.
20702 * Careful about security.
20703 */
20704+ movl PT_OLDESP(%esp),%ebp
20705+
20706+#ifdef CONFIG_PAX_MEMORY_UDEREF
20707+ mov PT_OLDSS(%esp),%ds
20708+1: movl %ds:(%ebp),%ebp
20709+ push %ss
20710+ pop %ds
20711+#else
20712 cmpl $__PAGE_OFFSET-3,%ebp
20713 jae syscall_fault
20714 ASM_STAC
20715 1: movl (%ebp),%ebp
20716 ASM_CLAC
20717+#endif
20718+
20719 movl %ebp,PT_EBP(%esp)
20720 _ASM_EXTABLE(1b,syscall_fault)
20721
20722 GET_THREAD_INFO(%ebp)
20723
20724+#ifdef CONFIG_PAX_RANDKSTACK
20725+ pax_erase_kstack
20726+#endif
20727+
20728 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20729 jnz sysenter_audit
20730 sysenter_do_call:
20731@@ -444,12 +616,24 @@ sysenter_do_call:
20732 testl $_TIF_ALLWORK_MASK, %ecx
20733 jne sysexit_audit
20734 sysenter_exit:
20735+
20736+#ifdef CONFIG_PAX_RANDKSTACK
20737+ pushl_cfi %eax
20738+ movl %esp, %eax
20739+ call pax_randomize_kstack
20740+ popl_cfi %eax
20741+#endif
20742+
20743+ pax_erase_kstack
20744+
20745 /* if something modifies registers it must also disable sysexit */
20746 movl PT_EIP(%esp), %edx
20747 movl PT_OLDESP(%esp), %ecx
20748 xorl %ebp,%ebp
20749 TRACE_IRQS_ON
20750 1: mov PT_FS(%esp), %fs
20751+2: mov PT_DS(%esp), %ds
20752+3: mov PT_ES(%esp), %es
20753 PTGS_TO_GS
20754 ENABLE_INTERRUPTS_SYSEXIT
20755
20756@@ -466,6 +650,9 @@ sysenter_audit:
20757 movl %eax,%edx /* 2nd arg: syscall number */
20758 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
20759 call __audit_syscall_entry
20760+
20761+ pax_erase_kstack
20762+
20763 pushl_cfi %ebx
20764 movl PT_EAX(%esp),%eax /* reload syscall number */
20765 jmp sysenter_do_call
20766@@ -491,10 +678,16 @@ sysexit_audit:
20767
20768 CFI_ENDPROC
20769 .pushsection .fixup,"ax"
20770-2: movl $0,PT_FS(%esp)
20771+4: movl $0,PT_FS(%esp)
20772+ jmp 1b
20773+5: movl $0,PT_DS(%esp)
20774+ jmp 1b
20775+6: movl $0,PT_ES(%esp)
20776 jmp 1b
20777 .popsection
20778- _ASM_EXTABLE(1b,2b)
20779+ _ASM_EXTABLE(1b,4b)
20780+ _ASM_EXTABLE(2b,5b)
20781+ _ASM_EXTABLE(3b,6b)
20782 PTGS_TO_GS_EX
20783 ENDPROC(ia32_sysenter_target)
20784
20785@@ -509,6 +702,11 @@ ENTRY(system_call)
20786 pushl_cfi %eax # save orig_eax
20787 SAVE_ALL
20788 GET_THREAD_INFO(%ebp)
20789+
20790+#ifdef CONFIG_PAX_RANDKSTACK
20791+ pax_erase_kstack
20792+#endif
20793+
20794 # system call tracing in operation / emulation
20795 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20796 jnz syscall_trace_entry
20797@@ -527,6 +725,15 @@ syscall_exit:
20798 testl $_TIF_ALLWORK_MASK, %ecx # current->work
20799 jne syscall_exit_work
20800
20801+restore_all_pax:
20802+
20803+#ifdef CONFIG_PAX_RANDKSTACK
20804+ movl %esp, %eax
20805+ call pax_randomize_kstack
20806+#endif
20807+
20808+ pax_erase_kstack
20809+
20810 restore_all:
20811 TRACE_IRQS_IRET
20812 restore_all_notrace:
20813@@ -583,14 +790,34 @@ ldt_ss:
20814 * compensating for the offset by changing to the ESPFIX segment with
20815 * a base address that matches for the difference.
20816 */
20817-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
20818+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
20819 mov %esp, %edx /* load kernel esp */
20820 mov PT_OLDESP(%esp), %eax /* load userspace esp */
20821 mov %dx, %ax /* eax: new kernel esp */
20822 sub %eax, %edx /* offset (low word is 0) */
20823+#ifdef CONFIG_SMP
20824+ movl PER_CPU_VAR(cpu_number), %ebx
20825+ shll $PAGE_SHIFT_asm, %ebx
20826+ addl $cpu_gdt_table, %ebx
20827+#else
20828+ movl $cpu_gdt_table, %ebx
20829+#endif
20830 shr $16, %edx
20831- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
20832- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
20833+
20834+#ifdef CONFIG_PAX_KERNEXEC
20835+ mov %cr0, %esi
20836+ btr $16, %esi
20837+ mov %esi, %cr0
20838+#endif
20839+
20840+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
20841+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
20842+
20843+#ifdef CONFIG_PAX_KERNEXEC
20844+ bts $16, %esi
20845+ mov %esi, %cr0
20846+#endif
20847+
20848 pushl_cfi $__ESPFIX_SS
20849 pushl_cfi %eax /* new kernel esp */
20850 /* Disable interrupts, but do not irqtrace this section: we
20851@@ -619,20 +846,18 @@ work_resched:
20852 movl TI_flags(%ebp), %ecx
20853 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
20854 # than syscall tracing?
20855- jz restore_all
20856+ jz restore_all_pax
20857 testb $_TIF_NEED_RESCHED, %cl
20858 jnz work_resched
20859
20860 work_notifysig: # deal with pending signals and
20861 # notify-resume requests
20862+ movl %esp, %eax
20863 #ifdef CONFIG_VM86
20864 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
20865- movl %esp, %eax
20866 jne work_notifysig_v86 # returning to kernel-space or
20867 # vm86-space
20868 1:
20869-#else
20870- movl %esp, %eax
20871 #endif
20872 TRACE_IRQS_ON
20873 ENABLE_INTERRUPTS(CLBR_NONE)
20874@@ -653,7 +878,7 @@ work_notifysig_v86:
20875 movl %eax, %esp
20876 jmp 1b
20877 #endif
20878-END(work_pending)
20879+ENDPROC(work_pending)
20880
20881 # perform syscall exit tracing
20882 ALIGN
20883@@ -661,11 +886,14 @@ syscall_trace_entry:
20884 movl $-ENOSYS,PT_EAX(%esp)
20885 movl %esp, %eax
20886 call syscall_trace_enter
20887+
20888+ pax_erase_kstack
20889+
20890 /* What it returned is what we'll actually use. */
20891 cmpl $(NR_syscalls), %eax
20892 jnae syscall_call
20893 jmp syscall_exit
20894-END(syscall_trace_entry)
20895+ENDPROC(syscall_trace_entry)
20896
20897 # perform syscall exit tracing
20898 ALIGN
20899@@ -678,21 +906,25 @@ syscall_exit_work:
20900 movl %esp, %eax
20901 call syscall_trace_leave
20902 jmp resume_userspace
20903-END(syscall_exit_work)
20904+ENDPROC(syscall_exit_work)
20905 CFI_ENDPROC
20906
20907 RING0_INT_FRAME # can't unwind into user space anyway
20908 syscall_fault:
20909+#ifdef CONFIG_PAX_MEMORY_UDEREF
20910+ push %ss
20911+ pop %ds
20912+#endif
20913 ASM_CLAC
20914 GET_THREAD_INFO(%ebp)
20915 movl $-EFAULT,PT_EAX(%esp)
20916 jmp resume_userspace
20917-END(syscall_fault)
20918+ENDPROC(syscall_fault)
20919
20920 syscall_badsys:
20921 movl $-ENOSYS,PT_EAX(%esp)
20922 jmp resume_userspace
20923-END(syscall_badsys)
20924+ENDPROC(syscall_badsys)
20925 CFI_ENDPROC
20926 /*
20927 * End of kprobes section
20928@@ -708,8 +940,15 @@ END(syscall_badsys)
20929 * normal stack and adjusts ESP with the matching offset.
20930 */
20931 /* fixup the stack */
20932- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
20933- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
20934+#ifdef CONFIG_SMP
20935+ movl PER_CPU_VAR(cpu_number), %ebx
20936+ shll $PAGE_SHIFT_asm, %ebx
20937+ addl $cpu_gdt_table, %ebx
20938+#else
20939+ movl $cpu_gdt_table, %ebx
20940+#endif
20941+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
20942+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
20943 shl $16, %eax
20944 addl %esp, %eax /* the adjusted stack pointer */
20945 pushl_cfi $__KERNEL_DS
20946@@ -762,7 +1001,7 @@ vector=vector+1
20947 .endr
20948 2: jmp common_interrupt
20949 .endr
20950-END(irq_entries_start)
20951+ENDPROC(irq_entries_start)
20952
20953 .previous
20954 END(interrupt)
20955@@ -823,7 +1062,7 @@ ENTRY(coprocessor_error)
20956 pushl_cfi $do_coprocessor_error
20957 jmp error_code
20958 CFI_ENDPROC
20959-END(coprocessor_error)
20960+ENDPROC(coprocessor_error)
20961
20962 ENTRY(simd_coprocessor_error)
20963 RING0_INT_FRAME
20964@@ -836,7 +1075,7 @@ ENTRY(simd_coprocessor_error)
20965 .section .altinstructions,"a"
20966 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
20967 .previous
20968-.section .altinstr_replacement,"ax"
20969+.section .altinstr_replacement,"a"
20970 663: pushl $do_simd_coprocessor_error
20971 664:
20972 .previous
20973@@ -845,7 +1084,7 @@ ENTRY(simd_coprocessor_error)
20974 #endif
20975 jmp error_code
20976 CFI_ENDPROC
20977-END(simd_coprocessor_error)
20978+ENDPROC(simd_coprocessor_error)
20979
20980 ENTRY(device_not_available)
20981 RING0_INT_FRAME
20982@@ -854,18 +1093,18 @@ ENTRY(device_not_available)
20983 pushl_cfi $do_device_not_available
20984 jmp error_code
20985 CFI_ENDPROC
20986-END(device_not_available)
20987+ENDPROC(device_not_available)
20988
20989 #ifdef CONFIG_PARAVIRT
20990 ENTRY(native_iret)
20991 iret
20992 _ASM_EXTABLE(native_iret, iret_exc)
20993-END(native_iret)
20994+ENDPROC(native_iret)
20995
20996 ENTRY(native_irq_enable_sysexit)
20997 sti
20998 sysexit
20999-END(native_irq_enable_sysexit)
21000+ENDPROC(native_irq_enable_sysexit)
21001 #endif
21002
21003 ENTRY(overflow)
21004@@ -875,7 +1114,7 @@ ENTRY(overflow)
21005 pushl_cfi $do_overflow
21006 jmp error_code
21007 CFI_ENDPROC
21008-END(overflow)
21009+ENDPROC(overflow)
21010
21011 ENTRY(bounds)
21012 RING0_INT_FRAME
21013@@ -884,7 +1123,7 @@ ENTRY(bounds)
21014 pushl_cfi $do_bounds
21015 jmp error_code
21016 CFI_ENDPROC
21017-END(bounds)
21018+ENDPROC(bounds)
21019
21020 ENTRY(invalid_op)
21021 RING0_INT_FRAME
21022@@ -893,7 +1132,7 @@ ENTRY(invalid_op)
21023 pushl_cfi $do_invalid_op
21024 jmp error_code
21025 CFI_ENDPROC
21026-END(invalid_op)
21027+ENDPROC(invalid_op)
21028
21029 ENTRY(coprocessor_segment_overrun)
21030 RING0_INT_FRAME
21031@@ -902,7 +1141,7 @@ ENTRY(coprocessor_segment_overrun)
21032 pushl_cfi $do_coprocessor_segment_overrun
21033 jmp error_code
21034 CFI_ENDPROC
21035-END(coprocessor_segment_overrun)
21036+ENDPROC(coprocessor_segment_overrun)
21037
21038 ENTRY(invalid_TSS)
21039 RING0_EC_FRAME
21040@@ -910,7 +1149,7 @@ ENTRY(invalid_TSS)
21041 pushl_cfi $do_invalid_TSS
21042 jmp error_code
21043 CFI_ENDPROC
21044-END(invalid_TSS)
21045+ENDPROC(invalid_TSS)
21046
21047 ENTRY(segment_not_present)
21048 RING0_EC_FRAME
21049@@ -918,7 +1157,7 @@ ENTRY(segment_not_present)
21050 pushl_cfi $do_segment_not_present
21051 jmp error_code
21052 CFI_ENDPROC
21053-END(segment_not_present)
21054+ENDPROC(segment_not_present)
21055
21056 ENTRY(stack_segment)
21057 RING0_EC_FRAME
21058@@ -926,7 +1165,7 @@ ENTRY(stack_segment)
21059 pushl_cfi $do_stack_segment
21060 jmp error_code
21061 CFI_ENDPROC
21062-END(stack_segment)
21063+ENDPROC(stack_segment)
21064
21065 ENTRY(alignment_check)
21066 RING0_EC_FRAME
21067@@ -934,7 +1173,7 @@ ENTRY(alignment_check)
21068 pushl_cfi $do_alignment_check
21069 jmp error_code
21070 CFI_ENDPROC
21071-END(alignment_check)
21072+ENDPROC(alignment_check)
21073
21074 ENTRY(divide_error)
21075 RING0_INT_FRAME
21076@@ -943,7 +1182,7 @@ ENTRY(divide_error)
21077 pushl_cfi $do_divide_error
21078 jmp error_code
21079 CFI_ENDPROC
21080-END(divide_error)
21081+ENDPROC(divide_error)
21082
21083 #ifdef CONFIG_X86_MCE
21084 ENTRY(machine_check)
21085@@ -953,7 +1192,7 @@ ENTRY(machine_check)
21086 pushl_cfi machine_check_vector
21087 jmp error_code
21088 CFI_ENDPROC
21089-END(machine_check)
21090+ENDPROC(machine_check)
21091 #endif
21092
21093 ENTRY(spurious_interrupt_bug)
21094@@ -963,7 +1202,7 @@ ENTRY(spurious_interrupt_bug)
21095 pushl_cfi $do_spurious_interrupt_bug
21096 jmp error_code
21097 CFI_ENDPROC
21098-END(spurious_interrupt_bug)
21099+ENDPROC(spurious_interrupt_bug)
21100 /*
21101 * End of kprobes section
21102 */
21103@@ -1073,7 +1312,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
21104
21105 ENTRY(mcount)
21106 ret
21107-END(mcount)
21108+ENDPROC(mcount)
21109
21110 ENTRY(ftrace_caller)
21111 cmpl $0, function_trace_stop
21112@@ -1106,7 +1345,7 @@ ftrace_graph_call:
21113 .globl ftrace_stub
21114 ftrace_stub:
21115 ret
21116-END(ftrace_caller)
21117+ENDPROC(ftrace_caller)
21118
21119 ENTRY(ftrace_regs_caller)
21120 pushf /* push flags before compare (in cs location) */
21121@@ -1207,7 +1446,7 @@ trace:
21122 popl %ecx
21123 popl %eax
21124 jmp ftrace_stub
21125-END(mcount)
21126+ENDPROC(mcount)
21127 #endif /* CONFIG_DYNAMIC_FTRACE */
21128 #endif /* CONFIG_FUNCTION_TRACER */
21129
21130@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
21131 popl %ecx
21132 popl %eax
21133 ret
21134-END(ftrace_graph_caller)
21135+ENDPROC(ftrace_graph_caller)
21136
21137 .globl return_to_handler
21138 return_to_handler:
21139@@ -1281,15 +1520,18 @@ error_code:
21140 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
21141 REG_TO_PTGS %ecx
21142 SET_KERNEL_GS %ecx
21143- movl $(__USER_DS), %ecx
21144+ movl $(__KERNEL_DS), %ecx
21145 movl %ecx, %ds
21146 movl %ecx, %es
21147+
21148+ pax_enter_kernel
21149+
21150 TRACE_IRQS_OFF
21151 movl %esp,%eax # pt_regs pointer
21152 call *%edi
21153 jmp ret_from_exception
21154 CFI_ENDPROC
21155-END(page_fault)
21156+ENDPROC(page_fault)
21157
21158 /*
21159 * Debug traps and NMI can happen at the one SYSENTER instruction
21160@@ -1332,7 +1574,7 @@ debug_stack_correct:
21161 call do_debug
21162 jmp ret_from_exception
21163 CFI_ENDPROC
21164-END(debug)
21165+ENDPROC(debug)
21166
21167 /*
21168 * NMI is doubly nasty. It can happen _while_ we're handling
21169@@ -1370,6 +1612,9 @@ nmi_stack_correct:
21170 xorl %edx,%edx # zero error code
21171 movl %esp,%eax # pt_regs pointer
21172 call do_nmi
21173+
21174+ pax_exit_kernel
21175+
21176 jmp restore_all_notrace
21177 CFI_ENDPROC
21178
21179@@ -1406,12 +1651,15 @@ nmi_espfix_stack:
21180 FIXUP_ESPFIX_STACK # %eax == %esp
21181 xorl %edx,%edx # zero error code
21182 call do_nmi
21183+
21184+ pax_exit_kernel
21185+
21186 RESTORE_REGS
21187 lss 12+4(%esp), %esp # back to espfix stack
21188 CFI_ADJUST_CFA_OFFSET -24
21189 jmp irq_return
21190 CFI_ENDPROC
21191-END(nmi)
21192+ENDPROC(nmi)
21193
21194 ENTRY(int3)
21195 RING0_INT_FRAME
21196@@ -1424,14 +1672,14 @@ ENTRY(int3)
21197 call do_int3
21198 jmp ret_from_exception
21199 CFI_ENDPROC
21200-END(int3)
21201+ENDPROC(int3)
21202
21203 ENTRY(general_protection)
21204 RING0_EC_FRAME
21205 pushl_cfi $do_general_protection
21206 jmp error_code
21207 CFI_ENDPROC
21208-END(general_protection)
21209+ENDPROC(general_protection)
21210
21211 #ifdef CONFIG_KVM_GUEST
21212 ENTRY(async_page_fault)
21213@@ -1440,7 +1688,7 @@ ENTRY(async_page_fault)
21214 pushl_cfi $do_async_page_fault
21215 jmp error_code
21216 CFI_ENDPROC
21217-END(async_page_fault)
21218+ENDPROC(async_page_fault)
21219 #endif
21220
21221 /*
21222diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
21223index 1b69951..8430a6d 100644
21224--- a/arch/x86/kernel/entry_64.S
21225+++ b/arch/x86/kernel/entry_64.S
21226@@ -59,6 +59,8 @@
21227 #include <asm/context_tracking.h>
21228 #include <asm/smap.h>
21229 #include <linux/err.h>
21230+#include <asm/pgtable.h>
21231+#include <asm/alternative-asm.h>
21232
21233 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
21234 #include <linux/elf-em.h>
21235@@ -80,8 +82,9 @@
21236 #ifdef CONFIG_DYNAMIC_FTRACE
21237
21238 ENTRY(function_hook)
21239+ pax_force_retaddr
21240 retq
21241-END(function_hook)
21242+ENDPROC(function_hook)
21243
21244 /* skip is set if stack has been adjusted */
21245 .macro ftrace_caller_setup skip=0
21246@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
21247 #endif
21248
21249 GLOBAL(ftrace_stub)
21250+ pax_force_retaddr
21251 retq
21252-END(ftrace_caller)
21253+ENDPROC(ftrace_caller)
21254
21255 ENTRY(ftrace_regs_caller)
21256 /* Save the current flags before compare (in SS location)*/
21257@@ -191,7 +195,7 @@ ftrace_restore_flags:
21258 popfq
21259 jmp ftrace_stub
21260
21261-END(ftrace_regs_caller)
21262+ENDPROC(ftrace_regs_caller)
21263
21264
21265 #else /* ! CONFIG_DYNAMIC_FTRACE */
21266@@ -212,6 +216,7 @@ ENTRY(function_hook)
21267 #endif
21268
21269 GLOBAL(ftrace_stub)
21270+ pax_force_retaddr
21271 retq
21272
21273 trace:
21274@@ -225,12 +230,13 @@ trace:
21275 #endif
21276 subq $MCOUNT_INSN_SIZE, %rdi
21277
21278+ pax_force_fptr ftrace_trace_function
21279 call *ftrace_trace_function
21280
21281 MCOUNT_RESTORE_FRAME
21282
21283 jmp ftrace_stub
21284-END(function_hook)
21285+ENDPROC(function_hook)
21286 #endif /* CONFIG_DYNAMIC_FTRACE */
21287 #endif /* CONFIG_FUNCTION_TRACER */
21288
21289@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
21290
21291 MCOUNT_RESTORE_FRAME
21292
21293+ pax_force_retaddr
21294 retq
21295-END(ftrace_graph_caller)
21296+ENDPROC(ftrace_graph_caller)
21297
21298 GLOBAL(return_to_handler)
21299 subq $24, %rsp
21300@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
21301 movq 8(%rsp), %rdx
21302 movq (%rsp), %rax
21303 addq $24, %rsp
21304+ pax_force_fptr %rdi
21305 jmp *%rdi
21306+ENDPROC(return_to_handler)
21307 #endif
21308
21309
21310@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
21311 ENDPROC(native_usergs_sysret64)
21312 #endif /* CONFIG_PARAVIRT */
21313
21314+ .macro ljmpq sel, off
21315+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
21316+ .byte 0x48; ljmp *1234f(%rip)
21317+ .pushsection .rodata
21318+ .align 16
21319+ 1234: .quad \off; .word \sel
21320+ .popsection
21321+#else
21322+ pushq $\sel
21323+ pushq $\off
21324+ lretq
21325+#endif
21326+ .endm
21327+
21328+ .macro pax_enter_kernel
21329+ pax_set_fptr_mask
21330+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21331+ call pax_enter_kernel
21332+#endif
21333+ .endm
21334+
21335+ .macro pax_exit_kernel
21336+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21337+ call pax_exit_kernel
21338+#endif
21339+
21340+ .endm
21341+
21342+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21343+ENTRY(pax_enter_kernel)
21344+ pushq %rdi
21345+
21346+#ifdef CONFIG_PARAVIRT
21347+ PV_SAVE_REGS(CLBR_RDI)
21348+#endif
21349+
21350+#ifdef CONFIG_PAX_KERNEXEC
21351+ GET_CR0_INTO_RDI
21352+ bts $16,%rdi
21353+ jnc 3f
21354+ mov %cs,%edi
21355+ cmp $__KERNEL_CS,%edi
21356+ jnz 2f
21357+1:
21358+#endif
21359+
21360+#ifdef CONFIG_PAX_MEMORY_UDEREF
21361+ 661: jmp 111f
21362+ .pushsection .altinstr_replacement, "a"
21363+ 662: ASM_NOP2
21364+ .popsection
21365+ .pushsection .altinstructions, "a"
21366+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21367+ .popsection
21368+ GET_CR3_INTO_RDI
21369+ cmp $0,%dil
21370+ jnz 112f
21371+ mov $__KERNEL_DS,%edi
21372+ mov %edi,%ss
21373+ jmp 111f
21374+112: cmp $1,%dil
21375+ jz 113f
21376+ ud2
21377+113: sub $4097,%rdi
21378+ bts $63,%rdi
21379+ SET_RDI_INTO_CR3
21380+ mov $__UDEREF_KERNEL_DS,%edi
21381+ mov %edi,%ss
21382+111:
21383+#endif
21384+
21385+#ifdef CONFIG_PARAVIRT
21386+ PV_RESTORE_REGS(CLBR_RDI)
21387+#endif
21388+
21389+ popq %rdi
21390+ pax_force_retaddr
21391+ retq
21392+
21393+#ifdef CONFIG_PAX_KERNEXEC
21394+2: ljmpq __KERNEL_CS,1b
21395+3: ljmpq __KERNEXEC_KERNEL_CS,4f
21396+4: SET_RDI_INTO_CR0
21397+ jmp 1b
21398+#endif
21399+ENDPROC(pax_enter_kernel)
21400+
21401+ENTRY(pax_exit_kernel)
21402+ pushq %rdi
21403+
21404+#ifdef CONFIG_PARAVIRT
21405+ PV_SAVE_REGS(CLBR_RDI)
21406+#endif
21407+
21408+#ifdef CONFIG_PAX_KERNEXEC
21409+ mov %cs,%rdi
21410+ cmp $__KERNEXEC_KERNEL_CS,%edi
21411+ jz 2f
21412+ GET_CR0_INTO_RDI
21413+ bts $16,%rdi
21414+ jnc 4f
21415+1:
21416+#endif
21417+
21418+#ifdef CONFIG_PAX_MEMORY_UDEREF
21419+ 661: jmp 111f
21420+ .pushsection .altinstr_replacement, "a"
21421+ 662: ASM_NOP2
21422+ .popsection
21423+ .pushsection .altinstructions, "a"
21424+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21425+ .popsection
21426+ mov %ss,%edi
21427+ cmp $__UDEREF_KERNEL_DS,%edi
21428+ jnz 111f
21429+ GET_CR3_INTO_RDI
21430+ cmp $0,%dil
21431+ jz 112f
21432+ ud2
21433+112: add $4097,%rdi
21434+ bts $63,%rdi
21435+ SET_RDI_INTO_CR3
21436+ mov $__KERNEL_DS,%edi
21437+ mov %edi,%ss
21438+111:
21439+#endif
21440+
21441+#ifdef CONFIG_PARAVIRT
21442+ PV_RESTORE_REGS(CLBR_RDI);
21443+#endif
21444+
21445+ popq %rdi
21446+ pax_force_retaddr
21447+ retq
21448+
21449+#ifdef CONFIG_PAX_KERNEXEC
21450+2: GET_CR0_INTO_RDI
21451+ btr $16,%rdi
21452+ jnc 4f
21453+ ljmpq __KERNEL_CS,3f
21454+3: SET_RDI_INTO_CR0
21455+ jmp 1b
21456+4: ud2
21457+ jmp 4b
21458+#endif
21459+ENDPROC(pax_exit_kernel)
21460+#endif
21461+
21462+ .macro pax_enter_kernel_user
21463+ pax_set_fptr_mask
21464+#ifdef CONFIG_PAX_MEMORY_UDEREF
21465+ call pax_enter_kernel_user
21466+#endif
21467+ .endm
21468+
21469+ .macro pax_exit_kernel_user
21470+#ifdef CONFIG_PAX_MEMORY_UDEREF
21471+ call pax_exit_kernel_user
21472+#endif
21473+#ifdef CONFIG_PAX_RANDKSTACK
21474+ pushq %rax
21475+ pushq %r11
21476+ call pax_randomize_kstack
21477+ popq %r11
21478+ popq %rax
21479+#endif
21480+ .endm
21481+
21482+#ifdef CONFIG_PAX_MEMORY_UDEREF
21483+ENTRY(pax_enter_kernel_user)
21484+ pushq %rdi
21485+ pushq %rbx
21486+
21487+#ifdef CONFIG_PARAVIRT
21488+ PV_SAVE_REGS(CLBR_RDI)
21489+#endif
21490+
21491+ 661: jmp 111f
21492+ .pushsection .altinstr_replacement, "a"
21493+ 662: ASM_NOP2
21494+ .popsection
21495+ .pushsection .altinstructions, "a"
21496+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21497+ .popsection
21498+ GET_CR3_INTO_RDI
21499+ cmp $1,%dil
21500+ jnz 4f
21501+ sub $4097,%rdi
21502+ bts $63,%rdi
21503+ SET_RDI_INTO_CR3
21504+ jmp 3f
21505+111:
21506+
21507+ GET_CR3_INTO_RDI
21508+ mov %rdi,%rbx
21509+ add $__START_KERNEL_map,%rbx
21510+ sub phys_base(%rip),%rbx
21511+
21512+#ifdef CONFIG_PARAVIRT
21513+ cmpl $0, pv_info+PARAVIRT_enabled
21514+ jz 1f
21515+ pushq %rdi
21516+ i = 0
21517+ .rept USER_PGD_PTRS
21518+ mov i*8(%rbx),%rsi
21519+ mov $0,%sil
21520+ lea i*8(%rbx),%rdi
21521+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21522+ i = i + 1
21523+ .endr
21524+ popq %rdi
21525+ jmp 2f
21526+1:
21527+#endif
21528+
21529+ i = 0
21530+ .rept USER_PGD_PTRS
21531+ movb $0,i*8(%rbx)
21532+ i = i + 1
21533+ .endr
21534+
21535+2: SET_RDI_INTO_CR3
21536+
21537+#ifdef CONFIG_PAX_KERNEXEC
21538+ GET_CR0_INTO_RDI
21539+ bts $16,%rdi
21540+ SET_RDI_INTO_CR0
21541+#endif
21542+
21543+3:
21544+
21545+#ifdef CONFIG_PARAVIRT
21546+ PV_RESTORE_REGS(CLBR_RDI)
21547+#endif
21548+
21549+ popq %rbx
21550+ popq %rdi
21551+ pax_force_retaddr
21552+ retq
21553+4: ud2
21554+ENDPROC(pax_enter_kernel_user)
21555+
21556+ENTRY(pax_exit_kernel_user)
21557+ pushq %rdi
21558+ pushq %rbx
21559+
21560+#ifdef CONFIG_PARAVIRT
21561+ PV_SAVE_REGS(CLBR_RDI)
21562+#endif
21563+
21564+ GET_CR3_INTO_RDI
21565+ 661: jmp 1f
21566+ .pushsection .altinstr_replacement, "a"
21567+ 662: ASM_NOP2
21568+ .popsection
21569+ .pushsection .altinstructions, "a"
21570+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21571+ .popsection
21572+ cmp $0,%dil
21573+ jnz 3f
21574+ add $4097,%rdi
21575+ bts $63,%rdi
21576+ SET_RDI_INTO_CR3
21577+ jmp 2f
21578+1:
21579+
21580+ mov %rdi,%rbx
21581+
21582+#ifdef CONFIG_PAX_KERNEXEC
21583+ GET_CR0_INTO_RDI
21584+ btr $16,%rdi
21585+ jnc 3f
21586+ SET_RDI_INTO_CR0
21587+#endif
21588+
21589+ add $__START_KERNEL_map,%rbx
21590+ sub phys_base(%rip),%rbx
21591+
21592+#ifdef CONFIG_PARAVIRT
21593+ cmpl $0, pv_info+PARAVIRT_enabled
21594+ jz 1f
21595+ i = 0
21596+ .rept USER_PGD_PTRS
21597+ mov i*8(%rbx),%rsi
21598+ mov $0x67,%sil
21599+ lea i*8(%rbx),%rdi
21600+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21601+ i = i + 1
21602+ .endr
21603+ jmp 2f
21604+1:
21605+#endif
21606+
21607+ i = 0
21608+ .rept USER_PGD_PTRS
21609+ movb $0x67,i*8(%rbx)
21610+ i = i + 1
21611+ .endr
21612+2:
21613+
21614+#ifdef CONFIG_PARAVIRT
21615+ PV_RESTORE_REGS(CLBR_RDI)
21616+#endif
21617+
21618+ popq %rbx
21619+ popq %rdi
21620+ pax_force_retaddr
21621+ retq
21622+3: ud2
21623+ENDPROC(pax_exit_kernel_user)
21624+#endif
21625+
21626+ .macro pax_enter_kernel_nmi
21627+ pax_set_fptr_mask
21628+
21629+#ifdef CONFIG_PAX_KERNEXEC
21630+ GET_CR0_INTO_RDI
21631+ bts $16,%rdi
21632+ jc 110f
21633+ SET_RDI_INTO_CR0
21634+ or $2,%ebx
21635+110:
21636+#endif
21637+
21638+#ifdef CONFIG_PAX_MEMORY_UDEREF
21639+ 661: jmp 111f
21640+ .pushsection .altinstr_replacement, "a"
21641+ 662: ASM_NOP2
21642+ .popsection
21643+ .pushsection .altinstructions, "a"
21644+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21645+ .popsection
21646+ GET_CR3_INTO_RDI
21647+ cmp $0,%dil
21648+ jz 111f
21649+ sub $4097,%rdi
21650+ or $4,%ebx
21651+ bts $63,%rdi
21652+ SET_RDI_INTO_CR3
21653+ mov $__UDEREF_KERNEL_DS,%edi
21654+ mov %edi,%ss
21655+111:
21656+#endif
21657+ .endm
21658+
21659+ .macro pax_exit_kernel_nmi
21660+#ifdef CONFIG_PAX_KERNEXEC
21661+ btr $1,%ebx
21662+ jnc 110f
21663+ GET_CR0_INTO_RDI
21664+ btr $16,%rdi
21665+ SET_RDI_INTO_CR0
21666+110:
21667+#endif
21668+
21669+#ifdef CONFIG_PAX_MEMORY_UDEREF
21670+ btr $2,%ebx
21671+ jnc 111f
21672+ GET_CR3_INTO_RDI
21673+ add $4097,%rdi
21674+ bts $63,%rdi
21675+ SET_RDI_INTO_CR3
21676+ mov $__KERNEL_DS,%edi
21677+ mov %edi,%ss
21678+111:
21679+#endif
21680+ .endm
21681+
21682+ .macro pax_erase_kstack
21683+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21684+ call pax_erase_kstack
21685+#endif
21686+ .endm
21687+
21688+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21689+ENTRY(pax_erase_kstack)
21690+ pushq %rdi
21691+ pushq %rcx
21692+ pushq %rax
21693+ pushq %r11
21694+
21695+ GET_THREAD_INFO(%r11)
21696+ mov TI_lowest_stack(%r11), %rdi
21697+ mov $-0xBEEF, %rax
21698+ std
21699+
21700+1: mov %edi, %ecx
21701+ and $THREAD_SIZE_asm - 1, %ecx
21702+ shr $3, %ecx
21703+ repne scasq
21704+ jecxz 2f
21705+
21706+ cmp $2*8, %ecx
21707+ jc 2f
21708+
21709+ mov $2*8, %ecx
21710+ repe scasq
21711+ jecxz 2f
21712+ jne 1b
21713+
21714+2: cld
21715+ mov %esp, %ecx
21716+ sub %edi, %ecx
21717+
21718+ cmp $THREAD_SIZE_asm, %rcx
21719+ jb 3f
21720+ ud2
21721+3:
21722+
21723+ shr $3, %ecx
21724+ rep stosq
21725+
21726+ mov TI_task_thread_sp0(%r11), %rdi
21727+ sub $256, %rdi
21728+ mov %rdi, TI_lowest_stack(%r11)
21729+
21730+ popq %r11
21731+ popq %rax
21732+ popq %rcx
21733+ popq %rdi
21734+ pax_force_retaddr
21735+ ret
21736+ENDPROC(pax_erase_kstack)
21737+#endif
21738
21739 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
21740 #ifdef CONFIG_TRACE_IRQFLAGS
21741@@ -375,8 +808,8 @@ ENDPROC(native_usergs_sysret64)
21742 .endm
21743
21744 .macro UNFAKE_STACK_FRAME
21745- addq $8*6, %rsp
21746- CFI_ADJUST_CFA_OFFSET -(6*8)
21747+ addq $8*6 + ARG_SKIP, %rsp
21748+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
21749 .endm
21750
21751 /*
21752@@ -463,7 +896,7 @@ ENDPROC(native_usergs_sysret64)
21753 movq %rsp, %rsi
21754
21755 leaq -RBP(%rsp),%rdi /* arg1 for handler */
21756- testl $3, CS-RBP(%rsi)
21757+ testb $3, CS-RBP(%rsi)
21758 je 1f
21759 SWAPGS
21760 /*
21761@@ -498,9 +931,10 @@ ENTRY(save_rest)
21762 movq_cfi r15, R15+16
21763 movq %r11, 8(%rsp) /* return address */
21764 FIXUP_TOP_OF_STACK %r11, 16
21765+ pax_force_retaddr
21766 ret
21767 CFI_ENDPROC
21768-END(save_rest)
21769+ENDPROC(save_rest)
21770
21771 /* save complete stack frame */
21772 .pushsection .kprobes.text, "ax"
21773@@ -529,9 +963,10 @@ ENTRY(save_paranoid)
21774 js 1f /* negative -> in kernel */
21775 SWAPGS
21776 xorl %ebx,%ebx
21777-1: ret
21778+1: pax_force_retaddr_bts
21779+ ret
21780 CFI_ENDPROC
21781-END(save_paranoid)
21782+ENDPROC(save_paranoid)
21783 .popsection
21784
21785 /*
21786@@ -553,7 +988,7 @@ ENTRY(ret_from_fork)
21787
21788 RESTORE_REST
21789
21790- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21791+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21792 jz 1f
21793
21794 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
21795@@ -571,7 +1006,7 @@ ENTRY(ret_from_fork)
21796 RESTORE_REST
21797 jmp int_ret_from_sys_call
21798 CFI_ENDPROC
21799-END(ret_from_fork)
21800+ENDPROC(ret_from_fork)
21801
21802 /*
21803 * System call entry. Up to 6 arguments in registers are supported.
21804@@ -608,7 +1043,7 @@ END(ret_from_fork)
21805 ENTRY(system_call)
21806 CFI_STARTPROC simple
21807 CFI_SIGNAL_FRAME
21808- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
21809+ CFI_DEF_CFA rsp,0
21810 CFI_REGISTER rip,rcx
21811 /*CFI_REGISTER rflags,r11*/
21812 SWAPGS_UNSAFE_STACK
21813@@ -621,16 +1056,23 @@ GLOBAL(system_call_after_swapgs)
21814
21815 movq %rsp,PER_CPU_VAR(old_rsp)
21816 movq PER_CPU_VAR(kernel_stack),%rsp
21817+ SAVE_ARGS 8*6,0
21818+ pax_enter_kernel_user
21819+
21820+#ifdef CONFIG_PAX_RANDKSTACK
21821+ pax_erase_kstack
21822+#endif
21823+
21824 /*
21825 * No need to follow this irqs off/on section - it's straight
21826 * and short:
21827 */
21828 ENABLE_INTERRUPTS(CLBR_NONE)
21829- SAVE_ARGS 8,0
21830 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
21831 movq %rcx,RIP-ARGOFFSET(%rsp)
21832 CFI_REL_OFFSET rip,RIP-ARGOFFSET
21833- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21834+ GET_THREAD_INFO(%rcx)
21835+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
21836 jnz tracesys
21837 system_call_fastpath:
21838 #if __SYSCALL_MASK == ~0
21839@@ -640,7 +1082,7 @@ system_call_fastpath:
21840 cmpl $__NR_syscall_max,%eax
21841 #endif
21842 ja badsys
21843- movq %r10,%rcx
21844+ movq R10-ARGOFFSET(%rsp),%rcx
21845 call *sys_call_table(,%rax,8) # XXX: rip relative
21846 movq %rax,RAX-ARGOFFSET(%rsp)
21847 /*
21848@@ -654,10 +1096,13 @@ sysret_check:
21849 LOCKDEP_SYS_EXIT
21850 DISABLE_INTERRUPTS(CLBR_NONE)
21851 TRACE_IRQS_OFF
21852- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
21853+ GET_THREAD_INFO(%rcx)
21854+ movl TI_flags(%rcx),%edx
21855 andl %edi,%edx
21856 jnz sysret_careful
21857 CFI_REMEMBER_STATE
21858+ pax_exit_kernel_user
21859+ pax_erase_kstack
21860 /*
21861 * sysretq will re-enable interrupts:
21862 */
21863@@ -709,14 +1154,18 @@ badsys:
21864 * jump back to the normal fast path.
21865 */
21866 auditsys:
21867- movq %r10,%r9 /* 6th arg: 4th syscall arg */
21868+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
21869 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
21870 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
21871 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
21872 movq %rax,%rsi /* 2nd arg: syscall number */
21873 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
21874 call __audit_syscall_entry
21875+
21876+ pax_erase_kstack
21877+
21878 LOAD_ARGS 0 /* reload call-clobbered registers */
21879+ pax_set_fptr_mask
21880 jmp system_call_fastpath
21881
21882 /*
21883@@ -737,7 +1186,7 @@ sysret_audit:
21884 /* Do syscall tracing */
21885 tracesys:
21886 #ifdef CONFIG_AUDITSYSCALL
21887- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21888+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
21889 jz auditsys
21890 #endif
21891 SAVE_REST
21892@@ -745,12 +1194,16 @@ tracesys:
21893 FIXUP_TOP_OF_STACK %rdi
21894 movq %rsp,%rdi
21895 call syscall_trace_enter
21896+
21897+ pax_erase_kstack
21898+
21899 /*
21900 * Reload arg registers from stack in case ptrace changed them.
21901 * We don't reload %rax because syscall_trace_enter() returned
21902 * the value it wants us to use in the table lookup.
21903 */
21904 LOAD_ARGS ARGOFFSET, 1
21905+ pax_set_fptr_mask
21906 RESTORE_REST
21907 #if __SYSCALL_MASK == ~0
21908 cmpq $__NR_syscall_max,%rax
21909@@ -759,7 +1212,7 @@ tracesys:
21910 cmpl $__NR_syscall_max,%eax
21911 #endif
21912 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
21913- movq %r10,%rcx /* fixup for C */
21914+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
21915 call *sys_call_table(,%rax,8)
21916 movq %rax,RAX-ARGOFFSET(%rsp)
21917 /* Use IRET because user could have changed frame */
21918@@ -780,7 +1233,9 @@ GLOBAL(int_with_check)
21919 andl %edi,%edx
21920 jnz int_careful
21921 andl $~TS_COMPAT,TI_status(%rcx)
21922- jmp retint_swapgs
21923+ pax_exit_kernel_user
21924+ pax_erase_kstack
21925+ jmp retint_swapgs_pax
21926
21927 /* Either reschedule or signal or syscall exit tracking needed. */
21928 /* First do a reschedule test. */
21929@@ -826,7 +1281,7 @@ int_restore_rest:
21930 TRACE_IRQS_OFF
21931 jmp int_with_check
21932 CFI_ENDPROC
21933-END(system_call)
21934+ENDPROC(system_call)
21935
21936 .macro FORK_LIKE func
21937 ENTRY(stub_\func)
21938@@ -839,9 +1294,10 @@ ENTRY(stub_\func)
21939 DEFAULT_FRAME 0 8 /* offset 8: return address */
21940 call sys_\func
21941 RESTORE_TOP_OF_STACK %r11, 8
21942+ pax_force_retaddr
21943 ret $REST_SKIP /* pop extended registers */
21944 CFI_ENDPROC
21945-END(stub_\func)
21946+ENDPROC(stub_\func)
21947 .endm
21948
21949 .macro FIXED_FRAME label,func
21950@@ -851,9 +1307,10 @@ ENTRY(\label)
21951 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
21952 call \func
21953 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
21954+ pax_force_retaddr
21955 ret
21956 CFI_ENDPROC
21957-END(\label)
21958+ENDPROC(\label)
21959 .endm
21960
21961 FORK_LIKE clone
21962@@ -870,9 +1327,10 @@ ENTRY(ptregscall_common)
21963 movq_cfi_restore R12+8, r12
21964 movq_cfi_restore RBP+8, rbp
21965 movq_cfi_restore RBX+8, rbx
21966+ pax_force_retaddr
21967 ret $REST_SKIP /* pop extended registers */
21968 CFI_ENDPROC
21969-END(ptregscall_common)
21970+ENDPROC(ptregscall_common)
21971
21972 ENTRY(stub_execve)
21973 CFI_STARTPROC
21974@@ -885,7 +1343,7 @@ ENTRY(stub_execve)
21975 RESTORE_REST
21976 jmp int_ret_from_sys_call
21977 CFI_ENDPROC
21978-END(stub_execve)
21979+ENDPROC(stub_execve)
21980
21981 /*
21982 * sigreturn is special because it needs to restore all registers on return.
21983@@ -902,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
21984 RESTORE_REST
21985 jmp int_ret_from_sys_call
21986 CFI_ENDPROC
21987-END(stub_rt_sigreturn)
21988+ENDPROC(stub_rt_sigreturn)
21989
21990 #ifdef CONFIG_X86_X32_ABI
21991 ENTRY(stub_x32_rt_sigreturn)
21992@@ -916,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
21993 RESTORE_REST
21994 jmp int_ret_from_sys_call
21995 CFI_ENDPROC
21996-END(stub_x32_rt_sigreturn)
21997+ENDPROC(stub_x32_rt_sigreturn)
21998
21999 ENTRY(stub_x32_execve)
22000 CFI_STARTPROC
22001@@ -930,7 +1388,7 @@ ENTRY(stub_x32_execve)
22002 RESTORE_REST
22003 jmp int_ret_from_sys_call
22004 CFI_ENDPROC
22005-END(stub_x32_execve)
22006+ENDPROC(stub_x32_execve)
22007
22008 #endif
22009
22010@@ -967,7 +1425,7 @@ vector=vector+1
22011 2: jmp common_interrupt
22012 .endr
22013 CFI_ENDPROC
22014-END(irq_entries_start)
22015+ENDPROC(irq_entries_start)
22016
22017 .previous
22018 END(interrupt)
22019@@ -987,6 +1445,16 @@ END(interrupt)
22020 subq $ORIG_RAX-RBP, %rsp
22021 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
22022 SAVE_ARGS_IRQ
22023+#ifdef CONFIG_PAX_MEMORY_UDEREF
22024+ testb $3, CS(%rdi)
22025+ jnz 1f
22026+ pax_enter_kernel
22027+ jmp 2f
22028+1: pax_enter_kernel_user
22029+2:
22030+#else
22031+ pax_enter_kernel
22032+#endif
22033 call \func
22034 .endm
22035
22036@@ -1019,7 +1487,7 @@ ret_from_intr:
22037
22038 exit_intr:
22039 GET_THREAD_INFO(%rcx)
22040- testl $3,CS-ARGOFFSET(%rsp)
22041+ testb $3,CS-ARGOFFSET(%rsp)
22042 je retint_kernel
22043
22044 /* Interrupt came from user space */
22045@@ -1041,12 +1509,16 @@ retint_swapgs: /* return to user-space */
22046 * The iretq could re-enable interrupts:
22047 */
22048 DISABLE_INTERRUPTS(CLBR_ANY)
22049+ pax_exit_kernel_user
22050+retint_swapgs_pax:
22051 TRACE_IRQS_IRETQ
22052 SWAPGS
22053 jmp restore_args
22054
22055 retint_restore_args: /* return to kernel space */
22056 DISABLE_INTERRUPTS(CLBR_ANY)
22057+ pax_exit_kernel
22058+ pax_force_retaddr (RIP-ARGOFFSET)
22059 /*
22060 * The iretq could re-enable interrupts:
22061 */
22062@@ -1129,7 +1601,7 @@ ENTRY(retint_kernel)
22063 #endif
22064
22065 CFI_ENDPROC
22066-END(common_interrupt)
22067+ENDPROC(common_interrupt)
22068 /*
22069 * End of kprobes section
22070 */
22071@@ -1147,7 +1619,7 @@ ENTRY(\sym)
22072 interrupt \do_sym
22073 jmp ret_from_intr
22074 CFI_ENDPROC
22075-END(\sym)
22076+ENDPROC(\sym)
22077 .endm
22078
22079 #ifdef CONFIG_TRACING
22080@@ -1230,12 +1702,22 @@ ENTRY(\sym)
22081 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22082 call error_entry
22083 DEFAULT_FRAME 0
22084+#ifdef CONFIG_PAX_MEMORY_UDEREF
22085+ testb $3, CS(%rsp)
22086+ jnz 1f
22087+ pax_enter_kernel
22088+ jmp 2f
22089+1: pax_enter_kernel_user
22090+2:
22091+#else
22092+ pax_enter_kernel
22093+#endif
22094 movq %rsp,%rdi /* pt_regs pointer */
22095 xorl %esi,%esi /* no error code */
22096 call \do_sym
22097 jmp error_exit /* %ebx: no swapgs flag */
22098 CFI_ENDPROC
22099-END(\sym)
22100+ENDPROC(\sym)
22101 .endm
22102
22103 .macro paranoidzeroentry sym do_sym
22104@@ -1248,15 +1730,25 @@ ENTRY(\sym)
22105 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22106 call save_paranoid
22107 TRACE_IRQS_OFF
22108+#ifdef CONFIG_PAX_MEMORY_UDEREF
22109+ testb $3, CS(%rsp)
22110+ jnz 1f
22111+ pax_enter_kernel
22112+ jmp 2f
22113+1: pax_enter_kernel_user
22114+2:
22115+#else
22116+ pax_enter_kernel
22117+#endif
22118 movq %rsp,%rdi /* pt_regs pointer */
22119 xorl %esi,%esi /* no error code */
22120 call \do_sym
22121 jmp paranoid_exit /* %ebx: no swapgs flag */
22122 CFI_ENDPROC
22123-END(\sym)
22124+ENDPROC(\sym)
22125 .endm
22126
22127-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
22128+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
22129 .macro paranoidzeroentry_ist sym do_sym ist
22130 ENTRY(\sym)
22131 INTR_FRAME
22132@@ -1267,14 +1759,30 @@ ENTRY(\sym)
22133 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22134 call save_paranoid
22135 TRACE_IRQS_OFF_DEBUG
22136+#ifdef CONFIG_PAX_MEMORY_UDEREF
22137+ testb $3, CS(%rsp)
22138+ jnz 1f
22139+ pax_enter_kernel
22140+ jmp 2f
22141+1: pax_enter_kernel_user
22142+2:
22143+#else
22144+ pax_enter_kernel
22145+#endif
22146 movq %rsp,%rdi /* pt_regs pointer */
22147 xorl %esi,%esi /* no error code */
22148+#ifdef CONFIG_SMP
22149+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
22150+ lea init_tss(%r12), %r12
22151+#else
22152+ lea init_tss(%rip), %r12
22153+#endif
22154 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22155 call \do_sym
22156 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22157 jmp paranoid_exit /* %ebx: no swapgs flag */
22158 CFI_ENDPROC
22159-END(\sym)
22160+ENDPROC(\sym)
22161 .endm
22162
22163 .macro errorentry sym do_sym
22164@@ -1286,13 +1794,23 @@ ENTRY(\sym)
22165 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22166 call error_entry
22167 DEFAULT_FRAME 0
22168+#ifdef CONFIG_PAX_MEMORY_UDEREF
22169+ testb $3, CS(%rsp)
22170+ jnz 1f
22171+ pax_enter_kernel
22172+ jmp 2f
22173+1: pax_enter_kernel_user
22174+2:
22175+#else
22176+ pax_enter_kernel
22177+#endif
22178 movq %rsp,%rdi /* pt_regs pointer */
22179 movq ORIG_RAX(%rsp),%rsi /* get error code */
22180 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22181 call \do_sym
22182 jmp error_exit /* %ebx: no swapgs flag */
22183 CFI_ENDPROC
22184-END(\sym)
22185+ENDPROC(\sym)
22186 .endm
22187
22188 /* error code is on the stack already */
22189@@ -1306,13 +1824,23 @@ ENTRY(\sym)
22190 call save_paranoid
22191 DEFAULT_FRAME 0
22192 TRACE_IRQS_OFF
22193+#ifdef CONFIG_PAX_MEMORY_UDEREF
22194+ testb $3, CS(%rsp)
22195+ jnz 1f
22196+ pax_enter_kernel
22197+ jmp 2f
22198+1: pax_enter_kernel_user
22199+2:
22200+#else
22201+ pax_enter_kernel
22202+#endif
22203 movq %rsp,%rdi /* pt_regs pointer */
22204 movq ORIG_RAX(%rsp),%rsi /* get error code */
22205 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22206 call \do_sym
22207 jmp paranoid_exit /* %ebx: no swapgs flag */
22208 CFI_ENDPROC
22209-END(\sym)
22210+ENDPROC(\sym)
22211 .endm
22212
22213 zeroentry divide_error do_divide_error
22214@@ -1342,9 +1870,10 @@ gs_change:
22215 2: mfence /* workaround */
22216 SWAPGS
22217 popfq_cfi
22218+ pax_force_retaddr
22219 ret
22220 CFI_ENDPROC
22221-END(native_load_gs_index)
22222+ENDPROC(native_load_gs_index)
22223
22224 _ASM_EXTABLE(gs_change,bad_gs)
22225 .section .fixup,"ax"
22226@@ -1372,9 +1901,10 @@ ENTRY(call_softirq)
22227 CFI_DEF_CFA_REGISTER rsp
22228 CFI_ADJUST_CFA_OFFSET -8
22229 decl PER_CPU_VAR(irq_count)
22230+ pax_force_retaddr
22231 ret
22232 CFI_ENDPROC
22233-END(call_softirq)
22234+ENDPROC(call_softirq)
22235
22236 #ifdef CONFIG_XEN
22237 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
22238@@ -1412,7 +1942,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
22239 decl PER_CPU_VAR(irq_count)
22240 jmp error_exit
22241 CFI_ENDPROC
22242-END(xen_do_hypervisor_callback)
22243+ENDPROC(xen_do_hypervisor_callback)
22244
22245 /*
22246 * Hypervisor uses this for application faults while it executes.
22247@@ -1471,7 +2001,7 @@ ENTRY(xen_failsafe_callback)
22248 SAVE_ALL
22249 jmp error_exit
22250 CFI_ENDPROC
22251-END(xen_failsafe_callback)
22252+ENDPROC(xen_failsafe_callback)
22253
22254 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
22255 xen_hvm_callback_vector xen_evtchn_do_upcall
22256@@ -1523,18 +2053,33 @@ ENTRY(paranoid_exit)
22257 DEFAULT_FRAME
22258 DISABLE_INTERRUPTS(CLBR_NONE)
22259 TRACE_IRQS_OFF_DEBUG
22260- testl %ebx,%ebx /* swapgs needed? */
22261+ testl $1,%ebx /* swapgs needed? */
22262 jnz paranoid_restore
22263- testl $3,CS(%rsp)
22264+ testb $3,CS(%rsp)
22265 jnz paranoid_userspace
22266+#ifdef CONFIG_PAX_MEMORY_UDEREF
22267+ pax_exit_kernel
22268+ TRACE_IRQS_IRETQ 0
22269+ SWAPGS_UNSAFE_STACK
22270+ RESTORE_ALL 8
22271+ pax_force_retaddr_bts
22272+ jmp irq_return
22273+#endif
22274 paranoid_swapgs:
22275+#ifdef CONFIG_PAX_MEMORY_UDEREF
22276+ pax_exit_kernel_user
22277+#else
22278+ pax_exit_kernel
22279+#endif
22280 TRACE_IRQS_IRETQ 0
22281 SWAPGS_UNSAFE_STACK
22282 RESTORE_ALL 8
22283 jmp irq_return
22284 paranoid_restore:
22285+ pax_exit_kernel
22286 TRACE_IRQS_IRETQ_DEBUG 0
22287 RESTORE_ALL 8
22288+ pax_force_retaddr_bts
22289 jmp irq_return
22290 paranoid_userspace:
22291 GET_THREAD_INFO(%rcx)
22292@@ -1563,7 +2108,7 @@ paranoid_schedule:
22293 TRACE_IRQS_OFF
22294 jmp paranoid_userspace
22295 CFI_ENDPROC
22296-END(paranoid_exit)
22297+ENDPROC(paranoid_exit)
22298
22299 /*
22300 * Exception entry point. This expects an error code/orig_rax on the stack.
22301@@ -1590,12 +2135,13 @@ ENTRY(error_entry)
22302 movq_cfi r14, R14+8
22303 movq_cfi r15, R15+8
22304 xorl %ebx,%ebx
22305- testl $3,CS+8(%rsp)
22306+ testb $3,CS+8(%rsp)
22307 je error_kernelspace
22308 error_swapgs:
22309 SWAPGS
22310 error_sti:
22311 TRACE_IRQS_OFF
22312+ pax_force_retaddr_bts
22313 ret
22314
22315 /*
22316@@ -1622,7 +2168,7 @@ bstep_iret:
22317 movq %rcx,RIP+8(%rsp)
22318 jmp error_swapgs
22319 CFI_ENDPROC
22320-END(error_entry)
22321+ENDPROC(error_entry)
22322
22323
22324 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
22325@@ -1633,7 +2179,7 @@ ENTRY(error_exit)
22326 DISABLE_INTERRUPTS(CLBR_NONE)
22327 TRACE_IRQS_OFF
22328 GET_THREAD_INFO(%rcx)
22329- testl %eax,%eax
22330+ testl $1,%eax
22331 jne retint_kernel
22332 LOCKDEP_SYS_EXIT_IRQ
22333 movl TI_flags(%rcx),%edx
22334@@ -1642,7 +2188,7 @@ ENTRY(error_exit)
22335 jnz retint_careful
22336 jmp retint_swapgs
22337 CFI_ENDPROC
22338-END(error_exit)
22339+ENDPROC(error_exit)
22340
22341 /*
22342 * Test if a given stack is an NMI stack or not.
22343@@ -1700,9 +2246,11 @@ ENTRY(nmi)
22344 * If %cs was not the kernel segment, then the NMI triggered in user
22345 * space, which means it is definitely not nested.
22346 */
22347+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
22348+ je 1f
22349 cmpl $__KERNEL_CS, 16(%rsp)
22350 jne first_nmi
22351-
22352+1:
22353 /*
22354 * Check the special variable on the stack to see if NMIs are
22355 * executing.
22356@@ -1736,8 +2284,7 @@ nested_nmi:
22357
22358 1:
22359 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
22360- leaq -1*8(%rsp), %rdx
22361- movq %rdx, %rsp
22362+ subq $8, %rsp
22363 CFI_ADJUST_CFA_OFFSET 1*8
22364 leaq -10*8(%rsp), %rdx
22365 pushq_cfi $__KERNEL_DS
22366@@ -1755,6 +2302,7 @@ nested_nmi_out:
22367 CFI_RESTORE rdx
22368
22369 /* No need to check faults here */
22370+# pax_force_retaddr_bts
22371 INTERRUPT_RETURN
22372
22373 CFI_RESTORE_STATE
22374@@ -1871,6 +2419,8 @@ end_repeat_nmi:
22375 */
22376 movq %cr2, %r12
22377
22378+ pax_enter_kernel_nmi
22379+
22380 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
22381 movq %rsp,%rdi
22382 movq $-1,%rsi
22383@@ -1883,26 +2433,31 @@ end_repeat_nmi:
22384 movq %r12, %cr2
22385 1:
22386
22387- testl %ebx,%ebx /* swapgs needed? */
22388+ testl $1,%ebx /* swapgs needed? */
22389 jnz nmi_restore
22390 nmi_swapgs:
22391 SWAPGS_UNSAFE_STACK
22392 nmi_restore:
22393+ pax_exit_kernel_nmi
22394 /* Pop the extra iret frame at once */
22395 RESTORE_ALL 6*8
22396+ testb $3, 8(%rsp)
22397+ jnz 1f
22398+ pax_force_retaddr_bts
22399+1:
22400
22401 /* Clear the NMI executing stack variable */
22402 movq $0, 5*8(%rsp)
22403 jmp irq_return
22404 CFI_ENDPROC
22405-END(nmi)
22406+ENDPROC(nmi)
22407
22408 ENTRY(ignore_sysret)
22409 CFI_STARTPROC
22410 mov $-ENOSYS,%eax
22411 sysret
22412 CFI_ENDPROC
22413-END(ignore_sysret)
22414+ENDPROC(ignore_sysret)
22415
22416 /*
22417 * End of kprobes section
22418diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
22419index 42a392a..fbbd930 100644
22420--- a/arch/x86/kernel/ftrace.c
22421+++ b/arch/x86/kernel/ftrace.c
22422@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
22423 {
22424 unsigned char replaced[MCOUNT_INSN_SIZE];
22425
22426+ ip = ktla_ktva(ip);
22427+
22428 /*
22429 * Note: Due to modules and __init, code can
22430 * disappear and change, we need to protect against faulting
22431@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22432 unsigned char old[MCOUNT_INSN_SIZE], *new;
22433 int ret;
22434
22435- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
22436+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
22437 new = ftrace_call_replace(ip, (unsigned long)func);
22438
22439 /* See comment above by declaration of modifying_ftrace_code */
22440@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22441 /* Also update the regs callback function */
22442 if (!ret) {
22443 ip = (unsigned long)(&ftrace_regs_call);
22444- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
22445+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
22446 new = ftrace_call_replace(ip, (unsigned long)func);
22447 ret = ftrace_modify_code(ip, old, new);
22448 }
22449@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
22450 * kernel identity mapping to modify code.
22451 */
22452 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
22453- ip = (unsigned long)__va(__pa_symbol(ip));
22454+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
22455
22456 return probe_kernel_write((void *)ip, val, size);
22457 }
22458@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
22459 unsigned char replaced[MCOUNT_INSN_SIZE];
22460 unsigned char brk = BREAKPOINT_INSTRUCTION;
22461
22462- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
22463+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
22464 return -EFAULT;
22465
22466 /* Make sure it is what we expect it to be */
22467@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
22468 return ret;
22469
22470 fail_update:
22471- probe_kernel_write((void *)ip, &old_code[0], 1);
22472+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
22473 goto out;
22474 }
22475
22476@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
22477 {
22478 unsigned char code[MCOUNT_INSN_SIZE];
22479
22480+ ip = ktla_ktva(ip);
22481+
22482 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
22483 return -EFAULT;
22484
22485diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
22486index 55b6761..a6456fc 100644
22487--- a/arch/x86/kernel/head64.c
22488+++ b/arch/x86/kernel/head64.c
22489@@ -67,12 +67,12 @@ again:
22490 pgd = *pgd_p;
22491
22492 /*
22493- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
22494- * critical -- __PAGE_OFFSET would point us back into the dynamic
22495+ * The use of __early_va rather than __va here is critical:
22496+ * __va would point us back into the dynamic
22497 * range and we might end up looping forever...
22498 */
22499 if (pgd)
22500- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22501+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
22502 else {
22503 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22504 reset_early_page_tables();
22505@@ -82,13 +82,13 @@ again:
22506 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
22507 for (i = 0; i < PTRS_PER_PUD; i++)
22508 pud_p[i] = 0;
22509- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22510+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
22511 }
22512 pud_p += pud_index(address);
22513 pud = *pud_p;
22514
22515 if (pud)
22516- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22517+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
22518 else {
22519 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22520 reset_early_page_tables();
22521@@ -98,7 +98,7 @@ again:
22522 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
22523 for (i = 0; i < PTRS_PER_PMD; i++)
22524 pmd_p[i] = 0;
22525- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22526+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
22527 }
22528 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
22529 pmd_p[pmd_index(address)] = pmd;
22530@@ -175,7 +175,6 @@ void __init x86_64_start_kernel(char * real_mode_data)
22531 if (console_loglevel == 10)
22532 early_printk("Kernel alive\n");
22533
22534- clear_page(init_level4_pgt);
22535 /* set init_level4_pgt kernel high mapping*/
22536 init_level4_pgt[511] = early_level4_pgt[511];
22537
22538diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
22539index 5dd87a8..d68b3f4 100644
22540--- a/arch/x86/kernel/head_32.S
22541+++ b/arch/x86/kernel/head_32.S
22542@@ -26,6 +26,12 @@
22543 /* Physical address */
22544 #define pa(X) ((X) - __PAGE_OFFSET)
22545
22546+#ifdef CONFIG_PAX_KERNEXEC
22547+#define ta(X) (X)
22548+#else
22549+#define ta(X) ((X) - __PAGE_OFFSET)
22550+#endif
22551+
22552 /*
22553 * References to members of the new_cpu_data structure.
22554 */
22555@@ -55,11 +61,7 @@
22556 * and small than max_low_pfn, otherwise will waste some page table entries
22557 */
22558
22559-#if PTRS_PER_PMD > 1
22560-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
22561-#else
22562-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
22563-#endif
22564+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
22565
22566 /* Number of possible pages in the lowmem region */
22567 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
22568@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
22569 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22570
22571 /*
22572+ * Real beginning of normal "text" segment
22573+ */
22574+ENTRY(stext)
22575+ENTRY(_stext)
22576+
22577+/*
22578 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
22579 * %esi points to the real-mode code as a 32-bit pointer.
22580 * CS and DS must be 4 GB flat segments, but we don't depend on
22581@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22582 * can.
22583 */
22584 __HEAD
22585+
22586+#ifdef CONFIG_PAX_KERNEXEC
22587+ jmp startup_32
22588+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
22589+.fill PAGE_SIZE-5,1,0xcc
22590+#endif
22591+
22592 ENTRY(startup_32)
22593 movl pa(stack_start),%ecx
22594
22595@@ -106,6 +121,59 @@ ENTRY(startup_32)
22596 2:
22597 leal -__PAGE_OFFSET(%ecx),%esp
22598
22599+#ifdef CONFIG_SMP
22600+ movl $pa(cpu_gdt_table),%edi
22601+ movl $__per_cpu_load,%eax
22602+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
22603+ rorl $16,%eax
22604+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
22605+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
22606+ movl $__per_cpu_end - 1,%eax
22607+ subl $__per_cpu_start,%eax
22608+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
22609+#endif
22610+
22611+#ifdef CONFIG_PAX_MEMORY_UDEREF
22612+ movl $NR_CPUS,%ecx
22613+ movl $pa(cpu_gdt_table),%edi
22614+1:
22615+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
22616+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
22617+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
22618+ addl $PAGE_SIZE_asm,%edi
22619+ loop 1b
22620+#endif
22621+
22622+#ifdef CONFIG_PAX_KERNEXEC
22623+ movl $pa(boot_gdt),%edi
22624+ movl $__LOAD_PHYSICAL_ADDR,%eax
22625+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
22626+ rorl $16,%eax
22627+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
22628+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
22629+ rorl $16,%eax
22630+
22631+ ljmp $(__BOOT_CS),$1f
22632+1:
22633+
22634+ movl $NR_CPUS,%ecx
22635+ movl $pa(cpu_gdt_table),%edi
22636+ addl $__PAGE_OFFSET,%eax
22637+1:
22638+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
22639+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
22640+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
22641+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
22642+ rorl $16,%eax
22643+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
22644+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
22645+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
22646+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
22647+ rorl $16,%eax
22648+ addl $PAGE_SIZE_asm,%edi
22649+ loop 1b
22650+#endif
22651+
22652 /*
22653 * Clear BSS first so that there are no surprises...
22654 */
22655@@ -201,8 +269,11 @@ ENTRY(startup_32)
22656 movl %eax, pa(max_pfn_mapped)
22657
22658 /* Do early initialization of the fixmap area */
22659- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22660- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
22661+#ifdef CONFIG_COMPAT_VDSO
22662+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
22663+#else
22664+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
22665+#endif
22666 #else /* Not PAE */
22667
22668 page_pde_offset = (__PAGE_OFFSET >> 20);
22669@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22670 movl %eax, pa(max_pfn_mapped)
22671
22672 /* Do early initialization of the fixmap area */
22673- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22674- movl %eax,pa(initial_page_table+0xffc)
22675+#ifdef CONFIG_COMPAT_VDSO
22676+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
22677+#else
22678+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
22679+#endif
22680 #endif
22681
22682 #ifdef CONFIG_PARAVIRT
22683@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22684 cmpl $num_subarch_entries, %eax
22685 jae bad_subarch
22686
22687- movl pa(subarch_entries)(,%eax,4), %eax
22688- subl $__PAGE_OFFSET, %eax
22689- jmp *%eax
22690+ jmp *pa(subarch_entries)(,%eax,4)
22691
22692 bad_subarch:
22693 WEAK(lguest_entry)
22694@@ -261,10 +333,10 @@ WEAK(xen_entry)
22695 __INITDATA
22696
22697 subarch_entries:
22698- .long default_entry /* normal x86/PC */
22699- .long lguest_entry /* lguest hypervisor */
22700- .long xen_entry /* Xen hypervisor */
22701- .long default_entry /* Moorestown MID */
22702+ .long ta(default_entry) /* normal x86/PC */
22703+ .long ta(lguest_entry) /* lguest hypervisor */
22704+ .long ta(xen_entry) /* Xen hypervisor */
22705+ .long ta(default_entry) /* Moorestown MID */
22706 num_subarch_entries = (. - subarch_entries) / 4
22707 .previous
22708 #else
22709@@ -354,6 +426,7 @@ default_entry:
22710 movl pa(mmu_cr4_features),%eax
22711 movl %eax,%cr4
22712
22713+#ifdef CONFIG_X86_PAE
22714 testb $X86_CR4_PAE, %al # check if PAE is enabled
22715 jz enable_paging
22716
22717@@ -382,6 +455,9 @@ default_entry:
22718 /* Make changes effective */
22719 wrmsr
22720
22721+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
22722+#endif
22723+
22724 enable_paging:
22725
22726 /*
22727@@ -449,14 +525,20 @@ is486:
22728 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
22729 movl %eax,%ss # after changing gdt.
22730
22731- movl $(__USER_DS),%eax # DS/ES contains default USER segment
22732+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
22733 movl %eax,%ds
22734 movl %eax,%es
22735
22736 movl $(__KERNEL_PERCPU), %eax
22737 movl %eax,%fs # set this cpu's percpu
22738
22739+#ifdef CONFIG_CC_STACKPROTECTOR
22740 movl $(__KERNEL_STACK_CANARY),%eax
22741+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22742+ movl $(__USER_DS),%eax
22743+#else
22744+ xorl %eax,%eax
22745+#endif
22746 movl %eax,%gs
22747
22748 xorl %eax,%eax # Clear LDT
22749@@ -512,8 +594,11 @@ setup_once:
22750 * relocation. Manually set base address in stack canary
22751 * segment descriptor.
22752 */
22753- movl $gdt_page,%eax
22754+ movl $cpu_gdt_table,%eax
22755 movl $stack_canary,%ecx
22756+#ifdef CONFIG_SMP
22757+ addl $__per_cpu_load,%ecx
22758+#endif
22759 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
22760 shrl $16, %ecx
22761 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
22762@@ -544,7 +629,7 @@ ENDPROC(early_idt_handlers)
22763 /* This is global to keep gas from relaxing the jumps */
22764 ENTRY(early_idt_handler)
22765 cld
22766- cmpl $2,%ss:early_recursion_flag
22767+ cmpl $1,%ss:early_recursion_flag
22768 je hlt_loop
22769 incl %ss:early_recursion_flag
22770
22771@@ -582,8 +667,8 @@ ENTRY(early_idt_handler)
22772 pushl (20+6*4)(%esp) /* trapno */
22773 pushl $fault_msg
22774 call printk
22775-#endif
22776 call dump_stack
22777+#endif
22778 hlt_loop:
22779 hlt
22780 jmp hlt_loop
22781@@ -602,8 +687,11 @@ ENDPROC(early_idt_handler)
22782 /* This is the default interrupt "handler" :-) */
22783 ALIGN
22784 ignore_int:
22785- cld
22786 #ifdef CONFIG_PRINTK
22787+ cmpl $2,%ss:early_recursion_flag
22788+ je hlt_loop
22789+ incl %ss:early_recursion_flag
22790+ cld
22791 pushl %eax
22792 pushl %ecx
22793 pushl %edx
22794@@ -612,9 +700,6 @@ ignore_int:
22795 movl $(__KERNEL_DS),%eax
22796 movl %eax,%ds
22797 movl %eax,%es
22798- cmpl $2,early_recursion_flag
22799- je hlt_loop
22800- incl early_recursion_flag
22801 pushl 16(%esp)
22802 pushl 24(%esp)
22803 pushl 32(%esp)
22804@@ -648,29 +733,34 @@ ENTRY(setup_once_ref)
22805 /*
22806 * BSS section
22807 */
22808-__PAGE_ALIGNED_BSS
22809- .align PAGE_SIZE
22810 #ifdef CONFIG_X86_PAE
22811+.section .initial_pg_pmd,"a",@progbits
22812 initial_pg_pmd:
22813 .fill 1024*KPMDS,4,0
22814 #else
22815+.section .initial_page_table,"a",@progbits
22816 ENTRY(initial_page_table)
22817 .fill 1024,4,0
22818 #endif
22819+.section .initial_pg_fixmap,"a",@progbits
22820 initial_pg_fixmap:
22821 .fill 1024,4,0
22822+.section .empty_zero_page,"a",@progbits
22823 ENTRY(empty_zero_page)
22824 .fill 4096,1,0
22825+.section .swapper_pg_dir,"a",@progbits
22826 ENTRY(swapper_pg_dir)
22827+#ifdef CONFIG_X86_PAE
22828+ .fill 4,8,0
22829+#else
22830 .fill 1024,4,0
22831+#endif
22832
22833 /*
22834 * This starts the data section.
22835 */
22836 #ifdef CONFIG_X86_PAE
22837-__PAGE_ALIGNED_DATA
22838- /* Page-aligned for the benefit of paravirt? */
22839- .align PAGE_SIZE
22840+.section .initial_page_table,"a",@progbits
22841 ENTRY(initial_page_table)
22842 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
22843 # if KPMDS == 3
22844@@ -689,12 +779,20 @@ ENTRY(initial_page_table)
22845 # error "Kernel PMDs should be 1, 2 or 3"
22846 # endif
22847 .align PAGE_SIZE /* needs to be page-sized too */
22848+
22849+#ifdef CONFIG_PAX_PER_CPU_PGD
22850+ENTRY(cpu_pgd)
22851+ .rept 2*NR_CPUS
22852+ .fill 4,8,0
22853+ .endr
22854+#endif
22855+
22856 #endif
22857
22858 .data
22859 .balign 4
22860 ENTRY(stack_start)
22861- .long init_thread_union+THREAD_SIZE
22862+ .long init_thread_union+THREAD_SIZE-8
22863
22864 __INITRODATA
22865 int_msg:
22866@@ -722,7 +820,7 @@ fault_msg:
22867 * segment size, and 32-bit linear address value:
22868 */
22869
22870- .data
22871+.section .rodata,"a",@progbits
22872 .globl boot_gdt_descr
22873 .globl idt_descr
22874
22875@@ -731,7 +829,7 @@ fault_msg:
22876 .word 0 # 32 bit align gdt_desc.address
22877 boot_gdt_descr:
22878 .word __BOOT_DS+7
22879- .long boot_gdt - __PAGE_OFFSET
22880+ .long pa(boot_gdt)
22881
22882 .word 0 # 32-bit align idt_desc.address
22883 idt_descr:
22884@@ -742,7 +840,7 @@ idt_descr:
22885 .word 0 # 32 bit align gdt_desc.address
22886 ENTRY(early_gdt_descr)
22887 .word GDT_ENTRIES*8-1
22888- .long gdt_page /* Overwritten for secondary CPUs */
22889+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
22890
22891 /*
22892 * The boot_gdt must mirror the equivalent in setup.S and is
22893@@ -751,5 +849,65 @@ ENTRY(early_gdt_descr)
22894 .align L1_CACHE_BYTES
22895 ENTRY(boot_gdt)
22896 .fill GDT_ENTRY_BOOT_CS,8,0
22897- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
22898- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
22899+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
22900+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
22901+
22902+ .align PAGE_SIZE_asm
22903+ENTRY(cpu_gdt_table)
22904+ .rept NR_CPUS
22905+ .quad 0x0000000000000000 /* NULL descriptor */
22906+ .quad 0x0000000000000000 /* 0x0b reserved */
22907+ .quad 0x0000000000000000 /* 0x13 reserved */
22908+ .quad 0x0000000000000000 /* 0x1b reserved */
22909+
22910+#ifdef CONFIG_PAX_KERNEXEC
22911+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
22912+#else
22913+ .quad 0x0000000000000000 /* 0x20 unused */
22914+#endif
22915+
22916+ .quad 0x0000000000000000 /* 0x28 unused */
22917+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
22918+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
22919+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
22920+ .quad 0x0000000000000000 /* 0x4b reserved */
22921+ .quad 0x0000000000000000 /* 0x53 reserved */
22922+ .quad 0x0000000000000000 /* 0x5b reserved */
22923+
22924+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
22925+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
22926+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
22927+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
22928+
22929+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
22930+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
22931+
22932+ /*
22933+ * Segments used for calling PnP BIOS have byte granularity.
22934+ * The code segments and data segments have fixed 64k limits,
22935+ * the transfer segment sizes are set at run time.
22936+ */
22937+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
22938+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
22939+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
22940+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
22941+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
22942+
22943+ /*
22944+ * The APM segments have byte granularity and their bases
22945+ * are set at run time. All have 64k limits.
22946+ */
22947+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
22948+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
22949+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
22950+
22951+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
22952+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
22953+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
22954+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
22955+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
22956+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
22957+
22958+ /* Be sure this is zeroed to avoid false validations in Xen */
22959+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
22960+ .endr
22961diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
22962index e1aabdb..73dcad8 100644
22963--- a/arch/x86/kernel/head_64.S
22964+++ b/arch/x86/kernel/head_64.S
22965@@ -20,6 +20,8 @@
22966 #include <asm/processor-flags.h>
22967 #include <asm/percpu.h>
22968 #include <asm/nops.h>
22969+#include <asm/cpufeature.h>
22970+#include <asm/alternative-asm.h>
22971
22972 #ifdef CONFIG_PARAVIRT
22973 #include <asm/asm-offsets.h>
22974@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
22975 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
22976 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
22977 L3_START_KERNEL = pud_index(__START_KERNEL_map)
22978+L4_VMALLOC_START = pgd_index(VMALLOC_START)
22979+L3_VMALLOC_START = pud_index(VMALLOC_START)
22980+L4_VMALLOC_END = pgd_index(VMALLOC_END)
22981+L3_VMALLOC_END = pud_index(VMALLOC_END)
22982+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
22983+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
22984
22985 .text
22986 __HEAD
22987@@ -89,11 +97,23 @@ startup_64:
22988 * Fixup the physical addresses in the page table
22989 */
22990 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
22991+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
22992+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
22993+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
22994+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
22995+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
22996
22997- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
22998- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
22999+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
23000+#ifndef CONFIG_XEN
23001+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
23002+#endif
23003
23004- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
23005+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
23006+
23007+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
23008+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
23009+
23010+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
23011
23012 /*
23013 * Set up the identity mapping for the switchover. These
23014@@ -177,8 +197,8 @@ ENTRY(secondary_startup_64)
23015 movq $(init_level4_pgt - __START_KERNEL_map), %rax
23016 1:
23017
23018- /* Enable PAE mode and PGE */
23019- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
23020+ /* Enable PAE mode and PSE/PGE */
23021+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
23022 movq %rcx, %cr4
23023
23024 /* Setup early boot stage 4 level pagetables. */
23025@@ -199,10 +219,18 @@ ENTRY(secondary_startup_64)
23026 movl $MSR_EFER, %ecx
23027 rdmsr
23028 btsl $_EFER_SCE, %eax /* Enable System Call */
23029- btl $20,%edi /* No Execute supported? */
23030+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
23031 jnc 1f
23032 btsl $_EFER_NX, %eax
23033 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
23034+ leaq init_level4_pgt(%rip), %rdi
23035+#ifndef CONFIG_EFI
23036+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
23037+#endif
23038+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
23039+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
23040+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
23041+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
23042 1: wrmsr /* Make changes effective */
23043
23044 /* Setup cr0 */
23045@@ -282,6 +310,7 @@ ENTRY(secondary_startup_64)
23046 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
23047 * address given in m16:64.
23048 */
23049+ pax_set_fptr_mask
23050 movq initial_code(%rip),%rax
23051 pushq $0 # fake return address to stop unwinder
23052 pushq $__KERNEL_CS # set correct cs
23053@@ -388,7 +417,7 @@ ENTRY(early_idt_handler)
23054 call dump_stack
23055 #ifdef CONFIG_KALLSYMS
23056 leaq early_idt_ripmsg(%rip),%rdi
23057- movq 40(%rsp),%rsi # %rip again
23058+ movq 88(%rsp),%rsi # %rip again
23059 call __print_symbol
23060 #endif
23061 #endif /* EARLY_PRINTK */
23062@@ -416,6 +445,7 @@ ENDPROC(early_idt_handler)
23063 early_recursion_flag:
23064 .long 0
23065
23066+ .section .rodata,"a",@progbits
23067 #ifdef CONFIG_EARLY_PRINTK
23068 early_idt_msg:
23069 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
23070@@ -443,29 +473,52 @@ NEXT_PAGE(early_level4_pgt)
23071 NEXT_PAGE(early_dynamic_pgts)
23072 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
23073
23074- .data
23075+ .section .rodata,"a",@progbits
23076
23077-#ifndef CONFIG_XEN
23078 NEXT_PAGE(init_level4_pgt)
23079- .fill 512,8,0
23080-#else
23081-NEXT_PAGE(init_level4_pgt)
23082- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23083 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
23084 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23085+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
23086+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
23087+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
23088+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
23089+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
23090+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23091 .org init_level4_pgt + L4_START_KERNEL*8, 0
23092 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
23093 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
23094
23095+#ifdef CONFIG_PAX_PER_CPU_PGD
23096+NEXT_PAGE(cpu_pgd)
23097+ .rept 2*NR_CPUS
23098+ .fill 512,8,0
23099+ .endr
23100+#endif
23101+
23102 NEXT_PAGE(level3_ident_pgt)
23103 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23104+#ifdef CONFIG_XEN
23105 .fill 511, 8, 0
23106+#else
23107+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
23108+ .fill 510,8,0
23109+#endif
23110+
23111+NEXT_PAGE(level3_vmalloc_start_pgt)
23112+ .fill 512,8,0
23113+
23114+NEXT_PAGE(level3_vmalloc_end_pgt)
23115+ .fill 512,8,0
23116+
23117+NEXT_PAGE(level3_vmemmap_pgt)
23118+ .fill L3_VMEMMAP_START,8,0
23119+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23120+
23121 NEXT_PAGE(level2_ident_pgt)
23122- /* Since I easily can, map the first 1G.
23123+ /* Since I easily can, map the first 2G.
23124 * Don't set NX because code runs from these pages.
23125 */
23126- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
23127-#endif
23128+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
23129
23130 NEXT_PAGE(level3_kernel_pgt)
23131 .fill L3_START_KERNEL,8,0
23132@@ -473,6 +526,9 @@ NEXT_PAGE(level3_kernel_pgt)
23133 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
23134 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23135
23136+NEXT_PAGE(level2_vmemmap_pgt)
23137+ .fill 512,8,0
23138+
23139 NEXT_PAGE(level2_kernel_pgt)
23140 /*
23141 * 512 MB kernel mapping. We spend a full page on this pagetable
23142@@ -488,30 +544,62 @@ NEXT_PAGE(level2_kernel_pgt)
23143 KERNEL_IMAGE_SIZE/PMD_SIZE)
23144
23145 NEXT_PAGE(level2_fixmap_pgt)
23146- .fill 506,8,0
23147- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23148- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
23149- .fill 5,8,0
23150+ .fill 507,8,0
23151+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
23152+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
23153+ .fill 4,8,0
23154
23155-NEXT_PAGE(level1_fixmap_pgt)
23156+NEXT_PAGE(level1_vsyscall_pgt)
23157 .fill 512,8,0
23158
23159 #undef PMDS
23160
23161- .data
23162+ .align PAGE_SIZE
23163+ENTRY(cpu_gdt_table)
23164+ .rept NR_CPUS
23165+ .quad 0x0000000000000000 /* NULL descriptor */
23166+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
23167+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
23168+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
23169+ .quad 0x00cffb000000ffff /* __USER32_CS */
23170+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
23171+ .quad 0x00affb000000ffff /* __USER_CS */
23172+
23173+#ifdef CONFIG_PAX_KERNEXEC
23174+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
23175+#else
23176+ .quad 0x0 /* unused */
23177+#endif
23178+
23179+ .quad 0,0 /* TSS */
23180+ .quad 0,0 /* LDT */
23181+ .quad 0,0,0 /* three TLS descriptors */
23182+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
23183+ /* asm/segment.h:GDT_ENTRIES must match this */
23184+
23185+#ifdef CONFIG_PAX_MEMORY_UDEREF
23186+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
23187+#else
23188+ .quad 0x0 /* unused */
23189+#endif
23190+
23191+ /* zero the remaining page */
23192+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
23193+ .endr
23194+
23195 .align 16
23196 .globl early_gdt_descr
23197 early_gdt_descr:
23198 .word GDT_ENTRIES*8-1
23199 early_gdt_descr_base:
23200- .quad INIT_PER_CPU_VAR(gdt_page)
23201+ .quad cpu_gdt_table
23202
23203 ENTRY(phys_base)
23204 /* This must match the first entry in level2_kernel_pgt */
23205 .quad 0x0000000000000000
23206
23207 #include "../../x86/xen/xen-head.S"
23208-
23209- __PAGE_ALIGNED_BSS
23210+
23211+ .section .rodata,"a",@progbits
23212 NEXT_PAGE(empty_zero_page)
23213 .skip PAGE_SIZE
23214diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
23215index 0fa6912..b37438b 100644
23216--- a/arch/x86/kernel/i386_ksyms_32.c
23217+++ b/arch/x86/kernel/i386_ksyms_32.c
23218@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
23219 EXPORT_SYMBOL(cmpxchg8b_emu);
23220 #endif
23221
23222+EXPORT_SYMBOL_GPL(cpu_gdt_table);
23223+
23224 /* Networking helper routines. */
23225 EXPORT_SYMBOL(csum_partial_copy_generic);
23226+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
23227+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
23228
23229 EXPORT_SYMBOL(__get_user_1);
23230 EXPORT_SYMBOL(__get_user_2);
23231@@ -37,3 +41,11 @@ EXPORT_SYMBOL(strstr);
23232
23233 EXPORT_SYMBOL(csum_partial);
23234 EXPORT_SYMBOL(empty_zero_page);
23235+
23236+#ifdef CONFIG_PAX_KERNEXEC
23237+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
23238+#endif
23239+
23240+#ifdef CONFIG_PAX_PER_CPU_PGD
23241+EXPORT_SYMBOL(cpu_pgd);
23242+#endif
23243diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
23244index 5d576ab..1403a03 100644
23245--- a/arch/x86/kernel/i387.c
23246+++ b/arch/x86/kernel/i387.c
23247@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
23248 static inline bool interrupted_user_mode(void)
23249 {
23250 struct pt_regs *regs = get_irq_regs();
23251- return regs && user_mode_vm(regs);
23252+ return regs && user_mode(regs);
23253 }
23254
23255 /*
23256diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
23257index 9a5c460..84868423 100644
23258--- a/arch/x86/kernel/i8259.c
23259+++ b/arch/x86/kernel/i8259.c
23260@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
23261 static void make_8259A_irq(unsigned int irq)
23262 {
23263 disable_irq_nosync(irq);
23264- io_apic_irqs &= ~(1<<irq);
23265+ io_apic_irqs &= ~(1UL<<irq);
23266 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
23267 i8259A_chip.name);
23268 enable_irq(irq);
23269@@ -209,7 +209,7 @@ spurious_8259A_irq:
23270 "spurious 8259A interrupt: IRQ%d.\n", irq);
23271 spurious_irq_mask |= irqmask;
23272 }
23273- atomic_inc(&irq_err_count);
23274+ atomic_inc_unchecked(&irq_err_count);
23275 /*
23276 * Theoretically we do not have to handle this IRQ,
23277 * but in Linux this does not cause problems and is
23278@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
23279 /* (slave's support for AEOI in flat mode is to be investigated) */
23280 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
23281
23282+ pax_open_kernel();
23283 if (auto_eoi)
23284 /*
23285 * In AEOI mode we just have to mask the interrupt
23286 * when acking.
23287 */
23288- i8259A_chip.irq_mask_ack = disable_8259A_irq;
23289+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
23290 else
23291- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23292+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23293+ pax_close_kernel();
23294
23295 udelay(100); /* wait for 8259A to initialize */
23296
23297diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
23298index a979b5b..1d6db75 100644
23299--- a/arch/x86/kernel/io_delay.c
23300+++ b/arch/x86/kernel/io_delay.c
23301@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
23302 * Quirk table for systems that misbehave (lock up, etc.) if port
23303 * 0x80 is used:
23304 */
23305-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
23306+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
23307 {
23308 .callback = dmi_io_delay_0xed_port,
23309 .ident = "Compaq Presario V6000",
23310diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
23311index 4ddaf66..6292f4e 100644
23312--- a/arch/x86/kernel/ioport.c
23313+++ b/arch/x86/kernel/ioport.c
23314@@ -6,6 +6,7 @@
23315 #include <linux/sched.h>
23316 #include <linux/kernel.h>
23317 #include <linux/capability.h>
23318+#include <linux/security.h>
23319 #include <linux/errno.h>
23320 #include <linux/types.h>
23321 #include <linux/ioport.h>
23322@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23323
23324 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
23325 return -EINVAL;
23326+#ifdef CONFIG_GRKERNSEC_IO
23327+ if (turn_on && grsec_disable_privio) {
23328+ gr_handle_ioperm();
23329+ return -EPERM;
23330+ }
23331+#endif
23332 if (turn_on && !capable(CAP_SYS_RAWIO))
23333 return -EPERM;
23334
23335@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23336 * because the ->io_bitmap_max value must match the bitmap
23337 * contents:
23338 */
23339- tss = &per_cpu(init_tss, get_cpu());
23340+ tss = init_tss + get_cpu();
23341
23342 if (turn_on)
23343 bitmap_clear(t->io_bitmap_ptr, from, num);
23344@@ -103,6 +110,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
23345 return -EINVAL;
23346 /* Trying to gain more privileges? */
23347 if (level > old) {
23348+#ifdef CONFIG_GRKERNSEC_IO
23349+ if (grsec_disable_privio) {
23350+ gr_handle_iopl();
23351+ return -EPERM;
23352+ }
23353+#endif
23354 if (!capable(CAP_SYS_RAWIO))
23355 return -EPERM;
23356 }
23357diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
23358index 3a8185c..3c042ee 100644
23359--- a/arch/x86/kernel/irq.c
23360+++ b/arch/x86/kernel/irq.c
23361@@ -21,7 +21,7 @@
23362 #define CREATE_TRACE_POINTS
23363 #include <asm/trace/irq_vectors.h>
23364
23365-atomic_t irq_err_count;
23366+atomic_unchecked_t irq_err_count;
23367
23368 /* Function pointer for generic interrupt vector handling */
23369 void (*x86_platform_ipi_callback)(void) = NULL;
23370@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
23371 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
23372 seq_printf(p, " Machine check polls\n");
23373 #endif
23374- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
23375+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
23376 #if defined(CONFIG_X86_IO_APIC)
23377- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
23378+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
23379 #endif
23380 return 0;
23381 }
23382@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
23383
23384 u64 arch_irq_stat(void)
23385 {
23386- u64 sum = atomic_read(&irq_err_count);
23387+ u64 sum = atomic_read_unchecked(&irq_err_count);
23388 return sum;
23389 }
23390
23391diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
23392index 4186755..784efa0 100644
23393--- a/arch/x86/kernel/irq_32.c
23394+++ b/arch/x86/kernel/irq_32.c
23395@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
23396 __asm__ __volatile__("andl %%esp,%0" :
23397 "=r" (sp) : "0" (THREAD_SIZE - 1));
23398
23399- return sp < (sizeof(struct thread_info) + STACK_WARN);
23400+ return sp < STACK_WARN;
23401 }
23402
23403 static void print_stack_overflow(void)
23404@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
23405 * per-CPU IRQ handling contexts (thread information and stack)
23406 */
23407 union irq_ctx {
23408- struct thread_info tinfo;
23409- u32 stack[THREAD_SIZE/sizeof(u32)];
23410+ unsigned long previous_esp;
23411+ u32 stack[THREAD_SIZE/sizeof(u32)];
23412 } __attribute__((aligned(THREAD_SIZE)));
23413
23414 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
23415@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
23416 static inline int
23417 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23418 {
23419- union irq_ctx *curctx, *irqctx;
23420+ union irq_ctx *irqctx;
23421 u32 *isp, arg1, arg2;
23422
23423- curctx = (union irq_ctx *) current_thread_info();
23424 irqctx = __this_cpu_read(hardirq_ctx);
23425
23426 /*
23427@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23428 * handler) we can't do that and just have to keep using the
23429 * current stack (which is the irq stack already after all)
23430 */
23431- if (unlikely(curctx == irqctx))
23432+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
23433 return 0;
23434
23435 /* build the stack frame on the IRQ stack */
23436- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23437- irqctx->tinfo.task = curctx->tinfo.task;
23438- irqctx->tinfo.previous_esp = current_stack_pointer;
23439+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23440+ irqctx->previous_esp = current_stack_pointer;
23441
23442- /* Copy the preempt_count so that the [soft]irq checks work. */
23443- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
23444+#ifdef CONFIG_PAX_MEMORY_UDEREF
23445+ __set_fs(MAKE_MM_SEG(0));
23446+#endif
23447
23448 if (unlikely(overflow))
23449 call_on_stack(print_stack_overflow, isp);
23450@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23451 : "0" (irq), "1" (desc), "2" (isp),
23452 "D" (desc->handle_irq)
23453 : "memory", "cc", "ecx");
23454+
23455+#ifdef CONFIG_PAX_MEMORY_UDEREF
23456+ __set_fs(current_thread_info()->addr_limit);
23457+#endif
23458+
23459 return 1;
23460 }
23461
23462@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23463 */
23464 void irq_ctx_init(int cpu)
23465 {
23466- union irq_ctx *irqctx;
23467-
23468 if (per_cpu(hardirq_ctx, cpu))
23469 return;
23470
23471- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23472- THREADINFO_GFP,
23473- THREAD_SIZE_ORDER));
23474- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23475- irqctx->tinfo.cpu = cpu;
23476- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
23477- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23478+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23479+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23480
23481- per_cpu(hardirq_ctx, cpu) = irqctx;
23482-
23483- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23484- THREADINFO_GFP,
23485- THREAD_SIZE_ORDER));
23486- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23487- irqctx->tinfo.cpu = cpu;
23488- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23489-
23490- per_cpu(softirq_ctx, cpu) = irqctx;
23491+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23492+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23493
23494 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23495 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23496@@ -152,7 +141,6 @@ void irq_ctx_init(int cpu)
23497 asmlinkage void do_softirq(void)
23498 {
23499 unsigned long flags;
23500- struct thread_info *curctx;
23501 union irq_ctx *irqctx;
23502 u32 *isp;
23503
23504@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
23505 local_irq_save(flags);
23506
23507 if (local_softirq_pending()) {
23508- curctx = current_thread_info();
23509 irqctx = __this_cpu_read(softirq_ctx);
23510- irqctx->tinfo.task = curctx->task;
23511- irqctx->tinfo.previous_esp = current_stack_pointer;
23512+ irqctx->previous_esp = current_stack_pointer;
23513
23514 /* build the stack frame on the softirq stack */
23515- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23516+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23517+
23518+#ifdef CONFIG_PAX_MEMORY_UDEREF
23519+ __set_fs(MAKE_MM_SEG(0));
23520+#endif
23521
23522 call_on_stack(__do_softirq, isp);
23523+
23524+#ifdef CONFIG_PAX_MEMORY_UDEREF
23525+ __set_fs(current_thread_info()->addr_limit);
23526+#endif
23527+
23528 /*
23529 * Shouldn't happen, we returned above if in_interrupt():
23530 */
23531@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
23532 if (unlikely(!desc))
23533 return false;
23534
23535- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23536+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23537 if (unlikely(overflow))
23538 print_stack_overflow();
23539 desc->handle_irq(irq, desc);
23540diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
23541index d04d3ec..ea4b374 100644
23542--- a/arch/x86/kernel/irq_64.c
23543+++ b/arch/x86/kernel/irq_64.c
23544@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
23545 u64 estack_top, estack_bottom;
23546 u64 curbase = (u64)task_stack_page(current);
23547
23548- if (user_mode_vm(regs))
23549+ if (user_mode(regs))
23550 return;
23551
23552 if (regs->sp >= curbase + sizeof(struct thread_info) +
23553diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
23554index dc1404b..bbc43e7 100644
23555--- a/arch/x86/kernel/kdebugfs.c
23556+++ b/arch/x86/kernel/kdebugfs.c
23557@@ -27,7 +27,7 @@ struct setup_data_node {
23558 u32 len;
23559 };
23560
23561-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
23562+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
23563 size_t count, loff_t *ppos)
23564 {
23565 struct setup_data_node *node = file->private_data;
23566diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
23567index 836f832..a8bda67 100644
23568--- a/arch/x86/kernel/kgdb.c
23569+++ b/arch/x86/kernel/kgdb.c
23570@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
23571 #ifdef CONFIG_X86_32
23572 switch (regno) {
23573 case GDB_SS:
23574- if (!user_mode_vm(regs))
23575+ if (!user_mode(regs))
23576 *(unsigned long *)mem = __KERNEL_DS;
23577 break;
23578 case GDB_SP:
23579- if (!user_mode_vm(regs))
23580+ if (!user_mode(regs))
23581 *(unsigned long *)mem = kernel_stack_pointer(regs);
23582 break;
23583 case GDB_GS:
23584@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
23585 bp->attr.bp_addr = breakinfo[breakno].addr;
23586 bp->attr.bp_len = breakinfo[breakno].len;
23587 bp->attr.bp_type = breakinfo[breakno].type;
23588- info->address = breakinfo[breakno].addr;
23589+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
23590+ info->address = ktla_ktva(breakinfo[breakno].addr);
23591+ else
23592+ info->address = breakinfo[breakno].addr;
23593 info->len = breakinfo[breakno].len;
23594 info->type = breakinfo[breakno].type;
23595 val = arch_install_hw_breakpoint(bp);
23596@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
23597 case 'k':
23598 /* clear the trace bit */
23599 linux_regs->flags &= ~X86_EFLAGS_TF;
23600- atomic_set(&kgdb_cpu_doing_single_step, -1);
23601+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
23602
23603 /* set the trace bit if we're stepping */
23604 if (remcomInBuffer[0] == 's') {
23605 linux_regs->flags |= X86_EFLAGS_TF;
23606- atomic_set(&kgdb_cpu_doing_single_step,
23607+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
23608 raw_smp_processor_id());
23609 }
23610
23611@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
23612
23613 switch (cmd) {
23614 case DIE_DEBUG:
23615- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
23616+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
23617 if (user_mode(regs))
23618 return single_step_cont(regs, args);
23619 break;
23620@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23621 #endif /* CONFIG_DEBUG_RODATA */
23622
23623 bpt->type = BP_BREAKPOINT;
23624- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
23625+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
23626 BREAK_INSTR_SIZE);
23627 if (err)
23628 return err;
23629- err = probe_kernel_write((char *)bpt->bpt_addr,
23630+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23631 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
23632 #ifdef CONFIG_DEBUG_RODATA
23633 if (!err)
23634@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23635 return -EBUSY;
23636 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
23637 BREAK_INSTR_SIZE);
23638- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23639+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23640 if (err)
23641 return err;
23642 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
23643@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
23644 if (mutex_is_locked(&text_mutex))
23645 goto knl_write;
23646 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
23647- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23648+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23649 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
23650 goto knl_write;
23651 return err;
23652 knl_write:
23653 #endif /* CONFIG_DEBUG_RODATA */
23654- return probe_kernel_write((char *)bpt->bpt_addr,
23655+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23656 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
23657 }
23658
23659diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
23660index 211bce4..6e2580a 100644
23661--- a/arch/x86/kernel/kprobes/core.c
23662+++ b/arch/x86/kernel/kprobes/core.c
23663@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
23664 s32 raddr;
23665 } __packed *insn;
23666
23667- insn = (struct __arch_relative_insn *)from;
23668+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
23669+
23670+ pax_open_kernel();
23671 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
23672 insn->op = op;
23673+ pax_close_kernel();
23674 }
23675
23676 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
23677@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
23678 kprobe_opcode_t opcode;
23679 kprobe_opcode_t *orig_opcodes = opcodes;
23680
23681- if (search_exception_tables((unsigned long)opcodes))
23682+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
23683 return 0; /* Page fault may occur on this address. */
23684
23685 retry:
23686@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
23687 * for the first byte, we can recover the original instruction
23688 * from it and kp->opcode.
23689 */
23690- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23691+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23692 buf[0] = kp->opcode;
23693- return (unsigned long)buf;
23694+ return ktva_ktla((unsigned long)buf);
23695 }
23696
23697 /*
23698@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23699 /* Another subsystem puts a breakpoint, failed to recover */
23700 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
23701 return 0;
23702+ pax_open_kernel();
23703 memcpy(dest, insn.kaddr, insn.length);
23704+ pax_close_kernel();
23705
23706 #ifdef CONFIG_X86_64
23707 if (insn_rip_relative(&insn)) {
23708@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23709 return 0;
23710 }
23711 disp = (u8 *) dest + insn_offset_displacement(&insn);
23712+ pax_open_kernel();
23713 *(s32 *) disp = (s32) newdisp;
23714+ pax_close_kernel();
23715 }
23716 #endif
23717 return insn.length;
23718@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23719 * nor set current_kprobe, because it doesn't use single
23720 * stepping.
23721 */
23722- regs->ip = (unsigned long)p->ainsn.insn;
23723+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23724 preempt_enable_no_resched();
23725 return;
23726 }
23727@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23728 regs->flags &= ~X86_EFLAGS_IF;
23729 /* single step inline if the instruction is an int3 */
23730 if (p->opcode == BREAKPOINT_INSTRUCTION)
23731- regs->ip = (unsigned long)p->addr;
23732+ regs->ip = ktla_ktva((unsigned long)p->addr);
23733 else
23734- regs->ip = (unsigned long)p->ainsn.insn;
23735+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23736 }
23737
23738 /*
23739@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
23740 setup_singlestep(p, regs, kcb, 0);
23741 return 1;
23742 }
23743- } else if (*addr != BREAKPOINT_INSTRUCTION) {
23744+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
23745 /*
23746 * The breakpoint instruction was removed right
23747 * after we hit it. Another cpu has removed
23748@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
23749 " movq %rax, 152(%rsp)\n"
23750 RESTORE_REGS_STRING
23751 " popfq\n"
23752+#ifdef KERNEXEC_PLUGIN
23753+ " btsq $63,(%rsp)\n"
23754+#endif
23755 #else
23756 " pushf\n"
23757 SAVE_REGS_STRING
23758@@ -779,7 +789,7 @@ static void __kprobes
23759 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
23760 {
23761 unsigned long *tos = stack_addr(regs);
23762- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
23763+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
23764 unsigned long orig_ip = (unsigned long)p->addr;
23765 kprobe_opcode_t *insn = p->ainsn.insn;
23766
23767@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
23768 struct die_args *args = data;
23769 int ret = NOTIFY_DONE;
23770
23771- if (args->regs && user_mode_vm(args->regs))
23772+ if (args->regs && user_mode(args->regs))
23773 return ret;
23774
23775 switch (val) {
23776diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
23777index 76dc6f0..66bdfc3 100644
23778--- a/arch/x86/kernel/kprobes/opt.c
23779+++ b/arch/x86/kernel/kprobes/opt.c
23780@@ -79,6 +79,7 @@ found:
23781 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
23782 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
23783 {
23784+ pax_open_kernel();
23785 #ifdef CONFIG_X86_64
23786 *addr++ = 0x48;
23787 *addr++ = 0xbf;
23788@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
23789 *addr++ = 0xb8;
23790 #endif
23791 *(unsigned long *)addr = val;
23792+ pax_close_kernel();
23793 }
23794
23795 static void __used __kprobes kprobes_optinsn_template_holder(void)
23796@@ -338,7 +340,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23797 * Verify if the address gap is in 2GB range, because this uses
23798 * a relative jump.
23799 */
23800- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
23801+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
23802 if (abs(rel) > 0x7fffffff)
23803 return -ERANGE;
23804
23805@@ -353,16 +355,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23806 op->optinsn.size = ret;
23807
23808 /* Copy arch-dep-instance from template */
23809- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
23810+ pax_open_kernel();
23811+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
23812+ pax_close_kernel();
23813
23814 /* Set probe information */
23815 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
23816
23817 /* Set probe function call */
23818- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
23819+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
23820
23821 /* Set returning jmp instruction at the tail of out-of-line buffer */
23822- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
23823+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
23824 (u8 *)op->kp.addr + op->optinsn.size);
23825
23826 flush_icache_range((unsigned long) buf,
23827@@ -385,7 +389,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
23828 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
23829
23830 /* Backup instructions which will be replaced by jump address */
23831- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
23832+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
23833 RELATIVE_ADDR_SIZE);
23834
23835 insn_buf[0] = RELATIVEJUMP_OPCODE;
23836@@ -483,7 +487,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
23837 /* This kprobe is really able to run optimized path. */
23838 op = container_of(p, struct optimized_kprobe, kp);
23839 /* Detour through copied instructions */
23840- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
23841+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
23842 if (!reenter)
23843 reset_current_kprobe();
23844 preempt_enable_no_resched();
23845diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
23846index ebc9873..1b9724b 100644
23847--- a/arch/x86/kernel/ldt.c
23848+++ b/arch/x86/kernel/ldt.c
23849@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
23850 if (reload) {
23851 #ifdef CONFIG_SMP
23852 preempt_disable();
23853- load_LDT(pc);
23854+ load_LDT_nolock(pc);
23855 if (!cpumask_equal(mm_cpumask(current->mm),
23856 cpumask_of(smp_processor_id())))
23857 smp_call_function(flush_ldt, current->mm, 1);
23858 preempt_enable();
23859 #else
23860- load_LDT(pc);
23861+ load_LDT_nolock(pc);
23862 #endif
23863 }
23864 if (oldsize) {
23865@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
23866 return err;
23867
23868 for (i = 0; i < old->size; i++)
23869- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
23870+ write_ldt_entry(new->ldt, i, old->ldt + i);
23871 return 0;
23872 }
23873
23874@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
23875 retval = copy_ldt(&mm->context, &old_mm->context);
23876 mutex_unlock(&old_mm->context.lock);
23877 }
23878+
23879+ if (tsk == current) {
23880+ mm->context.vdso = 0;
23881+
23882+#ifdef CONFIG_X86_32
23883+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23884+ mm->context.user_cs_base = 0UL;
23885+ mm->context.user_cs_limit = ~0UL;
23886+
23887+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
23888+ cpus_clear(mm->context.cpu_user_cs_mask);
23889+#endif
23890+
23891+#endif
23892+#endif
23893+
23894+ }
23895+
23896 return retval;
23897 }
23898
23899@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
23900 }
23901 }
23902
23903+#ifdef CONFIG_PAX_SEGMEXEC
23904+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
23905+ error = -EINVAL;
23906+ goto out_unlock;
23907+ }
23908+#endif
23909+
23910 fill_ldt(&ldt, &ldt_info);
23911 if (oldmode)
23912 ldt.avl = 0;
23913diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
23914index 5b19e4d..6476a76 100644
23915--- a/arch/x86/kernel/machine_kexec_32.c
23916+++ b/arch/x86/kernel/machine_kexec_32.c
23917@@ -26,7 +26,7 @@
23918 #include <asm/cacheflush.h>
23919 #include <asm/debugreg.h>
23920
23921-static void set_idt(void *newidt, __u16 limit)
23922+static void set_idt(struct desc_struct *newidt, __u16 limit)
23923 {
23924 struct desc_ptr curidt;
23925
23926@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
23927 }
23928
23929
23930-static void set_gdt(void *newgdt, __u16 limit)
23931+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
23932 {
23933 struct desc_ptr curgdt;
23934
23935@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
23936 }
23937
23938 control_page = page_address(image->control_code_page);
23939- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
23940+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
23941
23942 relocate_kernel_ptr = control_page;
23943 page_list[PA_CONTROL_PAGE] = __pa(control_page);
23944diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
23945index 15c9876..0a43909 100644
23946--- a/arch/x86/kernel/microcode_core.c
23947+++ b/arch/x86/kernel/microcode_core.c
23948@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
23949 return NOTIFY_OK;
23950 }
23951
23952-static struct notifier_block __refdata mc_cpu_notifier = {
23953+static struct notifier_block mc_cpu_notifier = {
23954 .notifier_call = mc_cpu_callback,
23955 };
23956
23957diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
23958index 5fb2ceb..3ae90bb 100644
23959--- a/arch/x86/kernel/microcode_intel.c
23960+++ b/arch/x86/kernel/microcode_intel.c
23961@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
23962
23963 static int get_ucode_user(void *to, const void *from, size_t n)
23964 {
23965- return copy_from_user(to, from, n);
23966+ return copy_from_user(to, (const void __force_user *)from, n);
23967 }
23968
23969 static enum ucode_state
23970 request_microcode_user(int cpu, const void __user *buf, size_t size)
23971 {
23972- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
23973+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
23974 }
23975
23976 static void microcode_fini_cpu(int cpu)
23977diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
23978index 216a4d7..228255a 100644
23979--- a/arch/x86/kernel/module.c
23980+++ b/arch/x86/kernel/module.c
23981@@ -43,15 +43,60 @@ do { \
23982 } while (0)
23983 #endif
23984
23985-void *module_alloc(unsigned long size)
23986+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
23987 {
23988- if (PAGE_ALIGN(size) > MODULES_LEN)
23989+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
23990 return NULL;
23991 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
23992- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
23993+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
23994 -1, __builtin_return_address(0));
23995 }
23996
23997+void *module_alloc(unsigned long size)
23998+{
23999+
24000+#ifdef CONFIG_PAX_KERNEXEC
24001+ return __module_alloc(size, PAGE_KERNEL);
24002+#else
24003+ return __module_alloc(size, PAGE_KERNEL_EXEC);
24004+#endif
24005+
24006+}
24007+
24008+#ifdef CONFIG_PAX_KERNEXEC
24009+#ifdef CONFIG_X86_32
24010+void *module_alloc_exec(unsigned long size)
24011+{
24012+ struct vm_struct *area;
24013+
24014+ if (size == 0)
24015+ return NULL;
24016+
24017+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
24018+ return area ? area->addr : NULL;
24019+}
24020+EXPORT_SYMBOL(module_alloc_exec);
24021+
24022+void module_free_exec(struct module *mod, void *module_region)
24023+{
24024+ vunmap(module_region);
24025+}
24026+EXPORT_SYMBOL(module_free_exec);
24027+#else
24028+void module_free_exec(struct module *mod, void *module_region)
24029+{
24030+ module_free(mod, module_region);
24031+}
24032+EXPORT_SYMBOL(module_free_exec);
24033+
24034+void *module_alloc_exec(unsigned long size)
24035+{
24036+ return __module_alloc(size, PAGE_KERNEL_RX);
24037+}
24038+EXPORT_SYMBOL(module_alloc_exec);
24039+#endif
24040+#endif
24041+
24042 #ifdef CONFIG_X86_32
24043 int apply_relocate(Elf32_Shdr *sechdrs,
24044 const char *strtab,
24045@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24046 unsigned int i;
24047 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
24048 Elf32_Sym *sym;
24049- uint32_t *location;
24050+ uint32_t *plocation, location;
24051
24052 DEBUGP("Applying relocate section %u to %u\n",
24053 relsec, sechdrs[relsec].sh_info);
24054 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
24055 /* This is where to make the change */
24056- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
24057- + rel[i].r_offset;
24058+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
24059+ location = (uint32_t)plocation;
24060+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
24061+ plocation = ktla_ktva((void *)plocation);
24062 /* This is the symbol it is referring to. Note that all
24063 undefined symbols have been resolved. */
24064 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
24065@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24066 switch (ELF32_R_TYPE(rel[i].r_info)) {
24067 case R_386_32:
24068 /* We add the value into the location given */
24069- *location += sym->st_value;
24070+ pax_open_kernel();
24071+ *plocation += sym->st_value;
24072+ pax_close_kernel();
24073 break;
24074 case R_386_PC32:
24075 /* Add the value, subtract its position */
24076- *location += sym->st_value - (uint32_t)location;
24077+ pax_open_kernel();
24078+ *plocation += sym->st_value - location;
24079+ pax_close_kernel();
24080 break;
24081 default:
24082 pr_err("%s: Unknown relocation: %u\n",
24083@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
24084 case R_X86_64_NONE:
24085 break;
24086 case R_X86_64_64:
24087+ pax_open_kernel();
24088 *(u64 *)loc = val;
24089+ pax_close_kernel();
24090 break;
24091 case R_X86_64_32:
24092+ pax_open_kernel();
24093 *(u32 *)loc = val;
24094+ pax_close_kernel();
24095 if (val != *(u32 *)loc)
24096 goto overflow;
24097 break;
24098 case R_X86_64_32S:
24099+ pax_open_kernel();
24100 *(s32 *)loc = val;
24101+ pax_close_kernel();
24102 if ((s64)val != *(s32 *)loc)
24103 goto overflow;
24104 break;
24105 case R_X86_64_PC32:
24106 val -= (u64)loc;
24107+ pax_open_kernel();
24108 *(u32 *)loc = val;
24109+ pax_close_kernel();
24110+
24111 #if 0
24112 if ((s64)val != *(s32 *)loc)
24113 goto overflow;
24114diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
24115index 88458fa..349f7a4 100644
24116--- a/arch/x86/kernel/msr.c
24117+++ b/arch/x86/kernel/msr.c
24118@@ -233,7 +233,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
24119 return notifier_from_errno(err);
24120 }
24121
24122-static struct notifier_block __refdata msr_class_cpu_notifier = {
24123+static struct notifier_block msr_class_cpu_notifier = {
24124 .notifier_call = msr_class_cpu_callback,
24125 };
24126
24127diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
24128index ba77ebc..65da999 100644
24129--- a/arch/x86/kernel/nmi.c
24130+++ b/arch/x86/kernel/nmi.c
24131@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
24132 return handled;
24133 }
24134
24135-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24136+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
24137 {
24138 struct nmi_desc *desc = nmi_to_desc(type);
24139 unsigned long flags;
24140@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24141 * event confuses some handlers (kdump uses this flag)
24142 */
24143 if (action->flags & NMI_FLAG_FIRST)
24144- list_add_rcu(&action->list, &desc->head);
24145+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
24146 else
24147- list_add_tail_rcu(&action->list, &desc->head);
24148+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
24149
24150 spin_unlock_irqrestore(&desc->lock, flags);
24151 return 0;
24152@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
24153 if (!strcmp(n->name, name)) {
24154 WARN(in_nmi(),
24155 "Trying to free NMI (%s) from NMI context!\n", n->name);
24156- list_del_rcu(&n->list);
24157+ pax_list_del_rcu((struct list_head *)&n->list);
24158 break;
24159 }
24160 }
24161@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
24162 dotraplinkage notrace __kprobes void
24163 do_nmi(struct pt_regs *regs, long error_code)
24164 {
24165+
24166+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24167+ if (!user_mode(regs)) {
24168+ unsigned long cs = regs->cs & 0xFFFF;
24169+ unsigned long ip = ktva_ktla(regs->ip);
24170+
24171+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
24172+ regs->ip = ip;
24173+ }
24174+#endif
24175+
24176 nmi_nesting_preprocess(regs);
24177
24178 nmi_enter();
24179diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
24180index 6d9582e..f746287 100644
24181--- a/arch/x86/kernel/nmi_selftest.c
24182+++ b/arch/x86/kernel/nmi_selftest.c
24183@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
24184 {
24185 /* trap all the unknown NMIs we may generate */
24186 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
24187- __initdata);
24188+ __initconst);
24189 }
24190
24191 static void __init cleanup_nmi_testsuite(void)
24192@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
24193 unsigned long timeout;
24194
24195 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
24196- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
24197+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
24198 nmi_fail = FAILURE;
24199 return;
24200 }
24201diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
24202index 676b8c7..870ba04 100644
24203--- a/arch/x86/kernel/paravirt-spinlocks.c
24204+++ b/arch/x86/kernel/paravirt-spinlocks.c
24205@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
24206 arch_spin_lock(lock);
24207 }
24208
24209-struct pv_lock_ops pv_lock_ops = {
24210+struct pv_lock_ops pv_lock_ops __read_only = {
24211 #ifdef CONFIG_SMP
24212 .spin_is_locked = __ticket_spin_is_locked,
24213 .spin_is_contended = __ticket_spin_is_contended,
24214diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
24215index cd6de64..27c6af0 100644
24216--- a/arch/x86/kernel/paravirt.c
24217+++ b/arch/x86/kernel/paravirt.c
24218@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
24219 {
24220 return x;
24221 }
24222+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24223+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
24224+#endif
24225
24226 void __init default_banner(void)
24227 {
24228@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
24229 if (opfunc == NULL)
24230 /* If there's no function, patch it with a ud2a (BUG) */
24231 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
24232- else if (opfunc == _paravirt_nop)
24233+ else if (opfunc == (void *)_paravirt_nop)
24234 /* If the operation is a nop, then nop the callsite */
24235 ret = paravirt_patch_nop();
24236
24237 /* identity functions just return their single argument */
24238- else if (opfunc == _paravirt_ident_32)
24239+ else if (opfunc == (void *)_paravirt_ident_32)
24240 ret = paravirt_patch_ident_32(insnbuf, len);
24241- else if (opfunc == _paravirt_ident_64)
24242+ else if (opfunc == (void *)_paravirt_ident_64)
24243 ret = paravirt_patch_ident_64(insnbuf, len);
24244+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24245+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
24246+ ret = paravirt_patch_ident_64(insnbuf, len);
24247+#endif
24248
24249 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
24250 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
24251@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
24252 if (insn_len > len || start == NULL)
24253 insn_len = len;
24254 else
24255- memcpy(insnbuf, start, insn_len);
24256+ memcpy(insnbuf, ktla_ktva(start), insn_len);
24257
24258 return insn_len;
24259 }
24260@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
24261 return this_cpu_read(paravirt_lazy_mode);
24262 }
24263
24264-struct pv_info pv_info = {
24265+struct pv_info pv_info __read_only = {
24266 .name = "bare hardware",
24267 .paravirt_enabled = 0,
24268 .kernel_rpl = 0,
24269@@ -315,16 +322,16 @@ struct pv_info pv_info = {
24270 #endif
24271 };
24272
24273-struct pv_init_ops pv_init_ops = {
24274+struct pv_init_ops pv_init_ops __read_only = {
24275 .patch = native_patch,
24276 };
24277
24278-struct pv_time_ops pv_time_ops = {
24279+struct pv_time_ops pv_time_ops __read_only = {
24280 .sched_clock = native_sched_clock,
24281 .steal_clock = native_steal_clock,
24282 };
24283
24284-struct pv_irq_ops pv_irq_ops = {
24285+struct pv_irq_ops pv_irq_ops __read_only = {
24286 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
24287 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
24288 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
24289@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
24290 #endif
24291 };
24292
24293-struct pv_cpu_ops pv_cpu_ops = {
24294+struct pv_cpu_ops pv_cpu_ops __read_only = {
24295 .cpuid = native_cpuid,
24296 .get_debugreg = native_get_debugreg,
24297 .set_debugreg = native_set_debugreg,
24298@@ -394,21 +401,26 @@ struct pv_cpu_ops pv_cpu_ops = {
24299 .end_context_switch = paravirt_nop,
24300 };
24301
24302-struct pv_apic_ops pv_apic_ops = {
24303+struct pv_apic_ops pv_apic_ops __read_only= {
24304 #ifdef CONFIG_X86_LOCAL_APIC
24305 .startup_ipi_hook = paravirt_nop,
24306 #endif
24307 };
24308
24309-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
24310+#ifdef CONFIG_X86_32
24311+#ifdef CONFIG_X86_PAE
24312+/* 64-bit pagetable entries */
24313+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
24314+#else
24315 /* 32-bit pagetable entries */
24316 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
24317+#endif
24318 #else
24319 /* 64-bit pagetable entries */
24320 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
24321 #endif
24322
24323-struct pv_mmu_ops pv_mmu_ops = {
24324+struct pv_mmu_ops pv_mmu_ops __read_only = {
24325
24326 .read_cr2 = native_read_cr2,
24327 .write_cr2 = native_write_cr2,
24328@@ -458,6 +470,7 @@ struct pv_mmu_ops pv_mmu_ops = {
24329 .make_pud = PTE_IDENT,
24330
24331 .set_pgd = native_set_pgd,
24332+ .set_pgd_batched = native_set_pgd_batched,
24333 #endif
24334 #endif /* PAGETABLE_LEVELS >= 3 */
24335
24336@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
24337 },
24338
24339 .set_fixmap = native_set_fixmap,
24340+
24341+#ifdef CONFIG_PAX_KERNEXEC
24342+ .pax_open_kernel = native_pax_open_kernel,
24343+ .pax_close_kernel = native_pax_close_kernel,
24344+#endif
24345+
24346 };
24347
24348 EXPORT_SYMBOL_GPL(pv_time_ops);
24349diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
24350index 299d493..2ccb0ee 100644
24351--- a/arch/x86/kernel/pci-calgary_64.c
24352+++ b/arch/x86/kernel/pci-calgary_64.c
24353@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
24354 tce_space = be64_to_cpu(readq(target));
24355 tce_space = tce_space & TAR_SW_BITS;
24356
24357- tce_space = tce_space & (~specified_table_size);
24358+ tce_space = tce_space & (~(unsigned long)specified_table_size);
24359 info->tce_space = (u64 *)__va(tce_space);
24360 }
24361 }
24362diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
24363index 35ccf75..7a15747 100644
24364--- a/arch/x86/kernel/pci-iommu_table.c
24365+++ b/arch/x86/kernel/pci-iommu_table.c
24366@@ -2,7 +2,7 @@
24367 #include <asm/iommu_table.h>
24368 #include <linux/string.h>
24369 #include <linux/kallsyms.h>
24370-
24371+#include <linux/sched.h>
24372
24373 #define DEBUG 1
24374
24375diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
24376index 6c483ba..d10ce2f 100644
24377--- a/arch/x86/kernel/pci-swiotlb.c
24378+++ b/arch/x86/kernel/pci-swiotlb.c
24379@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
24380 void *vaddr, dma_addr_t dma_addr,
24381 struct dma_attrs *attrs)
24382 {
24383- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
24384+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
24385 }
24386
24387 static struct dma_map_ops swiotlb_dma_ops = {
24388diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
24389index 83369e5..52b93f0 100644
24390--- a/arch/x86/kernel/process.c
24391+++ b/arch/x86/kernel/process.c
24392@@ -36,7 +36,8 @@
24393 * section. Since TSS's are completely CPU-local, we want them
24394 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
24395 */
24396-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
24397+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
24398+EXPORT_SYMBOL(init_tss);
24399
24400 #ifdef CONFIG_X86_64
24401 static DEFINE_PER_CPU(unsigned char, is_idle);
24402@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
24403 task_xstate_cachep =
24404 kmem_cache_create("task_xstate", xstate_size,
24405 __alignof__(union thread_xstate),
24406- SLAB_PANIC | SLAB_NOTRACK, NULL);
24407+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
24408 }
24409
24410 /*
24411@@ -105,7 +106,7 @@ void exit_thread(void)
24412 unsigned long *bp = t->io_bitmap_ptr;
24413
24414 if (bp) {
24415- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
24416+ struct tss_struct *tss = init_tss + get_cpu();
24417
24418 t->io_bitmap_ptr = NULL;
24419 clear_thread_flag(TIF_IO_BITMAP);
24420@@ -125,6 +126,9 @@ void flush_thread(void)
24421 {
24422 struct task_struct *tsk = current;
24423
24424+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
24425+ loadsegment(gs, 0);
24426+#endif
24427 flush_ptrace_hw_breakpoint(tsk);
24428 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
24429 drop_init_fpu(tsk);
24430@@ -271,7 +275,7 @@ static void __exit_idle(void)
24431 void exit_idle(void)
24432 {
24433 /* idle loop has pid 0 */
24434- if (current->pid)
24435+ if (task_pid_nr(current))
24436 return;
24437 __exit_idle();
24438 }
24439@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
24440 return ret;
24441 }
24442 #endif
24443-void stop_this_cpu(void *dummy)
24444+__noreturn void stop_this_cpu(void *dummy)
24445 {
24446 local_irq_disable();
24447 /*
24448@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
24449 }
24450 early_param("idle", idle_setup);
24451
24452-unsigned long arch_align_stack(unsigned long sp)
24453+#ifdef CONFIG_PAX_RANDKSTACK
24454+void pax_randomize_kstack(struct pt_regs *regs)
24455 {
24456- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
24457- sp -= get_random_int() % 8192;
24458- return sp & ~0xf;
24459-}
24460+ struct thread_struct *thread = &current->thread;
24461+ unsigned long time;
24462
24463-unsigned long arch_randomize_brk(struct mm_struct *mm)
24464-{
24465- unsigned long range_end = mm->brk + 0x02000000;
24466- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
24467-}
24468+ if (!randomize_va_space)
24469+ return;
24470+
24471+ if (v8086_mode(regs))
24472+ return;
24473
24474+ rdtscl(time);
24475+
24476+ /* P4 seems to return a 0 LSB, ignore it */
24477+#ifdef CONFIG_MPENTIUM4
24478+ time &= 0x3EUL;
24479+ time <<= 2;
24480+#elif defined(CONFIG_X86_64)
24481+ time &= 0xFUL;
24482+ time <<= 4;
24483+#else
24484+ time &= 0x1FUL;
24485+ time <<= 3;
24486+#endif
24487+
24488+ thread->sp0 ^= time;
24489+ load_sp0(init_tss + smp_processor_id(), thread);
24490+
24491+#ifdef CONFIG_X86_64
24492+ this_cpu_write(kernel_stack, thread->sp0);
24493+#endif
24494+}
24495+#endif
24496diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
24497index f8adefc..4bce3d6 100644
24498--- a/arch/x86/kernel/process_32.c
24499+++ b/arch/x86/kernel/process_32.c
24500@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
24501 unsigned long thread_saved_pc(struct task_struct *tsk)
24502 {
24503 return ((unsigned long *)tsk->thread.sp)[3];
24504+//XXX return tsk->thread.eip;
24505 }
24506
24507 void __show_regs(struct pt_regs *regs, int all)
24508@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
24509 unsigned long sp;
24510 unsigned short ss, gs;
24511
24512- if (user_mode_vm(regs)) {
24513+ if (user_mode(regs)) {
24514 sp = regs->sp;
24515 ss = regs->ss & 0xffff;
24516- gs = get_user_gs(regs);
24517 } else {
24518 sp = kernel_stack_pointer(regs);
24519 savesegment(ss, ss);
24520- savesegment(gs, gs);
24521 }
24522+ gs = get_user_gs(regs);
24523
24524 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
24525 (u16)regs->cs, regs->ip, regs->flags,
24526- smp_processor_id());
24527+ raw_smp_processor_id());
24528 print_symbol("EIP is at %s\n", regs->ip);
24529
24530 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
24531@@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
24532 int copy_thread(unsigned long clone_flags, unsigned long sp,
24533 unsigned long arg, struct task_struct *p)
24534 {
24535- struct pt_regs *childregs = task_pt_regs(p);
24536+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
24537 struct task_struct *tsk;
24538 int err;
24539
24540 p->thread.sp = (unsigned long) childregs;
24541 p->thread.sp0 = (unsigned long) (childregs+1);
24542+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24543
24544 if (unlikely(p->flags & PF_KTHREAD)) {
24545 /* kernel thread */
24546 memset(childregs, 0, sizeof(struct pt_regs));
24547 p->thread.ip = (unsigned long) ret_from_kernel_thread;
24548- task_user_gs(p) = __KERNEL_STACK_CANARY;
24549- childregs->ds = __USER_DS;
24550- childregs->es = __USER_DS;
24551+ savesegment(gs, childregs->gs);
24552+ childregs->ds = __KERNEL_DS;
24553+ childregs->es = __KERNEL_DS;
24554 childregs->fs = __KERNEL_PERCPU;
24555 childregs->bx = sp; /* function */
24556 childregs->bp = arg;
24557@@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24558 struct thread_struct *prev = &prev_p->thread,
24559 *next = &next_p->thread;
24560 int cpu = smp_processor_id();
24561- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24562+ struct tss_struct *tss = init_tss + cpu;
24563 fpu_switch_t fpu;
24564
24565 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
24566@@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24567 */
24568 lazy_save_gs(prev->gs);
24569
24570+#ifdef CONFIG_PAX_MEMORY_UDEREF
24571+ __set_fs(task_thread_info(next_p)->addr_limit);
24572+#endif
24573+
24574 /*
24575 * Load the per-thread Thread-Local Storage descriptor.
24576 */
24577@@ -307,6 +312,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24578 */
24579 arch_end_context_switch(next_p);
24580
24581+ this_cpu_write(current_task, next_p);
24582+ this_cpu_write(current_tinfo, &next_p->tinfo);
24583+
24584 /*
24585 * Restore %gs if needed (which is common)
24586 */
24587@@ -315,8 +323,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24588
24589 switch_fpu_finish(next_p, fpu);
24590
24591- this_cpu_write(current_task, next_p);
24592-
24593 return prev_p;
24594 }
24595
24596@@ -346,4 +352,3 @@ unsigned long get_wchan(struct task_struct *p)
24597 } while (count++ < 16);
24598 return 0;
24599 }
24600-
24601diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
24602index 05646ba..0c2906d 100644
24603--- a/arch/x86/kernel/process_64.c
24604+++ b/arch/x86/kernel/process_64.c
24605@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24606 struct pt_regs *childregs;
24607 struct task_struct *me = current;
24608
24609- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
24610+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
24611 childregs = task_pt_regs(p);
24612 p->thread.sp = (unsigned long) childregs;
24613 p->thread.usersp = me->thread.usersp;
24614+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24615 set_tsk_thread_flag(p, TIF_FORK);
24616 p->fpu_counter = 0;
24617 p->thread.io_bitmap_ptr = NULL;
24618@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24619 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
24620 savesegment(es, p->thread.es);
24621 savesegment(ds, p->thread.ds);
24622+ savesegment(ss, p->thread.ss);
24623+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
24624 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
24625
24626 if (unlikely(p->flags & PF_KTHREAD)) {
24627@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24628 struct thread_struct *prev = &prev_p->thread;
24629 struct thread_struct *next = &next_p->thread;
24630 int cpu = smp_processor_id();
24631- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24632+ struct tss_struct *tss = init_tss + cpu;
24633 unsigned fsindex, gsindex;
24634 fpu_switch_t fpu;
24635
24636@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24637 if (unlikely(next->ds | prev->ds))
24638 loadsegment(ds, next->ds);
24639
24640+ savesegment(ss, prev->ss);
24641+ if (unlikely(next->ss != prev->ss))
24642+ loadsegment(ss, next->ss);
24643
24644 /* We must save %fs and %gs before load_TLS() because
24645 * %fs and %gs may be cleared by load_TLS().
24646@@ -362,10 +368,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24647 prev->usersp = this_cpu_read(old_rsp);
24648 this_cpu_write(old_rsp, next->usersp);
24649 this_cpu_write(current_task, next_p);
24650+ this_cpu_write(current_tinfo, &next_p->tinfo);
24651
24652- this_cpu_write(kernel_stack,
24653- (unsigned long)task_stack_page(next_p) +
24654- THREAD_SIZE - KERNEL_STACK_OFFSET);
24655+ this_cpu_write(kernel_stack, next->sp0);
24656
24657 /*
24658 * Now maybe reload the debug registers and handle I/O bitmaps
24659@@ -434,12 +439,11 @@ unsigned long get_wchan(struct task_struct *p)
24660 if (!p || p == current || p->state == TASK_RUNNING)
24661 return 0;
24662 stack = (unsigned long)task_stack_page(p);
24663- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
24664+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
24665 return 0;
24666 fp = *(u64 *)(p->thread.sp);
24667 do {
24668- if (fp < (unsigned long)stack ||
24669- fp >= (unsigned long)stack+THREAD_SIZE)
24670+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
24671 return 0;
24672 ip = *(u64 *)(fp+8);
24673 if (!in_sched_functions(ip))
24674diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
24675index 7461f50..1334029 100644
24676--- a/arch/x86/kernel/ptrace.c
24677+++ b/arch/x86/kernel/ptrace.c
24678@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
24679 {
24680 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
24681 unsigned long sp = (unsigned long)&regs->sp;
24682- struct thread_info *tinfo;
24683
24684- if (context == (sp & ~(THREAD_SIZE - 1)))
24685+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
24686 return sp;
24687
24688- tinfo = (struct thread_info *)context;
24689- if (tinfo->previous_esp)
24690- return tinfo->previous_esp;
24691+ sp = *(unsigned long *)context;
24692+ if (sp)
24693+ return sp;
24694
24695 return (unsigned long)regs;
24696 }
24697@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
24698 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
24699 {
24700 int i;
24701- int dr7 = 0;
24702+ unsigned long dr7 = 0;
24703 struct arch_hw_breakpoint *info;
24704
24705 for (i = 0; i < HBP_NUM; i++) {
24706@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
24707 unsigned long addr, unsigned long data)
24708 {
24709 int ret;
24710- unsigned long __user *datap = (unsigned long __user *)data;
24711+ unsigned long __user *datap = (__force unsigned long __user *)data;
24712
24713 switch (request) {
24714 /* read the word at location addr in the USER area. */
24715@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
24716 if ((int) addr < 0)
24717 return -EIO;
24718 ret = do_get_thread_area(child, addr,
24719- (struct user_desc __user *)data);
24720+ (__force struct user_desc __user *) data);
24721 break;
24722
24723 case PTRACE_SET_THREAD_AREA:
24724 if ((int) addr < 0)
24725 return -EIO;
24726 ret = do_set_thread_area(child, addr,
24727- (struct user_desc __user *)data, 0);
24728+ (__force struct user_desc __user *) data, 0);
24729 break;
24730 #endif
24731
24732@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
24733
24734 #ifdef CONFIG_X86_64
24735
24736-static struct user_regset x86_64_regsets[] __read_mostly = {
24737+static user_regset_no_const x86_64_regsets[] __read_only = {
24738 [REGSET_GENERAL] = {
24739 .core_note_type = NT_PRSTATUS,
24740 .n = sizeof(struct user_regs_struct) / sizeof(long),
24741@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
24742 #endif /* CONFIG_X86_64 */
24743
24744 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
24745-static struct user_regset x86_32_regsets[] __read_mostly = {
24746+static user_regset_no_const x86_32_regsets[] __read_only = {
24747 [REGSET_GENERAL] = {
24748 .core_note_type = NT_PRSTATUS,
24749 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
24750@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
24751 */
24752 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
24753
24754-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24755+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24756 {
24757 #ifdef CONFIG_X86_64
24758 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
24759@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
24760 memset(info, 0, sizeof(*info));
24761 info->si_signo = SIGTRAP;
24762 info->si_code = si_code;
24763- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
24764+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
24765 }
24766
24767 void user_single_step_siginfo(struct task_struct *tsk,
24768@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
24769 # define IS_IA32 0
24770 #endif
24771
24772+#ifdef CONFIG_GRKERNSEC_SETXID
24773+extern void gr_delayed_cred_worker(void);
24774+#endif
24775+
24776 /*
24777 * We must return the syscall number to actually look up in the table.
24778 * This can be -1L to skip running any syscall at all.
24779@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
24780
24781 user_exit();
24782
24783+#ifdef CONFIG_GRKERNSEC_SETXID
24784+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24785+ gr_delayed_cred_worker();
24786+#endif
24787+
24788 /*
24789 * If we stepped into a sysenter/syscall insn, it trapped in
24790 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
24791@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
24792 */
24793 user_exit();
24794
24795+#ifdef CONFIG_GRKERNSEC_SETXID
24796+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24797+ gr_delayed_cred_worker();
24798+#endif
24799+
24800 audit_syscall_exit(regs);
24801
24802 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
24803diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
24804index 2cb9470..ff1fd80 100644
24805--- a/arch/x86/kernel/pvclock.c
24806+++ b/arch/x86/kernel/pvclock.c
24807@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
24808 return pv_tsc_khz;
24809 }
24810
24811-static atomic64_t last_value = ATOMIC64_INIT(0);
24812+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
24813
24814 void pvclock_resume(void)
24815 {
24816- atomic64_set(&last_value, 0);
24817+ atomic64_set_unchecked(&last_value, 0);
24818 }
24819
24820 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
24821@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
24822 * updating at the same time, and one of them could be slightly behind,
24823 * making the assumption that last_value always go forward fail to hold.
24824 */
24825- last = atomic64_read(&last_value);
24826+ last = atomic64_read_unchecked(&last_value);
24827 do {
24828 if (ret < last)
24829 return last;
24830- last = atomic64_cmpxchg(&last_value, last, ret);
24831+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
24832 } while (unlikely(last != ret));
24833
24834 return ret;
24835diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
24836index 563ed91..b9c3313 100644
24837--- a/arch/x86/kernel/reboot.c
24838+++ b/arch/x86/kernel/reboot.c
24839@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
24840
24841 void __noreturn machine_real_restart(unsigned int type)
24842 {
24843+
24844+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
24845+ struct desc_struct *gdt;
24846+#endif
24847+
24848 local_irq_disable();
24849
24850 /*
24851@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
24852
24853 /* Jump to the identity-mapped low memory code */
24854 #ifdef CONFIG_X86_32
24855- asm volatile("jmpl *%0" : :
24856+
24857+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
24858+ gdt = get_cpu_gdt_table(smp_processor_id());
24859+ pax_open_kernel();
24860+#ifdef CONFIG_PAX_MEMORY_UDEREF
24861+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
24862+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
24863+ loadsegment(ds, __KERNEL_DS);
24864+ loadsegment(es, __KERNEL_DS);
24865+ loadsegment(ss, __KERNEL_DS);
24866+#endif
24867+#ifdef CONFIG_PAX_KERNEXEC
24868+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
24869+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
24870+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
24871+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
24872+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
24873+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
24874+#endif
24875+ pax_close_kernel();
24876+#endif
24877+
24878+ asm volatile("ljmpl *%0" : :
24879 "rm" (real_mode_header->machine_real_restart_asm),
24880 "a" (type));
24881 #else
24882@@ -442,7 +469,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
24883 * try to force a triple fault and then cycle between hitting the keyboard
24884 * controller and doing that
24885 */
24886-static void native_machine_emergency_restart(void)
24887+static void __noreturn native_machine_emergency_restart(void)
24888 {
24889 int i;
24890 int attempt = 0;
24891@@ -551,13 +578,13 @@ void native_machine_shutdown(void)
24892 #endif
24893 }
24894
24895-static void __machine_emergency_restart(int emergency)
24896+static void __noreturn __machine_emergency_restart(int emergency)
24897 {
24898 reboot_emergency = emergency;
24899 machine_ops.emergency_restart();
24900 }
24901
24902-static void native_machine_restart(char *__unused)
24903+static void __noreturn native_machine_restart(char *__unused)
24904 {
24905 pr_notice("machine restart\n");
24906
24907@@ -566,7 +593,7 @@ static void native_machine_restart(char *__unused)
24908 __machine_emergency_restart(0);
24909 }
24910
24911-static void native_machine_halt(void)
24912+static void __noreturn native_machine_halt(void)
24913 {
24914 /* Stop other cpus and apics */
24915 machine_shutdown();
24916@@ -576,7 +603,7 @@ static void native_machine_halt(void)
24917 stop_this_cpu(NULL);
24918 }
24919
24920-static void native_machine_power_off(void)
24921+static void __noreturn native_machine_power_off(void)
24922 {
24923 if (pm_power_off) {
24924 if (!reboot_force)
24925@@ -585,9 +612,10 @@ static void native_machine_power_off(void)
24926 }
24927 /* A fallback in case there is no PM info available */
24928 tboot_shutdown(TB_SHUTDOWN_HALT);
24929+ unreachable();
24930 }
24931
24932-struct machine_ops machine_ops = {
24933+struct machine_ops machine_ops __read_only = {
24934 .power_off = native_machine_power_off,
24935 .shutdown = native_machine_shutdown,
24936 .emergency_restart = native_machine_emergency_restart,
24937diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
24938index c8e41e9..64049ef 100644
24939--- a/arch/x86/kernel/reboot_fixups_32.c
24940+++ b/arch/x86/kernel/reboot_fixups_32.c
24941@@ -57,7 +57,7 @@ struct device_fixup {
24942 unsigned int vendor;
24943 unsigned int device;
24944 void (*reboot_fixup)(struct pci_dev *);
24945-};
24946+} __do_const;
24947
24948 /*
24949 * PCI ids solely used for fixups_table go here
24950diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
24951index 3fd2c69..16ef367 100644
24952--- a/arch/x86/kernel/relocate_kernel_64.S
24953+++ b/arch/x86/kernel/relocate_kernel_64.S
24954@@ -11,6 +11,7 @@
24955 #include <asm/kexec.h>
24956 #include <asm/processor-flags.h>
24957 #include <asm/pgtable_types.h>
24958+#include <asm/alternative-asm.h>
24959
24960 /*
24961 * Must be relocatable PIC code callable as a C function
24962@@ -96,8 +97,7 @@ relocate_kernel:
24963
24964 /* jump to identity mapped page */
24965 addq $(identity_mapped - relocate_kernel), %r8
24966- pushq %r8
24967- ret
24968+ jmp *%r8
24969
24970 identity_mapped:
24971 /* set return address to 0 if not preserving context */
24972@@ -167,6 +167,7 @@ identity_mapped:
24973 xorl %r14d, %r14d
24974 xorl %r15d, %r15d
24975
24976+ pax_force_retaddr 0, 1
24977 ret
24978
24979 1:
24980diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
24981index f8ec578..0cc110a 100644
24982--- a/arch/x86/kernel/setup.c
24983+++ b/arch/x86/kernel/setup.c
24984@@ -110,6 +110,7 @@
24985 #include <asm/mce.h>
24986 #include <asm/alternative.h>
24987 #include <asm/prom.h>
24988+#include <asm/boot.h>
24989
24990 /*
24991 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
24992@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
24993 #endif
24994
24995
24996-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
24997-unsigned long mmu_cr4_features;
24998+#ifdef CONFIG_X86_64
24999+unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
25000+#elif defined(CONFIG_X86_PAE)
25001+unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
25002 #else
25003-unsigned long mmu_cr4_features = X86_CR4_PAE;
25004+unsigned long mmu_cr4_features __read_only;
25005 #endif
25006
25007+void set_in_cr4(unsigned long mask)
25008+{
25009+ unsigned long cr4 = read_cr4();
25010+
25011+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
25012+ return;
25013+
25014+ pax_open_kernel();
25015+ mmu_cr4_features |= mask;
25016+ pax_close_kernel();
25017+
25018+ if (trampoline_cr4_features)
25019+ *trampoline_cr4_features = mmu_cr4_features;
25020+ cr4 |= mask;
25021+ write_cr4(cr4);
25022+}
25023+EXPORT_SYMBOL(set_in_cr4);
25024+
25025+void clear_in_cr4(unsigned long mask)
25026+{
25027+ unsigned long cr4 = read_cr4();
25028+
25029+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
25030+ return;
25031+
25032+ pax_open_kernel();
25033+ mmu_cr4_features &= ~mask;
25034+ pax_close_kernel();
25035+
25036+ if (trampoline_cr4_features)
25037+ *trampoline_cr4_features = mmu_cr4_features;
25038+ cr4 &= ~mask;
25039+ write_cr4(cr4);
25040+}
25041+EXPORT_SYMBOL(clear_in_cr4);
25042+
25043 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
25044 int bootloader_type, bootloader_version;
25045
25046@@ -444,7 +483,7 @@ static void __init parse_setup_data(void)
25047
25048 switch (data->type) {
25049 case SETUP_E820_EXT:
25050- parse_e820_ext(data);
25051+ parse_e820_ext((struct setup_data __force_kernel *)data);
25052 break;
25053 case SETUP_DTB:
25054 add_dtb(pa_data);
25055@@ -771,7 +810,7 @@ static void __init trim_bios_range(void)
25056 * area (640->1Mb) as ram even though it is not.
25057 * take them out.
25058 */
25059- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
25060+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
25061
25062 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
25063 }
25064@@ -779,7 +818,7 @@ static void __init trim_bios_range(void)
25065 /* called before trim_bios_range() to spare extra sanitize */
25066 static void __init e820_add_kernel_range(void)
25067 {
25068- u64 start = __pa_symbol(_text);
25069+ u64 start = __pa_symbol(ktla_ktva(_text));
25070 u64 size = __pa_symbol(_end) - start;
25071
25072 /*
25073@@ -841,8 +880,12 @@ static void __init trim_low_memory_range(void)
25074
25075 void __init setup_arch(char **cmdline_p)
25076 {
25077+#ifdef CONFIG_X86_32
25078+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
25079+#else
25080 memblock_reserve(__pa_symbol(_text),
25081 (unsigned long)__bss_stop - (unsigned long)_text);
25082+#endif
25083
25084 early_reserve_initrd();
25085
25086@@ -934,14 +977,14 @@ void __init setup_arch(char **cmdline_p)
25087
25088 if (!boot_params.hdr.root_flags)
25089 root_mountflags &= ~MS_RDONLY;
25090- init_mm.start_code = (unsigned long) _text;
25091- init_mm.end_code = (unsigned long) _etext;
25092+ init_mm.start_code = ktla_ktva((unsigned long) _text);
25093+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
25094 init_mm.end_data = (unsigned long) _edata;
25095 init_mm.brk = _brk_end;
25096
25097- code_resource.start = __pa_symbol(_text);
25098- code_resource.end = __pa_symbol(_etext)-1;
25099- data_resource.start = __pa_symbol(_etext);
25100+ code_resource.start = __pa_symbol(ktla_ktva(_text));
25101+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
25102+ data_resource.start = __pa_symbol(_sdata);
25103 data_resource.end = __pa_symbol(_edata)-1;
25104 bss_resource.start = __pa_symbol(__bss_start);
25105 bss_resource.end = __pa_symbol(__bss_stop)-1;
25106diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
25107index 5cdff03..80fa283 100644
25108--- a/arch/x86/kernel/setup_percpu.c
25109+++ b/arch/x86/kernel/setup_percpu.c
25110@@ -21,19 +21,17 @@
25111 #include <asm/cpu.h>
25112 #include <asm/stackprotector.h>
25113
25114-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
25115+#ifdef CONFIG_SMP
25116+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
25117 EXPORT_PER_CPU_SYMBOL(cpu_number);
25118+#endif
25119
25120-#ifdef CONFIG_X86_64
25121 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
25122-#else
25123-#define BOOT_PERCPU_OFFSET 0
25124-#endif
25125
25126 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
25127 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
25128
25129-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
25130+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
25131 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
25132 };
25133 EXPORT_SYMBOL(__per_cpu_offset);
25134@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
25135 {
25136 #ifdef CONFIG_NEED_MULTIPLE_NODES
25137 pg_data_t *last = NULL;
25138- unsigned int cpu;
25139+ int cpu;
25140
25141 for_each_possible_cpu(cpu) {
25142 int node = early_cpu_to_node(cpu);
25143@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
25144 {
25145 #ifdef CONFIG_X86_32
25146 struct desc_struct gdt;
25147+ unsigned long base = per_cpu_offset(cpu);
25148
25149- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
25150- 0x2 | DESCTYPE_S, 0x8);
25151- gdt.s = 1;
25152+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
25153+ 0x83 | DESCTYPE_S, 0xC);
25154 write_gdt_entry(get_cpu_gdt_table(cpu),
25155 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
25156 #endif
25157@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
25158 /* alrighty, percpu areas up and running */
25159 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
25160 for_each_possible_cpu(cpu) {
25161+#ifdef CONFIG_CC_STACKPROTECTOR
25162+#ifdef CONFIG_X86_32
25163+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
25164+#endif
25165+#endif
25166 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
25167 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
25168 per_cpu(cpu_number, cpu) = cpu;
25169@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
25170 */
25171 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
25172 #endif
25173+#ifdef CONFIG_CC_STACKPROTECTOR
25174+#ifdef CONFIG_X86_32
25175+ if (!cpu)
25176+ per_cpu(stack_canary.canary, cpu) = canary;
25177+#endif
25178+#endif
25179 /*
25180 * Up to this point, the boot CPU has been using .init.data
25181 * area. Reload any changed state for the boot CPU.
25182diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
25183index cf91358..a7081ea 100644
25184--- a/arch/x86/kernel/signal.c
25185+++ b/arch/x86/kernel/signal.c
25186@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
25187 * Align the stack pointer according to the i386 ABI,
25188 * i.e. so that on function entry ((sp + 4) & 15) == 0.
25189 */
25190- sp = ((sp + 4) & -16ul) - 4;
25191+ sp = ((sp - 12) & -16ul) - 4;
25192 #else /* !CONFIG_X86_32 */
25193 sp = round_down(sp, 16) - 8;
25194 #endif
25195@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25196 }
25197
25198 if (current->mm->context.vdso)
25199- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25200+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25201 else
25202- restorer = &frame->retcode;
25203+ restorer = (void __user *)&frame->retcode;
25204 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25205 restorer = ksig->ka.sa.sa_restorer;
25206
25207@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25208 * reasons and because gdb uses it as a signature to notice
25209 * signal handler stack frames.
25210 */
25211- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
25212+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
25213
25214 if (err)
25215 return -EFAULT;
25216@@ -358,10 +358,13 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25217 else
25218 put_user_ex(0, &frame->uc.uc_flags);
25219 put_user_ex(0, &frame->uc.uc_link);
25220- err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
25221+ __save_altstack_ex(&frame->uc.uc_stack, regs->sp);
25222
25223 /* Set up to return from userspace. */
25224- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25225+ if (current->mm->context.vdso)
25226+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25227+ else
25228+ restorer = (void __user *)&frame->retcode;
25229 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25230 restorer = ksig->ka.sa.sa_restorer;
25231 put_user_ex(restorer, &frame->pretcode);
25232@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25233 * reasons and because gdb uses it as a signature to notice
25234 * signal handler stack frames.
25235 */
25236- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
25237+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
25238 } put_user_catch(err);
25239
25240 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
25241@@ -423,7 +426,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25242 else
25243 put_user_ex(0, &frame->uc.uc_flags);
25244 put_user_ex(0, &frame->uc.uc_link);
25245- err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
25246+ __save_altstack_ex(&frame->uc.uc_stack, regs->sp);
25247
25248 /* Set up to return from userspace. If provided, use a stub
25249 already in userspace. */
25250@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25251 {
25252 int usig = signr_convert(ksig->sig);
25253 sigset_t *set = sigmask_to_save();
25254- compat_sigset_t *cset = (compat_sigset_t *) set;
25255+ sigset_t sigcopy;
25256+ compat_sigset_t *cset;
25257+
25258+ sigcopy = *set;
25259+
25260+ cset = (compat_sigset_t *) &sigcopy;
25261
25262 /* Set up the stack frame */
25263 if (is_ia32_frame()) {
25264@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25265 } else if (is_x32_frame()) {
25266 return x32_setup_rt_frame(ksig, cset, regs);
25267 } else {
25268- return __setup_rt_frame(ksig->sig, ksig, set, regs);
25269+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
25270 }
25271 }
25272
25273diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
25274index cdaa347..f5af55d 100644
25275--- a/arch/x86/kernel/smp.c
25276+++ b/arch/x86/kernel/smp.c
25277@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
25278
25279 __setup("nonmi_ipi", nonmi_ipi_setup);
25280
25281-struct smp_ops smp_ops = {
25282+struct smp_ops smp_ops __read_only = {
25283 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
25284 .smp_prepare_cpus = native_smp_prepare_cpus,
25285 .smp_cpus_done = native_smp_cpus_done,
25286diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
25287index aecc98a..0244a53 100644
25288--- a/arch/x86/kernel/smpboot.c
25289+++ b/arch/x86/kernel/smpboot.c
25290@@ -251,14 +251,18 @@ static void notrace start_secondary(void *unused)
25291
25292 enable_start_cpu0 = 0;
25293
25294-#ifdef CONFIG_X86_32
25295- /* switch away from the initial page table */
25296- load_cr3(swapper_pg_dir);
25297- __flush_tlb_all();
25298-#endif
25299-
25300 /* otherwise gcc will move up smp_processor_id before the cpu_init */
25301 barrier();
25302+
25303+ /* switch away from the initial page table */
25304+#ifdef CONFIG_PAX_PER_CPU_PGD
25305+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
25306+ __flush_tlb_all();
25307+#elif defined(CONFIG_X86_32)
25308+ load_cr3(swapper_pg_dir);
25309+ __flush_tlb_all();
25310+#endif
25311+
25312 /*
25313 * Check TSC synchronization with the BP:
25314 */
25315@@ -748,6 +752,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25316 idle->thread.sp = (unsigned long) (((struct pt_regs *)
25317 (THREAD_SIZE + task_stack_page(idle))) - 1);
25318 per_cpu(current_task, cpu) = idle;
25319+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
25320
25321 #ifdef CONFIG_X86_32
25322 /* Stack for startup_32 can be just as for start_secondary onwards */
25323@@ -755,11 +760,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25324 #else
25325 clear_tsk_thread_flag(idle, TIF_FORK);
25326 initial_gs = per_cpu_offset(cpu);
25327- per_cpu(kernel_stack, cpu) =
25328- (unsigned long)task_stack_page(idle) -
25329- KERNEL_STACK_OFFSET + THREAD_SIZE;
25330+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
25331 #endif
25332+
25333+ pax_open_kernel();
25334 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
25335+ pax_close_kernel();
25336+
25337 initial_code = (unsigned long)start_secondary;
25338 stack_start = idle->thread.sp;
25339
25340@@ -908,6 +915,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
25341 /* the FPU context is blank, nobody can own it */
25342 __cpu_disable_lazy_restore(cpu);
25343
25344+#ifdef CONFIG_PAX_PER_CPU_PGD
25345+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
25346+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25347+ KERNEL_PGD_PTRS);
25348+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
25349+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25350+ KERNEL_PGD_PTRS);
25351+#endif
25352+
25353 err = do_boot_cpu(apicid, cpu, tidle);
25354 if (err) {
25355 pr_debug("do_boot_cpu failed %d\n", err);
25356diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
25357index 9b4d51d..5d28b58 100644
25358--- a/arch/x86/kernel/step.c
25359+++ b/arch/x86/kernel/step.c
25360@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25361 struct desc_struct *desc;
25362 unsigned long base;
25363
25364- seg &= ~7UL;
25365+ seg >>= 3;
25366
25367 mutex_lock(&child->mm->context.lock);
25368- if (unlikely((seg >> 3) >= child->mm->context.size))
25369+ if (unlikely(seg >= child->mm->context.size))
25370 addr = -1L; /* bogus selector, access would fault */
25371 else {
25372 desc = child->mm->context.ldt + seg;
25373@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25374 addr += base;
25375 }
25376 mutex_unlock(&child->mm->context.lock);
25377- }
25378+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
25379+ addr = ktla_ktva(addr);
25380
25381 return addr;
25382 }
25383@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
25384 unsigned char opcode[15];
25385 unsigned long addr = convert_ip_to_linear(child, regs);
25386
25387+ if (addr == -EINVAL)
25388+ return 0;
25389+
25390 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
25391 for (i = 0; i < copied; i++) {
25392 switch (opcode[i]) {
25393diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
25394new file mode 100644
25395index 0000000..5877189
25396--- /dev/null
25397+++ b/arch/x86/kernel/sys_i386_32.c
25398@@ -0,0 +1,189 @@
25399+/*
25400+ * This file contains various random system calls that
25401+ * have a non-standard calling sequence on the Linux/i386
25402+ * platform.
25403+ */
25404+
25405+#include <linux/errno.h>
25406+#include <linux/sched.h>
25407+#include <linux/mm.h>
25408+#include <linux/fs.h>
25409+#include <linux/smp.h>
25410+#include <linux/sem.h>
25411+#include <linux/msg.h>
25412+#include <linux/shm.h>
25413+#include <linux/stat.h>
25414+#include <linux/syscalls.h>
25415+#include <linux/mman.h>
25416+#include <linux/file.h>
25417+#include <linux/utsname.h>
25418+#include <linux/ipc.h>
25419+#include <linux/elf.h>
25420+
25421+#include <linux/uaccess.h>
25422+#include <linux/unistd.h>
25423+
25424+#include <asm/syscalls.h>
25425+
25426+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
25427+{
25428+ unsigned long pax_task_size = TASK_SIZE;
25429+
25430+#ifdef CONFIG_PAX_SEGMEXEC
25431+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
25432+ pax_task_size = SEGMEXEC_TASK_SIZE;
25433+#endif
25434+
25435+ if (flags & MAP_FIXED)
25436+ if (len > pax_task_size || addr > pax_task_size - len)
25437+ return -EINVAL;
25438+
25439+ return 0;
25440+}
25441+
25442+/*
25443+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
25444+ */
25445+static unsigned long get_align_mask(void)
25446+{
25447+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
25448+ return 0;
25449+
25450+ if (!(current->flags & PF_RANDOMIZE))
25451+ return 0;
25452+
25453+ return va_align.mask;
25454+}
25455+
25456+unsigned long
25457+arch_get_unmapped_area(struct file *filp, unsigned long addr,
25458+ unsigned long len, unsigned long pgoff, unsigned long flags)
25459+{
25460+ struct mm_struct *mm = current->mm;
25461+ struct vm_area_struct *vma;
25462+ unsigned long pax_task_size = TASK_SIZE;
25463+ struct vm_unmapped_area_info info;
25464+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25465+
25466+#ifdef CONFIG_PAX_SEGMEXEC
25467+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25468+ pax_task_size = SEGMEXEC_TASK_SIZE;
25469+#endif
25470+
25471+ pax_task_size -= PAGE_SIZE;
25472+
25473+ if (len > pax_task_size)
25474+ return -ENOMEM;
25475+
25476+ if (flags & MAP_FIXED)
25477+ return addr;
25478+
25479+#ifdef CONFIG_PAX_RANDMMAP
25480+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25481+#endif
25482+
25483+ if (addr) {
25484+ addr = PAGE_ALIGN(addr);
25485+ if (pax_task_size - len >= addr) {
25486+ vma = find_vma(mm, addr);
25487+ if (check_heap_stack_gap(vma, addr, len, offset))
25488+ return addr;
25489+ }
25490+ }
25491+
25492+ info.flags = 0;
25493+ info.length = len;
25494+ info.align_mask = filp ? get_align_mask() : 0;
25495+ info.align_offset = pgoff << PAGE_SHIFT;
25496+ info.threadstack_offset = offset;
25497+
25498+#ifdef CONFIG_PAX_PAGEEXEC
25499+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
25500+ info.low_limit = 0x00110000UL;
25501+ info.high_limit = mm->start_code;
25502+
25503+#ifdef CONFIG_PAX_RANDMMAP
25504+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25505+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
25506+#endif
25507+
25508+ if (info.low_limit < info.high_limit) {
25509+ addr = vm_unmapped_area(&info);
25510+ if (!IS_ERR_VALUE(addr))
25511+ return addr;
25512+ }
25513+ } else
25514+#endif
25515+
25516+ info.low_limit = mm->mmap_base;
25517+ info.high_limit = pax_task_size;
25518+
25519+ return vm_unmapped_area(&info);
25520+}
25521+
25522+unsigned long
25523+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25524+ const unsigned long len, const unsigned long pgoff,
25525+ const unsigned long flags)
25526+{
25527+ struct vm_area_struct *vma;
25528+ struct mm_struct *mm = current->mm;
25529+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
25530+ struct vm_unmapped_area_info info;
25531+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25532+
25533+#ifdef CONFIG_PAX_SEGMEXEC
25534+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25535+ pax_task_size = SEGMEXEC_TASK_SIZE;
25536+#endif
25537+
25538+ pax_task_size -= PAGE_SIZE;
25539+
25540+ /* requested length too big for entire address space */
25541+ if (len > pax_task_size)
25542+ return -ENOMEM;
25543+
25544+ if (flags & MAP_FIXED)
25545+ return addr;
25546+
25547+#ifdef CONFIG_PAX_PAGEEXEC
25548+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
25549+ goto bottomup;
25550+#endif
25551+
25552+#ifdef CONFIG_PAX_RANDMMAP
25553+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25554+#endif
25555+
25556+ /* requesting a specific address */
25557+ if (addr) {
25558+ addr = PAGE_ALIGN(addr);
25559+ if (pax_task_size - len >= addr) {
25560+ vma = find_vma(mm, addr);
25561+ if (check_heap_stack_gap(vma, addr, len, offset))
25562+ return addr;
25563+ }
25564+ }
25565+
25566+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
25567+ info.length = len;
25568+ info.low_limit = PAGE_SIZE;
25569+ info.high_limit = mm->mmap_base;
25570+ info.align_mask = filp ? get_align_mask() : 0;
25571+ info.align_offset = pgoff << PAGE_SHIFT;
25572+ info.threadstack_offset = offset;
25573+
25574+ addr = vm_unmapped_area(&info);
25575+ if (!(addr & ~PAGE_MASK))
25576+ return addr;
25577+ VM_BUG_ON(addr != -ENOMEM);
25578+
25579+bottomup:
25580+ /*
25581+ * A failed mmap() very likely causes application failure,
25582+ * so fall back to the bottom-up function here. This scenario
25583+ * can happen with large stack limits and large mmap()
25584+ * allocations.
25585+ */
25586+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
25587+}
25588diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
25589index 30277e2..5664a29 100644
25590--- a/arch/x86/kernel/sys_x86_64.c
25591+++ b/arch/x86/kernel/sys_x86_64.c
25592@@ -81,8 +81,8 @@ out:
25593 return error;
25594 }
25595
25596-static void find_start_end(unsigned long flags, unsigned long *begin,
25597- unsigned long *end)
25598+static void find_start_end(struct mm_struct *mm, unsigned long flags,
25599+ unsigned long *begin, unsigned long *end)
25600 {
25601 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
25602 unsigned long new_begin;
25603@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
25604 *begin = new_begin;
25605 }
25606 } else {
25607- *begin = current->mm->mmap_legacy_base;
25608+ *begin = mm->mmap_legacy_base;
25609 *end = TASK_SIZE;
25610 }
25611 }
25612@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25613 struct vm_area_struct *vma;
25614 struct vm_unmapped_area_info info;
25615 unsigned long begin, end;
25616+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25617
25618 if (flags & MAP_FIXED)
25619 return addr;
25620
25621- find_start_end(flags, &begin, &end);
25622+ find_start_end(mm, flags, &begin, &end);
25623
25624 if (len > end)
25625 return -ENOMEM;
25626
25627+#ifdef CONFIG_PAX_RANDMMAP
25628+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25629+#endif
25630+
25631 if (addr) {
25632 addr = PAGE_ALIGN(addr);
25633 vma = find_vma(mm, addr);
25634- if (end - len >= addr &&
25635- (!vma || addr + len <= vma->vm_start))
25636+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25637 return addr;
25638 }
25639
25640@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25641 info.high_limit = end;
25642 info.align_mask = filp ? get_align_mask() : 0;
25643 info.align_offset = pgoff << PAGE_SHIFT;
25644+ info.threadstack_offset = offset;
25645 return vm_unmapped_area(&info);
25646 }
25647
25648@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25649 struct mm_struct *mm = current->mm;
25650 unsigned long addr = addr0;
25651 struct vm_unmapped_area_info info;
25652+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25653
25654 /* requested length too big for entire address space */
25655 if (len > TASK_SIZE)
25656@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25657 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
25658 goto bottomup;
25659
25660+#ifdef CONFIG_PAX_RANDMMAP
25661+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25662+#endif
25663+
25664 /* requesting a specific address */
25665 if (addr) {
25666 addr = PAGE_ALIGN(addr);
25667 vma = find_vma(mm, addr);
25668- if (TASK_SIZE - len >= addr &&
25669- (!vma || addr + len <= vma->vm_start))
25670+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25671 return addr;
25672 }
25673
25674@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25675 info.high_limit = mm->mmap_base;
25676 info.align_mask = filp ? get_align_mask() : 0;
25677 info.align_offset = pgoff << PAGE_SHIFT;
25678+ info.threadstack_offset = offset;
25679 addr = vm_unmapped_area(&info);
25680 if (!(addr & ~PAGE_MASK))
25681 return addr;
25682diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
25683index addf7b5..f960685 100644
25684--- a/arch/x86/kernel/tboot.c
25685+++ b/arch/x86/kernel/tboot.c
25686@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
25687
25688 void tboot_shutdown(u32 shutdown_type)
25689 {
25690- void (*shutdown)(void);
25691+ void (* __noreturn shutdown)(void);
25692
25693 if (!tboot_enabled())
25694 return;
25695@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
25696
25697 switch_to_tboot_pt();
25698
25699- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
25700+ shutdown = (void *)tboot->shutdown_entry;
25701 shutdown();
25702
25703 /* should not reach here */
25704@@ -301,7 +301,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
25705 return 0;
25706 }
25707
25708-static atomic_t ap_wfs_count;
25709+static atomic_unchecked_t ap_wfs_count;
25710
25711 static int tboot_wait_for_aps(int num_aps)
25712 {
25713@@ -325,9 +325,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
25714 {
25715 switch (action) {
25716 case CPU_DYING:
25717- atomic_inc(&ap_wfs_count);
25718+ atomic_inc_unchecked(&ap_wfs_count);
25719 if (num_online_cpus() == 1)
25720- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
25721+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
25722 return NOTIFY_BAD;
25723 break;
25724 }
25725@@ -413,7 +413,7 @@ static __init int tboot_late_init(void)
25726
25727 tboot_create_trampoline();
25728
25729- atomic_set(&ap_wfs_count, 0);
25730+ atomic_set_unchecked(&ap_wfs_count, 0);
25731 register_hotcpu_notifier(&tboot_cpu_notifier);
25732
25733 #ifdef CONFIG_DEBUG_FS
25734diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
25735index 24d3c91..d06b473 100644
25736--- a/arch/x86/kernel/time.c
25737+++ b/arch/x86/kernel/time.c
25738@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
25739 {
25740 unsigned long pc = instruction_pointer(regs);
25741
25742- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
25743+ if (!user_mode(regs) && in_lock_functions(pc)) {
25744 #ifdef CONFIG_FRAME_POINTER
25745- return *(unsigned long *)(regs->bp + sizeof(long));
25746+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
25747 #else
25748 unsigned long *sp =
25749 (unsigned long *)kernel_stack_pointer(regs);
25750@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
25751 * or above a saved flags. Eflags has bits 22-31 zero,
25752 * kernel addresses don't.
25753 */
25754+
25755+#ifdef CONFIG_PAX_KERNEXEC
25756+ return ktla_ktva(sp[0]);
25757+#else
25758 if (sp[0] >> 22)
25759 return sp[0];
25760 if (sp[1] >> 22)
25761 return sp[1];
25762 #endif
25763+
25764+#endif
25765 }
25766 return pc;
25767 }
25768diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
25769index f7fec09..9991981 100644
25770--- a/arch/x86/kernel/tls.c
25771+++ b/arch/x86/kernel/tls.c
25772@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
25773 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
25774 return -EINVAL;
25775
25776+#ifdef CONFIG_PAX_SEGMEXEC
25777+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
25778+ return -EINVAL;
25779+#endif
25780+
25781 set_tls_desc(p, idx, &info, 1);
25782
25783 return 0;
25784@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
25785
25786 if (kbuf)
25787 info = kbuf;
25788- else if (__copy_from_user(infobuf, ubuf, count))
25789+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
25790 return -EFAULT;
25791 else
25792 info = infobuf;
25793diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
25794index 1c113db..287b42e 100644
25795--- a/arch/x86/kernel/tracepoint.c
25796+++ b/arch/x86/kernel/tracepoint.c
25797@@ -9,11 +9,11 @@
25798 #include <linux/atomic.h>
25799
25800 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
25801-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25802+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25803 (unsigned long) trace_idt_table };
25804
25805 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25806-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
25807+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
25808
25809 static int trace_irq_vector_refcount;
25810 static DEFINE_MUTEX(irq_vector_mutex);
25811diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
25812index 1b23a1c..910de0d 100644
25813--- a/arch/x86/kernel/traps.c
25814+++ b/arch/x86/kernel/traps.c
25815@@ -65,7 +65,7 @@
25816 #include <asm/proto.h>
25817
25818 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25819-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
25820+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
25821 #else
25822 #include <asm/processor-flags.h>
25823 #include <asm/setup.h>
25824@@ -74,7 +74,7 @@ asmlinkage int system_call(void);
25825 #endif
25826
25827 /* Must be page-aligned because the real IDT is used in a fixmap. */
25828-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
25829+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
25830
25831 DECLARE_BITMAP(used_vectors, NR_VECTORS);
25832 EXPORT_SYMBOL_GPL(used_vectors);
25833@@ -106,11 +106,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
25834 }
25835
25836 static int __kprobes
25837-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25838+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
25839 struct pt_regs *regs, long error_code)
25840 {
25841 #ifdef CONFIG_X86_32
25842- if (regs->flags & X86_VM_MASK) {
25843+ if (v8086_mode(regs)) {
25844 /*
25845 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
25846 * On nmi (interrupt 2), do_trap should not be called.
25847@@ -123,12 +123,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25848 return -1;
25849 }
25850 #endif
25851- if (!user_mode(regs)) {
25852+ if (!user_mode_novm(regs)) {
25853 if (!fixup_exception(regs)) {
25854 tsk->thread.error_code = error_code;
25855 tsk->thread.trap_nr = trapnr;
25856+
25857+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25858+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
25859+ str = "PAX: suspicious stack segment fault";
25860+#endif
25861+
25862 die(str, regs, error_code);
25863 }
25864+
25865+#ifdef CONFIG_PAX_REFCOUNT
25866+ if (trapnr == 4)
25867+ pax_report_refcount_overflow(regs);
25868+#endif
25869+
25870 return 0;
25871 }
25872
25873@@ -136,7 +148,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25874 }
25875
25876 static void __kprobes
25877-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25878+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
25879 long error_code, siginfo_t *info)
25880 {
25881 struct task_struct *tsk = current;
25882@@ -160,7 +172,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25883 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
25884 printk_ratelimit()) {
25885 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
25886- tsk->comm, tsk->pid, str,
25887+ tsk->comm, task_pid_nr(tsk), str,
25888 regs->ip, regs->sp, error_code);
25889 print_vma_addr(" in ", regs->ip);
25890 pr_cont("\n");
25891@@ -276,7 +288,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
25892 conditional_sti(regs);
25893
25894 #ifdef CONFIG_X86_32
25895- if (regs->flags & X86_VM_MASK) {
25896+ if (v8086_mode(regs)) {
25897 local_irq_enable();
25898 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
25899 goto exit;
25900@@ -284,18 +296,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
25901 #endif
25902
25903 tsk = current;
25904- if (!user_mode(regs)) {
25905+ if (!user_mode_novm(regs)) {
25906 if (fixup_exception(regs))
25907 goto exit;
25908
25909 tsk->thread.error_code = error_code;
25910 tsk->thread.trap_nr = X86_TRAP_GP;
25911 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
25912- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
25913+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
25914+
25915+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25916+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
25917+ die("PAX: suspicious general protection fault", regs, error_code);
25918+ else
25919+#endif
25920+
25921 die("general protection fault", regs, error_code);
25922+ }
25923 goto exit;
25924 }
25925
25926+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25927+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
25928+ struct mm_struct *mm = tsk->mm;
25929+ unsigned long limit;
25930+
25931+ down_write(&mm->mmap_sem);
25932+ limit = mm->context.user_cs_limit;
25933+ if (limit < TASK_SIZE) {
25934+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
25935+ up_write(&mm->mmap_sem);
25936+ return;
25937+ }
25938+ up_write(&mm->mmap_sem);
25939+ }
25940+#endif
25941+
25942 tsk->thread.error_code = error_code;
25943 tsk->thread.trap_nr = X86_TRAP_GP;
25944
25945@@ -453,7 +489,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
25946 /* It's safe to allow irq's after DR6 has been saved */
25947 preempt_conditional_sti(regs);
25948
25949- if (regs->flags & X86_VM_MASK) {
25950+ if (v8086_mode(regs)) {
25951 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
25952 X86_TRAP_DB);
25953 preempt_conditional_cli(regs);
25954@@ -468,7 +504,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
25955 * We already checked v86 mode above, so we can check for kernel mode
25956 * by just checking the CPL of CS.
25957 */
25958- if ((dr6 & DR_STEP) && !user_mode(regs)) {
25959+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
25960 tsk->thread.debugreg6 &= ~DR_STEP;
25961 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
25962 regs->flags &= ~X86_EFLAGS_TF;
25963@@ -500,7 +536,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
25964 return;
25965 conditional_sti(regs);
25966
25967- if (!user_mode_vm(regs))
25968+ if (!user_mode(regs))
25969 {
25970 if (!fixup_exception(regs)) {
25971 task->thread.error_code = error_code;
25972diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
25973index 2ed8459..7cf329f 100644
25974--- a/arch/x86/kernel/uprobes.c
25975+++ b/arch/x86/kernel/uprobes.c
25976@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
25977 int ret = NOTIFY_DONE;
25978
25979 /* We are only interested in userspace traps */
25980- if (regs && !user_mode_vm(regs))
25981+ if (regs && !user_mode(regs))
25982 return NOTIFY_DONE;
25983
25984 switch (val) {
25985@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
25986
25987 if (ncopied != rasize) {
25988 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
25989- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
25990+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
25991
25992 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
25993 }
25994diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
25995index b9242ba..50c5edd 100644
25996--- a/arch/x86/kernel/verify_cpu.S
25997+++ b/arch/x86/kernel/verify_cpu.S
25998@@ -20,6 +20,7 @@
25999 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
26000 * arch/x86/kernel/trampoline_64.S: secondary processor verification
26001 * arch/x86/kernel/head_32.S: processor startup
26002+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
26003 *
26004 * verify_cpu, returns the status of longmode and SSE in register %eax.
26005 * 0: Success 1: Failure
26006diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
26007index e8edcf5..27f9344 100644
26008--- a/arch/x86/kernel/vm86_32.c
26009+++ b/arch/x86/kernel/vm86_32.c
26010@@ -44,6 +44,7 @@
26011 #include <linux/ptrace.h>
26012 #include <linux/audit.h>
26013 #include <linux/stddef.h>
26014+#include <linux/grsecurity.h>
26015
26016 #include <asm/uaccess.h>
26017 #include <asm/io.h>
26018@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
26019 do_exit(SIGSEGV);
26020 }
26021
26022- tss = &per_cpu(init_tss, get_cpu());
26023+ tss = init_tss + get_cpu();
26024 current->thread.sp0 = current->thread.saved_sp0;
26025 current->thread.sysenter_cs = __KERNEL_CS;
26026 load_sp0(tss, &current->thread);
26027@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
26028
26029 if (tsk->thread.saved_sp0)
26030 return -EPERM;
26031+
26032+#ifdef CONFIG_GRKERNSEC_VM86
26033+ if (!capable(CAP_SYS_RAWIO)) {
26034+ gr_handle_vm86();
26035+ return -EPERM;
26036+ }
26037+#endif
26038+
26039 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
26040 offsetof(struct kernel_vm86_struct, vm86plus) -
26041 sizeof(info.regs));
26042@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
26043 int tmp;
26044 struct vm86plus_struct __user *v86;
26045
26046+#ifdef CONFIG_GRKERNSEC_VM86
26047+ if (!capable(CAP_SYS_RAWIO)) {
26048+ gr_handle_vm86();
26049+ return -EPERM;
26050+ }
26051+#endif
26052+
26053 tsk = current;
26054 switch (cmd) {
26055 case VM86_REQUEST_IRQ:
26056@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
26057 tsk->thread.saved_fs = info->regs32->fs;
26058 tsk->thread.saved_gs = get_user_gs(info->regs32);
26059
26060- tss = &per_cpu(init_tss, get_cpu());
26061+ tss = init_tss + get_cpu();
26062 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
26063 if (cpu_has_sep)
26064 tsk->thread.sysenter_cs = 0;
26065@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
26066 goto cannot_handle;
26067 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
26068 goto cannot_handle;
26069- intr_ptr = (unsigned long __user *) (i << 2);
26070+ intr_ptr = (__force unsigned long __user *) (i << 2);
26071 if (get_user(segoffs, intr_ptr))
26072 goto cannot_handle;
26073 if ((segoffs >> 16) == BIOSSEG)
26074diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
26075index 10c4f30..65408b9 100644
26076--- a/arch/x86/kernel/vmlinux.lds.S
26077+++ b/arch/x86/kernel/vmlinux.lds.S
26078@@ -26,6 +26,13 @@
26079 #include <asm/page_types.h>
26080 #include <asm/cache.h>
26081 #include <asm/boot.h>
26082+#include <asm/segment.h>
26083+
26084+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26085+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
26086+#else
26087+#define __KERNEL_TEXT_OFFSET 0
26088+#endif
26089
26090 #undef i386 /* in case the preprocessor is a 32bit one */
26091
26092@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
26093
26094 PHDRS {
26095 text PT_LOAD FLAGS(5); /* R_E */
26096+#ifdef CONFIG_X86_32
26097+ module PT_LOAD FLAGS(5); /* R_E */
26098+#endif
26099+#ifdef CONFIG_XEN
26100+ rodata PT_LOAD FLAGS(5); /* R_E */
26101+#else
26102+ rodata PT_LOAD FLAGS(4); /* R__ */
26103+#endif
26104 data PT_LOAD FLAGS(6); /* RW_ */
26105-#ifdef CONFIG_X86_64
26106+ init.begin PT_LOAD FLAGS(6); /* RW_ */
26107 #ifdef CONFIG_SMP
26108 percpu PT_LOAD FLAGS(6); /* RW_ */
26109 #endif
26110+ text.init PT_LOAD FLAGS(5); /* R_E */
26111+ text.exit PT_LOAD FLAGS(5); /* R_E */
26112 init PT_LOAD FLAGS(7); /* RWE */
26113-#endif
26114 note PT_NOTE FLAGS(0); /* ___ */
26115 }
26116
26117 SECTIONS
26118 {
26119 #ifdef CONFIG_X86_32
26120- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
26121- phys_startup_32 = startup_32 - LOAD_OFFSET;
26122+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
26123 #else
26124- . = __START_KERNEL;
26125- phys_startup_64 = startup_64 - LOAD_OFFSET;
26126+ . = __START_KERNEL;
26127 #endif
26128
26129 /* Text and read-only data */
26130- .text : AT(ADDR(.text) - LOAD_OFFSET) {
26131- _text = .;
26132+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26133 /* bootstrapping code */
26134+#ifdef CONFIG_X86_32
26135+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26136+#else
26137+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26138+#endif
26139+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26140+ _text = .;
26141 HEAD_TEXT
26142 . = ALIGN(8);
26143 _stext = .;
26144@@ -104,13 +124,47 @@ SECTIONS
26145 IRQENTRY_TEXT
26146 *(.fixup)
26147 *(.gnu.warning)
26148- /* End of text section */
26149- _etext = .;
26150 } :text = 0x9090
26151
26152- NOTES :text :note
26153+ . += __KERNEL_TEXT_OFFSET;
26154
26155- EXCEPTION_TABLE(16) :text = 0x9090
26156+#ifdef CONFIG_X86_32
26157+ . = ALIGN(PAGE_SIZE);
26158+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
26159+
26160+#ifdef CONFIG_PAX_KERNEXEC
26161+ MODULES_EXEC_VADDR = .;
26162+ BYTE(0)
26163+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
26164+ . = ALIGN(HPAGE_SIZE) - 1;
26165+ MODULES_EXEC_END = .;
26166+#endif
26167+
26168+ } :module
26169+#endif
26170+
26171+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
26172+ /* End of text section */
26173+ BYTE(0)
26174+ _etext = . - __KERNEL_TEXT_OFFSET;
26175+ }
26176+
26177+#ifdef CONFIG_X86_32
26178+ . = ALIGN(PAGE_SIZE);
26179+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
26180+ . = ALIGN(PAGE_SIZE);
26181+ *(.empty_zero_page)
26182+ *(.initial_pg_fixmap)
26183+ *(.initial_pg_pmd)
26184+ *(.initial_page_table)
26185+ *(.swapper_pg_dir)
26186+ } :rodata
26187+#endif
26188+
26189+ . = ALIGN(PAGE_SIZE);
26190+ NOTES :rodata :note
26191+
26192+ EXCEPTION_TABLE(16) :rodata
26193
26194 #if defined(CONFIG_DEBUG_RODATA)
26195 /* .text should occupy whole number of pages */
26196@@ -122,16 +176,20 @@ SECTIONS
26197
26198 /* Data */
26199 .data : AT(ADDR(.data) - LOAD_OFFSET) {
26200+
26201+#ifdef CONFIG_PAX_KERNEXEC
26202+ . = ALIGN(HPAGE_SIZE);
26203+#else
26204+ . = ALIGN(PAGE_SIZE);
26205+#endif
26206+
26207 /* Start of data section */
26208 _sdata = .;
26209
26210 /* init_task */
26211 INIT_TASK_DATA(THREAD_SIZE)
26212
26213-#ifdef CONFIG_X86_32
26214- /* 32 bit has nosave before _edata */
26215 NOSAVE_DATA
26216-#endif
26217
26218 PAGE_ALIGNED_DATA(PAGE_SIZE)
26219
26220@@ -172,12 +230,19 @@ SECTIONS
26221 #endif /* CONFIG_X86_64 */
26222
26223 /* Init code and data - will be freed after init */
26224- . = ALIGN(PAGE_SIZE);
26225 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
26226+ BYTE(0)
26227+
26228+#ifdef CONFIG_PAX_KERNEXEC
26229+ . = ALIGN(HPAGE_SIZE);
26230+#else
26231+ . = ALIGN(PAGE_SIZE);
26232+#endif
26233+
26234 __init_begin = .; /* paired with __init_end */
26235- }
26236+ } :init.begin
26237
26238-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
26239+#ifdef CONFIG_SMP
26240 /*
26241 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
26242 * output PHDR, so the next output section - .init.text - should
26243@@ -186,12 +251,27 @@ SECTIONS
26244 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
26245 #endif
26246
26247- INIT_TEXT_SECTION(PAGE_SIZE)
26248-#ifdef CONFIG_X86_64
26249- :init
26250-#endif
26251+ . = ALIGN(PAGE_SIZE);
26252+ init_begin = .;
26253+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
26254+ VMLINUX_SYMBOL(_sinittext) = .;
26255+ INIT_TEXT
26256+ VMLINUX_SYMBOL(_einittext) = .;
26257+ . = ALIGN(PAGE_SIZE);
26258+ } :text.init
26259
26260- INIT_DATA_SECTION(16)
26261+ /*
26262+ * .exit.text is discard at runtime, not link time, to deal with
26263+ * references from .altinstructions and .eh_frame
26264+ */
26265+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26266+ EXIT_TEXT
26267+ . = ALIGN(16);
26268+ } :text.exit
26269+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
26270+
26271+ . = ALIGN(PAGE_SIZE);
26272+ INIT_DATA_SECTION(16) :init
26273
26274 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
26275 __x86_cpu_dev_start = .;
26276@@ -253,19 +333,12 @@ SECTIONS
26277 }
26278
26279 . = ALIGN(8);
26280- /*
26281- * .exit.text is discard at runtime, not link time, to deal with
26282- * references from .altinstructions and .eh_frame
26283- */
26284- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
26285- EXIT_TEXT
26286- }
26287
26288 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
26289 EXIT_DATA
26290 }
26291
26292-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
26293+#ifndef CONFIG_SMP
26294 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
26295 #endif
26296
26297@@ -284,16 +357,10 @@ SECTIONS
26298 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
26299 __smp_locks = .;
26300 *(.smp_locks)
26301- . = ALIGN(PAGE_SIZE);
26302 __smp_locks_end = .;
26303+ . = ALIGN(PAGE_SIZE);
26304 }
26305
26306-#ifdef CONFIG_X86_64
26307- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
26308- NOSAVE_DATA
26309- }
26310-#endif
26311-
26312 /* BSS */
26313 . = ALIGN(PAGE_SIZE);
26314 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
26315@@ -309,6 +376,7 @@ SECTIONS
26316 __brk_base = .;
26317 . += 64 * 1024; /* 64k alignment slop space */
26318 *(.brk_reservation) /* areas brk users have reserved */
26319+ . = ALIGN(HPAGE_SIZE);
26320 __brk_limit = .;
26321 }
26322
26323@@ -335,13 +403,12 @@ SECTIONS
26324 * for the boot processor.
26325 */
26326 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
26327-INIT_PER_CPU(gdt_page);
26328 INIT_PER_CPU(irq_stack_union);
26329
26330 /*
26331 * Build-time check on the image size:
26332 */
26333-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
26334+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
26335 "kernel image bigger than KERNEL_IMAGE_SIZE");
26336
26337 #ifdef CONFIG_SMP
26338diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
26339index 1f96f93..d5c8f7a 100644
26340--- a/arch/x86/kernel/vsyscall_64.c
26341+++ b/arch/x86/kernel/vsyscall_64.c
26342@@ -56,15 +56,13 @@
26343 DEFINE_VVAR(int, vgetcpu_mode);
26344 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
26345
26346-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
26347+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
26348
26349 static int __init vsyscall_setup(char *str)
26350 {
26351 if (str) {
26352 if (!strcmp("emulate", str))
26353 vsyscall_mode = EMULATE;
26354- else if (!strcmp("native", str))
26355- vsyscall_mode = NATIVE;
26356 else if (!strcmp("none", str))
26357 vsyscall_mode = NONE;
26358 else
26359@@ -323,8 +321,7 @@ do_ret:
26360 return true;
26361
26362 sigsegv:
26363- force_sig(SIGSEGV, current);
26364- return true;
26365+ do_group_exit(SIGKILL);
26366 }
26367
26368 /*
26369@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
26370 extern char __vvar_page;
26371 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
26372
26373- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
26374- vsyscall_mode == NATIVE
26375- ? PAGE_KERNEL_VSYSCALL
26376- : PAGE_KERNEL_VVAR);
26377+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
26378 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
26379 (unsigned long)VSYSCALL_START);
26380
26381diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
26382index b014d94..e775258 100644
26383--- a/arch/x86/kernel/x8664_ksyms_64.c
26384+++ b/arch/x86/kernel/x8664_ksyms_64.c
26385@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
26386 EXPORT_SYMBOL(copy_user_generic_unrolled);
26387 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
26388 EXPORT_SYMBOL(__copy_user_nocache);
26389-EXPORT_SYMBOL(_copy_from_user);
26390-EXPORT_SYMBOL(_copy_to_user);
26391
26392 EXPORT_SYMBOL(copy_page);
26393 EXPORT_SYMBOL(clear_page);
26394@@ -66,3 +64,7 @@ EXPORT_SYMBOL(empty_zero_page);
26395 #ifndef CONFIG_PARAVIRT
26396 EXPORT_SYMBOL(native_load_gs_index);
26397 #endif
26398+
26399+#ifdef CONFIG_PAX_PER_CPU_PGD
26400+EXPORT_SYMBOL(cpu_pgd);
26401+#endif
26402diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
26403index 5f24c71..1dadf09 100644
26404--- a/arch/x86/kernel/x86_init.c
26405+++ b/arch/x86/kernel/x86_init.c
26406@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
26407 static void default_nmi_init(void) { };
26408 static int default_i8042_detect(void) { return 1; };
26409
26410-struct x86_platform_ops x86_platform = {
26411+struct x86_platform_ops x86_platform __read_only = {
26412 .calibrate_tsc = native_calibrate_tsc,
26413 .get_wallclock = mach_get_cmos_time,
26414 .set_wallclock = mach_set_rtc_mmss,
26415@@ -107,7 +107,7 @@ struct x86_platform_ops x86_platform = {
26416 };
26417
26418 EXPORT_SYMBOL_GPL(x86_platform);
26419-struct x86_msi_ops x86_msi = {
26420+struct x86_msi_ops x86_msi __read_only = {
26421 .setup_msi_irqs = native_setup_msi_irqs,
26422 .compose_msi_msg = native_compose_msi_msg,
26423 .teardown_msi_irq = native_teardown_msi_irq,
26424@@ -116,7 +116,7 @@ struct x86_msi_ops x86_msi = {
26425 .setup_hpet_msi = default_setup_hpet_msi,
26426 };
26427
26428-struct x86_io_apic_ops x86_io_apic_ops = {
26429+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
26430 .init = native_io_apic_init_mappings,
26431 .read = native_io_apic_read,
26432 .write = native_io_apic_write,
26433diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
26434index 422fd82..c3687ca 100644
26435--- a/arch/x86/kernel/xsave.c
26436+++ b/arch/x86/kernel/xsave.c
26437@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
26438 {
26439 int err;
26440
26441+ buf = (struct xsave_struct __user *)____m(buf);
26442 if (use_xsave())
26443 err = xsave_user(buf);
26444 else if (use_fxsr())
26445@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
26446 */
26447 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
26448 {
26449+ buf = (void __user *)____m(buf);
26450 if (use_xsave()) {
26451 if ((unsigned long)buf % 64 || fx_only) {
26452 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
26453diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
26454index a20ecb5..d0e2194 100644
26455--- a/arch/x86/kvm/cpuid.c
26456+++ b/arch/x86/kvm/cpuid.c
26457@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
26458 struct kvm_cpuid2 *cpuid,
26459 struct kvm_cpuid_entry2 __user *entries)
26460 {
26461- int r;
26462+ int r, i;
26463
26464 r = -E2BIG;
26465 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
26466 goto out;
26467 r = -EFAULT;
26468- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
26469- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26470+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26471 goto out;
26472+ for (i = 0; i < cpuid->nent; ++i) {
26473+ struct kvm_cpuid_entry2 cpuid_entry;
26474+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
26475+ goto out;
26476+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
26477+ }
26478 vcpu->arch.cpuid_nent = cpuid->nent;
26479 kvm_apic_set_version(vcpu);
26480 kvm_x86_ops->cpuid_update(vcpu);
26481@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
26482 struct kvm_cpuid2 *cpuid,
26483 struct kvm_cpuid_entry2 __user *entries)
26484 {
26485- int r;
26486+ int r, i;
26487
26488 r = -E2BIG;
26489 if (cpuid->nent < vcpu->arch.cpuid_nent)
26490 goto out;
26491 r = -EFAULT;
26492- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
26493- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26494+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26495 goto out;
26496+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
26497+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
26498+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
26499+ goto out;
26500+ }
26501 return 0;
26502
26503 out:
26504diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
26505index afc1124..3e431f2 100644
26506--- a/arch/x86/kvm/lapic.c
26507+++ b/arch/x86/kvm/lapic.c
26508@@ -55,7 +55,7 @@
26509 #define APIC_BUS_CYCLE_NS 1
26510
26511 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
26512-#define apic_debug(fmt, arg...)
26513+#define apic_debug(fmt, arg...) do {} while (0)
26514
26515 #define APIC_LVT_NUM 6
26516 /* 14 is the version for Xeon and Pentium 8.4.8*/
26517diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
26518index 7769699..c8aca4a7f 100644
26519--- a/arch/x86/kvm/paging_tmpl.h
26520+++ b/arch/x86/kvm/paging_tmpl.h
26521@@ -208,7 +208,7 @@ retry_walk:
26522 if (unlikely(kvm_is_error_hva(host_addr)))
26523 goto error;
26524
26525- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
26526+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
26527 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
26528 goto error;
26529 walker->ptep_user[walker->level - 1] = ptep_user;
26530diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
26531index c0bc803..6837a50 100644
26532--- a/arch/x86/kvm/svm.c
26533+++ b/arch/x86/kvm/svm.c
26534@@ -3501,7 +3501,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
26535 int cpu = raw_smp_processor_id();
26536
26537 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
26538+
26539+ pax_open_kernel();
26540 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
26541+ pax_close_kernel();
26542+
26543 load_TR_desc();
26544 }
26545
26546@@ -3902,6 +3906,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
26547 #endif
26548 #endif
26549
26550+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26551+ __set_fs(current_thread_info()->addr_limit);
26552+#endif
26553+
26554 reload_tss(vcpu);
26555
26556 local_irq_disable();
26557diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
26558index 064d0be..f5f758e 100644
26559--- a/arch/x86/kvm/vmx.c
26560+++ b/arch/x86/kvm/vmx.c
26561@@ -1311,12 +1311,12 @@ static void vmcs_write64(unsigned long field, u64 value)
26562 #endif
26563 }
26564
26565-static void vmcs_clear_bits(unsigned long field, u32 mask)
26566+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
26567 {
26568 vmcs_writel(field, vmcs_readl(field) & ~mask);
26569 }
26570
26571-static void vmcs_set_bits(unsigned long field, u32 mask)
26572+static void vmcs_set_bits(unsigned long field, unsigned long mask)
26573 {
26574 vmcs_writel(field, vmcs_readl(field) | mask);
26575 }
26576@@ -1517,7 +1517,11 @@ static void reload_tss(void)
26577 struct desc_struct *descs;
26578
26579 descs = (void *)gdt->address;
26580+
26581+ pax_open_kernel();
26582 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
26583+ pax_close_kernel();
26584+
26585 load_TR_desc();
26586 }
26587
26588@@ -1741,6 +1745,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
26589 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
26590 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
26591
26592+#ifdef CONFIG_PAX_PER_CPU_PGD
26593+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26594+#endif
26595+
26596 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
26597 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
26598 vmx->loaded_vmcs->cpu = cpu;
26599@@ -2940,8 +2948,11 @@ static __init int hardware_setup(void)
26600 if (!cpu_has_vmx_flexpriority())
26601 flexpriority_enabled = 0;
26602
26603- if (!cpu_has_vmx_tpr_shadow())
26604- kvm_x86_ops->update_cr8_intercept = NULL;
26605+ if (!cpu_has_vmx_tpr_shadow()) {
26606+ pax_open_kernel();
26607+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26608+ pax_close_kernel();
26609+ }
26610
26611 if (enable_ept && !cpu_has_vmx_ept_2m_page())
26612 kvm_disable_largepages();
26613@@ -2952,13 +2963,15 @@ static __init int hardware_setup(void)
26614 if (!cpu_has_vmx_apicv())
26615 enable_apicv = 0;
26616
26617+ pax_open_kernel();
26618 if (enable_apicv)
26619- kvm_x86_ops->update_cr8_intercept = NULL;
26620+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26621 else {
26622- kvm_x86_ops->hwapic_irr_update = NULL;
26623- kvm_x86_ops->deliver_posted_interrupt = NULL;
26624- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26625+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
26626+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
26627+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26628 }
26629+ pax_close_kernel();
26630
26631 if (nested)
26632 nested_vmx_setup_ctls_msrs();
26633@@ -4081,7 +4094,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26634
26635 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
26636 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
26637+
26638+#ifndef CONFIG_PAX_PER_CPU_PGD
26639 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26640+#endif
26641
26642 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
26643 #ifdef CONFIG_X86_64
26644@@ -4103,7 +4119,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26645 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
26646 vmx->host_idt_base = dt.address;
26647
26648- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
26649+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
26650
26651 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
26652 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
26653@@ -7039,6 +7055,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26654 "jmp 2f \n\t"
26655 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
26656 "2: "
26657+
26658+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26659+ "ljmp %[cs],$3f\n\t"
26660+ "3: "
26661+#endif
26662+
26663 /* Save guest registers, load host registers, keep flags */
26664 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
26665 "pop %0 \n\t"
26666@@ -7091,6 +7113,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26667 #endif
26668 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
26669 [wordsize]"i"(sizeof(ulong))
26670+
26671+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26672+ ,[cs]"i"(__KERNEL_CS)
26673+#endif
26674+
26675 : "cc", "memory"
26676 #ifdef CONFIG_X86_64
26677 , "rax", "rbx", "rdi", "rsi"
26678@@ -7104,7 +7131,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26679 if (debugctlmsr)
26680 update_debugctlmsr(debugctlmsr);
26681
26682-#ifndef CONFIG_X86_64
26683+#ifdef CONFIG_X86_32
26684 /*
26685 * The sysexit path does not restore ds/es, so we must set them to
26686 * a reasonable value ourselves.
26687@@ -7113,8 +7140,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26688 * may be executed in interrupt context, which saves and restore segments
26689 * around it, nullifying its effect.
26690 */
26691- loadsegment(ds, __USER_DS);
26692- loadsegment(es, __USER_DS);
26693+ loadsegment(ds, __KERNEL_DS);
26694+ loadsegment(es, __KERNEL_DS);
26695+ loadsegment(ss, __KERNEL_DS);
26696+
26697+#ifdef CONFIG_PAX_KERNEXEC
26698+ loadsegment(fs, __KERNEL_PERCPU);
26699+#endif
26700+
26701+#ifdef CONFIG_PAX_MEMORY_UDEREF
26702+ __set_fs(current_thread_info()->addr_limit);
26703+#endif
26704+
26705 #endif
26706
26707 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
26708diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
26709index d21bce5..fdae9f1 100644
26710--- a/arch/x86/kvm/x86.c
26711+++ b/arch/x86/kvm/x86.c
26712@@ -1766,8 +1766,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
26713 {
26714 struct kvm *kvm = vcpu->kvm;
26715 int lm = is_long_mode(vcpu);
26716- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26717- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26718+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26719+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26720 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
26721 : kvm->arch.xen_hvm_config.blob_size_32;
26722 u32 page_num = data & ~PAGE_MASK;
26723@@ -2650,6 +2650,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
26724 if (n < msr_list.nmsrs)
26725 goto out;
26726 r = -EFAULT;
26727+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
26728+ goto out;
26729 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
26730 num_msrs_to_save * sizeof(u32)))
26731 goto out;
26732@@ -5344,7 +5346,7 @@ static struct notifier_block pvclock_gtod_notifier = {
26733 };
26734 #endif
26735
26736-int kvm_arch_init(void *opaque)
26737+int kvm_arch_init(const void *opaque)
26738 {
26739 int r;
26740 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
26741diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
26742index 6a22c19..1763f04 100644
26743--- a/arch/x86/lguest/boot.c
26744+++ b/arch/x86/lguest/boot.c
26745@@ -1201,9 +1201,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
26746 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
26747 * Launcher to reboot us.
26748 */
26749-static void lguest_restart(char *reason)
26750+static __noreturn void lguest_restart(char *reason)
26751 {
26752 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
26753+ BUG();
26754 }
26755
26756 /*G:050
26757diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
26758index 00933d5..3a64af9 100644
26759--- a/arch/x86/lib/atomic64_386_32.S
26760+++ b/arch/x86/lib/atomic64_386_32.S
26761@@ -48,6 +48,10 @@ BEGIN(read)
26762 movl (v), %eax
26763 movl 4(v), %edx
26764 RET_ENDP
26765+BEGIN(read_unchecked)
26766+ movl (v), %eax
26767+ movl 4(v), %edx
26768+RET_ENDP
26769 #undef v
26770
26771 #define v %esi
26772@@ -55,6 +59,10 @@ BEGIN(set)
26773 movl %ebx, (v)
26774 movl %ecx, 4(v)
26775 RET_ENDP
26776+BEGIN(set_unchecked)
26777+ movl %ebx, (v)
26778+ movl %ecx, 4(v)
26779+RET_ENDP
26780 #undef v
26781
26782 #define v %esi
26783@@ -70,6 +78,20 @@ RET_ENDP
26784 BEGIN(add)
26785 addl %eax, (v)
26786 adcl %edx, 4(v)
26787+
26788+#ifdef CONFIG_PAX_REFCOUNT
26789+ jno 0f
26790+ subl %eax, (v)
26791+ sbbl %edx, 4(v)
26792+ int $4
26793+0:
26794+ _ASM_EXTABLE(0b, 0b)
26795+#endif
26796+
26797+RET_ENDP
26798+BEGIN(add_unchecked)
26799+ addl %eax, (v)
26800+ adcl %edx, 4(v)
26801 RET_ENDP
26802 #undef v
26803
26804@@ -77,6 +99,24 @@ RET_ENDP
26805 BEGIN(add_return)
26806 addl (v), %eax
26807 adcl 4(v), %edx
26808+
26809+#ifdef CONFIG_PAX_REFCOUNT
26810+ into
26811+1234:
26812+ _ASM_EXTABLE(1234b, 2f)
26813+#endif
26814+
26815+ movl %eax, (v)
26816+ movl %edx, 4(v)
26817+
26818+#ifdef CONFIG_PAX_REFCOUNT
26819+2:
26820+#endif
26821+
26822+RET_ENDP
26823+BEGIN(add_return_unchecked)
26824+ addl (v), %eax
26825+ adcl 4(v), %edx
26826 movl %eax, (v)
26827 movl %edx, 4(v)
26828 RET_ENDP
26829@@ -86,6 +126,20 @@ RET_ENDP
26830 BEGIN(sub)
26831 subl %eax, (v)
26832 sbbl %edx, 4(v)
26833+
26834+#ifdef CONFIG_PAX_REFCOUNT
26835+ jno 0f
26836+ addl %eax, (v)
26837+ adcl %edx, 4(v)
26838+ int $4
26839+0:
26840+ _ASM_EXTABLE(0b, 0b)
26841+#endif
26842+
26843+RET_ENDP
26844+BEGIN(sub_unchecked)
26845+ subl %eax, (v)
26846+ sbbl %edx, 4(v)
26847 RET_ENDP
26848 #undef v
26849
26850@@ -96,6 +150,27 @@ BEGIN(sub_return)
26851 sbbl $0, %edx
26852 addl (v), %eax
26853 adcl 4(v), %edx
26854+
26855+#ifdef CONFIG_PAX_REFCOUNT
26856+ into
26857+1234:
26858+ _ASM_EXTABLE(1234b, 2f)
26859+#endif
26860+
26861+ movl %eax, (v)
26862+ movl %edx, 4(v)
26863+
26864+#ifdef CONFIG_PAX_REFCOUNT
26865+2:
26866+#endif
26867+
26868+RET_ENDP
26869+BEGIN(sub_return_unchecked)
26870+ negl %edx
26871+ negl %eax
26872+ sbbl $0, %edx
26873+ addl (v), %eax
26874+ adcl 4(v), %edx
26875 movl %eax, (v)
26876 movl %edx, 4(v)
26877 RET_ENDP
26878@@ -105,6 +180,20 @@ RET_ENDP
26879 BEGIN(inc)
26880 addl $1, (v)
26881 adcl $0, 4(v)
26882+
26883+#ifdef CONFIG_PAX_REFCOUNT
26884+ jno 0f
26885+ subl $1, (v)
26886+ sbbl $0, 4(v)
26887+ int $4
26888+0:
26889+ _ASM_EXTABLE(0b, 0b)
26890+#endif
26891+
26892+RET_ENDP
26893+BEGIN(inc_unchecked)
26894+ addl $1, (v)
26895+ adcl $0, 4(v)
26896 RET_ENDP
26897 #undef v
26898
26899@@ -114,6 +203,26 @@ BEGIN(inc_return)
26900 movl 4(v), %edx
26901 addl $1, %eax
26902 adcl $0, %edx
26903+
26904+#ifdef CONFIG_PAX_REFCOUNT
26905+ into
26906+1234:
26907+ _ASM_EXTABLE(1234b, 2f)
26908+#endif
26909+
26910+ movl %eax, (v)
26911+ movl %edx, 4(v)
26912+
26913+#ifdef CONFIG_PAX_REFCOUNT
26914+2:
26915+#endif
26916+
26917+RET_ENDP
26918+BEGIN(inc_return_unchecked)
26919+ movl (v), %eax
26920+ movl 4(v), %edx
26921+ addl $1, %eax
26922+ adcl $0, %edx
26923 movl %eax, (v)
26924 movl %edx, 4(v)
26925 RET_ENDP
26926@@ -123,6 +232,20 @@ RET_ENDP
26927 BEGIN(dec)
26928 subl $1, (v)
26929 sbbl $0, 4(v)
26930+
26931+#ifdef CONFIG_PAX_REFCOUNT
26932+ jno 0f
26933+ addl $1, (v)
26934+ adcl $0, 4(v)
26935+ int $4
26936+0:
26937+ _ASM_EXTABLE(0b, 0b)
26938+#endif
26939+
26940+RET_ENDP
26941+BEGIN(dec_unchecked)
26942+ subl $1, (v)
26943+ sbbl $0, 4(v)
26944 RET_ENDP
26945 #undef v
26946
26947@@ -132,6 +255,26 @@ BEGIN(dec_return)
26948 movl 4(v), %edx
26949 subl $1, %eax
26950 sbbl $0, %edx
26951+
26952+#ifdef CONFIG_PAX_REFCOUNT
26953+ into
26954+1234:
26955+ _ASM_EXTABLE(1234b, 2f)
26956+#endif
26957+
26958+ movl %eax, (v)
26959+ movl %edx, 4(v)
26960+
26961+#ifdef CONFIG_PAX_REFCOUNT
26962+2:
26963+#endif
26964+
26965+RET_ENDP
26966+BEGIN(dec_return_unchecked)
26967+ movl (v), %eax
26968+ movl 4(v), %edx
26969+ subl $1, %eax
26970+ sbbl $0, %edx
26971 movl %eax, (v)
26972 movl %edx, 4(v)
26973 RET_ENDP
26974@@ -143,6 +286,13 @@ BEGIN(add_unless)
26975 adcl %edx, %edi
26976 addl (v), %eax
26977 adcl 4(v), %edx
26978+
26979+#ifdef CONFIG_PAX_REFCOUNT
26980+ into
26981+1234:
26982+ _ASM_EXTABLE(1234b, 2f)
26983+#endif
26984+
26985 cmpl %eax, %ecx
26986 je 3f
26987 1:
26988@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
26989 1:
26990 addl $1, %eax
26991 adcl $0, %edx
26992+
26993+#ifdef CONFIG_PAX_REFCOUNT
26994+ into
26995+1234:
26996+ _ASM_EXTABLE(1234b, 2f)
26997+#endif
26998+
26999 movl %eax, (v)
27000 movl %edx, 4(v)
27001 movl $1, %eax
27002@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
27003 movl 4(v), %edx
27004 subl $1, %eax
27005 sbbl $0, %edx
27006+
27007+#ifdef CONFIG_PAX_REFCOUNT
27008+ into
27009+1234:
27010+ _ASM_EXTABLE(1234b, 1f)
27011+#endif
27012+
27013 js 1f
27014 movl %eax, (v)
27015 movl %edx, 4(v)
27016diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
27017index f5cc9eb..51fa319 100644
27018--- a/arch/x86/lib/atomic64_cx8_32.S
27019+++ b/arch/x86/lib/atomic64_cx8_32.S
27020@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
27021 CFI_STARTPROC
27022
27023 read64 %ecx
27024+ pax_force_retaddr
27025 ret
27026 CFI_ENDPROC
27027 ENDPROC(atomic64_read_cx8)
27028
27029+ENTRY(atomic64_read_unchecked_cx8)
27030+ CFI_STARTPROC
27031+
27032+ read64 %ecx
27033+ pax_force_retaddr
27034+ ret
27035+ CFI_ENDPROC
27036+ENDPROC(atomic64_read_unchecked_cx8)
27037+
27038 ENTRY(atomic64_set_cx8)
27039 CFI_STARTPROC
27040
27041@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
27042 cmpxchg8b (%esi)
27043 jne 1b
27044
27045+ pax_force_retaddr
27046 ret
27047 CFI_ENDPROC
27048 ENDPROC(atomic64_set_cx8)
27049
27050+ENTRY(atomic64_set_unchecked_cx8)
27051+ CFI_STARTPROC
27052+
27053+1:
27054+/* we don't need LOCK_PREFIX since aligned 64-bit writes
27055+ * are atomic on 586 and newer */
27056+ cmpxchg8b (%esi)
27057+ jne 1b
27058+
27059+ pax_force_retaddr
27060+ ret
27061+ CFI_ENDPROC
27062+ENDPROC(atomic64_set_unchecked_cx8)
27063+
27064 ENTRY(atomic64_xchg_cx8)
27065 CFI_STARTPROC
27066
27067@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
27068 cmpxchg8b (%esi)
27069 jne 1b
27070
27071+ pax_force_retaddr
27072 ret
27073 CFI_ENDPROC
27074 ENDPROC(atomic64_xchg_cx8)
27075
27076-.macro addsub_return func ins insc
27077-ENTRY(atomic64_\func\()_return_cx8)
27078+.macro addsub_return func ins insc unchecked=""
27079+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27080 CFI_STARTPROC
27081 SAVE ebp
27082 SAVE ebx
27083@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
27084 movl %edx, %ecx
27085 \ins\()l %esi, %ebx
27086 \insc\()l %edi, %ecx
27087+
27088+.ifb \unchecked
27089+#ifdef CONFIG_PAX_REFCOUNT
27090+ into
27091+2:
27092+ _ASM_EXTABLE(2b, 3f)
27093+#endif
27094+.endif
27095+
27096 LOCK_PREFIX
27097 cmpxchg8b (%ebp)
27098 jne 1b
27099-
27100-10:
27101 movl %ebx, %eax
27102 movl %ecx, %edx
27103+
27104+.ifb \unchecked
27105+#ifdef CONFIG_PAX_REFCOUNT
27106+3:
27107+#endif
27108+.endif
27109+
27110 RESTORE edi
27111 RESTORE esi
27112 RESTORE ebx
27113 RESTORE ebp
27114+ pax_force_retaddr
27115 ret
27116 CFI_ENDPROC
27117-ENDPROC(atomic64_\func\()_return_cx8)
27118+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27119 .endm
27120
27121 addsub_return add add adc
27122 addsub_return sub sub sbb
27123+addsub_return add add adc _unchecked
27124+addsub_return sub sub sbb _unchecked
27125
27126-.macro incdec_return func ins insc
27127-ENTRY(atomic64_\func\()_return_cx8)
27128+.macro incdec_return func ins insc unchecked=""
27129+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27130 CFI_STARTPROC
27131 SAVE ebx
27132
27133@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
27134 movl %edx, %ecx
27135 \ins\()l $1, %ebx
27136 \insc\()l $0, %ecx
27137+
27138+.ifb \unchecked
27139+#ifdef CONFIG_PAX_REFCOUNT
27140+ into
27141+2:
27142+ _ASM_EXTABLE(2b, 3f)
27143+#endif
27144+.endif
27145+
27146 LOCK_PREFIX
27147 cmpxchg8b (%esi)
27148 jne 1b
27149
27150-10:
27151 movl %ebx, %eax
27152 movl %ecx, %edx
27153+
27154+.ifb \unchecked
27155+#ifdef CONFIG_PAX_REFCOUNT
27156+3:
27157+#endif
27158+.endif
27159+
27160 RESTORE ebx
27161+ pax_force_retaddr
27162 ret
27163 CFI_ENDPROC
27164-ENDPROC(atomic64_\func\()_return_cx8)
27165+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27166 .endm
27167
27168 incdec_return inc add adc
27169 incdec_return dec sub sbb
27170+incdec_return inc add adc _unchecked
27171+incdec_return dec sub sbb _unchecked
27172
27173 ENTRY(atomic64_dec_if_positive_cx8)
27174 CFI_STARTPROC
27175@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
27176 movl %edx, %ecx
27177 subl $1, %ebx
27178 sbb $0, %ecx
27179+
27180+#ifdef CONFIG_PAX_REFCOUNT
27181+ into
27182+1234:
27183+ _ASM_EXTABLE(1234b, 2f)
27184+#endif
27185+
27186 js 2f
27187 LOCK_PREFIX
27188 cmpxchg8b (%esi)
27189@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
27190 movl %ebx, %eax
27191 movl %ecx, %edx
27192 RESTORE ebx
27193+ pax_force_retaddr
27194 ret
27195 CFI_ENDPROC
27196 ENDPROC(atomic64_dec_if_positive_cx8)
27197@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
27198 movl %edx, %ecx
27199 addl %ebp, %ebx
27200 adcl %edi, %ecx
27201+
27202+#ifdef CONFIG_PAX_REFCOUNT
27203+ into
27204+1234:
27205+ _ASM_EXTABLE(1234b, 3f)
27206+#endif
27207+
27208 LOCK_PREFIX
27209 cmpxchg8b (%esi)
27210 jne 1b
27211@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
27212 CFI_ADJUST_CFA_OFFSET -8
27213 RESTORE ebx
27214 RESTORE ebp
27215+ pax_force_retaddr
27216 ret
27217 4:
27218 cmpl %edx, 4(%esp)
27219@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
27220 xorl %ecx, %ecx
27221 addl $1, %ebx
27222 adcl %edx, %ecx
27223+
27224+#ifdef CONFIG_PAX_REFCOUNT
27225+ into
27226+1234:
27227+ _ASM_EXTABLE(1234b, 3f)
27228+#endif
27229+
27230 LOCK_PREFIX
27231 cmpxchg8b (%esi)
27232 jne 1b
27233@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
27234 movl $1, %eax
27235 3:
27236 RESTORE ebx
27237+ pax_force_retaddr
27238 ret
27239 CFI_ENDPROC
27240 ENDPROC(atomic64_inc_not_zero_cx8)
27241diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
27242index e78b8ee..7e173a8 100644
27243--- a/arch/x86/lib/checksum_32.S
27244+++ b/arch/x86/lib/checksum_32.S
27245@@ -29,7 +29,8 @@
27246 #include <asm/dwarf2.h>
27247 #include <asm/errno.h>
27248 #include <asm/asm.h>
27249-
27250+#include <asm/segment.h>
27251+
27252 /*
27253 * computes a partial checksum, e.g. for TCP/UDP fragments
27254 */
27255@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
27256
27257 #define ARGBASE 16
27258 #define FP 12
27259-
27260-ENTRY(csum_partial_copy_generic)
27261+
27262+ENTRY(csum_partial_copy_generic_to_user)
27263 CFI_STARTPROC
27264+
27265+#ifdef CONFIG_PAX_MEMORY_UDEREF
27266+ pushl_cfi %gs
27267+ popl_cfi %es
27268+ jmp csum_partial_copy_generic
27269+#endif
27270+
27271+ENTRY(csum_partial_copy_generic_from_user)
27272+
27273+#ifdef CONFIG_PAX_MEMORY_UDEREF
27274+ pushl_cfi %gs
27275+ popl_cfi %ds
27276+#endif
27277+
27278+ENTRY(csum_partial_copy_generic)
27279 subl $4,%esp
27280 CFI_ADJUST_CFA_OFFSET 4
27281 pushl_cfi %edi
27282@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
27283 jmp 4f
27284 SRC(1: movw (%esi), %bx )
27285 addl $2, %esi
27286-DST( movw %bx, (%edi) )
27287+DST( movw %bx, %es:(%edi) )
27288 addl $2, %edi
27289 addw %bx, %ax
27290 adcl $0, %eax
27291@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
27292 SRC(1: movl (%esi), %ebx )
27293 SRC( movl 4(%esi), %edx )
27294 adcl %ebx, %eax
27295-DST( movl %ebx, (%edi) )
27296+DST( movl %ebx, %es:(%edi) )
27297 adcl %edx, %eax
27298-DST( movl %edx, 4(%edi) )
27299+DST( movl %edx, %es:4(%edi) )
27300
27301 SRC( movl 8(%esi), %ebx )
27302 SRC( movl 12(%esi), %edx )
27303 adcl %ebx, %eax
27304-DST( movl %ebx, 8(%edi) )
27305+DST( movl %ebx, %es:8(%edi) )
27306 adcl %edx, %eax
27307-DST( movl %edx, 12(%edi) )
27308+DST( movl %edx, %es:12(%edi) )
27309
27310 SRC( movl 16(%esi), %ebx )
27311 SRC( movl 20(%esi), %edx )
27312 adcl %ebx, %eax
27313-DST( movl %ebx, 16(%edi) )
27314+DST( movl %ebx, %es:16(%edi) )
27315 adcl %edx, %eax
27316-DST( movl %edx, 20(%edi) )
27317+DST( movl %edx, %es:20(%edi) )
27318
27319 SRC( movl 24(%esi), %ebx )
27320 SRC( movl 28(%esi), %edx )
27321 adcl %ebx, %eax
27322-DST( movl %ebx, 24(%edi) )
27323+DST( movl %ebx, %es:24(%edi) )
27324 adcl %edx, %eax
27325-DST( movl %edx, 28(%edi) )
27326+DST( movl %edx, %es:28(%edi) )
27327
27328 lea 32(%esi), %esi
27329 lea 32(%edi), %edi
27330@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
27331 shrl $2, %edx # This clears CF
27332 SRC(3: movl (%esi), %ebx )
27333 adcl %ebx, %eax
27334-DST( movl %ebx, (%edi) )
27335+DST( movl %ebx, %es:(%edi) )
27336 lea 4(%esi), %esi
27337 lea 4(%edi), %edi
27338 dec %edx
27339@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
27340 jb 5f
27341 SRC( movw (%esi), %cx )
27342 leal 2(%esi), %esi
27343-DST( movw %cx, (%edi) )
27344+DST( movw %cx, %es:(%edi) )
27345 leal 2(%edi), %edi
27346 je 6f
27347 shll $16,%ecx
27348 SRC(5: movb (%esi), %cl )
27349-DST( movb %cl, (%edi) )
27350+DST( movb %cl, %es:(%edi) )
27351 6: addl %ecx, %eax
27352 adcl $0, %eax
27353 7:
27354@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
27355
27356 6001:
27357 movl ARGBASE+20(%esp), %ebx # src_err_ptr
27358- movl $-EFAULT, (%ebx)
27359+ movl $-EFAULT, %ss:(%ebx)
27360
27361 # zero the complete destination - computing the rest
27362 # is too much work
27363@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
27364
27365 6002:
27366 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27367- movl $-EFAULT,(%ebx)
27368+ movl $-EFAULT,%ss:(%ebx)
27369 jmp 5000b
27370
27371 .previous
27372
27373+ pushl_cfi %ss
27374+ popl_cfi %ds
27375+ pushl_cfi %ss
27376+ popl_cfi %es
27377 popl_cfi %ebx
27378 CFI_RESTORE ebx
27379 popl_cfi %esi
27380@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
27381 popl_cfi %ecx # equivalent to addl $4,%esp
27382 ret
27383 CFI_ENDPROC
27384-ENDPROC(csum_partial_copy_generic)
27385+ENDPROC(csum_partial_copy_generic_to_user)
27386
27387 #else
27388
27389 /* Version for PentiumII/PPro */
27390
27391 #define ROUND1(x) \
27392+ nop; nop; nop; \
27393 SRC(movl x(%esi), %ebx ) ; \
27394 addl %ebx, %eax ; \
27395- DST(movl %ebx, x(%edi) ) ;
27396+ DST(movl %ebx, %es:x(%edi)) ;
27397
27398 #define ROUND(x) \
27399+ nop; nop; nop; \
27400 SRC(movl x(%esi), %ebx ) ; \
27401 adcl %ebx, %eax ; \
27402- DST(movl %ebx, x(%edi) ) ;
27403+ DST(movl %ebx, %es:x(%edi)) ;
27404
27405 #define ARGBASE 12
27406-
27407-ENTRY(csum_partial_copy_generic)
27408+
27409+ENTRY(csum_partial_copy_generic_to_user)
27410 CFI_STARTPROC
27411+
27412+#ifdef CONFIG_PAX_MEMORY_UDEREF
27413+ pushl_cfi %gs
27414+ popl_cfi %es
27415+ jmp csum_partial_copy_generic
27416+#endif
27417+
27418+ENTRY(csum_partial_copy_generic_from_user)
27419+
27420+#ifdef CONFIG_PAX_MEMORY_UDEREF
27421+ pushl_cfi %gs
27422+ popl_cfi %ds
27423+#endif
27424+
27425+ENTRY(csum_partial_copy_generic)
27426 pushl_cfi %ebx
27427 CFI_REL_OFFSET ebx, 0
27428 pushl_cfi %edi
27429@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
27430 subl %ebx, %edi
27431 lea -1(%esi),%edx
27432 andl $-32,%edx
27433- lea 3f(%ebx,%ebx), %ebx
27434+ lea 3f(%ebx,%ebx,2), %ebx
27435 testl %esi, %esi
27436 jmp *%ebx
27437 1: addl $64,%esi
27438@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
27439 jb 5f
27440 SRC( movw (%esi), %dx )
27441 leal 2(%esi), %esi
27442-DST( movw %dx, (%edi) )
27443+DST( movw %dx, %es:(%edi) )
27444 leal 2(%edi), %edi
27445 je 6f
27446 shll $16,%edx
27447 5:
27448 SRC( movb (%esi), %dl )
27449-DST( movb %dl, (%edi) )
27450+DST( movb %dl, %es:(%edi) )
27451 6: addl %edx, %eax
27452 adcl $0, %eax
27453 7:
27454 .section .fixup, "ax"
27455 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
27456- movl $-EFAULT, (%ebx)
27457+ movl $-EFAULT, %ss:(%ebx)
27458 # zero the complete destination (computing the rest is too much work)
27459 movl ARGBASE+8(%esp),%edi # dst
27460 movl ARGBASE+12(%esp),%ecx # len
27461@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
27462 rep; stosb
27463 jmp 7b
27464 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27465- movl $-EFAULT, (%ebx)
27466+ movl $-EFAULT, %ss:(%ebx)
27467 jmp 7b
27468 .previous
27469
27470+#ifdef CONFIG_PAX_MEMORY_UDEREF
27471+ pushl_cfi %ss
27472+ popl_cfi %ds
27473+ pushl_cfi %ss
27474+ popl_cfi %es
27475+#endif
27476+
27477 popl_cfi %esi
27478 CFI_RESTORE esi
27479 popl_cfi %edi
27480@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
27481 CFI_RESTORE ebx
27482 ret
27483 CFI_ENDPROC
27484-ENDPROC(csum_partial_copy_generic)
27485+ENDPROC(csum_partial_copy_generic_to_user)
27486
27487 #undef ROUND
27488 #undef ROUND1
27489diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
27490index f2145cf..cea889d 100644
27491--- a/arch/x86/lib/clear_page_64.S
27492+++ b/arch/x86/lib/clear_page_64.S
27493@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
27494 movl $4096/8,%ecx
27495 xorl %eax,%eax
27496 rep stosq
27497+ pax_force_retaddr
27498 ret
27499 CFI_ENDPROC
27500 ENDPROC(clear_page_c)
27501@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
27502 movl $4096,%ecx
27503 xorl %eax,%eax
27504 rep stosb
27505+ pax_force_retaddr
27506 ret
27507 CFI_ENDPROC
27508 ENDPROC(clear_page_c_e)
27509@@ -43,6 +45,7 @@ ENTRY(clear_page)
27510 leaq 64(%rdi),%rdi
27511 jnz .Lloop
27512 nop
27513+ pax_force_retaddr
27514 ret
27515 CFI_ENDPROC
27516 .Lclear_page_end:
27517@@ -58,7 +61,7 @@ ENDPROC(clear_page)
27518
27519 #include <asm/cpufeature.h>
27520
27521- .section .altinstr_replacement,"ax"
27522+ .section .altinstr_replacement,"a"
27523 1: .byte 0xeb /* jmp <disp8> */
27524 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
27525 2: .byte 0xeb /* jmp <disp8> */
27526diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
27527index 1e572c5..2a162cd 100644
27528--- a/arch/x86/lib/cmpxchg16b_emu.S
27529+++ b/arch/x86/lib/cmpxchg16b_emu.S
27530@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
27531
27532 popf
27533 mov $1, %al
27534+ pax_force_retaddr
27535 ret
27536
27537 not_same:
27538 popf
27539 xor %al,%al
27540+ pax_force_retaddr
27541 ret
27542
27543 CFI_ENDPROC
27544diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
27545index 176cca6..1166c50 100644
27546--- a/arch/x86/lib/copy_page_64.S
27547+++ b/arch/x86/lib/copy_page_64.S
27548@@ -9,6 +9,7 @@ copy_page_rep:
27549 CFI_STARTPROC
27550 movl $4096/8, %ecx
27551 rep movsq
27552+ pax_force_retaddr
27553 ret
27554 CFI_ENDPROC
27555 ENDPROC(copy_page_rep)
27556@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
27557
27558 ENTRY(copy_page)
27559 CFI_STARTPROC
27560- subq $2*8, %rsp
27561- CFI_ADJUST_CFA_OFFSET 2*8
27562+ subq $3*8, %rsp
27563+ CFI_ADJUST_CFA_OFFSET 3*8
27564 movq %rbx, (%rsp)
27565 CFI_REL_OFFSET rbx, 0
27566 movq %r12, 1*8(%rsp)
27567 CFI_REL_OFFSET r12, 1*8
27568+ movq %r13, 2*8(%rsp)
27569+ CFI_REL_OFFSET r13, 2*8
27570
27571 movl $(4096/64)-5, %ecx
27572 .p2align 4
27573@@ -36,7 +39,7 @@ ENTRY(copy_page)
27574 movq 0x8*2(%rsi), %rdx
27575 movq 0x8*3(%rsi), %r8
27576 movq 0x8*4(%rsi), %r9
27577- movq 0x8*5(%rsi), %r10
27578+ movq 0x8*5(%rsi), %r13
27579 movq 0x8*6(%rsi), %r11
27580 movq 0x8*7(%rsi), %r12
27581
27582@@ -47,7 +50,7 @@ ENTRY(copy_page)
27583 movq %rdx, 0x8*2(%rdi)
27584 movq %r8, 0x8*3(%rdi)
27585 movq %r9, 0x8*4(%rdi)
27586- movq %r10, 0x8*5(%rdi)
27587+ movq %r13, 0x8*5(%rdi)
27588 movq %r11, 0x8*6(%rdi)
27589 movq %r12, 0x8*7(%rdi)
27590
27591@@ -66,7 +69,7 @@ ENTRY(copy_page)
27592 movq 0x8*2(%rsi), %rdx
27593 movq 0x8*3(%rsi), %r8
27594 movq 0x8*4(%rsi), %r9
27595- movq 0x8*5(%rsi), %r10
27596+ movq 0x8*5(%rsi), %r13
27597 movq 0x8*6(%rsi), %r11
27598 movq 0x8*7(%rsi), %r12
27599
27600@@ -75,7 +78,7 @@ ENTRY(copy_page)
27601 movq %rdx, 0x8*2(%rdi)
27602 movq %r8, 0x8*3(%rdi)
27603 movq %r9, 0x8*4(%rdi)
27604- movq %r10, 0x8*5(%rdi)
27605+ movq %r13, 0x8*5(%rdi)
27606 movq %r11, 0x8*6(%rdi)
27607 movq %r12, 0x8*7(%rdi)
27608
27609@@ -87,8 +90,11 @@ ENTRY(copy_page)
27610 CFI_RESTORE rbx
27611 movq 1*8(%rsp), %r12
27612 CFI_RESTORE r12
27613- addq $2*8, %rsp
27614- CFI_ADJUST_CFA_OFFSET -2*8
27615+ movq 2*8(%rsp), %r13
27616+ CFI_RESTORE r13
27617+ addq $3*8, %rsp
27618+ CFI_ADJUST_CFA_OFFSET -3*8
27619+ pax_force_retaddr
27620 ret
27621 .Lcopy_page_end:
27622 CFI_ENDPROC
27623@@ -99,7 +105,7 @@ ENDPROC(copy_page)
27624
27625 #include <asm/cpufeature.h>
27626
27627- .section .altinstr_replacement,"ax"
27628+ .section .altinstr_replacement,"a"
27629 1: .byte 0xeb /* jmp <disp8> */
27630 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
27631 2:
27632diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
27633index a30ca15..6b3f4e1 100644
27634--- a/arch/x86/lib/copy_user_64.S
27635+++ b/arch/x86/lib/copy_user_64.S
27636@@ -18,31 +18,7 @@
27637 #include <asm/alternative-asm.h>
27638 #include <asm/asm.h>
27639 #include <asm/smap.h>
27640-
27641-/*
27642- * By placing feature2 after feature1 in altinstructions section, we logically
27643- * implement:
27644- * If CPU has feature2, jmp to alt2 is used
27645- * else if CPU has feature1, jmp to alt1 is used
27646- * else jmp to orig is used.
27647- */
27648- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
27649-0:
27650- .byte 0xe9 /* 32bit jump */
27651- .long \orig-1f /* by default jump to orig */
27652-1:
27653- .section .altinstr_replacement,"ax"
27654-2: .byte 0xe9 /* near jump with 32bit immediate */
27655- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
27656-3: .byte 0xe9 /* near jump with 32bit immediate */
27657- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
27658- .previous
27659-
27660- .section .altinstructions,"a"
27661- altinstruction_entry 0b,2b,\feature1,5,5
27662- altinstruction_entry 0b,3b,\feature2,5,5
27663- .previous
27664- .endm
27665+#include <asm/pgtable.h>
27666
27667 .macro ALIGN_DESTINATION
27668 #ifdef FIX_ALIGNMENT
27669@@ -70,52 +46,6 @@
27670 #endif
27671 .endm
27672
27673-/* Standard copy_to_user with segment limit checking */
27674-ENTRY(_copy_to_user)
27675- CFI_STARTPROC
27676- GET_THREAD_INFO(%rax)
27677- movq %rdi,%rcx
27678- addq %rdx,%rcx
27679- jc bad_to_user
27680- cmpq TI_addr_limit(%rax),%rcx
27681- ja bad_to_user
27682- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27683- copy_user_generic_unrolled,copy_user_generic_string, \
27684- copy_user_enhanced_fast_string
27685- CFI_ENDPROC
27686-ENDPROC(_copy_to_user)
27687-
27688-/* Standard copy_from_user with segment limit checking */
27689-ENTRY(_copy_from_user)
27690- CFI_STARTPROC
27691- GET_THREAD_INFO(%rax)
27692- movq %rsi,%rcx
27693- addq %rdx,%rcx
27694- jc bad_from_user
27695- cmpq TI_addr_limit(%rax),%rcx
27696- ja bad_from_user
27697- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27698- copy_user_generic_unrolled,copy_user_generic_string, \
27699- copy_user_enhanced_fast_string
27700- CFI_ENDPROC
27701-ENDPROC(_copy_from_user)
27702-
27703- .section .fixup,"ax"
27704- /* must zero dest */
27705-ENTRY(bad_from_user)
27706-bad_from_user:
27707- CFI_STARTPROC
27708- movl %edx,%ecx
27709- xorl %eax,%eax
27710- rep
27711- stosb
27712-bad_to_user:
27713- movl %edx,%eax
27714- ret
27715- CFI_ENDPROC
27716-ENDPROC(bad_from_user)
27717- .previous
27718-
27719 /*
27720 * copy_user_generic_unrolled - memory copy with exception handling.
27721 * This version is for CPUs like P4 that don't have efficient micro
27722@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
27723 */
27724 ENTRY(copy_user_generic_unrolled)
27725 CFI_STARTPROC
27726+ ASM_PAX_OPEN_USERLAND
27727 ASM_STAC
27728 cmpl $8,%edx
27729 jb 20f /* less then 8 bytes, go to byte copy loop */
27730@@ -141,19 +72,19 @@ ENTRY(copy_user_generic_unrolled)
27731 jz 17f
27732 1: movq (%rsi),%r8
27733 2: movq 1*8(%rsi),%r9
27734-3: movq 2*8(%rsi),%r10
27735+3: movq 2*8(%rsi),%rax
27736 4: movq 3*8(%rsi),%r11
27737 5: movq %r8,(%rdi)
27738 6: movq %r9,1*8(%rdi)
27739-7: movq %r10,2*8(%rdi)
27740+7: movq %rax,2*8(%rdi)
27741 8: movq %r11,3*8(%rdi)
27742 9: movq 4*8(%rsi),%r8
27743 10: movq 5*8(%rsi),%r9
27744-11: movq 6*8(%rsi),%r10
27745+11: movq 6*8(%rsi),%rax
27746 12: movq 7*8(%rsi),%r11
27747 13: movq %r8,4*8(%rdi)
27748 14: movq %r9,5*8(%rdi)
27749-15: movq %r10,6*8(%rdi)
27750+15: movq %rax,6*8(%rdi)
27751 16: movq %r11,7*8(%rdi)
27752 leaq 64(%rsi),%rsi
27753 leaq 64(%rdi),%rdi
27754@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
27755 jnz 21b
27756 23: xor %eax,%eax
27757 ASM_CLAC
27758+ ASM_PAX_CLOSE_USERLAND
27759+ pax_force_retaddr
27760 ret
27761
27762 .section .fixup,"ax"
27763@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
27764 */
27765 ENTRY(copy_user_generic_string)
27766 CFI_STARTPROC
27767+ ASM_PAX_OPEN_USERLAND
27768 ASM_STAC
27769 andl %edx,%edx
27770 jz 4f
27771@@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
27772 movsb
27773 4: xorl %eax,%eax
27774 ASM_CLAC
27775+ ASM_PAX_CLOSE_USERLAND
27776+ pax_force_retaddr
27777 ret
27778
27779 .section .fixup,"ax"
27780@@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
27781 */
27782 ENTRY(copy_user_enhanced_fast_string)
27783 CFI_STARTPROC
27784+ ASM_PAX_OPEN_USERLAND
27785 ASM_STAC
27786 andl %edx,%edx
27787 jz 2f
27788@@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
27789 movsb
27790 2: xorl %eax,%eax
27791 ASM_CLAC
27792+ ASM_PAX_CLOSE_USERLAND
27793+ pax_force_retaddr
27794 ret
27795
27796 .section .fixup,"ax"
27797diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
27798index 6a4f43c..55d26f2 100644
27799--- a/arch/x86/lib/copy_user_nocache_64.S
27800+++ b/arch/x86/lib/copy_user_nocache_64.S
27801@@ -8,6 +8,7 @@
27802
27803 #include <linux/linkage.h>
27804 #include <asm/dwarf2.h>
27805+#include <asm/alternative-asm.h>
27806
27807 #define FIX_ALIGNMENT 1
27808
27809@@ -16,6 +17,7 @@
27810 #include <asm/thread_info.h>
27811 #include <asm/asm.h>
27812 #include <asm/smap.h>
27813+#include <asm/pgtable.h>
27814
27815 .macro ALIGN_DESTINATION
27816 #ifdef FIX_ALIGNMENT
27817@@ -49,6 +51,16 @@
27818 */
27819 ENTRY(__copy_user_nocache)
27820 CFI_STARTPROC
27821+
27822+#ifdef CONFIG_PAX_MEMORY_UDEREF
27823+ mov pax_user_shadow_base,%rcx
27824+ cmp %rcx,%rsi
27825+ jae 1f
27826+ add %rcx,%rsi
27827+1:
27828+#endif
27829+
27830+ ASM_PAX_OPEN_USERLAND
27831 ASM_STAC
27832 cmpl $8,%edx
27833 jb 20f /* less then 8 bytes, go to byte copy loop */
27834@@ -59,19 +71,19 @@ ENTRY(__copy_user_nocache)
27835 jz 17f
27836 1: movq (%rsi),%r8
27837 2: movq 1*8(%rsi),%r9
27838-3: movq 2*8(%rsi),%r10
27839+3: movq 2*8(%rsi),%rax
27840 4: movq 3*8(%rsi),%r11
27841 5: movnti %r8,(%rdi)
27842 6: movnti %r9,1*8(%rdi)
27843-7: movnti %r10,2*8(%rdi)
27844+7: movnti %rax,2*8(%rdi)
27845 8: movnti %r11,3*8(%rdi)
27846 9: movq 4*8(%rsi),%r8
27847 10: movq 5*8(%rsi),%r9
27848-11: movq 6*8(%rsi),%r10
27849+11: movq 6*8(%rsi),%rax
27850 12: movq 7*8(%rsi),%r11
27851 13: movnti %r8,4*8(%rdi)
27852 14: movnti %r9,5*8(%rdi)
27853-15: movnti %r10,6*8(%rdi)
27854+15: movnti %rax,6*8(%rdi)
27855 16: movnti %r11,7*8(%rdi)
27856 leaq 64(%rsi),%rsi
27857 leaq 64(%rdi),%rdi
27858@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
27859 jnz 21b
27860 23: xorl %eax,%eax
27861 ASM_CLAC
27862+ ASM_PAX_CLOSE_USERLAND
27863 sfence
27864+ pax_force_retaddr
27865 ret
27866
27867 .section .fixup,"ax"
27868diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
27869index 2419d5f..953ee51 100644
27870--- a/arch/x86/lib/csum-copy_64.S
27871+++ b/arch/x86/lib/csum-copy_64.S
27872@@ -9,6 +9,7 @@
27873 #include <asm/dwarf2.h>
27874 #include <asm/errno.h>
27875 #include <asm/asm.h>
27876+#include <asm/alternative-asm.h>
27877
27878 /*
27879 * Checksum copy with exception handling.
27880@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
27881 CFI_RESTORE rbp
27882 addq $7*8, %rsp
27883 CFI_ADJUST_CFA_OFFSET -7*8
27884+ pax_force_retaddr 0, 1
27885 ret
27886 CFI_RESTORE_STATE
27887
27888diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
27889index 25b7ae8..c40113e 100644
27890--- a/arch/x86/lib/csum-wrappers_64.c
27891+++ b/arch/x86/lib/csum-wrappers_64.c
27892@@ -52,8 +52,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
27893 len -= 2;
27894 }
27895 }
27896- isum = csum_partial_copy_generic((__force const void *)src,
27897+ pax_open_userland();
27898+ stac();
27899+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
27900 dst, len, isum, errp, NULL);
27901+ clac();
27902+ pax_close_userland();
27903 if (unlikely(*errp))
27904 goto out_err;
27905
27906@@ -105,8 +109,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
27907 }
27908
27909 *errp = 0;
27910- return csum_partial_copy_generic(src, (void __force *)dst,
27911+ pax_open_userland();
27912+ stac();
27913+ isum = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
27914 len, isum, NULL, errp);
27915+ clac();
27916+ pax_close_userland();
27917+ return isum;
27918 }
27919 EXPORT_SYMBOL(csum_partial_copy_to_user);
27920
27921diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
27922index a451235..1daa956 100644
27923--- a/arch/x86/lib/getuser.S
27924+++ b/arch/x86/lib/getuser.S
27925@@ -33,17 +33,40 @@
27926 #include <asm/thread_info.h>
27927 #include <asm/asm.h>
27928 #include <asm/smap.h>
27929+#include <asm/segment.h>
27930+#include <asm/pgtable.h>
27931+#include <asm/alternative-asm.h>
27932+
27933+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
27934+#define __copyuser_seg gs;
27935+#else
27936+#define __copyuser_seg
27937+#endif
27938
27939 .text
27940 ENTRY(__get_user_1)
27941 CFI_STARTPROC
27942+
27943+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
27944 GET_THREAD_INFO(%_ASM_DX)
27945 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
27946 jae bad_get_user
27947 ASM_STAC
27948-1: movzbl (%_ASM_AX),%edx
27949+
27950+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27951+ mov pax_user_shadow_base,%_ASM_DX
27952+ cmp %_ASM_DX,%_ASM_AX
27953+ jae 1234f
27954+ add %_ASM_DX,%_ASM_AX
27955+1234:
27956+#endif
27957+
27958+#endif
27959+
27960+1: __copyuser_seg movzbl (%_ASM_AX),%edx
27961 xor %eax,%eax
27962 ASM_CLAC
27963+ pax_force_retaddr
27964 ret
27965 CFI_ENDPROC
27966 ENDPROC(__get_user_1)
27967@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
27968 ENTRY(__get_user_2)
27969 CFI_STARTPROC
27970 add $1,%_ASM_AX
27971+
27972+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
27973 jc bad_get_user
27974 GET_THREAD_INFO(%_ASM_DX)
27975 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
27976 jae bad_get_user
27977 ASM_STAC
27978-2: movzwl -1(%_ASM_AX),%edx
27979+
27980+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27981+ mov pax_user_shadow_base,%_ASM_DX
27982+ cmp %_ASM_DX,%_ASM_AX
27983+ jae 1234f
27984+ add %_ASM_DX,%_ASM_AX
27985+1234:
27986+#endif
27987+
27988+#endif
27989+
27990+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
27991 xor %eax,%eax
27992 ASM_CLAC
27993+ pax_force_retaddr
27994 ret
27995 CFI_ENDPROC
27996 ENDPROC(__get_user_2)
27997@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
27998 ENTRY(__get_user_4)
27999 CFI_STARTPROC
28000 add $3,%_ASM_AX
28001+
28002+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28003 jc bad_get_user
28004 GET_THREAD_INFO(%_ASM_DX)
28005 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28006 jae bad_get_user
28007 ASM_STAC
28008-3: movl -3(%_ASM_AX),%edx
28009+
28010+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28011+ mov pax_user_shadow_base,%_ASM_DX
28012+ cmp %_ASM_DX,%_ASM_AX
28013+ jae 1234f
28014+ add %_ASM_DX,%_ASM_AX
28015+1234:
28016+#endif
28017+
28018+#endif
28019+
28020+3: __copyuser_seg movl -3(%_ASM_AX),%edx
28021 xor %eax,%eax
28022 ASM_CLAC
28023+ pax_force_retaddr
28024 ret
28025 CFI_ENDPROC
28026 ENDPROC(__get_user_4)
28027@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
28028 GET_THREAD_INFO(%_ASM_DX)
28029 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28030 jae bad_get_user
28031+
28032+#ifdef CONFIG_PAX_MEMORY_UDEREF
28033+ mov pax_user_shadow_base,%_ASM_DX
28034+ cmp %_ASM_DX,%_ASM_AX
28035+ jae 1234f
28036+ add %_ASM_DX,%_ASM_AX
28037+1234:
28038+#endif
28039+
28040 ASM_STAC
28041 4: movq -7(%_ASM_AX),%rdx
28042 xor %eax,%eax
28043 ASM_CLAC
28044+ pax_force_retaddr
28045 ret
28046 #else
28047 add $7,%_ASM_AX
28048@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
28049 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28050 jae bad_get_user_8
28051 ASM_STAC
28052-4: movl -7(%_ASM_AX),%edx
28053-5: movl -3(%_ASM_AX),%ecx
28054+4: __copyuser_seg movl -7(%_ASM_AX),%edx
28055+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
28056 xor %eax,%eax
28057 ASM_CLAC
28058+ pax_force_retaddr
28059 ret
28060 #endif
28061 CFI_ENDPROC
28062@@ -113,6 +175,7 @@ bad_get_user:
28063 xor %edx,%edx
28064 mov $(-EFAULT),%_ASM_AX
28065 ASM_CLAC
28066+ pax_force_retaddr
28067 ret
28068 CFI_ENDPROC
28069 END(bad_get_user)
28070@@ -124,6 +187,7 @@ bad_get_user_8:
28071 xor %ecx,%ecx
28072 mov $(-EFAULT),%_ASM_AX
28073 ASM_CLAC
28074+ pax_force_retaddr
28075 ret
28076 CFI_ENDPROC
28077 END(bad_get_user_8)
28078diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
28079index 54fcffe..7be149e 100644
28080--- a/arch/x86/lib/insn.c
28081+++ b/arch/x86/lib/insn.c
28082@@ -20,8 +20,10 @@
28083
28084 #ifdef __KERNEL__
28085 #include <linux/string.h>
28086+#include <asm/pgtable_types.h>
28087 #else
28088 #include <string.h>
28089+#define ktla_ktva(addr) addr
28090 #endif
28091 #include <asm/inat.h>
28092 #include <asm/insn.h>
28093@@ -53,8 +55,8 @@
28094 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
28095 {
28096 memset(insn, 0, sizeof(*insn));
28097- insn->kaddr = kaddr;
28098- insn->next_byte = kaddr;
28099+ insn->kaddr = ktla_ktva(kaddr);
28100+ insn->next_byte = ktla_ktva(kaddr);
28101 insn->x86_64 = x86_64 ? 1 : 0;
28102 insn->opnd_bytes = 4;
28103 if (x86_64)
28104diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
28105index 05a95e7..326f2fa 100644
28106--- a/arch/x86/lib/iomap_copy_64.S
28107+++ b/arch/x86/lib/iomap_copy_64.S
28108@@ -17,6 +17,7 @@
28109
28110 #include <linux/linkage.h>
28111 #include <asm/dwarf2.h>
28112+#include <asm/alternative-asm.h>
28113
28114 /*
28115 * override generic version in lib/iomap_copy.c
28116@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
28117 CFI_STARTPROC
28118 movl %edx,%ecx
28119 rep movsd
28120+ pax_force_retaddr
28121 ret
28122 CFI_ENDPROC
28123 ENDPROC(__iowrite32_copy)
28124diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
28125index 56313a3..9b59269 100644
28126--- a/arch/x86/lib/memcpy_64.S
28127+++ b/arch/x86/lib/memcpy_64.S
28128@@ -24,7 +24,7 @@
28129 * This gets patched over the unrolled variant (below) via the
28130 * alternative instructions framework:
28131 */
28132- .section .altinstr_replacement, "ax", @progbits
28133+ .section .altinstr_replacement, "a", @progbits
28134 .Lmemcpy_c:
28135 movq %rdi, %rax
28136 movq %rdx, %rcx
28137@@ -33,6 +33,7 @@
28138 rep movsq
28139 movl %edx, %ecx
28140 rep movsb
28141+ pax_force_retaddr
28142 ret
28143 .Lmemcpy_e:
28144 .previous
28145@@ -44,11 +45,12 @@
28146 * This gets patched over the unrolled variant (below) via the
28147 * alternative instructions framework:
28148 */
28149- .section .altinstr_replacement, "ax", @progbits
28150+ .section .altinstr_replacement, "a", @progbits
28151 .Lmemcpy_c_e:
28152 movq %rdi, %rax
28153 movq %rdx, %rcx
28154 rep movsb
28155+ pax_force_retaddr
28156 ret
28157 .Lmemcpy_e_e:
28158 .previous
28159@@ -76,13 +78,13 @@ ENTRY(memcpy)
28160 */
28161 movq 0*8(%rsi), %r8
28162 movq 1*8(%rsi), %r9
28163- movq 2*8(%rsi), %r10
28164+ movq 2*8(%rsi), %rcx
28165 movq 3*8(%rsi), %r11
28166 leaq 4*8(%rsi), %rsi
28167
28168 movq %r8, 0*8(%rdi)
28169 movq %r9, 1*8(%rdi)
28170- movq %r10, 2*8(%rdi)
28171+ movq %rcx, 2*8(%rdi)
28172 movq %r11, 3*8(%rdi)
28173 leaq 4*8(%rdi), %rdi
28174 jae .Lcopy_forward_loop
28175@@ -105,12 +107,12 @@ ENTRY(memcpy)
28176 subq $0x20, %rdx
28177 movq -1*8(%rsi), %r8
28178 movq -2*8(%rsi), %r9
28179- movq -3*8(%rsi), %r10
28180+ movq -3*8(%rsi), %rcx
28181 movq -4*8(%rsi), %r11
28182 leaq -4*8(%rsi), %rsi
28183 movq %r8, -1*8(%rdi)
28184 movq %r9, -2*8(%rdi)
28185- movq %r10, -3*8(%rdi)
28186+ movq %rcx, -3*8(%rdi)
28187 movq %r11, -4*8(%rdi)
28188 leaq -4*8(%rdi), %rdi
28189 jae .Lcopy_backward_loop
28190@@ -130,12 +132,13 @@ ENTRY(memcpy)
28191 */
28192 movq 0*8(%rsi), %r8
28193 movq 1*8(%rsi), %r9
28194- movq -2*8(%rsi, %rdx), %r10
28195+ movq -2*8(%rsi, %rdx), %rcx
28196 movq -1*8(%rsi, %rdx), %r11
28197 movq %r8, 0*8(%rdi)
28198 movq %r9, 1*8(%rdi)
28199- movq %r10, -2*8(%rdi, %rdx)
28200+ movq %rcx, -2*8(%rdi, %rdx)
28201 movq %r11, -1*8(%rdi, %rdx)
28202+ pax_force_retaddr
28203 retq
28204 .p2align 4
28205 .Lless_16bytes:
28206@@ -148,6 +151,7 @@ ENTRY(memcpy)
28207 movq -1*8(%rsi, %rdx), %r9
28208 movq %r8, 0*8(%rdi)
28209 movq %r9, -1*8(%rdi, %rdx)
28210+ pax_force_retaddr
28211 retq
28212 .p2align 4
28213 .Lless_8bytes:
28214@@ -161,6 +165,7 @@ ENTRY(memcpy)
28215 movl -4(%rsi, %rdx), %r8d
28216 movl %ecx, (%rdi)
28217 movl %r8d, -4(%rdi, %rdx)
28218+ pax_force_retaddr
28219 retq
28220 .p2align 4
28221 .Lless_3bytes:
28222@@ -179,6 +184,7 @@ ENTRY(memcpy)
28223 movb %cl, (%rdi)
28224
28225 .Lend:
28226+ pax_force_retaddr
28227 retq
28228 CFI_ENDPROC
28229 ENDPROC(memcpy)
28230diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
28231index 65268a6..5aa7815 100644
28232--- a/arch/x86/lib/memmove_64.S
28233+++ b/arch/x86/lib/memmove_64.S
28234@@ -61,13 +61,13 @@ ENTRY(memmove)
28235 5:
28236 sub $0x20, %rdx
28237 movq 0*8(%rsi), %r11
28238- movq 1*8(%rsi), %r10
28239+ movq 1*8(%rsi), %rcx
28240 movq 2*8(%rsi), %r9
28241 movq 3*8(%rsi), %r8
28242 leaq 4*8(%rsi), %rsi
28243
28244 movq %r11, 0*8(%rdi)
28245- movq %r10, 1*8(%rdi)
28246+ movq %rcx, 1*8(%rdi)
28247 movq %r9, 2*8(%rdi)
28248 movq %r8, 3*8(%rdi)
28249 leaq 4*8(%rdi), %rdi
28250@@ -81,10 +81,10 @@ ENTRY(memmove)
28251 4:
28252 movq %rdx, %rcx
28253 movq -8(%rsi, %rdx), %r11
28254- lea -8(%rdi, %rdx), %r10
28255+ lea -8(%rdi, %rdx), %r9
28256 shrq $3, %rcx
28257 rep movsq
28258- movq %r11, (%r10)
28259+ movq %r11, (%r9)
28260 jmp 13f
28261 .Lmemmove_end_forward:
28262
28263@@ -95,14 +95,14 @@ ENTRY(memmove)
28264 7:
28265 movq %rdx, %rcx
28266 movq (%rsi), %r11
28267- movq %rdi, %r10
28268+ movq %rdi, %r9
28269 leaq -8(%rsi, %rdx), %rsi
28270 leaq -8(%rdi, %rdx), %rdi
28271 shrq $3, %rcx
28272 std
28273 rep movsq
28274 cld
28275- movq %r11, (%r10)
28276+ movq %r11, (%r9)
28277 jmp 13f
28278
28279 /*
28280@@ -127,13 +127,13 @@ ENTRY(memmove)
28281 8:
28282 subq $0x20, %rdx
28283 movq -1*8(%rsi), %r11
28284- movq -2*8(%rsi), %r10
28285+ movq -2*8(%rsi), %rcx
28286 movq -3*8(%rsi), %r9
28287 movq -4*8(%rsi), %r8
28288 leaq -4*8(%rsi), %rsi
28289
28290 movq %r11, -1*8(%rdi)
28291- movq %r10, -2*8(%rdi)
28292+ movq %rcx, -2*8(%rdi)
28293 movq %r9, -3*8(%rdi)
28294 movq %r8, -4*8(%rdi)
28295 leaq -4*8(%rdi), %rdi
28296@@ -151,11 +151,11 @@ ENTRY(memmove)
28297 * Move data from 16 bytes to 31 bytes.
28298 */
28299 movq 0*8(%rsi), %r11
28300- movq 1*8(%rsi), %r10
28301+ movq 1*8(%rsi), %rcx
28302 movq -2*8(%rsi, %rdx), %r9
28303 movq -1*8(%rsi, %rdx), %r8
28304 movq %r11, 0*8(%rdi)
28305- movq %r10, 1*8(%rdi)
28306+ movq %rcx, 1*8(%rdi)
28307 movq %r9, -2*8(%rdi, %rdx)
28308 movq %r8, -1*8(%rdi, %rdx)
28309 jmp 13f
28310@@ -167,9 +167,9 @@ ENTRY(memmove)
28311 * Move data from 8 bytes to 15 bytes.
28312 */
28313 movq 0*8(%rsi), %r11
28314- movq -1*8(%rsi, %rdx), %r10
28315+ movq -1*8(%rsi, %rdx), %r9
28316 movq %r11, 0*8(%rdi)
28317- movq %r10, -1*8(%rdi, %rdx)
28318+ movq %r9, -1*8(%rdi, %rdx)
28319 jmp 13f
28320 10:
28321 cmpq $4, %rdx
28322@@ -178,9 +178,9 @@ ENTRY(memmove)
28323 * Move data from 4 bytes to 7 bytes.
28324 */
28325 movl (%rsi), %r11d
28326- movl -4(%rsi, %rdx), %r10d
28327+ movl -4(%rsi, %rdx), %r9d
28328 movl %r11d, (%rdi)
28329- movl %r10d, -4(%rdi, %rdx)
28330+ movl %r9d, -4(%rdi, %rdx)
28331 jmp 13f
28332 11:
28333 cmp $2, %rdx
28334@@ -189,9 +189,9 @@ ENTRY(memmove)
28335 * Move data from 2 bytes to 3 bytes.
28336 */
28337 movw (%rsi), %r11w
28338- movw -2(%rsi, %rdx), %r10w
28339+ movw -2(%rsi, %rdx), %r9w
28340 movw %r11w, (%rdi)
28341- movw %r10w, -2(%rdi, %rdx)
28342+ movw %r9w, -2(%rdi, %rdx)
28343 jmp 13f
28344 12:
28345 cmp $1, %rdx
28346@@ -202,14 +202,16 @@ ENTRY(memmove)
28347 movb (%rsi), %r11b
28348 movb %r11b, (%rdi)
28349 13:
28350+ pax_force_retaddr
28351 retq
28352 CFI_ENDPROC
28353
28354- .section .altinstr_replacement,"ax"
28355+ .section .altinstr_replacement,"a"
28356 .Lmemmove_begin_forward_efs:
28357 /* Forward moving data. */
28358 movq %rdx, %rcx
28359 rep movsb
28360+ pax_force_retaddr
28361 retq
28362 .Lmemmove_end_forward_efs:
28363 .previous
28364diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
28365index 2dcb380..50a78bc 100644
28366--- a/arch/x86/lib/memset_64.S
28367+++ b/arch/x86/lib/memset_64.S
28368@@ -16,7 +16,7 @@
28369 *
28370 * rax original destination
28371 */
28372- .section .altinstr_replacement, "ax", @progbits
28373+ .section .altinstr_replacement, "a", @progbits
28374 .Lmemset_c:
28375 movq %rdi,%r9
28376 movq %rdx,%rcx
28377@@ -30,6 +30,7 @@
28378 movl %edx,%ecx
28379 rep stosb
28380 movq %r9,%rax
28381+ pax_force_retaddr
28382 ret
28383 .Lmemset_e:
28384 .previous
28385@@ -45,13 +46,14 @@
28386 *
28387 * rax original destination
28388 */
28389- .section .altinstr_replacement, "ax", @progbits
28390+ .section .altinstr_replacement, "a", @progbits
28391 .Lmemset_c_e:
28392 movq %rdi,%r9
28393 movb %sil,%al
28394 movq %rdx,%rcx
28395 rep stosb
28396 movq %r9,%rax
28397+ pax_force_retaddr
28398 ret
28399 .Lmemset_e_e:
28400 .previous
28401@@ -59,7 +61,7 @@
28402 ENTRY(memset)
28403 ENTRY(__memset)
28404 CFI_STARTPROC
28405- movq %rdi,%r10
28406+ movq %rdi,%r11
28407
28408 /* expand byte value */
28409 movzbl %sil,%ecx
28410@@ -117,7 +119,8 @@ ENTRY(__memset)
28411 jnz .Lloop_1
28412
28413 .Lende:
28414- movq %r10,%rax
28415+ movq %r11,%rax
28416+ pax_force_retaddr
28417 ret
28418
28419 CFI_RESTORE_STATE
28420diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
28421index c9f2d9b..e7fd2c0 100644
28422--- a/arch/x86/lib/mmx_32.c
28423+++ b/arch/x86/lib/mmx_32.c
28424@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28425 {
28426 void *p;
28427 int i;
28428+ unsigned long cr0;
28429
28430 if (unlikely(in_interrupt()))
28431 return __memcpy(to, from, len);
28432@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28433 kernel_fpu_begin();
28434
28435 __asm__ __volatile__ (
28436- "1: prefetch (%0)\n" /* This set is 28 bytes */
28437- " prefetch 64(%0)\n"
28438- " prefetch 128(%0)\n"
28439- " prefetch 192(%0)\n"
28440- " prefetch 256(%0)\n"
28441+ "1: prefetch (%1)\n" /* This set is 28 bytes */
28442+ " prefetch 64(%1)\n"
28443+ " prefetch 128(%1)\n"
28444+ " prefetch 192(%1)\n"
28445+ " prefetch 256(%1)\n"
28446 "2: \n"
28447 ".section .fixup, \"ax\"\n"
28448- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28449+ "3: \n"
28450+
28451+#ifdef CONFIG_PAX_KERNEXEC
28452+ " movl %%cr0, %0\n"
28453+ " movl %0, %%eax\n"
28454+ " andl $0xFFFEFFFF, %%eax\n"
28455+ " movl %%eax, %%cr0\n"
28456+#endif
28457+
28458+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28459+
28460+#ifdef CONFIG_PAX_KERNEXEC
28461+ " movl %0, %%cr0\n"
28462+#endif
28463+
28464 " jmp 2b\n"
28465 ".previous\n"
28466 _ASM_EXTABLE(1b, 3b)
28467- : : "r" (from));
28468+ : "=&r" (cr0) : "r" (from) : "ax");
28469
28470 for ( ; i > 5; i--) {
28471 __asm__ __volatile__ (
28472- "1: prefetch 320(%0)\n"
28473- "2: movq (%0), %%mm0\n"
28474- " movq 8(%0), %%mm1\n"
28475- " movq 16(%0), %%mm2\n"
28476- " movq 24(%0), %%mm3\n"
28477- " movq %%mm0, (%1)\n"
28478- " movq %%mm1, 8(%1)\n"
28479- " movq %%mm2, 16(%1)\n"
28480- " movq %%mm3, 24(%1)\n"
28481- " movq 32(%0), %%mm0\n"
28482- " movq 40(%0), %%mm1\n"
28483- " movq 48(%0), %%mm2\n"
28484- " movq 56(%0), %%mm3\n"
28485- " movq %%mm0, 32(%1)\n"
28486- " movq %%mm1, 40(%1)\n"
28487- " movq %%mm2, 48(%1)\n"
28488- " movq %%mm3, 56(%1)\n"
28489+ "1: prefetch 320(%1)\n"
28490+ "2: movq (%1), %%mm0\n"
28491+ " movq 8(%1), %%mm1\n"
28492+ " movq 16(%1), %%mm2\n"
28493+ " movq 24(%1), %%mm3\n"
28494+ " movq %%mm0, (%2)\n"
28495+ " movq %%mm1, 8(%2)\n"
28496+ " movq %%mm2, 16(%2)\n"
28497+ " movq %%mm3, 24(%2)\n"
28498+ " movq 32(%1), %%mm0\n"
28499+ " movq 40(%1), %%mm1\n"
28500+ " movq 48(%1), %%mm2\n"
28501+ " movq 56(%1), %%mm3\n"
28502+ " movq %%mm0, 32(%2)\n"
28503+ " movq %%mm1, 40(%2)\n"
28504+ " movq %%mm2, 48(%2)\n"
28505+ " movq %%mm3, 56(%2)\n"
28506 ".section .fixup, \"ax\"\n"
28507- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28508+ "3:\n"
28509+
28510+#ifdef CONFIG_PAX_KERNEXEC
28511+ " movl %%cr0, %0\n"
28512+ " movl %0, %%eax\n"
28513+ " andl $0xFFFEFFFF, %%eax\n"
28514+ " movl %%eax, %%cr0\n"
28515+#endif
28516+
28517+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28518+
28519+#ifdef CONFIG_PAX_KERNEXEC
28520+ " movl %0, %%cr0\n"
28521+#endif
28522+
28523 " jmp 2b\n"
28524 ".previous\n"
28525 _ASM_EXTABLE(1b, 3b)
28526- : : "r" (from), "r" (to) : "memory");
28527+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28528
28529 from += 64;
28530 to += 64;
28531@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
28532 static void fast_copy_page(void *to, void *from)
28533 {
28534 int i;
28535+ unsigned long cr0;
28536
28537 kernel_fpu_begin();
28538
28539@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
28540 * but that is for later. -AV
28541 */
28542 __asm__ __volatile__(
28543- "1: prefetch (%0)\n"
28544- " prefetch 64(%0)\n"
28545- " prefetch 128(%0)\n"
28546- " prefetch 192(%0)\n"
28547- " prefetch 256(%0)\n"
28548+ "1: prefetch (%1)\n"
28549+ " prefetch 64(%1)\n"
28550+ " prefetch 128(%1)\n"
28551+ " prefetch 192(%1)\n"
28552+ " prefetch 256(%1)\n"
28553 "2: \n"
28554 ".section .fixup, \"ax\"\n"
28555- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28556+ "3: \n"
28557+
28558+#ifdef CONFIG_PAX_KERNEXEC
28559+ " movl %%cr0, %0\n"
28560+ " movl %0, %%eax\n"
28561+ " andl $0xFFFEFFFF, %%eax\n"
28562+ " movl %%eax, %%cr0\n"
28563+#endif
28564+
28565+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28566+
28567+#ifdef CONFIG_PAX_KERNEXEC
28568+ " movl %0, %%cr0\n"
28569+#endif
28570+
28571 " jmp 2b\n"
28572 ".previous\n"
28573- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28574+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28575
28576 for (i = 0; i < (4096-320)/64; i++) {
28577 __asm__ __volatile__ (
28578- "1: prefetch 320(%0)\n"
28579- "2: movq (%0), %%mm0\n"
28580- " movntq %%mm0, (%1)\n"
28581- " movq 8(%0), %%mm1\n"
28582- " movntq %%mm1, 8(%1)\n"
28583- " movq 16(%0), %%mm2\n"
28584- " movntq %%mm2, 16(%1)\n"
28585- " movq 24(%0), %%mm3\n"
28586- " movntq %%mm3, 24(%1)\n"
28587- " movq 32(%0), %%mm4\n"
28588- " movntq %%mm4, 32(%1)\n"
28589- " movq 40(%0), %%mm5\n"
28590- " movntq %%mm5, 40(%1)\n"
28591- " movq 48(%0), %%mm6\n"
28592- " movntq %%mm6, 48(%1)\n"
28593- " movq 56(%0), %%mm7\n"
28594- " movntq %%mm7, 56(%1)\n"
28595+ "1: prefetch 320(%1)\n"
28596+ "2: movq (%1), %%mm0\n"
28597+ " movntq %%mm0, (%2)\n"
28598+ " movq 8(%1), %%mm1\n"
28599+ " movntq %%mm1, 8(%2)\n"
28600+ " movq 16(%1), %%mm2\n"
28601+ " movntq %%mm2, 16(%2)\n"
28602+ " movq 24(%1), %%mm3\n"
28603+ " movntq %%mm3, 24(%2)\n"
28604+ " movq 32(%1), %%mm4\n"
28605+ " movntq %%mm4, 32(%2)\n"
28606+ " movq 40(%1), %%mm5\n"
28607+ " movntq %%mm5, 40(%2)\n"
28608+ " movq 48(%1), %%mm6\n"
28609+ " movntq %%mm6, 48(%2)\n"
28610+ " movq 56(%1), %%mm7\n"
28611+ " movntq %%mm7, 56(%2)\n"
28612 ".section .fixup, \"ax\"\n"
28613- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28614+ "3:\n"
28615+
28616+#ifdef CONFIG_PAX_KERNEXEC
28617+ " movl %%cr0, %0\n"
28618+ " movl %0, %%eax\n"
28619+ " andl $0xFFFEFFFF, %%eax\n"
28620+ " movl %%eax, %%cr0\n"
28621+#endif
28622+
28623+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28624+
28625+#ifdef CONFIG_PAX_KERNEXEC
28626+ " movl %0, %%cr0\n"
28627+#endif
28628+
28629 " jmp 2b\n"
28630 ".previous\n"
28631- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
28632+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28633
28634 from += 64;
28635 to += 64;
28636@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
28637 static void fast_copy_page(void *to, void *from)
28638 {
28639 int i;
28640+ unsigned long cr0;
28641
28642 kernel_fpu_begin();
28643
28644 __asm__ __volatile__ (
28645- "1: prefetch (%0)\n"
28646- " prefetch 64(%0)\n"
28647- " prefetch 128(%0)\n"
28648- " prefetch 192(%0)\n"
28649- " prefetch 256(%0)\n"
28650+ "1: prefetch (%1)\n"
28651+ " prefetch 64(%1)\n"
28652+ " prefetch 128(%1)\n"
28653+ " prefetch 192(%1)\n"
28654+ " prefetch 256(%1)\n"
28655 "2: \n"
28656 ".section .fixup, \"ax\"\n"
28657- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28658+ "3: \n"
28659+
28660+#ifdef CONFIG_PAX_KERNEXEC
28661+ " movl %%cr0, %0\n"
28662+ " movl %0, %%eax\n"
28663+ " andl $0xFFFEFFFF, %%eax\n"
28664+ " movl %%eax, %%cr0\n"
28665+#endif
28666+
28667+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28668+
28669+#ifdef CONFIG_PAX_KERNEXEC
28670+ " movl %0, %%cr0\n"
28671+#endif
28672+
28673 " jmp 2b\n"
28674 ".previous\n"
28675- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28676+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28677
28678 for (i = 0; i < 4096/64; i++) {
28679 __asm__ __volatile__ (
28680- "1: prefetch 320(%0)\n"
28681- "2: movq (%0), %%mm0\n"
28682- " movq 8(%0), %%mm1\n"
28683- " movq 16(%0), %%mm2\n"
28684- " movq 24(%0), %%mm3\n"
28685- " movq %%mm0, (%1)\n"
28686- " movq %%mm1, 8(%1)\n"
28687- " movq %%mm2, 16(%1)\n"
28688- " movq %%mm3, 24(%1)\n"
28689- " movq 32(%0), %%mm0\n"
28690- " movq 40(%0), %%mm1\n"
28691- " movq 48(%0), %%mm2\n"
28692- " movq 56(%0), %%mm3\n"
28693- " movq %%mm0, 32(%1)\n"
28694- " movq %%mm1, 40(%1)\n"
28695- " movq %%mm2, 48(%1)\n"
28696- " movq %%mm3, 56(%1)\n"
28697+ "1: prefetch 320(%1)\n"
28698+ "2: movq (%1), %%mm0\n"
28699+ " movq 8(%1), %%mm1\n"
28700+ " movq 16(%1), %%mm2\n"
28701+ " movq 24(%1), %%mm3\n"
28702+ " movq %%mm0, (%2)\n"
28703+ " movq %%mm1, 8(%2)\n"
28704+ " movq %%mm2, 16(%2)\n"
28705+ " movq %%mm3, 24(%2)\n"
28706+ " movq 32(%1), %%mm0\n"
28707+ " movq 40(%1), %%mm1\n"
28708+ " movq 48(%1), %%mm2\n"
28709+ " movq 56(%1), %%mm3\n"
28710+ " movq %%mm0, 32(%2)\n"
28711+ " movq %%mm1, 40(%2)\n"
28712+ " movq %%mm2, 48(%2)\n"
28713+ " movq %%mm3, 56(%2)\n"
28714 ".section .fixup, \"ax\"\n"
28715- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28716+ "3:\n"
28717+
28718+#ifdef CONFIG_PAX_KERNEXEC
28719+ " movl %%cr0, %0\n"
28720+ " movl %0, %%eax\n"
28721+ " andl $0xFFFEFFFF, %%eax\n"
28722+ " movl %%eax, %%cr0\n"
28723+#endif
28724+
28725+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28726+
28727+#ifdef CONFIG_PAX_KERNEXEC
28728+ " movl %0, %%cr0\n"
28729+#endif
28730+
28731 " jmp 2b\n"
28732 ".previous\n"
28733 _ASM_EXTABLE(1b, 3b)
28734- : : "r" (from), "r" (to) : "memory");
28735+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28736
28737 from += 64;
28738 to += 64;
28739diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
28740index f6d13ee..aca5f0b 100644
28741--- a/arch/x86/lib/msr-reg.S
28742+++ b/arch/x86/lib/msr-reg.S
28743@@ -3,6 +3,7 @@
28744 #include <asm/dwarf2.h>
28745 #include <asm/asm.h>
28746 #include <asm/msr.h>
28747+#include <asm/alternative-asm.h>
28748
28749 #ifdef CONFIG_X86_64
28750 /*
28751@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
28752 CFI_STARTPROC
28753 pushq_cfi %rbx
28754 pushq_cfi %rbp
28755- movq %rdi, %r10 /* Save pointer */
28756+ movq %rdi, %r9 /* Save pointer */
28757 xorl %r11d, %r11d /* Return value */
28758 movl (%rdi), %eax
28759 movl 4(%rdi), %ecx
28760@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
28761 movl 28(%rdi), %edi
28762 CFI_REMEMBER_STATE
28763 1: \op
28764-2: movl %eax, (%r10)
28765+2: movl %eax, (%r9)
28766 movl %r11d, %eax /* Return value */
28767- movl %ecx, 4(%r10)
28768- movl %edx, 8(%r10)
28769- movl %ebx, 12(%r10)
28770- movl %ebp, 20(%r10)
28771- movl %esi, 24(%r10)
28772- movl %edi, 28(%r10)
28773+ movl %ecx, 4(%r9)
28774+ movl %edx, 8(%r9)
28775+ movl %ebx, 12(%r9)
28776+ movl %ebp, 20(%r9)
28777+ movl %esi, 24(%r9)
28778+ movl %edi, 28(%r9)
28779 popq_cfi %rbp
28780 popq_cfi %rbx
28781+ pax_force_retaddr
28782 ret
28783 3:
28784 CFI_RESTORE_STATE
28785diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
28786index fc6ba17..d4d989d 100644
28787--- a/arch/x86/lib/putuser.S
28788+++ b/arch/x86/lib/putuser.S
28789@@ -16,7 +16,9 @@
28790 #include <asm/errno.h>
28791 #include <asm/asm.h>
28792 #include <asm/smap.h>
28793-
28794+#include <asm/segment.h>
28795+#include <asm/pgtable.h>
28796+#include <asm/alternative-asm.h>
28797
28798 /*
28799 * __put_user_X
28800@@ -30,57 +32,125 @@
28801 * as they get called from within inline assembly.
28802 */
28803
28804-#define ENTER CFI_STARTPROC ; \
28805- GET_THREAD_INFO(%_ASM_BX)
28806-#define EXIT ASM_CLAC ; \
28807- ret ; \
28808+#define ENTER CFI_STARTPROC
28809+#define EXIT ASM_CLAC ; \
28810+ pax_force_retaddr ; \
28811+ ret ; \
28812 CFI_ENDPROC
28813
28814+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28815+#define _DEST %_ASM_CX,%_ASM_BX
28816+#else
28817+#define _DEST %_ASM_CX
28818+#endif
28819+
28820+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28821+#define __copyuser_seg gs;
28822+#else
28823+#define __copyuser_seg
28824+#endif
28825+
28826 .text
28827 ENTRY(__put_user_1)
28828 ENTER
28829+
28830+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28831+ GET_THREAD_INFO(%_ASM_BX)
28832 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
28833 jae bad_put_user
28834 ASM_STAC
28835-1: movb %al,(%_ASM_CX)
28836+
28837+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28838+ mov pax_user_shadow_base,%_ASM_BX
28839+ cmp %_ASM_BX,%_ASM_CX
28840+ jb 1234f
28841+ xor %ebx,%ebx
28842+1234:
28843+#endif
28844+
28845+#endif
28846+
28847+1: __copyuser_seg movb %al,(_DEST)
28848 xor %eax,%eax
28849 EXIT
28850 ENDPROC(__put_user_1)
28851
28852 ENTRY(__put_user_2)
28853 ENTER
28854+
28855+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28856+ GET_THREAD_INFO(%_ASM_BX)
28857 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28858 sub $1,%_ASM_BX
28859 cmp %_ASM_BX,%_ASM_CX
28860 jae bad_put_user
28861 ASM_STAC
28862-2: movw %ax,(%_ASM_CX)
28863+
28864+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28865+ mov pax_user_shadow_base,%_ASM_BX
28866+ cmp %_ASM_BX,%_ASM_CX
28867+ jb 1234f
28868+ xor %ebx,%ebx
28869+1234:
28870+#endif
28871+
28872+#endif
28873+
28874+2: __copyuser_seg movw %ax,(_DEST)
28875 xor %eax,%eax
28876 EXIT
28877 ENDPROC(__put_user_2)
28878
28879 ENTRY(__put_user_4)
28880 ENTER
28881+
28882+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28883+ GET_THREAD_INFO(%_ASM_BX)
28884 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28885 sub $3,%_ASM_BX
28886 cmp %_ASM_BX,%_ASM_CX
28887 jae bad_put_user
28888 ASM_STAC
28889-3: movl %eax,(%_ASM_CX)
28890+
28891+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28892+ mov pax_user_shadow_base,%_ASM_BX
28893+ cmp %_ASM_BX,%_ASM_CX
28894+ jb 1234f
28895+ xor %ebx,%ebx
28896+1234:
28897+#endif
28898+
28899+#endif
28900+
28901+3: __copyuser_seg movl %eax,(_DEST)
28902 xor %eax,%eax
28903 EXIT
28904 ENDPROC(__put_user_4)
28905
28906 ENTRY(__put_user_8)
28907 ENTER
28908+
28909+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28910+ GET_THREAD_INFO(%_ASM_BX)
28911 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28912 sub $7,%_ASM_BX
28913 cmp %_ASM_BX,%_ASM_CX
28914 jae bad_put_user
28915 ASM_STAC
28916-4: mov %_ASM_AX,(%_ASM_CX)
28917+
28918+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28919+ mov pax_user_shadow_base,%_ASM_BX
28920+ cmp %_ASM_BX,%_ASM_CX
28921+ jb 1234f
28922+ xor %ebx,%ebx
28923+1234:
28924+#endif
28925+
28926+#endif
28927+
28928+4: __copyuser_seg mov %_ASM_AX,(_DEST)
28929 #ifdef CONFIG_X86_32
28930-5: movl %edx,4(%_ASM_CX)
28931+5: __copyuser_seg movl %edx,4(_DEST)
28932 #endif
28933 xor %eax,%eax
28934 EXIT
28935diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
28936index 1cad221..de671ee 100644
28937--- a/arch/x86/lib/rwlock.S
28938+++ b/arch/x86/lib/rwlock.S
28939@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
28940 FRAME
28941 0: LOCK_PREFIX
28942 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
28943+
28944+#ifdef CONFIG_PAX_REFCOUNT
28945+ jno 1234f
28946+ LOCK_PREFIX
28947+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
28948+ int $4
28949+1234:
28950+ _ASM_EXTABLE(1234b, 1234b)
28951+#endif
28952+
28953 1: rep; nop
28954 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
28955 jne 1b
28956 LOCK_PREFIX
28957 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
28958+
28959+#ifdef CONFIG_PAX_REFCOUNT
28960+ jno 1234f
28961+ LOCK_PREFIX
28962+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
28963+ int $4
28964+1234:
28965+ _ASM_EXTABLE(1234b, 1234b)
28966+#endif
28967+
28968 jnz 0b
28969 ENDFRAME
28970+ pax_force_retaddr
28971 ret
28972 CFI_ENDPROC
28973 END(__write_lock_failed)
28974@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
28975 FRAME
28976 0: LOCK_PREFIX
28977 READ_LOCK_SIZE(inc) (%__lock_ptr)
28978+
28979+#ifdef CONFIG_PAX_REFCOUNT
28980+ jno 1234f
28981+ LOCK_PREFIX
28982+ READ_LOCK_SIZE(dec) (%__lock_ptr)
28983+ int $4
28984+1234:
28985+ _ASM_EXTABLE(1234b, 1234b)
28986+#endif
28987+
28988 1: rep; nop
28989 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
28990 js 1b
28991 LOCK_PREFIX
28992 READ_LOCK_SIZE(dec) (%__lock_ptr)
28993+
28994+#ifdef CONFIG_PAX_REFCOUNT
28995+ jno 1234f
28996+ LOCK_PREFIX
28997+ READ_LOCK_SIZE(inc) (%__lock_ptr)
28998+ int $4
28999+1234:
29000+ _ASM_EXTABLE(1234b, 1234b)
29001+#endif
29002+
29003 js 0b
29004 ENDFRAME
29005+ pax_force_retaddr
29006 ret
29007 CFI_ENDPROC
29008 END(__read_lock_failed)
29009diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
29010index 5dff5f0..cadebf4 100644
29011--- a/arch/x86/lib/rwsem.S
29012+++ b/arch/x86/lib/rwsem.S
29013@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
29014 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29015 CFI_RESTORE __ASM_REG(dx)
29016 restore_common_regs
29017+ pax_force_retaddr
29018 ret
29019 CFI_ENDPROC
29020 ENDPROC(call_rwsem_down_read_failed)
29021@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
29022 movq %rax,%rdi
29023 call rwsem_down_write_failed
29024 restore_common_regs
29025+ pax_force_retaddr
29026 ret
29027 CFI_ENDPROC
29028 ENDPROC(call_rwsem_down_write_failed)
29029@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
29030 movq %rax,%rdi
29031 call rwsem_wake
29032 restore_common_regs
29033-1: ret
29034+1: pax_force_retaddr
29035+ ret
29036 CFI_ENDPROC
29037 ENDPROC(call_rwsem_wake)
29038
29039@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
29040 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29041 CFI_RESTORE __ASM_REG(dx)
29042 restore_common_regs
29043+ pax_force_retaddr
29044 ret
29045 CFI_ENDPROC
29046 ENDPROC(call_rwsem_downgrade_wake)
29047diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
29048index a63efd6..ccecad8 100644
29049--- a/arch/x86/lib/thunk_64.S
29050+++ b/arch/x86/lib/thunk_64.S
29051@@ -8,6 +8,7 @@
29052 #include <linux/linkage.h>
29053 #include <asm/dwarf2.h>
29054 #include <asm/calling.h>
29055+#include <asm/alternative-asm.h>
29056
29057 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
29058 .macro THUNK name, func, put_ret_addr_in_rdi=0
29059@@ -41,5 +42,6 @@
29060 SAVE_ARGS
29061 restore:
29062 RESTORE_ARGS
29063+ pax_force_retaddr
29064 ret
29065 CFI_ENDPROC
29066diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
29067index 3eb18ac..6890bc3 100644
29068--- a/arch/x86/lib/usercopy_32.c
29069+++ b/arch/x86/lib/usercopy_32.c
29070@@ -42,11 +42,13 @@ do { \
29071 int __d0; \
29072 might_fault(); \
29073 __asm__ __volatile__( \
29074+ __COPYUSER_SET_ES \
29075 ASM_STAC "\n" \
29076 "0: rep; stosl\n" \
29077 " movl %2,%0\n" \
29078 "1: rep; stosb\n" \
29079 "2: " ASM_CLAC "\n" \
29080+ __COPYUSER_RESTORE_ES \
29081 ".section .fixup,\"ax\"\n" \
29082 "3: lea 0(%2,%0,4),%0\n" \
29083 " jmp 2b\n" \
29084@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
29085
29086 #ifdef CONFIG_X86_INTEL_USERCOPY
29087 static unsigned long
29088-__copy_user_intel(void __user *to, const void *from, unsigned long size)
29089+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
29090 {
29091 int d0, d1;
29092 __asm__ __volatile__(
29093@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29094 " .align 2,0x90\n"
29095 "3: movl 0(%4), %%eax\n"
29096 "4: movl 4(%4), %%edx\n"
29097- "5: movl %%eax, 0(%3)\n"
29098- "6: movl %%edx, 4(%3)\n"
29099+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
29100+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
29101 "7: movl 8(%4), %%eax\n"
29102 "8: movl 12(%4),%%edx\n"
29103- "9: movl %%eax, 8(%3)\n"
29104- "10: movl %%edx, 12(%3)\n"
29105+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
29106+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
29107 "11: movl 16(%4), %%eax\n"
29108 "12: movl 20(%4), %%edx\n"
29109- "13: movl %%eax, 16(%3)\n"
29110- "14: movl %%edx, 20(%3)\n"
29111+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
29112+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
29113 "15: movl 24(%4), %%eax\n"
29114 "16: movl 28(%4), %%edx\n"
29115- "17: movl %%eax, 24(%3)\n"
29116- "18: movl %%edx, 28(%3)\n"
29117+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
29118+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
29119 "19: movl 32(%4), %%eax\n"
29120 "20: movl 36(%4), %%edx\n"
29121- "21: movl %%eax, 32(%3)\n"
29122- "22: movl %%edx, 36(%3)\n"
29123+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
29124+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
29125 "23: movl 40(%4), %%eax\n"
29126 "24: movl 44(%4), %%edx\n"
29127- "25: movl %%eax, 40(%3)\n"
29128- "26: movl %%edx, 44(%3)\n"
29129+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
29130+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
29131 "27: movl 48(%4), %%eax\n"
29132 "28: movl 52(%4), %%edx\n"
29133- "29: movl %%eax, 48(%3)\n"
29134- "30: movl %%edx, 52(%3)\n"
29135+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
29136+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
29137 "31: movl 56(%4), %%eax\n"
29138 "32: movl 60(%4), %%edx\n"
29139- "33: movl %%eax, 56(%3)\n"
29140- "34: movl %%edx, 60(%3)\n"
29141+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
29142+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
29143 " addl $-64, %0\n"
29144 " addl $64, %4\n"
29145 " addl $64, %3\n"
29146@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29147 " shrl $2, %0\n"
29148 " andl $3, %%eax\n"
29149 " cld\n"
29150+ __COPYUSER_SET_ES
29151 "99: rep; movsl\n"
29152 "36: movl %%eax, %0\n"
29153 "37: rep; movsb\n"
29154 "100:\n"
29155+ __COPYUSER_RESTORE_ES
29156 ".section .fixup,\"ax\"\n"
29157 "101: lea 0(%%eax,%0,4),%0\n"
29158 " jmp 100b\n"
29159@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29160 }
29161
29162 static unsigned long
29163+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
29164+{
29165+ int d0, d1;
29166+ __asm__ __volatile__(
29167+ " .align 2,0x90\n"
29168+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
29169+ " cmpl $67, %0\n"
29170+ " jbe 3f\n"
29171+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
29172+ " .align 2,0x90\n"
29173+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
29174+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
29175+ "5: movl %%eax, 0(%3)\n"
29176+ "6: movl %%edx, 4(%3)\n"
29177+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
29178+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
29179+ "9: movl %%eax, 8(%3)\n"
29180+ "10: movl %%edx, 12(%3)\n"
29181+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
29182+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
29183+ "13: movl %%eax, 16(%3)\n"
29184+ "14: movl %%edx, 20(%3)\n"
29185+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
29186+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
29187+ "17: movl %%eax, 24(%3)\n"
29188+ "18: movl %%edx, 28(%3)\n"
29189+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
29190+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
29191+ "21: movl %%eax, 32(%3)\n"
29192+ "22: movl %%edx, 36(%3)\n"
29193+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
29194+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
29195+ "25: movl %%eax, 40(%3)\n"
29196+ "26: movl %%edx, 44(%3)\n"
29197+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
29198+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
29199+ "29: movl %%eax, 48(%3)\n"
29200+ "30: movl %%edx, 52(%3)\n"
29201+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
29202+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
29203+ "33: movl %%eax, 56(%3)\n"
29204+ "34: movl %%edx, 60(%3)\n"
29205+ " addl $-64, %0\n"
29206+ " addl $64, %4\n"
29207+ " addl $64, %3\n"
29208+ " cmpl $63, %0\n"
29209+ " ja 1b\n"
29210+ "35: movl %0, %%eax\n"
29211+ " shrl $2, %0\n"
29212+ " andl $3, %%eax\n"
29213+ " cld\n"
29214+ "99: rep; "__copyuser_seg" movsl\n"
29215+ "36: movl %%eax, %0\n"
29216+ "37: rep; "__copyuser_seg" movsb\n"
29217+ "100:\n"
29218+ ".section .fixup,\"ax\"\n"
29219+ "101: lea 0(%%eax,%0,4),%0\n"
29220+ " jmp 100b\n"
29221+ ".previous\n"
29222+ _ASM_EXTABLE(1b,100b)
29223+ _ASM_EXTABLE(2b,100b)
29224+ _ASM_EXTABLE(3b,100b)
29225+ _ASM_EXTABLE(4b,100b)
29226+ _ASM_EXTABLE(5b,100b)
29227+ _ASM_EXTABLE(6b,100b)
29228+ _ASM_EXTABLE(7b,100b)
29229+ _ASM_EXTABLE(8b,100b)
29230+ _ASM_EXTABLE(9b,100b)
29231+ _ASM_EXTABLE(10b,100b)
29232+ _ASM_EXTABLE(11b,100b)
29233+ _ASM_EXTABLE(12b,100b)
29234+ _ASM_EXTABLE(13b,100b)
29235+ _ASM_EXTABLE(14b,100b)
29236+ _ASM_EXTABLE(15b,100b)
29237+ _ASM_EXTABLE(16b,100b)
29238+ _ASM_EXTABLE(17b,100b)
29239+ _ASM_EXTABLE(18b,100b)
29240+ _ASM_EXTABLE(19b,100b)
29241+ _ASM_EXTABLE(20b,100b)
29242+ _ASM_EXTABLE(21b,100b)
29243+ _ASM_EXTABLE(22b,100b)
29244+ _ASM_EXTABLE(23b,100b)
29245+ _ASM_EXTABLE(24b,100b)
29246+ _ASM_EXTABLE(25b,100b)
29247+ _ASM_EXTABLE(26b,100b)
29248+ _ASM_EXTABLE(27b,100b)
29249+ _ASM_EXTABLE(28b,100b)
29250+ _ASM_EXTABLE(29b,100b)
29251+ _ASM_EXTABLE(30b,100b)
29252+ _ASM_EXTABLE(31b,100b)
29253+ _ASM_EXTABLE(32b,100b)
29254+ _ASM_EXTABLE(33b,100b)
29255+ _ASM_EXTABLE(34b,100b)
29256+ _ASM_EXTABLE(35b,100b)
29257+ _ASM_EXTABLE(36b,100b)
29258+ _ASM_EXTABLE(37b,100b)
29259+ _ASM_EXTABLE(99b,101b)
29260+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
29261+ : "1"(to), "2"(from), "0"(size)
29262+ : "eax", "edx", "memory");
29263+ return size;
29264+}
29265+
29266+static unsigned long __size_overflow(3)
29267 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29268 {
29269 int d0, d1;
29270 __asm__ __volatile__(
29271 " .align 2,0x90\n"
29272- "0: movl 32(%4), %%eax\n"
29273+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29274 " cmpl $67, %0\n"
29275 " jbe 2f\n"
29276- "1: movl 64(%4), %%eax\n"
29277+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29278 " .align 2,0x90\n"
29279- "2: movl 0(%4), %%eax\n"
29280- "21: movl 4(%4), %%edx\n"
29281+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29282+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29283 " movl %%eax, 0(%3)\n"
29284 " movl %%edx, 4(%3)\n"
29285- "3: movl 8(%4), %%eax\n"
29286- "31: movl 12(%4),%%edx\n"
29287+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29288+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29289 " movl %%eax, 8(%3)\n"
29290 " movl %%edx, 12(%3)\n"
29291- "4: movl 16(%4), %%eax\n"
29292- "41: movl 20(%4), %%edx\n"
29293+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29294+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29295 " movl %%eax, 16(%3)\n"
29296 " movl %%edx, 20(%3)\n"
29297- "10: movl 24(%4), %%eax\n"
29298- "51: movl 28(%4), %%edx\n"
29299+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29300+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29301 " movl %%eax, 24(%3)\n"
29302 " movl %%edx, 28(%3)\n"
29303- "11: movl 32(%4), %%eax\n"
29304- "61: movl 36(%4), %%edx\n"
29305+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29306+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29307 " movl %%eax, 32(%3)\n"
29308 " movl %%edx, 36(%3)\n"
29309- "12: movl 40(%4), %%eax\n"
29310- "71: movl 44(%4), %%edx\n"
29311+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29312+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29313 " movl %%eax, 40(%3)\n"
29314 " movl %%edx, 44(%3)\n"
29315- "13: movl 48(%4), %%eax\n"
29316- "81: movl 52(%4), %%edx\n"
29317+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29318+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29319 " movl %%eax, 48(%3)\n"
29320 " movl %%edx, 52(%3)\n"
29321- "14: movl 56(%4), %%eax\n"
29322- "91: movl 60(%4), %%edx\n"
29323+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29324+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29325 " movl %%eax, 56(%3)\n"
29326 " movl %%edx, 60(%3)\n"
29327 " addl $-64, %0\n"
29328@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29329 " shrl $2, %0\n"
29330 " andl $3, %%eax\n"
29331 " cld\n"
29332- "6: rep; movsl\n"
29333+ "6: rep; "__copyuser_seg" movsl\n"
29334 " movl %%eax,%0\n"
29335- "7: rep; movsb\n"
29336+ "7: rep; "__copyuser_seg" movsb\n"
29337 "8:\n"
29338 ".section .fixup,\"ax\"\n"
29339 "9: lea 0(%%eax,%0,4),%0\n"
29340@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29341 * hyoshiok@miraclelinux.com
29342 */
29343
29344-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29345+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
29346 const void __user *from, unsigned long size)
29347 {
29348 int d0, d1;
29349
29350 __asm__ __volatile__(
29351 " .align 2,0x90\n"
29352- "0: movl 32(%4), %%eax\n"
29353+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29354 " cmpl $67, %0\n"
29355 " jbe 2f\n"
29356- "1: movl 64(%4), %%eax\n"
29357+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29358 " .align 2,0x90\n"
29359- "2: movl 0(%4), %%eax\n"
29360- "21: movl 4(%4), %%edx\n"
29361+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29362+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29363 " movnti %%eax, 0(%3)\n"
29364 " movnti %%edx, 4(%3)\n"
29365- "3: movl 8(%4), %%eax\n"
29366- "31: movl 12(%4),%%edx\n"
29367+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29368+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29369 " movnti %%eax, 8(%3)\n"
29370 " movnti %%edx, 12(%3)\n"
29371- "4: movl 16(%4), %%eax\n"
29372- "41: movl 20(%4), %%edx\n"
29373+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29374+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29375 " movnti %%eax, 16(%3)\n"
29376 " movnti %%edx, 20(%3)\n"
29377- "10: movl 24(%4), %%eax\n"
29378- "51: movl 28(%4), %%edx\n"
29379+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29380+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29381 " movnti %%eax, 24(%3)\n"
29382 " movnti %%edx, 28(%3)\n"
29383- "11: movl 32(%4), %%eax\n"
29384- "61: movl 36(%4), %%edx\n"
29385+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29386+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29387 " movnti %%eax, 32(%3)\n"
29388 " movnti %%edx, 36(%3)\n"
29389- "12: movl 40(%4), %%eax\n"
29390- "71: movl 44(%4), %%edx\n"
29391+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29392+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29393 " movnti %%eax, 40(%3)\n"
29394 " movnti %%edx, 44(%3)\n"
29395- "13: movl 48(%4), %%eax\n"
29396- "81: movl 52(%4), %%edx\n"
29397+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29398+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29399 " movnti %%eax, 48(%3)\n"
29400 " movnti %%edx, 52(%3)\n"
29401- "14: movl 56(%4), %%eax\n"
29402- "91: movl 60(%4), %%edx\n"
29403+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29404+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29405 " movnti %%eax, 56(%3)\n"
29406 " movnti %%edx, 60(%3)\n"
29407 " addl $-64, %0\n"
29408@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29409 " shrl $2, %0\n"
29410 " andl $3, %%eax\n"
29411 " cld\n"
29412- "6: rep; movsl\n"
29413+ "6: rep; "__copyuser_seg" movsl\n"
29414 " movl %%eax,%0\n"
29415- "7: rep; movsb\n"
29416+ "7: rep; "__copyuser_seg" movsb\n"
29417 "8:\n"
29418 ".section .fixup,\"ax\"\n"
29419 "9: lea 0(%%eax,%0,4),%0\n"
29420@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29421 return size;
29422 }
29423
29424-static unsigned long __copy_user_intel_nocache(void *to,
29425+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
29426 const void __user *from, unsigned long size)
29427 {
29428 int d0, d1;
29429
29430 __asm__ __volatile__(
29431 " .align 2,0x90\n"
29432- "0: movl 32(%4), %%eax\n"
29433+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29434 " cmpl $67, %0\n"
29435 " jbe 2f\n"
29436- "1: movl 64(%4), %%eax\n"
29437+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29438 " .align 2,0x90\n"
29439- "2: movl 0(%4), %%eax\n"
29440- "21: movl 4(%4), %%edx\n"
29441+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29442+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29443 " movnti %%eax, 0(%3)\n"
29444 " movnti %%edx, 4(%3)\n"
29445- "3: movl 8(%4), %%eax\n"
29446- "31: movl 12(%4),%%edx\n"
29447+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29448+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29449 " movnti %%eax, 8(%3)\n"
29450 " movnti %%edx, 12(%3)\n"
29451- "4: movl 16(%4), %%eax\n"
29452- "41: movl 20(%4), %%edx\n"
29453+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29454+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29455 " movnti %%eax, 16(%3)\n"
29456 " movnti %%edx, 20(%3)\n"
29457- "10: movl 24(%4), %%eax\n"
29458- "51: movl 28(%4), %%edx\n"
29459+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29460+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29461 " movnti %%eax, 24(%3)\n"
29462 " movnti %%edx, 28(%3)\n"
29463- "11: movl 32(%4), %%eax\n"
29464- "61: movl 36(%4), %%edx\n"
29465+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29466+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29467 " movnti %%eax, 32(%3)\n"
29468 " movnti %%edx, 36(%3)\n"
29469- "12: movl 40(%4), %%eax\n"
29470- "71: movl 44(%4), %%edx\n"
29471+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29472+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29473 " movnti %%eax, 40(%3)\n"
29474 " movnti %%edx, 44(%3)\n"
29475- "13: movl 48(%4), %%eax\n"
29476- "81: movl 52(%4), %%edx\n"
29477+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29478+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29479 " movnti %%eax, 48(%3)\n"
29480 " movnti %%edx, 52(%3)\n"
29481- "14: movl 56(%4), %%eax\n"
29482- "91: movl 60(%4), %%edx\n"
29483+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29484+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29485 " movnti %%eax, 56(%3)\n"
29486 " movnti %%edx, 60(%3)\n"
29487 " addl $-64, %0\n"
29488@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
29489 " shrl $2, %0\n"
29490 " andl $3, %%eax\n"
29491 " cld\n"
29492- "6: rep; movsl\n"
29493+ "6: rep; "__copyuser_seg" movsl\n"
29494 " movl %%eax,%0\n"
29495- "7: rep; movsb\n"
29496+ "7: rep; "__copyuser_seg" movsb\n"
29497 "8:\n"
29498 ".section .fixup,\"ax\"\n"
29499 "9: lea 0(%%eax,%0,4),%0\n"
29500@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
29501 */
29502 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
29503 unsigned long size);
29504-unsigned long __copy_user_intel(void __user *to, const void *from,
29505+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
29506+ unsigned long size);
29507+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
29508 unsigned long size);
29509 unsigned long __copy_user_zeroing_intel_nocache(void *to,
29510 const void __user *from, unsigned long size);
29511 #endif /* CONFIG_X86_INTEL_USERCOPY */
29512
29513 /* Generic arbitrary sized copy. */
29514-#define __copy_user(to, from, size) \
29515+#define __copy_user(to, from, size, prefix, set, restore) \
29516 do { \
29517 int __d0, __d1, __d2; \
29518 __asm__ __volatile__( \
29519+ set \
29520 " cmp $7,%0\n" \
29521 " jbe 1f\n" \
29522 " movl %1,%0\n" \
29523 " negl %0\n" \
29524 " andl $7,%0\n" \
29525 " subl %0,%3\n" \
29526- "4: rep; movsb\n" \
29527+ "4: rep; "prefix"movsb\n" \
29528 " movl %3,%0\n" \
29529 " shrl $2,%0\n" \
29530 " andl $3,%3\n" \
29531 " .align 2,0x90\n" \
29532- "0: rep; movsl\n" \
29533+ "0: rep; "prefix"movsl\n" \
29534 " movl %3,%0\n" \
29535- "1: rep; movsb\n" \
29536+ "1: rep; "prefix"movsb\n" \
29537 "2:\n" \
29538+ restore \
29539 ".section .fixup,\"ax\"\n" \
29540 "5: addl %3,%0\n" \
29541 " jmp 2b\n" \
29542@@ -538,14 +650,14 @@ do { \
29543 " negl %0\n" \
29544 " andl $7,%0\n" \
29545 " subl %0,%3\n" \
29546- "4: rep; movsb\n" \
29547+ "4: rep; "__copyuser_seg"movsb\n" \
29548 " movl %3,%0\n" \
29549 " shrl $2,%0\n" \
29550 " andl $3,%3\n" \
29551 " .align 2,0x90\n" \
29552- "0: rep; movsl\n" \
29553+ "0: rep; "__copyuser_seg"movsl\n" \
29554 " movl %3,%0\n" \
29555- "1: rep; movsb\n" \
29556+ "1: rep; "__copyuser_seg"movsb\n" \
29557 "2:\n" \
29558 ".section .fixup,\"ax\"\n" \
29559 "5: addl %3,%0\n" \
29560@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
29561 {
29562 stac();
29563 if (movsl_is_ok(to, from, n))
29564- __copy_user(to, from, n);
29565+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
29566 else
29567- n = __copy_user_intel(to, from, n);
29568+ n = __generic_copy_to_user_intel(to, from, n);
29569 clac();
29570 return n;
29571 }
29572@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
29573 {
29574 stac();
29575 if (movsl_is_ok(to, from, n))
29576- __copy_user(to, from, n);
29577+ __copy_user(to, from, n, __copyuser_seg, "", "");
29578 else
29579- n = __copy_user_intel((void __user *)to,
29580- (const void *)from, n);
29581+ n = __generic_copy_from_user_intel(to, from, n);
29582 clac();
29583 return n;
29584 }
29585@@ -632,60 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
29586 if (n > 64 && cpu_has_xmm2)
29587 n = __copy_user_intel_nocache(to, from, n);
29588 else
29589- __copy_user(to, from, n);
29590+ __copy_user(to, from, n, __copyuser_seg, "", "");
29591 #else
29592- __copy_user(to, from, n);
29593+ __copy_user(to, from, n, __copyuser_seg, "", "");
29594 #endif
29595 clac();
29596 return n;
29597 }
29598 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
29599
29600-/**
29601- * copy_to_user: - Copy a block of data into user space.
29602- * @to: Destination address, in user space.
29603- * @from: Source address, in kernel space.
29604- * @n: Number of bytes to copy.
29605- *
29606- * Context: User context only. This function may sleep.
29607- *
29608- * Copy data from kernel space to user space.
29609- *
29610- * Returns number of bytes that could not be copied.
29611- * On success, this will be zero.
29612- */
29613-unsigned long
29614-copy_to_user(void __user *to, const void *from, unsigned long n)
29615+#ifdef CONFIG_PAX_MEMORY_UDEREF
29616+void __set_fs(mm_segment_t x)
29617 {
29618- if (access_ok(VERIFY_WRITE, to, n))
29619- n = __copy_to_user(to, from, n);
29620- return n;
29621+ switch (x.seg) {
29622+ case 0:
29623+ loadsegment(gs, 0);
29624+ break;
29625+ case TASK_SIZE_MAX:
29626+ loadsegment(gs, __USER_DS);
29627+ break;
29628+ case -1UL:
29629+ loadsegment(gs, __KERNEL_DS);
29630+ break;
29631+ default:
29632+ BUG();
29633+ }
29634 }
29635-EXPORT_SYMBOL(copy_to_user);
29636+EXPORT_SYMBOL(__set_fs);
29637
29638-/**
29639- * copy_from_user: - Copy a block of data from user space.
29640- * @to: Destination address, in kernel space.
29641- * @from: Source address, in user space.
29642- * @n: Number of bytes to copy.
29643- *
29644- * Context: User context only. This function may sleep.
29645- *
29646- * Copy data from user space to kernel space.
29647- *
29648- * Returns number of bytes that could not be copied.
29649- * On success, this will be zero.
29650- *
29651- * If some data could not be copied, this function will pad the copied
29652- * data to the requested size using zero bytes.
29653- */
29654-unsigned long
29655-_copy_from_user(void *to, const void __user *from, unsigned long n)
29656+void set_fs(mm_segment_t x)
29657 {
29658- if (access_ok(VERIFY_READ, from, n))
29659- n = __copy_from_user(to, from, n);
29660- else
29661- memset(to, 0, n);
29662- return n;
29663+ current_thread_info()->addr_limit = x;
29664+ __set_fs(x);
29665 }
29666-EXPORT_SYMBOL(_copy_from_user);
29667+EXPORT_SYMBOL(set_fs);
29668+#endif
29669diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
29670index 906fea3..0194a18 100644
29671--- a/arch/x86/lib/usercopy_64.c
29672+++ b/arch/x86/lib/usercopy_64.c
29673@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29674 might_fault();
29675 /* no memory constraint because it doesn't change any memory gcc knows
29676 about */
29677+ pax_open_userland();
29678 stac();
29679 asm volatile(
29680 " testq %[size8],%[size8]\n"
29681@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29682 _ASM_EXTABLE(0b,3b)
29683 _ASM_EXTABLE(1b,2b)
29684 : [size8] "=&c"(size), [dst] "=&D" (__d0)
29685- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
29686+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
29687 [zero] "r" (0UL), [eight] "r" (8UL));
29688 clac();
29689+ pax_close_userland();
29690 return size;
29691 }
29692 EXPORT_SYMBOL(__clear_user);
29693@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
29694 }
29695 EXPORT_SYMBOL(clear_user);
29696
29697-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
29698+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
29699 {
29700- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
29701- return copy_user_generic((__force void *)to, (__force void *)from, len);
29702- }
29703- return len;
29704+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
29705+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
29706+ return len;
29707 }
29708 EXPORT_SYMBOL(copy_in_user);
29709
29710@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
29711 * it is not necessary to optimize tail handling.
29712 */
29713 unsigned long
29714-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29715+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
29716 {
29717 char c;
29718 unsigned zero_len;
29719
29720+ clac();
29721+ pax_close_userland();
29722 for (; len; --len, to++) {
29723 if (__get_user_nocheck(c, from++, sizeof(char)))
29724 break;
29725@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29726 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
29727 if (__put_user_nocheck(c, to++, sizeof(char)))
29728 break;
29729- clac();
29730 return len;
29731 }
29732diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
29733index 23d8e5f..9ccc13a 100644
29734--- a/arch/x86/mm/Makefile
29735+++ b/arch/x86/mm/Makefile
29736@@ -28,3 +28,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
29737 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
29738
29739 obj-$(CONFIG_MEMTEST) += memtest.o
29740+
29741+quote:="
29742+obj-$(CONFIG_X86_64) += uderef_64.o
29743+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
29744diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
29745index 903ec1e..c4166b2 100644
29746--- a/arch/x86/mm/extable.c
29747+++ b/arch/x86/mm/extable.c
29748@@ -6,12 +6,24 @@
29749 static inline unsigned long
29750 ex_insn_addr(const struct exception_table_entry *x)
29751 {
29752- return (unsigned long)&x->insn + x->insn;
29753+ unsigned long reloc = 0;
29754+
29755+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29756+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29757+#endif
29758+
29759+ return (unsigned long)&x->insn + x->insn + reloc;
29760 }
29761 static inline unsigned long
29762 ex_fixup_addr(const struct exception_table_entry *x)
29763 {
29764- return (unsigned long)&x->fixup + x->fixup;
29765+ unsigned long reloc = 0;
29766+
29767+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29768+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29769+#endif
29770+
29771+ return (unsigned long)&x->fixup + x->fixup + reloc;
29772 }
29773
29774 int fixup_exception(struct pt_regs *regs)
29775@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
29776 unsigned long new_ip;
29777
29778 #ifdef CONFIG_PNPBIOS
29779- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
29780+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
29781 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
29782 extern u32 pnp_bios_is_utter_crap;
29783 pnp_bios_is_utter_crap = 1;
29784@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
29785 i += 4;
29786 p->fixup -= i;
29787 i += 4;
29788+
29789+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29790+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
29791+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29792+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29793+#endif
29794+
29795 }
29796 }
29797
29798diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
29799index 654be4a..a4a3da1 100644
29800--- a/arch/x86/mm/fault.c
29801+++ b/arch/x86/mm/fault.c
29802@@ -14,11 +14,18 @@
29803 #include <linux/hugetlb.h> /* hstate_index_to_shift */
29804 #include <linux/prefetch.h> /* prefetchw */
29805 #include <linux/context_tracking.h> /* exception_enter(), ... */
29806+#include <linux/unistd.h>
29807+#include <linux/compiler.h>
29808
29809 #include <asm/traps.h> /* dotraplinkage, ... */
29810 #include <asm/pgalloc.h> /* pgd_*(), ... */
29811 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
29812 #include <asm/fixmap.h> /* VSYSCALL_START */
29813+#include <asm/tlbflush.h>
29814+
29815+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29816+#include <asm/stacktrace.h>
29817+#endif
29818
29819 /*
29820 * Page fault error code bits:
29821@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
29822 int ret = 0;
29823
29824 /* kprobe_running() needs smp_processor_id() */
29825- if (kprobes_built_in() && !user_mode_vm(regs)) {
29826+ if (kprobes_built_in() && !user_mode(regs)) {
29827 preempt_disable();
29828 if (kprobe_running() && kprobe_fault_handler(regs, 14))
29829 ret = 1;
29830@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
29831 return !instr_lo || (instr_lo>>1) == 1;
29832 case 0x00:
29833 /* Prefetch instruction is 0x0F0D or 0x0F18 */
29834- if (probe_kernel_address(instr, opcode))
29835+ if (user_mode(regs)) {
29836+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29837+ return 0;
29838+ } else if (probe_kernel_address(instr, opcode))
29839 return 0;
29840
29841 *prefetch = (instr_lo == 0xF) &&
29842@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
29843 while (instr < max_instr) {
29844 unsigned char opcode;
29845
29846- if (probe_kernel_address(instr, opcode))
29847+ if (user_mode(regs)) {
29848+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29849+ break;
29850+ } else if (probe_kernel_address(instr, opcode))
29851 break;
29852
29853 instr++;
29854@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
29855 force_sig_info(si_signo, &info, tsk);
29856 }
29857
29858+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
29859+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
29860+#endif
29861+
29862+#ifdef CONFIG_PAX_EMUTRAMP
29863+static int pax_handle_fetch_fault(struct pt_regs *regs);
29864+#endif
29865+
29866+#ifdef CONFIG_PAX_PAGEEXEC
29867+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
29868+{
29869+ pgd_t *pgd;
29870+ pud_t *pud;
29871+ pmd_t *pmd;
29872+
29873+ pgd = pgd_offset(mm, address);
29874+ if (!pgd_present(*pgd))
29875+ return NULL;
29876+ pud = pud_offset(pgd, address);
29877+ if (!pud_present(*pud))
29878+ return NULL;
29879+ pmd = pmd_offset(pud, address);
29880+ if (!pmd_present(*pmd))
29881+ return NULL;
29882+ return pmd;
29883+}
29884+#endif
29885+
29886 DEFINE_SPINLOCK(pgd_lock);
29887 LIST_HEAD(pgd_list);
29888
29889@@ -232,10 +273,27 @@ void vmalloc_sync_all(void)
29890 for (address = VMALLOC_START & PMD_MASK;
29891 address >= TASK_SIZE && address < FIXADDR_TOP;
29892 address += PMD_SIZE) {
29893+
29894+#ifdef CONFIG_PAX_PER_CPU_PGD
29895+ unsigned long cpu;
29896+#else
29897 struct page *page;
29898+#endif
29899
29900 spin_lock(&pgd_lock);
29901+
29902+#ifdef CONFIG_PAX_PER_CPU_PGD
29903+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29904+ pgd_t *pgd = get_cpu_pgd(cpu, user);
29905+ pmd_t *ret;
29906+
29907+ ret = vmalloc_sync_one(pgd, address);
29908+ if (!ret)
29909+ break;
29910+ pgd = get_cpu_pgd(cpu, kernel);
29911+#else
29912 list_for_each_entry(page, &pgd_list, lru) {
29913+ pgd_t *pgd;
29914 spinlock_t *pgt_lock;
29915 pmd_t *ret;
29916
29917@@ -243,8 +301,14 @@ void vmalloc_sync_all(void)
29918 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
29919
29920 spin_lock(pgt_lock);
29921- ret = vmalloc_sync_one(page_address(page), address);
29922+ pgd = page_address(page);
29923+#endif
29924+
29925+ ret = vmalloc_sync_one(pgd, address);
29926+
29927+#ifndef CONFIG_PAX_PER_CPU_PGD
29928 spin_unlock(pgt_lock);
29929+#endif
29930
29931 if (!ret)
29932 break;
29933@@ -278,6 +342,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
29934 * an interrupt in the middle of a task switch..
29935 */
29936 pgd_paddr = read_cr3();
29937+
29938+#ifdef CONFIG_PAX_PER_CPU_PGD
29939+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
29940+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
29941+#endif
29942+
29943 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
29944 if (!pmd_k)
29945 return -1;
29946@@ -373,11 +443,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
29947 * happen within a race in page table update. In the later
29948 * case just flush:
29949 */
29950- pgd = pgd_offset(current->active_mm, address);
29951+
29952 pgd_ref = pgd_offset_k(address);
29953 if (pgd_none(*pgd_ref))
29954 return -1;
29955
29956+#ifdef CONFIG_PAX_PER_CPU_PGD
29957+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
29958+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
29959+ if (pgd_none(*pgd)) {
29960+ set_pgd(pgd, *pgd_ref);
29961+ arch_flush_lazy_mmu_mode();
29962+ } else {
29963+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
29964+ }
29965+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
29966+#else
29967+ pgd = pgd_offset(current->active_mm, address);
29968+#endif
29969+
29970 if (pgd_none(*pgd)) {
29971 set_pgd(pgd, *pgd_ref);
29972 arch_flush_lazy_mmu_mode();
29973@@ -543,7 +627,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
29974 static int is_errata100(struct pt_regs *regs, unsigned long address)
29975 {
29976 #ifdef CONFIG_X86_64
29977- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
29978+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
29979 return 1;
29980 #endif
29981 return 0;
29982@@ -570,7 +654,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
29983 }
29984
29985 static const char nx_warning[] = KERN_CRIT
29986-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
29987+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
29988
29989 static void
29990 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
29991@@ -579,15 +663,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
29992 if (!oops_may_print())
29993 return;
29994
29995- if (error_code & PF_INSTR) {
29996+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
29997 unsigned int level;
29998
29999 pte_t *pte = lookup_address(address, &level);
30000
30001 if (pte && pte_present(*pte) && !pte_exec(*pte))
30002- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
30003+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
30004 }
30005
30006+#ifdef CONFIG_PAX_KERNEXEC
30007+ if (init_mm.start_code <= address && address < init_mm.end_code) {
30008+ if (current->signal->curr_ip)
30009+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
30010+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
30011+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30012+ else
30013+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
30014+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30015+ }
30016+#endif
30017+
30018 printk(KERN_ALERT "BUG: unable to handle kernel ");
30019 if (address < PAGE_SIZE)
30020 printk(KERN_CONT "NULL pointer dereference");
30021@@ -750,6 +846,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
30022 return;
30023 }
30024 #endif
30025+
30026+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30027+ if (pax_is_fetch_fault(regs, error_code, address)) {
30028+
30029+#ifdef CONFIG_PAX_EMUTRAMP
30030+ switch (pax_handle_fetch_fault(regs)) {
30031+ case 2:
30032+ return;
30033+ }
30034+#endif
30035+
30036+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30037+ do_group_exit(SIGKILL);
30038+ }
30039+#endif
30040+
30041 /* Kernel addresses are always protection faults: */
30042 if (address >= TASK_SIZE)
30043 error_code |= PF_PROT;
30044@@ -835,7 +947,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
30045 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
30046 printk(KERN_ERR
30047 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
30048- tsk->comm, tsk->pid, address);
30049+ tsk->comm, task_pid_nr(tsk), address);
30050 code = BUS_MCEERR_AR;
30051 }
30052 #endif
30053@@ -898,6 +1010,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
30054 return 1;
30055 }
30056
30057+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30058+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
30059+{
30060+ pte_t *pte;
30061+ pmd_t *pmd;
30062+ spinlock_t *ptl;
30063+ unsigned char pte_mask;
30064+
30065+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
30066+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
30067+ return 0;
30068+
30069+ /* PaX: it's our fault, let's handle it if we can */
30070+
30071+ /* PaX: take a look at read faults before acquiring any locks */
30072+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
30073+ /* instruction fetch attempt from a protected page in user mode */
30074+ up_read(&mm->mmap_sem);
30075+
30076+#ifdef CONFIG_PAX_EMUTRAMP
30077+ switch (pax_handle_fetch_fault(regs)) {
30078+ case 2:
30079+ return 1;
30080+ }
30081+#endif
30082+
30083+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30084+ do_group_exit(SIGKILL);
30085+ }
30086+
30087+ pmd = pax_get_pmd(mm, address);
30088+ if (unlikely(!pmd))
30089+ return 0;
30090+
30091+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
30092+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
30093+ pte_unmap_unlock(pte, ptl);
30094+ return 0;
30095+ }
30096+
30097+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
30098+ /* write attempt to a protected page in user mode */
30099+ pte_unmap_unlock(pte, ptl);
30100+ return 0;
30101+ }
30102+
30103+#ifdef CONFIG_SMP
30104+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
30105+#else
30106+ if (likely(address > get_limit(regs->cs)))
30107+#endif
30108+ {
30109+ set_pte(pte, pte_mkread(*pte));
30110+ __flush_tlb_one(address);
30111+ pte_unmap_unlock(pte, ptl);
30112+ up_read(&mm->mmap_sem);
30113+ return 1;
30114+ }
30115+
30116+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
30117+
30118+ /*
30119+ * PaX: fill DTLB with user rights and retry
30120+ */
30121+ __asm__ __volatile__ (
30122+ "orb %2,(%1)\n"
30123+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
30124+/*
30125+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
30126+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
30127+ * page fault when examined during a TLB load attempt. this is true not only
30128+ * for PTEs holding a non-present entry but also present entries that will
30129+ * raise a page fault (such as those set up by PaX, or the copy-on-write
30130+ * mechanism). in effect it means that we do *not* need to flush the TLBs
30131+ * for our target pages since their PTEs are simply not in the TLBs at all.
30132+
30133+ * the best thing in omitting it is that we gain around 15-20% speed in the
30134+ * fast path of the page fault handler and can get rid of tracing since we
30135+ * can no longer flush unintended entries.
30136+ */
30137+ "invlpg (%0)\n"
30138+#endif
30139+ __copyuser_seg"testb $0,(%0)\n"
30140+ "xorb %3,(%1)\n"
30141+ :
30142+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
30143+ : "memory", "cc");
30144+ pte_unmap_unlock(pte, ptl);
30145+ up_read(&mm->mmap_sem);
30146+ return 1;
30147+}
30148+#endif
30149+
30150 /*
30151 * Handle a spurious fault caused by a stale TLB entry.
30152 *
30153@@ -964,6 +1169,9 @@ int show_unhandled_signals = 1;
30154 static inline int
30155 access_error(unsigned long error_code, struct vm_area_struct *vma)
30156 {
30157+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
30158+ return 1;
30159+
30160 if (error_code & PF_WRITE) {
30161 /* write, present and write, not present: */
30162 if (unlikely(!(vma->vm_flags & VM_WRITE)))
30163@@ -992,7 +1200,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
30164 if (error_code & PF_USER)
30165 return false;
30166
30167- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
30168+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
30169 return false;
30170
30171 return true;
30172@@ -1008,18 +1216,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30173 {
30174 struct vm_area_struct *vma;
30175 struct task_struct *tsk;
30176- unsigned long address;
30177 struct mm_struct *mm;
30178 int fault;
30179 int write = error_code & PF_WRITE;
30180 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
30181 (write ? FAULT_FLAG_WRITE : 0);
30182
30183- tsk = current;
30184- mm = tsk->mm;
30185-
30186 /* Get the faulting address: */
30187- address = read_cr2();
30188+ unsigned long address = read_cr2();
30189+
30190+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30191+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
30192+ if (!search_exception_tables(regs->ip)) {
30193+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30194+ bad_area_nosemaphore(regs, error_code, address);
30195+ return;
30196+ }
30197+ if (address < pax_user_shadow_base) {
30198+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30199+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
30200+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
30201+ } else
30202+ address -= pax_user_shadow_base;
30203+ }
30204+#endif
30205+
30206+ tsk = current;
30207+ mm = tsk->mm;
30208
30209 /*
30210 * Detect and handle instructions that would cause a page fault for
30211@@ -1080,7 +1303,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30212 * User-mode registers count as a user access even for any
30213 * potential system fault or CPU buglet:
30214 */
30215- if (user_mode_vm(regs)) {
30216+ if (user_mode(regs)) {
30217 local_irq_enable();
30218 error_code |= PF_USER;
30219 } else {
30220@@ -1142,6 +1365,11 @@ retry:
30221 might_sleep();
30222 }
30223
30224+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30225+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
30226+ return;
30227+#endif
30228+
30229 vma = find_vma(mm, address);
30230 if (unlikely(!vma)) {
30231 bad_area(regs, error_code, address);
30232@@ -1153,18 +1381,24 @@ retry:
30233 bad_area(regs, error_code, address);
30234 return;
30235 }
30236- if (error_code & PF_USER) {
30237- /*
30238- * Accessing the stack below %sp is always a bug.
30239- * The large cushion allows instructions like enter
30240- * and pusha to work. ("enter $65535, $31" pushes
30241- * 32 pointers and then decrements %sp by 65535.)
30242- */
30243- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
30244- bad_area(regs, error_code, address);
30245- return;
30246- }
30247+ /*
30248+ * Accessing the stack below %sp is always a bug.
30249+ * The large cushion allows instructions like enter
30250+ * and pusha to work. ("enter $65535, $31" pushes
30251+ * 32 pointers and then decrements %sp by 65535.)
30252+ */
30253+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
30254+ bad_area(regs, error_code, address);
30255+ return;
30256 }
30257+
30258+#ifdef CONFIG_PAX_SEGMEXEC
30259+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
30260+ bad_area(regs, error_code, address);
30261+ return;
30262+ }
30263+#endif
30264+
30265 if (unlikely(expand_stack(vma, address))) {
30266 bad_area(regs, error_code, address);
30267 return;
30268@@ -1230,3 +1464,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
30269 __do_page_fault(regs, error_code);
30270 exception_exit(prev_state);
30271 }
30272+
30273+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30274+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
30275+{
30276+ struct mm_struct *mm = current->mm;
30277+ unsigned long ip = regs->ip;
30278+
30279+ if (v8086_mode(regs))
30280+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
30281+
30282+#ifdef CONFIG_PAX_PAGEEXEC
30283+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
30284+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
30285+ return true;
30286+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
30287+ return true;
30288+ return false;
30289+ }
30290+#endif
30291+
30292+#ifdef CONFIG_PAX_SEGMEXEC
30293+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
30294+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
30295+ return true;
30296+ return false;
30297+ }
30298+#endif
30299+
30300+ return false;
30301+}
30302+#endif
30303+
30304+#ifdef CONFIG_PAX_EMUTRAMP
30305+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
30306+{
30307+ int err;
30308+
30309+ do { /* PaX: libffi trampoline emulation */
30310+ unsigned char mov, jmp;
30311+ unsigned int addr1, addr2;
30312+
30313+#ifdef CONFIG_X86_64
30314+ if ((regs->ip + 9) >> 32)
30315+ break;
30316+#endif
30317+
30318+ err = get_user(mov, (unsigned char __user *)regs->ip);
30319+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30320+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30321+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30322+
30323+ if (err)
30324+ break;
30325+
30326+ if (mov == 0xB8 && jmp == 0xE9) {
30327+ regs->ax = addr1;
30328+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30329+ return 2;
30330+ }
30331+ } while (0);
30332+
30333+ do { /* PaX: gcc trampoline emulation #1 */
30334+ unsigned char mov1, mov2;
30335+ unsigned short jmp;
30336+ unsigned int addr1, addr2;
30337+
30338+#ifdef CONFIG_X86_64
30339+ if ((regs->ip + 11) >> 32)
30340+ break;
30341+#endif
30342+
30343+ err = get_user(mov1, (unsigned char __user *)regs->ip);
30344+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30345+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
30346+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30347+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
30348+
30349+ if (err)
30350+ break;
30351+
30352+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
30353+ regs->cx = addr1;
30354+ regs->ax = addr2;
30355+ regs->ip = addr2;
30356+ return 2;
30357+ }
30358+ } while (0);
30359+
30360+ do { /* PaX: gcc trampoline emulation #2 */
30361+ unsigned char mov, jmp;
30362+ unsigned int addr1, addr2;
30363+
30364+#ifdef CONFIG_X86_64
30365+ if ((regs->ip + 9) >> 32)
30366+ break;
30367+#endif
30368+
30369+ err = get_user(mov, (unsigned char __user *)regs->ip);
30370+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30371+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30372+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30373+
30374+ if (err)
30375+ break;
30376+
30377+ if (mov == 0xB9 && jmp == 0xE9) {
30378+ regs->cx = addr1;
30379+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30380+ return 2;
30381+ }
30382+ } while (0);
30383+
30384+ return 1; /* PaX in action */
30385+}
30386+
30387+#ifdef CONFIG_X86_64
30388+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
30389+{
30390+ int err;
30391+
30392+ do { /* PaX: libffi trampoline emulation */
30393+ unsigned short mov1, mov2, jmp1;
30394+ unsigned char stcclc, jmp2;
30395+ unsigned long addr1, addr2;
30396+
30397+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30398+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30399+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30400+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30401+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
30402+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
30403+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
30404+
30405+ if (err)
30406+ break;
30407+
30408+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30409+ regs->r11 = addr1;
30410+ regs->r10 = addr2;
30411+ if (stcclc == 0xF8)
30412+ regs->flags &= ~X86_EFLAGS_CF;
30413+ else
30414+ regs->flags |= X86_EFLAGS_CF;
30415+ regs->ip = addr1;
30416+ return 2;
30417+ }
30418+ } while (0);
30419+
30420+ do { /* PaX: gcc trampoline emulation #1 */
30421+ unsigned short mov1, mov2, jmp1;
30422+ unsigned char jmp2;
30423+ unsigned int addr1;
30424+ unsigned long addr2;
30425+
30426+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30427+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
30428+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
30429+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
30430+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
30431+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
30432+
30433+ if (err)
30434+ break;
30435+
30436+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30437+ regs->r11 = addr1;
30438+ regs->r10 = addr2;
30439+ regs->ip = addr1;
30440+ return 2;
30441+ }
30442+ } while (0);
30443+
30444+ do { /* PaX: gcc trampoline emulation #2 */
30445+ unsigned short mov1, mov2, jmp1;
30446+ unsigned char jmp2;
30447+ unsigned long addr1, addr2;
30448+
30449+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30450+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30451+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30452+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30453+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
30454+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
30455+
30456+ if (err)
30457+ break;
30458+
30459+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30460+ regs->r11 = addr1;
30461+ regs->r10 = addr2;
30462+ regs->ip = addr1;
30463+ return 2;
30464+ }
30465+ } while (0);
30466+
30467+ return 1; /* PaX in action */
30468+}
30469+#endif
30470+
30471+/*
30472+ * PaX: decide what to do with offenders (regs->ip = fault address)
30473+ *
30474+ * returns 1 when task should be killed
30475+ * 2 when gcc trampoline was detected
30476+ */
30477+static int pax_handle_fetch_fault(struct pt_regs *regs)
30478+{
30479+ if (v8086_mode(regs))
30480+ return 1;
30481+
30482+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
30483+ return 1;
30484+
30485+#ifdef CONFIG_X86_32
30486+ return pax_handle_fetch_fault_32(regs);
30487+#else
30488+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
30489+ return pax_handle_fetch_fault_32(regs);
30490+ else
30491+ return pax_handle_fetch_fault_64(regs);
30492+#endif
30493+}
30494+#endif
30495+
30496+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30497+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
30498+{
30499+ long i;
30500+
30501+ printk(KERN_ERR "PAX: bytes at PC: ");
30502+ for (i = 0; i < 20; i++) {
30503+ unsigned char c;
30504+ if (get_user(c, (unsigned char __force_user *)pc+i))
30505+ printk(KERN_CONT "?? ");
30506+ else
30507+ printk(KERN_CONT "%02x ", c);
30508+ }
30509+ printk("\n");
30510+
30511+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
30512+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
30513+ unsigned long c;
30514+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
30515+#ifdef CONFIG_X86_32
30516+ printk(KERN_CONT "???????? ");
30517+#else
30518+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
30519+ printk(KERN_CONT "???????? ???????? ");
30520+ else
30521+ printk(KERN_CONT "???????????????? ");
30522+#endif
30523+ } else {
30524+#ifdef CONFIG_X86_64
30525+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
30526+ printk(KERN_CONT "%08x ", (unsigned int)c);
30527+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
30528+ } else
30529+#endif
30530+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
30531+ }
30532+ }
30533+ printk("\n");
30534+}
30535+#endif
30536+
30537+/**
30538+ * probe_kernel_write(): safely attempt to write to a location
30539+ * @dst: address to write to
30540+ * @src: pointer to the data that shall be written
30541+ * @size: size of the data chunk
30542+ *
30543+ * Safely write to address @dst from the buffer at @src. If a kernel fault
30544+ * happens, handle that and return -EFAULT.
30545+ */
30546+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
30547+{
30548+ long ret;
30549+ mm_segment_t old_fs = get_fs();
30550+
30551+ set_fs(KERNEL_DS);
30552+ pagefault_disable();
30553+ pax_open_kernel();
30554+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
30555+ pax_close_kernel();
30556+ pagefault_enable();
30557+ set_fs(old_fs);
30558+
30559+ return ret ? -EFAULT : 0;
30560+}
30561diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
30562index dd74e46..7d26398 100644
30563--- a/arch/x86/mm/gup.c
30564+++ b/arch/x86/mm/gup.c
30565@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
30566 addr = start;
30567 len = (unsigned long) nr_pages << PAGE_SHIFT;
30568 end = start + len;
30569- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30570+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30571 (void __user *)start, len)))
30572 return 0;
30573
30574diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
30575index 4500142..53a363c 100644
30576--- a/arch/x86/mm/highmem_32.c
30577+++ b/arch/x86/mm/highmem_32.c
30578@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
30579 idx = type + KM_TYPE_NR*smp_processor_id();
30580 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
30581 BUG_ON(!pte_none(*(kmap_pte-idx)));
30582+
30583+ pax_open_kernel();
30584 set_pte(kmap_pte-idx, mk_pte(page, prot));
30585+ pax_close_kernel();
30586+
30587 arch_flush_lazy_mmu_mode();
30588
30589 return (void *)vaddr;
30590diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
30591index 7e73e8c..11d3b86 100644
30592--- a/arch/x86/mm/hugetlbpage.c
30593+++ b/arch/x86/mm/hugetlbpage.c
30594@@ -84,23 +84,30 @@ int pud_huge(pud_t pud)
30595 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
30596 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
30597 unsigned long addr, unsigned long len,
30598- unsigned long pgoff, unsigned long flags)
30599+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30600 {
30601 struct hstate *h = hstate_file(file);
30602 struct vm_unmapped_area_info info;
30603-
30604+
30605 info.flags = 0;
30606 info.length = len;
30607 info.low_limit = TASK_UNMAPPED_BASE;
30608+
30609+#ifdef CONFIG_PAX_RANDMMAP
30610+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30611+ info.low_limit += current->mm->delta_mmap;
30612+#endif
30613+
30614 info.high_limit = TASK_SIZE;
30615 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30616 info.align_offset = 0;
30617+ info.threadstack_offset = offset;
30618 return vm_unmapped_area(&info);
30619 }
30620
30621 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30622 unsigned long addr0, unsigned long len,
30623- unsigned long pgoff, unsigned long flags)
30624+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30625 {
30626 struct hstate *h = hstate_file(file);
30627 struct vm_unmapped_area_info info;
30628@@ -112,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30629 info.high_limit = current->mm->mmap_base;
30630 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30631 info.align_offset = 0;
30632+ info.threadstack_offset = offset;
30633 addr = vm_unmapped_area(&info);
30634
30635 /*
30636@@ -124,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30637 VM_BUG_ON(addr != -ENOMEM);
30638 info.flags = 0;
30639 info.low_limit = TASK_UNMAPPED_BASE;
30640+
30641+#ifdef CONFIG_PAX_RANDMMAP
30642+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30643+ info.low_limit += current->mm->delta_mmap;
30644+#endif
30645+
30646 info.high_limit = TASK_SIZE;
30647 addr = vm_unmapped_area(&info);
30648 }
30649@@ -138,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30650 struct hstate *h = hstate_file(file);
30651 struct mm_struct *mm = current->mm;
30652 struct vm_area_struct *vma;
30653+ unsigned long pax_task_size = TASK_SIZE;
30654+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
30655
30656 if (len & ~huge_page_mask(h))
30657 return -EINVAL;
30658- if (len > TASK_SIZE)
30659+
30660+#ifdef CONFIG_PAX_SEGMEXEC
30661+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
30662+ pax_task_size = SEGMEXEC_TASK_SIZE;
30663+#endif
30664+
30665+ pax_task_size -= PAGE_SIZE;
30666+
30667+ if (len > pax_task_size)
30668 return -ENOMEM;
30669
30670 if (flags & MAP_FIXED) {
30671@@ -150,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30672 return addr;
30673 }
30674
30675+#ifdef CONFIG_PAX_RANDMMAP
30676+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30677+#endif
30678+
30679 if (addr) {
30680 addr = ALIGN(addr, huge_page_size(h));
30681 vma = find_vma(mm, addr);
30682- if (TASK_SIZE - len >= addr &&
30683- (!vma || addr + len <= vma->vm_start))
30684+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
30685 return addr;
30686 }
30687 if (mm->get_unmapped_area == arch_get_unmapped_area)
30688 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
30689- pgoff, flags);
30690+ pgoff, flags, offset);
30691 else
30692 return hugetlb_get_unmapped_area_topdown(file, addr, len,
30693- pgoff, flags);
30694+ pgoff, flags, offset);
30695 }
30696
30697 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
30698diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
30699index 04664cd..dae6e5d 100644
30700--- a/arch/x86/mm/init.c
30701+++ b/arch/x86/mm/init.c
30702@@ -4,6 +4,7 @@
30703 #include <linux/swap.h>
30704 #include <linux/memblock.h>
30705 #include <linux/bootmem.h> /* for max_low_pfn */
30706+#include <linux/tboot.h>
30707
30708 #include <asm/cacheflush.h>
30709 #include <asm/e820.h>
30710@@ -17,6 +18,8 @@
30711 #include <asm/proto.h>
30712 #include <asm/dma.h> /* for MAX_DMA_PFN */
30713 #include <asm/microcode.h>
30714+#include <asm/desc.h>
30715+#include <asm/bios_ebda.h>
30716
30717 #include "mm_internal.h"
30718
30719@@ -465,7 +468,18 @@ void __init init_mem_mapping(void)
30720 early_ioremap_page_table_range_init();
30721 #endif
30722
30723+#ifdef CONFIG_PAX_PER_CPU_PGD
30724+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
30725+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30726+ KERNEL_PGD_PTRS);
30727+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
30728+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30729+ KERNEL_PGD_PTRS);
30730+ load_cr3(get_cpu_pgd(0, kernel));
30731+#else
30732 load_cr3(swapper_pg_dir);
30733+#endif
30734+
30735 __flush_tlb_all();
30736
30737 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
30738@@ -481,10 +495,40 @@ void __init init_mem_mapping(void)
30739 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
30740 * mmio resources as well as potential bios/acpi data regions.
30741 */
30742+
30743+#ifdef CONFIG_GRKERNSEC_KMEM
30744+static unsigned int ebda_start __read_only;
30745+static unsigned int ebda_end __read_only;
30746+#endif
30747+
30748 int devmem_is_allowed(unsigned long pagenr)
30749 {
30750- if (pagenr < 256)
30751+#ifdef CONFIG_GRKERNSEC_KMEM
30752+ /* allow BDA */
30753+ if (!pagenr)
30754 return 1;
30755+ /* allow EBDA */
30756+ if (pagenr >= ebda_start && pagenr < ebda_end)
30757+ return 1;
30758+ /* if tboot is in use, allow access to its hardcoded serial log range */
30759+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
30760+ return 1;
30761+#else
30762+ if (!pagenr)
30763+ return 1;
30764+#ifdef CONFIG_VM86
30765+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
30766+ return 1;
30767+#endif
30768+#endif
30769+
30770+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
30771+ return 1;
30772+#ifdef CONFIG_GRKERNSEC_KMEM
30773+ /* throw out everything else below 1MB */
30774+ if (pagenr <= 256)
30775+ return 0;
30776+#endif
30777 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
30778 return 0;
30779 if (!page_is_ram(pagenr))
30780@@ -530,8 +574,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
30781 #endif
30782 }
30783
30784+#ifdef CONFIG_GRKERNSEC_KMEM
30785+static inline void gr_init_ebda(void)
30786+{
30787+ unsigned int ebda_addr;
30788+ unsigned int ebda_size = 0;
30789+
30790+ ebda_addr = get_bios_ebda();
30791+ if (ebda_addr) {
30792+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
30793+ ebda_size <<= 10;
30794+ }
30795+ if (ebda_addr && ebda_size) {
30796+ ebda_start = ebda_addr >> PAGE_SHIFT;
30797+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
30798+ } else {
30799+ ebda_start = 0x9f000 >> PAGE_SHIFT;
30800+ ebda_end = 0xa0000 >> PAGE_SHIFT;
30801+ }
30802+}
30803+#else
30804+static inline void gr_init_ebda(void) { }
30805+#endif
30806+
30807 void free_initmem(void)
30808 {
30809+#ifdef CONFIG_PAX_KERNEXEC
30810+#ifdef CONFIG_X86_32
30811+ /* PaX: limit KERNEL_CS to actual size */
30812+ unsigned long addr, limit;
30813+ struct desc_struct d;
30814+ int cpu;
30815+#else
30816+ pgd_t *pgd;
30817+ pud_t *pud;
30818+ pmd_t *pmd;
30819+ unsigned long addr, end;
30820+#endif
30821+#endif
30822+
30823+ gr_init_ebda();
30824+
30825+#ifdef CONFIG_PAX_KERNEXEC
30826+#ifdef CONFIG_X86_32
30827+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
30828+ limit = (limit - 1UL) >> PAGE_SHIFT;
30829+
30830+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
30831+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30832+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
30833+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
30834+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
30835+ }
30836+
30837+ /* PaX: make KERNEL_CS read-only */
30838+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
30839+ if (!paravirt_enabled())
30840+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
30841+/*
30842+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
30843+ pgd = pgd_offset_k(addr);
30844+ pud = pud_offset(pgd, addr);
30845+ pmd = pmd_offset(pud, addr);
30846+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30847+ }
30848+*/
30849+#ifdef CONFIG_X86_PAE
30850+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
30851+/*
30852+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
30853+ pgd = pgd_offset_k(addr);
30854+ pud = pud_offset(pgd, addr);
30855+ pmd = pmd_offset(pud, addr);
30856+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30857+ }
30858+*/
30859+#endif
30860+
30861+#ifdef CONFIG_MODULES
30862+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
30863+#endif
30864+
30865+#else
30866+ /* PaX: make kernel code/rodata read-only, rest non-executable */
30867+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
30868+ pgd = pgd_offset_k(addr);
30869+ pud = pud_offset(pgd, addr);
30870+ pmd = pmd_offset(pud, addr);
30871+ if (!pmd_present(*pmd))
30872+ continue;
30873+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
30874+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30875+ else
30876+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30877+ }
30878+
30879+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
30880+ end = addr + KERNEL_IMAGE_SIZE;
30881+ for (; addr < end; addr += PMD_SIZE) {
30882+ pgd = pgd_offset_k(addr);
30883+ pud = pud_offset(pgd, addr);
30884+ pmd = pmd_offset(pud, addr);
30885+ if (!pmd_present(*pmd))
30886+ continue;
30887+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
30888+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30889+ }
30890+#endif
30891+
30892+ flush_tlb_all();
30893+#endif
30894+
30895 free_init_pages("unused kernel",
30896 (unsigned long)(&__init_begin),
30897 (unsigned long)(&__init_end));
30898diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
30899index 4287f1f..3b99c71 100644
30900--- a/arch/x86/mm/init_32.c
30901+++ b/arch/x86/mm/init_32.c
30902@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
30903 bool __read_mostly __vmalloc_start_set = false;
30904
30905 /*
30906- * Creates a middle page table and puts a pointer to it in the
30907- * given global directory entry. This only returns the gd entry
30908- * in non-PAE compilation mode, since the middle layer is folded.
30909- */
30910-static pmd_t * __init one_md_table_init(pgd_t *pgd)
30911-{
30912- pud_t *pud;
30913- pmd_t *pmd_table;
30914-
30915-#ifdef CONFIG_X86_PAE
30916- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
30917- pmd_table = (pmd_t *)alloc_low_page();
30918- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
30919- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
30920- pud = pud_offset(pgd, 0);
30921- BUG_ON(pmd_table != pmd_offset(pud, 0));
30922-
30923- return pmd_table;
30924- }
30925-#endif
30926- pud = pud_offset(pgd, 0);
30927- pmd_table = pmd_offset(pud, 0);
30928-
30929- return pmd_table;
30930-}
30931-
30932-/*
30933 * Create a page table and place a pointer to it in a middle page
30934 * directory entry:
30935 */
30936@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
30937 pte_t *page_table = (pte_t *)alloc_low_page();
30938
30939 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
30940+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30941+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
30942+#else
30943 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
30944+#endif
30945 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
30946 }
30947
30948 return pte_offset_kernel(pmd, 0);
30949 }
30950
30951+static pmd_t * __init one_md_table_init(pgd_t *pgd)
30952+{
30953+ pud_t *pud;
30954+ pmd_t *pmd_table;
30955+
30956+ pud = pud_offset(pgd, 0);
30957+ pmd_table = pmd_offset(pud, 0);
30958+
30959+ return pmd_table;
30960+}
30961+
30962 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
30963 {
30964 int pgd_idx = pgd_index(vaddr);
30965@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
30966 int pgd_idx, pmd_idx;
30967 unsigned long vaddr;
30968 pgd_t *pgd;
30969+ pud_t *pud;
30970 pmd_t *pmd;
30971 pte_t *pte = NULL;
30972 unsigned long count = page_table_range_init_count(start, end);
30973@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
30974 pgd = pgd_base + pgd_idx;
30975
30976 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
30977- pmd = one_md_table_init(pgd);
30978- pmd = pmd + pmd_index(vaddr);
30979+ pud = pud_offset(pgd, vaddr);
30980+ pmd = pmd_offset(pud, vaddr);
30981+
30982+#ifdef CONFIG_X86_PAE
30983+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
30984+#endif
30985+
30986 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
30987 pmd++, pmd_idx++) {
30988 pte = page_table_kmap_check(one_page_table_init(pmd),
30989@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
30990 }
30991 }
30992
30993-static inline int is_kernel_text(unsigned long addr)
30994+static inline int is_kernel_text(unsigned long start, unsigned long end)
30995 {
30996- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
30997- return 1;
30998- return 0;
30999+ if ((start > ktla_ktva((unsigned long)_etext) ||
31000+ end <= ktla_ktva((unsigned long)_stext)) &&
31001+ (start > ktla_ktva((unsigned long)_einittext) ||
31002+ end <= ktla_ktva((unsigned long)_sinittext)) &&
31003+
31004+#ifdef CONFIG_ACPI_SLEEP
31005+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
31006+#endif
31007+
31008+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
31009+ return 0;
31010+ return 1;
31011 }
31012
31013 /*
31014@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
31015 unsigned long last_map_addr = end;
31016 unsigned long start_pfn, end_pfn;
31017 pgd_t *pgd_base = swapper_pg_dir;
31018- int pgd_idx, pmd_idx, pte_ofs;
31019+ unsigned int pgd_idx, pmd_idx, pte_ofs;
31020 unsigned long pfn;
31021 pgd_t *pgd;
31022+ pud_t *pud;
31023 pmd_t *pmd;
31024 pte_t *pte;
31025 unsigned pages_2m, pages_4k;
31026@@ -291,8 +295,13 @@ repeat:
31027 pfn = start_pfn;
31028 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31029 pgd = pgd_base + pgd_idx;
31030- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
31031- pmd = one_md_table_init(pgd);
31032+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
31033+ pud = pud_offset(pgd, 0);
31034+ pmd = pmd_offset(pud, 0);
31035+
31036+#ifdef CONFIG_X86_PAE
31037+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31038+#endif
31039
31040 if (pfn >= end_pfn)
31041 continue;
31042@@ -304,14 +313,13 @@ repeat:
31043 #endif
31044 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
31045 pmd++, pmd_idx++) {
31046- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
31047+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
31048
31049 /*
31050 * Map with big pages if possible, otherwise
31051 * create normal page tables:
31052 */
31053 if (use_pse) {
31054- unsigned int addr2;
31055 pgprot_t prot = PAGE_KERNEL_LARGE;
31056 /*
31057 * first pass will use the same initial
31058@@ -322,11 +330,7 @@ repeat:
31059 _PAGE_PSE);
31060
31061 pfn &= PMD_MASK >> PAGE_SHIFT;
31062- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
31063- PAGE_OFFSET + PAGE_SIZE-1;
31064-
31065- if (is_kernel_text(addr) ||
31066- is_kernel_text(addr2))
31067+ if (is_kernel_text(address, address + PMD_SIZE))
31068 prot = PAGE_KERNEL_LARGE_EXEC;
31069
31070 pages_2m++;
31071@@ -343,7 +347,7 @@ repeat:
31072 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31073 pte += pte_ofs;
31074 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
31075- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
31076+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
31077 pgprot_t prot = PAGE_KERNEL;
31078 /*
31079 * first pass will use the same initial
31080@@ -351,7 +355,7 @@ repeat:
31081 */
31082 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
31083
31084- if (is_kernel_text(addr))
31085+ if (is_kernel_text(address, address + PAGE_SIZE))
31086 prot = PAGE_KERNEL_EXEC;
31087
31088 pages_4k++;
31089@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
31090
31091 pud = pud_offset(pgd, va);
31092 pmd = pmd_offset(pud, va);
31093- if (!pmd_present(*pmd))
31094+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
31095 break;
31096
31097 /* should not be large page here */
31098@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
31099
31100 static void __init pagetable_init(void)
31101 {
31102- pgd_t *pgd_base = swapper_pg_dir;
31103-
31104- permanent_kmaps_init(pgd_base);
31105+ permanent_kmaps_init(swapper_pg_dir);
31106 }
31107
31108-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31109+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31110 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31111
31112 /* user-defined highmem size */
31113@@ -787,10 +789,10 @@ void __init mem_init(void)
31114 ((unsigned long)&__init_end -
31115 (unsigned long)&__init_begin) >> 10,
31116
31117- (unsigned long)&_etext, (unsigned long)&_edata,
31118- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
31119+ (unsigned long)&_sdata, (unsigned long)&_edata,
31120+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
31121
31122- (unsigned long)&_text, (unsigned long)&_etext,
31123+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
31124 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
31125
31126 /*
31127@@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
31128 if (!kernel_set_to_readonly)
31129 return;
31130
31131+ start = ktla_ktva(start);
31132 pr_debug("Set kernel text: %lx - %lx for read write\n",
31133 start, start+size);
31134
31135@@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
31136 if (!kernel_set_to_readonly)
31137 return;
31138
31139+ start = ktla_ktva(start);
31140 pr_debug("Set kernel text: %lx - %lx for read only\n",
31141 start, start+size);
31142
31143@@ -922,6 +926,7 @@ void mark_rodata_ro(void)
31144 unsigned long start = PFN_ALIGN(_text);
31145 unsigned long size = PFN_ALIGN(_etext) - start;
31146
31147+ start = ktla_ktva(start);
31148 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
31149 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
31150 size >> 10);
31151diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
31152index 104d56a..62ba13f 100644
31153--- a/arch/x86/mm/init_64.c
31154+++ b/arch/x86/mm/init_64.c
31155@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
31156 * around without checking the pgd every time.
31157 */
31158
31159-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
31160+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
31161 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31162
31163 int force_personality32;
31164@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31165
31166 for (address = start; address <= end; address += PGDIR_SIZE) {
31167 const pgd_t *pgd_ref = pgd_offset_k(address);
31168+
31169+#ifdef CONFIG_PAX_PER_CPU_PGD
31170+ unsigned long cpu;
31171+#else
31172 struct page *page;
31173+#endif
31174
31175 if (pgd_none(*pgd_ref))
31176 continue;
31177
31178 spin_lock(&pgd_lock);
31179+
31180+#ifdef CONFIG_PAX_PER_CPU_PGD
31181+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31182+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
31183+
31184+ if (pgd_none(*pgd))
31185+ set_pgd(pgd, *pgd_ref);
31186+ else
31187+ BUG_ON(pgd_page_vaddr(*pgd)
31188+ != pgd_page_vaddr(*pgd_ref));
31189+ pgd = pgd_offset_cpu(cpu, kernel, address);
31190+#else
31191 list_for_each_entry(page, &pgd_list, lru) {
31192 pgd_t *pgd;
31193 spinlock_t *pgt_lock;
31194@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31195 /* the pgt_lock only for Xen */
31196 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31197 spin_lock(pgt_lock);
31198+#endif
31199
31200 if (pgd_none(*pgd))
31201 set_pgd(pgd, *pgd_ref);
31202@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31203 BUG_ON(pgd_page_vaddr(*pgd)
31204 != pgd_page_vaddr(*pgd_ref));
31205
31206+#ifndef CONFIG_PAX_PER_CPU_PGD
31207 spin_unlock(pgt_lock);
31208+#endif
31209+
31210 }
31211 spin_unlock(&pgd_lock);
31212 }
31213@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
31214 {
31215 if (pgd_none(*pgd)) {
31216 pud_t *pud = (pud_t *)spp_getpage();
31217- pgd_populate(&init_mm, pgd, pud);
31218+ pgd_populate_kernel(&init_mm, pgd, pud);
31219 if (pud != pud_offset(pgd, 0))
31220 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
31221 pud, pud_offset(pgd, 0));
31222@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
31223 {
31224 if (pud_none(*pud)) {
31225 pmd_t *pmd = (pmd_t *) spp_getpage();
31226- pud_populate(&init_mm, pud, pmd);
31227+ pud_populate_kernel(&init_mm, pud, pmd);
31228 if (pmd != pmd_offset(pud, 0))
31229 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
31230 pmd, pmd_offset(pud, 0));
31231@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
31232 pmd = fill_pmd(pud, vaddr);
31233 pte = fill_pte(pmd, vaddr);
31234
31235+ pax_open_kernel();
31236 set_pte(pte, new_pte);
31237+ pax_close_kernel();
31238
31239 /*
31240 * It's enough to flush this one mapping.
31241@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
31242 pgd = pgd_offset_k((unsigned long)__va(phys));
31243 if (pgd_none(*pgd)) {
31244 pud = (pud_t *) spp_getpage();
31245- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
31246- _PAGE_USER));
31247+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
31248 }
31249 pud = pud_offset(pgd, (unsigned long)__va(phys));
31250 if (pud_none(*pud)) {
31251 pmd = (pmd_t *) spp_getpage();
31252- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
31253- _PAGE_USER));
31254+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
31255 }
31256 pmd = pmd_offset(pud, phys);
31257 BUG_ON(!pmd_none(*pmd));
31258@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
31259 prot);
31260
31261 spin_lock(&init_mm.page_table_lock);
31262- pud_populate(&init_mm, pud, pmd);
31263+ pud_populate_kernel(&init_mm, pud, pmd);
31264 spin_unlock(&init_mm.page_table_lock);
31265 }
31266 __flush_tlb_all();
31267@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
31268 page_size_mask);
31269
31270 spin_lock(&init_mm.page_table_lock);
31271- pgd_populate(&init_mm, pgd, pud);
31272+ pgd_populate_kernel(&init_mm, pgd, pud);
31273 spin_unlock(&init_mm.page_table_lock);
31274 pgd_changed = true;
31275 }
31276@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
31277 static struct vm_area_struct gate_vma = {
31278 .vm_start = VSYSCALL_START,
31279 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
31280- .vm_page_prot = PAGE_READONLY_EXEC,
31281- .vm_flags = VM_READ | VM_EXEC
31282+ .vm_page_prot = PAGE_READONLY,
31283+ .vm_flags = VM_READ
31284 };
31285
31286 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31287@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
31288
31289 const char *arch_vma_name(struct vm_area_struct *vma)
31290 {
31291- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31292+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31293 return "[vdso]";
31294 if (vma == &gate_vma)
31295 return "[vsyscall]";
31296diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
31297index 7b179b4..6bd17777 100644
31298--- a/arch/x86/mm/iomap_32.c
31299+++ b/arch/x86/mm/iomap_32.c
31300@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
31301 type = kmap_atomic_idx_push();
31302 idx = type + KM_TYPE_NR * smp_processor_id();
31303 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31304+
31305+ pax_open_kernel();
31306 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
31307+ pax_close_kernel();
31308+
31309 arch_flush_lazy_mmu_mode();
31310
31311 return (void *)vaddr;
31312diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
31313index 0215e2c..1c62dab 100644
31314--- a/arch/x86/mm/ioremap.c
31315+++ b/arch/x86/mm/ioremap.c
31316@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
31317 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
31318 int is_ram = page_is_ram(pfn);
31319
31320- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
31321+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
31322 return NULL;
31323 WARN_ON_ONCE(is_ram);
31324 }
31325@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
31326 *
31327 * Caller must ensure there is only one unmapping for the same pointer.
31328 */
31329-void iounmap(volatile void __iomem *addr)
31330+void iounmap(const volatile void __iomem *addr)
31331 {
31332 struct vm_struct *p, *o;
31333
31334@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31335
31336 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
31337 if (page_is_ram(start >> PAGE_SHIFT))
31338+#ifdef CONFIG_HIGHMEM
31339+ if ((start >> PAGE_SHIFT) < max_low_pfn)
31340+#endif
31341 return __va(phys);
31342
31343 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
31344@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31345 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
31346 {
31347 if (page_is_ram(phys >> PAGE_SHIFT))
31348+#ifdef CONFIG_HIGHMEM
31349+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
31350+#endif
31351 return;
31352
31353 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
31354@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
31355 early_param("early_ioremap_debug", early_ioremap_debug_setup);
31356
31357 static __initdata int after_paging_init;
31358-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
31359+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
31360
31361 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
31362 {
31363@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
31364 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
31365
31366 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
31367- memset(bm_pte, 0, sizeof(bm_pte));
31368- pmd_populate_kernel(&init_mm, pmd, bm_pte);
31369+ pmd_populate_user(&init_mm, pmd, bm_pte);
31370
31371 /*
31372 * The boot-ioremap range spans multiple pmds, for which
31373diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
31374index d87dd6d..bf3fa66 100644
31375--- a/arch/x86/mm/kmemcheck/kmemcheck.c
31376+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
31377@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
31378 * memory (e.g. tracked pages)? For now, we need this to avoid
31379 * invoking kmemcheck for PnP BIOS calls.
31380 */
31381- if (regs->flags & X86_VM_MASK)
31382+ if (v8086_mode(regs))
31383 return false;
31384- if (regs->cs != __KERNEL_CS)
31385+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
31386 return false;
31387
31388 pte = kmemcheck_pte_lookup(address);
31389diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
31390index 25e7e13..1964579 100644
31391--- a/arch/x86/mm/mmap.c
31392+++ b/arch/x86/mm/mmap.c
31393@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
31394 * Leave an at least ~128 MB hole with possible stack randomization.
31395 */
31396 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
31397-#define MAX_GAP (TASK_SIZE/6*5)
31398+#define MAX_GAP (pax_task_size/6*5)
31399
31400 static int mmap_is_legacy(void)
31401 {
31402@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
31403 return rnd << PAGE_SHIFT;
31404 }
31405
31406-static unsigned long mmap_base(void)
31407+static unsigned long mmap_base(struct mm_struct *mm)
31408 {
31409 unsigned long gap = rlimit(RLIMIT_STACK);
31410+ unsigned long pax_task_size = TASK_SIZE;
31411+
31412+#ifdef CONFIG_PAX_SEGMEXEC
31413+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31414+ pax_task_size = SEGMEXEC_TASK_SIZE;
31415+#endif
31416
31417 if (gap < MIN_GAP)
31418 gap = MIN_GAP;
31419 else if (gap > MAX_GAP)
31420 gap = MAX_GAP;
31421
31422- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
31423+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
31424 }
31425
31426 /*
31427 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
31428 * does, but not when emulating X86_32
31429 */
31430-static unsigned long mmap_legacy_base(void)
31431+static unsigned long mmap_legacy_base(struct mm_struct *mm)
31432 {
31433- if (mmap_is_ia32())
31434+ if (mmap_is_ia32()) {
31435+
31436+#ifdef CONFIG_PAX_SEGMEXEC
31437+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31438+ return SEGMEXEC_TASK_UNMAPPED_BASE;
31439+ else
31440+#endif
31441+
31442 return TASK_UNMAPPED_BASE;
31443- else
31444+ } else
31445 return TASK_UNMAPPED_BASE + mmap_rnd();
31446 }
31447
31448@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
31449 */
31450 void arch_pick_mmap_layout(struct mm_struct *mm)
31451 {
31452- mm->mmap_legacy_base = mmap_legacy_base();
31453- mm->mmap_base = mmap_base();
31454+ mm->mmap_legacy_base = mmap_legacy_base(mm);
31455+ mm->mmap_base = mmap_base(mm);
31456+
31457+#ifdef CONFIG_PAX_RANDMMAP
31458+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
31459+ mm->mmap_legacy_base += mm->delta_mmap;
31460+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
31461+ }
31462+#endif
31463
31464 if (mmap_is_legacy()) {
31465 mm->mmap_base = mm->mmap_legacy_base;
31466diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
31467index 0057a7a..95c7edd 100644
31468--- a/arch/x86/mm/mmio-mod.c
31469+++ b/arch/x86/mm/mmio-mod.c
31470@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
31471 break;
31472 default:
31473 {
31474- unsigned char *ip = (unsigned char *)instptr;
31475+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
31476 my_trace->opcode = MMIO_UNKNOWN_OP;
31477 my_trace->width = 0;
31478 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
31479@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
31480 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31481 void __iomem *addr)
31482 {
31483- static atomic_t next_id;
31484+ static atomic_unchecked_t next_id;
31485 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
31486 /* These are page-unaligned. */
31487 struct mmiotrace_map map = {
31488@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31489 .private = trace
31490 },
31491 .phys = offset,
31492- .id = atomic_inc_return(&next_id)
31493+ .id = atomic_inc_return_unchecked(&next_id)
31494 };
31495 map.map_id = trace->id;
31496
31497@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
31498 ioremap_trace_core(offset, size, addr);
31499 }
31500
31501-static void iounmap_trace_core(volatile void __iomem *addr)
31502+static void iounmap_trace_core(const volatile void __iomem *addr)
31503 {
31504 struct mmiotrace_map map = {
31505 .phys = 0,
31506@@ -328,7 +328,7 @@ not_enabled:
31507 }
31508 }
31509
31510-void mmiotrace_iounmap(volatile void __iomem *addr)
31511+void mmiotrace_iounmap(const volatile void __iomem *addr)
31512 {
31513 might_sleep();
31514 if (is_enabled()) /* recheck and proper locking in *_core() */
31515diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
31516index 8bf93ba..dbcd670 100644
31517--- a/arch/x86/mm/numa.c
31518+++ b/arch/x86/mm/numa.c
31519@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
31520 return true;
31521 }
31522
31523-static int __init numa_register_memblks(struct numa_meminfo *mi)
31524+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
31525 {
31526 unsigned long uninitialized_var(pfn_align);
31527 int i, nid;
31528diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
31529index d0b1773..4c3327c 100644
31530--- a/arch/x86/mm/pageattr-test.c
31531+++ b/arch/x86/mm/pageattr-test.c
31532@@ -36,7 +36,7 @@ enum {
31533
31534 static int pte_testbit(pte_t pte)
31535 {
31536- return pte_flags(pte) & _PAGE_UNUSED1;
31537+ return pte_flags(pte) & _PAGE_CPA_TEST;
31538 }
31539
31540 struct split_state {
31541diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
31542index bb32480..75f2f5e 100644
31543--- a/arch/x86/mm/pageattr.c
31544+++ b/arch/x86/mm/pageattr.c
31545@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31546 */
31547 #ifdef CONFIG_PCI_BIOS
31548 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
31549- pgprot_val(forbidden) |= _PAGE_NX;
31550+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31551 #endif
31552
31553 /*
31554@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31555 * Does not cover __inittext since that is gone later on. On
31556 * 64bit we do not enforce !NX on the low mapping
31557 */
31558- if (within(address, (unsigned long)_text, (unsigned long)_etext))
31559- pgprot_val(forbidden) |= _PAGE_NX;
31560+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
31561+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31562
31563+#ifdef CONFIG_DEBUG_RODATA
31564 /*
31565 * The .rodata section needs to be read-only. Using the pfn
31566 * catches all aliases.
31567@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31568 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
31569 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
31570 pgprot_val(forbidden) |= _PAGE_RW;
31571+#endif
31572
31573 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
31574 /*
31575@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31576 }
31577 #endif
31578
31579+#ifdef CONFIG_PAX_KERNEXEC
31580+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
31581+ pgprot_val(forbidden) |= _PAGE_RW;
31582+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31583+ }
31584+#endif
31585+
31586 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
31587
31588 return prot;
31589@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
31590 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
31591 {
31592 /* change init_mm */
31593+ pax_open_kernel();
31594 set_pte_atomic(kpte, pte);
31595+
31596 #ifdef CONFIG_X86_32
31597 if (!SHARED_KERNEL_PMD) {
31598+
31599+#ifdef CONFIG_PAX_PER_CPU_PGD
31600+ unsigned long cpu;
31601+#else
31602 struct page *page;
31603+#endif
31604
31605+#ifdef CONFIG_PAX_PER_CPU_PGD
31606+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31607+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
31608+#else
31609 list_for_each_entry(page, &pgd_list, lru) {
31610- pgd_t *pgd;
31611+ pgd_t *pgd = (pgd_t *)page_address(page);
31612+#endif
31613+
31614 pud_t *pud;
31615 pmd_t *pmd;
31616
31617- pgd = (pgd_t *)page_address(page) + pgd_index(address);
31618+ pgd += pgd_index(address);
31619 pud = pud_offset(pgd, address);
31620 pmd = pmd_offset(pud, address);
31621 set_pte_atomic((pte_t *)pmd, pte);
31622 }
31623 }
31624 #endif
31625+ pax_close_kernel();
31626 }
31627
31628 static int
31629diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
31630index 6574388..87e9bef 100644
31631--- a/arch/x86/mm/pat.c
31632+++ b/arch/x86/mm/pat.c
31633@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
31634
31635 if (!entry) {
31636 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
31637- current->comm, current->pid, start, end - 1);
31638+ current->comm, task_pid_nr(current), start, end - 1);
31639 return -EINVAL;
31640 }
31641
31642@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31643
31644 while (cursor < to) {
31645 if (!devmem_is_allowed(pfn)) {
31646- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
31647- current->comm, from, to - 1);
31648+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
31649+ current->comm, from, to - 1, cursor);
31650 return 0;
31651 }
31652 cursor += PAGE_SIZE;
31653@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
31654 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
31655 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
31656 "for [mem %#010Lx-%#010Lx]\n",
31657- current->comm, current->pid,
31658+ current->comm, task_pid_nr(current),
31659 cattr_name(flags),
31660 base, (unsigned long long)(base + size-1));
31661 return -EINVAL;
31662@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31663 flags = lookup_memtype(paddr);
31664 if (want_flags != flags) {
31665 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
31666- current->comm, current->pid,
31667+ current->comm, task_pid_nr(current),
31668 cattr_name(want_flags),
31669 (unsigned long long)paddr,
31670 (unsigned long long)(paddr + size - 1),
31671@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31672 free_memtype(paddr, paddr + size);
31673 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
31674 " for [mem %#010Lx-%#010Lx], got %s\n",
31675- current->comm, current->pid,
31676+ current->comm, task_pid_nr(current),
31677 cattr_name(want_flags),
31678 (unsigned long long)paddr,
31679 (unsigned long long)(paddr + size - 1),
31680diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
31681index 415f6c4..d319983 100644
31682--- a/arch/x86/mm/pat_rbtree.c
31683+++ b/arch/x86/mm/pat_rbtree.c
31684@@ -160,7 +160,7 @@ success:
31685
31686 failure:
31687 printk(KERN_INFO "%s:%d conflicting memory types "
31688- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
31689+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
31690 end, cattr_name(found_type), cattr_name(match->type));
31691 return -EBUSY;
31692 }
31693diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
31694index 9f0614d..92ae64a 100644
31695--- a/arch/x86/mm/pf_in.c
31696+++ b/arch/x86/mm/pf_in.c
31697@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
31698 int i;
31699 enum reason_type rv = OTHERS;
31700
31701- p = (unsigned char *)ins_addr;
31702+ p = (unsigned char *)ktla_ktva(ins_addr);
31703 p += skip_prefix(p, &prf);
31704 p += get_opcode(p, &opcode);
31705
31706@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
31707 struct prefix_bits prf;
31708 int i;
31709
31710- p = (unsigned char *)ins_addr;
31711+ p = (unsigned char *)ktla_ktva(ins_addr);
31712 p += skip_prefix(p, &prf);
31713 p += get_opcode(p, &opcode);
31714
31715@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
31716 struct prefix_bits prf;
31717 int i;
31718
31719- p = (unsigned char *)ins_addr;
31720+ p = (unsigned char *)ktla_ktva(ins_addr);
31721 p += skip_prefix(p, &prf);
31722 p += get_opcode(p, &opcode);
31723
31724@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
31725 struct prefix_bits prf;
31726 int i;
31727
31728- p = (unsigned char *)ins_addr;
31729+ p = (unsigned char *)ktla_ktva(ins_addr);
31730 p += skip_prefix(p, &prf);
31731 p += get_opcode(p, &opcode);
31732 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
31733@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
31734 struct prefix_bits prf;
31735 int i;
31736
31737- p = (unsigned char *)ins_addr;
31738+ p = (unsigned char *)ktla_ktva(ins_addr);
31739 p += skip_prefix(p, &prf);
31740 p += get_opcode(p, &opcode);
31741 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
31742diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
31743index dfa537a..fd45c64 100644
31744--- a/arch/x86/mm/pgtable.c
31745+++ b/arch/x86/mm/pgtable.c
31746@@ -91,10 +91,67 @@ static inline void pgd_list_del(pgd_t *pgd)
31747 list_del(&page->lru);
31748 }
31749
31750-#define UNSHARED_PTRS_PER_PGD \
31751- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31752+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31753+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
31754
31755+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
31756+{
31757+ unsigned int count = USER_PGD_PTRS;
31758
31759+ if (!pax_user_shadow_base)
31760+ return;
31761+
31762+ while (count--)
31763+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
31764+}
31765+#endif
31766+
31767+#ifdef CONFIG_PAX_PER_CPU_PGD
31768+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
31769+{
31770+ unsigned int count = USER_PGD_PTRS;
31771+
31772+ while (count--) {
31773+ pgd_t pgd;
31774+
31775+#ifdef CONFIG_X86_64
31776+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
31777+#else
31778+ pgd = *src++;
31779+#endif
31780+
31781+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31782+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
31783+#endif
31784+
31785+ *dst++ = pgd;
31786+ }
31787+
31788+}
31789+#endif
31790+
31791+#ifdef CONFIG_X86_64
31792+#define pxd_t pud_t
31793+#define pyd_t pgd_t
31794+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
31795+#define pxd_free(mm, pud) pud_free((mm), (pud))
31796+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
31797+#define pyd_offset(mm, address) pgd_offset((mm), (address))
31798+#define PYD_SIZE PGDIR_SIZE
31799+#else
31800+#define pxd_t pmd_t
31801+#define pyd_t pud_t
31802+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
31803+#define pxd_free(mm, pud) pmd_free((mm), (pud))
31804+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
31805+#define pyd_offset(mm, address) pud_offset((mm), (address))
31806+#define PYD_SIZE PUD_SIZE
31807+#endif
31808+
31809+#ifdef CONFIG_PAX_PER_CPU_PGD
31810+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
31811+static inline void pgd_dtor(pgd_t *pgd) {}
31812+#else
31813 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
31814 {
31815 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
31816@@ -135,6 +192,7 @@ static void pgd_dtor(pgd_t *pgd)
31817 pgd_list_del(pgd);
31818 spin_unlock(&pgd_lock);
31819 }
31820+#endif
31821
31822 /*
31823 * List of all pgd's needed for non-PAE so it can invalidate entries
31824@@ -147,7 +205,7 @@ static void pgd_dtor(pgd_t *pgd)
31825 * -- nyc
31826 */
31827
31828-#ifdef CONFIG_X86_PAE
31829+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
31830 /*
31831 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
31832 * updating the top-level pagetable entries to guarantee the
31833@@ -159,7 +217,7 @@ static void pgd_dtor(pgd_t *pgd)
31834 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
31835 * and initialize the kernel pmds here.
31836 */
31837-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
31838+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31839
31840 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31841 {
31842@@ -177,36 +235,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31843 */
31844 flush_tlb_mm(mm);
31845 }
31846+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
31847+#define PREALLOCATED_PXDS USER_PGD_PTRS
31848 #else /* !CONFIG_X86_PAE */
31849
31850 /* No need to prepopulate any pagetable entries in non-PAE modes. */
31851-#define PREALLOCATED_PMDS 0
31852+#define PREALLOCATED_PXDS 0
31853
31854 #endif /* CONFIG_X86_PAE */
31855
31856-static void free_pmds(pmd_t *pmds[])
31857+static void free_pxds(pxd_t *pxds[])
31858 {
31859 int i;
31860
31861- for(i = 0; i < PREALLOCATED_PMDS; i++)
31862- if (pmds[i])
31863- free_page((unsigned long)pmds[i]);
31864+ for(i = 0; i < PREALLOCATED_PXDS; i++)
31865+ if (pxds[i])
31866+ free_page((unsigned long)pxds[i]);
31867 }
31868
31869-static int preallocate_pmds(pmd_t *pmds[])
31870+static int preallocate_pxds(pxd_t *pxds[])
31871 {
31872 int i;
31873 bool failed = false;
31874
31875- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31876- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
31877- if (pmd == NULL)
31878+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31879+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
31880+ if (pxd == NULL)
31881 failed = true;
31882- pmds[i] = pmd;
31883+ pxds[i] = pxd;
31884 }
31885
31886 if (failed) {
31887- free_pmds(pmds);
31888+ free_pxds(pxds);
31889 return -ENOMEM;
31890 }
31891
31892@@ -219,49 +279,52 @@ static int preallocate_pmds(pmd_t *pmds[])
31893 * preallocate which never got a corresponding vma will need to be
31894 * freed manually.
31895 */
31896-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
31897+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
31898 {
31899 int i;
31900
31901- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31902+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31903 pgd_t pgd = pgdp[i];
31904
31905 if (pgd_val(pgd) != 0) {
31906- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
31907+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
31908
31909- pgdp[i] = native_make_pgd(0);
31910+ set_pgd(pgdp + i, native_make_pgd(0));
31911
31912- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
31913- pmd_free(mm, pmd);
31914+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
31915+ pxd_free(mm, pxd);
31916 }
31917 }
31918 }
31919
31920-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
31921+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
31922 {
31923- pud_t *pud;
31924+ pyd_t *pyd;
31925 int i;
31926
31927- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
31928+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
31929 return;
31930
31931- pud = pud_offset(pgd, 0);
31932-
31933- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
31934- pmd_t *pmd = pmds[i];
31935+#ifdef CONFIG_X86_64
31936+ pyd = pyd_offset(mm, 0L);
31937+#else
31938+ pyd = pyd_offset(pgd, 0L);
31939+#endif
31940
31941+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
31942+ pxd_t *pxd = pxds[i];
31943 if (i >= KERNEL_PGD_BOUNDARY)
31944- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
31945- sizeof(pmd_t) * PTRS_PER_PMD);
31946+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
31947+ sizeof(pxd_t) * PTRS_PER_PMD);
31948
31949- pud_populate(mm, pud, pmd);
31950+ pyd_populate(mm, pyd, pxd);
31951 }
31952 }
31953
31954 pgd_t *pgd_alloc(struct mm_struct *mm)
31955 {
31956 pgd_t *pgd;
31957- pmd_t *pmds[PREALLOCATED_PMDS];
31958+ pxd_t *pxds[PREALLOCATED_PXDS];
31959
31960 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
31961
31962@@ -270,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
31963
31964 mm->pgd = pgd;
31965
31966- if (preallocate_pmds(pmds) != 0)
31967+ if (preallocate_pxds(pxds) != 0)
31968 goto out_free_pgd;
31969
31970 if (paravirt_pgd_alloc(mm) != 0)
31971- goto out_free_pmds;
31972+ goto out_free_pxds;
31973
31974 /*
31975 * Make sure that pre-populating the pmds is atomic with
31976@@ -284,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
31977 spin_lock(&pgd_lock);
31978
31979 pgd_ctor(mm, pgd);
31980- pgd_prepopulate_pmd(mm, pgd, pmds);
31981+ pgd_prepopulate_pxd(mm, pgd, pxds);
31982
31983 spin_unlock(&pgd_lock);
31984
31985 return pgd;
31986
31987-out_free_pmds:
31988- free_pmds(pmds);
31989+out_free_pxds:
31990+ free_pxds(pxds);
31991 out_free_pgd:
31992 free_page((unsigned long)pgd);
31993 out:
31994@@ -300,7 +363,7 @@ out:
31995
31996 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
31997 {
31998- pgd_mop_up_pmds(mm, pgd);
31999+ pgd_mop_up_pxds(mm, pgd);
32000 pgd_dtor(pgd);
32001 paravirt_pgd_free(mm, pgd);
32002 free_page((unsigned long)pgd);
32003diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
32004index a69bcb8..19068ab 100644
32005--- a/arch/x86/mm/pgtable_32.c
32006+++ b/arch/x86/mm/pgtable_32.c
32007@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
32008 return;
32009 }
32010 pte = pte_offset_kernel(pmd, vaddr);
32011+
32012+ pax_open_kernel();
32013 if (pte_val(pteval))
32014 set_pte_at(&init_mm, vaddr, pte, pteval);
32015 else
32016 pte_clear(&init_mm, vaddr, pte);
32017+ pax_close_kernel();
32018
32019 /*
32020 * It's enough to flush this one mapping.
32021diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
32022index e666cbb..61788c45 100644
32023--- a/arch/x86/mm/physaddr.c
32024+++ b/arch/x86/mm/physaddr.c
32025@@ -10,7 +10,7 @@
32026 #ifdef CONFIG_X86_64
32027
32028 #ifdef CONFIG_DEBUG_VIRTUAL
32029-unsigned long __phys_addr(unsigned long x)
32030+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32031 {
32032 unsigned long y = x - __START_KERNEL_map;
32033
32034@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
32035 #else
32036
32037 #ifdef CONFIG_DEBUG_VIRTUAL
32038-unsigned long __phys_addr(unsigned long x)
32039+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32040 {
32041 unsigned long phys_addr = x - PAGE_OFFSET;
32042 /* VMALLOC_* aren't constants */
32043diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
32044index 90555bf..f5f1828 100644
32045--- a/arch/x86/mm/setup_nx.c
32046+++ b/arch/x86/mm/setup_nx.c
32047@@ -5,8 +5,10 @@
32048 #include <asm/pgtable.h>
32049 #include <asm/proto.h>
32050
32051+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32052 static int disable_nx;
32053
32054+#ifndef CONFIG_PAX_PAGEEXEC
32055 /*
32056 * noexec = on|off
32057 *
32058@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
32059 return 0;
32060 }
32061 early_param("noexec", noexec_setup);
32062+#endif
32063+
32064+#endif
32065
32066 void x86_configure_nx(void)
32067 {
32068+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32069 if (cpu_has_nx && !disable_nx)
32070 __supported_pte_mask |= _PAGE_NX;
32071 else
32072+#endif
32073 __supported_pte_mask &= ~_PAGE_NX;
32074 }
32075
32076diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
32077index 282375f..e03a98f 100644
32078--- a/arch/x86/mm/tlb.c
32079+++ b/arch/x86/mm/tlb.c
32080@@ -48,7 +48,11 @@ void leave_mm(int cpu)
32081 BUG();
32082 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
32083 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
32084+
32085+#ifndef CONFIG_PAX_PER_CPU_PGD
32086 load_cr3(swapper_pg_dir);
32087+#endif
32088+
32089 }
32090 }
32091 EXPORT_SYMBOL_GPL(leave_mm);
32092diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
32093new file mode 100644
32094index 0000000..dace51c
32095--- /dev/null
32096+++ b/arch/x86/mm/uderef_64.c
32097@@ -0,0 +1,37 @@
32098+#include <linux/mm.h>
32099+#include <asm/pgtable.h>
32100+#include <asm/uaccess.h>
32101+
32102+#ifdef CONFIG_PAX_MEMORY_UDEREF
32103+/* PaX: due to the special call convention these functions must
32104+ * - remain leaf functions under all configurations,
32105+ * - never be called directly, only dereferenced from the wrappers.
32106+ */
32107+void __pax_open_userland(void)
32108+{
32109+ unsigned int cpu;
32110+
32111+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32112+ return;
32113+
32114+ cpu = raw_get_cpu();
32115+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
32116+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
32117+ raw_put_cpu_no_resched();
32118+}
32119+EXPORT_SYMBOL(__pax_open_userland);
32120+
32121+void __pax_close_userland(void)
32122+{
32123+ unsigned int cpu;
32124+
32125+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32126+ return;
32127+
32128+ cpu = raw_get_cpu();
32129+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
32130+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
32131+ raw_put_cpu_no_resched();
32132+}
32133+EXPORT_SYMBOL(__pax_close_userland);
32134+#endif
32135diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
32136index 877b9a1..a8ecf42 100644
32137--- a/arch/x86/net/bpf_jit.S
32138+++ b/arch/x86/net/bpf_jit.S
32139@@ -9,6 +9,7 @@
32140 */
32141 #include <linux/linkage.h>
32142 #include <asm/dwarf2.h>
32143+#include <asm/alternative-asm.h>
32144
32145 /*
32146 * Calling convention :
32147@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
32148 jle bpf_slow_path_word
32149 mov (SKBDATA,%rsi),%eax
32150 bswap %eax /* ntohl() */
32151+ pax_force_retaddr
32152 ret
32153
32154 sk_load_half:
32155@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
32156 jle bpf_slow_path_half
32157 movzwl (SKBDATA,%rsi),%eax
32158 rol $8,%ax # ntohs()
32159+ pax_force_retaddr
32160 ret
32161
32162 sk_load_byte:
32163@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
32164 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
32165 jle bpf_slow_path_byte
32166 movzbl (SKBDATA,%rsi),%eax
32167+ pax_force_retaddr
32168 ret
32169
32170 /**
32171@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
32172 movzbl (SKBDATA,%rsi),%ebx
32173 and $15,%bl
32174 shl $2,%bl
32175+ pax_force_retaddr
32176 ret
32177
32178 /* rsi contains offset and can be scratched */
32179@@ -109,6 +114,7 @@ bpf_slow_path_word:
32180 js bpf_error
32181 mov -12(%rbp),%eax
32182 bswap %eax
32183+ pax_force_retaddr
32184 ret
32185
32186 bpf_slow_path_half:
32187@@ -117,12 +123,14 @@ bpf_slow_path_half:
32188 mov -12(%rbp),%ax
32189 rol $8,%ax
32190 movzwl %ax,%eax
32191+ pax_force_retaddr
32192 ret
32193
32194 bpf_slow_path_byte:
32195 bpf_slow_path_common(1)
32196 js bpf_error
32197 movzbl -12(%rbp),%eax
32198+ pax_force_retaddr
32199 ret
32200
32201 bpf_slow_path_byte_msh:
32202@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
32203 and $15,%al
32204 shl $2,%al
32205 xchg %eax,%ebx
32206+ pax_force_retaddr
32207 ret
32208
32209 #define sk_negative_common(SIZE) \
32210@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
32211 sk_negative_common(4)
32212 mov (%rax), %eax
32213 bswap %eax
32214+ pax_force_retaddr
32215 ret
32216
32217 bpf_slow_path_half_neg:
32218@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
32219 mov (%rax),%ax
32220 rol $8,%ax
32221 movzwl %ax,%eax
32222+ pax_force_retaddr
32223 ret
32224
32225 bpf_slow_path_byte_neg:
32226@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
32227 .globl sk_load_byte_negative_offset
32228 sk_negative_common(1)
32229 movzbl (%rax), %eax
32230+ pax_force_retaddr
32231 ret
32232
32233 bpf_slow_path_byte_msh_neg:
32234@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
32235 and $15,%al
32236 shl $2,%al
32237 xchg %eax,%ebx
32238+ pax_force_retaddr
32239 ret
32240
32241 bpf_error:
32242@@ -197,4 +210,5 @@ bpf_error:
32243 xor %eax,%eax
32244 mov -8(%rbp),%rbx
32245 leaveq
32246+ pax_force_retaddr
32247 ret
32248diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
32249index 79c216a..08d39cc 100644
32250--- a/arch/x86/net/bpf_jit_comp.c
32251+++ b/arch/x86/net/bpf_jit_comp.c
32252@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
32253 return ptr + len;
32254 }
32255
32256+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32257+#define MAX_INSTR_CODE_SIZE 96
32258+#else
32259+#define MAX_INSTR_CODE_SIZE 64
32260+#endif
32261+
32262 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
32263
32264 #define EMIT1(b1) EMIT(b1, 1)
32265 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
32266 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
32267 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
32268+
32269+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32270+/* original constant will appear in ecx */
32271+#define DILUTE_CONST_SEQUENCE(_off, _key) \
32272+do { \
32273+ /* mov ecx, randkey */ \
32274+ EMIT1(0xb9); \
32275+ EMIT(_key, 4); \
32276+ /* xor ecx, randkey ^ off */ \
32277+ EMIT2(0x81, 0xf1); \
32278+ EMIT((_key) ^ (_off), 4); \
32279+} while (0)
32280+
32281+#define EMIT1_off32(b1, _off) \
32282+do { \
32283+ switch (b1) { \
32284+ case 0x05: /* add eax, imm32 */ \
32285+ case 0x2d: /* sub eax, imm32 */ \
32286+ case 0x25: /* and eax, imm32 */ \
32287+ case 0x0d: /* or eax, imm32 */ \
32288+ case 0xb8: /* mov eax, imm32 */ \
32289+ case 0x35: /* xor eax, imm32 */ \
32290+ case 0x3d: /* cmp eax, imm32 */ \
32291+ case 0xa9: /* test eax, imm32 */ \
32292+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32293+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
32294+ break; \
32295+ case 0xbb: /* mov ebx, imm32 */ \
32296+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32297+ /* mov ebx, ecx */ \
32298+ EMIT2(0x89, 0xcb); \
32299+ break; \
32300+ case 0xbe: /* mov esi, imm32 */ \
32301+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32302+ /* mov esi, ecx */ \
32303+ EMIT2(0x89, 0xce); \
32304+ break; \
32305+ case 0xe8: /* call rel imm32, always to known funcs */ \
32306+ EMIT1(b1); \
32307+ EMIT(_off, 4); \
32308+ break; \
32309+ case 0xe9: /* jmp rel imm32 */ \
32310+ EMIT1(b1); \
32311+ EMIT(_off, 4); \
32312+ /* prevent fall-through, we're not called if off = 0 */ \
32313+ EMIT(0xcccccccc, 4); \
32314+ EMIT(0xcccccccc, 4); \
32315+ break; \
32316+ default: \
32317+ BUILD_BUG(); \
32318+ } \
32319+} while (0)
32320+
32321+#define EMIT2_off32(b1, b2, _off) \
32322+do { \
32323+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
32324+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
32325+ EMIT(randkey, 4); \
32326+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
32327+ EMIT((_off) - randkey, 4); \
32328+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
32329+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32330+ /* imul eax, ecx */ \
32331+ EMIT3(0x0f, 0xaf, 0xc1); \
32332+ } else { \
32333+ BUILD_BUG(); \
32334+ } \
32335+} while (0)
32336+#else
32337 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
32338+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
32339+#endif
32340
32341 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
32342 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
32343@@ -91,6 +168,24 @@ do { \
32344 #define X86_JBE 0x76
32345 #define X86_JA 0x77
32346
32347+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32348+#define APPEND_FLOW_VERIFY() \
32349+do { \
32350+ /* mov ecx, randkey */ \
32351+ EMIT1(0xb9); \
32352+ EMIT(randkey, 4); \
32353+ /* cmp ecx, randkey */ \
32354+ EMIT2(0x81, 0xf9); \
32355+ EMIT(randkey, 4); \
32356+ /* jz after 8 int 3s */ \
32357+ EMIT2(0x74, 0x08); \
32358+ EMIT(0xcccccccc, 4); \
32359+ EMIT(0xcccccccc, 4); \
32360+} while (0)
32361+#else
32362+#define APPEND_FLOW_VERIFY() do { } while (0)
32363+#endif
32364+
32365 #define EMIT_COND_JMP(op, offset) \
32366 do { \
32367 if (is_near(offset)) \
32368@@ -98,6 +193,7 @@ do { \
32369 else { \
32370 EMIT2(0x0f, op + 0x10); \
32371 EMIT(offset, 4); /* jxx .+off32 */ \
32372+ APPEND_FLOW_VERIFY(); \
32373 } \
32374 } while (0)
32375
32376@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
32377 return -1;
32378 }
32379
32380-struct bpf_binary_header {
32381- unsigned int pages;
32382- /* Note : for security reasons, bpf code will follow a randomly
32383- * sized amount of int3 instructions
32384- */
32385- u8 image[];
32386-};
32387-
32388-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
32389+/* Note : for security reasons, bpf code will follow a randomly
32390+ * sized amount of int3 instructions
32391+ */
32392+static u8 *bpf_alloc_binary(unsigned int proglen,
32393 u8 **image_ptr)
32394 {
32395 unsigned int sz, hole;
32396- struct bpf_binary_header *header;
32397+ u8 *header;
32398
32399 /* Most of BPF filters are really small,
32400 * but if some of them fill a page, allow at least
32401 * 128 extra bytes to insert a random section of int3
32402 */
32403- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
32404- header = module_alloc(sz);
32405+ sz = round_up(proglen + 128, PAGE_SIZE);
32406+ header = module_alloc_exec(sz);
32407 if (!header)
32408 return NULL;
32409
32410+ pax_open_kernel();
32411 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
32412+ pax_close_kernel();
32413
32414- header->pages = sz / PAGE_SIZE;
32415- hole = sz - (proglen + sizeof(*header));
32416+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
32417
32418 /* insert a random number of int3 instructions before BPF code */
32419- *image_ptr = &header->image[prandom_u32() % hole];
32420+ *image_ptr = &header[prandom_u32() % hole];
32421 return header;
32422 }
32423
32424 void bpf_jit_compile(struct sk_filter *fp)
32425 {
32426- u8 temp[64];
32427+ u8 temp[MAX_INSTR_CODE_SIZE];
32428 u8 *prog;
32429 unsigned int proglen, oldproglen = 0;
32430 int ilen, i;
32431 int t_offset, f_offset;
32432 u8 t_op, f_op, seen = 0, pass;
32433 u8 *image = NULL;
32434- struct bpf_binary_header *header = NULL;
32435+ u8 *header = NULL;
32436 u8 *func;
32437 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
32438 unsigned int cleanup_addr; /* epilogue code offset */
32439 unsigned int *addrs;
32440 const struct sock_filter *filter = fp->insns;
32441 int flen = fp->len;
32442+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32443+ unsigned int randkey;
32444+#endif
32445
32446 if (!bpf_jit_enable)
32447 return;
32448@@ -202,11 +297,15 @@ void bpf_jit_compile(struct sk_filter *fp)
32449 if (addrs == NULL)
32450 return;
32451
32452+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32453+ randkey = get_random_int();
32454+#endif
32455+
32456 /* Before first pass, make a rough estimation of addrs[]
32457- * each bpf instruction is translated to less than 64 bytes
32458+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
32459 */
32460 for (proglen = 0, i = 0; i < flen; i++) {
32461- proglen += 64;
32462+ proglen += MAX_INSTR_CODE_SIZE;
32463 addrs[i] = proglen;
32464 }
32465 cleanup_addr = proglen; /* epilogue address */
32466@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
32467 case BPF_S_ALU_MUL_K: /* A *= K */
32468 if (is_imm8(K))
32469 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
32470- else {
32471- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
32472- EMIT(K, 4);
32473- }
32474+ else
32475+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
32476 break;
32477 case BPF_S_ALU_DIV_X: /* A /= X; */
32478 seen |= SEEN_XREG;
32479@@ -360,13 +457,23 @@ void bpf_jit_compile(struct sk_filter *fp)
32480 break;
32481 case BPF_S_ALU_MOD_K: /* A %= K; */
32482 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
32483+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32484+ DILUTE_CONST_SEQUENCE(K, randkey);
32485+#else
32486 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
32487+#endif
32488 EMIT2(0xf7, 0xf1); /* div %ecx */
32489 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
32490 break;
32491 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
32492+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32493+ DILUTE_CONST_SEQUENCE(K, randkey);
32494+ // imul rax, rcx
32495+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
32496+#else
32497 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
32498 EMIT(K, 4);
32499+#endif
32500 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
32501 break;
32502 case BPF_S_ALU_AND_X:
32503@@ -637,8 +744,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
32504 if (is_imm8(K)) {
32505 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
32506 } else {
32507- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
32508- EMIT(K, 4);
32509+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
32510 }
32511 } else {
32512 EMIT2(0x89,0xde); /* mov %ebx,%esi */
32513@@ -728,10 +834,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32514 if (unlikely(proglen + ilen > oldproglen)) {
32515 pr_err("bpb_jit_compile fatal error\n");
32516 kfree(addrs);
32517- module_free(NULL, header);
32518+ module_free_exec(NULL, image);
32519 return;
32520 }
32521+ pax_open_kernel();
32522 memcpy(image + proglen, temp, ilen);
32523+ pax_close_kernel();
32524 }
32525 proglen += ilen;
32526 addrs[i] = proglen;
32527@@ -764,7 +872,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32528
32529 if (image) {
32530 bpf_flush_icache(header, image + proglen);
32531- set_memory_ro((unsigned long)header, header->pages);
32532 fp->bpf_func = (void *)image;
32533 }
32534 out:
32535@@ -776,9 +883,7 @@ void bpf_jit_free(struct sk_filter *fp)
32536 {
32537 if (fp->bpf_func != sk_run_filter) {
32538 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
32539- struct bpf_binary_header *header = (void *)addr;
32540-
32541- set_memory_rw(addr, header->pages);
32542- module_free(NULL, header);
32543+ set_memory_rw(addr, 1);
32544+ module_free_exec(NULL, (void *)addr);
32545 }
32546 }
32547diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
32548index d6aa6e8..266395a 100644
32549--- a/arch/x86/oprofile/backtrace.c
32550+++ b/arch/x86/oprofile/backtrace.c
32551@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
32552 struct stack_frame_ia32 *fp;
32553 unsigned long bytes;
32554
32555- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32556+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32557 if (bytes != sizeof(bufhead))
32558 return NULL;
32559
32560- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
32561+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
32562
32563 oprofile_add_trace(bufhead[0].return_address);
32564
32565@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
32566 struct stack_frame bufhead[2];
32567 unsigned long bytes;
32568
32569- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32570+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32571 if (bytes != sizeof(bufhead))
32572 return NULL;
32573
32574@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
32575 {
32576 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
32577
32578- if (!user_mode_vm(regs)) {
32579+ if (!user_mode(regs)) {
32580 unsigned long stack = kernel_stack_pointer(regs);
32581 if (depth)
32582 dump_trace(NULL, regs, (unsigned long *)stack, 0,
32583diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
32584index 48768df..ba9143c 100644
32585--- a/arch/x86/oprofile/nmi_int.c
32586+++ b/arch/x86/oprofile/nmi_int.c
32587@@ -23,6 +23,7 @@
32588 #include <asm/nmi.h>
32589 #include <asm/msr.h>
32590 #include <asm/apic.h>
32591+#include <asm/pgtable.h>
32592
32593 #include "op_counter.h"
32594 #include "op_x86_model.h"
32595@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
32596 if (ret)
32597 return ret;
32598
32599- if (!model->num_virt_counters)
32600- model->num_virt_counters = model->num_counters;
32601+ if (!model->num_virt_counters) {
32602+ pax_open_kernel();
32603+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
32604+ pax_close_kernel();
32605+ }
32606
32607 mux_init(ops);
32608
32609diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
32610index b2b9443..be58856 100644
32611--- a/arch/x86/oprofile/op_model_amd.c
32612+++ b/arch/x86/oprofile/op_model_amd.c
32613@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
32614 num_counters = AMD64_NUM_COUNTERS;
32615 }
32616
32617- op_amd_spec.num_counters = num_counters;
32618- op_amd_spec.num_controls = num_counters;
32619- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32620+ pax_open_kernel();
32621+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
32622+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
32623+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32624+ pax_close_kernel();
32625
32626 return 0;
32627 }
32628diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
32629index d90528e..0127e2b 100644
32630--- a/arch/x86/oprofile/op_model_ppro.c
32631+++ b/arch/x86/oprofile/op_model_ppro.c
32632@@ -19,6 +19,7 @@
32633 #include <asm/msr.h>
32634 #include <asm/apic.h>
32635 #include <asm/nmi.h>
32636+#include <asm/pgtable.h>
32637
32638 #include "op_x86_model.h"
32639 #include "op_counter.h"
32640@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
32641
32642 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
32643
32644- op_arch_perfmon_spec.num_counters = num_counters;
32645- op_arch_perfmon_spec.num_controls = num_counters;
32646+ pax_open_kernel();
32647+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
32648+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
32649+ pax_close_kernel();
32650 }
32651
32652 static int arch_perfmon_init(struct oprofile_operations *ignore)
32653diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
32654index 71e8a67..6a313bb 100644
32655--- a/arch/x86/oprofile/op_x86_model.h
32656+++ b/arch/x86/oprofile/op_x86_model.h
32657@@ -52,7 +52,7 @@ struct op_x86_model_spec {
32658 void (*switch_ctrl)(struct op_x86_model_spec const *model,
32659 struct op_msrs const * const msrs);
32660 #endif
32661-};
32662+} __do_const;
32663
32664 struct op_counter_config;
32665
32666diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
32667index 372e9b8..e775a6c 100644
32668--- a/arch/x86/pci/irq.c
32669+++ b/arch/x86/pci/irq.c
32670@@ -50,7 +50,7 @@ struct irq_router {
32671 struct irq_router_handler {
32672 u16 vendor;
32673 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
32674-};
32675+} __do_const;
32676
32677 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
32678 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
32679@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
32680 return 0;
32681 }
32682
32683-static __initdata struct irq_router_handler pirq_routers[] = {
32684+static __initconst const struct irq_router_handler pirq_routers[] = {
32685 { PCI_VENDOR_ID_INTEL, intel_router_probe },
32686 { PCI_VENDOR_ID_AL, ali_router_probe },
32687 { PCI_VENDOR_ID_ITE, ite_router_probe },
32688@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
32689 static void __init pirq_find_router(struct irq_router *r)
32690 {
32691 struct irq_routing_table *rt = pirq_table;
32692- struct irq_router_handler *h;
32693+ const struct irq_router_handler *h;
32694
32695 #ifdef CONFIG_PCI_BIOS
32696 if (!rt->signature) {
32697@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
32698 return 0;
32699 }
32700
32701-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
32702+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
32703 {
32704 .callback = fix_broken_hp_bios_irq9,
32705 .ident = "HP Pavilion N5400 Series Laptop",
32706diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
32707index 6eb18c4..20d83de 100644
32708--- a/arch/x86/pci/mrst.c
32709+++ b/arch/x86/pci/mrst.c
32710@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
32711 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
32712 pci_mmcfg_late_init();
32713 pcibios_enable_irq = mrst_pci_irq_enable;
32714- pci_root_ops = pci_mrst_ops;
32715+ pax_open_kernel();
32716+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
32717+ pax_close_kernel();
32718 pci_soc_mode = 1;
32719 /* Continue with standard init */
32720 return 1;
32721diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
32722index c77b24a..c979855 100644
32723--- a/arch/x86/pci/pcbios.c
32724+++ b/arch/x86/pci/pcbios.c
32725@@ -79,7 +79,7 @@ union bios32 {
32726 static struct {
32727 unsigned long address;
32728 unsigned short segment;
32729-} bios32_indirect = { 0, __KERNEL_CS };
32730+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
32731
32732 /*
32733 * Returns the entry point for the given service, NULL on error
32734@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
32735 unsigned long length; /* %ecx */
32736 unsigned long entry; /* %edx */
32737 unsigned long flags;
32738+ struct desc_struct d, *gdt;
32739
32740 local_irq_save(flags);
32741- __asm__("lcall *(%%edi); cld"
32742+
32743+ gdt = get_cpu_gdt_table(smp_processor_id());
32744+
32745+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
32746+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32747+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
32748+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32749+
32750+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
32751 : "=a" (return_code),
32752 "=b" (address),
32753 "=c" (length),
32754 "=d" (entry)
32755 : "0" (service),
32756 "1" (0),
32757- "D" (&bios32_indirect));
32758+ "D" (&bios32_indirect),
32759+ "r"(__PCIBIOS_DS)
32760+ : "memory");
32761+
32762+ pax_open_kernel();
32763+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
32764+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
32765+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
32766+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
32767+ pax_close_kernel();
32768+
32769 local_irq_restore(flags);
32770
32771 switch (return_code) {
32772- case 0:
32773- return address + entry;
32774- case 0x80: /* Not present */
32775- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32776- return 0;
32777- default: /* Shouldn't happen */
32778- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32779- service, return_code);
32780+ case 0: {
32781+ int cpu;
32782+ unsigned char flags;
32783+
32784+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
32785+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
32786+ printk(KERN_WARNING "bios32_service: not valid\n");
32787 return 0;
32788+ }
32789+ address = address + PAGE_OFFSET;
32790+ length += 16UL; /* some BIOSs underreport this... */
32791+ flags = 4;
32792+ if (length >= 64*1024*1024) {
32793+ length >>= PAGE_SHIFT;
32794+ flags |= 8;
32795+ }
32796+
32797+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32798+ gdt = get_cpu_gdt_table(cpu);
32799+ pack_descriptor(&d, address, length, 0x9b, flags);
32800+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32801+ pack_descriptor(&d, address, length, 0x93, flags);
32802+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32803+ }
32804+ return entry;
32805+ }
32806+ case 0x80: /* Not present */
32807+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32808+ return 0;
32809+ default: /* Shouldn't happen */
32810+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32811+ service, return_code);
32812+ return 0;
32813 }
32814 }
32815
32816 static struct {
32817 unsigned long address;
32818 unsigned short segment;
32819-} pci_indirect = { 0, __KERNEL_CS };
32820+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
32821
32822-static int pci_bios_present;
32823+static int pci_bios_present __read_only;
32824
32825 static int check_pcibios(void)
32826 {
32827@@ -131,11 +174,13 @@ static int check_pcibios(void)
32828 unsigned long flags, pcibios_entry;
32829
32830 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
32831- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
32832+ pci_indirect.address = pcibios_entry;
32833
32834 local_irq_save(flags);
32835- __asm__(
32836- "lcall *(%%edi); cld\n\t"
32837+ __asm__("movw %w6, %%ds\n\t"
32838+ "lcall *%%ss:(%%edi); cld\n\t"
32839+ "push %%ss\n\t"
32840+ "pop %%ds\n\t"
32841 "jc 1f\n\t"
32842 "xor %%ah, %%ah\n"
32843 "1:"
32844@@ -144,7 +189,8 @@ static int check_pcibios(void)
32845 "=b" (ebx),
32846 "=c" (ecx)
32847 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
32848- "D" (&pci_indirect)
32849+ "D" (&pci_indirect),
32850+ "r" (__PCIBIOS_DS)
32851 : "memory");
32852 local_irq_restore(flags);
32853
32854@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32855
32856 switch (len) {
32857 case 1:
32858- __asm__("lcall *(%%esi); cld\n\t"
32859+ __asm__("movw %w6, %%ds\n\t"
32860+ "lcall *%%ss:(%%esi); cld\n\t"
32861+ "push %%ss\n\t"
32862+ "pop %%ds\n\t"
32863 "jc 1f\n\t"
32864 "xor %%ah, %%ah\n"
32865 "1:"
32866@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32867 : "1" (PCIBIOS_READ_CONFIG_BYTE),
32868 "b" (bx),
32869 "D" ((long)reg),
32870- "S" (&pci_indirect));
32871+ "S" (&pci_indirect),
32872+ "r" (__PCIBIOS_DS));
32873 /*
32874 * Zero-extend the result beyond 8 bits, do not trust the
32875 * BIOS having done it:
32876@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32877 *value &= 0xff;
32878 break;
32879 case 2:
32880- __asm__("lcall *(%%esi); cld\n\t"
32881+ __asm__("movw %w6, %%ds\n\t"
32882+ "lcall *%%ss:(%%esi); cld\n\t"
32883+ "push %%ss\n\t"
32884+ "pop %%ds\n\t"
32885 "jc 1f\n\t"
32886 "xor %%ah, %%ah\n"
32887 "1:"
32888@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32889 : "1" (PCIBIOS_READ_CONFIG_WORD),
32890 "b" (bx),
32891 "D" ((long)reg),
32892- "S" (&pci_indirect));
32893+ "S" (&pci_indirect),
32894+ "r" (__PCIBIOS_DS));
32895 /*
32896 * Zero-extend the result beyond 16 bits, do not trust the
32897 * BIOS having done it:
32898@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32899 *value &= 0xffff;
32900 break;
32901 case 4:
32902- __asm__("lcall *(%%esi); cld\n\t"
32903+ __asm__("movw %w6, %%ds\n\t"
32904+ "lcall *%%ss:(%%esi); cld\n\t"
32905+ "push %%ss\n\t"
32906+ "pop %%ds\n\t"
32907 "jc 1f\n\t"
32908 "xor %%ah, %%ah\n"
32909 "1:"
32910@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32911 : "1" (PCIBIOS_READ_CONFIG_DWORD),
32912 "b" (bx),
32913 "D" ((long)reg),
32914- "S" (&pci_indirect));
32915+ "S" (&pci_indirect),
32916+ "r" (__PCIBIOS_DS));
32917 break;
32918 }
32919
32920@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32921
32922 switch (len) {
32923 case 1:
32924- __asm__("lcall *(%%esi); cld\n\t"
32925+ __asm__("movw %w6, %%ds\n\t"
32926+ "lcall *%%ss:(%%esi); cld\n\t"
32927+ "push %%ss\n\t"
32928+ "pop %%ds\n\t"
32929 "jc 1f\n\t"
32930 "xor %%ah, %%ah\n"
32931 "1:"
32932@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32933 "c" (value),
32934 "b" (bx),
32935 "D" ((long)reg),
32936- "S" (&pci_indirect));
32937+ "S" (&pci_indirect),
32938+ "r" (__PCIBIOS_DS));
32939 break;
32940 case 2:
32941- __asm__("lcall *(%%esi); cld\n\t"
32942+ __asm__("movw %w6, %%ds\n\t"
32943+ "lcall *%%ss:(%%esi); cld\n\t"
32944+ "push %%ss\n\t"
32945+ "pop %%ds\n\t"
32946 "jc 1f\n\t"
32947 "xor %%ah, %%ah\n"
32948 "1:"
32949@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32950 "c" (value),
32951 "b" (bx),
32952 "D" ((long)reg),
32953- "S" (&pci_indirect));
32954+ "S" (&pci_indirect),
32955+ "r" (__PCIBIOS_DS));
32956 break;
32957 case 4:
32958- __asm__("lcall *(%%esi); cld\n\t"
32959+ __asm__("movw %w6, %%ds\n\t"
32960+ "lcall *%%ss:(%%esi); cld\n\t"
32961+ "push %%ss\n\t"
32962+ "pop %%ds\n\t"
32963 "jc 1f\n\t"
32964 "xor %%ah, %%ah\n"
32965 "1:"
32966@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32967 "c" (value),
32968 "b" (bx),
32969 "D" ((long)reg),
32970- "S" (&pci_indirect));
32971+ "S" (&pci_indirect),
32972+ "r" (__PCIBIOS_DS));
32973 break;
32974 }
32975
32976@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
32977
32978 DBG("PCI: Fetching IRQ routing table... ");
32979 __asm__("push %%es\n\t"
32980+ "movw %w8, %%ds\n\t"
32981 "push %%ds\n\t"
32982 "pop %%es\n\t"
32983- "lcall *(%%esi); cld\n\t"
32984+ "lcall *%%ss:(%%esi); cld\n\t"
32985 "pop %%es\n\t"
32986+ "push %%ss\n\t"
32987+ "pop %%ds\n"
32988 "jc 1f\n\t"
32989 "xor %%ah, %%ah\n"
32990 "1:"
32991@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
32992 "1" (0),
32993 "D" ((long) &opt),
32994 "S" (&pci_indirect),
32995- "m" (opt)
32996+ "m" (opt),
32997+ "r" (__PCIBIOS_DS)
32998 : "memory");
32999 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
33000 if (ret & 0xff00)
33001@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33002 {
33003 int ret;
33004
33005- __asm__("lcall *(%%esi); cld\n\t"
33006+ __asm__("movw %w5, %%ds\n\t"
33007+ "lcall *%%ss:(%%esi); cld\n\t"
33008+ "push %%ss\n\t"
33009+ "pop %%ds\n"
33010 "jc 1f\n\t"
33011 "xor %%ah, %%ah\n"
33012 "1:"
33013@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33014 : "0" (PCIBIOS_SET_PCI_HW_INT),
33015 "b" ((dev->bus->number << 8) | dev->devfn),
33016 "c" ((irq << 8) | (pin + 10)),
33017- "S" (&pci_indirect));
33018+ "S" (&pci_indirect),
33019+ "r" (__PCIBIOS_DS));
33020 return !(ret & 0xff00);
33021 }
33022 EXPORT_SYMBOL(pcibios_set_irq_routing);
33023diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
33024index 40e4469..d915bf9 100644
33025--- a/arch/x86/platform/efi/efi_32.c
33026+++ b/arch/x86/platform/efi/efi_32.c
33027@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
33028 {
33029 struct desc_ptr gdt_descr;
33030
33031+#ifdef CONFIG_PAX_KERNEXEC
33032+ struct desc_struct d;
33033+#endif
33034+
33035 local_irq_save(efi_rt_eflags);
33036
33037 load_cr3(initial_page_table);
33038 __flush_tlb_all();
33039
33040+#ifdef CONFIG_PAX_KERNEXEC
33041+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
33042+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33043+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
33044+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33045+#endif
33046+
33047 gdt_descr.address = __pa(get_cpu_gdt_table(0));
33048 gdt_descr.size = GDT_SIZE - 1;
33049 load_gdt(&gdt_descr);
33050@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
33051 {
33052 struct desc_ptr gdt_descr;
33053
33054+#ifdef CONFIG_PAX_KERNEXEC
33055+ struct desc_struct d;
33056+
33057+ memset(&d, 0, sizeof d);
33058+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33059+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33060+#endif
33061+
33062 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
33063 gdt_descr.size = GDT_SIZE - 1;
33064 load_gdt(&gdt_descr);
33065
33066+#ifdef CONFIG_PAX_PER_CPU_PGD
33067+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33068+#else
33069 load_cr3(swapper_pg_dir);
33070+#endif
33071+
33072 __flush_tlb_all();
33073
33074 local_irq_restore(efi_rt_eflags);
33075diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
33076index 39a0e7f1..872396e 100644
33077--- a/arch/x86/platform/efi/efi_64.c
33078+++ b/arch/x86/platform/efi/efi_64.c
33079@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
33080 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
33081 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
33082 }
33083+
33084+#ifdef CONFIG_PAX_PER_CPU_PGD
33085+ load_cr3(swapper_pg_dir);
33086+#endif
33087+
33088 __flush_tlb_all();
33089 }
33090
33091@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
33092 for (pgd = 0; pgd < n_pgds; pgd++)
33093 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
33094 kfree(save_pgd);
33095+
33096+#ifdef CONFIG_PAX_PER_CPU_PGD
33097+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33098+#endif
33099+
33100 __flush_tlb_all();
33101 local_irq_restore(efi_flags);
33102 early_code_mapping_set_exec(0);
33103diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
33104index fbe66e6..eae5e38 100644
33105--- a/arch/x86/platform/efi/efi_stub_32.S
33106+++ b/arch/x86/platform/efi/efi_stub_32.S
33107@@ -6,7 +6,9 @@
33108 */
33109
33110 #include <linux/linkage.h>
33111+#include <linux/init.h>
33112 #include <asm/page_types.h>
33113+#include <asm/segment.h>
33114
33115 /*
33116 * efi_call_phys(void *, ...) is a function with variable parameters.
33117@@ -20,7 +22,7 @@
33118 * service functions will comply with gcc calling convention, too.
33119 */
33120
33121-.text
33122+__INIT
33123 ENTRY(efi_call_phys)
33124 /*
33125 * 0. The function can only be called in Linux kernel. So CS has been
33126@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
33127 * The mapping of lower virtual memory has been created in prelog and
33128 * epilog.
33129 */
33130- movl $1f, %edx
33131- subl $__PAGE_OFFSET, %edx
33132- jmp *%edx
33133+#ifdef CONFIG_PAX_KERNEXEC
33134+ movl $(__KERNEXEC_EFI_DS), %edx
33135+ mov %edx, %ds
33136+ mov %edx, %es
33137+ mov %edx, %ss
33138+ addl $2f,(1f)
33139+ ljmp *(1f)
33140+
33141+__INITDATA
33142+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
33143+.previous
33144+
33145+2:
33146+ subl $2b,(1b)
33147+#else
33148+ jmp 1f-__PAGE_OFFSET
33149 1:
33150+#endif
33151
33152 /*
33153 * 2. Now on the top of stack is the return
33154@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
33155 * parameter 2, ..., param n. To make things easy, we save the return
33156 * address of efi_call_phys in a global variable.
33157 */
33158- popl %edx
33159- movl %edx, saved_return_addr
33160- /* get the function pointer into ECX*/
33161- popl %ecx
33162- movl %ecx, efi_rt_function_ptr
33163- movl $2f, %edx
33164- subl $__PAGE_OFFSET, %edx
33165- pushl %edx
33166+ popl (saved_return_addr)
33167+ popl (efi_rt_function_ptr)
33168
33169 /*
33170 * 3. Clear PG bit in %CR0.
33171@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
33172 /*
33173 * 5. Call the physical function.
33174 */
33175- jmp *%ecx
33176+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
33177
33178-2:
33179 /*
33180 * 6. After EFI runtime service returns, control will return to
33181 * following instruction. We'd better readjust stack pointer first.
33182@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
33183 movl %cr0, %edx
33184 orl $0x80000000, %edx
33185 movl %edx, %cr0
33186- jmp 1f
33187-1:
33188+
33189 /*
33190 * 8. Now restore the virtual mode from flat mode by
33191 * adding EIP with PAGE_OFFSET.
33192 */
33193- movl $1f, %edx
33194- jmp *%edx
33195+#ifdef CONFIG_PAX_KERNEXEC
33196+ movl $(__KERNEL_DS), %edx
33197+ mov %edx, %ds
33198+ mov %edx, %es
33199+ mov %edx, %ss
33200+ ljmp $(__KERNEL_CS),$1f
33201+#else
33202+ jmp 1f+__PAGE_OFFSET
33203+#endif
33204 1:
33205
33206 /*
33207 * 9. Balance the stack. And because EAX contain the return value,
33208 * we'd better not clobber it.
33209 */
33210- leal efi_rt_function_ptr, %edx
33211- movl (%edx), %ecx
33212- pushl %ecx
33213+ pushl (efi_rt_function_ptr)
33214
33215 /*
33216- * 10. Push the saved return address onto the stack and return.
33217+ * 10. Return to the saved return address.
33218 */
33219- leal saved_return_addr, %edx
33220- movl (%edx), %ecx
33221- pushl %ecx
33222- ret
33223+ jmpl *(saved_return_addr)
33224 ENDPROC(efi_call_phys)
33225 .previous
33226
33227-.data
33228+__INITDATA
33229 saved_return_addr:
33230 .long 0
33231 efi_rt_function_ptr:
33232diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
33233index 4c07cca..2c8427d 100644
33234--- a/arch/x86/platform/efi/efi_stub_64.S
33235+++ b/arch/x86/platform/efi/efi_stub_64.S
33236@@ -7,6 +7,7 @@
33237 */
33238
33239 #include <linux/linkage.h>
33240+#include <asm/alternative-asm.h>
33241
33242 #define SAVE_XMM \
33243 mov %rsp, %rax; \
33244@@ -40,6 +41,7 @@ ENTRY(efi_call0)
33245 call *%rdi
33246 addq $32, %rsp
33247 RESTORE_XMM
33248+ pax_force_retaddr 0, 1
33249 ret
33250 ENDPROC(efi_call0)
33251
33252@@ -50,6 +52,7 @@ ENTRY(efi_call1)
33253 call *%rdi
33254 addq $32, %rsp
33255 RESTORE_XMM
33256+ pax_force_retaddr 0, 1
33257 ret
33258 ENDPROC(efi_call1)
33259
33260@@ -60,6 +63,7 @@ ENTRY(efi_call2)
33261 call *%rdi
33262 addq $32, %rsp
33263 RESTORE_XMM
33264+ pax_force_retaddr 0, 1
33265 ret
33266 ENDPROC(efi_call2)
33267
33268@@ -71,6 +75,7 @@ ENTRY(efi_call3)
33269 call *%rdi
33270 addq $32, %rsp
33271 RESTORE_XMM
33272+ pax_force_retaddr 0, 1
33273 ret
33274 ENDPROC(efi_call3)
33275
33276@@ -83,6 +88,7 @@ ENTRY(efi_call4)
33277 call *%rdi
33278 addq $32, %rsp
33279 RESTORE_XMM
33280+ pax_force_retaddr 0, 1
33281 ret
33282 ENDPROC(efi_call4)
33283
33284@@ -96,6 +102,7 @@ ENTRY(efi_call5)
33285 call *%rdi
33286 addq $48, %rsp
33287 RESTORE_XMM
33288+ pax_force_retaddr 0, 1
33289 ret
33290 ENDPROC(efi_call5)
33291
33292@@ -112,5 +119,6 @@ ENTRY(efi_call6)
33293 call *%rdi
33294 addq $48, %rsp
33295 RESTORE_XMM
33296+ pax_force_retaddr 0, 1
33297 ret
33298 ENDPROC(efi_call6)
33299diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
33300index 47fe66f..6206449 100644
33301--- a/arch/x86/platform/mrst/mrst.c
33302+++ b/arch/x86/platform/mrst/mrst.c
33303@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
33304 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
33305 int sfi_mrtc_num;
33306
33307-static void mrst_power_off(void)
33308+static __noreturn void mrst_power_off(void)
33309 {
33310+ BUG();
33311 }
33312
33313-static void mrst_reboot(void)
33314+static __noreturn void mrst_reboot(void)
33315 {
33316 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
33317+ BUG();
33318 }
33319
33320 /* parse all the mtimer info to a static mtimer array */
33321diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
33322index d6ee929..3637cb5 100644
33323--- a/arch/x86/platform/olpc/olpc_dt.c
33324+++ b/arch/x86/platform/olpc/olpc_dt.c
33325@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
33326 return res;
33327 }
33328
33329-static struct of_pdt_ops prom_olpc_ops __initdata = {
33330+static struct of_pdt_ops prom_olpc_ops __initconst = {
33331 .nextprop = olpc_dt_nextprop,
33332 .getproplen = olpc_dt_getproplen,
33333 .getproperty = olpc_dt_getproperty,
33334diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
33335index 1cf5b30..fd45732 100644
33336--- a/arch/x86/power/cpu.c
33337+++ b/arch/x86/power/cpu.c
33338@@ -137,11 +137,8 @@ static void do_fpu_end(void)
33339 static void fix_processor_context(void)
33340 {
33341 int cpu = smp_processor_id();
33342- struct tss_struct *t = &per_cpu(init_tss, cpu);
33343-#ifdef CONFIG_X86_64
33344- struct desc_struct *desc = get_cpu_gdt_table(cpu);
33345- tss_desc tss;
33346-#endif
33347+ struct tss_struct *t = init_tss + cpu;
33348+
33349 set_tss_desc(cpu, t); /*
33350 * This just modifies memory; should not be
33351 * necessary. But... This is necessary, because
33352@@ -150,10 +147,6 @@ static void fix_processor_context(void)
33353 */
33354
33355 #ifdef CONFIG_X86_64
33356- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
33357- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
33358- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
33359-
33360 syscall_init(); /* This sets MSR_*STAR and related */
33361 #endif
33362 load_TR_desc(); /* This does ltr */
33363diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
33364index a44f457..9140171 100644
33365--- a/arch/x86/realmode/init.c
33366+++ b/arch/x86/realmode/init.c
33367@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
33368 __va(real_mode_header->trampoline_header);
33369
33370 #ifdef CONFIG_X86_32
33371- trampoline_header->start = __pa_symbol(startup_32_smp);
33372+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
33373+
33374+#ifdef CONFIG_PAX_KERNEXEC
33375+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
33376+#endif
33377+
33378+ trampoline_header->boot_cs = __BOOT_CS;
33379 trampoline_header->gdt_limit = __BOOT_DS + 7;
33380 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
33381 #else
33382@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
33383 *trampoline_cr4_features = read_cr4();
33384
33385 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
33386- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
33387+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
33388 trampoline_pgd[511] = init_level4_pgt[511].pgd;
33389 #endif
33390 }
33391diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
33392index 8869287..d577672 100644
33393--- a/arch/x86/realmode/rm/Makefile
33394+++ b/arch/x86/realmode/rm/Makefile
33395@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
33396 $(call cc-option, -fno-unit-at-a-time)) \
33397 $(call cc-option, -fno-stack-protector) \
33398 $(call cc-option, -mpreferred-stack-boundary=2)
33399+ifdef CONSTIFY_PLUGIN
33400+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
33401+endif
33402 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
33403 GCOV_PROFILE := n
33404diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
33405index a28221d..93c40f1 100644
33406--- a/arch/x86/realmode/rm/header.S
33407+++ b/arch/x86/realmode/rm/header.S
33408@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
33409 #endif
33410 /* APM/BIOS reboot */
33411 .long pa_machine_real_restart_asm
33412-#ifdef CONFIG_X86_64
33413+#ifdef CONFIG_X86_32
33414+ .long __KERNEL_CS
33415+#else
33416 .long __KERNEL32_CS
33417 #endif
33418 END(real_mode_header)
33419diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
33420index c1b2791..f9e31c7 100644
33421--- a/arch/x86/realmode/rm/trampoline_32.S
33422+++ b/arch/x86/realmode/rm/trampoline_32.S
33423@@ -25,6 +25,12 @@
33424 #include <asm/page_types.h>
33425 #include "realmode.h"
33426
33427+#ifdef CONFIG_PAX_KERNEXEC
33428+#define ta(X) (X)
33429+#else
33430+#define ta(X) (pa_ ## X)
33431+#endif
33432+
33433 .text
33434 .code16
33435
33436@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
33437
33438 cli # We should be safe anyway
33439
33440- movl tr_start, %eax # where we need to go
33441-
33442 movl $0xA5A5A5A5, trampoline_status
33443 # write marker for master knows we're running
33444
33445@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
33446 movw $1, %dx # protected mode (PE) bit
33447 lmsw %dx # into protected mode
33448
33449- ljmpl $__BOOT_CS, $pa_startup_32
33450+ ljmpl *(trampoline_header)
33451
33452 .section ".text32","ax"
33453 .code32
33454@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
33455 .balign 8
33456 GLOBAL(trampoline_header)
33457 tr_start: .space 4
33458- tr_gdt_pad: .space 2
33459+ tr_boot_cs: .space 2
33460 tr_gdt: .space 6
33461 END(trampoline_header)
33462
33463diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
33464index bb360dc..d0fd8f8 100644
33465--- a/arch/x86/realmode/rm/trampoline_64.S
33466+++ b/arch/x86/realmode/rm/trampoline_64.S
33467@@ -94,6 +94,7 @@ ENTRY(startup_32)
33468 movl %edx, %gs
33469
33470 movl pa_tr_cr4, %eax
33471+ andl $~X86_CR4_PCIDE, %eax
33472 movl %eax, %cr4 # Enable PAE mode
33473
33474 # Setup trampoline 4 level pagetables
33475@@ -107,7 +108,7 @@ ENTRY(startup_32)
33476 wrmsr
33477
33478 # Enable paging and in turn activate Long Mode
33479- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
33480+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
33481 movl %eax, %cr0
33482
33483 /*
33484diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
33485index e812034..c747134 100644
33486--- a/arch/x86/tools/Makefile
33487+++ b/arch/x86/tools/Makefile
33488@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
33489
33490 $(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
33491
33492-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
33493+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
33494 hostprogs-y += relocs
33495 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
33496 relocs: $(obj)/relocs
33497diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
33498index f7bab68..b6d9886 100644
33499--- a/arch/x86/tools/relocs.c
33500+++ b/arch/x86/tools/relocs.c
33501@@ -1,5 +1,7 @@
33502 /* This is included from relocs_32/64.c */
33503
33504+#include "../../../include/generated/autoconf.h"
33505+
33506 #define ElfW(type) _ElfW(ELF_BITS, type)
33507 #define _ElfW(bits, type) __ElfW(bits, type)
33508 #define __ElfW(bits, type) Elf##bits##_##type
33509@@ -11,6 +13,7 @@
33510 #define Elf_Sym ElfW(Sym)
33511
33512 static Elf_Ehdr ehdr;
33513+static Elf_Phdr *phdr;
33514
33515 struct relocs {
33516 uint32_t *offset;
33517@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
33518 }
33519 }
33520
33521+static void read_phdrs(FILE *fp)
33522+{
33523+ unsigned int i;
33524+
33525+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
33526+ if (!phdr) {
33527+ die("Unable to allocate %d program headers\n",
33528+ ehdr.e_phnum);
33529+ }
33530+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
33531+ die("Seek to %d failed: %s\n",
33532+ ehdr.e_phoff, strerror(errno));
33533+ }
33534+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
33535+ die("Cannot read ELF program headers: %s\n",
33536+ strerror(errno));
33537+ }
33538+ for(i = 0; i < ehdr.e_phnum; i++) {
33539+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
33540+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
33541+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
33542+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
33543+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
33544+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
33545+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
33546+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
33547+ }
33548+
33549+}
33550+
33551 static void read_shdrs(FILE *fp)
33552 {
33553- int i;
33554+ unsigned int i;
33555 Elf_Shdr shdr;
33556
33557 secs = calloc(ehdr.e_shnum, sizeof(struct section));
33558@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
33559
33560 static void read_strtabs(FILE *fp)
33561 {
33562- int i;
33563+ unsigned int i;
33564 for (i = 0; i < ehdr.e_shnum; i++) {
33565 struct section *sec = &secs[i];
33566 if (sec->shdr.sh_type != SHT_STRTAB) {
33567@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
33568
33569 static void read_symtabs(FILE *fp)
33570 {
33571- int i,j;
33572+ unsigned int i,j;
33573 for (i = 0; i < ehdr.e_shnum; i++) {
33574 struct section *sec = &secs[i];
33575 if (sec->shdr.sh_type != SHT_SYMTAB) {
33576@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
33577 }
33578
33579
33580-static void read_relocs(FILE *fp)
33581+static void read_relocs(FILE *fp, int use_real_mode)
33582 {
33583- int i,j;
33584+ unsigned int i,j;
33585+ uint32_t base;
33586+
33587 for (i = 0; i < ehdr.e_shnum; i++) {
33588 struct section *sec = &secs[i];
33589 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33590@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
33591 die("Cannot read symbol table: %s\n",
33592 strerror(errno));
33593 }
33594+ base = 0;
33595+
33596+#ifdef CONFIG_X86_32
33597+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
33598+ if (phdr[j].p_type != PT_LOAD )
33599+ continue;
33600+ 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)
33601+ continue;
33602+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
33603+ break;
33604+ }
33605+#endif
33606+
33607 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
33608 Elf_Rel *rel = &sec->reltab[j];
33609- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
33610+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
33611 rel->r_info = elf_xword_to_cpu(rel->r_info);
33612 #if (SHT_REL_TYPE == SHT_RELA)
33613 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
33614@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
33615
33616 static void print_absolute_symbols(void)
33617 {
33618- int i;
33619+ unsigned int i;
33620 const char *format;
33621
33622 if (ELF_BITS == 64)
33623@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
33624 for (i = 0; i < ehdr.e_shnum; i++) {
33625 struct section *sec = &secs[i];
33626 char *sym_strtab;
33627- int j;
33628+ unsigned int j;
33629
33630 if (sec->shdr.sh_type != SHT_SYMTAB) {
33631 continue;
33632@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
33633
33634 static void print_absolute_relocs(void)
33635 {
33636- int i, printed = 0;
33637+ unsigned int i, printed = 0;
33638 const char *format;
33639
33640 if (ELF_BITS == 64)
33641@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
33642 struct section *sec_applies, *sec_symtab;
33643 char *sym_strtab;
33644 Elf_Sym *sh_symtab;
33645- int j;
33646+ unsigned int j;
33647 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33648 continue;
33649 }
33650@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
33651 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
33652 Elf_Sym *sym, const char *symname))
33653 {
33654- int i;
33655+ unsigned int i;
33656 /* Walk through the relocations */
33657 for (i = 0; i < ehdr.e_shnum; i++) {
33658 char *sym_strtab;
33659 Elf_Sym *sh_symtab;
33660 struct section *sec_applies, *sec_symtab;
33661- int j;
33662+ unsigned int j;
33663 struct section *sec = &secs[i];
33664
33665 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33666@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33667 {
33668 unsigned r_type = ELF32_R_TYPE(rel->r_info);
33669 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
33670+ char *sym_strtab = sec->link->link->strtab;
33671+
33672+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
33673+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
33674+ return 0;
33675+
33676+#ifdef CONFIG_PAX_KERNEXEC
33677+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
33678+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
33679+ return 0;
33680+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
33681+ return 0;
33682+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
33683+ return 0;
33684+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
33685+ return 0;
33686+#endif
33687
33688 switch (r_type) {
33689 case R_386_NONE:
33690@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
33691
33692 static void emit_relocs(int as_text, int use_real_mode)
33693 {
33694- int i;
33695+ unsigned int i;
33696 int (*write_reloc)(uint32_t, FILE *) = write32;
33697 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33698 const char *symname);
33699@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
33700 {
33701 regex_init(use_real_mode);
33702 read_ehdr(fp);
33703+ read_phdrs(fp);
33704 read_shdrs(fp);
33705 read_strtabs(fp);
33706 read_symtabs(fp);
33707- read_relocs(fp);
33708+ read_relocs(fp, use_real_mode);
33709 if (ELF_BITS == 64)
33710 percpu_init();
33711 if (show_absolute_syms) {
33712diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
33713index 80ffa5b..a33bd15 100644
33714--- a/arch/x86/um/tls_32.c
33715+++ b/arch/x86/um/tls_32.c
33716@@ -260,7 +260,7 @@ out:
33717 if (unlikely(task == current &&
33718 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
33719 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
33720- "without flushed TLS.", current->pid);
33721+ "without flushed TLS.", task_pid_nr(current));
33722 }
33723
33724 return 0;
33725diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
33726index fd14be1..e3c79c0 100644
33727--- a/arch/x86/vdso/Makefile
33728+++ b/arch/x86/vdso/Makefile
33729@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
33730 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
33731 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
33732
33733-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33734+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33735 GCOV_PROFILE := n
33736
33737 #
33738diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
33739index d6bfb87..876ee18 100644
33740--- a/arch/x86/vdso/vdso32-setup.c
33741+++ b/arch/x86/vdso/vdso32-setup.c
33742@@ -25,6 +25,7 @@
33743 #include <asm/tlbflush.h>
33744 #include <asm/vdso.h>
33745 #include <asm/proto.h>
33746+#include <asm/mman.h>
33747
33748 enum {
33749 VDSO_DISABLED = 0,
33750@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
33751 void enable_sep_cpu(void)
33752 {
33753 int cpu = get_cpu();
33754- struct tss_struct *tss = &per_cpu(init_tss, cpu);
33755+ struct tss_struct *tss = init_tss + cpu;
33756
33757 if (!boot_cpu_has(X86_FEATURE_SEP)) {
33758 put_cpu();
33759@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
33760 gate_vma.vm_start = FIXADDR_USER_START;
33761 gate_vma.vm_end = FIXADDR_USER_END;
33762 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
33763- gate_vma.vm_page_prot = __P101;
33764+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
33765
33766 return 0;
33767 }
33768@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33769 if (compat)
33770 addr = VDSO_HIGH_BASE;
33771 else {
33772- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
33773+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
33774 if (IS_ERR_VALUE(addr)) {
33775 ret = addr;
33776 goto up_fail;
33777 }
33778 }
33779
33780- current->mm->context.vdso = (void *)addr;
33781+ current->mm->context.vdso = addr;
33782
33783 if (compat_uses_vma || !compat) {
33784 /*
33785@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33786 }
33787
33788 current_thread_info()->sysenter_return =
33789- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33790+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33791
33792 up_fail:
33793 if (ret)
33794- current->mm->context.vdso = NULL;
33795+ current->mm->context.vdso = 0;
33796
33797 up_write(&mm->mmap_sem);
33798
33799@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
33800
33801 const char *arch_vma_name(struct vm_area_struct *vma)
33802 {
33803- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
33804+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
33805 return "[vdso]";
33806+
33807+#ifdef CONFIG_PAX_SEGMEXEC
33808+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
33809+ return "[vdso]";
33810+#endif
33811+
33812 return NULL;
33813 }
33814
33815@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
33816 * Check to see if the corresponding task was created in compat vdso
33817 * mode.
33818 */
33819- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
33820+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
33821 return &gate_vma;
33822 return NULL;
33823 }
33824diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
33825index 431e875..cbb23f3 100644
33826--- a/arch/x86/vdso/vma.c
33827+++ b/arch/x86/vdso/vma.c
33828@@ -16,8 +16,6 @@
33829 #include <asm/vdso.h>
33830 #include <asm/page.h>
33831
33832-unsigned int __read_mostly vdso_enabled = 1;
33833-
33834 extern char vdso_start[], vdso_end[];
33835 extern unsigned short vdso_sync_cpuid;
33836
33837@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
33838 * unaligned here as a result of stack start randomization.
33839 */
33840 addr = PAGE_ALIGN(addr);
33841- addr = align_vdso_addr(addr);
33842
33843 return addr;
33844 }
33845@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
33846 unsigned size)
33847 {
33848 struct mm_struct *mm = current->mm;
33849- unsigned long addr;
33850+ unsigned long addr = 0;
33851 int ret;
33852
33853- if (!vdso_enabled)
33854- return 0;
33855-
33856 down_write(&mm->mmap_sem);
33857+
33858+#ifdef CONFIG_PAX_RANDMMAP
33859+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
33860+#endif
33861+
33862 addr = vdso_addr(mm->start_stack, size);
33863+ addr = align_vdso_addr(addr);
33864 addr = get_unmapped_area(NULL, addr, size, 0, 0);
33865 if (IS_ERR_VALUE(addr)) {
33866 ret = addr;
33867 goto up_fail;
33868 }
33869
33870- current->mm->context.vdso = (void *)addr;
33871+ mm->context.vdso = addr;
33872
33873 ret = install_special_mapping(mm, addr, size,
33874 VM_READ|VM_EXEC|
33875 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
33876 pages);
33877- if (ret) {
33878- current->mm->context.vdso = NULL;
33879- goto up_fail;
33880- }
33881+ if (ret)
33882+ mm->context.vdso = 0;
33883
33884 up_fail:
33885 up_write(&mm->mmap_sem);
33886@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33887 vdsox32_size);
33888 }
33889 #endif
33890-
33891-static __init int vdso_setup(char *s)
33892-{
33893- vdso_enabled = simple_strtoul(s, NULL, 0);
33894- return 0;
33895-}
33896-__setup("vdso=", vdso_setup);
33897diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
33898index 193097e..7590269 100644
33899--- a/arch/x86/xen/enlighten.c
33900+++ b/arch/x86/xen/enlighten.c
33901@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
33902
33903 struct shared_info xen_dummy_shared_info;
33904
33905-void *xen_initial_gdt;
33906-
33907 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
33908 __read_mostly int xen_have_vector_callback;
33909 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
33910@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
33911 {
33912 unsigned long va = dtr->address;
33913 unsigned int size = dtr->size + 1;
33914- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
33915- unsigned long frames[pages];
33916+ unsigned long frames[65536 / PAGE_SIZE];
33917 int f;
33918
33919 /*
33920@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
33921 {
33922 unsigned long va = dtr->address;
33923 unsigned int size = dtr->size + 1;
33924- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
33925- unsigned long frames[pages];
33926+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
33927 int f;
33928
33929 /*
33930@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
33931 * 8-byte entries, or 16 4k pages..
33932 */
33933
33934- BUG_ON(size > 65536);
33935+ BUG_ON(size > GDT_SIZE);
33936 BUG_ON(va & ~PAGE_MASK);
33937
33938 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
33939@@ -985,7 +981,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
33940 return 0;
33941 }
33942
33943-static void set_xen_basic_apic_ops(void)
33944+static void __init set_xen_basic_apic_ops(void)
33945 {
33946 apic->read = xen_apic_read;
33947 apic->write = xen_apic_write;
33948@@ -1290,30 +1286,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
33949 #endif
33950 };
33951
33952-static void xen_reboot(int reason)
33953+static __noreturn void xen_reboot(int reason)
33954 {
33955 struct sched_shutdown r = { .reason = reason };
33956
33957- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
33958- BUG();
33959+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
33960+ BUG();
33961 }
33962
33963-static void xen_restart(char *msg)
33964+static __noreturn void xen_restart(char *msg)
33965 {
33966 xen_reboot(SHUTDOWN_reboot);
33967 }
33968
33969-static void xen_emergency_restart(void)
33970+static __noreturn void xen_emergency_restart(void)
33971 {
33972 xen_reboot(SHUTDOWN_reboot);
33973 }
33974
33975-static void xen_machine_halt(void)
33976+static __noreturn void xen_machine_halt(void)
33977 {
33978 xen_reboot(SHUTDOWN_poweroff);
33979 }
33980
33981-static void xen_machine_power_off(void)
33982+static __noreturn void xen_machine_power_off(void)
33983 {
33984 if (pm_power_off)
33985 pm_power_off();
33986@@ -1464,7 +1460,17 @@ asmlinkage void __init xen_start_kernel(void)
33987 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
33988
33989 /* Work out if we support NX */
33990- x86_configure_nx();
33991+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33992+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
33993+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
33994+ unsigned l, h;
33995+
33996+ __supported_pte_mask |= _PAGE_NX;
33997+ rdmsr(MSR_EFER, l, h);
33998+ l |= EFER_NX;
33999+ wrmsr(MSR_EFER, l, h);
34000+ }
34001+#endif
34002
34003 xen_setup_features();
34004
34005@@ -1495,13 +1501,6 @@ asmlinkage void __init xen_start_kernel(void)
34006
34007 machine_ops = xen_machine_ops;
34008
34009- /*
34010- * The only reliable way to retain the initial address of the
34011- * percpu gdt_page is to remember it here, so we can go and
34012- * mark it RW later, when the initial percpu area is freed.
34013- */
34014- xen_initial_gdt = &per_cpu(gdt_page, 0);
34015-
34016 xen_smp_init();
34017
34018 #ifdef CONFIG_ACPI_NUMA
34019diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
34020index fdc3ba2..3daee39 100644
34021--- a/arch/x86/xen/mmu.c
34022+++ b/arch/x86/xen/mmu.c
34023@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34024 /* L3_k[510] -> level2_kernel_pgt
34025 * L3_i[511] -> level2_fixmap_pgt */
34026 convert_pfn_mfn(level3_kernel_pgt);
34027+ convert_pfn_mfn(level3_vmalloc_start_pgt);
34028+ convert_pfn_mfn(level3_vmalloc_end_pgt);
34029+ convert_pfn_mfn(level3_vmemmap_pgt);
34030
34031 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
34032 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
34033@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34034 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
34035 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
34036 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
34037+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
34038+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
34039+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
34040 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
34041 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
34042+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
34043 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
34044 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
34045
34046@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
34047 pv_mmu_ops.set_pud = xen_set_pud;
34048 #if PAGETABLE_LEVELS == 4
34049 pv_mmu_ops.set_pgd = xen_set_pgd;
34050+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
34051 #endif
34052
34053 /* This will work as long as patching hasn't happened yet
34054@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
34055 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
34056 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
34057 .set_pgd = xen_set_pgd_hyper,
34058+ .set_pgd_batched = xen_set_pgd_hyper,
34059
34060 .alloc_pud = xen_alloc_pmd_init,
34061 .release_pud = xen_release_pmd_init,
34062diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
34063index b81c88e..2cbe7b8 100644
34064--- a/arch/x86/xen/smp.c
34065+++ b/arch/x86/xen/smp.c
34066@@ -272,11 +272,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
34067 {
34068 BUG_ON(smp_processor_id() != 0);
34069 native_smp_prepare_boot_cpu();
34070-
34071- /* We've switched to the "real" per-cpu gdt, so make sure the
34072- old memory can be recycled */
34073- make_lowmem_page_readwrite(xen_initial_gdt);
34074-
34075 xen_filter_cpu_maps();
34076 xen_setup_vcpu_info_placement();
34077 }
34078@@ -346,7 +341,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34079 ctxt->user_regs.ss = __KERNEL_DS;
34080 #ifdef CONFIG_X86_32
34081 ctxt->user_regs.fs = __KERNEL_PERCPU;
34082- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
34083+ savesegment(gs, ctxt->user_regs.gs);
34084 #else
34085 ctxt->gs_base_kernel = per_cpu_offset(cpu);
34086 #endif
34087@@ -356,8 +351,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34088
34089 {
34090 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
34091- ctxt->user_regs.ds = __USER_DS;
34092- ctxt->user_regs.es = __USER_DS;
34093+ ctxt->user_regs.ds = __KERNEL_DS;
34094+ ctxt->user_regs.es = __KERNEL_DS;
34095
34096 xen_copy_trap_info(ctxt->trap_ctxt);
34097
34098@@ -402,13 +397,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
34099 int rc;
34100
34101 per_cpu(current_task, cpu) = idle;
34102+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
34103 #ifdef CONFIG_X86_32
34104 irq_ctx_init(cpu);
34105 #else
34106 clear_tsk_thread_flag(idle, TIF_FORK);
34107- per_cpu(kernel_stack, cpu) =
34108- (unsigned long)task_stack_page(idle) -
34109- KERNEL_STACK_OFFSET + THREAD_SIZE;
34110+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
34111 #endif
34112 xen_setup_runstate_info(cpu);
34113 xen_setup_timer(cpu);
34114@@ -678,7 +672,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
34115
34116 void __init xen_smp_init(void)
34117 {
34118- smp_ops = xen_smp_ops;
34119+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
34120 xen_fill_possible_map();
34121 xen_init_spinlocks();
34122 }
34123diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
34124index 33ca6e4..0ded929 100644
34125--- a/arch/x86/xen/xen-asm_32.S
34126+++ b/arch/x86/xen/xen-asm_32.S
34127@@ -84,14 +84,14 @@ ENTRY(xen_iret)
34128 ESP_OFFSET=4 # bytes pushed onto stack
34129
34130 /*
34131- * Store vcpu_info pointer for easy access. Do it this way to
34132- * avoid having to reload %fs
34133+ * Store vcpu_info pointer for easy access.
34134 */
34135 #ifdef CONFIG_SMP
34136- GET_THREAD_INFO(%eax)
34137- movl %ss:TI_cpu(%eax), %eax
34138- movl %ss:__per_cpu_offset(,%eax,4), %eax
34139- mov %ss:xen_vcpu(%eax), %eax
34140+ push %fs
34141+ mov $(__KERNEL_PERCPU), %eax
34142+ mov %eax, %fs
34143+ mov PER_CPU_VAR(xen_vcpu), %eax
34144+ pop %fs
34145 #else
34146 movl %ss:xen_vcpu, %eax
34147 #endif
34148diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
34149index 7faed58..ba4427c 100644
34150--- a/arch/x86/xen/xen-head.S
34151+++ b/arch/x86/xen/xen-head.S
34152@@ -19,6 +19,17 @@ ENTRY(startup_xen)
34153 #ifdef CONFIG_X86_32
34154 mov %esi,xen_start_info
34155 mov $init_thread_union+THREAD_SIZE,%esp
34156+#ifdef CONFIG_SMP
34157+ movl $cpu_gdt_table,%edi
34158+ movl $__per_cpu_load,%eax
34159+ movw %ax,__KERNEL_PERCPU + 2(%edi)
34160+ rorl $16,%eax
34161+ movb %al,__KERNEL_PERCPU + 4(%edi)
34162+ movb %ah,__KERNEL_PERCPU + 7(%edi)
34163+ movl $__per_cpu_end - 1,%eax
34164+ subl $__per_cpu_start,%eax
34165+ movw %ax,__KERNEL_PERCPU + 0(%edi)
34166+#endif
34167 #else
34168 mov %rsi,xen_start_info
34169 mov $init_thread_union+THREAD_SIZE,%rsp
34170diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
34171index 86782c5..fa272c8 100644
34172--- a/arch/x86/xen/xen-ops.h
34173+++ b/arch/x86/xen/xen-ops.h
34174@@ -10,8 +10,6 @@
34175 extern const char xen_hypervisor_callback[];
34176 extern const char xen_failsafe_callback[];
34177
34178-extern void *xen_initial_gdt;
34179-
34180 struct trap_info;
34181 void xen_copy_trap_info(struct trap_info *traps);
34182
34183diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
34184index 525bd3d..ef888b1 100644
34185--- a/arch/xtensa/variants/dc232b/include/variant/core.h
34186+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
34187@@ -119,9 +119,9 @@
34188 ----------------------------------------------------------------------*/
34189
34190 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
34191-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
34192 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
34193 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
34194+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34195
34196 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
34197 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
34198diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
34199index 2f33760..835e50a 100644
34200--- a/arch/xtensa/variants/fsf/include/variant/core.h
34201+++ b/arch/xtensa/variants/fsf/include/variant/core.h
34202@@ -11,6 +11,7 @@
34203 #ifndef _XTENSA_CORE_H
34204 #define _XTENSA_CORE_H
34205
34206+#include <linux/const.h>
34207
34208 /****************************************************************************
34209 Parameters Useful for Any Code, USER or PRIVILEGED
34210@@ -112,9 +113,9 @@
34211 ----------------------------------------------------------------------*/
34212
34213 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34214-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34215 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34216 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34217+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34218
34219 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
34220 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
34221diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
34222index af00795..2bb8105 100644
34223--- a/arch/xtensa/variants/s6000/include/variant/core.h
34224+++ b/arch/xtensa/variants/s6000/include/variant/core.h
34225@@ -11,6 +11,7 @@
34226 #ifndef _XTENSA_CORE_CONFIGURATION_H
34227 #define _XTENSA_CORE_CONFIGURATION_H
34228
34229+#include <linux/const.h>
34230
34231 /****************************************************************************
34232 Parameters Useful for Any Code, USER or PRIVILEGED
34233@@ -118,9 +119,9 @@
34234 ----------------------------------------------------------------------*/
34235
34236 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34237-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34238 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34239 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34240+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34241
34242 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
34243 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
34244diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
34245index 290792a..416f287 100644
34246--- a/block/blk-cgroup.c
34247+++ b/block/blk-cgroup.c
34248@@ -808,7 +808,7 @@ static void blkcg_css_free(struct cgroup *cgroup)
34249
34250 static struct cgroup_subsys_state *blkcg_css_alloc(struct cgroup *cgroup)
34251 {
34252- static atomic64_t id_seq = ATOMIC64_INIT(0);
34253+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
34254 struct blkcg *blkcg;
34255 struct cgroup *parent = cgroup->parent;
34256
34257@@ -823,7 +823,7 @@ static struct cgroup_subsys_state *blkcg_css_alloc(struct cgroup *cgroup)
34258
34259 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
34260 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
34261- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
34262+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
34263 done:
34264 spin_lock_init(&blkcg->lock);
34265 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
34266diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
34267index 4b8d9b54..ff76220 100644
34268--- a/block/blk-iopoll.c
34269+++ b/block/blk-iopoll.c
34270@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
34271 }
34272 EXPORT_SYMBOL(blk_iopoll_complete);
34273
34274-static void blk_iopoll_softirq(struct softirq_action *h)
34275+static void blk_iopoll_softirq(void)
34276 {
34277 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
34278 int rearm = 0, budget = blk_iopoll_budget;
34279diff --git a/block/blk-map.c b/block/blk-map.c
34280index 623e1cd..ca1e109 100644
34281--- a/block/blk-map.c
34282+++ b/block/blk-map.c
34283@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
34284 if (!len || !kbuf)
34285 return -EINVAL;
34286
34287- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
34288+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
34289 if (do_copy)
34290 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
34291 else
34292diff --git a/block/blk-softirq.c b/block/blk-softirq.c
34293index ec9e606..2244d4e 100644
34294--- a/block/blk-softirq.c
34295+++ b/block/blk-softirq.c
34296@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
34297 * Softirq action handler - move entries to local list and loop over them
34298 * while passing them to the queue registered handler.
34299 */
34300-static void blk_done_softirq(struct softirq_action *h)
34301+static void blk_done_softirq(void)
34302 {
34303 struct list_head *cpu_list, local_list;
34304
34305diff --git a/block/bsg.c b/block/bsg.c
34306index 420a5a9..23834aa 100644
34307--- a/block/bsg.c
34308+++ b/block/bsg.c
34309@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
34310 struct sg_io_v4 *hdr, struct bsg_device *bd,
34311 fmode_t has_write_perm)
34312 {
34313+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34314+ unsigned char *cmdptr;
34315+
34316 if (hdr->request_len > BLK_MAX_CDB) {
34317 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
34318 if (!rq->cmd)
34319 return -ENOMEM;
34320- }
34321+ cmdptr = rq->cmd;
34322+ } else
34323+ cmdptr = tmpcmd;
34324
34325- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
34326+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
34327 hdr->request_len))
34328 return -EFAULT;
34329
34330+ if (cmdptr != rq->cmd)
34331+ memcpy(rq->cmd, cmdptr, hdr->request_len);
34332+
34333 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
34334 if (blk_verify_command(rq->cmd, has_write_perm))
34335 return -EPERM;
34336diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
34337index 7e5d474..0cf0017 100644
34338--- a/block/compat_ioctl.c
34339+++ b/block/compat_ioctl.c
34340@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
34341 err |= __get_user(f->spec1, &uf->spec1);
34342 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
34343 err |= __get_user(name, &uf->name);
34344- f->name = compat_ptr(name);
34345+ f->name = (void __force_kernel *)compat_ptr(name);
34346 if (err) {
34347 err = -EFAULT;
34348 goto out;
34349diff --git a/block/genhd.c b/block/genhd.c
34350index dadf42b..48dc887 100644
34351--- a/block/genhd.c
34352+++ b/block/genhd.c
34353@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
34354
34355 /*
34356 * Register device numbers dev..(dev+range-1)
34357- * range must be nonzero
34358+ * Noop if @range is zero.
34359 * The hash chain is sorted on range, so that subranges can override.
34360 */
34361 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
34362 struct kobject *(*probe)(dev_t, int *, void *),
34363 int (*lock)(dev_t, void *), void *data)
34364 {
34365- kobj_map(bdev_map, devt, range, module, probe, lock, data);
34366+ if (range)
34367+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
34368 }
34369
34370 EXPORT_SYMBOL(blk_register_region);
34371
34372+/* undo blk_register_region(), noop if @range is zero */
34373 void blk_unregister_region(dev_t devt, unsigned long range)
34374 {
34375- kobj_unmap(bdev_map, devt, range);
34376+ if (range)
34377+ kobj_unmap(bdev_map, devt, range);
34378 }
34379
34380 EXPORT_SYMBOL(blk_unregister_region);
34381diff --git a/block/partitions/efi.c b/block/partitions/efi.c
34382index c85fc89..51e690b 100644
34383--- a/block/partitions/efi.c
34384+++ b/block/partitions/efi.c
34385@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
34386 if (!gpt)
34387 return NULL;
34388
34389+ if (!le32_to_cpu(gpt->num_partition_entries))
34390+ return NULL;
34391+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
34392+ if (!pte)
34393+ return NULL;
34394+
34395 count = le32_to_cpu(gpt->num_partition_entries) *
34396 le32_to_cpu(gpt->sizeof_partition_entry);
34397- if (!count)
34398- return NULL;
34399- pte = kmalloc(count, GFP_KERNEL);
34400- if (!pte)
34401- return NULL;
34402-
34403 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
34404 (u8 *) pte,
34405 count) < count) {
34406diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
34407index a5ffcc9..3cedc9c 100644
34408--- a/block/scsi_ioctl.c
34409+++ b/block/scsi_ioctl.c
34410@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
34411 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
34412 struct sg_io_hdr *hdr, fmode_t mode)
34413 {
34414- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
34415+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34416+ unsigned char *cmdptr;
34417+
34418+ if (rq->cmd != rq->__cmd)
34419+ cmdptr = rq->cmd;
34420+ else
34421+ cmdptr = tmpcmd;
34422+
34423+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
34424 return -EFAULT;
34425+
34426+ if (cmdptr != rq->cmd)
34427+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
34428+
34429 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
34430 return -EPERM;
34431
34432@@ -434,6 +446,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34433 int err;
34434 unsigned int in_len, out_len, bytes, opcode, cmdlen;
34435 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
34436+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34437+ unsigned char *cmdptr;
34438
34439 if (!sic)
34440 return -EINVAL;
34441@@ -467,9 +481,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34442 */
34443 err = -EFAULT;
34444 rq->cmd_len = cmdlen;
34445- if (copy_from_user(rq->cmd, sic->data, cmdlen))
34446+
34447+ if (rq->cmd != rq->__cmd)
34448+ cmdptr = rq->cmd;
34449+ else
34450+ cmdptr = tmpcmd;
34451+
34452+ if (copy_from_user(cmdptr, sic->data, cmdlen))
34453 goto error;
34454
34455+ if (rq->cmd != cmdptr)
34456+ memcpy(rq->cmd, cmdptr, cmdlen);
34457+
34458 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
34459 goto error;
34460
34461diff --git a/crypto/api.c b/crypto/api.c
34462index 3b61803..37c4c72 100644
34463--- a/crypto/api.c
34464+++ b/crypto/api.c
34465@@ -34,6 +34,8 @@ EXPORT_SYMBOL_GPL(crypto_alg_sem);
34466 BLOCKING_NOTIFIER_HEAD(crypto_chain);
34467 EXPORT_SYMBOL_GPL(crypto_chain);
34468
34469+static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg);
34470+
34471 struct crypto_alg *crypto_mod_get(struct crypto_alg *alg)
34472 {
34473 return try_module_get(alg->cra_module) ? crypto_alg_get(alg) : NULL;
34474@@ -144,8 +146,11 @@ static struct crypto_alg *crypto_larval_add(const char *name, u32 type,
34475 }
34476 up_write(&crypto_alg_sem);
34477
34478- if (alg != &larval->alg)
34479+ if (alg != &larval->alg) {
34480 kfree(larval);
34481+ if (crypto_is_larval(alg))
34482+ alg = crypto_larval_wait(alg);
34483+ }
34484
34485 return alg;
34486 }
34487diff --git a/crypto/cryptd.c b/crypto/cryptd.c
34488index 7bdd61b..afec999 100644
34489--- a/crypto/cryptd.c
34490+++ b/crypto/cryptd.c
34491@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
34492
34493 struct cryptd_blkcipher_request_ctx {
34494 crypto_completion_t complete;
34495-};
34496+} __no_const;
34497
34498 struct cryptd_hash_ctx {
34499 struct crypto_shash *child;
34500@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
34501
34502 struct cryptd_aead_request_ctx {
34503 crypto_completion_t complete;
34504-};
34505+} __no_const;
34506
34507 static void cryptd_queue_worker(struct work_struct *work);
34508
34509diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
34510index f8c920c..ab2cb5a 100644
34511--- a/crypto/pcrypt.c
34512+++ b/crypto/pcrypt.c
34513@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
34514 int ret;
34515
34516 pinst->kobj.kset = pcrypt_kset;
34517- ret = kobject_add(&pinst->kobj, NULL, name);
34518+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
34519 if (!ret)
34520 kobject_uevent(&pinst->kobj, KOBJ_ADD);
34521
34522diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
34523index f220d64..d359ad6 100644
34524--- a/drivers/acpi/apei/apei-internal.h
34525+++ b/drivers/acpi/apei/apei-internal.h
34526@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
34527 struct apei_exec_ins_type {
34528 u32 flags;
34529 apei_exec_ins_func_t run;
34530-};
34531+} __do_const;
34532
34533 struct apei_exec_context {
34534 u32 ip;
34535diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
34536index 33dc6a0..4b24b47 100644
34537--- a/drivers/acpi/apei/cper.c
34538+++ b/drivers/acpi/apei/cper.c
34539@@ -39,12 +39,12 @@
34540 */
34541 u64 cper_next_record_id(void)
34542 {
34543- static atomic64_t seq;
34544+ static atomic64_unchecked_t seq;
34545
34546- if (!atomic64_read(&seq))
34547- atomic64_set(&seq, ((u64)get_seconds()) << 32);
34548+ if (!atomic64_read_unchecked(&seq))
34549+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
34550
34551- return atomic64_inc_return(&seq);
34552+ return atomic64_inc_return_unchecked(&seq);
34553 }
34554 EXPORT_SYMBOL_GPL(cper_next_record_id);
34555
34556diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
34557index ec9b57d..9682b3a 100644
34558--- a/drivers/acpi/apei/ghes.c
34559+++ b/drivers/acpi/apei/ghes.c
34560@@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
34561 const struct acpi_hest_generic *generic,
34562 const struct acpi_hest_generic_status *estatus)
34563 {
34564- static atomic_t seqno;
34565+ static atomic_unchecked_t seqno;
34566 unsigned int curr_seqno;
34567 char pfx_seq[64];
34568
34569@@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
34570 else
34571 pfx = KERN_ERR;
34572 }
34573- curr_seqno = atomic_inc_return(&seqno);
34574+ curr_seqno = atomic_inc_return_unchecked(&seqno);
34575 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
34576 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
34577 pfx_seq, generic->header.source_id);
34578diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
34579index be60399..778b33e8 100644
34580--- a/drivers/acpi/bgrt.c
34581+++ b/drivers/acpi/bgrt.c
34582@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
34583 return -ENODEV;
34584
34585 sysfs_bin_attr_init(&image_attr);
34586- image_attr.private = bgrt_image;
34587- image_attr.size = bgrt_image_size;
34588+ pax_open_kernel();
34589+ *(void **)&image_attr.private = bgrt_image;
34590+ *(size_t *)&image_attr.size = bgrt_image_size;
34591+ pax_close_kernel();
34592
34593 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
34594 if (!bgrt_kobj)
34595diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
34596index cb96296..b81293b 100644
34597--- a/drivers/acpi/blacklist.c
34598+++ b/drivers/acpi/blacklist.c
34599@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
34600 u32 is_critical_error;
34601 };
34602
34603-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
34604+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
34605
34606 /*
34607 * POLICY: If *anything* doesn't work, put it on the blacklist.
34608@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
34609 return 0;
34610 }
34611
34612-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
34613+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
34614 {
34615 .callback = dmi_disable_osi_vista,
34616 .ident = "Fujitsu Siemens",
34617diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
34618index f98dd00..7b69865 100644
34619--- a/drivers/acpi/processor_idle.c
34620+++ b/drivers/acpi/processor_idle.c
34621@@ -992,7 +992,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
34622 {
34623 int i, count = CPUIDLE_DRIVER_STATE_START;
34624 struct acpi_processor_cx *cx;
34625- struct cpuidle_state *state;
34626+ cpuidle_state_no_const *state;
34627 struct cpuidle_driver *drv = &acpi_idle_driver;
34628
34629 if (!pr->flags.power_setup_done)
34630diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
34631index 05306a5..733d1f0 100644
34632--- a/drivers/acpi/sysfs.c
34633+++ b/drivers/acpi/sysfs.c
34634@@ -423,11 +423,11 @@ static u32 num_counters;
34635 static struct attribute **all_attrs;
34636 static u32 acpi_gpe_count;
34637
34638-static struct attribute_group interrupt_stats_attr_group = {
34639+static attribute_group_no_const interrupt_stats_attr_group = {
34640 .name = "interrupts",
34641 };
34642
34643-static struct kobj_attribute *counter_attrs;
34644+static kobj_attribute_no_const *counter_attrs;
34645
34646 static void delete_gpe_attr_array(void)
34647 {
34648diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
34649index acfd0f7..e5acb08 100644
34650--- a/drivers/ata/libahci.c
34651+++ b/drivers/ata/libahci.c
34652@@ -1231,7 +1231,7 @@ int ahci_kick_engine(struct ata_port *ap)
34653 }
34654 EXPORT_SYMBOL_GPL(ahci_kick_engine);
34655
34656-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34657+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34658 struct ata_taskfile *tf, int is_cmd, u16 flags,
34659 unsigned long timeout_msec)
34660 {
34661diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
34662index c24354d..335c975 100644
34663--- a/drivers/ata/libata-core.c
34664+++ b/drivers/ata/libata-core.c
34665@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
34666 static void ata_dev_xfermask(struct ata_device *dev);
34667 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
34668
34669-atomic_t ata_print_id = ATOMIC_INIT(0);
34670+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
34671
34672 struct ata_force_param {
34673 const char *name;
34674@@ -4792,7 +4792,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
34675 struct ata_port *ap;
34676 unsigned int tag;
34677
34678- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34679+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34680 ap = qc->ap;
34681
34682 qc->flags = 0;
34683@@ -4808,7 +4808,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
34684 struct ata_port *ap;
34685 struct ata_link *link;
34686
34687- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34688+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34689 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
34690 ap = qc->ap;
34691 link = qc->dev->link;
34692@@ -5927,6 +5927,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34693 return;
34694
34695 spin_lock(&lock);
34696+ pax_open_kernel();
34697
34698 for (cur = ops->inherits; cur; cur = cur->inherits) {
34699 void **inherit = (void **)cur;
34700@@ -5940,8 +5941,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34701 if (IS_ERR(*pp))
34702 *pp = NULL;
34703
34704- ops->inherits = NULL;
34705+ *(struct ata_port_operations **)&ops->inherits = NULL;
34706
34707+ pax_close_kernel();
34708 spin_unlock(&lock);
34709 }
34710
34711@@ -6134,7 +6136,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
34712
34713 /* give ports names and add SCSI hosts */
34714 for (i = 0; i < host->n_ports; i++) {
34715- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
34716+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
34717 host->ports[i]->local_port_no = i + 1;
34718 }
34719
34720diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
34721index b1e880a..8cf82e1 100644
34722--- a/drivers/ata/libata-scsi.c
34723+++ b/drivers/ata/libata-scsi.c
34724@@ -4104,7 +4104,7 @@ int ata_sas_port_init(struct ata_port *ap)
34725
34726 if (rc)
34727 return rc;
34728- ap->print_id = atomic_inc_return(&ata_print_id);
34729+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
34730 return 0;
34731 }
34732 EXPORT_SYMBOL_GPL(ata_sas_port_init);
34733diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
34734index 577d902b..cb4781e 100644
34735--- a/drivers/ata/libata.h
34736+++ b/drivers/ata/libata.h
34737@@ -53,7 +53,7 @@ enum {
34738 ATA_DNXFER_QUIET = (1 << 31),
34739 };
34740
34741-extern atomic_t ata_print_id;
34742+extern atomic_unchecked_t ata_print_id;
34743 extern int atapi_passthru16;
34744 extern int libata_fua;
34745 extern int libata_noacpi;
34746diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
34747index 848ed32..132f39d 100644
34748--- a/drivers/ata/pata_arasan_cf.c
34749+++ b/drivers/ata/pata_arasan_cf.c
34750@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
34751 /* Handle platform specific quirks */
34752 if (quirk) {
34753 if (quirk & CF_BROKEN_PIO) {
34754- ap->ops->set_piomode = NULL;
34755+ pax_open_kernel();
34756+ *(void **)&ap->ops->set_piomode = NULL;
34757+ pax_close_kernel();
34758 ap->pio_mask = 0;
34759 }
34760 if (quirk & CF_BROKEN_MWDMA)
34761diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
34762index f9b983a..887b9d8 100644
34763--- a/drivers/atm/adummy.c
34764+++ b/drivers/atm/adummy.c
34765@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
34766 vcc->pop(vcc, skb);
34767 else
34768 dev_kfree_skb_any(skb);
34769- atomic_inc(&vcc->stats->tx);
34770+ atomic_inc_unchecked(&vcc->stats->tx);
34771
34772 return 0;
34773 }
34774diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
34775index 62a7607..cc4be104 100644
34776--- a/drivers/atm/ambassador.c
34777+++ b/drivers/atm/ambassador.c
34778@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
34779 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
34780
34781 // VC layer stats
34782- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34783+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34784
34785 // free the descriptor
34786 kfree (tx_descr);
34787@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34788 dump_skb ("<<<", vc, skb);
34789
34790 // VC layer stats
34791- atomic_inc(&atm_vcc->stats->rx);
34792+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34793 __net_timestamp(skb);
34794 // end of our responsibility
34795 atm_vcc->push (atm_vcc, skb);
34796@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34797 } else {
34798 PRINTK (KERN_INFO, "dropped over-size frame");
34799 // should we count this?
34800- atomic_inc(&atm_vcc->stats->rx_drop);
34801+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34802 }
34803
34804 } else {
34805@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
34806 }
34807
34808 if (check_area (skb->data, skb->len)) {
34809- atomic_inc(&atm_vcc->stats->tx_err);
34810+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
34811 return -ENOMEM; // ?
34812 }
34813
34814diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
34815index 0e3f8f9..765a7a5 100644
34816--- a/drivers/atm/atmtcp.c
34817+++ b/drivers/atm/atmtcp.c
34818@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34819 if (vcc->pop) vcc->pop(vcc,skb);
34820 else dev_kfree_skb(skb);
34821 if (dev_data) return 0;
34822- atomic_inc(&vcc->stats->tx_err);
34823+ atomic_inc_unchecked(&vcc->stats->tx_err);
34824 return -ENOLINK;
34825 }
34826 size = skb->len+sizeof(struct atmtcp_hdr);
34827@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34828 if (!new_skb) {
34829 if (vcc->pop) vcc->pop(vcc,skb);
34830 else dev_kfree_skb(skb);
34831- atomic_inc(&vcc->stats->tx_err);
34832+ atomic_inc_unchecked(&vcc->stats->tx_err);
34833 return -ENOBUFS;
34834 }
34835 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
34836@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34837 if (vcc->pop) vcc->pop(vcc,skb);
34838 else dev_kfree_skb(skb);
34839 out_vcc->push(out_vcc,new_skb);
34840- atomic_inc(&vcc->stats->tx);
34841- atomic_inc(&out_vcc->stats->rx);
34842+ atomic_inc_unchecked(&vcc->stats->tx);
34843+ atomic_inc_unchecked(&out_vcc->stats->rx);
34844 return 0;
34845 }
34846
34847@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34848 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
34849 read_unlock(&vcc_sklist_lock);
34850 if (!out_vcc) {
34851- atomic_inc(&vcc->stats->tx_err);
34852+ atomic_inc_unchecked(&vcc->stats->tx_err);
34853 goto done;
34854 }
34855 skb_pull(skb,sizeof(struct atmtcp_hdr));
34856@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34857 __net_timestamp(new_skb);
34858 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
34859 out_vcc->push(out_vcc,new_skb);
34860- atomic_inc(&vcc->stats->tx);
34861- atomic_inc(&out_vcc->stats->rx);
34862+ atomic_inc_unchecked(&vcc->stats->tx);
34863+ atomic_inc_unchecked(&out_vcc->stats->rx);
34864 done:
34865 if (vcc->pop) vcc->pop(vcc,skb);
34866 else dev_kfree_skb(skb);
34867diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
34868index b1955ba..b179940 100644
34869--- a/drivers/atm/eni.c
34870+++ b/drivers/atm/eni.c
34871@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
34872 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
34873 vcc->dev->number);
34874 length = 0;
34875- atomic_inc(&vcc->stats->rx_err);
34876+ atomic_inc_unchecked(&vcc->stats->rx_err);
34877 }
34878 else {
34879 length = ATM_CELL_SIZE-1; /* no HEC */
34880@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34881 size);
34882 }
34883 eff = length = 0;
34884- atomic_inc(&vcc->stats->rx_err);
34885+ atomic_inc_unchecked(&vcc->stats->rx_err);
34886 }
34887 else {
34888 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
34889@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34890 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
34891 vcc->dev->number,vcc->vci,length,size << 2,descr);
34892 length = eff = 0;
34893- atomic_inc(&vcc->stats->rx_err);
34894+ atomic_inc_unchecked(&vcc->stats->rx_err);
34895 }
34896 }
34897 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
34898@@ -767,7 +767,7 @@ rx_dequeued++;
34899 vcc->push(vcc,skb);
34900 pushed++;
34901 }
34902- atomic_inc(&vcc->stats->rx);
34903+ atomic_inc_unchecked(&vcc->stats->rx);
34904 }
34905 wake_up(&eni_dev->rx_wait);
34906 }
34907@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
34908 PCI_DMA_TODEVICE);
34909 if (vcc->pop) vcc->pop(vcc,skb);
34910 else dev_kfree_skb_irq(skb);
34911- atomic_inc(&vcc->stats->tx);
34912+ atomic_inc_unchecked(&vcc->stats->tx);
34913 wake_up(&eni_dev->tx_wait);
34914 dma_complete++;
34915 }
34916diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
34917index b41c948..a002b17 100644
34918--- a/drivers/atm/firestream.c
34919+++ b/drivers/atm/firestream.c
34920@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
34921 }
34922 }
34923
34924- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34925+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34926
34927 fs_dprintk (FS_DEBUG_TXMEM, "i");
34928 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
34929@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
34930 #endif
34931 skb_put (skb, qe->p1 & 0xffff);
34932 ATM_SKB(skb)->vcc = atm_vcc;
34933- atomic_inc(&atm_vcc->stats->rx);
34934+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34935 __net_timestamp(skb);
34936 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
34937 atm_vcc->push (atm_vcc, skb);
34938@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
34939 kfree (pe);
34940 }
34941 if (atm_vcc)
34942- atomic_inc(&atm_vcc->stats->rx_drop);
34943+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34944 break;
34945 case 0x1f: /* Reassembly abort: no buffers. */
34946 /* Silently increment error counter. */
34947 if (atm_vcc)
34948- atomic_inc(&atm_vcc->stats->rx_drop);
34949+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34950 break;
34951 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
34952 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
34953diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
34954index 204814e..cede831 100644
34955--- a/drivers/atm/fore200e.c
34956+++ b/drivers/atm/fore200e.c
34957@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
34958 #endif
34959 /* check error condition */
34960 if (*entry->status & STATUS_ERROR)
34961- atomic_inc(&vcc->stats->tx_err);
34962+ atomic_inc_unchecked(&vcc->stats->tx_err);
34963 else
34964- atomic_inc(&vcc->stats->tx);
34965+ atomic_inc_unchecked(&vcc->stats->tx);
34966 }
34967 }
34968
34969@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
34970 if (skb == NULL) {
34971 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
34972
34973- atomic_inc(&vcc->stats->rx_drop);
34974+ atomic_inc_unchecked(&vcc->stats->rx_drop);
34975 return -ENOMEM;
34976 }
34977
34978@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
34979
34980 dev_kfree_skb_any(skb);
34981
34982- atomic_inc(&vcc->stats->rx_drop);
34983+ atomic_inc_unchecked(&vcc->stats->rx_drop);
34984 return -ENOMEM;
34985 }
34986
34987 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
34988
34989 vcc->push(vcc, skb);
34990- atomic_inc(&vcc->stats->rx);
34991+ atomic_inc_unchecked(&vcc->stats->rx);
34992
34993 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
34994
34995@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
34996 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
34997 fore200e->atm_dev->number,
34998 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
34999- atomic_inc(&vcc->stats->rx_err);
35000+ atomic_inc_unchecked(&vcc->stats->rx_err);
35001 }
35002 }
35003
35004@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
35005 goto retry_here;
35006 }
35007
35008- atomic_inc(&vcc->stats->tx_err);
35009+ atomic_inc_unchecked(&vcc->stats->tx_err);
35010
35011 fore200e->tx_sat++;
35012 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
35013diff --git a/drivers/atm/he.c b/drivers/atm/he.c
35014index 507362a..a845e57 100644
35015--- a/drivers/atm/he.c
35016+++ b/drivers/atm/he.c
35017@@ -1698,7 +1698,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35018
35019 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
35020 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
35021- atomic_inc(&vcc->stats->rx_drop);
35022+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35023 goto return_host_buffers;
35024 }
35025
35026@@ -1725,7 +1725,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35027 RBRQ_LEN_ERR(he_dev->rbrq_head)
35028 ? "LEN_ERR" : "",
35029 vcc->vpi, vcc->vci);
35030- atomic_inc(&vcc->stats->rx_err);
35031+ atomic_inc_unchecked(&vcc->stats->rx_err);
35032 goto return_host_buffers;
35033 }
35034
35035@@ -1777,7 +1777,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35036 vcc->push(vcc, skb);
35037 spin_lock(&he_dev->global_lock);
35038
35039- atomic_inc(&vcc->stats->rx);
35040+ atomic_inc_unchecked(&vcc->stats->rx);
35041
35042 return_host_buffers:
35043 ++pdus_assembled;
35044@@ -2103,7 +2103,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
35045 tpd->vcc->pop(tpd->vcc, tpd->skb);
35046 else
35047 dev_kfree_skb_any(tpd->skb);
35048- atomic_inc(&tpd->vcc->stats->tx_err);
35049+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
35050 }
35051 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
35052 return;
35053@@ -2515,7 +2515,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35054 vcc->pop(vcc, skb);
35055 else
35056 dev_kfree_skb_any(skb);
35057- atomic_inc(&vcc->stats->tx_err);
35058+ atomic_inc_unchecked(&vcc->stats->tx_err);
35059 return -EINVAL;
35060 }
35061
35062@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35063 vcc->pop(vcc, skb);
35064 else
35065 dev_kfree_skb_any(skb);
35066- atomic_inc(&vcc->stats->tx_err);
35067+ atomic_inc_unchecked(&vcc->stats->tx_err);
35068 return -EINVAL;
35069 }
35070 #endif
35071@@ -2538,7 +2538,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35072 vcc->pop(vcc, skb);
35073 else
35074 dev_kfree_skb_any(skb);
35075- atomic_inc(&vcc->stats->tx_err);
35076+ atomic_inc_unchecked(&vcc->stats->tx_err);
35077 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35078 return -ENOMEM;
35079 }
35080@@ -2580,7 +2580,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35081 vcc->pop(vcc, skb);
35082 else
35083 dev_kfree_skb_any(skb);
35084- atomic_inc(&vcc->stats->tx_err);
35085+ atomic_inc_unchecked(&vcc->stats->tx_err);
35086 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35087 return -ENOMEM;
35088 }
35089@@ -2611,7 +2611,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35090 __enqueue_tpd(he_dev, tpd, cid);
35091 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35092
35093- atomic_inc(&vcc->stats->tx);
35094+ atomic_inc_unchecked(&vcc->stats->tx);
35095
35096 return 0;
35097 }
35098diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
35099index 1dc0519..1aadaf7 100644
35100--- a/drivers/atm/horizon.c
35101+++ b/drivers/atm/horizon.c
35102@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
35103 {
35104 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
35105 // VC layer stats
35106- atomic_inc(&vcc->stats->rx);
35107+ atomic_inc_unchecked(&vcc->stats->rx);
35108 __net_timestamp(skb);
35109 // end of our responsibility
35110 vcc->push (vcc, skb);
35111@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
35112 dev->tx_iovec = NULL;
35113
35114 // VC layer stats
35115- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35116+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35117
35118 // free the skb
35119 hrz_kfree_skb (skb);
35120diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
35121index 272f009..a18ba55 100644
35122--- a/drivers/atm/idt77252.c
35123+++ b/drivers/atm/idt77252.c
35124@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
35125 else
35126 dev_kfree_skb(skb);
35127
35128- atomic_inc(&vcc->stats->tx);
35129+ atomic_inc_unchecked(&vcc->stats->tx);
35130 }
35131
35132 atomic_dec(&scq->used);
35133@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35134 if ((sb = dev_alloc_skb(64)) == NULL) {
35135 printk("%s: Can't allocate buffers for aal0.\n",
35136 card->name);
35137- atomic_add(i, &vcc->stats->rx_drop);
35138+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35139 break;
35140 }
35141 if (!atm_charge(vcc, sb->truesize)) {
35142 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
35143 card->name);
35144- atomic_add(i - 1, &vcc->stats->rx_drop);
35145+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
35146 dev_kfree_skb(sb);
35147 break;
35148 }
35149@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35150 ATM_SKB(sb)->vcc = vcc;
35151 __net_timestamp(sb);
35152 vcc->push(vcc, sb);
35153- atomic_inc(&vcc->stats->rx);
35154+ atomic_inc_unchecked(&vcc->stats->rx);
35155
35156 cell += ATM_CELL_PAYLOAD;
35157 }
35158@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35159 "(CDC: %08x)\n",
35160 card->name, len, rpp->len, readl(SAR_REG_CDC));
35161 recycle_rx_pool_skb(card, rpp);
35162- atomic_inc(&vcc->stats->rx_err);
35163+ atomic_inc_unchecked(&vcc->stats->rx_err);
35164 return;
35165 }
35166 if (stat & SAR_RSQE_CRC) {
35167 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
35168 recycle_rx_pool_skb(card, rpp);
35169- atomic_inc(&vcc->stats->rx_err);
35170+ atomic_inc_unchecked(&vcc->stats->rx_err);
35171 return;
35172 }
35173 if (skb_queue_len(&rpp->queue) > 1) {
35174@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35175 RXPRINTK("%s: Can't alloc RX skb.\n",
35176 card->name);
35177 recycle_rx_pool_skb(card, rpp);
35178- atomic_inc(&vcc->stats->rx_err);
35179+ atomic_inc_unchecked(&vcc->stats->rx_err);
35180 return;
35181 }
35182 if (!atm_charge(vcc, skb->truesize)) {
35183@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35184 __net_timestamp(skb);
35185
35186 vcc->push(vcc, skb);
35187- atomic_inc(&vcc->stats->rx);
35188+ atomic_inc_unchecked(&vcc->stats->rx);
35189
35190 return;
35191 }
35192@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35193 __net_timestamp(skb);
35194
35195 vcc->push(vcc, skb);
35196- atomic_inc(&vcc->stats->rx);
35197+ atomic_inc_unchecked(&vcc->stats->rx);
35198
35199 if (skb->truesize > SAR_FB_SIZE_3)
35200 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
35201@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
35202 if (vcc->qos.aal != ATM_AAL0) {
35203 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
35204 card->name, vpi, vci);
35205- atomic_inc(&vcc->stats->rx_drop);
35206+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35207 goto drop;
35208 }
35209
35210 if ((sb = dev_alloc_skb(64)) == NULL) {
35211 printk("%s: Can't allocate buffers for AAL0.\n",
35212 card->name);
35213- atomic_inc(&vcc->stats->rx_err);
35214+ atomic_inc_unchecked(&vcc->stats->rx_err);
35215 goto drop;
35216 }
35217
35218@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
35219 ATM_SKB(sb)->vcc = vcc;
35220 __net_timestamp(sb);
35221 vcc->push(vcc, sb);
35222- atomic_inc(&vcc->stats->rx);
35223+ atomic_inc_unchecked(&vcc->stats->rx);
35224
35225 drop:
35226 skb_pull(queue, 64);
35227@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35228
35229 if (vc == NULL) {
35230 printk("%s: NULL connection in send().\n", card->name);
35231- atomic_inc(&vcc->stats->tx_err);
35232+ atomic_inc_unchecked(&vcc->stats->tx_err);
35233 dev_kfree_skb(skb);
35234 return -EINVAL;
35235 }
35236 if (!test_bit(VCF_TX, &vc->flags)) {
35237 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
35238- atomic_inc(&vcc->stats->tx_err);
35239+ atomic_inc_unchecked(&vcc->stats->tx_err);
35240 dev_kfree_skb(skb);
35241 return -EINVAL;
35242 }
35243@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35244 break;
35245 default:
35246 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
35247- atomic_inc(&vcc->stats->tx_err);
35248+ atomic_inc_unchecked(&vcc->stats->tx_err);
35249 dev_kfree_skb(skb);
35250 return -EINVAL;
35251 }
35252
35253 if (skb_shinfo(skb)->nr_frags != 0) {
35254 printk("%s: No scatter-gather yet.\n", card->name);
35255- atomic_inc(&vcc->stats->tx_err);
35256+ atomic_inc_unchecked(&vcc->stats->tx_err);
35257 dev_kfree_skb(skb);
35258 return -EINVAL;
35259 }
35260@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35261
35262 err = queue_skb(card, vc, skb, oam);
35263 if (err) {
35264- atomic_inc(&vcc->stats->tx_err);
35265+ atomic_inc_unchecked(&vcc->stats->tx_err);
35266 dev_kfree_skb(skb);
35267 return err;
35268 }
35269@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
35270 skb = dev_alloc_skb(64);
35271 if (!skb) {
35272 printk("%s: Out of memory in send_oam().\n", card->name);
35273- atomic_inc(&vcc->stats->tx_err);
35274+ atomic_inc_unchecked(&vcc->stats->tx_err);
35275 return -ENOMEM;
35276 }
35277 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
35278diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
35279index 4217f29..88f547a 100644
35280--- a/drivers/atm/iphase.c
35281+++ b/drivers/atm/iphase.c
35282@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
35283 status = (u_short) (buf_desc_ptr->desc_mode);
35284 if (status & (RX_CER | RX_PTE | RX_OFL))
35285 {
35286- atomic_inc(&vcc->stats->rx_err);
35287+ atomic_inc_unchecked(&vcc->stats->rx_err);
35288 IF_ERR(printk("IA: bad packet, dropping it");)
35289 if (status & RX_CER) {
35290 IF_ERR(printk(" cause: packet CRC error\n");)
35291@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
35292 len = dma_addr - buf_addr;
35293 if (len > iadev->rx_buf_sz) {
35294 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
35295- atomic_inc(&vcc->stats->rx_err);
35296+ atomic_inc_unchecked(&vcc->stats->rx_err);
35297 goto out_free_desc;
35298 }
35299
35300@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35301 ia_vcc = INPH_IA_VCC(vcc);
35302 if (ia_vcc == NULL)
35303 {
35304- atomic_inc(&vcc->stats->rx_err);
35305+ atomic_inc_unchecked(&vcc->stats->rx_err);
35306 atm_return(vcc, skb->truesize);
35307 dev_kfree_skb_any(skb);
35308 goto INCR_DLE;
35309@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35310 if ((length > iadev->rx_buf_sz) || (length >
35311 (skb->len - sizeof(struct cpcs_trailer))))
35312 {
35313- atomic_inc(&vcc->stats->rx_err);
35314+ atomic_inc_unchecked(&vcc->stats->rx_err);
35315 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
35316 length, skb->len);)
35317 atm_return(vcc, skb->truesize);
35318@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35319
35320 IF_RX(printk("rx_dle_intr: skb push");)
35321 vcc->push(vcc,skb);
35322- atomic_inc(&vcc->stats->rx);
35323+ atomic_inc_unchecked(&vcc->stats->rx);
35324 iadev->rx_pkt_cnt++;
35325 }
35326 INCR_DLE:
35327@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
35328 {
35329 struct k_sonet_stats *stats;
35330 stats = &PRIV(_ia_dev[board])->sonet_stats;
35331- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
35332- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
35333- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
35334- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
35335- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
35336- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
35337- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
35338- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
35339- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
35340+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
35341+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
35342+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
35343+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
35344+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
35345+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
35346+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
35347+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
35348+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
35349 }
35350 ia_cmds.status = 0;
35351 break;
35352@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35353 if ((desc == 0) || (desc > iadev->num_tx_desc))
35354 {
35355 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
35356- atomic_inc(&vcc->stats->tx);
35357+ atomic_inc_unchecked(&vcc->stats->tx);
35358 if (vcc->pop)
35359 vcc->pop(vcc, skb);
35360 else
35361@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35362 ATM_DESC(skb) = vcc->vci;
35363 skb_queue_tail(&iadev->tx_dma_q, skb);
35364
35365- atomic_inc(&vcc->stats->tx);
35366+ atomic_inc_unchecked(&vcc->stats->tx);
35367 iadev->tx_pkt_cnt++;
35368 /* Increment transaction counter */
35369 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
35370
35371 #if 0
35372 /* add flow control logic */
35373- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
35374+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
35375 if (iavcc->vc_desc_cnt > 10) {
35376 vcc->tx_quota = vcc->tx_quota * 3 / 4;
35377 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
35378diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
35379index fa7d701..1e404c7 100644
35380--- a/drivers/atm/lanai.c
35381+++ b/drivers/atm/lanai.c
35382@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
35383 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
35384 lanai_endtx(lanai, lvcc);
35385 lanai_free_skb(lvcc->tx.atmvcc, skb);
35386- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
35387+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
35388 }
35389
35390 /* Try to fill the buffer - don't call unless there is backlog */
35391@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
35392 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
35393 __net_timestamp(skb);
35394 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
35395- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
35396+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
35397 out:
35398 lvcc->rx.buf.ptr = end;
35399 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
35400@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35401 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
35402 "vcc %d\n", lanai->number, (unsigned int) s, vci);
35403 lanai->stats.service_rxnotaal5++;
35404- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35405+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35406 return 0;
35407 }
35408 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
35409@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35410 int bytes;
35411 read_unlock(&vcc_sklist_lock);
35412 DPRINTK("got trashed rx pdu on vci %d\n", vci);
35413- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35414+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35415 lvcc->stats.x.aal5.service_trash++;
35416 bytes = (SERVICE_GET_END(s) * 16) -
35417 (((unsigned long) lvcc->rx.buf.ptr) -
35418@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35419 }
35420 if (s & SERVICE_STREAM) {
35421 read_unlock(&vcc_sklist_lock);
35422- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35423+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35424 lvcc->stats.x.aal5.service_stream++;
35425 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
35426 "PDU on VCI %d!\n", lanai->number, vci);
35427@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35428 return 0;
35429 }
35430 DPRINTK("got rx crc error on vci %d\n", vci);
35431- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35432+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35433 lvcc->stats.x.aal5.service_rxcrc++;
35434 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
35435 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
35436diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
35437index 6587dc2..149833d 100644
35438--- a/drivers/atm/nicstar.c
35439+++ b/drivers/atm/nicstar.c
35440@@ -1641,7 +1641,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35441 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
35442 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
35443 card->index);
35444- atomic_inc(&vcc->stats->tx_err);
35445+ atomic_inc_unchecked(&vcc->stats->tx_err);
35446 dev_kfree_skb_any(skb);
35447 return -EINVAL;
35448 }
35449@@ -1649,7 +1649,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35450 if (!vc->tx) {
35451 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
35452 card->index);
35453- atomic_inc(&vcc->stats->tx_err);
35454+ atomic_inc_unchecked(&vcc->stats->tx_err);
35455 dev_kfree_skb_any(skb);
35456 return -EINVAL;
35457 }
35458@@ -1657,14 +1657,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35459 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
35460 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
35461 card->index);
35462- atomic_inc(&vcc->stats->tx_err);
35463+ atomic_inc_unchecked(&vcc->stats->tx_err);
35464 dev_kfree_skb_any(skb);
35465 return -EINVAL;
35466 }
35467
35468 if (skb_shinfo(skb)->nr_frags != 0) {
35469 printk("nicstar%d: No scatter-gather yet.\n", card->index);
35470- atomic_inc(&vcc->stats->tx_err);
35471+ atomic_inc_unchecked(&vcc->stats->tx_err);
35472 dev_kfree_skb_any(skb);
35473 return -EINVAL;
35474 }
35475@@ -1712,11 +1712,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35476 }
35477
35478 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
35479- atomic_inc(&vcc->stats->tx_err);
35480+ atomic_inc_unchecked(&vcc->stats->tx_err);
35481 dev_kfree_skb_any(skb);
35482 return -EIO;
35483 }
35484- atomic_inc(&vcc->stats->tx);
35485+ atomic_inc_unchecked(&vcc->stats->tx);
35486
35487 return 0;
35488 }
35489@@ -2033,14 +2033,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35490 printk
35491 ("nicstar%d: Can't allocate buffers for aal0.\n",
35492 card->index);
35493- atomic_add(i, &vcc->stats->rx_drop);
35494+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35495 break;
35496 }
35497 if (!atm_charge(vcc, sb->truesize)) {
35498 RXPRINTK
35499 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
35500 card->index);
35501- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35502+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35503 dev_kfree_skb_any(sb);
35504 break;
35505 }
35506@@ -2055,7 +2055,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35507 ATM_SKB(sb)->vcc = vcc;
35508 __net_timestamp(sb);
35509 vcc->push(vcc, sb);
35510- atomic_inc(&vcc->stats->rx);
35511+ atomic_inc_unchecked(&vcc->stats->rx);
35512 cell += ATM_CELL_PAYLOAD;
35513 }
35514
35515@@ -2072,7 +2072,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35516 if (iovb == NULL) {
35517 printk("nicstar%d: Out of iovec buffers.\n",
35518 card->index);
35519- atomic_inc(&vcc->stats->rx_drop);
35520+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35521 recycle_rx_buf(card, skb);
35522 return;
35523 }
35524@@ -2096,7 +2096,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35525 small or large buffer itself. */
35526 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
35527 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
35528- atomic_inc(&vcc->stats->rx_err);
35529+ atomic_inc_unchecked(&vcc->stats->rx_err);
35530 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35531 NS_MAX_IOVECS);
35532 NS_PRV_IOVCNT(iovb) = 0;
35533@@ -2116,7 +2116,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35534 ("nicstar%d: Expected a small buffer, and this is not one.\n",
35535 card->index);
35536 which_list(card, skb);
35537- atomic_inc(&vcc->stats->rx_err);
35538+ atomic_inc_unchecked(&vcc->stats->rx_err);
35539 recycle_rx_buf(card, skb);
35540 vc->rx_iov = NULL;
35541 recycle_iov_buf(card, iovb);
35542@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35543 ("nicstar%d: Expected a large buffer, and this is not one.\n",
35544 card->index);
35545 which_list(card, skb);
35546- atomic_inc(&vcc->stats->rx_err);
35547+ atomic_inc_unchecked(&vcc->stats->rx_err);
35548 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35549 NS_PRV_IOVCNT(iovb));
35550 vc->rx_iov = NULL;
35551@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35552 printk(" - PDU size mismatch.\n");
35553 else
35554 printk(".\n");
35555- atomic_inc(&vcc->stats->rx_err);
35556+ atomic_inc_unchecked(&vcc->stats->rx_err);
35557 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35558 NS_PRV_IOVCNT(iovb));
35559 vc->rx_iov = NULL;
35560@@ -2166,7 +2166,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35561 /* skb points to a small buffer */
35562 if (!atm_charge(vcc, skb->truesize)) {
35563 push_rxbufs(card, skb);
35564- atomic_inc(&vcc->stats->rx_drop);
35565+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35566 } else {
35567 skb_put(skb, len);
35568 dequeue_sm_buf(card, skb);
35569@@ -2176,7 +2176,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35570 ATM_SKB(skb)->vcc = vcc;
35571 __net_timestamp(skb);
35572 vcc->push(vcc, skb);
35573- atomic_inc(&vcc->stats->rx);
35574+ atomic_inc_unchecked(&vcc->stats->rx);
35575 }
35576 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
35577 struct sk_buff *sb;
35578@@ -2187,7 +2187,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35579 if (len <= NS_SMBUFSIZE) {
35580 if (!atm_charge(vcc, sb->truesize)) {
35581 push_rxbufs(card, sb);
35582- atomic_inc(&vcc->stats->rx_drop);
35583+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35584 } else {
35585 skb_put(sb, len);
35586 dequeue_sm_buf(card, sb);
35587@@ -2197,7 +2197,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35588 ATM_SKB(sb)->vcc = vcc;
35589 __net_timestamp(sb);
35590 vcc->push(vcc, sb);
35591- atomic_inc(&vcc->stats->rx);
35592+ atomic_inc_unchecked(&vcc->stats->rx);
35593 }
35594
35595 push_rxbufs(card, skb);
35596@@ -2206,7 +2206,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35597
35598 if (!atm_charge(vcc, skb->truesize)) {
35599 push_rxbufs(card, skb);
35600- atomic_inc(&vcc->stats->rx_drop);
35601+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35602 } else {
35603 dequeue_lg_buf(card, skb);
35604 #ifdef NS_USE_DESTRUCTORS
35605@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35606 ATM_SKB(skb)->vcc = vcc;
35607 __net_timestamp(skb);
35608 vcc->push(vcc, skb);
35609- atomic_inc(&vcc->stats->rx);
35610+ atomic_inc_unchecked(&vcc->stats->rx);
35611 }
35612
35613 push_rxbufs(card, sb);
35614@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35615 printk
35616 ("nicstar%d: Out of huge buffers.\n",
35617 card->index);
35618- atomic_inc(&vcc->stats->rx_drop);
35619+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35620 recycle_iovec_rx_bufs(card,
35621 (struct iovec *)
35622 iovb->data,
35623@@ -2291,7 +2291,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35624 card->hbpool.count++;
35625 } else
35626 dev_kfree_skb_any(hb);
35627- atomic_inc(&vcc->stats->rx_drop);
35628+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35629 } else {
35630 /* Copy the small buffer to the huge buffer */
35631 sb = (struct sk_buff *)iov->iov_base;
35632@@ -2328,7 +2328,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35633 #endif /* NS_USE_DESTRUCTORS */
35634 __net_timestamp(hb);
35635 vcc->push(vcc, hb);
35636- atomic_inc(&vcc->stats->rx);
35637+ atomic_inc_unchecked(&vcc->stats->rx);
35638 }
35639 }
35640
35641diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
35642index 32784d1..4a8434a 100644
35643--- a/drivers/atm/solos-pci.c
35644+++ b/drivers/atm/solos-pci.c
35645@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
35646 }
35647 atm_charge(vcc, skb->truesize);
35648 vcc->push(vcc, skb);
35649- atomic_inc(&vcc->stats->rx);
35650+ atomic_inc_unchecked(&vcc->stats->rx);
35651 break;
35652
35653 case PKT_STATUS:
35654@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
35655 vcc = SKB_CB(oldskb)->vcc;
35656
35657 if (vcc) {
35658- atomic_inc(&vcc->stats->tx);
35659+ atomic_inc_unchecked(&vcc->stats->tx);
35660 solos_pop(vcc, oldskb);
35661 } else {
35662 dev_kfree_skb_irq(oldskb);
35663diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
35664index 0215934..ce9f5b1 100644
35665--- a/drivers/atm/suni.c
35666+++ b/drivers/atm/suni.c
35667@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
35668
35669
35670 #define ADD_LIMITED(s,v) \
35671- atomic_add((v),&stats->s); \
35672- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
35673+ atomic_add_unchecked((v),&stats->s); \
35674+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
35675
35676
35677 static void suni_hz(unsigned long from_timer)
35678diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
35679index 5120a96..e2572bd 100644
35680--- a/drivers/atm/uPD98402.c
35681+++ b/drivers/atm/uPD98402.c
35682@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
35683 struct sonet_stats tmp;
35684 int error = 0;
35685
35686- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35687+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35688 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
35689 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
35690 if (zero && !error) {
35691@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
35692
35693
35694 #define ADD_LIMITED(s,v) \
35695- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
35696- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
35697- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35698+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
35699+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
35700+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35701
35702
35703 static void stat_event(struct atm_dev *dev)
35704@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
35705 if (reason & uPD98402_INT_PFM) stat_event(dev);
35706 if (reason & uPD98402_INT_PCO) {
35707 (void) GET(PCOCR); /* clear interrupt cause */
35708- atomic_add(GET(HECCT),
35709+ atomic_add_unchecked(GET(HECCT),
35710 &PRIV(dev)->sonet_stats.uncorr_hcs);
35711 }
35712 if ((reason & uPD98402_INT_RFO) &&
35713@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
35714 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
35715 uPD98402_INT_LOS),PIMR); /* enable them */
35716 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
35717- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35718- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
35719- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
35720+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35721+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
35722+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
35723 return 0;
35724 }
35725
35726diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
35727index 969c3c2..9b72956 100644
35728--- a/drivers/atm/zatm.c
35729+++ b/drivers/atm/zatm.c
35730@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35731 }
35732 if (!size) {
35733 dev_kfree_skb_irq(skb);
35734- if (vcc) atomic_inc(&vcc->stats->rx_err);
35735+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
35736 continue;
35737 }
35738 if (!atm_charge(vcc,skb->truesize)) {
35739@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35740 skb->len = size;
35741 ATM_SKB(skb)->vcc = vcc;
35742 vcc->push(vcc,skb);
35743- atomic_inc(&vcc->stats->rx);
35744+ atomic_inc_unchecked(&vcc->stats->rx);
35745 }
35746 zout(pos & 0xffff,MTA(mbx));
35747 #if 0 /* probably a stupid idea */
35748@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
35749 skb_queue_head(&zatm_vcc->backlog,skb);
35750 break;
35751 }
35752- atomic_inc(&vcc->stats->tx);
35753+ atomic_inc_unchecked(&vcc->stats->tx);
35754 wake_up(&zatm_vcc->tx_wait);
35755 }
35756
35757diff --git a/drivers/base/bus.c b/drivers/base/bus.c
35758index d414331..b4dd4ba 100644
35759--- a/drivers/base/bus.c
35760+++ b/drivers/base/bus.c
35761@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
35762 return -EINVAL;
35763
35764 mutex_lock(&subsys->p->mutex);
35765- list_add_tail(&sif->node, &subsys->p->interfaces);
35766+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
35767 if (sif->add_dev) {
35768 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35769 while ((dev = subsys_dev_iter_next(&iter)))
35770@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
35771 subsys = sif->subsys;
35772
35773 mutex_lock(&subsys->p->mutex);
35774- list_del_init(&sif->node);
35775+ pax_list_del_init((struct list_head *)&sif->node);
35776 if (sif->remove_dev) {
35777 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35778 while ((dev = subsys_dev_iter_next(&iter)))
35779diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
35780index 7413d06..79155fa 100644
35781--- a/drivers/base/devtmpfs.c
35782+++ b/drivers/base/devtmpfs.c
35783@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
35784 if (!thread)
35785 return 0;
35786
35787- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
35788+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
35789 if (err)
35790 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
35791 else
35792@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
35793 *err = sys_unshare(CLONE_NEWNS);
35794 if (*err)
35795 goto out;
35796- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
35797+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
35798 if (*err)
35799 goto out;
35800- sys_chdir("/.."); /* will traverse into overmounted root */
35801- sys_chroot(".");
35802+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
35803+ sys_chroot((char __force_user *)".");
35804 complete(&setup_done);
35805 while (1) {
35806 spin_lock(&req_lock);
35807diff --git a/drivers/base/node.c b/drivers/base/node.c
35808index 7616a77c..8f57f51 100644
35809--- a/drivers/base/node.c
35810+++ b/drivers/base/node.c
35811@@ -626,7 +626,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
35812 struct node_attr {
35813 struct device_attribute attr;
35814 enum node_states state;
35815-};
35816+} __do_const;
35817
35818 static ssize_t show_node_state(struct device *dev,
35819 struct device_attribute *attr, char *buf)
35820diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
35821index bfb8955..42c9b9a 100644
35822--- a/drivers/base/power/domain.c
35823+++ b/drivers/base/power/domain.c
35824@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
35825 {
35826 struct cpuidle_driver *cpuidle_drv;
35827 struct gpd_cpu_data *cpu_data;
35828- struct cpuidle_state *idle_state;
35829+ cpuidle_state_no_const *idle_state;
35830 int ret = 0;
35831
35832 if (IS_ERR_OR_NULL(genpd) || state < 0)
35833@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
35834 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
35835 {
35836 struct gpd_cpu_data *cpu_data;
35837- struct cpuidle_state *idle_state;
35838+ cpuidle_state_no_const *idle_state;
35839 int ret = 0;
35840
35841 if (IS_ERR_OR_NULL(genpd))
35842diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
35843index a53ebd2..8f73eeb 100644
35844--- a/drivers/base/power/sysfs.c
35845+++ b/drivers/base/power/sysfs.c
35846@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
35847 return -EIO;
35848 }
35849 }
35850- return sprintf(buf, p);
35851+ return sprintf(buf, "%s", p);
35852 }
35853
35854 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
35855diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
35856index 2d56f41..8830f19 100644
35857--- a/drivers/base/power/wakeup.c
35858+++ b/drivers/base/power/wakeup.c
35859@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
35860 * They need to be modified together atomically, so it's better to use one
35861 * atomic variable to hold them both.
35862 */
35863-static atomic_t combined_event_count = ATOMIC_INIT(0);
35864+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
35865
35866 #define IN_PROGRESS_BITS (sizeof(int) * 4)
35867 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
35868
35869 static void split_counters(unsigned int *cnt, unsigned int *inpr)
35870 {
35871- unsigned int comb = atomic_read(&combined_event_count);
35872+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
35873
35874 *cnt = (comb >> IN_PROGRESS_BITS);
35875 *inpr = comb & MAX_IN_PROGRESS;
35876@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
35877 ws->start_prevent_time = ws->last_time;
35878
35879 /* Increment the counter of events in progress. */
35880- cec = atomic_inc_return(&combined_event_count);
35881+ cec = atomic_inc_return_unchecked(&combined_event_count);
35882
35883 trace_wakeup_source_activate(ws->name, cec);
35884 }
35885@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
35886 * Increment the counter of registered wakeup events and decrement the
35887 * couter of wakeup events in progress simultaneously.
35888 */
35889- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
35890+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
35891 trace_wakeup_source_deactivate(ws->name, cec);
35892
35893 split_counters(&cnt, &inpr);
35894diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
35895index e8d11b6..7b1b36f 100644
35896--- a/drivers/base/syscore.c
35897+++ b/drivers/base/syscore.c
35898@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
35899 void register_syscore_ops(struct syscore_ops *ops)
35900 {
35901 mutex_lock(&syscore_ops_lock);
35902- list_add_tail(&ops->node, &syscore_ops_list);
35903+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
35904 mutex_unlock(&syscore_ops_lock);
35905 }
35906 EXPORT_SYMBOL_GPL(register_syscore_ops);
35907@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
35908 void unregister_syscore_ops(struct syscore_ops *ops)
35909 {
35910 mutex_lock(&syscore_ops_lock);
35911- list_del(&ops->node);
35912+ pax_list_del((struct list_head *)&ops->node);
35913 mutex_unlock(&syscore_ops_lock);
35914 }
35915 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
35916diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
35917index 62b6c2c..4a11354 100644
35918--- a/drivers/block/cciss.c
35919+++ b/drivers/block/cciss.c
35920@@ -1189,6 +1189,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
35921 int err;
35922 u32 cp;
35923
35924+ memset(&arg64, 0, sizeof(arg64));
35925+
35926 err = 0;
35927 err |=
35928 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
35929@@ -3010,7 +3012,7 @@ static void start_io(ctlr_info_t *h)
35930 while (!list_empty(&h->reqQ)) {
35931 c = list_entry(h->reqQ.next, CommandList_struct, list);
35932 /* can't do anything if fifo is full */
35933- if ((h->access.fifo_full(h))) {
35934+ if ((h->access->fifo_full(h))) {
35935 dev_warn(&h->pdev->dev, "fifo full\n");
35936 break;
35937 }
35938@@ -3020,7 +3022,7 @@ static void start_io(ctlr_info_t *h)
35939 h->Qdepth--;
35940
35941 /* Tell the controller execute command */
35942- h->access.submit_command(h, c);
35943+ h->access->submit_command(h, c);
35944
35945 /* Put job onto the completed Q */
35946 addQ(&h->cmpQ, c);
35947@@ -3446,17 +3448,17 @@ startio:
35948
35949 static inline unsigned long get_next_completion(ctlr_info_t *h)
35950 {
35951- return h->access.command_completed(h);
35952+ return h->access->command_completed(h);
35953 }
35954
35955 static inline int interrupt_pending(ctlr_info_t *h)
35956 {
35957- return h->access.intr_pending(h);
35958+ return h->access->intr_pending(h);
35959 }
35960
35961 static inline long interrupt_not_for_us(ctlr_info_t *h)
35962 {
35963- return ((h->access.intr_pending(h) == 0) ||
35964+ return ((h->access->intr_pending(h) == 0) ||
35965 (h->interrupts_enabled == 0));
35966 }
35967
35968@@ -3489,7 +3491,7 @@ static inline u32 next_command(ctlr_info_t *h)
35969 u32 a;
35970
35971 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
35972- return h->access.command_completed(h);
35973+ return h->access->command_completed(h);
35974
35975 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
35976 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
35977@@ -4046,7 +4048,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
35978 trans_support & CFGTBL_Trans_use_short_tags);
35979
35980 /* Change the access methods to the performant access methods */
35981- h->access = SA5_performant_access;
35982+ h->access = &SA5_performant_access;
35983 h->transMethod = CFGTBL_Trans_Performant;
35984
35985 return;
35986@@ -4319,7 +4321,7 @@ static int cciss_pci_init(ctlr_info_t *h)
35987 if (prod_index < 0)
35988 return -ENODEV;
35989 h->product_name = products[prod_index].product_name;
35990- h->access = *(products[prod_index].access);
35991+ h->access = products[prod_index].access;
35992
35993 if (cciss_board_disabled(h)) {
35994 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
35995@@ -5051,7 +5053,7 @@ reinit_after_soft_reset:
35996 }
35997
35998 /* make sure the board interrupts are off */
35999- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36000+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36001 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
36002 if (rc)
36003 goto clean2;
36004@@ -5101,7 +5103,7 @@ reinit_after_soft_reset:
36005 * fake ones to scoop up any residual completions.
36006 */
36007 spin_lock_irqsave(&h->lock, flags);
36008- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36009+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36010 spin_unlock_irqrestore(&h->lock, flags);
36011 free_irq(h->intr[h->intr_mode], h);
36012 rc = cciss_request_irq(h, cciss_msix_discard_completions,
36013@@ -5121,9 +5123,9 @@ reinit_after_soft_reset:
36014 dev_info(&h->pdev->dev, "Board READY.\n");
36015 dev_info(&h->pdev->dev,
36016 "Waiting for stale completions to drain.\n");
36017- h->access.set_intr_mask(h, CCISS_INTR_ON);
36018+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36019 msleep(10000);
36020- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36021+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36022
36023 rc = controller_reset_failed(h->cfgtable);
36024 if (rc)
36025@@ -5146,7 +5148,7 @@ reinit_after_soft_reset:
36026 cciss_scsi_setup(h);
36027
36028 /* Turn the interrupts on so we can service requests */
36029- h->access.set_intr_mask(h, CCISS_INTR_ON);
36030+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36031
36032 /* Get the firmware version */
36033 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
36034@@ -5218,7 +5220,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
36035 kfree(flush_buf);
36036 if (return_code != IO_OK)
36037 dev_warn(&h->pdev->dev, "Error flushing cache\n");
36038- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36039+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36040 free_irq(h->intr[h->intr_mode], h);
36041 }
36042
36043diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
36044index 7fda30e..eb5dfe0 100644
36045--- a/drivers/block/cciss.h
36046+++ b/drivers/block/cciss.h
36047@@ -101,7 +101,7 @@ struct ctlr_info
36048 /* information about each logical volume */
36049 drive_info_struct *drv[CISS_MAX_LUN];
36050
36051- struct access_method access;
36052+ struct access_method *access;
36053
36054 /* queue and queue Info */
36055 struct list_head reqQ;
36056diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
36057index 639d26b..fd6ad1f 100644
36058--- a/drivers/block/cpqarray.c
36059+++ b/drivers/block/cpqarray.c
36060@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36061 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
36062 goto Enomem4;
36063 }
36064- hba[i]->access.set_intr_mask(hba[i], 0);
36065+ hba[i]->access->set_intr_mask(hba[i], 0);
36066 if (request_irq(hba[i]->intr, do_ida_intr,
36067 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
36068 {
36069@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36070 add_timer(&hba[i]->timer);
36071
36072 /* Enable IRQ now that spinlock and rate limit timer are set up */
36073- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36074+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36075
36076 for(j=0; j<NWD; j++) {
36077 struct gendisk *disk = ida_gendisk[i][j];
36078@@ -694,7 +694,7 @@ DBGINFO(
36079 for(i=0; i<NR_PRODUCTS; i++) {
36080 if (board_id == products[i].board_id) {
36081 c->product_name = products[i].product_name;
36082- c->access = *(products[i].access);
36083+ c->access = products[i].access;
36084 break;
36085 }
36086 }
36087@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
36088 hba[ctlr]->intr = intr;
36089 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
36090 hba[ctlr]->product_name = products[j].product_name;
36091- hba[ctlr]->access = *(products[j].access);
36092+ hba[ctlr]->access = products[j].access;
36093 hba[ctlr]->ctlr = ctlr;
36094 hba[ctlr]->board_id = board_id;
36095 hba[ctlr]->pci_dev = NULL; /* not PCI */
36096@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
36097
36098 while((c = h->reqQ) != NULL) {
36099 /* Can't do anything if we're busy */
36100- if (h->access.fifo_full(h) == 0)
36101+ if (h->access->fifo_full(h) == 0)
36102 return;
36103
36104 /* Get the first entry from the request Q */
36105@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
36106 h->Qdepth--;
36107
36108 /* Tell the controller to do our bidding */
36109- h->access.submit_command(h, c);
36110+ h->access->submit_command(h, c);
36111
36112 /* Get onto the completion Q */
36113 addQ(&h->cmpQ, c);
36114@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36115 unsigned long flags;
36116 __u32 a,a1;
36117
36118- istat = h->access.intr_pending(h);
36119+ istat = h->access->intr_pending(h);
36120 /* Is this interrupt for us? */
36121 if (istat == 0)
36122 return IRQ_NONE;
36123@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36124 */
36125 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
36126 if (istat & FIFO_NOT_EMPTY) {
36127- while((a = h->access.command_completed(h))) {
36128+ while((a = h->access->command_completed(h))) {
36129 a1 = a; a &= ~3;
36130 if ((c = h->cmpQ) == NULL)
36131 {
36132@@ -1193,6 +1193,7 @@ out_passthru:
36133 ida_pci_info_struct pciinfo;
36134
36135 if (!arg) return -EINVAL;
36136+ memset(&pciinfo, 0, sizeof(pciinfo));
36137 pciinfo.bus = host->pci_dev->bus->number;
36138 pciinfo.dev_fn = host->pci_dev->devfn;
36139 pciinfo.board_id = host->board_id;
36140@@ -1447,11 +1448,11 @@ static int sendcmd(
36141 /*
36142 * Disable interrupt
36143 */
36144- info_p->access.set_intr_mask(info_p, 0);
36145+ info_p->access->set_intr_mask(info_p, 0);
36146 /* Make sure there is room in the command FIFO */
36147 /* Actually it should be completely empty at this time. */
36148 for (i = 200000; i > 0; i--) {
36149- temp = info_p->access.fifo_full(info_p);
36150+ temp = info_p->access->fifo_full(info_p);
36151 if (temp != 0) {
36152 break;
36153 }
36154@@ -1464,7 +1465,7 @@ DBG(
36155 /*
36156 * Send the cmd
36157 */
36158- info_p->access.submit_command(info_p, c);
36159+ info_p->access->submit_command(info_p, c);
36160 complete = pollcomplete(ctlr);
36161
36162 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
36163@@ -1547,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
36164 * we check the new geometry. Then turn interrupts back on when
36165 * we're done.
36166 */
36167- host->access.set_intr_mask(host, 0);
36168+ host->access->set_intr_mask(host, 0);
36169 getgeometry(ctlr);
36170- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
36171+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
36172
36173 for(i=0; i<NWD; i++) {
36174 struct gendisk *disk = ida_gendisk[ctlr][i];
36175@@ -1589,7 +1590,7 @@ static int pollcomplete(int ctlr)
36176 /* Wait (up to 2 seconds) for a command to complete */
36177
36178 for (i = 200000; i > 0; i--) {
36179- done = hba[ctlr]->access.command_completed(hba[ctlr]);
36180+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
36181 if (done == 0) {
36182 udelay(10); /* a short fixed delay */
36183 } else
36184diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
36185index be73e9d..7fbf140 100644
36186--- a/drivers/block/cpqarray.h
36187+++ b/drivers/block/cpqarray.h
36188@@ -99,7 +99,7 @@ struct ctlr_info {
36189 drv_info_t drv[NWD];
36190 struct proc_dir_entry *proc;
36191
36192- struct access_method access;
36193+ struct access_method *access;
36194
36195 cmdlist_t *reqQ;
36196 cmdlist_t *cmpQ;
36197diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
36198index 2d7f608..11245fe 100644
36199--- a/drivers/block/drbd/drbd_int.h
36200+++ b/drivers/block/drbd/drbd_int.h
36201@@ -582,7 +582,7 @@ struct drbd_epoch {
36202 struct drbd_tconn *tconn;
36203 struct list_head list;
36204 unsigned int barrier_nr;
36205- atomic_t epoch_size; /* increased on every request added. */
36206+ atomic_unchecked_t epoch_size; /* increased on every request added. */
36207 atomic_t active; /* increased on every req. added, and dec on every finished. */
36208 unsigned long flags;
36209 };
36210@@ -1022,7 +1022,7 @@ struct drbd_conf {
36211 unsigned int al_tr_number;
36212 int al_tr_cycle;
36213 wait_queue_head_t seq_wait;
36214- atomic_t packet_seq;
36215+ atomic_unchecked_t packet_seq;
36216 unsigned int peer_seq;
36217 spinlock_t peer_seq_lock;
36218 unsigned int minor;
36219@@ -1572,7 +1572,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
36220 char __user *uoptval;
36221 int err;
36222
36223- uoptval = (char __user __force *)optval;
36224+ uoptval = (char __force_user *)optval;
36225
36226 set_fs(KERNEL_DS);
36227 if (level == SOL_SOCKET)
36228diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
36229index 55635ed..40e837c 100644
36230--- a/drivers/block/drbd/drbd_main.c
36231+++ b/drivers/block/drbd/drbd_main.c
36232@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
36233 p->sector = sector;
36234 p->block_id = block_id;
36235 p->blksize = blksize;
36236- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36237+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36238 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
36239 }
36240
36241@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
36242 return -EIO;
36243 p->sector = cpu_to_be64(req->i.sector);
36244 p->block_id = (unsigned long)req;
36245- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36246+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36247 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
36248 if (mdev->state.conn >= C_SYNC_SOURCE &&
36249 mdev->state.conn <= C_PAUSED_SYNC_T)
36250@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
36251 {
36252 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
36253
36254- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
36255- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
36256+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
36257+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
36258 kfree(tconn->current_epoch);
36259
36260 idr_destroy(&tconn->volumes);
36261diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
36262index 8cc1e64..ba7ffa9 100644
36263--- a/drivers/block/drbd/drbd_nl.c
36264+++ b/drivers/block/drbd/drbd_nl.c
36265@@ -3440,7 +3440,7 @@ out:
36266
36267 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36268 {
36269- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36270+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36271 struct sk_buff *msg;
36272 struct drbd_genlmsghdr *d_out;
36273 unsigned seq;
36274@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36275 return;
36276 }
36277
36278- seq = atomic_inc_return(&drbd_genl_seq);
36279+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
36280 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
36281 if (!msg)
36282 goto failed;
36283diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
36284index cc29cd3..d4b058b 100644
36285--- a/drivers/block/drbd/drbd_receiver.c
36286+++ b/drivers/block/drbd/drbd_receiver.c
36287@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
36288 {
36289 int err;
36290
36291- atomic_set(&mdev->packet_seq, 0);
36292+ atomic_set_unchecked(&mdev->packet_seq, 0);
36293 mdev->peer_seq = 0;
36294
36295 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
36296@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36297 do {
36298 next_epoch = NULL;
36299
36300- epoch_size = atomic_read(&epoch->epoch_size);
36301+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
36302
36303 switch (ev & ~EV_CLEANUP) {
36304 case EV_PUT:
36305@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36306 rv = FE_DESTROYED;
36307 } else {
36308 epoch->flags = 0;
36309- atomic_set(&epoch->epoch_size, 0);
36310+ atomic_set_unchecked(&epoch->epoch_size, 0);
36311 /* atomic_set(&epoch->active, 0); is already zero */
36312 if (rv == FE_STILL_LIVE)
36313 rv = FE_RECYCLED;
36314@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36315 conn_wait_active_ee_empty(tconn);
36316 drbd_flush(tconn);
36317
36318- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36319+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36320 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
36321 if (epoch)
36322 break;
36323@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36324 }
36325
36326 epoch->flags = 0;
36327- atomic_set(&epoch->epoch_size, 0);
36328+ atomic_set_unchecked(&epoch->epoch_size, 0);
36329 atomic_set(&epoch->active, 0);
36330
36331 spin_lock(&tconn->epoch_lock);
36332- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36333+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36334 list_add(&epoch->list, &tconn->current_epoch->list);
36335 tconn->current_epoch = epoch;
36336 tconn->epochs++;
36337@@ -2172,7 +2172,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36338
36339 err = wait_for_and_update_peer_seq(mdev, peer_seq);
36340 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
36341- atomic_inc(&tconn->current_epoch->epoch_size);
36342+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
36343 err2 = drbd_drain_block(mdev, pi->size);
36344 if (!err)
36345 err = err2;
36346@@ -2206,7 +2206,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36347
36348 spin_lock(&tconn->epoch_lock);
36349 peer_req->epoch = tconn->current_epoch;
36350- atomic_inc(&peer_req->epoch->epoch_size);
36351+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
36352 atomic_inc(&peer_req->epoch->active);
36353 spin_unlock(&tconn->epoch_lock);
36354
36355@@ -4347,7 +4347,7 @@ struct data_cmd {
36356 int expect_payload;
36357 size_t pkt_size;
36358 int (*fn)(struct drbd_tconn *, struct packet_info *);
36359-};
36360+} __do_const;
36361
36362 static struct data_cmd drbd_cmd_handler[] = {
36363 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
36364@@ -4467,7 +4467,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
36365 if (!list_empty(&tconn->current_epoch->list))
36366 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
36367 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
36368- atomic_set(&tconn->current_epoch->epoch_size, 0);
36369+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
36370 tconn->send.seen_any_write_yet = false;
36371
36372 conn_info(tconn, "Connection closed\n");
36373@@ -5223,7 +5223,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
36374 struct asender_cmd {
36375 size_t pkt_size;
36376 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
36377-};
36378+} __do_const;
36379
36380 static struct asender_cmd asender_tbl[] = {
36381 [P_PING] = { 0, got_Ping },
36382diff --git a/drivers/block/loop.c b/drivers/block/loop.c
36383index 40e7155..df5c79a 100644
36384--- a/drivers/block/loop.c
36385+++ b/drivers/block/loop.c
36386@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
36387
36388 file_start_write(file);
36389 set_fs(get_ds());
36390- bw = file->f_op->write(file, buf, len, &pos);
36391+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
36392 set_fs(old_fs);
36393 file_end_write(file);
36394 if (likely(bw == len))
36395diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
36396index f5d0ea1..c62380a 100644
36397--- a/drivers/block/pktcdvd.c
36398+++ b/drivers/block/pktcdvd.c
36399@@ -84,7 +84,7 @@
36400 #define MAX_SPEED 0xffff
36401
36402 #define ZONE(sector, pd) (((sector) + (pd)->offset) & \
36403- ~(sector_t)((pd)->settings.size - 1))
36404+ ~(sector_t)((pd)->settings.size - 1UL))
36405
36406 static DEFINE_MUTEX(pktcdvd_mutex);
36407 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
36408diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
36409index 8a3aff7..d7538c2 100644
36410--- a/drivers/cdrom/cdrom.c
36411+++ b/drivers/cdrom/cdrom.c
36412@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
36413 ENSURE(reset, CDC_RESET);
36414 ENSURE(generic_packet, CDC_GENERIC_PACKET);
36415 cdi->mc_flags = 0;
36416- cdo->n_minors = 0;
36417 cdi->options = CDO_USE_FFLAGS;
36418
36419 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
36420@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
36421 else
36422 cdi->cdda_method = CDDA_OLD;
36423
36424- if (!cdo->generic_packet)
36425- cdo->generic_packet = cdrom_dummy_generic_packet;
36426+ if (!cdo->generic_packet) {
36427+ pax_open_kernel();
36428+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
36429+ pax_close_kernel();
36430+ }
36431
36432 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
36433 mutex_lock(&cdrom_mutex);
36434@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
36435 if (cdi->exit)
36436 cdi->exit(cdi);
36437
36438- cdi->ops->n_minors--;
36439 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
36440 }
36441
36442@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
36443 */
36444 nr = nframes;
36445 do {
36446- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36447+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36448 if (cgc.buffer)
36449 break;
36450
36451@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
36452 struct cdrom_device_info *cdi;
36453 int ret;
36454
36455- ret = scnprintf(info + *pos, max_size - *pos, header);
36456+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
36457 if (!ret)
36458 return 1;
36459
36460diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
36461index 5980cb9..6d7bd7e 100644
36462--- a/drivers/cdrom/gdrom.c
36463+++ b/drivers/cdrom/gdrom.c
36464@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
36465 .audio_ioctl = gdrom_audio_ioctl,
36466 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
36467 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
36468- .n_minors = 1,
36469 };
36470
36471 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
36472diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
36473index 1421997..33f5d6d 100644
36474--- a/drivers/char/Kconfig
36475+++ b/drivers/char/Kconfig
36476@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
36477
36478 config DEVKMEM
36479 bool "/dev/kmem virtual device support"
36480- default y
36481+ default n
36482+ depends on !GRKERNSEC_KMEM
36483 help
36484 Say Y here if you want to support the /dev/kmem device. The
36485 /dev/kmem device is rarely used, but can be used for certain
36486@@ -570,6 +571,7 @@ config DEVPORT
36487 bool
36488 depends on !M68K
36489 depends on ISA || PCI
36490+ depends on !GRKERNSEC_KMEM
36491 default y
36492
36493 source "drivers/s390/char/Kconfig"
36494diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
36495index a48e05b..6bac831 100644
36496--- a/drivers/char/agp/compat_ioctl.c
36497+++ b/drivers/char/agp/compat_ioctl.c
36498@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
36499 return -ENOMEM;
36500 }
36501
36502- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
36503+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
36504 sizeof(*usegment) * ureserve.seg_count)) {
36505 kfree(usegment);
36506 kfree(ksegment);
36507diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
36508index 1b19239..b87b143 100644
36509--- a/drivers/char/agp/frontend.c
36510+++ b/drivers/char/agp/frontend.c
36511@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36512 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
36513 return -EFAULT;
36514
36515- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
36516+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
36517 return -EFAULT;
36518
36519 client = agp_find_client_by_pid(reserve.pid);
36520@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36521 if (segment == NULL)
36522 return -ENOMEM;
36523
36524- if (copy_from_user(segment, (void __user *) reserve.seg_list,
36525+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
36526 sizeof(struct agp_segment) * reserve.seg_count)) {
36527 kfree(segment);
36528 return -EFAULT;
36529diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
36530index 4f94375..413694e 100644
36531--- a/drivers/char/genrtc.c
36532+++ b/drivers/char/genrtc.c
36533@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
36534 switch (cmd) {
36535
36536 case RTC_PLL_GET:
36537+ memset(&pll, 0, sizeof(pll));
36538 if (get_rtc_pll(&pll))
36539 return -EINVAL;
36540 else
36541diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
36542index 448ce5e..3a76625 100644
36543--- a/drivers/char/hpet.c
36544+++ b/drivers/char/hpet.c
36545@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
36546 }
36547
36548 static int
36549-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
36550+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
36551 struct hpet_info *info)
36552 {
36553 struct hpet_timer __iomem *timer;
36554diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
36555index 86fe45c..c0ea948 100644
36556--- a/drivers/char/hw_random/intel-rng.c
36557+++ b/drivers/char/hw_random/intel-rng.c
36558@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
36559
36560 if (no_fwh_detect)
36561 return -ENODEV;
36562- printk(warning);
36563+ printk("%s", warning);
36564 return -EBUSY;
36565 }
36566
36567diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
36568index 4445fa1..7c6de37 100644
36569--- a/drivers/char/ipmi/ipmi_msghandler.c
36570+++ b/drivers/char/ipmi/ipmi_msghandler.c
36571@@ -420,7 +420,7 @@ struct ipmi_smi {
36572 struct proc_dir_entry *proc_dir;
36573 char proc_dir_name[10];
36574
36575- atomic_t stats[IPMI_NUM_STATS];
36576+ atomic_unchecked_t stats[IPMI_NUM_STATS];
36577
36578 /*
36579 * run_to_completion duplicate of smb_info, smi_info
36580@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
36581
36582
36583 #define ipmi_inc_stat(intf, stat) \
36584- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
36585+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
36586 #define ipmi_get_stat(intf, stat) \
36587- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
36588+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
36589
36590 static int is_lan_addr(struct ipmi_addr *addr)
36591 {
36592@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
36593 INIT_LIST_HEAD(&intf->cmd_rcvrs);
36594 init_waitqueue_head(&intf->waitq);
36595 for (i = 0; i < IPMI_NUM_STATS; i++)
36596- atomic_set(&intf->stats[i], 0);
36597+ atomic_set_unchecked(&intf->stats[i], 0);
36598
36599 intf->proc_dir = NULL;
36600
36601diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
36602index af4b23f..79806fc 100644
36603--- a/drivers/char/ipmi/ipmi_si_intf.c
36604+++ b/drivers/char/ipmi/ipmi_si_intf.c
36605@@ -275,7 +275,7 @@ struct smi_info {
36606 unsigned char slave_addr;
36607
36608 /* Counters and things for the proc filesystem. */
36609- atomic_t stats[SI_NUM_STATS];
36610+ atomic_unchecked_t stats[SI_NUM_STATS];
36611
36612 struct task_struct *thread;
36613
36614@@ -284,9 +284,9 @@ struct smi_info {
36615 };
36616
36617 #define smi_inc_stat(smi, stat) \
36618- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
36619+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
36620 #define smi_get_stat(smi, stat) \
36621- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
36622+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
36623
36624 #define SI_MAX_PARMS 4
36625
36626@@ -3258,7 +3258,7 @@ static int try_smi_init(struct smi_info *new_smi)
36627 atomic_set(&new_smi->req_events, 0);
36628 new_smi->run_to_completion = 0;
36629 for (i = 0; i < SI_NUM_STATS; i++)
36630- atomic_set(&new_smi->stats[i], 0);
36631+ atomic_set_unchecked(&new_smi->stats[i], 0);
36632
36633 new_smi->interrupt_disabled = 1;
36634 atomic_set(&new_smi->stop_operation, 0);
36635diff --git a/drivers/char/mem.c b/drivers/char/mem.c
36636index f895a8c..2bc9147 100644
36637--- a/drivers/char/mem.c
36638+++ b/drivers/char/mem.c
36639@@ -18,6 +18,7 @@
36640 #include <linux/raw.h>
36641 #include <linux/tty.h>
36642 #include <linux/capability.h>
36643+#include <linux/security.h>
36644 #include <linux/ptrace.h>
36645 #include <linux/device.h>
36646 #include <linux/highmem.h>
36647@@ -37,6 +38,10 @@
36648
36649 #define DEVPORT_MINOR 4
36650
36651+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36652+extern const struct file_operations grsec_fops;
36653+#endif
36654+
36655 static inline unsigned long size_inside_page(unsigned long start,
36656 unsigned long size)
36657 {
36658@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36659
36660 while (cursor < to) {
36661 if (!devmem_is_allowed(pfn)) {
36662+#ifdef CONFIG_GRKERNSEC_KMEM
36663+ gr_handle_mem_readwrite(from, to);
36664+#else
36665 printk(KERN_INFO
36666 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
36667 current->comm, from, to);
36668+#endif
36669 return 0;
36670 }
36671 cursor += PAGE_SIZE;
36672@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36673 }
36674 return 1;
36675 }
36676+#elif defined(CONFIG_GRKERNSEC_KMEM)
36677+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36678+{
36679+ return 0;
36680+}
36681 #else
36682 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36683 {
36684@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36685
36686 while (count > 0) {
36687 unsigned long remaining;
36688+ char *temp;
36689
36690 sz = size_inside_page(p, count);
36691
36692@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36693 if (!ptr)
36694 return -EFAULT;
36695
36696- remaining = copy_to_user(buf, ptr, sz);
36697+#ifdef CONFIG_PAX_USERCOPY
36698+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36699+ if (!temp) {
36700+ unxlate_dev_mem_ptr(p, ptr);
36701+ return -ENOMEM;
36702+ }
36703+ memcpy(temp, ptr, sz);
36704+#else
36705+ temp = ptr;
36706+#endif
36707+
36708+ remaining = copy_to_user(buf, temp, sz);
36709+
36710+#ifdef CONFIG_PAX_USERCOPY
36711+ kfree(temp);
36712+#endif
36713+
36714 unxlate_dev_mem_ptr(p, ptr);
36715 if (remaining)
36716 return -EFAULT;
36717@@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36718 size_t count, loff_t *ppos)
36719 {
36720 unsigned long p = *ppos;
36721- ssize_t low_count, read, sz;
36722+ ssize_t low_count, read, sz, err = 0;
36723 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
36724- int err = 0;
36725
36726 read = 0;
36727 if (p < (unsigned long) high_memory) {
36728@@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36729 }
36730 #endif
36731 while (low_count > 0) {
36732+ char *temp;
36733+
36734 sz = size_inside_page(p, low_count);
36735
36736 /*
36737@@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36738 */
36739 kbuf = xlate_dev_kmem_ptr((char *)p);
36740
36741- if (copy_to_user(buf, kbuf, sz))
36742+#ifdef CONFIG_PAX_USERCOPY
36743+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36744+ if (!temp)
36745+ return -ENOMEM;
36746+ memcpy(temp, kbuf, sz);
36747+#else
36748+ temp = kbuf;
36749+#endif
36750+
36751+ err = copy_to_user(buf, temp, sz);
36752+
36753+#ifdef CONFIG_PAX_USERCOPY
36754+ kfree(temp);
36755+#endif
36756+
36757+ if (err)
36758 return -EFAULT;
36759 buf += sz;
36760 p += sz;
36761@@ -822,6 +869,9 @@ static const struct memdev {
36762 #ifdef CONFIG_PRINTK
36763 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
36764 #endif
36765+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36766+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
36767+#endif
36768 };
36769
36770 static int memory_open(struct inode *inode, struct file *filp)
36771@@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
36772 continue;
36773
36774 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
36775- NULL, devlist[minor].name);
36776+ NULL, "%s", devlist[minor].name);
36777 }
36778
36779 return tty_init();
36780diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
36781index 9df78e2..01ba9ae 100644
36782--- a/drivers/char/nvram.c
36783+++ b/drivers/char/nvram.c
36784@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
36785
36786 spin_unlock_irq(&rtc_lock);
36787
36788- if (copy_to_user(buf, contents, tmp - contents))
36789+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
36790 return -EFAULT;
36791
36792 *ppos = i;
36793diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
36794index 5c5cc00..ac9edb7 100644
36795--- a/drivers/char/pcmcia/synclink_cs.c
36796+++ b/drivers/char/pcmcia/synclink_cs.c
36797@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36798
36799 if (debug_level >= DEBUG_LEVEL_INFO)
36800 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
36801- __FILE__, __LINE__, info->device_name, port->count);
36802+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
36803
36804- WARN_ON(!port->count);
36805+ WARN_ON(!atomic_read(&port->count));
36806
36807 if (tty_port_close_start(port, tty, filp) == 0)
36808 goto cleanup;
36809@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36810 cleanup:
36811 if (debug_level >= DEBUG_LEVEL_INFO)
36812 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
36813- tty->driver->name, port->count);
36814+ tty->driver->name, atomic_read(&port->count));
36815 }
36816
36817 /* Wait until the transmitter is empty.
36818@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36819
36820 if (debug_level >= DEBUG_LEVEL_INFO)
36821 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
36822- __FILE__, __LINE__, tty->driver->name, port->count);
36823+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
36824
36825 /* If port is closing, signal caller to try again */
36826 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
36827@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36828 goto cleanup;
36829 }
36830 spin_lock(&port->lock);
36831- port->count++;
36832+ atomic_inc(&port->count);
36833 spin_unlock(&port->lock);
36834 spin_unlock_irqrestore(&info->netlock, flags);
36835
36836- if (port->count == 1) {
36837+ if (atomic_read(&port->count) == 1) {
36838 /* 1st open on this device, init hardware */
36839 retval = startup(info, tty);
36840 if (retval < 0)
36841@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
36842 unsigned short new_crctype;
36843
36844 /* return error if TTY interface open */
36845- if (info->port.count)
36846+ if (atomic_read(&info->port.count))
36847 return -EBUSY;
36848
36849 switch (encoding)
36850@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
36851
36852 /* arbitrate between network and tty opens */
36853 spin_lock_irqsave(&info->netlock, flags);
36854- if (info->port.count != 0 || info->netcount != 0) {
36855+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
36856 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
36857 spin_unlock_irqrestore(&info->netlock, flags);
36858 return -EBUSY;
36859@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36860 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
36861
36862 /* return error if TTY interface open */
36863- if (info->port.count)
36864+ if (atomic_read(&info->port.count))
36865 return -EBUSY;
36866
36867 if (cmd != SIOCWANDEV)
36868diff --git a/drivers/char/random.c b/drivers/char/random.c
36869index 0d91fe5..f8e37b0 100644
36870--- a/drivers/char/random.c
36871+++ b/drivers/char/random.c
36872@@ -272,8 +272,13 @@
36873 /*
36874 * Configuration information
36875 */
36876+#ifdef CONFIG_GRKERNSEC_RANDNET
36877+#define INPUT_POOL_WORDS 512
36878+#define OUTPUT_POOL_WORDS 128
36879+#else
36880 #define INPUT_POOL_WORDS 128
36881 #define OUTPUT_POOL_WORDS 32
36882+#endif
36883 #define SEC_XFER_SIZE 512
36884 #define EXTRACT_SIZE 10
36885
36886@@ -313,10 +318,17 @@ static struct poolinfo {
36887 int poolwords;
36888 int tap1, tap2, tap3, tap4, tap5;
36889 } poolinfo_table[] = {
36890+#ifdef CONFIG_GRKERNSEC_RANDNET
36891+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
36892+ { 512, 411, 308, 208, 104, 1 },
36893+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
36894+ { 128, 103, 76, 51, 25, 1 },
36895+#else
36896 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
36897 { 128, 103, 76, 51, 25, 1 },
36898 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
36899 { 32, 26, 20, 14, 7, 1 },
36900+#endif
36901 #if 0
36902 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
36903 { 2048, 1638, 1231, 819, 411, 1 },
36904@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
36905 input_rotate += i ? 7 : 14;
36906 }
36907
36908- ACCESS_ONCE(r->input_rotate) = input_rotate;
36909- ACCESS_ONCE(r->add_ptr) = i;
36910+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
36911+ ACCESS_ONCE_RW(r->add_ptr) = i;
36912 smp_wmb();
36913
36914 if (out)
36915@@ -1032,7 +1044,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
36916
36917 extract_buf(r, tmp);
36918 i = min_t(int, nbytes, EXTRACT_SIZE);
36919- if (copy_to_user(buf, tmp, i)) {
36920+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
36921 ret = -EFAULT;
36922 break;
36923 }
36924@@ -1368,7 +1380,7 @@ EXPORT_SYMBOL(generate_random_uuid);
36925 #include <linux/sysctl.h>
36926
36927 static int min_read_thresh = 8, min_write_thresh;
36928-static int max_read_thresh = INPUT_POOL_WORDS * 32;
36929+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
36930 static int max_write_thresh = INPUT_POOL_WORDS * 32;
36931 static char sysctl_bootid[16];
36932
36933@@ -1384,7 +1396,7 @@ static char sysctl_bootid[16];
36934 static int proc_do_uuid(struct ctl_table *table, int write,
36935 void __user *buffer, size_t *lenp, loff_t *ppos)
36936 {
36937- struct ctl_table fake_table;
36938+ ctl_table_no_const fake_table;
36939 unsigned char buf[64], tmp_uuid[16], *uuid;
36940
36941 uuid = table->data;
36942diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
36943index bf2349db..5456d53 100644
36944--- a/drivers/char/sonypi.c
36945+++ b/drivers/char/sonypi.c
36946@@ -54,6 +54,7 @@
36947
36948 #include <asm/uaccess.h>
36949 #include <asm/io.h>
36950+#include <asm/local.h>
36951
36952 #include <linux/sonypi.h>
36953
36954@@ -490,7 +491,7 @@ static struct sonypi_device {
36955 spinlock_t fifo_lock;
36956 wait_queue_head_t fifo_proc_list;
36957 struct fasync_struct *fifo_async;
36958- int open_count;
36959+ local_t open_count;
36960 int model;
36961 struct input_dev *input_jog_dev;
36962 struct input_dev *input_key_dev;
36963@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
36964 static int sonypi_misc_release(struct inode *inode, struct file *file)
36965 {
36966 mutex_lock(&sonypi_device.lock);
36967- sonypi_device.open_count--;
36968+ local_dec(&sonypi_device.open_count);
36969 mutex_unlock(&sonypi_device.lock);
36970 return 0;
36971 }
36972@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
36973 {
36974 mutex_lock(&sonypi_device.lock);
36975 /* Flush input queue on first open */
36976- if (!sonypi_device.open_count)
36977+ if (!local_read(&sonypi_device.open_count))
36978 kfifo_reset(&sonypi_device.fifo);
36979- sonypi_device.open_count++;
36980+ local_inc(&sonypi_device.open_count);
36981 mutex_unlock(&sonypi_device.lock);
36982
36983 return 0;
36984diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
36985index 64420b3..5c40b56 100644
36986--- a/drivers/char/tpm/tpm_acpi.c
36987+++ b/drivers/char/tpm/tpm_acpi.c
36988@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
36989 virt = acpi_os_map_memory(start, len);
36990 if (!virt) {
36991 kfree(log->bios_event_log);
36992+ log->bios_event_log = NULL;
36993 printk("%s: ERROR - Unable to map memory\n", __func__);
36994 return -EIO;
36995 }
36996
36997- memcpy_fromio(log->bios_event_log, virt, len);
36998+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
36999
37000 acpi_os_unmap_memory(virt, len);
37001 return 0;
37002diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
37003index 84ddc55..1d32f1e 100644
37004--- a/drivers/char/tpm/tpm_eventlog.c
37005+++ b/drivers/char/tpm/tpm_eventlog.c
37006@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
37007 event = addr;
37008
37009 if ((event->event_type == 0 && event->event_size == 0) ||
37010- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
37011+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
37012 return NULL;
37013
37014 return addr;
37015@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
37016 return NULL;
37017
37018 if ((event->event_type == 0 && event->event_size == 0) ||
37019- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
37020+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
37021 return NULL;
37022
37023 (*pos)++;
37024@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
37025 int i;
37026
37027 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
37028- seq_putc(m, data[i]);
37029+ if (!seq_putc(m, data[i]))
37030+ return -EFAULT;
37031
37032 return 0;
37033 }
37034diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
37035index fc45567..fa2a590 100644
37036--- a/drivers/char/virtio_console.c
37037+++ b/drivers/char/virtio_console.c
37038@@ -682,7 +682,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
37039 if (to_user) {
37040 ssize_t ret;
37041
37042- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
37043+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
37044 if (ret)
37045 return -EFAULT;
37046 } else {
37047@@ -785,7 +785,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
37048 if (!port_has_data(port) && !port->host_connected)
37049 return 0;
37050
37051- return fill_readbuf(port, ubuf, count, true);
37052+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
37053 }
37054
37055 static int wait_port_writable(struct port *port, bool nonblock)
37056diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
37057index a33f46f..a720eed 100644
37058--- a/drivers/clk/clk-composite.c
37059+++ b/drivers/clk/clk-composite.c
37060@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
37061 struct clk *clk;
37062 struct clk_init_data init;
37063 struct clk_composite *composite;
37064- struct clk_ops *clk_composite_ops;
37065+ clk_ops_no_const *clk_composite_ops;
37066
37067 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
37068 if (!composite) {
37069diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
37070index 5bb848c..f00ff83 100644
37071--- a/drivers/clk/socfpga/clk.c
37072+++ b/drivers/clk/socfpga/clk.c
37073@@ -22,6 +22,7 @@
37074 #include <linux/clk-provider.h>
37075 #include <linux/io.h>
37076 #include <linux/of.h>
37077+#include <asm/pgtable.h>
37078
37079 /* Clock Manager offsets */
37080 #define CLKMGR_CTRL 0x0
37081@@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
37082 streq(clk_name, "periph_pll") ||
37083 streq(clk_name, "sdram_pll")) {
37084 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
37085- clk_pll_ops.enable = clk_gate_ops.enable;
37086- clk_pll_ops.disable = clk_gate_ops.disable;
37087+ pax_open_kernel();
37088+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
37089+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
37090+ pax_close_kernel();
37091 }
37092
37093 clk = clk_register(NULL, &socfpga_clk->hw.hw);
37094diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
37095index 3926402..37b580d 100644
37096--- a/drivers/cpufreq/acpi-cpufreq.c
37097+++ b/drivers/cpufreq/acpi-cpufreq.c
37098@@ -173,7 +173,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
37099 return sprintf(buf, "%u\n", boost_enabled);
37100 }
37101
37102-static struct global_attr global_boost = __ATTR(boost, 0644,
37103+static global_attr_no_const global_boost = __ATTR(boost, 0644,
37104 show_global_boost,
37105 store_global_boost);
37106
37107@@ -722,8 +722,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37108 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
37109 per_cpu(acfreq_data, cpu) = data;
37110
37111- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
37112- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37113+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
37114+ pax_open_kernel();
37115+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37116+ pax_close_kernel();
37117+ }
37118
37119 result = acpi_processor_register_performance(data->acpi_data, cpu);
37120 if (result)
37121@@ -851,7 +854,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37122 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
37123 break;
37124 case ACPI_ADR_SPACE_FIXED_HARDWARE:
37125- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37126+ pax_open_kernel();
37127+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37128+ pax_close_kernel();
37129 policy->cur = get_cur_freq_on_cpu(cpu);
37130 break;
37131 default:
37132@@ -862,8 +867,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37133 acpi_processor_notify_smm(THIS_MODULE);
37134
37135 /* Check for APERF/MPERF support in hardware */
37136- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
37137- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
37138+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
37139+ pax_open_kernel();
37140+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
37141+ pax_close_kernel();
37142+ }
37143
37144 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
37145 for (i = 0; i < perf->state_count; i++)
37146diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
37147index f0a5e2b..0a7ee46 100644
37148--- a/drivers/cpufreq/cpufreq.c
37149+++ b/drivers/cpufreq/cpufreq.c
37150@@ -1959,7 +1959,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
37151 return NOTIFY_OK;
37152 }
37153
37154-static struct notifier_block __refdata cpufreq_cpu_notifier = {
37155+static struct notifier_block cpufreq_cpu_notifier = {
37156 .notifier_call = cpufreq_cpu_callback,
37157 };
37158
37159@@ -1991,8 +1991,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
37160
37161 pr_debug("trying to register driver %s\n", driver_data->name);
37162
37163- if (driver_data->setpolicy)
37164- driver_data->flags |= CPUFREQ_CONST_LOOPS;
37165+ if (driver_data->setpolicy) {
37166+ pax_open_kernel();
37167+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
37168+ pax_close_kernel();
37169+ }
37170
37171 write_lock_irqsave(&cpufreq_driver_lock, flags);
37172 if (cpufreq_driver) {
37173diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
37174index e59afaa..a53a3ff 100644
37175--- a/drivers/cpufreq/cpufreq_governor.c
37176+++ b/drivers/cpufreq/cpufreq_governor.c
37177@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37178 struct dbs_data *dbs_data;
37179 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
37180 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
37181- struct od_ops *od_ops = NULL;
37182+ const struct od_ops *od_ops = NULL;
37183 struct od_dbs_tuners *od_tuners = NULL;
37184 struct cs_dbs_tuners *cs_tuners = NULL;
37185 struct cpu_dbs_common_info *cpu_cdbs;
37186@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37187
37188 if ((cdata->governor == GOV_CONSERVATIVE) &&
37189 (!policy->governor->initialized)) {
37190- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37191+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37192
37193 cpufreq_register_notifier(cs_ops->notifier_block,
37194 CPUFREQ_TRANSITION_NOTIFIER);
37195@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37196
37197 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
37198 (policy->governor->initialized == 1)) {
37199- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37200+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37201
37202 cpufreq_unregister_notifier(cs_ops->notifier_block,
37203 CPUFREQ_TRANSITION_NOTIFIER);
37204diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
37205index d5f12b4..421daae 100644
37206--- a/drivers/cpufreq/cpufreq_governor.h
37207+++ b/drivers/cpufreq/cpufreq_governor.h
37208@@ -204,7 +204,7 @@ struct common_dbs_data {
37209 void (*exit)(struct dbs_data *dbs_data);
37210
37211 /* Governor specific ops, see below */
37212- void *gov_ops;
37213+ const void *gov_ops;
37214 };
37215
37216 /* Governer Per policy data */
37217diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
37218index c087347..dad6268 100644
37219--- a/drivers/cpufreq/cpufreq_ondemand.c
37220+++ b/drivers/cpufreq/cpufreq_ondemand.c
37221@@ -615,14 +615,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
37222 (struct cpufreq_policy *, unsigned int, unsigned int),
37223 unsigned int powersave_bias)
37224 {
37225- od_ops.powersave_bias_target = f;
37226+ pax_open_kernel();
37227+ *(void **)&od_ops.powersave_bias_target = f;
37228+ pax_close_kernel();
37229 od_set_powersave_bias(powersave_bias);
37230 }
37231 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
37232
37233 void od_unregister_powersave_bias_handler(void)
37234 {
37235- od_ops.powersave_bias_target = generic_powersave_bias_target;
37236+ pax_open_kernel();
37237+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
37238+ pax_close_kernel();
37239 od_set_powersave_bias(0);
37240 }
37241 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
37242diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
37243index d37568c..fbb19a1 100644
37244--- a/drivers/cpufreq/cpufreq_stats.c
37245+++ b/drivers/cpufreq/cpufreq_stats.c
37246@@ -365,7 +365,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
37247 }
37248
37249 /* priority=1 so this will get called before cpufreq_remove_dev */
37250-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
37251+static struct notifier_block cpufreq_stat_cpu_notifier = {
37252 .notifier_call = cpufreq_stat_cpu_callback,
37253 .priority = 1,
37254 };
37255diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
37256index 9ee7817..17b658e 100644
37257--- a/drivers/cpufreq/p4-clockmod.c
37258+++ b/drivers/cpufreq/p4-clockmod.c
37259@@ -160,10 +160,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37260 case 0x0F: /* Core Duo */
37261 case 0x16: /* Celeron Core */
37262 case 0x1C: /* Atom */
37263- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37264+ pax_open_kernel();
37265+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37266+ pax_close_kernel();
37267 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
37268 case 0x0D: /* Pentium M (Dothan) */
37269- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37270+ pax_open_kernel();
37271+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37272+ pax_close_kernel();
37273 /* fall through */
37274 case 0x09: /* Pentium M (Banias) */
37275 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
37276@@ -175,7 +179,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37277
37278 /* on P-4s, the TSC runs with constant frequency independent whether
37279 * throttling is active or not. */
37280- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37281+ pax_open_kernel();
37282+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37283+ pax_close_kernel();
37284
37285 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
37286 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
37287diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
37288index 880ee29..2445bc6 100644
37289--- a/drivers/cpufreq/sparc-us3-cpufreq.c
37290+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
37291@@ -18,14 +18,12 @@
37292 #include <asm/head.h>
37293 #include <asm/timer.h>
37294
37295-static struct cpufreq_driver *cpufreq_us3_driver;
37296-
37297 struct us3_freq_percpu_info {
37298 struct cpufreq_frequency_table table[4];
37299 };
37300
37301 /* Indexed by cpu number. */
37302-static struct us3_freq_percpu_info *us3_freq_table;
37303+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
37304
37305 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
37306 * in the Safari config register.
37307@@ -186,12 +184,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
37308
37309 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
37310 {
37311- if (cpufreq_us3_driver)
37312- us3_set_cpu_divider_index(policy, 0);
37313+ us3_set_cpu_divider_index(policy->cpu, 0);
37314
37315 return 0;
37316 }
37317
37318+static int __init us3_freq_init(void);
37319+static void __exit us3_freq_exit(void);
37320+
37321+static struct cpufreq_driver cpufreq_us3_driver = {
37322+ .init = us3_freq_cpu_init,
37323+ .verify = us3_freq_verify,
37324+ .target = us3_freq_target,
37325+ .get = us3_freq_get,
37326+ .exit = us3_freq_cpu_exit,
37327+ .owner = THIS_MODULE,
37328+ .name = "UltraSPARC-III",
37329+
37330+};
37331+
37332 static int __init us3_freq_init(void)
37333 {
37334 unsigned long manuf, impl, ver;
37335@@ -208,57 +219,15 @@ static int __init us3_freq_init(void)
37336 (impl == CHEETAH_IMPL ||
37337 impl == CHEETAH_PLUS_IMPL ||
37338 impl == JAGUAR_IMPL ||
37339- impl == PANTHER_IMPL)) {
37340- struct cpufreq_driver *driver;
37341-
37342- ret = -ENOMEM;
37343- driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
37344- if (!driver)
37345- goto err_out;
37346-
37347- us3_freq_table = kzalloc(
37348- (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
37349- GFP_KERNEL);
37350- if (!us3_freq_table)
37351- goto err_out;
37352-
37353- driver->init = us3_freq_cpu_init;
37354- driver->verify = us3_freq_verify;
37355- driver->target = us3_freq_target;
37356- driver->get = us3_freq_get;
37357- driver->exit = us3_freq_cpu_exit;
37358- driver->owner = THIS_MODULE,
37359- strcpy(driver->name, "UltraSPARC-III");
37360-
37361- cpufreq_us3_driver = driver;
37362- ret = cpufreq_register_driver(driver);
37363- if (ret)
37364- goto err_out;
37365-
37366- return 0;
37367-
37368-err_out:
37369- if (driver) {
37370- kfree(driver);
37371- cpufreq_us3_driver = NULL;
37372- }
37373- kfree(us3_freq_table);
37374- us3_freq_table = NULL;
37375- return ret;
37376- }
37377+ impl == PANTHER_IMPL))
37378+ return cpufreq_register_driver(&cpufreq_us3_driver);
37379
37380 return -ENODEV;
37381 }
37382
37383 static void __exit us3_freq_exit(void)
37384 {
37385- if (cpufreq_us3_driver) {
37386- cpufreq_unregister_driver(cpufreq_us3_driver);
37387- kfree(cpufreq_us3_driver);
37388- cpufreq_us3_driver = NULL;
37389- kfree(us3_freq_table);
37390- us3_freq_table = NULL;
37391- }
37392+ cpufreq_unregister_driver(&cpufreq_us3_driver);
37393 }
37394
37395 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
37396diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
37397index 0915e71..53376ed 100644
37398--- a/drivers/cpufreq/speedstep-centrino.c
37399+++ b/drivers/cpufreq/speedstep-centrino.c
37400@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
37401 !cpu_has(cpu, X86_FEATURE_EST))
37402 return -ENODEV;
37403
37404- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
37405- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37406+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
37407+ pax_open_kernel();
37408+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37409+ pax_close_kernel();
37410+ }
37411
37412 if (policy->cpu != 0)
37413 return -ENODEV;
37414diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
37415index fdc432f..98e64e2 100644
37416--- a/drivers/cpuidle/cpuidle.c
37417+++ b/drivers/cpuidle/cpuidle.c
37418@@ -254,7 +254,7 @@ static int poll_idle(struct cpuidle_device *dev,
37419
37420 static void poll_idle_init(struct cpuidle_driver *drv)
37421 {
37422- struct cpuidle_state *state = &drv->states[0];
37423+ cpuidle_state_no_const *state = &drv->states[0];
37424
37425 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
37426 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
37427diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
37428index ea2f8e7..70ac501 100644
37429--- a/drivers/cpuidle/governor.c
37430+++ b/drivers/cpuidle/governor.c
37431@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
37432 mutex_lock(&cpuidle_lock);
37433 if (__cpuidle_find_governor(gov->name) == NULL) {
37434 ret = 0;
37435- list_add_tail(&gov->governor_list, &cpuidle_governors);
37436+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
37437 if (!cpuidle_curr_governor ||
37438 cpuidle_curr_governor->rating < gov->rating)
37439 cpuidle_switch_governor(gov);
37440@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
37441 new_gov = cpuidle_replace_governor(gov->rating);
37442 cpuidle_switch_governor(new_gov);
37443 }
37444- list_del(&gov->governor_list);
37445+ pax_list_del((struct list_head *)&gov->governor_list);
37446 mutex_unlock(&cpuidle_lock);
37447 }
37448
37449diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
37450index 428754a..8bdf9cc 100644
37451--- a/drivers/cpuidle/sysfs.c
37452+++ b/drivers/cpuidle/sysfs.c
37453@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
37454 NULL
37455 };
37456
37457-static struct attribute_group cpuidle_attr_group = {
37458+static attribute_group_no_const cpuidle_attr_group = {
37459 .attrs = cpuidle_default_attrs,
37460 .name = "cpuidle",
37461 };
37462diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
37463index 12fea3e..1e28f47 100644
37464--- a/drivers/crypto/hifn_795x.c
37465+++ b/drivers/crypto/hifn_795x.c
37466@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
37467 MODULE_PARM_DESC(hifn_pll_ref,
37468 "PLL reference clock (pci[freq] or ext[freq], default ext)");
37469
37470-static atomic_t hifn_dev_number;
37471+static atomic_unchecked_t hifn_dev_number;
37472
37473 #define ACRYPTO_OP_DECRYPT 0
37474 #define ACRYPTO_OP_ENCRYPT 1
37475@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
37476 goto err_out_disable_pci_device;
37477
37478 snprintf(name, sizeof(name), "hifn%d",
37479- atomic_inc_return(&hifn_dev_number)-1);
37480+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
37481
37482 err = pci_request_regions(pdev, name);
37483 if (err)
37484diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
37485index e94e619..f7e249c 100644
37486--- a/drivers/devfreq/devfreq.c
37487+++ b/drivers/devfreq/devfreq.c
37488@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
37489 goto err_out;
37490 }
37491
37492- list_add(&governor->node, &devfreq_governor_list);
37493+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
37494
37495 list_for_each_entry(devfreq, &devfreq_list, node) {
37496 int ret = 0;
37497@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
37498 }
37499 }
37500
37501- list_del(&governor->node);
37502+ pax_list_del((struct list_head *)&governor->node);
37503 err_out:
37504 mutex_unlock(&devfreq_list_lock);
37505
37506diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
37507index 5039fbc..841169f 100644
37508--- a/drivers/dma/sh/shdma.c
37509+++ b/drivers/dma/sh/shdma.c
37510@@ -488,7 +488,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
37511 return ret;
37512 }
37513
37514-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
37515+static struct notifier_block sh_dmae_nmi_notifier = {
37516 .notifier_call = sh_dmae_nmi_handler,
37517
37518 /* Run before NMI debug handler and KGDB */
37519diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
37520index 211021d..201d47f 100644
37521--- a/drivers/edac/edac_device.c
37522+++ b/drivers/edac/edac_device.c
37523@@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
37524 */
37525 int edac_device_alloc_index(void)
37526 {
37527- static atomic_t device_indexes = ATOMIC_INIT(0);
37528+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
37529
37530- return atomic_inc_return(&device_indexes) - 1;
37531+ return atomic_inc_return_unchecked(&device_indexes) - 1;
37532 }
37533 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
37534
37535diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
37536index e7c32c4..6397af1 100644
37537--- a/drivers/edac/edac_mc_sysfs.c
37538+++ b/drivers/edac/edac_mc_sysfs.c
37539@@ -148,7 +148,7 @@ static const char * const edac_caps[] = {
37540 struct dev_ch_attribute {
37541 struct device_attribute attr;
37542 int channel;
37543-};
37544+} __do_const;
37545
37546 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
37547 struct dev_ch_attribute dev_attr_legacy_##_name = \
37548@@ -1005,14 +1005,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
37549 }
37550
37551 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
37552+ pax_open_kernel();
37553 if (mci->get_sdram_scrub_rate) {
37554- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37555- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37556+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37557+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37558 }
37559 if (mci->set_sdram_scrub_rate) {
37560- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37561- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37562+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37563+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37564 }
37565+ pax_close_kernel();
37566 err = device_create_file(&mci->dev,
37567 &dev_attr_sdram_scrub_rate);
37568 if (err) {
37569diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
37570index dd370f9..0281629 100644
37571--- a/drivers/edac/edac_pci.c
37572+++ b/drivers/edac/edac_pci.c
37573@@ -29,7 +29,7 @@
37574
37575 static DEFINE_MUTEX(edac_pci_ctls_mutex);
37576 static LIST_HEAD(edac_pci_list);
37577-static atomic_t pci_indexes = ATOMIC_INIT(0);
37578+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
37579
37580 /*
37581 * edac_pci_alloc_ctl_info
37582@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
37583 */
37584 int edac_pci_alloc_index(void)
37585 {
37586- return atomic_inc_return(&pci_indexes) - 1;
37587+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
37588 }
37589 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
37590
37591diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
37592index e8658e4..22746d6 100644
37593--- a/drivers/edac/edac_pci_sysfs.c
37594+++ b/drivers/edac/edac_pci_sysfs.c
37595@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
37596 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
37597 static int edac_pci_poll_msec = 1000; /* one second workq period */
37598
37599-static atomic_t pci_parity_count = ATOMIC_INIT(0);
37600-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
37601+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
37602+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
37603
37604 static struct kobject *edac_pci_top_main_kobj;
37605 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
37606@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
37607 void *value;
37608 ssize_t(*show) (void *, char *);
37609 ssize_t(*store) (void *, const char *, size_t);
37610-};
37611+} __do_const;
37612
37613 /* Set of show/store abstract level functions for PCI Parity object */
37614 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
37615@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37616 edac_printk(KERN_CRIT, EDAC_PCI,
37617 "Signaled System Error on %s\n",
37618 pci_name(dev));
37619- atomic_inc(&pci_nonparity_count);
37620+ atomic_inc_unchecked(&pci_nonparity_count);
37621 }
37622
37623 if (status & (PCI_STATUS_PARITY)) {
37624@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37625 "Master Data Parity Error on %s\n",
37626 pci_name(dev));
37627
37628- atomic_inc(&pci_parity_count);
37629+ atomic_inc_unchecked(&pci_parity_count);
37630 }
37631
37632 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37633@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37634 "Detected Parity Error on %s\n",
37635 pci_name(dev));
37636
37637- atomic_inc(&pci_parity_count);
37638+ atomic_inc_unchecked(&pci_parity_count);
37639 }
37640 }
37641
37642@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37643 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
37644 "Signaled System Error on %s\n",
37645 pci_name(dev));
37646- atomic_inc(&pci_nonparity_count);
37647+ atomic_inc_unchecked(&pci_nonparity_count);
37648 }
37649
37650 if (status & (PCI_STATUS_PARITY)) {
37651@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37652 "Master Data Parity Error on "
37653 "%s\n", pci_name(dev));
37654
37655- atomic_inc(&pci_parity_count);
37656+ atomic_inc_unchecked(&pci_parity_count);
37657 }
37658
37659 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37660@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37661 "Detected Parity Error on %s\n",
37662 pci_name(dev));
37663
37664- atomic_inc(&pci_parity_count);
37665+ atomic_inc_unchecked(&pci_parity_count);
37666 }
37667 }
37668 }
37669@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
37670 if (!check_pci_errors)
37671 return;
37672
37673- before_count = atomic_read(&pci_parity_count);
37674+ before_count = atomic_read_unchecked(&pci_parity_count);
37675
37676 /* scan all PCI devices looking for a Parity Error on devices and
37677 * bridges.
37678@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
37679 /* Only if operator has selected panic on PCI Error */
37680 if (edac_pci_get_panic_on_pe()) {
37681 /* If the count is different 'after' from 'before' */
37682- if (before_count != atomic_read(&pci_parity_count))
37683+ if (before_count != atomic_read_unchecked(&pci_parity_count))
37684 panic("EDAC: PCI Parity Error");
37685 }
37686 }
37687diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
37688index 51b7e3a..aa8a3e8 100644
37689--- a/drivers/edac/mce_amd.h
37690+++ b/drivers/edac/mce_amd.h
37691@@ -77,7 +77,7 @@ struct amd_decoder_ops {
37692 bool (*mc0_mce)(u16, u8);
37693 bool (*mc1_mce)(u16, u8);
37694 bool (*mc2_mce)(u16, u8);
37695-};
37696+} __no_const;
37697
37698 void amd_report_gart_errors(bool);
37699 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
37700diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
37701index 57ea7f4..af06b76 100644
37702--- a/drivers/firewire/core-card.c
37703+++ b/drivers/firewire/core-card.c
37704@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
37705 const struct fw_card_driver *driver,
37706 struct device *device)
37707 {
37708- static atomic_t index = ATOMIC_INIT(-1);
37709+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
37710
37711- card->index = atomic_inc_return(&index);
37712+ card->index = atomic_inc_return_unchecked(&index);
37713 card->driver = driver;
37714 card->device = device;
37715 card->current_tlabel = 0;
37716@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
37717
37718 void fw_core_remove_card(struct fw_card *card)
37719 {
37720- struct fw_card_driver dummy_driver = dummy_driver_template;
37721+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
37722
37723 card->driver->update_phy_reg(card, 4,
37724 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
37725diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
37726index de4aa40..49ab1f2 100644
37727--- a/drivers/firewire/core-device.c
37728+++ b/drivers/firewire/core-device.c
37729@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
37730 struct config_rom_attribute {
37731 struct device_attribute attr;
37732 u32 key;
37733-};
37734+} __do_const;
37735
37736 static ssize_t show_immediate(struct device *dev,
37737 struct device_attribute *dattr, char *buf)
37738diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
37739index 28a94c7..58da63a 100644
37740--- a/drivers/firewire/core-transaction.c
37741+++ b/drivers/firewire/core-transaction.c
37742@@ -38,6 +38,7 @@
37743 #include <linux/timer.h>
37744 #include <linux/types.h>
37745 #include <linux/workqueue.h>
37746+#include <linux/sched.h>
37747
37748 #include <asm/byteorder.h>
37749
37750diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
37751index 515a42c..5ecf3ba 100644
37752--- a/drivers/firewire/core.h
37753+++ b/drivers/firewire/core.h
37754@@ -111,6 +111,7 @@ struct fw_card_driver {
37755
37756 int (*stop_iso)(struct fw_iso_context *ctx);
37757 };
37758+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
37759
37760 void fw_card_initialize(struct fw_card *card,
37761 const struct fw_card_driver *driver, struct device *device);
37762diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
37763index 94a58a0..f5eba42 100644
37764--- a/drivers/firmware/dmi-id.c
37765+++ b/drivers/firmware/dmi-id.c
37766@@ -16,7 +16,7 @@
37767 struct dmi_device_attribute{
37768 struct device_attribute dev_attr;
37769 int field;
37770-};
37771+} __do_const;
37772 #define to_dmi_dev_attr(_dev_attr) \
37773 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
37774
37775diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
37776index 232fa8f..386c255 100644
37777--- a/drivers/firmware/dmi_scan.c
37778+++ b/drivers/firmware/dmi_scan.c
37779@@ -504,11 +504,6 @@ void __init dmi_scan_machine(void)
37780 }
37781 }
37782 else {
37783- /*
37784- * no iounmap() for that ioremap(); it would be a no-op, but
37785- * it's so early in setup that sucker gets confused into doing
37786- * what it shouldn't if we actually call it.
37787- */
37788 p = dmi_ioremap(0xF0000, 0x10000);
37789 if (p == NULL)
37790 goto error;
37791@@ -806,7 +801,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
37792 if (buf == NULL)
37793 return -1;
37794
37795- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
37796+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
37797
37798 iounmap(buf);
37799 return 0;
37800diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
37801index 5145fa3..0d3babd 100644
37802--- a/drivers/firmware/efi/efi.c
37803+++ b/drivers/firmware/efi/efi.c
37804@@ -65,14 +65,16 @@ static struct attribute_group efi_subsys_attr_group = {
37805 };
37806
37807 static struct efivars generic_efivars;
37808-static struct efivar_operations generic_ops;
37809+static efivar_operations_no_const generic_ops __read_only;
37810
37811 static int generic_ops_register(void)
37812 {
37813- generic_ops.get_variable = efi.get_variable;
37814- generic_ops.set_variable = efi.set_variable;
37815- generic_ops.get_next_variable = efi.get_next_variable;
37816- generic_ops.query_variable_store = efi_query_variable_store;
37817+ pax_open_kernel();
37818+ *(void **)&generic_ops.get_variable = efi.get_variable;
37819+ *(void **)&generic_ops.set_variable = efi.set_variable;
37820+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
37821+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
37822+ pax_close_kernel();
37823
37824 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
37825 }
37826diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
37827index 8a7432a..28fb839 100644
37828--- a/drivers/firmware/efi/efivars.c
37829+++ b/drivers/firmware/efi/efivars.c
37830@@ -452,7 +452,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
37831 static int
37832 create_efivars_bin_attributes(void)
37833 {
37834- struct bin_attribute *attr;
37835+ bin_attribute_no_const *attr;
37836 int error;
37837
37838 /* new_var */
37839diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
37840index 2a90ba6..07f3733 100644
37841--- a/drivers/firmware/google/memconsole.c
37842+++ b/drivers/firmware/google/memconsole.c
37843@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
37844 if (!found_memconsole())
37845 return -ENODEV;
37846
37847- memconsole_bin_attr.size = memconsole_length;
37848+ pax_open_kernel();
37849+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
37850+ pax_close_kernel();
37851
37852 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
37853
37854diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
37855index 2729e3d..f9deca1 100644
37856--- a/drivers/gpio/gpio-ich.c
37857+++ b/drivers/gpio/gpio-ich.c
37858@@ -71,7 +71,7 @@ struct ichx_desc {
37859 /* Some chipsets have quirks, let these use their own request/get */
37860 int (*request)(struct gpio_chip *chip, unsigned offset);
37861 int (*get)(struct gpio_chip *chip, unsigned offset);
37862-};
37863+} __do_const;
37864
37865 static struct {
37866 spinlock_t lock;
37867diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
37868index 9902732..64b62dd 100644
37869--- a/drivers/gpio/gpio-vr41xx.c
37870+++ b/drivers/gpio/gpio-vr41xx.c
37871@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
37872 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
37873 maskl, pendl, maskh, pendh);
37874
37875- atomic_inc(&irq_err_count);
37876+ atomic_inc_unchecked(&irq_err_count);
37877
37878 return -EINVAL;
37879 }
37880diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
37881index 6a64749..0767a9f 100644
37882--- a/drivers/gpu/drm/drm_crtc_helper.c
37883+++ b/drivers/gpu/drm/drm_crtc_helper.c
37884@@ -322,7 +322,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
37885 struct drm_crtc *tmp;
37886 int crtc_mask = 1;
37887
37888- WARN(!crtc, "checking null crtc?\n");
37889+ BUG_ON(!crtc);
37890
37891 dev = crtc->dev;
37892
37893diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
37894index 99fcd7c..13cf6c5 100644
37895--- a/drivers/gpu/drm/drm_drv.c
37896+++ b/drivers/gpu/drm/drm_drv.c
37897@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
37898 /**
37899 * Copy and IOCTL return string to user space
37900 */
37901-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
37902+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
37903 {
37904 int len;
37905
37906@@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
37907 struct drm_file *file_priv = filp->private_data;
37908 struct drm_device *dev;
37909 const struct drm_ioctl_desc *ioctl = NULL;
37910- drm_ioctl_t *func;
37911+ drm_ioctl_no_const_t func;
37912 unsigned int nr = DRM_IOCTL_NR(cmd);
37913 int retcode = -EINVAL;
37914 char stack_kdata[128];
37915@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
37916 return -ENODEV;
37917
37918 atomic_inc(&dev->ioctl_count);
37919- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
37920+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
37921 ++file_priv->ioctl_count;
37922
37923 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
37924diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
37925index 3a24385..4e426e0 100644
37926--- a/drivers/gpu/drm/drm_fops.c
37927+++ b/drivers/gpu/drm/drm_fops.c
37928@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
37929 }
37930
37931 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
37932- atomic_set(&dev->counts[i], 0);
37933+ atomic_set_unchecked(&dev->counts[i], 0);
37934
37935 dev->sigdata.lock = NULL;
37936
37937@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
37938 if (drm_device_is_unplugged(dev))
37939 return -ENODEV;
37940
37941- if (!dev->open_count++)
37942+ if (local_inc_return(&dev->open_count) == 1)
37943 need_setup = 1;
37944 mutex_lock(&dev->struct_mutex);
37945 old_imapping = inode->i_mapping;
37946@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
37947 retcode = drm_open_helper(inode, filp, dev);
37948 if (retcode)
37949 goto err_undo;
37950- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
37951+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
37952 if (need_setup) {
37953 retcode = drm_setup(dev);
37954 if (retcode)
37955@@ -166,7 +166,7 @@ err_undo:
37956 iput(container_of(dev->dev_mapping, struct inode, i_data));
37957 dev->dev_mapping = old_mapping;
37958 mutex_unlock(&dev->struct_mutex);
37959- dev->open_count--;
37960+ local_dec(&dev->open_count);
37961 return retcode;
37962 }
37963 EXPORT_SYMBOL(drm_open);
37964@@ -456,7 +456,7 @@ int drm_release(struct inode *inode, struct file *filp)
37965
37966 mutex_lock(&drm_global_mutex);
37967
37968- DRM_DEBUG("open_count = %d\n", dev->open_count);
37969+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
37970
37971 if (dev->driver->preclose)
37972 dev->driver->preclose(dev, file_priv);
37973@@ -465,10 +465,10 @@ int drm_release(struct inode *inode, struct file *filp)
37974 * Begin inline drm_release
37975 */
37976
37977- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
37978+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
37979 task_pid_nr(current),
37980 (long)old_encode_dev(file_priv->minor->device),
37981- dev->open_count);
37982+ local_read(&dev->open_count));
37983
37984 /* Release any auth tokens that might point to this file_priv,
37985 (do that under the drm_global_mutex) */
37986@@ -565,8 +565,8 @@ int drm_release(struct inode *inode, struct file *filp)
37987 * End inline drm_release
37988 */
37989
37990- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
37991- if (!--dev->open_count) {
37992+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
37993+ if (local_dec_and_test(&dev->open_count)) {
37994 if (atomic_read(&dev->ioctl_count)) {
37995 DRM_ERROR("Device busy: %d\n",
37996 atomic_read(&dev->ioctl_count));
37997diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
37998index f731116..629842c 100644
37999--- a/drivers/gpu/drm/drm_global.c
38000+++ b/drivers/gpu/drm/drm_global.c
38001@@ -36,7 +36,7 @@
38002 struct drm_global_item {
38003 struct mutex mutex;
38004 void *object;
38005- int refcount;
38006+ atomic_t refcount;
38007 };
38008
38009 static struct drm_global_item glob[DRM_GLOBAL_NUM];
38010@@ -49,7 +49,7 @@ void drm_global_init(void)
38011 struct drm_global_item *item = &glob[i];
38012 mutex_init(&item->mutex);
38013 item->object = NULL;
38014- item->refcount = 0;
38015+ atomic_set(&item->refcount, 0);
38016 }
38017 }
38018
38019@@ -59,7 +59,7 @@ void drm_global_release(void)
38020 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
38021 struct drm_global_item *item = &glob[i];
38022 BUG_ON(item->object != NULL);
38023- BUG_ON(item->refcount != 0);
38024+ BUG_ON(atomic_read(&item->refcount) != 0);
38025 }
38026 }
38027
38028@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38029 void *object;
38030
38031 mutex_lock(&item->mutex);
38032- if (item->refcount == 0) {
38033+ if (atomic_read(&item->refcount) == 0) {
38034 item->object = kzalloc(ref->size, GFP_KERNEL);
38035 if (unlikely(item->object == NULL)) {
38036 ret = -ENOMEM;
38037@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38038 goto out_err;
38039
38040 }
38041- ++item->refcount;
38042+ atomic_inc(&item->refcount);
38043 ref->object = item->object;
38044 object = item->object;
38045 mutex_unlock(&item->mutex);
38046@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
38047 struct drm_global_item *item = &glob[ref->global_type];
38048
38049 mutex_lock(&item->mutex);
38050- BUG_ON(item->refcount == 0);
38051+ BUG_ON(atomic_read(&item->refcount) == 0);
38052 BUG_ON(ref->object != item->object);
38053- if (--item->refcount == 0) {
38054+ if (atomic_dec_and_test(&item->refcount)) {
38055 ref->release(ref);
38056 item->object = NULL;
38057 }
38058diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
38059index d4b20ce..77a8d41 100644
38060--- a/drivers/gpu/drm/drm_info.c
38061+++ b/drivers/gpu/drm/drm_info.c
38062@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
38063 struct drm_local_map *map;
38064 struct drm_map_list *r_list;
38065
38066- /* Hardcoded from _DRM_FRAME_BUFFER,
38067- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
38068- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
38069- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
38070+ static const char * const types[] = {
38071+ [_DRM_FRAME_BUFFER] = "FB",
38072+ [_DRM_REGISTERS] = "REG",
38073+ [_DRM_SHM] = "SHM",
38074+ [_DRM_AGP] = "AGP",
38075+ [_DRM_SCATTER_GATHER] = "SG",
38076+ [_DRM_CONSISTENT] = "PCI",
38077+ [_DRM_GEM] = "GEM" };
38078 const char *type;
38079 int i;
38080
38081@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
38082 map = r_list->map;
38083 if (!map)
38084 continue;
38085- if (map->type < 0 || map->type > 5)
38086+ if (map->type >= ARRAY_SIZE(types))
38087 type = "??";
38088 else
38089 type = types[map->type];
38090@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
38091 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
38092 vma->vm_flags & VM_LOCKED ? 'l' : '-',
38093 vma->vm_flags & VM_IO ? 'i' : '-',
38094+#ifdef CONFIG_GRKERNSEC_HIDESYM
38095+ 0);
38096+#else
38097 vma->vm_pgoff);
38098+#endif
38099
38100 #if defined(__i386__)
38101 pgprot = pgprot_val(vma->vm_page_prot);
38102diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
38103index 2f4c434..dd12cd2 100644
38104--- a/drivers/gpu/drm/drm_ioc32.c
38105+++ b/drivers/gpu/drm/drm_ioc32.c
38106@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
38107 request = compat_alloc_user_space(nbytes);
38108 if (!access_ok(VERIFY_WRITE, request, nbytes))
38109 return -EFAULT;
38110- list = (struct drm_buf_desc *) (request + 1);
38111+ list = (struct drm_buf_desc __user *) (request + 1);
38112
38113 if (__put_user(count, &request->count)
38114 || __put_user(list, &request->list))
38115@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
38116 request = compat_alloc_user_space(nbytes);
38117 if (!access_ok(VERIFY_WRITE, request, nbytes))
38118 return -EFAULT;
38119- list = (struct drm_buf_pub *) (request + 1);
38120+ list = (struct drm_buf_pub __user *) (request + 1);
38121
38122 if (__put_user(count, &request->count)
38123 || __put_user(list, &request->list))
38124@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
38125 return 0;
38126 }
38127
38128-drm_ioctl_compat_t *drm_compat_ioctls[] = {
38129+drm_ioctl_compat_t drm_compat_ioctls[] = {
38130 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
38131 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
38132 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
38133@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
38134 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38135 {
38136 unsigned int nr = DRM_IOCTL_NR(cmd);
38137- drm_ioctl_compat_t *fn;
38138 int ret;
38139
38140 /* Assume that ioctls without an explicit compat routine will just
38141@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38142 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
38143 return drm_ioctl(filp, cmd, arg);
38144
38145- fn = drm_compat_ioctls[nr];
38146-
38147- if (fn != NULL)
38148- ret = (*fn) (filp, cmd, arg);
38149+ if (drm_compat_ioctls[nr] != NULL)
38150+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
38151 else
38152 ret = drm_ioctl(filp, cmd, arg);
38153
38154diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
38155index ffd7a7b..a64643e 100644
38156--- a/drivers/gpu/drm/drm_ioctl.c
38157+++ b/drivers/gpu/drm/drm_ioctl.c
38158@@ -265,7 +265,7 @@ int drm_getstats(struct drm_device *dev, void *data,
38159 stats->data[i].value =
38160 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
38161 else
38162- stats->data[i].value = atomic_read(&dev->counts[i]);
38163+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
38164 stats->data[i].type = dev->types[i];
38165 }
38166
38167diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
38168index d752c96..fe08455 100644
38169--- a/drivers/gpu/drm/drm_lock.c
38170+++ b/drivers/gpu/drm/drm_lock.c
38171@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38172 if (drm_lock_take(&master->lock, lock->context)) {
38173 master->lock.file_priv = file_priv;
38174 master->lock.lock_time = jiffies;
38175- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
38176+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
38177 break; /* Got lock */
38178 }
38179
38180@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38181 return -EINVAL;
38182 }
38183
38184- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
38185+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
38186
38187 if (drm_lock_free(&master->lock, lock->context)) {
38188 /* FIXME: Should really bail out here. */
38189diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
38190index 327ca19..684d3c0 100644
38191--- a/drivers/gpu/drm/drm_stub.c
38192+++ b/drivers/gpu/drm/drm_stub.c
38193@@ -495,7 +495,7 @@ void drm_unplug_dev(struct drm_device *dev)
38194
38195 drm_device_set_unplugged(dev);
38196
38197- if (dev->open_count == 0) {
38198+ if (local_read(&dev->open_count) == 0) {
38199 drm_put_dev(dev);
38200 }
38201 mutex_unlock(&drm_global_mutex);
38202diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
38203index 2290b3b..22056a1 100644
38204--- a/drivers/gpu/drm/drm_sysfs.c
38205+++ b/drivers/gpu/drm/drm_sysfs.c
38206@@ -524,7 +524,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
38207 int drm_sysfs_device_add(struct drm_minor *minor)
38208 {
38209 int err;
38210- char *minor_str;
38211+ const char *minor_str;
38212
38213 minor->kdev.parent = minor->dev->dev;
38214
38215diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
38216index ada49ed..29275a0 100644
38217--- a/drivers/gpu/drm/i810/i810_dma.c
38218+++ b/drivers/gpu/drm/i810/i810_dma.c
38219@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
38220 dma->buflist[vertex->idx],
38221 vertex->discard, vertex->used);
38222
38223- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38224- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38225+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38226+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38227 sarea_priv->last_enqueue = dev_priv->counter - 1;
38228 sarea_priv->last_dispatch = (int)hw_status[5];
38229
38230@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
38231 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
38232 mc->last_render);
38233
38234- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38235- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38236+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38237+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38238 sarea_priv->last_enqueue = dev_priv->counter - 1;
38239 sarea_priv->last_dispatch = (int)hw_status[5];
38240
38241diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
38242index 6e0acad..93c8289 100644
38243--- a/drivers/gpu/drm/i810/i810_drv.h
38244+++ b/drivers/gpu/drm/i810/i810_drv.h
38245@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
38246 int page_flipping;
38247
38248 wait_queue_head_t irq_queue;
38249- atomic_t irq_received;
38250- atomic_t irq_emitted;
38251+ atomic_unchecked_t irq_received;
38252+ atomic_unchecked_t irq_emitted;
38253
38254 int front_offset;
38255 } drm_i810_private_t;
38256diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
38257index 47d6c74..279123f 100644
38258--- a/drivers/gpu/drm/i915/i915_debugfs.c
38259+++ b/drivers/gpu/drm/i915/i915_debugfs.c
38260@@ -541,7 +541,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
38261 I915_READ(GTIMR));
38262 }
38263 seq_printf(m, "Interrupts received: %d\n",
38264- atomic_read(&dev_priv->irq_received));
38265+ atomic_read_unchecked(&dev_priv->irq_received));
38266 for_each_ring(ring, dev_priv, i) {
38267 if (IS_GEN6(dev) || IS_GEN7(dev)) {
38268 seq_printf(m,
38269diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
38270index f466980..8f2883f 100644
38271--- a/drivers/gpu/drm/i915/i915_dma.c
38272+++ b/drivers/gpu/drm/i915/i915_dma.c
38273@@ -1260,7 +1260,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
38274 bool can_switch;
38275
38276 spin_lock(&dev->count_lock);
38277- can_switch = (dev->open_count == 0);
38278+ can_switch = (local_read(&dev->open_count) == 0);
38279 spin_unlock(&dev->count_lock);
38280 return can_switch;
38281 }
38282diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
38283index 1929bff..dab130d 100644
38284--- a/drivers/gpu/drm/i915/i915_drv.h
38285+++ b/drivers/gpu/drm/i915/i915_drv.h
38286@@ -1028,7 +1028,7 @@ typedef struct drm_i915_private {
38287 drm_dma_handle_t *status_page_dmah;
38288 struct resource mch_res;
38289
38290- atomic_t irq_received;
38291+ atomic_unchecked_t irq_received;
38292
38293 /* protects the irq masks */
38294 spinlock_t irq_lock;
38295diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38296index 87a3227..cd13d8f 100644
38297--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38298+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38299@@ -727,9 +727,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
38300
38301 static int
38302 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
38303- int count)
38304+ unsigned int count)
38305 {
38306- int i;
38307+ unsigned int i;
38308 int relocs_total = 0;
38309 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
38310
38311diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
38312index 3c59584..500f2e9 100644
38313--- a/drivers/gpu/drm/i915/i915_ioc32.c
38314+++ b/drivers/gpu/drm/i915/i915_ioc32.c
38315@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
38316 (unsigned long)request);
38317 }
38318
38319-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38320+static drm_ioctl_compat_t i915_compat_ioctls[] = {
38321 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
38322 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
38323 [DRM_I915_GETPARAM] = compat_i915_getparam,
38324@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38325 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38326 {
38327 unsigned int nr = DRM_IOCTL_NR(cmd);
38328- drm_ioctl_compat_t *fn = NULL;
38329 int ret;
38330
38331 if (nr < DRM_COMMAND_BASE)
38332 return drm_compat_ioctl(filp, cmd, arg);
38333
38334- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
38335- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38336-
38337- if (fn != NULL)
38338+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
38339+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38340 ret = (*fn) (filp, cmd, arg);
38341- else
38342+ } else
38343 ret = drm_ioctl(filp, cmd, arg);
38344
38345 return ret;
38346diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
38347index 3d92a7c..9a9cfd7 100644
38348--- a/drivers/gpu/drm/i915/i915_irq.c
38349+++ b/drivers/gpu/drm/i915/i915_irq.c
38350@@ -970,7 +970,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
38351 int pipe;
38352 u32 pipe_stats[I915_MAX_PIPES];
38353
38354- atomic_inc(&dev_priv->irq_received);
38355+ atomic_inc_unchecked(&dev_priv->irq_received);
38356
38357 while (true) {
38358 iir = I915_READ(VLV_IIR);
38359@@ -1187,7 +1187,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
38360 irqreturn_t ret = IRQ_NONE;
38361 int i;
38362
38363- atomic_inc(&dev_priv->irq_received);
38364+ atomic_inc_unchecked(&dev_priv->irq_received);
38365
38366 /* We get interrupts on unclaimed registers, so check for this before we
38367 * do any I915_{READ,WRITE}. */
38368@@ -1307,7 +1307,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
38369 int ret = IRQ_NONE;
38370 u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier;
38371
38372- atomic_inc(&dev_priv->irq_received);
38373+ atomic_inc_unchecked(&dev_priv->irq_received);
38374
38375 /* disable master interrupt before clearing iir */
38376 de_ier = I915_READ(DEIER);
38377@@ -2566,7 +2566,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
38378 {
38379 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38380
38381- atomic_set(&dev_priv->irq_received, 0);
38382+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38383
38384 I915_WRITE(HWSTAM, 0xeffe);
38385
38386@@ -2588,7 +2588,7 @@ static void ivybridge_irq_preinstall(struct drm_device *dev)
38387 {
38388 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38389
38390- atomic_set(&dev_priv->irq_received, 0);
38391+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38392
38393 I915_WRITE(HWSTAM, 0xeffe);
38394
38395@@ -2616,7 +2616,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
38396 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38397 int pipe;
38398
38399- atomic_set(&dev_priv->irq_received, 0);
38400+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38401
38402 /* VLV magic */
38403 I915_WRITE(VLV_IMR, 0);
38404@@ -2928,7 +2928,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
38405 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38406 int pipe;
38407
38408- atomic_set(&dev_priv->irq_received, 0);
38409+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38410
38411 for_each_pipe(pipe)
38412 I915_WRITE(PIPESTAT(pipe), 0);
38413@@ -3007,7 +3007,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
38414 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38415 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38416
38417- atomic_inc(&dev_priv->irq_received);
38418+ atomic_inc_unchecked(&dev_priv->irq_received);
38419
38420 iir = I915_READ16(IIR);
38421 if (iir == 0)
38422@@ -3082,7 +3082,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
38423 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38424 int pipe;
38425
38426- atomic_set(&dev_priv->irq_received, 0);
38427+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38428
38429 if (I915_HAS_HOTPLUG(dev)) {
38430 I915_WRITE(PORT_HOTPLUG_EN, 0);
38431@@ -3181,7 +3181,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
38432 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38433 int pipe, ret = IRQ_NONE;
38434
38435- atomic_inc(&dev_priv->irq_received);
38436+ atomic_inc_unchecked(&dev_priv->irq_received);
38437
38438 iir = I915_READ(IIR);
38439 do {
38440@@ -3305,7 +3305,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
38441 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38442 int pipe;
38443
38444- atomic_set(&dev_priv->irq_received, 0);
38445+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38446
38447 I915_WRITE(PORT_HOTPLUG_EN, 0);
38448 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
38449@@ -3414,7 +3414,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
38450 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38451 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38452
38453- atomic_inc(&dev_priv->irq_received);
38454+ atomic_inc_unchecked(&dev_priv->irq_received);
38455
38456 iir = I915_READ(IIR);
38457
38458diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
38459index be79f47..95e150b 100644
38460--- a/drivers/gpu/drm/i915/intel_display.c
38461+++ b/drivers/gpu/drm/i915/intel_display.c
38462@@ -9418,13 +9418,13 @@ struct intel_quirk {
38463 int subsystem_vendor;
38464 int subsystem_device;
38465 void (*hook)(struct drm_device *dev);
38466-};
38467+} __do_const;
38468
38469 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
38470 struct intel_dmi_quirk {
38471 void (*hook)(struct drm_device *dev);
38472 const struct dmi_system_id (*dmi_id_list)[];
38473-};
38474+} __do_const;
38475
38476 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38477 {
38478@@ -9432,18 +9432,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38479 return 1;
38480 }
38481
38482-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38483+static const struct dmi_system_id intel_dmi_quirks_table[] = {
38484 {
38485- .dmi_id_list = &(const struct dmi_system_id[]) {
38486- {
38487- .callback = intel_dmi_reverse_brightness,
38488- .ident = "NCR Corporation",
38489- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38490- DMI_MATCH(DMI_PRODUCT_NAME, ""),
38491- },
38492- },
38493- { } /* terminating entry */
38494+ .callback = intel_dmi_reverse_brightness,
38495+ .ident = "NCR Corporation",
38496+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38497+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
38498 },
38499+ },
38500+ { } /* terminating entry */
38501+};
38502+
38503+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38504+ {
38505+ .dmi_id_list = &intel_dmi_quirks_table,
38506 .hook = quirk_invert_brightness,
38507 },
38508 };
38509diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
38510index 54558a0..2d97005 100644
38511--- a/drivers/gpu/drm/mga/mga_drv.h
38512+++ b/drivers/gpu/drm/mga/mga_drv.h
38513@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
38514 u32 clear_cmd;
38515 u32 maccess;
38516
38517- atomic_t vbl_received; /**< Number of vblanks received. */
38518+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
38519 wait_queue_head_t fence_queue;
38520- atomic_t last_fence_retired;
38521+ atomic_unchecked_t last_fence_retired;
38522 u32 next_fence_to_post;
38523
38524 unsigned int fb_cpp;
38525diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
38526index 709e90d..89a1c0d 100644
38527--- a/drivers/gpu/drm/mga/mga_ioc32.c
38528+++ b/drivers/gpu/drm/mga/mga_ioc32.c
38529@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
38530 return 0;
38531 }
38532
38533-drm_ioctl_compat_t *mga_compat_ioctls[] = {
38534+drm_ioctl_compat_t mga_compat_ioctls[] = {
38535 [DRM_MGA_INIT] = compat_mga_init,
38536 [DRM_MGA_GETPARAM] = compat_mga_getparam,
38537 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
38538@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
38539 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38540 {
38541 unsigned int nr = DRM_IOCTL_NR(cmd);
38542- drm_ioctl_compat_t *fn = NULL;
38543 int ret;
38544
38545 if (nr < DRM_COMMAND_BASE)
38546 return drm_compat_ioctl(filp, cmd, arg);
38547
38548- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
38549- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38550-
38551- if (fn != NULL)
38552+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
38553+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38554 ret = (*fn) (filp, cmd, arg);
38555- else
38556+ } else
38557 ret = drm_ioctl(filp, cmd, arg);
38558
38559 return ret;
38560diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
38561index 598c281..60d590e 100644
38562--- a/drivers/gpu/drm/mga/mga_irq.c
38563+++ b/drivers/gpu/drm/mga/mga_irq.c
38564@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
38565 if (crtc != 0)
38566 return 0;
38567
38568- return atomic_read(&dev_priv->vbl_received);
38569+ return atomic_read_unchecked(&dev_priv->vbl_received);
38570 }
38571
38572
38573@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38574 /* VBLANK interrupt */
38575 if (status & MGA_VLINEPEN) {
38576 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
38577- atomic_inc(&dev_priv->vbl_received);
38578+ atomic_inc_unchecked(&dev_priv->vbl_received);
38579 drm_handle_vblank(dev, 0);
38580 handled = 1;
38581 }
38582@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38583 if ((prim_start & ~0x03) != (prim_end & ~0x03))
38584 MGA_WRITE(MGA_PRIMEND, prim_end);
38585
38586- atomic_inc(&dev_priv->last_fence_retired);
38587+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
38588 DRM_WAKEUP(&dev_priv->fence_queue);
38589 handled = 1;
38590 }
38591@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
38592 * using fences.
38593 */
38594 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
38595- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
38596+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
38597 - *sequence) <= (1 << 23)));
38598
38599 *sequence = cur_fence;
38600diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
38601index 3e72876..d1c15ad 100644
38602--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
38603+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
38604@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
38605 struct bit_table {
38606 const char id;
38607 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
38608-};
38609+} __no_const;
38610
38611 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
38612
38613diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
38614index 41ff7e0..fa854ef 100644
38615--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
38616+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
38617@@ -92,7 +92,6 @@ struct nouveau_drm {
38618 struct drm_global_reference mem_global_ref;
38619 struct ttm_bo_global_ref bo_global_ref;
38620 struct ttm_bo_device bdev;
38621- atomic_t validate_sequence;
38622 int (*move)(struct nouveau_channel *,
38623 struct ttm_buffer_object *,
38624 struct ttm_mem_reg *, struct ttm_mem_reg *);
38625diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38626index 08214bc..9208577 100644
38627--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38628+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38629@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
38630 unsigned long arg)
38631 {
38632 unsigned int nr = DRM_IOCTL_NR(cmd);
38633- drm_ioctl_compat_t *fn = NULL;
38634+ drm_ioctl_compat_t fn = NULL;
38635 int ret;
38636
38637 if (nr < DRM_COMMAND_BASE)
38638diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
38639index 25d3495..d81aaf6 100644
38640--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
38641+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
38642@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
38643 bool can_switch;
38644
38645 spin_lock(&dev->count_lock);
38646- can_switch = (dev->open_count == 0);
38647+ can_switch = (local_read(&dev->open_count) == 0);
38648 spin_unlock(&dev->count_lock);
38649 return can_switch;
38650 }
38651diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
38652index 1dfd84c..104896c 100644
38653--- a/drivers/gpu/drm/qxl/qxl_ttm.c
38654+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
38655@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
38656 }
38657 }
38658
38659-static struct vm_operations_struct qxl_ttm_vm_ops;
38660+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
38661 static const struct vm_operations_struct *ttm_vm_ops;
38662
38663 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38664@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
38665 return r;
38666 if (unlikely(ttm_vm_ops == NULL)) {
38667 ttm_vm_ops = vma->vm_ops;
38668+ pax_open_kernel();
38669 qxl_ttm_vm_ops = *ttm_vm_ops;
38670 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
38671+ pax_close_kernel();
38672 }
38673 vma->vm_ops = &qxl_ttm_vm_ops;
38674 return 0;
38675@@ -556,25 +558,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
38676 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
38677 {
38678 #if defined(CONFIG_DEBUG_FS)
38679- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
38680- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
38681- unsigned i;
38682+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
38683+ {
38684+ .name = "qxl_mem_mm",
38685+ .show = &qxl_mm_dump_table,
38686+ },
38687+ {
38688+ .name = "qxl_surf_mm",
38689+ .show = &qxl_mm_dump_table,
38690+ }
38691+ };
38692
38693- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
38694- if (i == 0)
38695- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
38696- else
38697- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
38698- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
38699- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
38700- qxl_mem_types_list[i].driver_features = 0;
38701- if (i == 0)
38702- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38703- else
38704- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38705+ pax_open_kernel();
38706+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38707+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38708+ pax_close_kernel();
38709
38710- }
38711- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
38712+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
38713 #else
38714 return 0;
38715 #endif
38716diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
38717index d4660cf..70dbe65 100644
38718--- a/drivers/gpu/drm/r128/r128_cce.c
38719+++ b/drivers/gpu/drm/r128/r128_cce.c
38720@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
38721
38722 /* GH: Simple idle check.
38723 */
38724- atomic_set(&dev_priv->idle_count, 0);
38725+ atomic_set_unchecked(&dev_priv->idle_count, 0);
38726
38727 /* We don't support anything other than bus-mastering ring mode,
38728 * but the ring can be in either AGP or PCI space for the ring
38729diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
38730index 930c71b..499aded 100644
38731--- a/drivers/gpu/drm/r128/r128_drv.h
38732+++ b/drivers/gpu/drm/r128/r128_drv.h
38733@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
38734 int is_pci;
38735 unsigned long cce_buffers_offset;
38736
38737- atomic_t idle_count;
38738+ atomic_unchecked_t idle_count;
38739
38740 int page_flipping;
38741 int current_page;
38742 u32 crtc_offset;
38743 u32 crtc_offset_cntl;
38744
38745- atomic_t vbl_received;
38746+ atomic_unchecked_t vbl_received;
38747
38748 u32 color_fmt;
38749 unsigned int front_offset;
38750diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
38751index a954c54..9cc595c 100644
38752--- a/drivers/gpu/drm/r128/r128_ioc32.c
38753+++ b/drivers/gpu/drm/r128/r128_ioc32.c
38754@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
38755 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
38756 }
38757
38758-drm_ioctl_compat_t *r128_compat_ioctls[] = {
38759+drm_ioctl_compat_t r128_compat_ioctls[] = {
38760 [DRM_R128_INIT] = compat_r128_init,
38761 [DRM_R128_DEPTH] = compat_r128_depth,
38762 [DRM_R128_STIPPLE] = compat_r128_stipple,
38763@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
38764 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38765 {
38766 unsigned int nr = DRM_IOCTL_NR(cmd);
38767- drm_ioctl_compat_t *fn = NULL;
38768 int ret;
38769
38770 if (nr < DRM_COMMAND_BASE)
38771 return drm_compat_ioctl(filp, cmd, arg);
38772
38773- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
38774- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
38775-
38776- if (fn != NULL)
38777+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
38778+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
38779 ret = (*fn) (filp, cmd, arg);
38780- else
38781+ } else
38782 ret = drm_ioctl(filp, cmd, arg);
38783
38784 return ret;
38785diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
38786index 2ea4f09..d391371 100644
38787--- a/drivers/gpu/drm/r128/r128_irq.c
38788+++ b/drivers/gpu/drm/r128/r128_irq.c
38789@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
38790 if (crtc != 0)
38791 return 0;
38792
38793- return atomic_read(&dev_priv->vbl_received);
38794+ return atomic_read_unchecked(&dev_priv->vbl_received);
38795 }
38796
38797 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
38798@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
38799 /* VBLANK interrupt */
38800 if (status & R128_CRTC_VBLANK_INT) {
38801 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
38802- atomic_inc(&dev_priv->vbl_received);
38803+ atomic_inc_unchecked(&dev_priv->vbl_received);
38804 drm_handle_vblank(dev, 0);
38805 return IRQ_HANDLED;
38806 }
38807diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
38808index 19bb7e6..de7e2a2 100644
38809--- a/drivers/gpu/drm/r128/r128_state.c
38810+++ b/drivers/gpu/drm/r128/r128_state.c
38811@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
38812
38813 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
38814 {
38815- if (atomic_read(&dev_priv->idle_count) == 0)
38816+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
38817 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
38818 else
38819- atomic_set(&dev_priv->idle_count, 0);
38820+ atomic_set_unchecked(&dev_priv->idle_count, 0);
38821 }
38822
38823 #endif
38824diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
38825index af85299..ed9ac8d 100644
38826--- a/drivers/gpu/drm/radeon/mkregtable.c
38827+++ b/drivers/gpu/drm/radeon/mkregtable.c
38828@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
38829 regex_t mask_rex;
38830 regmatch_t match[4];
38831 char buf[1024];
38832- size_t end;
38833+ long end;
38834 int len;
38835 int done = 0;
38836 int r;
38837 unsigned o;
38838 struct offset *offset;
38839 char last_reg_s[10];
38840- int last_reg;
38841+ unsigned long last_reg;
38842
38843 if (regcomp
38844 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
38845diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
38846index 63398ae..669e045 100644
38847--- a/drivers/gpu/drm/radeon/radeon_device.c
38848+++ b/drivers/gpu/drm/radeon/radeon_device.c
38849@@ -1105,7 +1105,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
38850 bool can_switch;
38851
38852 spin_lock(&dev->count_lock);
38853- can_switch = (dev->open_count == 0);
38854+ can_switch = (local_read(&dev->open_count) == 0);
38855 spin_unlock(&dev->count_lock);
38856 return can_switch;
38857 }
38858diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
38859index b369d42..8dd04eb 100644
38860--- a/drivers/gpu/drm/radeon/radeon_drv.h
38861+++ b/drivers/gpu/drm/radeon/radeon_drv.h
38862@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
38863
38864 /* SW interrupt */
38865 wait_queue_head_t swi_queue;
38866- atomic_t swi_emitted;
38867+ atomic_unchecked_t swi_emitted;
38868 int vblank_crtc;
38869 uint32_t irq_enable_reg;
38870 uint32_t r500_disp_irq_reg;
38871diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
38872index c180df8..5fd8186 100644
38873--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
38874+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
38875@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
38876 request = compat_alloc_user_space(sizeof(*request));
38877 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
38878 || __put_user(req32.param, &request->param)
38879- || __put_user((void __user *)(unsigned long)req32.value,
38880+ || __put_user((unsigned long)req32.value,
38881 &request->value))
38882 return -EFAULT;
38883
38884@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
38885 #define compat_radeon_cp_setparam NULL
38886 #endif /* X86_64 || IA64 */
38887
38888-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
38889+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
38890 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
38891 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
38892 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
38893@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
38894 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38895 {
38896 unsigned int nr = DRM_IOCTL_NR(cmd);
38897- drm_ioctl_compat_t *fn = NULL;
38898 int ret;
38899
38900 if (nr < DRM_COMMAND_BASE)
38901 return drm_compat_ioctl(filp, cmd, arg);
38902
38903- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
38904- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
38905-
38906- if (fn != NULL)
38907+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
38908+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
38909 ret = (*fn) (filp, cmd, arg);
38910- else
38911+ } else
38912 ret = drm_ioctl(filp, cmd, arg);
38913
38914 return ret;
38915diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
38916index 8d68e97..9dcfed8 100644
38917--- a/drivers/gpu/drm/radeon/radeon_irq.c
38918+++ b/drivers/gpu/drm/radeon/radeon_irq.c
38919@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
38920 unsigned int ret;
38921 RING_LOCALS;
38922
38923- atomic_inc(&dev_priv->swi_emitted);
38924- ret = atomic_read(&dev_priv->swi_emitted);
38925+ atomic_inc_unchecked(&dev_priv->swi_emitted);
38926+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
38927
38928 BEGIN_RING(4);
38929 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
38930@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
38931 drm_radeon_private_t *dev_priv =
38932 (drm_radeon_private_t *) dev->dev_private;
38933
38934- atomic_set(&dev_priv->swi_emitted, 0);
38935+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
38936 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
38937
38938 dev->max_vblank_count = 0x001fffff;
38939diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
38940index 4d20910..6726b6d 100644
38941--- a/drivers/gpu/drm/radeon/radeon_state.c
38942+++ b/drivers/gpu/drm/radeon/radeon_state.c
38943@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
38944 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
38945 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
38946
38947- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
38948+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
38949 sarea_priv->nbox * sizeof(depth_boxes[0])))
38950 return -EFAULT;
38951
38952@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
38953 {
38954 drm_radeon_private_t *dev_priv = dev->dev_private;
38955 drm_radeon_getparam_t *param = data;
38956- int value;
38957+ int value = 0;
38958
38959 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
38960
38961diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
38962index 6c0ce89..57a2529 100644
38963--- a/drivers/gpu/drm/radeon/radeon_ttm.c
38964+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
38965@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
38966 man->size = size >> PAGE_SHIFT;
38967 }
38968
38969-static struct vm_operations_struct radeon_ttm_vm_ops;
38970+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
38971 static const struct vm_operations_struct *ttm_vm_ops = NULL;
38972
38973 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38974@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
38975 }
38976 if (unlikely(ttm_vm_ops == NULL)) {
38977 ttm_vm_ops = vma->vm_ops;
38978+ pax_open_kernel();
38979 radeon_ttm_vm_ops = *ttm_vm_ops;
38980 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
38981+ pax_close_kernel();
38982 }
38983 vma->vm_ops = &radeon_ttm_vm_ops;
38984 return 0;
38985@@ -853,38 +855,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
38986 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
38987 {
38988 #if defined(CONFIG_DEBUG_FS)
38989- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
38990- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
38991+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
38992+ {
38993+ .name = "radeon_vram_mm",
38994+ .show = &radeon_mm_dump_table,
38995+ },
38996+ {
38997+ .name = "radeon_gtt_mm",
38998+ .show = &radeon_mm_dump_table,
38999+ },
39000+ {
39001+ .name = "ttm_page_pool",
39002+ .show = &ttm_page_alloc_debugfs,
39003+ },
39004+ {
39005+ .name = "ttm_dma_page_pool",
39006+ .show = &ttm_dma_page_alloc_debugfs,
39007+ },
39008+ };
39009 unsigned i;
39010
39011- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
39012- if (i == 0)
39013- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
39014- else
39015- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
39016- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39017- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
39018- radeon_mem_types_list[i].driver_features = 0;
39019- if (i == 0)
39020- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39021- else
39022- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39023-
39024- }
39025- /* Add ttm page pool to debugfs */
39026- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
39027- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39028- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
39029- radeon_mem_types_list[i].driver_features = 0;
39030- radeon_mem_types_list[i++].data = NULL;
39031+ pax_open_kernel();
39032+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39033+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39034+ pax_close_kernel();
39035 #ifdef CONFIG_SWIOTLB
39036- if (swiotlb_nr_tbl()) {
39037- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
39038- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39039- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
39040- radeon_mem_types_list[i].driver_features = 0;
39041- radeon_mem_types_list[i++].data = NULL;
39042- }
39043+ if (swiotlb_nr_tbl())
39044+ i++;
39045 #endif
39046 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
39047
39048diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
39049index d8ddfb3..609de1d 100644
39050--- a/drivers/gpu/drm/radeon/rs690.c
39051+++ b/drivers/gpu/drm/radeon/rs690.c
39052@@ -345,9 +345,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
39053 if (max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
39054 rdev->pm.sideport_bandwidth.full)
39055 max_bandwidth = rdev->pm.sideport_bandwidth;
39056- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
39057+ read_delay_latency.full = dfixed_const(800 * 1000);
39058 read_delay_latency.full = dfixed_div(read_delay_latency,
39059 rdev->pm.igp_sideport_mclk);
39060+ a.full = dfixed_const(370);
39061+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
39062 } else {
39063 if (max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
39064 rdev->pm.k8_bandwidth.full)
39065diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
39066index dbc2def..0a9f710 100644
39067--- a/drivers/gpu/drm/ttm/ttm_memory.c
39068+++ b/drivers/gpu/drm/ttm/ttm_memory.c
39069@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
39070 zone->glob = glob;
39071 glob->zone_kernel = zone;
39072 ret = kobject_init_and_add(
39073- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39074+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39075 if (unlikely(ret != 0)) {
39076 kobject_put(&zone->kobj);
39077 return ret;
39078@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
39079 zone->glob = glob;
39080 glob->zone_dma32 = zone;
39081 ret = kobject_init_and_add(
39082- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39083+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39084 if (unlikely(ret != 0)) {
39085 kobject_put(&zone->kobj);
39086 return ret;
39087diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39088index bd2a3b4..122d9ad 100644
39089--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
39090+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39091@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
39092 static int ttm_pool_mm_shrink(struct shrinker *shrink,
39093 struct shrink_control *sc)
39094 {
39095- static atomic_t start_pool = ATOMIC_INIT(0);
39096+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
39097 unsigned i;
39098- unsigned pool_offset = atomic_add_return(1, &start_pool);
39099+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
39100 struct ttm_page_pool *pool;
39101 int shrink_pages = sc->nr_to_scan;
39102
39103diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
39104index 97e9d61..bf23c461 100644
39105--- a/drivers/gpu/drm/udl/udl_fb.c
39106+++ b/drivers/gpu/drm/udl/udl_fb.c
39107@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
39108 fb_deferred_io_cleanup(info);
39109 kfree(info->fbdefio);
39110 info->fbdefio = NULL;
39111- info->fbops->fb_mmap = udl_fb_mmap;
39112 }
39113
39114 pr_warn("released /dev/fb%d user=%d count=%d\n",
39115diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
39116index 893a650..6190d3b 100644
39117--- a/drivers/gpu/drm/via/via_drv.h
39118+++ b/drivers/gpu/drm/via/via_drv.h
39119@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
39120 typedef uint32_t maskarray_t[5];
39121
39122 typedef struct drm_via_irq {
39123- atomic_t irq_received;
39124+ atomic_unchecked_t irq_received;
39125 uint32_t pending_mask;
39126 uint32_t enable_mask;
39127 wait_queue_head_t irq_queue;
39128@@ -75,7 +75,7 @@ typedef struct drm_via_private {
39129 struct timeval last_vblank;
39130 int last_vblank_valid;
39131 unsigned usec_per_vblank;
39132- atomic_t vbl_received;
39133+ atomic_unchecked_t vbl_received;
39134 drm_via_state_t hc_state;
39135 char pci_buf[VIA_PCI_BUF_SIZE];
39136 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
39137diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
39138index ac98964..5dbf512 100644
39139--- a/drivers/gpu/drm/via/via_irq.c
39140+++ b/drivers/gpu/drm/via/via_irq.c
39141@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
39142 if (crtc != 0)
39143 return 0;
39144
39145- return atomic_read(&dev_priv->vbl_received);
39146+ return atomic_read_unchecked(&dev_priv->vbl_received);
39147 }
39148
39149 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39150@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39151
39152 status = VIA_READ(VIA_REG_INTERRUPT);
39153 if (status & VIA_IRQ_VBLANK_PENDING) {
39154- atomic_inc(&dev_priv->vbl_received);
39155- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
39156+ atomic_inc_unchecked(&dev_priv->vbl_received);
39157+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
39158 do_gettimeofday(&cur_vblank);
39159 if (dev_priv->last_vblank_valid) {
39160 dev_priv->usec_per_vblank =
39161@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39162 dev_priv->last_vblank = cur_vblank;
39163 dev_priv->last_vblank_valid = 1;
39164 }
39165- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
39166+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
39167 DRM_DEBUG("US per vblank is: %u\n",
39168 dev_priv->usec_per_vblank);
39169 }
39170@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39171
39172 for (i = 0; i < dev_priv->num_irqs; ++i) {
39173 if (status & cur_irq->pending_mask) {
39174- atomic_inc(&cur_irq->irq_received);
39175+ atomic_inc_unchecked(&cur_irq->irq_received);
39176 DRM_WAKEUP(&cur_irq->irq_queue);
39177 handled = 1;
39178 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
39179@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
39180 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39181 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
39182 masks[irq][4]));
39183- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
39184+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
39185 } else {
39186 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39187 (((cur_irq_sequence =
39188- atomic_read(&cur_irq->irq_received)) -
39189+ atomic_read_unchecked(&cur_irq->irq_received)) -
39190 *sequence) <= (1 << 23)));
39191 }
39192 *sequence = cur_irq_sequence;
39193@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
39194 }
39195
39196 for (i = 0; i < dev_priv->num_irqs; ++i) {
39197- atomic_set(&cur_irq->irq_received, 0);
39198+ atomic_set_unchecked(&cur_irq->irq_received, 0);
39199 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
39200 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
39201 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
39202@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
39203 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
39204 case VIA_IRQ_RELATIVE:
39205 irqwait->request.sequence +=
39206- atomic_read(&cur_irq->irq_received);
39207+ atomic_read_unchecked(&cur_irq->irq_received);
39208 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
39209 case VIA_IRQ_ABSOLUTE:
39210 break;
39211diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39212index 13aeda7..4a952d1 100644
39213--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39214+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39215@@ -290,7 +290,7 @@ struct vmw_private {
39216 * Fencing and IRQs.
39217 */
39218
39219- atomic_t marker_seq;
39220+ atomic_unchecked_t marker_seq;
39221 wait_queue_head_t fence_queue;
39222 wait_queue_head_t fifo_queue;
39223 int fence_queue_waiters; /* Protected by hw_mutex */
39224diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39225index 3eb1486..0a47ee9 100644
39226--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39227+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39228@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
39229 (unsigned int) min,
39230 (unsigned int) fifo->capabilities);
39231
39232- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39233+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39234 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
39235 vmw_marker_queue_init(&fifo->marker_queue);
39236 return vmw_fifo_send_fence(dev_priv, &dummy);
39237@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
39238 if (reserveable)
39239 iowrite32(bytes, fifo_mem +
39240 SVGA_FIFO_RESERVED);
39241- return fifo_mem + (next_cmd >> 2);
39242+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
39243 } else {
39244 need_bounce = true;
39245 }
39246@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39247
39248 fm = vmw_fifo_reserve(dev_priv, bytes);
39249 if (unlikely(fm == NULL)) {
39250- *seqno = atomic_read(&dev_priv->marker_seq);
39251+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39252 ret = -ENOMEM;
39253 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
39254 false, 3*HZ);
39255@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39256 }
39257
39258 do {
39259- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
39260+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
39261 } while (*seqno == 0);
39262
39263 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
39264diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39265index c509d40..3b640c3 100644
39266--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39267+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39268@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
39269 int ret;
39270
39271 num_clips = arg->num_clips;
39272- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39273+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39274
39275 if (unlikely(num_clips == 0))
39276 return 0;
39277@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
39278 int ret;
39279
39280 num_clips = arg->num_clips;
39281- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39282+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39283
39284 if (unlikely(num_clips == 0))
39285 return 0;
39286diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39287index 4640adb..e1384ed 100644
39288--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39289+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39290@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
39291 * emitted. Then the fence is stale and signaled.
39292 */
39293
39294- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
39295+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
39296 > VMW_FENCE_WRAP);
39297
39298 return ret;
39299@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
39300
39301 if (fifo_idle)
39302 down_read(&fifo_state->rwsem);
39303- signal_seq = atomic_read(&dev_priv->marker_seq);
39304+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
39305 ret = 0;
39306
39307 for (;;) {
39308diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39309index 8a8725c2..afed796 100644
39310--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39311+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39312@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
39313 while (!vmw_lag_lt(queue, us)) {
39314 spin_lock(&queue->lock);
39315 if (list_empty(&queue->head))
39316- seqno = atomic_read(&dev_priv->marker_seq);
39317+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39318 else {
39319 marker = list_first_entry(&queue->head,
39320 struct vmw_marker, head);
39321diff --git a/drivers/gpu/host1x/drm/dc.c b/drivers/gpu/host1x/drm/dc.c
39322index 5360e5a..c2c0d26 100644
39323--- a/drivers/gpu/host1x/drm/dc.c
39324+++ b/drivers/gpu/host1x/drm/dc.c
39325@@ -1004,7 +1004,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
39326 }
39327
39328 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
39329- dc->debugfs_files[i].data = dc;
39330+ *(void **)&dc->debugfs_files[i].data = dc;
39331
39332 err = drm_debugfs_create_files(dc->debugfs_files,
39333 ARRAY_SIZE(debugfs_files),
39334diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
39335index 36668d1..9f4ccb0 100644
39336--- a/drivers/hid/hid-core.c
39337+++ b/drivers/hid/hid-core.c
39338@@ -63,6 +63,8 @@ struct hid_report *hid_register_report(struct hid_device *device, unsigned type,
39339 struct hid_report_enum *report_enum = device->report_enum + type;
39340 struct hid_report *report;
39341
39342+ if (id >= HID_MAX_IDS)
39343+ return NULL;
39344 if (report_enum->report_id_hash[id])
39345 return report_enum->report_id_hash[id];
39346
39347@@ -404,8 +406,10 @@ static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
39348
39349 case HID_GLOBAL_ITEM_TAG_REPORT_ID:
39350 parser->global.report_id = item_udata(item);
39351- if (parser->global.report_id == 0) {
39352- hid_err(parser->device, "report_id 0 is invalid\n");
39353+ if (parser->global.report_id == 0 ||
39354+ parser->global.report_id >= HID_MAX_IDS) {
39355+ hid_err(parser->device, "report_id %u is invalid\n",
39356+ parser->global.report_id);
39357 return -1;
39358 }
39359 return 0;
39360@@ -575,7 +579,7 @@ static void hid_close_report(struct hid_device *device)
39361 for (i = 0; i < HID_REPORT_TYPES; i++) {
39362 struct hid_report_enum *report_enum = device->report_enum + i;
39363
39364- for (j = 0; j < 256; j++) {
39365+ for (j = 0; j < HID_MAX_IDS; j++) {
39366 struct hid_report *report = report_enum->report_id_hash[j];
39367 if (report)
39368 hid_free_report(report);
39369@@ -755,6 +759,56 @@ int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size)
39370 }
39371 EXPORT_SYMBOL_GPL(hid_parse_report);
39372
39373+static const char * const hid_report_names[] = {
39374+ "HID_INPUT_REPORT",
39375+ "HID_OUTPUT_REPORT",
39376+ "HID_FEATURE_REPORT",
39377+};
39378+/**
39379+ * hid_validate_report - validate existing device report
39380+ *
39381+ * @device: hid device
39382+ * @type: which report type to examine
39383+ * @id: which report ID to examine (0 for first)
39384+ * @fields: expected number of fields
39385+ * @report_counts: expected number of values per field
39386+ *
39387+ * Validate the report details after parsing.
39388+ */
39389+struct hid_report *hid_validate_report(struct hid_device *hid,
39390+ unsigned int type, unsigned int id,
39391+ unsigned int fields,
39392+ unsigned int report_counts)
39393+{
39394+ struct hid_report *report;
39395+ unsigned int i;
39396+
39397+ if (type > HID_FEATURE_REPORT) {
39398+ hid_err(hid, "invalid HID report %u\n", type);
39399+ return NULL;
39400+ }
39401+
39402+ report = hid->report_enum[type].report_id_hash[id];
39403+ if (!report) {
39404+ hid_err(hid, "missing %s %u\n", hid_report_names[type], id);
39405+ return NULL;
39406+ }
39407+ if (report->maxfield < fields) {
39408+ hid_err(hid, "not enough fields in %s %u\n",
39409+ hid_report_names[type], id);
39410+ return NULL;
39411+ }
39412+ for (i = 0; i < fields; i++) {
39413+ if (report->field[i]->report_count < report_counts) {
39414+ hid_err(hid, "not enough values in %s %u fields\n",
39415+ hid_report_names[type], id);
39416+ return NULL;
39417+ }
39418+ }
39419+ return report;
39420+}
39421+EXPORT_SYMBOL_GPL(hid_validate_report);
39422+
39423 /**
39424 * hid_open_report - open a driver-specific device report
39425 *
39426@@ -1152,7 +1206,12 @@ EXPORT_SYMBOL_GPL(hid_output_report);
39427
39428 int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
39429 {
39430- unsigned size = field->report_size;
39431+ unsigned size;
39432+
39433+ if (!field)
39434+ return -1;
39435+
39436+ size = field->report_size;
39437
39438 hid_dump_input(field->report->device, field->usage + offset, value);
39439
39440@@ -2285,7 +2344,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
39441
39442 int hid_add_device(struct hid_device *hdev)
39443 {
39444- static atomic_t id = ATOMIC_INIT(0);
39445+ static atomic_unchecked_t id = ATOMIC_INIT(0);
39446 int ret;
39447
39448 if (WARN_ON(hdev->status & HID_STAT_ADDED))
39449@@ -2319,7 +2378,7 @@ int hid_add_device(struct hid_device *hdev)
39450 /* XXX hack, any other cleaner solution after the driver core
39451 * is converted to allow more than 20 bytes as the device name? */
39452 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
39453- hdev->vendor, hdev->product, atomic_inc_return(&id));
39454+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
39455
39456 hid_debug_register(hdev, dev_name(&hdev->dev));
39457 ret = device_add(&hdev->dev);
39458diff --git a/drivers/hid/hid-lenovo-tpkbd.c b/drivers/hid/hid-lenovo-tpkbd.c
39459index 07837f5..b697ada 100644
39460--- a/drivers/hid/hid-lenovo-tpkbd.c
39461+++ b/drivers/hid/hid-lenovo-tpkbd.c
39462@@ -341,6 +341,11 @@ static int tpkbd_probe_tp(struct hid_device *hdev)
39463 char *name_mute, *name_micmute;
39464 int ret;
39465
39466+ /* Validate required reports. */
39467+ if (!hid_validate_report(hdev, HID_OUTPUT_REPORT, 4, 4, 1) ||
39468+ !hid_validate_report(hdev, HID_OUTPUT_REPORT, 3, 1, 2))
39469+ return -ENODEV;
39470+
39471 if (sysfs_create_group(&hdev->dev.kobj,
39472 &tpkbd_attr_group_pointer)) {
39473 hid_warn(hdev, "Could not create sysfs group\n");
39474diff --git a/drivers/hid/hid-lg2ff.c b/drivers/hid/hid-lg2ff.c
39475index b3cd150..9805197 100644
39476--- a/drivers/hid/hid-lg2ff.c
39477+++ b/drivers/hid/hid-lg2ff.c
39478@@ -64,26 +64,13 @@ int lg2ff_init(struct hid_device *hid)
39479 struct hid_report *report;
39480 struct hid_input *hidinput = list_entry(hid->inputs.next,
39481 struct hid_input, list);
39482- struct list_head *report_list =
39483- &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39484 struct input_dev *dev = hidinput->input;
39485 int error;
39486
39487- if (list_empty(report_list)) {
39488- hid_err(hid, "no output report found\n");
39489+ /* Check that the report looks ok */
39490+ report = hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 7);
39491+ if (!report)
39492 return -ENODEV;
39493- }
39494-
39495- report = list_entry(report_list->next, struct hid_report, list);
39496-
39497- if (report->maxfield < 1) {
39498- hid_err(hid, "output report is empty\n");
39499- return -ENODEV;
39500- }
39501- if (report->field[0]->report_count < 7) {
39502- hid_err(hid, "not enough values in the field\n");
39503- return -ENODEV;
39504- }
39505
39506 lg2ff = kmalloc(sizeof(struct lg2ff_device), GFP_KERNEL);
39507 if (!lg2ff)
39508diff --git a/drivers/hid/hid-lg3ff.c b/drivers/hid/hid-lg3ff.c
39509index e52f181..53ac79b 100644
39510--- a/drivers/hid/hid-lg3ff.c
39511+++ b/drivers/hid/hid-lg3ff.c
39512@@ -66,10 +66,11 @@ static int hid_lg3ff_play(struct input_dev *dev, void *data,
39513 int x, y;
39514
39515 /*
39516- * Maxusage should always be 63 (maximum fields)
39517- * likely a better way to ensure this data is clean
39518+ * Available values in the field should always be 63, but we only use up to
39519+ * 35. Instead, clear the entire area, however big it is.
39520 */
39521- memset(report->field[0]->value, 0, sizeof(__s32)*report->field[0]->maxusage);
39522+ memset(report->field[0]->value, 0,
39523+ sizeof(__s32) * report->field[0]->report_count);
39524
39525 switch (effect->type) {
39526 case FF_CONSTANT:
39527@@ -129,32 +130,14 @@ static const signed short ff3_joystick_ac[] = {
39528 int lg3ff_init(struct hid_device *hid)
39529 {
39530 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
39531- struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39532 struct input_dev *dev = hidinput->input;
39533- struct hid_report *report;
39534- struct hid_field *field;
39535 const signed short *ff_bits = ff3_joystick_ac;
39536 int error;
39537 int i;
39538
39539- /* Find the report to use */
39540- if (list_empty(report_list)) {
39541- hid_err(hid, "No output report found\n");
39542- return -1;
39543- }
39544-
39545 /* Check that the report looks ok */
39546- report = list_entry(report_list->next, struct hid_report, list);
39547- if (!report) {
39548- hid_err(hid, "NULL output report\n");
39549- return -1;
39550- }
39551-
39552- field = report->field[0];
39553- if (!field) {
39554- hid_err(hid, "NULL field\n");
39555- return -1;
39556- }
39557+ if (!hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 35))
39558+ return -ENODEV;
39559
39560 /* Assume single fixed device G940 */
39561 for (i = 0; ff_bits[i] >= 0; i++)
39562diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c
39563index 0ddae2a..8b89f0f 100644
39564--- a/drivers/hid/hid-lg4ff.c
39565+++ b/drivers/hid/hid-lg4ff.c
39566@@ -484,34 +484,16 @@ static enum led_brightness lg4ff_led_get_brightness(struct led_classdev *led_cde
39567 int lg4ff_init(struct hid_device *hid)
39568 {
39569 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
39570- struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39571 struct input_dev *dev = hidinput->input;
39572- struct hid_report *report;
39573- struct hid_field *field;
39574 struct lg4ff_device_entry *entry;
39575 struct lg_drv_data *drv_data;
39576 struct usb_device_descriptor *udesc;
39577 int error, i, j;
39578 __u16 bcdDevice, rev_maj, rev_min;
39579
39580- /* Find the report to use */
39581- if (list_empty(report_list)) {
39582- hid_err(hid, "No output report found\n");
39583- return -1;
39584- }
39585-
39586 /* Check that the report looks ok */
39587- report = list_entry(report_list->next, struct hid_report, list);
39588- if (!report) {
39589- hid_err(hid, "NULL output report\n");
39590+ if (!hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 7))
39591 return -1;
39592- }
39593-
39594- field = report->field[0];
39595- if (!field) {
39596- hid_err(hid, "NULL field\n");
39597- return -1;
39598- }
39599
39600 /* Check what wheel has been connected */
39601 for (i = 0; i < ARRAY_SIZE(lg4ff_devices); i++) {
39602diff --git a/drivers/hid/hid-lgff.c b/drivers/hid/hid-lgff.c
39603index d7ea8c8..a84fb40 100644
39604--- a/drivers/hid/hid-lgff.c
39605+++ b/drivers/hid/hid-lgff.c
39606@@ -128,27 +128,14 @@ static void hid_lgff_set_autocenter(struct input_dev *dev, u16 magnitude)
39607 int lgff_init(struct hid_device* hid)
39608 {
39609 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
39610- struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39611 struct input_dev *dev = hidinput->input;
39612- struct hid_report *report;
39613- struct hid_field *field;
39614 const signed short *ff_bits = ff_joystick;
39615 int error;
39616 int i;
39617
39618- /* Find the report to use */
39619- if (list_empty(report_list)) {
39620- hid_err(hid, "No output report found\n");
39621- return -1;
39622- }
39623-
39624 /* Check that the report looks ok */
39625- report = list_entry(report_list->next, struct hid_report, list);
39626- field = report->field[0];
39627- if (!field) {
39628- hid_err(hid, "NULL field\n");
39629- return -1;
39630- }
39631+ if (!hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 7))
39632+ return -ENODEV;
39633
39634 for (i = 0; i < ARRAY_SIZE(devices); i++) {
39635 if (dev->id.vendor == devices[i].idVendor &&
39636diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
39637index cd33084..7b99c2a 100644
39638--- a/drivers/hid/hid-logitech-dj.c
39639+++ b/drivers/hid/hid-logitech-dj.c
39640@@ -461,7 +461,7 @@ static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev,
39641 struct hid_report *report;
39642 struct hid_report_enum *output_report_enum;
39643 u8 *data = (u8 *)(&dj_report->device_index);
39644- int i;
39645+ unsigned int i, length;
39646
39647 output_report_enum = &hdev->report_enum[HID_OUTPUT_REPORT];
39648 report = output_report_enum->report_id_hash[REPORT_ID_DJ_SHORT];
39649@@ -471,7 +471,9 @@ static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev,
39650 return -ENODEV;
39651 }
39652
39653- for (i = 0; i < report->field[0]->report_count; i++)
39654+ length = min_t(size_t, sizeof(*dj_report) - 1,
39655+ report->field[0]->report_count);
39656+ for (i = 0; i < length; i++)
39657 report->field[0]->value[i] = data[i];
39658
39659 hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
39660@@ -783,6 +785,12 @@ static int logi_dj_probe(struct hid_device *hdev,
39661 goto hid_parse_fail;
39662 }
39663
39664+ if (!hid_validate_report(hdev, HID_OUTPUT_REPORT, REPORT_ID_DJ_SHORT,
39665+ 1, 3)) {
39666+ retval = -ENODEV;
39667+ goto hid_parse_fail;
39668+ }
39669+
39670 /* Starts the usb device and connects to upper interfaces hiddev and
39671 * hidraw */
39672 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
39673diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
39674index cb0e361..2aa275e 100644
39675--- a/drivers/hid/hid-multitouch.c
39676+++ b/drivers/hid/hid-multitouch.c
39677@@ -330,9 +330,18 @@ static void mt_feature_mapping(struct hid_device *hdev,
39678 break;
39679 }
39680 }
39681+ /* Ignore if value index is out of bounds. */
39682+ if (td->inputmode_index < 0 ||
39683+ td->inputmode_index >= field->report_count) {
39684+ dev_err(&hdev->dev, "HID_DG_INPUTMODE out of range\n");
39685+ td->inputmode = -1;
39686+ }
39687
39688 break;
39689 case HID_DG_CONTACTMAX:
39690+ /* Ignore if value count is out of bounds. */
39691+ if (field->report_count < 1)
39692+ break;
39693 td->maxcontact_report_id = field->report->id;
39694 td->maxcontacts = field->value[0];
39695 if (!td->maxcontacts &&
39696@@ -743,15 +752,21 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report)
39697 unsigned count;
39698 int r, n;
39699
39700+ if (report->maxfield == 0)
39701+ return;
39702+
39703 /*
39704 * Includes multi-packet support where subsequent
39705 * packets are sent with zero contactcount.
39706 */
39707- if (td->cc_index >= 0) {
39708- struct hid_field *field = report->field[td->cc_index];
39709- int value = field->value[td->cc_value_index];
39710- if (value)
39711- td->num_expected = value;
39712+ if (td->cc_index >= 0 && td->cc_index < report->maxfield) {
39713+ field = report->field[td->cc_index];
39714+ if (td->cc_value_index >= 0 &&
39715+ td->cc_value_index < field->report_count) {
39716+ int value = field->value[td->cc_value_index];
39717+ if (value)
39718+ td->num_expected = value;
39719+ }
39720 }
39721
39722 for (r = 0; r < report->maxfield; r++) {
39723diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c
39724index ef95102..5482156 100644
39725--- a/drivers/hid/hid-ntrig.c
39726+++ b/drivers/hid/hid-ntrig.c
39727@@ -115,7 +115,8 @@ static inline int ntrig_get_mode(struct hid_device *hdev)
39728 struct hid_report *report = hdev->report_enum[HID_FEATURE_REPORT].
39729 report_id_hash[0x0d];
39730
39731- if (!report)
39732+ if (!report || report->maxfield < 1 ||
39733+ report->field[0]->report_count < 1)
39734 return -EINVAL;
39735
39736 hid_hw_request(hdev, report, HID_REQ_GET_REPORT);
39737diff --git a/drivers/hid/hid-picolcd_core.c b/drivers/hid/hid-picolcd_core.c
39738index b48092d..72bba1e 100644
39739--- a/drivers/hid/hid-picolcd_core.c
39740+++ b/drivers/hid/hid-picolcd_core.c
39741@@ -290,7 +290,7 @@ static ssize_t picolcd_operation_mode_store(struct device *dev,
39742 buf += 10;
39743 cnt -= 10;
39744 }
39745- if (!report)
39746+ if (!report || report->maxfield < 1)
39747 return -EINVAL;
39748
39749 while (cnt > 0 && (buf[cnt-1] == '\n' || buf[cnt-1] == '\r'))
39750diff --git a/drivers/hid/hid-pl.c b/drivers/hid/hid-pl.c
39751index d29112f..2dcd7d9 100644
39752--- a/drivers/hid/hid-pl.c
39753+++ b/drivers/hid/hid-pl.c
39754@@ -132,8 +132,14 @@ static int plff_init(struct hid_device *hid)
39755 strong = &report->field[0]->value[2];
39756 weak = &report->field[0]->value[3];
39757 debug("detected single-field device");
39758- } else if (report->maxfield >= 4 && report->field[0]->maxusage == 1 &&
39759- report->field[0]->usage[0].hid == (HID_UP_LED | 0x43)) {
39760+ } else if (report->field[0]->maxusage == 1 &&
39761+ report->field[0]->usage[0].hid ==
39762+ (HID_UP_LED | 0x43) &&
39763+ report->maxfield >= 4 &&
39764+ report->field[0]->report_count >= 1 &&
39765+ report->field[1]->report_count >= 1 &&
39766+ report->field[2]->report_count >= 1 &&
39767+ report->field[3]->report_count >= 1) {
39768 report->field[0]->value[0] = 0x00;
39769 report->field[1]->value[0] = 0x00;
39770 strong = &report->field[2]->value[0];
39771diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
39772index ca749810..aa34755 100644
39773--- a/drivers/hid/hid-sensor-hub.c
39774+++ b/drivers/hid/hid-sensor-hub.c
39775@@ -221,7 +221,8 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
39776
39777 mutex_lock(&data->mutex);
39778 report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
39779- if (!report || (field_index >= report->maxfield)) {
39780+ if (!report || (field_index >= report->maxfield) ||
39781+ report->field[field_index]->report_count < 1) {
39782 ret = -EINVAL;
39783 goto done_proc;
39784 }
39785diff --git a/drivers/hid/hid-steelseries.c b/drivers/hid/hid-steelseries.c
39786index d164911..ef42e86 100644
39787--- a/drivers/hid/hid-steelseries.c
39788+++ b/drivers/hid/hid-steelseries.c
39789@@ -249,6 +249,11 @@ static int steelseries_srws1_probe(struct hid_device *hdev,
39790 goto err_free;
39791 }
39792
39793+ if (!hid_validate_report(hdev, HID_OUTPUT_REPORT, 0, 1, 16)) {
39794+ ret = -ENODEV;
39795+ goto err_free;
39796+ }
39797+
39798 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
39799 if (ret) {
39800 hid_err(hdev, "hw start failed\n");
39801diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
39802index c13fb5b..55a3802 100644
39803--- a/drivers/hid/hid-wiimote-debug.c
39804+++ b/drivers/hid/hid-wiimote-debug.c
39805@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
39806 else if (size == 0)
39807 return -EIO;
39808
39809- if (copy_to_user(u, buf, size))
39810+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
39811 return -EFAULT;
39812
39813 *off += size;
39814diff --git a/drivers/hid/hid-zpff.c b/drivers/hid/hid-zpff.c
39815index 6ec28a3..b124991 100644
39816--- a/drivers/hid/hid-zpff.c
39817+++ b/drivers/hid/hid-zpff.c
39818@@ -68,22 +68,12 @@ static int zpff_init(struct hid_device *hid)
39819 struct hid_report *report;
39820 struct hid_input *hidinput = list_entry(hid->inputs.next,
39821 struct hid_input, list);
39822- struct list_head *report_list =
39823- &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39824 struct input_dev *dev = hidinput->input;
39825 int error;
39826
39827- if (list_empty(report_list)) {
39828- hid_err(hid, "no output report found\n");
39829+ report = hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 4, 1);
39830+ if (!report)
39831 return -ENODEV;
39832- }
39833-
39834- report = list_entry(report_list->next, struct hid_report, list);
39835-
39836- if (report->maxfield < 4) {
39837- hid_err(hid, "not enough fields in report\n");
39838- return -ENODEV;
39839- }
39840
39841 zpff = kzalloc(sizeof(struct zpff_device), GFP_KERNEL);
39842 if (!zpff)
39843diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
39844index fc307e0..2b255e8 100644
39845--- a/drivers/hid/uhid.c
39846+++ b/drivers/hid/uhid.c
39847@@ -47,7 +47,7 @@ struct uhid_device {
39848 struct mutex report_lock;
39849 wait_queue_head_t report_wait;
39850 atomic_t report_done;
39851- atomic_t report_id;
39852+ atomic_unchecked_t report_id;
39853 struct uhid_event report_buf;
39854 };
39855
39856@@ -187,7 +187,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
39857
39858 spin_lock_irqsave(&uhid->qlock, flags);
39859 ev->type = UHID_FEATURE;
39860- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
39861+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
39862 ev->u.feature.rnum = rnum;
39863 ev->u.feature.rtype = report_type;
39864
39865@@ -471,7 +471,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
39866 spin_lock_irqsave(&uhid->qlock, flags);
39867
39868 /* id for old report; drop it silently */
39869- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
39870+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
39871 goto unlock;
39872 if (atomic_read(&uhid->report_done))
39873 goto unlock;
39874diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
39875index 6de6c98..18319e9 100644
39876--- a/drivers/hv/channel.c
39877+++ b/drivers/hv/channel.c
39878@@ -406,8 +406,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
39879 int ret = 0;
39880 int t;
39881
39882- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
39883- atomic_inc(&vmbus_connection.next_gpadl_handle);
39884+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
39885+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
39886
39887 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
39888 if (ret)
39889diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
39890index 88f4096..e50452e 100644
39891--- a/drivers/hv/hv.c
39892+++ b/drivers/hv/hv.c
39893@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
39894 u64 output_address = (output) ? virt_to_phys(output) : 0;
39895 u32 output_address_hi = output_address >> 32;
39896 u32 output_address_lo = output_address & 0xFFFFFFFF;
39897- void *hypercall_page = hv_context.hypercall_page;
39898+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
39899
39900 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
39901 "=a"(hv_status_lo) : "d" (control_hi),
39902diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
39903index deb5c25..ed2d4fd 100644
39904--- a/drivers/hv/hv_balloon.c
39905+++ b/drivers/hv/hv_balloon.c
39906@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
39907
39908 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
39909 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
39910-static atomic_t trans_id = ATOMIC_INIT(0);
39911+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
39912
39913 static int dm_ring_size = (5 * PAGE_SIZE);
39914
39915@@ -825,7 +825,7 @@ static void hot_add_req(struct work_struct *dummy)
39916 memset(&resp, 0, sizeof(struct dm_hot_add_response));
39917 resp.hdr.type = DM_MEM_HOT_ADD_RESPONSE;
39918 resp.hdr.size = sizeof(struct dm_hot_add_response);
39919- resp.hdr.trans_id = atomic_inc_return(&trans_id);
39920+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39921
39922 #ifdef CONFIG_MEMORY_HOTPLUG
39923 pg_start = dm->ha_wrk.ha_page_range.finfo.start_page;
39924@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
39925 memset(&status, 0, sizeof(struct dm_status));
39926 status.hdr.type = DM_STATUS_REPORT;
39927 status.hdr.size = sizeof(struct dm_status);
39928- status.hdr.trans_id = atomic_inc_return(&trans_id);
39929+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39930
39931 /*
39932 * The host expects the guest to report free memory.
39933@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
39934 * send the status. This can happen if we were interrupted
39935 * after we picked our transaction ID.
39936 */
39937- if (status.hdr.trans_id != atomic_read(&trans_id))
39938+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
39939 return;
39940
39941 vmbus_sendpacket(dm->dev->channel, &status,
39942@@ -1081,7 +1081,7 @@ static void balloon_up(struct work_struct *dummy)
39943 bl_resp = (struct dm_balloon_response *)send_buffer;
39944 memset(send_buffer, 0, PAGE_SIZE);
39945 bl_resp->hdr.type = DM_BALLOON_RESPONSE;
39946- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
39947+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39948 bl_resp->hdr.size = sizeof(struct dm_balloon_response);
39949 bl_resp->more_pages = 1;
39950
39951@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
39952
39953 memset(&resp, 0, sizeof(struct dm_unballoon_response));
39954 resp.hdr.type = DM_UNBALLOON_RESPONSE;
39955- resp.hdr.trans_id = atomic_inc_return(&trans_id);
39956+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39957 resp.hdr.size = sizeof(struct dm_unballoon_response);
39958
39959 vmbus_sendpacket(dm_device.dev->channel, &resp,
39960@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
39961 memset(&version_req, 0, sizeof(struct dm_version_request));
39962 version_req.hdr.type = DM_VERSION_REQUEST;
39963 version_req.hdr.size = sizeof(struct dm_version_request);
39964- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
39965+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39966 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
39967 version_req.is_last_attempt = 1;
39968
39969@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
39970 memset(&version_req, 0, sizeof(struct dm_version_request));
39971 version_req.hdr.type = DM_VERSION_REQUEST;
39972 version_req.hdr.size = sizeof(struct dm_version_request);
39973- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
39974+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39975 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
39976 version_req.is_last_attempt = 0;
39977
39978@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
39979 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
39980 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
39981 cap_msg.hdr.size = sizeof(struct dm_capabilities);
39982- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
39983+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39984
39985 cap_msg.caps.cap_bits.balloon = 1;
39986 cap_msg.caps.cap_bits.hot_add = 1;
39987diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
39988index d84918f..7f38f9f 100644
39989--- a/drivers/hv/hyperv_vmbus.h
39990+++ b/drivers/hv/hyperv_vmbus.h
39991@@ -595,7 +595,7 @@ enum vmbus_connect_state {
39992 struct vmbus_connection {
39993 enum vmbus_connect_state conn_state;
39994
39995- atomic_t next_gpadl_handle;
39996+ atomic_unchecked_t next_gpadl_handle;
39997
39998 /*
39999 * Represents channel interrupts. Each bit position represents a
40000diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
40001index e8e071f..5b4b245 100644
40002--- a/drivers/hv/vmbus_drv.c
40003+++ b/drivers/hv/vmbus_drv.c
40004@@ -672,10 +672,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
40005 {
40006 int ret = 0;
40007
40008- static atomic_t device_num = ATOMIC_INIT(0);
40009+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
40010
40011 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
40012- atomic_inc_return(&device_num));
40013+ atomic_inc_return_unchecked(&device_num));
40014
40015 child_device_obj->device.bus = &hv_bus;
40016 child_device_obj->device.parent = &hv_acpi_dev->dev;
40017diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
40018index 6351aba..dc4aaf4 100644
40019--- a/drivers/hwmon/acpi_power_meter.c
40020+++ b/drivers/hwmon/acpi_power_meter.c
40021@@ -117,7 +117,7 @@ struct sensor_template {
40022 struct device_attribute *devattr,
40023 const char *buf, size_t count);
40024 int index;
40025-};
40026+} __do_const;
40027
40028 /* Averaging interval */
40029 static int update_avg_interval(struct acpi_power_meter_resource *resource)
40030@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
40031 struct sensor_template *attrs)
40032 {
40033 struct device *dev = &resource->acpi_dev->dev;
40034- struct sensor_device_attribute *sensors =
40035+ sensor_device_attribute_no_const *sensors =
40036 &resource->sensors[resource->num_sensors];
40037 int res = 0;
40038
40039diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
40040index 62c2e32..8f2859a 100644
40041--- a/drivers/hwmon/applesmc.c
40042+++ b/drivers/hwmon/applesmc.c
40043@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
40044 {
40045 struct applesmc_node_group *grp;
40046 struct applesmc_dev_attr *node;
40047- struct attribute *attr;
40048+ attribute_no_const *attr;
40049 int ret, i;
40050
40051 for (grp = groups; grp->format; grp++) {
40052diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
40053index b25c643..a13460d 100644
40054--- a/drivers/hwmon/asus_atk0110.c
40055+++ b/drivers/hwmon/asus_atk0110.c
40056@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
40057 struct atk_sensor_data {
40058 struct list_head list;
40059 struct atk_data *data;
40060- struct device_attribute label_attr;
40061- struct device_attribute input_attr;
40062- struct device_attribute limit1_attr;
40063- struct device_attribute limit2_attr;
40064+ device_attribute_no_const label_attr;
40065+ device_attribute_no_const input_attr;
40066+ device_attribute_no_const limit1_attr;
40067+ device_attribute_no_const limit2_attr;
40068 char label_attr_name[ATTR_NAME_SIZE];
40069 char input_attr_name[ATTR_NAME_SIZE];
40070 char limit1_attr_name[ATTR_NAME_SIZE];
40071@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
40072 static struct device_attribute atk_name_attr =
40073 __ATTR(name, 0444, atk_name_show, NULL);
40074
40075-static void atk_init_attribute(struct device_attribute *attr, char *name,
40076+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
40077 sysfs_show_func show)
40078 {
40079 sysfs_attr_init(&attr->attr);
40080diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
40081index 2e5e2dc..5208b31 100644
40082--- a/drivers/hwmon/coretemp.c
40083+++ b/drivers/hwmon/coretemp.c
40084@@ -785,7 +785,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
40085 return NOTIFY_OK;
40086 }
40087
40088-static struct notifier_block coretemp_cpu_notifier __refdata = {
40089+static struct notifier_block coretemp_cpu_notifier = {
40090 .notifier_call = coretemp_cpu_callback,
40091 };
40092
40093diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
40094index 1429f6e..ee03d59 100644
40095--- a/drivers/hwmon/ibmaem.c
40096+++ b/drivers/hwmon/ibmaem.c
40097@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
40098 struct aem_rw_sensor_template *rw)
40099 {
40100 struct device *dev = &data->pdev->dev;
40101- struct sensor_device_attribute *sensors = data->sensors;
40102+ sensor_device_attribute_no_const *sensors = data->sensors;
40103 int err;
40104
40105 /* Set up read-only sensors */
40106diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
40107index 708081b..fe2d4ab 100644
40108--- a/drivers/hwmon/iio_hwmon.c
40109+++ b/drivers/hwmon/iio_hwmon.c
40110@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
40111 {
40112 struct device *dev = &pdev->dev;
40113 struct iio_hwmon_state *st;
40114- struct sensor_device_attribute *a;
40115+ sensor_device_attribute_no_const *a;
40116 int ret, i;
40117 int in_i = 1, temp_i = 1, curr_i = 1;
40118 enum iio_chan_type type;
40119diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
40120index 9add6092..ee7ba3f 100644
40121--- a/drivers/hwmon/pmbus/pmbus_core.c
40122+++ b/drivers/hwmon/pmbus/pmbus_core.c
40123@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
40124 return 0;
40125 }
40126
40127-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
40128+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
40129 const char *name,
40130 umode_t mode,
40131 ssize_t (*show)(struct device *dev,
40132@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
40133 dev_attr->store = store;
40134 }
40135
40136-static void pmbus_attr_init(struct sensor_device_attribute *a,
40137+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
40138 const char *name,
40139 umode_t mode,
40140 ssize_t (*show)(struct device *dev,
40141@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
40142 u16 reg, u8 mask)
40143 {
40144 struct pmbus_boolean *boolean;
40145- struct sensor_device_attribute *a;
40146+ sensor_device_attribute_no_const *a;
40147
40148 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
40149 if (!boolean)
40150@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
40151 bool update, bool readonly)
40152 {
40153 struct pmbus_sensor *sensor;
40154- struct device_attribute *a;
40155+ device_attribute_no_const *a;
40156
40157 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
40158 if (!sensor)
40159@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
40160 const char *lstring, int index)
40161 {
40162 struct pmbus_label *label;
40163- struct device_attribute *a;
40164+ device_attribute_no_const *a;
40165
40166 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
40167 if (!label)
40168diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
40169index 2507f90..1645765 100644
40170--- a/drivers/hwmon/sht15.c
40171+++ b/drivers/hwmon/sht15.c
40172@@ -169,7 +169,7 @@ struct sht15_data {
40173 int supply_uv;
40174 bool supply_uv_valid;
40175 struct work_struct update_supply_work;
40176- atomic_t interrupt_handled;
40177+ atomic_unchecked_t interrupt_handled;
40178 };
40179
40180 /**
40181@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
40182 ret = gpio_direction_input(data->pdata->gpio_data);
40183 if (ret)
40184 return ret;
40185- atomic_set(&data->interrupt_handled, 0);
40186+ atomic_set_unchecked(&data->interrupt_handled, 0);
40187
40188 enable_irq(gpio_to_irq(data->pdata->gpio_data));
40189 if (gpio_get_value(data->pdata->gpio_data) == 0) {
40190 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
40191 /* Only relevant if the interrupt hasn't occurred. */
40192- if (!atomic_read(&data->interrupt_handled))
40193+ if (!atomic_read_unchecked(&data->interrupt_handled))
40194 schedule_work(&data->read_work);
40195 }
40196 ret = wait_event_timeout(data->wait_queue,
40197@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
40198
40199 /* First disable the interrupt */
40200 disable_irq_nosync(irq);
40201- atomic_inc(&data->interrupt_handled);
40202+ atomic_inc_unchecked(&data->interrupt_handled);
40203 /* Then schedule a reading work struct */
40204 if (data->state != SHT15_READING_NOTHING)
40205 schedule_work(&data->read_work);
40206@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
40207 * If not, then start the interrupt again - care here as could
40208 * have gone low in meantime so verify it hasn't!
40209 */
40210- atomic_set(&data->interrupt_handled, 0);
40211+ atomic_set_unchecked(&data->interrupt_handled, 0);
40212 enable_irq(gpio_to_irq(data->pdata->gpio_data));
40213 /* If still not occurred or another handler was scheduled */
40214 if (gpio_get_value(data->pdata->gpio_data)
40215- || atomic_read(&data->interrupt_handled))
40216+ || atomic_read_unchecked(&data->interrupt_handled))
40217 return;
40218 }
40219
40220diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
40221index 38944e9..ae9e5ed 100644
40222--- a/drivers/hwmon/via-cputemp.c
40223+++ b/drivers/hwmon/via-cputemp.c
40224@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
40225 return NOTIFY_OK;
40226 }
40227
40228-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
40229+static struct notifier_block via_cputemp_cpu_notifier = {
40230 .notifier_call = via_cputemp_cpu_callback,
40231 };
40232
40233diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
40234index 07f01ac..d79ad3d 100644
40235--- a/drivers/i2c/busses/i2c-amd756-s4882.c
40236+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
40237@@ -43,7 +43,7 @@
40238 extern struct i2c_adapter amd756_smbus;
40239
40240 static struct i2c_adapter *s4882_adapter;
40241-static struct i2c_algorithm *s4882_algo;
40242+static i2c_algorithm_no_const *s4882_algo;
40243
40244 /* Wrapper access functions for multiplexed SMBus */
40245 static DEFINE_MUTEX(amd756_lock);
40246diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
40247index 2ca268d..c6acbdf 100644
40248--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
40249+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
40250@@ -41,7 +41,7 @@
40251 extern struct i2c_adapter *nforce2_smbus;
40252
40253 static struct i2c_adapter *s4985_adapter;
40254-static struct i2c_algorithm *s4985_algo;
40255+static i2c_algorithm_no_const *s4985_algo;
40256
40257 /* Wrapper access functions for multiplexed SMBus */
40258 static DEFINE_MUTEX(nforce2_lock);
40259diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
40260index c3ccdea..5b3dc1a 100644
40261--- a/drivers/i2c/i2c-dev.c
40262+++ b/drivers/i2c/i2c-dev.c
40263@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
40264 break;
40265 }
40266
40267- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
40268+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
40269 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
40270 if (IS_ERR(rdwr_pa[i].buf)) {
40271 res = PTR_ERR(rdwr_pa[i].buf);
40272diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
40273index 0b510ba..4fbb5085 100644
40274--- a/drivers/ide/ide-cd.c
40275+++ b/drivers/ide/ide-cd.c
40276@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
40277 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
40278 if ((unsigned long)buf & alignment
40279 || blk_rq_bytes(rq) & q->dma_pad_mask
40280- || object_is_on_stack(buf))
40281+ || object_starts_on_stack(buf))
40282 drive->dma = 0;
40283 }
40284 }
40285diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
40286index e145931..08bfc59 100644
40287--- a/drivers/iio/industrialio-core.c
40288+++ b/drivers/iio/industrialio-core.c
40289@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
40290 }
40291
40292 static
40293-int __iio_device_attr_init(struct device_attribute *dev_attr,
40294+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
40295 const char *postfix,
40296 struct iio_chan_spec const *chan,
40297 ssize_t (*readfunc)(struct device *dev,
40298diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
40299index 784b97c..c9ceadf 100644
40300--- a/drivers/infiniband/core/cm.c
40301+++ b/drivers/infiniband/core/cm.c
40302@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
40303
40304 struct cm_counter_group {
40305 struct kobject obj;
40306- atomic_long_t counter[CM_ATTR_COUNT];
40307+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
40308 };
40309
40310 struct cm_counter_attribute {
40311@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
40312 struct ib_mad_send_buf *msg = NULL;
40313 int ret;
40314
40315- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40316+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40317 counter[CM_REQ_COUNTER]);
40318
40319 /* Quick state check to discard duplicate REQs. */
40320@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
40321 if (!cm_id_priv)
40322 return;
40323
40324- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40325+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40326 counter[CM_REP_COUNTER]);
40327 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
40328 if (ret)
40329@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
40330 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
40331 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
40332 spin_unlock_irq(&cm_id_priv->lock);
40333- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40334+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40335 counter[CM_RTU_COUNTER]);
40336 goto out;
40337 }
40338@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
40339 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
40340 dreq_msg->local_comm_id);
40341 if (!cm_id_priv) {
40342- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40343+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40344 counter[CM_DREQ_COUNTER]);
40345 cm_issue_drep(work->port, work->mad_recv_wc);
40346 return -EINVAL;
40347@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
40348 case IB_CM_MRA_REP_RCVD:
40349 break;
40350 case IB_CM_TIMEWAIT:
40351- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40352+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40353 counter[CM_DREQ_COUNTER]);
40354 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40355 goto unlock;
40356@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
40357 cm_free_msg(msg);
40358 goto deref;
40359 case IB_CM_DREQ_RCVD:
40360- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40361+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40362 counter[CM_DREQ_COUNTER]);
40363 goto unlock;
40364 default:
40365@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
40366 ib_modify_mad(cm_id_priv->av.port->mad_agent,
40367 cm_id_priv->msg, timeout)) {
40368 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
40369- atomic_long_inc(&work->port->
40370+ atomic_long_inc_unchecked(&work->port->
40371 counter_group[CM_RECV_DUPLICATES].
40372 counter[CM_MRA_COUNTER]);
40373 goto out;
40374@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
40375 break;
40376 case IB_CM_MRA_REQ_RCVD:
40377 case IB_CM_MRA_REP_RCVD:
40378- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40379+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40380 counter[CM_MRA_COUNTER]);
40381 /* fall through */
40382 default:
40383@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
40384 case IB_CM_LAP_IDLE:
40385 break;
40386 case IB_CM_MRA_LAP_SENT:
40387- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40388+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40389 counter[CM_LAP_COUNTER]);
40390 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40391 goto unlock;
40392@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
40393 cm_free_msg(msg);
40394 goto deref;
40395 case IB_CM_LAP_RCVD:
40396- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40397+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40398 counter[CM_LAP_COUNTER]);
40399 goto unlock;
40400 default:
40401@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
40402 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
40403 if (cur_cm_id_priv) {
40404 spin_unlock_irq(&cm.lock);
40405- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40406+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40407 counter[CM_SIDR_REQ_COUNTER]);
40408 goto out; /* Duplicate message. */
40409 }
40410@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
40411 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
40412 msg->retries = 1;
40413
40414- atomic_long_add(1 + msg->retries,
40415+ atomic_long_add_unchecked(1 + msg->retries,
40416 &port->counter_group[CM_XMIT].counter[attr_index]);
40417 if (msg->retries)
40418- atomic_long_add(msg->retries,
40419+ atomic_long_add_unchecked(msg->retries,
40420 &port->counter_group[CM_XMIT_RETRIES].
40421 counter[attr_index]);
40422
40423@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
40424 }
40425
40426 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
40427- atomic_long_inc(&port->counter_group[CM_RECV].
40428+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
40429 counter[attr_id - CM_ATTR_ID_OFFSET]);
40430
40431 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
40432@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
40433 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
40434
40435 return sprintf(buf, "%ld\n",
40436- atomic_long_read(&group->counter[cm_attr->index]));
40437+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
40438 }
40439
40440 static const struct sysfs_ops cm_counter_ops = {
40441diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
40442index 9f5ad7c..588cd84 100644
40443--- a/drivers/infiniband/core/fmr_pool.c
40444+++ b/drivers/infiniband/core/fmr_pool.c
40445@@ -98,8 +98,8 @@ struct ib_fmr_pool {
40446
40447 struct task_struct *thread;
40448
40449- atomic_t req_ser;
40450- atomic_t flush_ser;
40451+ atomic_unchecked_t req_ser;
40452+ atomic_unchecked_t flush_ser;
40453
40454 wait_queue_head_t force_wait;
40455 };
40456@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40457 struct ib_fmr_pool *pool = pool_ptr;
40458
40459 do {
40460- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
40461+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
40462 ib_fmr_batch_release(pool);
40463
40464- atomic_inc(&pool->flush_ser);
40465+ atomic_inc_unchecked(&pool->flush_ser);
40466 wake_up_interruptible(&pool->force_wait);
40467
40468 if (pool->flush_function)
40469@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40470 }
40471
40472 set_current_state(TASK_INTERRUPTIBLE);
40473- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
40474+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
40475 !kthread_should_stop())
40476 schedule();
40477 __set_current_state(TASK_RUNNING);
40478@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
40479 pool->dirty_watermark = params->dirty_watermark;
40480 pool->dirty_len = 0;
40481 spin_lock_init(&pool->pool_lock);
40482- atomic_set(&pool->req_ser, 0);
40483- atomic_set(&pool->flush_ser, 0);
40484+ atomic_set_unchecked(&pool->req_ser, 0);
40485+ atomic_set_unchecked(&pool->flush_ser, 0);
40486 init_waitqueue_head(&pool->force_wait);
40487
40488 pool->thread = kthread_run(ib_fmr_cleanup_thread,
40489@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
40490 }
40491 spin_unlock_irq(&pool->pool_lock);
40492
40493- serial = atomic_inc_return(&pool->req_ser);
40494+ serial = atomic_inc_return_unchecked(&pool->req_ser);
40495 wake_up_process(pool->thread);
40496
40497 if (wait_event_interruptible(pool->force_wait,
40498- atomic_read(&pool->flush_ser) - serial >= 0))
40499+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
40500 return -EINTR;
40501
40502 return 0;
40503@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
40504 } else {
40505 list_add_tail(&fmr->list, &pool->dirty_list);
40506 if (++pool->dirty_len >= pool->dirty_watermark) {
40507- atomic_inc(&pool->req_ser);
40508+ atomic_inc_unchecked(&pool->req_ser);
40509 wake_up_process(pool->thread);
40510 }
40511 }
40512diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
40513index 4cb8eb2..146bf60 100644
40514--- a/drivers/infiniband/hw/cxgb4/mem.c
40515+++ b/drivers/infiniband/hw/cxgb4/mem.c
40516@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40517 int err;
40518 struct fw_ri_tpte tpt;
40519 u32 stag_idx;
40520- static atomic_t key;
40521+ static atomic_unchecked_t key;
40522
40523 if (c4iw_fatal_error(rdev))
40524 return -EIO;
40525@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40526 if (rdev->stats.stag.cur > rdev->stats.stag.max)
40527 rdev->stats.stag.max = rdev->stats.stag.cur;
40528 mutex_unlock(&rdev->stats.lock);
40529- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
40530+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
40531 }
40532 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
40533 __func__, stag_state, type, pdid, stag_idx);
40534diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
40535index 79b3dbc..96e5fcc 100644
40536--- a/drivers/infiniband/hw/ipath/ipath_rc.c
40537+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
40538@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40539 struct ib_atomic_eth *ateth;
40540 struct ipath_ack_entry *e;
40541 u64 vaddr;
40542- atomic64_t *maddr;
40543+ atomic64_unchecked_t *maddr;
40544 u64 sdata;
40545 u32 rkey;
40546 u8 next;
40547@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40548 IB_ACCESS_REMOTE_ATOMIC)))
40549 goto nack_acc_unlck;
40550 /* Perform atomic OP and save result. */
40551- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40552+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40553 sdata = be64_to_cpu(ateth->swap_data);
40554 e = &qp->s_ack_queue[qp->r_head_ack_queue];
40555 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
40556- (u64) atomic64_add_return(sdata, maddr) - sdata :
40557+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40558 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40559 be64_to_cpu(ateth->compare_data),
40560 sdata);
40561diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
40562index 1f95bba..9530f87 100644
40563--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
40564+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
40565@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
40566 unsigned long flags;
40567 struct ib_wc wc;
40568 u64 sdata;
40569- atomic64_t *maddr;
40570+ atomic64_unchecked_t *maddr;
40571 enum ib_wc_status send_status;
40572
40573 /*
40574@@ -382,11 +382,11 @@ again:
40575 IB_ACCESS_REMOTE_ATOMIC)))
40576 goto acc_err;
40577 /* Perform atomic OP and save result. */
40578- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40579+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40580 sdata = wqe->wr.wr.atomic.compare_add;
40581 *(u64 *) sqp->s_sge.sge.vaddr =
40582 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
40583- (u64) atomic64_add_return(sdata, maddr) - sdata :
40584+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40585 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40586 sdata, wqe->wr.wr.atomic.swap);
40587 goto send_comp;
40588diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
40589index f2a3f48..673ec79 100644
40590--- a/drivers/infiniband/hw/mlx4/mad.c
40591+++ b/drivers/infiniband/hw/mlx4/mad.c
40592@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
40593
40594 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
40595 {
40596- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
40597+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
40598 cpu_to_be64(0xff00000000000000LL);
40599 }
40600
40601diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
40602index 25b2cdf..099ff97 100644
40603--- a/drivers/infiniband/hw/mlx4/mcg.c
40604+++ b/drivers/infiniband/hw/mlx4/mcg.c
40605@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
40606 {
40607 char name[20];
40608
40609- atomic_set(&ctx->tid, 0);
40610+ atomic_set_unchecked(&ctx->tid, 0);
40611 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
40612 ctx->mcg_wq = create_singlethread_workqueue(name);
40613 if (!ctx->mcg_wq)
40614diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40615index f61ec26..ebf72cf 100644
40616--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
40617+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40618@@ -398,7 +398,7 @@ struct mlx4_ib_demux_ctx {
40619 struct list_head mcg_mgid0_list;
40620 struct workqueue_struct *mcg_wq;
40621 struct mlx4_ib_demux_pv_ctx **tun;
40622- atomic_t tid;
40623+ atomic_unchecked_t tid;
40624 int flushing; /* flushing the work queue */
40625 };
40626
40627diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
40628index 9d3e5c1..d9afe4a 100644
40629--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
40630+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
40631@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
40632 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
40633 }
40634
40635-int mthca_QUERY_FW(struct mthca_dev *dev)
40636+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
40637 {
40638 struct mthca_mailbox *mailbox;
40639 u32 *outbox;
40640diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
40641index ed9a989..e0c5871 100644
40642--- a/drivers/infiniband/hw/mthca/mthca_mr.c
40643+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
40644@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
40645 return key;
40646 }
40647
40648-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40649+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40650 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
40651 {
40652 struct mthca_mailbox *mailbox;
40653diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
40654index 4291410..d2ab1fb 100644
40655--- a/drivers/infiniband/hw/nes/nes.c
40656+++ b/drivers/infiniband/hw/nes/nes.c
40657@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
40658 LIST_HEAD(nes_adapter_list);
40659 static LIST_HEAD(nes_dev_list);
40660
40661-atomic_t qps_destroyed;
40662+atomic_unchecked_t qps_destroyed;
40663
40664 static unsigned int ee_flsh_adapter;
40665 static unsigned int sysfs_nonidx_addr;
40666@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
40667 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
40668 struct nes_adapter *nesadapter = nesdev->nesadapter;
40669
40670- atomic_inc(&qps_destroyed);
40671+ atomic_inc_unchecked(&qps_destroyed);
40672
40673 /* Free the control structures */
40674
40675diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
40676index 33cc589..3bd6538 100644
40677--- a/drivers/infiniband/hw/nes/nes.h
40678+++ b/drivers/infiniband/hw/nes/nes.h
40679@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
40680 extern unsigned int wqm_quanta;
40681 extern struct list_head nes_adapter_list;
40682
40683-extern atomic_t cm_connects;
40684-extern atomic_t cm_accepts;
40685-extern atomic_t cm_disconnects;
40686-extern atomic_t cm_closes;
40687-extern atomic_t cm_connecteds;
40688-extern atomic_t cm_connect_reqs;
40689-extern atomic_t cm_rejects;
40690-extern atomic_t mod_qp_timouts;
40691-extern atomic_t qps_created;
40692-extern atomic_t qps_destroyed;
40693-extern atomic_t sw_qps_destroyed;
40694+extern atomic_unchecked_t cm_connects;
40695+extern atomic_unchecked_t cm_accepts;
40696+extern atomic_unchecked_t cm_disconnects;
40697+extern atomic_unchecked_t cm_closes;
40698+extern atomic_unchecked_t cm_connecteds;
40699+extern atomic_unchecked_t cm_connect_reqs;
40700+extern atomic_unchecked_t cm_rejects;
40701+extern atomic_unchecked_t mod_qp_timouts;
40702+extern atomic_unchecked_t qps_created;
40703+extern atomic_unchecked_t qps_destroyed;
40704+extern atomic_unchecked_t sw_qps_destroyed;
40705 extern u32 mh_detected;
40706 extern u32 mh_pauses_sent;
40707 extern u32 cm_packets_sent;
40708@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
40709 extern u32 cm_packets_received;
40710 extern u32 cm_packets_dropped;
40711 extern u32 cm_packets_retrans;
40712-extern atomic_t cm_listens_created;
40713-extern atomic_t cm_listens_destroyed;
40714+extern atomic_unchecked_t cm_listens_created;
40715+extern atomic_unchecked_t cm_listens_destroyed;
40716 extern u32 cm_backlog_drops;
40717-extern atomic_t cm_loopbacks;
40718-extern atomic_t cm_nodes_created;
40719-extern atomic_t cm_nodes_destroyed;
40720-extern atomic_t cm_accel_dropped_pkts;
40721-extern atomic_t cm_resets_recvd;
40722-extern atomic_t pau_qps_created;
40723-extern atomic_t pau_qps_destroyed;
40724+extern atomic_unchecked_t cm_loopbacks;
40725+extern atomic_unchecked_t cm_nodes_created;
40726+extern atomic_unchecked_t cm_nodes_destroyed;
40727+extern atomic_unchecked_t cm_accel_dropped_pkts;
40728+extern atomic_unchecked_t cm_resets_recvd;
40729+extern atomic_unchecked_t pau_qps_created;
40730+extern atomic_unchecked_t pau_qps_destroyed;
40731
40732 extern u32 int_mod_timer_init;
40733 extern u32 int_mod_cq_depth_256;
40734diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
40735index 24b9f1a..00fd004 100644
40736--- a/drivers/infiniband/hw/nes/nes_cm.c
40737+++ b/drivers/infiniband/hw/nes/nes_cm.c
40738@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
40739 u32 cm_packets_retrans;
40740 u32 cm_packets_created;
40741 u32 cm_packets_received;
40742-atomic_t cm_listens_created;
40743-atomic_t cm_listens_destroyed;
40744+atomic_unchecked_t cm_listens_created;
40745+atomic_unchecked_t cm_listens_destroyed;
40746 u32 cm_backlog_drops;
40747-atomic_t cm_loopbacks;
40748-atomic_t cm_nodes_created;
40749-atomic_t cm_nodes_destroyed;
40750-atomic_t cm_accel_dropped_pkts;
40751-atomic_t cm_resets_recvd;
40752+atomic_unchecked_t cm_loopbacks;
40753+atomic_unchecked_t cm_nodes_created;
40754+atomic_unchecked_t cm_nodes_destroyed;
40755+atomic_unchecked_t cm_accel_dropped_pkts;
40756+atomic_unchecked_t cm_resets_recvd;
40757
40758 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
40759 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
40760@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
40761
40762 static struct nes_cm_core *g_cm_core;
40763
40764-atomic_t cm_connects;
40765-atomic_t cm_accepts;
40766-atomic_t cm_disconnects;
40767-atomic_t cm_closes;
40768-atomic_t cm_connecteds;
40769-atomic_t cm_connect_reqs;
40770-atomic_t cm_rejects;
40771+atomic_unchecked_t cm_connects;
40772+atomic_unchecked_t cm_accepts;
40773+atomic_unchecked_t cm_disconnects;
40774+atomic_unchecked_t cm_closes;
40775+atomic_unchecked_t cm_connecteds;
40776+atomic_unchecked_t cm_connect_reqs;
40777+atomic_unchecked_t cm_rejects;
40778
40779 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
40780 {
40781@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
40782 kfree(listener);
40783 listener = NULL;
40784 ret = 0;
40785- atomic_inc(&cm_listens_destroyed);
40786+ atomic_inc_unchecked(&cm_listens_destroyed);
40787 } else {
40788 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
40789 }
40790@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
40791 cm_node->rem_mac);
40792
40793 add_hte_node(cm_core, cm_node);
40794- atomic_inc(&cm_nodes_created);
40795+ atomic_inc_unchecked(&cm_nodes_created);
40796
40797 return cm_node;
40798 }
40799@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
40800 }
40801
40802 atomic_dec(&cm_core->node_cnt);
40803- atomic_inc(&cm_nodes_destroyed);
40804+ atomic_inc_unchecked(&cm_nodes_destroyed);
40805 nesqp = cm_node->nesqp;
40806 if (nesqp) {
40807 nesqp->cm_node = NULL;
40808@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
40809
40810 static void drop_packet(struct sk_buff *skb)
40811 {
40812- atomic_inc(&cm_accel_dropped_pkts);
40813+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40814 dev_kfree_skb_any(skb);
40815 }
40816
40817@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
40818 {
40819
40820 int reset = 0; /* whether to send reset in case of err.. */
40821- atomic_inc(&cm_resets_recvd);
40822+ atomic_inc_unchecked(&cm_resets_recvd);
40823 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
40824 " refcnt=%d\n", cm_node, cm_node->state,
40825 atomic_read(&cm_node->ref_count));
40826@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
40827 rem_ref_cm_node(cm_node->cm_core, cm_node);
40828 return NULL;
40829 }
40830- atomic_inc(&cm_loopbacks);
40831+ atomic_inc_unchecked(&cm_loopbacks);
40832 loopbackremotenode->loopbackpartner = cm_node;
40833 loopbackremotenode->tcp_cntxt.rcv_wscale =
40834 NES_CM_DEFAULT_RCV_WND_SCALE;
40835@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
40836 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
40837 else {
40838 rem_ref_cm_node(cm_core, cm_node);
40839- atomic_inc(&cm_accel_dropped_pkts);
40840+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40841 dev_kfree_skb_any(skb);
40842 }
40843 break;
40844@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40845
40846 if ((cm_id) && (cm_id->event_handler)) {
40847 if (issue_disconn) {
40848- atomic_inc(&cm_disconnects);
40849+ atomic_inc_unchecked(&cm_disconnects);
40850 cm_event.event = IW_CM_EVENT_DISCONNECT;
40851 cm_event.status = disconn_status;
40852 cm_event.local_addr = cm_id->local_addr;
40853@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40854 }
40855
40856 if (issue_close) {
40857- atomic_inc(&cm_closes);
40858+ atomic_inc_unchecked(&cm_closes);
40859 nes_disconnect(nesqp, 1);
40860
40861 cm_id->provider_data = nesqp;
40862@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40863
40864 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
40865 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
40866- atomic_inc(&cm_accepts);
40867+ atomic_inc_unchecked(&cm_accepts);
40868
40869 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
40870 netdev_refcnt_read(nesvnic->netdev));
40871@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
40872 struct nes_cm_core *cm_core;
40873 u8 *start_buff;
40874
40875- atomic_inc(&cm_rejects);
40876+ atomic_inc_unchecked(&cm_rejects);
40877 cm_node = (struct nes_cm_node *)cm_id->provider_data;
40878 loopback = cm_node->loopbackpartner;
40879 cm_core = cm_node->cm_core;
40880@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40881 ntohl(cm_id->local_addr.sin_addr.s_addr),
40882 ntohs(cm_id->local_addr.sin_port));
40883
40884- atomic_inc(&cm_connects);
40885+ atomic_inc_unchecked(&cm_connects);
40886 nesqp->active_conn = 1;
40887
40888 /* cache the cm_id in the qp */
40889@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
40890 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
40891 return err;
40892 }
40893- atomic_inc(&cm_listens_created);
40894+ atomic_inc_unchecked(&cm_listens_created);
40895 }
40896
40897 cm_id->add_ref(cm_id);
40898@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
40899
40900 if (nesqp->destroyed)
40901 return;
40902- atomic_inc(&cm_connecteds);
40903+ atomic_inc_unchecked(&cm_connecteds);
40904 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
40905 " local port 0x%04X. jiffies = %lu.\n",
40906 nesqp->hwqp.qp_id,
40907@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
40908
40909 cm_id->add_ref(cm_id);
40910 ret = cm_id->event_handler(cm_id, &cm_event);
40911- atomic_inc(&cm_closes);
40912+ atomic_inc_unchecked(&cm_closes);
40913 cm_event.event = IW_CM_EVENT_CLOSE;
40914 cm_event.status = 0;
40915 cm_event.provider_data = cm_id->provider_data;
40916@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
40917 return;
40918 cm_id = cm_node->cm_id;
40919
40920- atomic_inc(&cm_connect_reqs);
40921+ atomic_inc_unchecked(&cm_connect_reqs);
40922 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
40923 cm_node, cm_id, jiffies);
40924
40925@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
40926 return;
40927 cm_id = cm_node->cm_id;
40928
40929- atomic_inc(&cm_connect_reqs);
40930+ atomic_inc_unchecked(&cm_connect_reqs);
40931 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
40932 cm_node, cm_id, jiffies);
40933
40934diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
40935index 4166452..fc952c3 100644
40936--- a/drivers/infiniband/hw/nes/nes_mgt.c
40937+++ b/drivers/infiniband/hw/nes/nes_mgt.c
40938@@ -40,8 +40,8 @@
40939 #include "nes.h"
40940 #include "nes_mgt.h"
40941
40942-atomic_t pau_qps_created;
40943-atomic_t pau_qps_destroyed;
40944+atomic_unchecked_t pau_qps_created;
40945+atomic_unchecked_t pau_qps_destroyed;
40946
40947 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
40948 {
40949@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
40950 {
40951 struct sk_buff *skb;
40952 unsigned long flags;
40953- atomic_inc(&pau_qps_destroyed);
40954+ atomic_inc_unchecked(&pau_qps_destroyed);
40955
40956 /* Free packets that have not yet been forwarded */
40957 /* Lock is acquired by skb_dequeue when removing the skb */
40958@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
40959 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
40960 skb_queue_head_init(&nesqp->pau_list);
40961 spin_lock_init(&nesqp->pau_lock);
40962- atomic_inc(&pau_qps_created);
40963+ atomic_inc_unchecked(&pau_qps_created);
40964 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
40965 }
40966
40967diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
40968index 49eb511..a774366 100644
40969--- a/drivers/infiniband/hw/nes/nes_nic.c
40970+++ b/drivers/infiniband/hw/nes/nes_nic.c
40971@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
40972 target_stat_values[++index] = mh_detected;
40973 target_stat_values[++index] = mh_pauses_sent;
40974 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
40975- target_stat_values[++index] = atomic_read(&cm_connects);
40976- target_stat_values[++index] = atomic_read(&cm_accepts);
40977- target_stat_values[++index] = atomic_read(&cm_disconnects);
40978- target_stat_values[++index] = atomic_read(&cm_connecteds);
40979- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
40980- target_stat_values[++index] = atomic_read(&cm_rejects);
40981- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
40982- target_stat_values[++index] = atomic_read(&qps_created);
40983- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
40984- target_stat_values[++index] = atomic_read(&qps_destroyed);
40985- target_stat_values[++index] = atomic_read(&cm_closes);
40986+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
40987+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
40988+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
40989+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
40990+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
40991+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
40992+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
40993+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
40994+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
40995+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
40996+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
40997 target_stat_values[++index] = cm_packets_sent;
40998 target_stat_values[++index] = cm_packets_bounced;
40999 target_stat_values[++index] = cm_packets_created;
41000 target_stat_values[++index] = cm_packets_received;
41001 target_stat_values[++index] = cm_packets_dropped;
41002 target_stat_values[++index] = cm_packets_retrans;
41003- target_stat_values[++index] = atomic_read(&cm_listens_created);
41004- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
41005+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
41006+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
41007 target_stat_values[++index] = cm_backlog_drops;
41008- target_stat_values[++index] = atomic_read(&cm_loopbacks);
41009- target_stat_values[++index] = atomic_read(&cm_nodes_created);
41010- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
41011- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
41012- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
41013+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
41014+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
41015+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
41016+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
41017+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
41018 target_stat_values[++index] = nesadapter->free_4kpbl;
41019 target_stat_values[++index] = nesadapter->free_256pbl;
41020 target_stat_values[++index] = int_mod_timer_init;
41021 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
41022 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
41023 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
41024- target_stat_values[++index] = atomic_read(&pau_qps_created);
41025- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
41026+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
41027+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
41028 }
41029
41030 /**
41031diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
41032index 5b53ca5..443da3c 100644
41033--- a/drivers/infiniband/hw/nes/nes_verbs.c
41034+++ b/drivers/infiniband/hw/nes/nes_verbs.c
41035@@ -46,9 +46,9 @@
41036
41037 #include <rdma/ib_umem.h>
41038
41039-atomic_t mod_qp_timouts;
41040-atomic_t qps_created;
41041-atomic_t sw_qps_destroyed;
41042+atomic_unchecked_t mod_qp_timouts;
41043+atomic_unchecked_t qps_created;
41044+atomic_unchecked_t sw_qps_destroyed;
41045
41046 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
41047
41048@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
41049 if (init_attr->create_flags)
41050 return ERR_PTR(-EINVAL);
41051
41052- atomic_inc(&qps_created);
41053+ atomic_inc_unchecked(&qps_created);
41054 switch (init_attr->qp_type) {
41055 case IB_QPT_RC:
41056 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
41057@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
41058 struct iw_cm_event cm_event;
41059 int ret = 0;
41060
41061- atomic_inc(&sw_qps_destroyed);
41062+ atomic_inc_unchecked(&sw_qps_destroyed);
41063 nesqp->destroyed = 1;
41064
41065 /* Blow away the connection if it exists. */
41066diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
41067index 4a9af79..b993f75 100644
41068--- a/drivers/infiniband/hw/qib/qib.h
41069+++ b/drivers/infiniband/hw/qib/qib.h
41070@@ -52,6 +52,7 @@
41071 #include <linux/kref.h>
41072 #include <linux/sched.h>
41073 #include <linux/kthread.h>
41074+#include <linux/slab.h>
41075
41076 #include "qib_common.h"
41077 #include "qib_verbs.h"
41078diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
41079index da739d9..da1c7f4 100644
41080--- a/drivers/input/gameport/gameport.c
41081+++ b/drivers/input/gameport/gameport.c
41082@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
41083 */
41084 static void gameport_init_port(struct gameport *gameport)
41085 {
41086- static atomic_t gameport_no = ATOMIC_INIT(0);
41087+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
41088
41089 __module_get(THIS_MODULE);
41090
41091 mutex_init(&gameport->drv_mutex);
41092 device_initialize(&gameport->dev);
41093 dev_set_name(&gameport->dev, "gameport%lu",
41094- (unsigned long)atomic_inc_return(&gameport_no) - 1);
41095+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
41096 gameport->dev.bus = &gameport_bus;
41097 gameport->dev.release = gameport_release_port;
41098 if (gameport->parent)
41099diff --git a/drivers/input/input.c b/drivers/input/input.c
41100index c044699..174d71a 100644
41101--- a/drivers/input/input.c
41102+++ b/drivers/input/input.c
41103@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
41104 */
41105 int input_register_device(struct input_dev *dev)
41106 {
41107- static atomic_t input_no = ATOMIC_INIT(0);
41108+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
41109 struct input_devres *devres = NULL;
41110 struct input_handler *handler;
41111 unsigned int packet_size;
41112@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
41113 dev->setkeycode = input_default_setkeycode;
41114
41115 dev_set_name(&dev->dev, "input%ld",
41116- (unsigned long) atomic_inc_return(&input_no) - 1);
41117+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
41118
41119 error = device_add(&dev->dev);
41120 if (error)
41121diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
41122index 04c69af..5f92d00 100644
41123--- a/drivers/input/joystick/sidewinder.c
41124+++ b/drivers/input/joystick/sidewinder.c
41125@@ -30,6 +30,7 @@
41126 #include <linux/kernel.h>
41127 #include <linux/module.h>
41128 #include <linux/slab.h>
41129+#include <linux/sched.h>
41130 #include <linux/init.h>
41131 #include <linux/input.h>
41132 #include <linux/gameport.h>
41133diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
41134index 75e3b10..fb390fd 100644
41135--- a/drivers/input/joystick/xpad.c
41136+++ b/drivers/input/joystick/xpad.c
41137@@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
41138
41139 static int xpad_led_probe(struct usb_xpad *xpad)
41140 {
41141- static atomic_t led_seq = ATOMIC_INIT(0);
41142+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
41143 long led_no;
41144 struct xpad_led *led;
41145 struct led_classdev *led_cdev;
41146@@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
41147 if (!led)
41148 return -ENOMEM;
41149
41150- led_no = (long)atomic_inc_return(&led_seq) - 1;
41151+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
41152
41153 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
41154 led->xpad = xpad;
41155diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
41156index e204f26..8459f15 100644
41157--- a/drivers/input/misc/ims-pcu.c
41158+++ b/drivers/input/misc/ims-pcu.c
41159@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
41160
41161 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
41162 {
41163- static atomic_t device_no = ATOMIC_INIT(0);
41164+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
41165
41166 const struct ims_pcu_device_info *info;
41167 u8 device_id;
41168@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
41169 }
41170
41171 /* Device appears to be operable, complete initialization */
41172- pcu->device_no = atomic_inc_return(&device_no) - 1;
41173+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
41174
41175 error = ims_pcu_setup_backlight(pcu);
41176 if (error)
41177diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
41178index 2f0b39d..7370f13 100644
41179--- a/drivers/input/mouse/psmouse.h
41180+++ b/drivers/input/mouse/psmouse.h
41181@@ -116,7 +116,7 @@ struct psmouse_attribute {
41182 ssize_t (*set)(struct psmouse *psmouse, void *data,
41183 const char *buf, size_t count);
41184 bool protect;
41185-};
41186+} __do_const;
41187 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
41188
41189 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
41190diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
41191index 4c842c3..590b0bf 100644
41192--- a/drivers/input/mousedev.c
41193+++ b/drivers/input/mousedev.c
41194@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
41195
41196 spin_unlock_irq(&client->packet_lock);
41197
41198- if (copy_to_user(buffer, data, count))
41199+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
41200 return -EFAULT;
41201
41202 return count;
41203diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
41204index 25fc597..558bf3b3 100644
41205--- a/drivers/input/serio/serio.c
41206+++ b/drivers/input/serio/serio.c
41207@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
41208 */
41209 static void serio_init_port(struct serio *serio)
41210 {
41211- static atomic_t serio_no = ATOMIC_INIT(0);
41212+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
41213
41214 __module_get(THIS_MODULE);
41215
41216@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
41217 mutex_init(&serio->drv_mutex);
41218 device_initialize(&serio->dev);
41219 dev_set_name(&serio->dev, "serio%ld",
41220- (long)atomic_inc_return(&serio_no) - 1);
41221+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
41222 serio->dev.bus = &serio_bus;
41223 serio->dev.release = serio_release_port;
41224 serio->dev.groups = serio_device_attr_groups;
41225diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
41226index 59df2e7..8f1cafb 100644
41227--- a/drivers/input/serio/serio_raw.c
41228+++ b/drivers/input/serio/serio_raw.c
41229@@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
41230
41231 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41232 {
41233- static atomic_t serio_raw_no = ATOMIC_INIT(0);
41234+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
41235 struct serio_raw *serio_raw;
41236 int err;
41237
41238@@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41239 }
41240
41241 snprintf(serio_raw->name, sizeof(serio_raw->name),
41242- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
41243+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
41244 kref_init(&serio_raw->kref);
41245 INIT_LIST_HEAD(&serio_raw->client_list);
41246 init_waitqueue_head(&serio_raw->wait);
41247diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
41248index fbe9ca7..dbee61d 100644
41249--- a/drivers/iommu/iommu.c
41250+++ b/drivers/iommu/iommu.c
41251@@ -583,7 +583,7 @@ static struct notifier_block iommu_bus_nb = {
41252 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
41253 {
41254 bus_register_notifier(bus, &iommu_bus_nb);
41255- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
41256+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
41257 }
41258
41259 /**
41260diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
41261index 39f81ae..2660096 100644
41262--- a/drivers/iommu/irq_remapping.c
41263+++ b/drivers/iommu/irq_remapping.c
41264@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
41265 void panic_if_irq_remap(const char *msg)
41266 {
41267 if (irq_remapping_enabled)
41268- panic(msg);
41269+ panic("%s", msg);
41270 }
41271
41272 static void ir_ack_apic_edge(struct irq_data *data)
41273@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
41274
41275 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
41276 {
41277- chip->irq_print_chip = ir_print_prefix;
41278- chip->irq_ack = ir_ack_apic_edge;
41279- chip->irq_eoi = ir_ack_apic_level;
41280- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41281+ pax_open_kernel();
41282+ *(void **)&chip->irq_print_chip = ir_print_prefix;
41283+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
41284+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
41285+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41286+ pax_close_kernel();
41287 }
41288
41289 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
41290diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
41291index ee7c503..5d4ce08 100644
41292--- a/drivers/irqchip/irq-gic.c
41293+++ b/drivers/irqchip/irq-gic.c
41294@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
41295 * Supported arch specific GIC irq extension.
41296 * Default make them NULL.
41297 */
41298-struct irq_chip gic_arch_extn = {
41299+irq_chip_no_const gic_arch_extn = {
41300 .irq_eoi = NULL,
41301 .irq_mask = NULL,
41302 .irq_unmask = NULL,
41303@@ -333,7 +333,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
41304 chained_irq_exit(chip, desc);
41305 }
41306
41307-static struct irq_chip gic_chip = {
41308+static irq_chip_no_const gic_chip __read_only = {
41309 .name = "GIC",
41310 .irq_mask = gic_mask_irq,
41311 .irq_unmask = gic_unmask_irq,
41312diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
41313index ac6f72b..81150f2 100644
41314--- a/drivers/isdn/capi/capi.c
41315+++ b/drivers/isdn/capi/capi.c
41316@@ -81,8 +81,8 @@ struct capiminor {
41317
41318 struct capi20_appl *ap;
41319 u32 ncci;
41320- atomic_t datahandle;
41321- atomic_t msgid;
41322+ atomic_unchecked_t datahandle;
41323+ atomic_unchecked_t msgid;
41324
41325 struct tty_port port;
41326 int ttyinstop;
41327@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
41328 capimsg_setu16(s, 2, mp->ap->applid);
41329 capimsg_setu8 (s, 4, CAPI_DATA_B3);
41330 capimsg_setu8 (s, 5, CAPI_RESP);
41331- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
41332+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
41333 capimsg_setu32(s, 8, mp->ncci);
41334 capimsg_setu16(s, 12, datahandle);
41335 }
41336@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
41337 mp->outbytes -= len;
41338 spin_unlock_bh(&mp->outlock);
41339
41340- datahandle = atomic_inc_return(&mp->datahandle);
41341+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
41342 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
41343 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41344 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41345 capimsg_setu16(skb->data, 2, mp->ap->applid);
41346 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
41347 capimsg_setu8 (skb->data, 5, CAPI_REQ);
41348- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
41349+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
41350 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
41351 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
41352 capimsg_setu16(skb->data, 16, len); /* Data length */
41353diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
41354index 600c79b..3752bab 100644
41355--- a/drivers/isdn/gigaset/interface.c
41356+++ b/drivers/isdn/gigaset/interface.c
41357@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
41358 }
41359 tty->driver_data = cs;
41360
41361- ++cs->port.count;
41362+ atomic_inc(&cs->port.count);
41363
41364- if (cs->port.count == 1) {
41365+ if (atomic_read(&cs->port.count) == 1) {
41366 tty_port_tty_set(&cs->port, tty);
41367 cs->port.low_latency = 1;
41368 }
41369@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
41370
41371 if (!cs->connected)
41372 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
41373- else if (!cs->port.count)
41374+ else if (!atomic_read(&cs->port.count))
41375 dev_warn(cs->dev, "%s: device not opened\n", __func__);
41376- else if (!--cs->port.count)
41377+ else if (!atomic_dec_return(&cs->port.count))
41378 tty_port_tty_set(&cs->port, NULL);
41379
41380 mutex_unlock(&cs->mutex);
41381diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
41382index d0a41cb..f0cdb8c 100644
41383--- a/drivers/isdn/gigaset/usb-gigaset.c
41384+++ b/drivers/isdn/gigaset/usb-gigaset.c
41385@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
41386 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
41387 memcpy(cs->hw.usb->bchars, buf, 6);
41388 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
41389- 0, 0, &buf, 6, 2000);
41390+ 0, 0, buf, 6, 2000);
41391 }
41392
41393 static void gigaset_freebcshw(struct bc_state *bcs)
41394diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
41395index 4d9b195..455075c 100644
41396--- a/drivers/isdn/hardware/avm/b1.c
41397+++ b/drivers/isdn/hardware/avm/b1.c
41398@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
41399 }
41400 if (left) {
41401 if (t4file->user) {
41402- if (copy_from_user(buf, dp, left))
41403+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41404 return -EFAULT;
41405 } else {
41406 memcpy(buf, dp, left);
41407@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
41408 }
41409 if (left) {
41410 if (config->user) {
41411- if (copy_from_user(buf, dp, left))
41412+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41413 return -EFAULT;
41414 } else {
41415 memcpy(buf, dp, left);
41416diff --git a/drivers/isdn/hisax/amd7930_fn.c b/drivers/isdn/hisax/amd7930_fn.c
41417index 1063bab..36817e0 100644
41418--- a/drivers/isdn/hisax/amd7930_fn.c
41419+++ b/drivers/isdn/hisax/amd7930_fn.c
41420@@ -314,7 +314,7 @@ Amd7930_empty_Dfifo(struct IsdnCardState *cs, int flag)
41421
41422 t += sprintf(t, "Amd7930: empty_Dfifo cnt: %d |", cs->rcvidx);
41423 QuickHex(t, cs->rcvbuf, cs->rcvidx);
41424- debugl1(cs, cs->dlog);
41425+ debugl1(cs, "%s", cs->dlog);
41426 }
41427 /* moves received data in sk-buffer */
41428 memcpy(skb_put(skb, cs->rcvidx), cs->rcvbuf, cs->rcvidx);
41429@@ -406,7 +406,7 @@ Amd7930_fill_Dfifo(struct IsdnCardState *cs)
41430
41431 t += sprintf(t, "Amd7930: fill_Dfifo cnt: %d |", count);
41432 QuickHex(t, deb_ptr, count);
41433- debugl1(cs, cs->dlog);
41434+ debugl1(cs, "%s", cs->dlog);
41435 }
41436 /* AMD interrupts on */
41437 AmdIrqOn(cs);
41438diff --git a/drivers/isdn/hisax/avm_pci.c b/drivers/isdn/hisax/avm_pci.c
41439index ee9b9a0..d1427bd 100644
41440--- a/drivers/isdn/hisax/avm_pci.c
41441+++ b/drivers/isdn/hisax/avm_pci.c
41442@@ -285,7 +285,7 @@ hdlc_empty_fifo(struct BCState *bcs, int count)
41443 t += sprintf(t, "hdlc_empty_fifo %c cnt %d",
41444 bcs->channel ? 'B' : 'A', count);
41445 QuickHex(t, p, count);
41446- debugl1(cs, bcs->blog);
41447+ debugl1(cs, "%s", bcs->blog);
41448 }
41449 }
41450
41451@@ -345,7 +345,7 @@ hdlc_fill_fifo(struct BCState *bcs)
41452 t += sprintf(t, "hdlc_fill_fifo %c cnt %d",
41453 bcs->channel ? 'B' : 'A', count);
41454 QuickHex(t, p, count);
41455- debugl1(cs, bcs->blog);
41456+ debugl1(cs, "%s", bcs->blog);
41457 }
41458 }
41459
41460diff --git a/drivers/isdn/hisax/config.c b/drivers/isdn/hisax/config.c
41461index bf04d2a..b33f53b 100644
41462--- a/drivers/isdn/hisax/config.c
41463+++ b/drivers/isdn/hisax/config.c
41464@@ -1896,7 +1896,7 @@ static void EChannel_proc_rcv(struct hisax_d_if *d_if)
41465 ptr--;
41466 *ptr++ = '\n';
41467 *ptr = 0;
41468- HiSax_putstatus(cs, NULL, cs->dlog);
41469+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41470 } else
41471 HiSax_putstatus(cs, "LogEcho: ",
41472 "warning Frame too big (%d)",
41473diff --git a/drivers/isdn/hisax/diva.c b/drivers/isdn/hisax/diva.c
41474index 8d0cf6e..4fc90de 100644
41475--- a/drivers/isdn/hisax/diva.c
41476+++ b/drivers/isdn/hisax/diva.c
41477@@ -427,7 +427,7 @@ Memhscx_empty_fifo(struct BCState *bcs, int count)
41478 t += sprintf(t, "hscx_empty_fifo %c cnt %d",
41479 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41480 QuickHex(t, ptr, count);
41481- debugl1(cs, bcs->blog);
41482+ debugl1(cs, "%s", bcs->blog);
41483 }
41484 }
41485
41486@@ -469,7 +469,7 @@ Memhscx_fill_fifo(struct BCState *bcs)
41487 t += sprintf(t, "hscx_fill_fifo %c cnt %d",
41488 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41489 QuickHex(t, ptr, count);
41490- debugl1(cs, bcs->blog);
41491+ debugl1(cs, "%s", bcs->blog);
41492 }
41493 }
41494
41495diff --git a/drivers/isdn/hisax/elsa.c b/drivers/isdn/hisax/elsa.c
41496index 1df6f9a..2be1c8a 100644
41497--- a/drivers/isdn/hisax/elsa.c
41498+++ b/drivers/isdn/hisax/elsa.c
41499@@ -535,7 +535,7 @@ check_arcofi(struct IsdnCardState *cs)
41500 t = tmp;
41501 t += sprintf(tmp, "Arcofi data");
41502 QuickHex(t, p, cs->dc.isac.mon_rxp);
41503- debugl1(cs, tmp);
41504+ debugl1(cs, "%s", tmp);
41505 if ((cs->dc.isac.mon_rxp == 2) && (cs->dc.isac.mon_rx[0] == 0xa0)) {
41506 switch (cs->dc.isac.mon_rx[1]) {
41507 case 0x80:
41508diff --git a/drivers/isdn/hisax/elsa_ser.c b/drivers/isdn/hisax/elsa_ser.c
41509index d4c98d3..3f84dd8 100644
41510--- a/drivers/isdn/hisax/elsa_ser.c
41511+++ b/drivers/isdn/hisax/elsa_ser.c
41512@@ -344,7 +344,7 @@ static inline void receive_chars(struct IsdnCardState *cs,
41513
41514 t += sprintf(t, "modem read cnt %d", cs->hw.elsa.rcvcnt);
41515 QuickHex(t, cs->hw.elsa.rcvbuf, cs->hw.elsa.rcvcnt);
41516- debugl1(cs, tmp);
41517+ debugl1(cs, "%s", tmp);
41518 }
41519 cs->hw.elsa.rcvcnt = 0;
41520 }
41521diff --git a/drivers/isdn/hisax/hfc_pci.c b/drivers/isdn/hisax/hfc_pci.c
41522index 3ccd724..497bd02 100644
41523--- a/drivers/isdn/hisax/hfc_pci.c
41524+++ b/drivers/isdn/hisax/hfc_pci.c
41525@@ -901,7 +901,7 @@ Begin:
41526 ptr--;
41527 *ptr++ = '\n';
41528 *ptr = 0;
41529- HiSax_putstatus(cs, NULL, cs->dlog);
41530+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41531 } else
41532 HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", total - 3);
41533 }
41534diff --git a/drivers/isdn/hisax/hfc_sx.c b/drivers/isdn/hisax/hfc_sx.c
41535index dc4574f..fa1fefd 100644
41536--- a/drivers/isdn/hisax/hfc_sx.c
41537+++ b/drivers/isdn/hisax/hfc_sx.c
41538@@ -674,7 +674,7 @@ receive_emsg(struct IsdnCardState *cs)
41539 ptr--;
41540 *ptr++ = '\n';
41541 *ptr = 0;
41542- HiSax_putstatus(cs, NULL, cs->dlog);
41543+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41544 } else
41545 HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", skb->len);
41546 }
41547diff --git a/drivers/isdn/hisax/hscx_irq.c b/drivers/isdn/hisax/hscx_irq.c
41548index f398d48..a8d6188 100644
41549--- a/drivers/isdn/hisax/hscx_irq.c
41550+++ b/drivers/isdn/hisax/hscx_irq.c
41551@@ -75,7 +75,7 @@ hscx_empty_fifo(struct BCState *bcs, int count)
41552 t += sprintf(t, "hscx_empty_fifo %c cnt %d",
41553 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41554 QuickHex(t, ptr, count);
41555- debugl1(cs, bcs->blog);
41556+ debugl1(cs, "%s", bcs->blog);
41557 }
41558 }
41559
41560@@ -115,7 +115,7 @@ hscx_fill_fifo(struct BCState *bcs)
41561 t += sprintf(t, "hscx_fill_fifo %c cnt %d",
41562 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41563 QuickHex(t, ptr, count);
41564- debugl1(cs, bcs->blog);
41565+ debugl1(cs, "%s", bcs->blog);
41566 }
41567 }
41568
41569diff --git a/drivers/isdn/hisax/icc.c b/drivers/isdn/hisax/icc.c
41570index db5321f..51dae91 100644
41571--- a/drivers/isdn/hisax/icc.c
41572+++ b/drivers/isdn/hisax/icc.c
41573@@ -134,7 +134,7 @@ icc_empty_fifo(struct IsdnCardState *cs, int count)
41574
41575 t += sprintf(t, "icc_empty_fifo cnt %d", count);
41576 QuickHex(t, ptr, count);
41577- debugl1(cs, cs->dlog);
41578+ debugl1(cs, "%s", cs->dlog);
41579 }
41580 }
41581
41582@@ -176,7 +176,7 @@ icc_fill_fifo(struct IsdnCardState *cs)
41583
41584 t += sprintf(t, "icc_fill_fifo cnt %d", count);
41585 QuickHex(t, ptr, count);
41586- debugl1(cs, cs->dlog);
41587+ debugl1(cs, "%s", cs->dlog);
41588 }
41589 }
41590
41591diff --git a/drivers/isdn/hisax/ipacx.c b/drivers/isdn/hisax/ipacx.c
41592index 74feb5c..5faa5de 100644
41593--- a/drivers/isdn/hisax/ipacx.c
41594+++ b/drivers/isdn/hisax/ipacx.c
41595@@ -260,7 +260,7 @@ dch_empty_fifo(struct IsdnCardState *cs, int count)
41596
41597 t += sprintf(t, "dch_empty_fifo() cnt %d", count);
41598 QuickHex(t, ptr, count);
41599- debugl1(cs, cs->dlog);
41600+ debugl1(cs, "%s", cs->dlog);
41601 }
41602 }
41603
41604@@ -307,7 +307,7 @@ dch_fill_fifo(struct IsdnCardState *cs)
41605
41606 t += sprintf(t, "dch_fill_fifo() cnt %d", count);
41607 QuickHex(t, ptr, count);
41608- debugl1(cs, cs->dlog);
41609+ debugl1(cs, "%s", cs->dlog);
41610 }
41611 }
41612
41613@@ -539,7 +539,7 @@ bch_empty_fifo(struct BCState *bcs, int count)
41614
41615 t += sprintf(t, "bch_empty_fifo() B-%d cnt %d", hscx, count);
41616 QuickHex(t, ptr, count);
41617- debugl1(cs, bcs->blog);
41618+ debugl1(cs, "%s", bcs->blog);
41619 }
41620 }
41621
41622@@ -582,7 +582,7 @@ bch_fill_fifo(struct BCState *bcs)
41623
41624 t += sprintf(t, "chb_fill_fifo() B-%d cnt %d", hscx, count);
41625 QuickHex(t, ptr, count);
41626- debugl1(cs, bcs->blog);
41627+ debugl1(cs, "%s", bcs->blog);
41628 }
41629 }
41630
41631diff --git a/drivers/isdn/hisax/isac.c b/drivers/isdn/hisax/isac.c
41632index a365ccc..7fdf78f 100644
41633--- a/drivers/isdn/hisax/isac.c
41634+++ b/drivers/isdn/hisax/isac.c
41635@@ -137,7 +137,7 @@ isac_empty_fifo(struct IsdnCardState *cs, int count)
41636
41637 t += sprintf(t, "isac_empty_fifo cnt %d", count);
41638 QuickHex(t, ptr, count);
41639- debugl1(cs, cs->dlog);
41640+ debugl1(cs, "%s", cs->dlog);
41641 }
41642 }
41643
41644@@ -179,7 +179,7 @@ isac_fill_fifo(struct IsdnCardState *cs)
41645
41646 t += sprintf(t, "isac_fill_fifo cnt %d", count);
41647 QuickHex(t, ptr, count);
41648- debugl1(cs, cs->dlog);
41649+ debugl1(cs, "%s", cs->dlog);
41650 }
41651 }
41652
41653diff --git a/drivers/isdn/hisax/isar.c b/drivers/isdn/hisax/isar.c
41654index 7fdf347..f4956c7 100644
41655--- a/drivers/isdn/hisax/isar.c
41656+++ b/drivers/isdn/hisax/isar.c
41657@@ -74,7 +74,7 @@ sendmsg(struct IsdnCardState *cs, u_char his, u_char creg, u_char len,
41658 t = tmp;
41659 t += sprintf(t, "sendmbox cnt %d", len);
41660 QuickHex(t, &msg[len-i], (i > 64) ? 64 : i);
41661- debugl1(cs, tmp);
41662+ debugl1(cs, "%s", tmp);
41663 i -= 64;
41664 }
41665 }
41666@@ -105,7 +105,7 @@ rcv_mbox(struct IsdnCardState *cs, struct isar_reg *ireg, u_char *msg)
41667 t = tmp;
41668 t += sprintf(t, "rcv_mbox cnt %d", ireg->clsb);
41669 QuickHex(t, &msg[ireg->clsb - i], (i > 64) ? 64 : i);
41670- debugl1(cs, tmp);
41671+ debugl1(cs, "%s", tmp);
41672 i -= 64;
41673 }
41674 }
41675@@ -1248,7 +1248,7 @@ isar_int_main(struct IsdnCardState *cs)
41676 tp += sprintf(debbuf, "msg iis(%x) msb(%x)",
41677 ireg->iis, ireg->cmsb);
41678 QuickHex(tp, (u_char *)ireg->par, ireg->clsb);
41679- debugl1(cs, debbuf);
41680+ debugl1(cs, "%s", debbuf);
41681 }
41682 break;
41683 case ISAR_IIS_INVMSG:
41684diff --git a/drivers/isdn/hisax/jade.c b/drivers/isdn/hisax/jade.c
41685index f946c58..e2ae787 100644
41686--- a/drivers/isdn/hisax/jade.c
41687+++ b/drivers/isdn/hisax/jade.c
41688@@ -81,10 +81,7 @@ modejade(struct BCState *bcs, int mode, int bc)
41689 int jade = bcs->hw.hscx.hscx;
41690
41691 if (cs->debug & L1_DEB_HSCX) {
41692- char tmp[40];
41693- sprintf(tmp, "jade %c mode %d ichan %d",
41694- 'A' + jade, mode, bc);
41695- debugl1(cs, tmp);
41696+ debugl1(cs, "jade %c mode %d ichan %d", 'A' + jade, mode, bc);
41697 }
41698 bcs->mode = mode;
41699 bcs->channel = bc;
41700@@ -257,23 +254,18 @@ void
41701 clear_pending_jade_ints(struct IsdnCardState *cs)
41702 {
41703 int val;
41704- char tmp[64];
41705
41706 cs->BC_Write_Reg(cs, 0, jade_HDLC_IMR, 0x00);
41707 cs->BC_Write_Reg(cs, 1, jade_HDLC_IMR, 0x00);
41708
41709 val = cs->BC_Read_Reg(cs, 1, jade_HDLC_ISR);
41710- sprintf(tmp, "jade B ISTA %x", val);
41711- debugl1(cs, tmp);
41712+ debugl1(cs, "jade B ISTA %x", val);
41713 val = cs->BC_Read_Reg(cs, 0, jade_HDLC_ISR);
41714- sprintf(tmp, "jade A ISTA %x", val);
41715- debugl1(cs, tmp);
41716+ debugl1(cs, "jade A ISTA %x", val);
41717 val = cs->BC_Read_Reg(cs, 1, jade_HDLC_STAR);
41718- sprintf(tmp, "jade B STAR %x", val);
41719- debugl1(cs, tmp);
41720+ debugl1(cs, "jade B STAR %x", val);
41721 val = cs->BC_Read_Reg(cs, 0, jade_HDLC_STAR);
41722- sprintf(tmp, "jade A STAR %x", val);
41723- debugl1(cs, tmp);
41724+ debugl1(cs, "jade A STAR %x", val);
41725 /* Unmask ints */
41726 cs->BC_Write_Reg(cs, 0, jade_HDLC_IMR, 0xF8);
41727 cs->BC_Write_Reg(cs, 1, jade_HDLC_IMR, 0xF8);
41728diff --git a/drivers/isdn/hisax/jade_irq.c b/drivers/isdn/hisax/jade_irq.c
41729index f521fc8..b930da9 100644
41730--- a/drivers/isdn/hisax/jade_irq.c
41731+++ b/drivers/isdn/hisax/jade_irq.c
41732@@ -65,7 +65,7 @@ jade_empty_fifo(struct BCState *bcs, int count)
41733 t += sprintf(t, "jade_empty_fifo %c cnt %d",
41734 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41735 QuickHex(t, ptr, count);
41736- debugl1(cs, bcs->blog);
41737+ debugl1(cs, "%s", bcs->blog);
41738 }
41739 }
41740
41741@@ -105,7 +105,7 @@ jade_fill_fifo(struct BCState *bcs)
41742 t += sprintf(t, "jade_fill_fifo %c cnt %d",
41743 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41744 QuickHex(t, ptr, count);
41745- debugl1(cs, bcs->blog);
41746+ debugl1(cs, "%s", bcs->blog);
41747 }
41748 }
41749
41750diff --git a/drivers/isdn/hisax/l3_1tr6.c b/drivers/isdn/hisax/l3_1tr6.c
41751index 4c1bca5..875402e 100644
41752--- a/drivers/isdn/hisax/l3_1tr6.c
41753+++ b/drivers/isdn/hisax/l3_1tr6.c
41754@@ -63,7 +63,7 @@ l3_1tr6_error(struct l3_process *pc, u_char *msg, struct sk_buff *skb)
41755 {
41756 dev_kfree_skb(skb);
41757 if (pc->st->l3.debug & L3_DEB_WARN)
41758- l3_debug(pc->st, msg);
41759+ l3_debug(pc->st, "%s", msg);
41760 l3_1tr6_release_req(pc, 0, NULL);
41761 }
41762
41763@@ -161,7 +161,6 @@ l3_1tr6_setup(struct l3_process *pc, u_char pr, void *arg)
41764 {
41765 u_char *p;
41766 int bcfound = 0;
41767- char tmp[80];
41768 struct sk_buff *skb = arg;
41769
41770 /* Channel Identification */
41771@@ -214,10 +213,9 @@ l3_1tr6_setup(struct l3_process *pc, u_char pr, void *arg)
41772 /* Signal all services, linklevel takes care of Service-Indicator */
41773 if (bcfound) {
41774 if ((pc->para.setup.si1 != 7) && (pc->st->l3.debug & L3_DEB_WARN)) {
41775- sprintf(tmp, "non-digital call: %s -> %s",
41776+ l3_debug(pc->st, "non-digital call: %s -> %s",
41777 pc->para.setup.phone,
41778 pc->para.setup.eazmsn);
41779- l3_debug(pc->st, tmp);
41780 }
41781 newl3state(pc, 6);
41782 pc->st->l3.l3l4(pc->st, CC_SETUP | INDICATION, pc);
41783@@ -301,7 +299,7 @@ l3_1tr6_info(struct l3_process *pc, u_char pr, void *arg)
41784 {
41785 u_char *p;
41786 int i, tmpcharge = 0;
41787- char a_charge[8], tmp[32];
41788+ char a_charge[8];
41789 struct sk_buff *skb = arg;
41790
41791 p = skb->data;
41792@@ -316,8 +314,8 @@ l3_1tr6_info(struct l3_process *pc, u_char pr, void *arg)
41793 pc->st->l3.l3l4(pc->st, CC_CHARGE | INDICATION, pc);
41794 }
41795 if (pc->st->l3.debug & L3_DEB_CHARGE) {
41796- sprintf(tmp, "charging info %d", pc->para.chargeinfo);
41797- l3_debug(pc->st, tmp);
41798+ l3_debug(pc->st, "charging info %d",
41799+ pc->para.chargeinfo);
41800 }
41801 } else if (pc->st->l3.debug & L3_DEB_CHARGE)
41802 l3_debug(pc->st, "charging info not found");
41803@@ -399,7 +397,7 @@ l3_1tr6_disc(struct l3_process *pc, u_char pr, void *arg)
41804 struct sk_buff *skb = arg;
41805 u_char *p;
41806 int i, tmpcharge = 0;
41807- char a_charge[8], tmp[32];
41808+ char a_charge[8];
41809
41810 StopAllL3Timer(pc);
41811 p = skb->data;
41812@@ -414,8 +412,8 @@ l3_1tr6_disc(struct l3_process *pc, u_char pr, void *arg)
41813 pc->st->l3.l3l4(pc->st, CC_CHARGE | INDICATION, pc);
41814 }
41815 if (pc->st->l3.debug & L3_DEB_CHARGE) {
41816- sprintf(tmp, "charging info %d", pc->para.chargeinfo);
41817- l3_debug(pc->st, tmp);
41818+ l3_debug(pc->st, "charging info %d",
41819+ pc->para.chargeinfo);
41820 }
41821 } else if (pc->st->l3.debug & L3_DEB_CHARGE)
41822 l3_debug(pc->st, "charging info not found");
41823@@ -746,7 +744,6 @@ up1tr6(struct PStack *st, int pr, void *arg)
41824 int i, mt, cr;
41825 struct l3_process *proc;
41826 struct sk_buff *skb = arg;
41827- char tmp[80];
41828
41829 switch (pr) {
41830 case (DL_DATA | INDICATION):
41831@@ -762,26 +759,23 @@ up1tr6(struct PStack *st, int pr, void *arg)
41832 }
41833 if (skb->len < 4) {
41834 if (st->l3.debug & L3_DEB_PROTERR) {
41835- sprintf(tmp, "up1tr6 len only %d", skb->len);
41836- l3_debug(st, tmp);
41837+ l3_debug(st, "up1tr6 len only %d", skb->len);
41838 }
41839 dev_kfree_skb(skb);
41840 return;
41841 }
41842 if ((skb->data[0] & 0xfe) != PROTO_DIS_N0) {
41843 if (st->l3.debug & L3_DEB_PROTERR) {
41844- sprintf(tmp, "up1tr6%sunexpected discriminator %x message len %d",
41845+ l3_debug(st, "up1tr6%sunexpected discriminator %x message len %d",
41846 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41847 skb->data[0], skb->len);
41848- l3_debug(st, tmp);
41849 }
41850 dev_kfree_skb(skb);
41851 return;
41852 }
41853 if (skb->data[1] != 1) {
41854 if (st->l3.debug & L3_DEB_PROTERR) {
41855- sprintf(tmp, "up1tr6 CR len not 1");
41856- l3_debug(st, tmp);
41857+ l3_debug(st, "up1tr6 CR len not 1");
41858 }
41859 dev_kfree_skb(skb);
41860 return;
41861@@ -791,9 +785,8 @@ up1tr6(struct PStack *st, int pr, void *arg)
41862 if (skb->data[0] == PROTO_DIS_N0) {
41863 dev_kfree_skb(skb);
41864 if (st->l3.debug & L3_DEB_STATE) {
41865- sprintf(tmp, "up1tr6%s N0 mt %x unhandled",
41866+ l3_debug(st, "up1tr6%s N0 mt %x unhandled",
41867 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ", mt);
41868- l3_debug(st, tmp);
41869 }
41870 } else if (skb->data[0] == PROTO_DIS_N1) {
41871 if (!(proc = getl3proc(st, cr))) {
41872@@ -801,8 +794,7 @@ up1tr6(struct PStack *st, int pr, void *arg)
41873 if (cr < 128) {
41874 if (!(proc = new_l3_process(st, cr))) {
41875 if (st->l3.debug & L3_DEB_PROTERR) {
41876- sprintf(tmp, "up1tr6 no roc mem");
41877- l3_debug(st, tmp);
41878+ l3_debug(st, "up1tr6 no roc mem");
41879 }
41880 dev_kfree_skb(skb);
41881 return;
41882@@ -821,8 +813,7 @@ up1tr6(struct PStack *st, int pr, void *arg)
41883 } else {
41884 if (!(proc = new_l3_process(st, cr))) {
41885 if (st->l3.debug & L3_DEB_PROTERR) {
41886- sprintf(tmp, "up1tr6 no roc mem");
41887- l3_debug(st, tmp);
41888+ l3_debug(st, "up1tr6 no roc mem");
41889 }
41890 dev_kfree_skb(skb);
41891 return;
41892@@ -837,18 +828,16 @@ up1tr6(struct PStack *st, int pr, void *arg)
41893 if (i == ARRAY_SIZE(datastln1)) {
41894 dev_kfree_skb(skb);
41895 if (st->l3.debug & L3_DEB_STATE) {
41896- sprintf(tmp, "up1tr6%sstate %d mt %x unhandled",
41897+ l3_debug(st, "up1tr6%sstate %d mt %x unhandled",
41898 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41899 proc->state, mt);
41900- l3_debug(st, tmp);
41901 }
41902 return;
41903 } else {
41904 if (st->l3.debug & L3_DEB_STATE) {
41905- sprintf(tmp, "up1tr6%sstate %d mt %x",
41906+ l3_debug(st, "up1tr6%sstate %d mt %x",
41907 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41908 proc->state, mt);
41909- l3_debug(st, tmp);
41910 }
41911 datastln1[i].rout(proc, pr, skb);
41912 }
41913@@ -861,7 +850,6 @@ down1tr6(struct PStack *st, int pr, void *arg)
41914 int i, cr;
41915 struct l3_process *proc;
41916 struct Channel *chan;
41917- char tmp[80];
41918
41919 if ((DL_ESTABLISH | REQUEST) == pr) {
41920 l3_msg(st, pr, NULL);
41921@@ -888,15 +876,13 @@ down1tr6(struct PStack *st, int pr, void *arg)
41922 break;
41923 if (i == ARRAY_SIZE(downstl)) {
41924 if (st->l3.debug & L3_DEB_STATE) {
41925- sprintf(tmp, "down1tr6 state %d prim %d unhandled",
41926+ l3_debug(st, "down1tr6 state %d prim %d unhandled",
41927 proc->state, pr);
41928- l3_debug(st, tmp);
41929 }
41930 } else {
41931 if (st->l3.debug & L3_DEB_STATE) {
41932- sprintf(tmp, "down1tr6 state %d prim %d",
41933+ l3_debug(st, "down1tr6 state %d prim %d",
41934 proc->state, pr);
41935- l3_debug(st, tmp);
41936 }
41937 downstl[i].rout(proc, pr, arg);
41938 }
41939diff --git a/drivers/isdn/hisax/netjet.c b/drivers/isdn/hisax/netjet.c
41940index b646eed..233e432 100644
41941--- a/drivers/isdn/hisax/netjet.c
41942+++ b/drivers/isdn/hisax/netjet.c
41943@@ -176,7 +176,7 @@ static void printframe(struct IsdnCardState *cs, u_char *buf, int count, char *s
41944 else
41945 j = i;
41946 QuickHex(t, p, j);
41947- debugl1(cs, tmp);
41948+ debugl1(cs, "%s", tmp);
41949 p += j;
41950 i -= j;
41951 t = tmp;
41952diff --git a/drivers/isdn/hisax/q931.c b/drivers/isdn/hisax/q931.c
41953index 041bf52..af1b020 100644
41954--- a/drivers/isdn/hisax/q931.c
41955+++ b/drivers/isdn/hisax/q931.c
41956@@ -1179,7 +1179,7 @@ LogFrame(struct IsdnCardState *cs, u_char *buf, int size)
41957 dp--;
41958 *dp++ = '\n';
41959 *dp = 0;
41960- HiSax_putstatus(cs, NULL, cs->dlog);
41961+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41962 } else
41963 HiSax_putstatus(cs, "LogFrame: ", "warning Frame too big (%d)", size);
41964 }
41965@@ -1246,7 +1246,7 @@ dlogframe(struct IsdnCardState *cs, struct sk_buff *skb, int dir)
41966 }
41967 if (finish) {
41968 *dp = 0;
41969- HiSax_putstatus(cs, NULL, cs->dlog);
41970+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41971 return;
41972 }
41973 if ((0xfe & buf[0]) == PROTO_DIS_N0) { /* 1TR6 */
41974@@ -1509,5 +1509,5 @@ dlogframe(struct IsdnCardState *cs, struct sk_buff *skb, int dir)
41975 dp += sprintf(dp, "Unknown protocol %x!", buf[0]);
41976 }
41977 *dp = 0;
41978- HiSax_putstatus(cs, NULL, cs->dlog);
41979+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41980 }
41981diff --git a/drivers/isdn/hisax/w6692.c b/drivers/isdn/hisax/w6692.c
41982index d8cac69..a858955 100644
41983--- a/drivers/isdn/hisax/w6692.c
41984+++ b/drivers/isdn/hisax/w6692.c
41985@@ -154,7 +154,7 @@ W6692_empty_fifo(struct IsdnCardState *cs, int count)
41986
41987 t += sprintf(t, "W6692_empty_fifo cnt %d", count);
41988 QuickHex(t, ptr, count);
41989- debugl1(cs, cs->dlog);
41990+ debugl1(cs, "%s", cs->dlog);
41991 }
41992 }
41993
41994@@ -196,7 +196,7 @@ W6692_fill_fifo(struct IsdnCardState *cs)
41995
41996 t += sprintf(t, "W6692_fill_fifo cnt %d", count);
41997 QuickHex(t, ptr, count);
41998- debugl1(cs, cs->dlog);
41999+ debugl1(cs, "%s", cs->dlog);
42000 }
42001 }
42002
42003@@ -226,7 +226,7 @@ W6692B_empty_fifo(struct BCState *bcs, int count)
42004 t += sprintf(t, "W6692B_empty_fifo %c cnt %d",
42005 bcs->channel + '1', count);
42006 QuickHex(t, ptr, count);
42007- debugl1(cs, bcs->blog);
42008+ debugl1(cs, "%s", bcs->blog);
42009 }
42010 }
42011
42012@@ -264,7 +264,7 @@ W6692B_fill_fifo(struct BCState *bcs)
42013 t += sprintf(t, "W6692B_fill_fifo %c cnt %d",
42014 bcs->channel + '1', count);
42015 QuickHex(t, ptr, count);
42016- debugl1(cs, bcs->blog);
42017+ debugl1(cs, "%s", bcs->blog);
42018 }
42019 }
42020
42021diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
42022index 9bb12ba..d4262f7 100644
42023--- a/drivers/isdn/i4l/isdn_common.c
42024+++ b/drivers/isdn/i4l/isdn_common.c
42025@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
42026 } else
42027 return -EINVAL;
42028 case IIOCDBGVAR:
42029+ if (!capable(CAP_SYS_RAWIO))
42030+ return -EPERM;
42031 if (arg) {
42032 if (copy_to_user(argp, &dev, sizeof(ulong)))
42033 return -EFAULT;
42034diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
42035index 3c5f249..5fac4d0 100644
42036--- a/drivers/isdn/i4l/isdn_tty.c
42037+++ b/drivers/isdn/i4l/isdn_tty.c
42038@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
42039
42040 #ifdef ISDN_DEBUG_MODEM_OPEN
42041 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
42042- port->count);
42043+ atomic_read(&port->count));
42044 #endif
42045- port->count++;
42046+ atomic_inc(&port->count);
42047 port->tty = tty;
42048 /*
42049 * Start up serial port
42050@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42051 #endif
42052 return;
42053 }
42054- if ((tty->count == 1) && (port->count != 1)) {
42055+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
42056 /*
42057 * Uh, oh. tty->count is 1, which means that the tty
42058 * structure will be freed. Info->count should always
42059@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42060 * serial port won't be shutdown.
42061 */
42062 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
42063- "info->count is %d\n", port->count);
42064- port->count = 1;
42065+ "info->count is %d\n", atomic_read(&port->count));
42066+ atomic_set(&port->count, 1);
42067 }
42068- if (--port->count < 0) {
42069+ if (atomic_dec_return(&port->count) < 0) {
42070 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
42071- info->line, port->count);
42072- port->count = 0;
42073+ info->line, atomic_read(&port->count));
42074+ atomic_set(&port->count, 0);
42075 }
42076- if (port->count) {
42077+ if (atomic_read(&port->count)) {
42078 #ifdef ISDN_DEBUG_MODEM_OPEN
42079 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
42080 #endif
42081@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
42082 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
42083 return;
42084 isdn_tty_shutdown(info);
42085- port->count = 0;
42086+ atomic_set(&port->count, 0);
42087 port->flags &= ~ASYNC_NORMAL_ACTIVE;
42088 port->tty = NULL;
42089 wake_up_interruptible(&port->open_wait);
42090@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
42091 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
42092 modem_info *info = &dev->mdm.info[i];
42093
42094- if (info->port.count == 0)
42095+ if (atomic_read(&info->port.count) == 0)
42096 continue;
42097 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
42098 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
42099diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
42100index e74df7c..03a03ba 100644
42101--- a/drivers/isdn/icn/icn.c
42102+++ b/drivers/isdn/icn/icn.c
42103@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
42104 if (count > len)
42105 count = len;
42106 if (user) {
42107- if (copy_from_user(msg, buf, count))
42108+ if (count > sizeof msg || copy_from_user(msg, buf, count))
42109 return -EFAULT;
42110 } else
42111 memcpy(msg, buf, count);
42112diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
42113index 6a8405d..0bd1c7e 100644
42114--- a/drivers/leds/leds-clevo-mail.c
42115+++ b/drivers/leds/leds-clevo-mail.c
42116@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
42117 * detected as working, but in reality it is not) as low as
42118 * possible.
42119 */
42120-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
42121+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
42122 {
42123 .callback = clevo_mail_led_dmi_callback,
42124 .ident = "Clevo D410J",
42125diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
42126index 64e204e..c6bf189 100644
42127--- a/drivers/leds/leds-ss4200.c
42128+++ b/drivers/leds/leds-ss4200.c
42129@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
42130 * detected as working, but in reality it is not) as low as
42131 * possible.
42132 */
42133-static struct dmi_system_id __initdata nas_led_whitelist[] = {
42134+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
42135 {
42136 .callback = ss4200_led_dmi_callback,
42137 .ident = "Intel SS4200-E",
42138diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
42139index 0bf1e4e..b4bf44e 100644
42140--- a/drivers/lguest/core.c
42141+++ b/drivers/lguest/core.c
42142@@ -97,9 +97,17 @@ static __init int map_switcher(void)
42143 * The end address needs +1 because __get_vm_area allocates an
42144 * extra guard page, so we need space for that.
42145 */
42146+
42147+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
42148+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42149+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
42150+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42151+#else
42152 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42153 VM_ALLOC, switcher_addr, switcher_addr
42154 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42155+#endif
42156+
42157 if (!switcher_vma) {
42158 err = -ENOMEM;
42159 printk("lguest: could not map switcher pages high\n");
42160@@ -124,7 +132,7 @@ static __init int map_switcher(void)
42161 * Now the Switcher is mapped at the right address, we can't fail!
42162 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
42163 */
42164- memcpy(switcher_vma->addr, start_switcher_text,
42165+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
42166 end_switcher_text - start_switcher_text);
42167
42168 printk(KERN_INFO "lguest: mapped switcher at %p\n",
42169diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
42170index a35d8d1..59fb772 100644
42171--- a/drivers/lguest/page_tables.c
42172+++ b/drivers/lguest/page_tables.c
42173@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
42174 /*:*/
42175
42176 #ifdef CONFIG_X86_PAE
42177-static void release_pmd(pmd_t *spmd)
42178+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
42179 {
42180 /* If the entry's not present, there's nothing to release. */
42181 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
42182diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
42183index 5169239..47cb4db 100644
42184--- a/drivers/lguest/x86/core.c
42185+++ b/drivers/lguest/x86/core.c
42186@@ -59,7 +59,7 @@ static struct {
42187 /* Offset from where switcher.S was compiled to where we've copied it */
42188 static unsigned long switcher_offset(void)
42189 {
42190- return switcher_addr - (unsigned long)start_switcher_text;
42191+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
42192 }
42193
42194 /* This cpu's struct lguest_pages (after the Switcher text page) */
42195@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
42196 * These copies are pretty cheap, so we do them unconditionally: */
42197 /* Save the current Host top-level page directory.
42198 */
42199+
42200+#ifdef CONFIG_PAX_PER_CPU_PGD
42201+ pages->state.host_cr3 = read_cr3();
42202+#else
42203 pages->state.host_cr3 = __pa(current->mm->pgd);
42204+#endif
42205+
42206 /*
42207 * Set up the Guest's page tables to see this CPU's pages (and no
42208 * other CPU's pages).
42209@@ -475,7 +481,7 @@ void __init lguest_arch_host_init(void)
42210 * compiled-in switcher code and the high-mapped copy we just made.
42211 */
42212 for (i = 0; i < IDT_ENTRIES; i++)
42213- default_idt_entries[i] += switcher_offset();
42214+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
42215
42216 /*
42217 * Set up the Switcher's per-cpu areas.
42218@@ -558,7 +564,7 @@ void __init lguest_arch_host_init(void)
42219 * it will be undisturbed when we switch. To change %cs and jump we
42220 * need this structure to feed to Intel's "lcall" instruction.
42221 */
42222- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
42223+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
42224 lguest_entry.segment = LGUEST_CS;
42225
42226 /*
42227diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
42228index 40634b0..4f5855e 100644
42229--- a/drivers/lguest/x86/switcher_32.S
42230+++ b/drivers/lguest/x86/switcher_32.S
42231@@ -87,6 +87,7 @@
42232 #include <asm/page.h>
42233 #include <asm/segment.h>
42234 #include <asm/lguest.h>
42235+#include <asm/processor-flags.h>
42236
42237 // We mark the start of the code to copy
42238 // It's placed in .text tho it's never run here
42239@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
42240 // Changes type when we load it: damn Intel!
42241 // For after we switch over our page tables
42242 // That entry will be read-only: we'd crash.
42243+
42244+#ifdef CONFIG_PAX_KERNEXEC
42245+ mov %cr0, %edx
42246+ xor $X86_CR0_WP, %edx
42247+ mov %edx, %cr0
42248+#endif
42249+
42250 movl $(GDT_ENTRY_TSS*8), %edx
42251 ltr %dx
42252
42253@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
42254 // Let's clear it again for our return.
42255 // The GDT descriptor of the Host
42256 // Points to the table after two "size" bytes
42257- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
42258+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
42259 // Clear "used" from type field (byte 5, bit 2)
42260- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
42261+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
42262+
42263+#ifdef CONFIG_PAX_KERNEXEC
42264+ mov %cr0, %eax
42265+ xor $X86_CR0_WP, %eax
42266+ mov %eax, %cr0
42267+#endif
42268
42269 // Once our page table's switched, the Guest is live!
42270 // The Host fades as we run this final step.
42271@@ -295,13 +309,12 @@ deliver_to_host:
42272 // I consulted gcc, and it gave
42273 // These instructions, which I gladly credit:
42274 leal (%edx,%ebx,8), %eax
42275- movzwl (%eax),%edx
42276- movl 4(%eax), %eax
42277- xorw %ax, %ax
42278- orl %eax, %edx
42279+ movl 4(%eax), %edx
42280+ movw (%eax), %dx
42281 // Now the address of the handler's in %edx
42282 // We call it now: its "iret" drops us home.
42283- jmp *%edx
42284+ ljmp $__KERNEL_CS, $1f
42285+1: jmp *%edx
42286
42287 // Every interrupt can come to us here
42288 // But we must truly tell each apart.
42289diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
42290index 0003992..854bbce 100644
42291--- a/drivers/md/bcache/closure.h
42292+++ b/drivers/md/bcache/closure.h
42293@@ -622,7 +622,7 @@ static inline void closure_wake_up(struct closure_waitlist *list)
42294 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
42295 struct workqueue_struct *wq)
42296 {
42297- BUG_ON(object_is_on_stack(cl));
42298+ BUG_ON(object_starts_on_stack(cl));
42299 closure_set_ip(cl);
42300 cl->fn = fn;
42301 cl->wq = wq;
42302diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
42303index 547c4c5..5be1de4 100644
42304--- a/drivers/md/bcache/super.c
42305+++ b/drivers/md/bcache/super.c
42306@@ -1644,7 +1644,7 @@ err_unlock_gc:
42307 err:
42308 closure_sync(&op.cl);
42309 /* XXX: test this, it's broken */
42310- bch_cache_set_error(c, err);
42311+ bch_cache_set_error(c, "%s", err);
42312 }
42313
42314 static bool can_attach_cache(struct cache *ca, struct cache_set *c)
42315diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
42316index a7fd821..9dcf6c3 100644
42317--- a/drivers/md/bitmap.c
42318+++ b/drivers/md/bitmap.c
42319@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
42320 chunk_kb ? "KB" : "B");
42321 if (bitmap->storage.file) {
42322 seq_printf(seq, ", file: ");
42323- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
42324+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
42325 }
42326
42327 seq_printf(seq, "\n");
42328diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
42329index f1b7586..a49c4bd 100644
42330--- a/drivers/md/dm-ioctl.c
42331+++ b/drivers/md/dm-ioctl.c
42332@@ -1739,7 +1739,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
42333 cmd == DM_LIST_VERSIONS_CMD)
42334 return 0;
42335
42336- if ((cmd == DM_DEV_CREATE_CMD)) {
42337+ if (cmd == DM_DEV_CREATE_CMD) {
42338 if (!*param->name) {
42339 DMWARN("name not supplied when creating device");
42340 return -EINVAL;
42341diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
42342index 699b5be..eac0a15 100644
42343--- a/drivers/md/dm-raid1.c
42344+++ b/drivers/md/dm-raid1.c
42345@@ -40,7 +40,7 @@ enum dm_raid1_error {
42346
42347 struct mirror {
42348 struct mirror_set *ms;
42349- atomic_t error_count;
42350+ atomic_unchecked_t error_count;
42351 unsigned long error_type;
42352 struct dm_dev *dev;
42353 sector_t offset;
42354@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
42355 struct mirror *m;
42356
42357 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
42358- if (!atomic_read(&m->error_count))
42359+ if (!atomic_read_unchecked(&m->error_count))
42360 return m;
42361
42362 return NULL;
42363@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
42364 * simple way to tell if a device has encountered
42365 * errors.
42366 */
42367- atomic_inc(&m->error_count);
42368+ atomic_inc_unchecked(&m->error_count);
42369
42370 if (test_and_set_bit(error_type, &m->error_type))
42371 return;
42372@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
42373 struct mirror *m = get_default_mirror(ms);
42374
42375 do {
42376- if (likely(!atomic_read(&m->error_count)))
42377+ if (likely(!atomic_read_unchecked(&m->error_count)))
42378 return m;
42379
42380 if (m-- == ms->mirror)
42381@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
42382 {
42383 struct mirror *default_mirror = get_default_mirror(m->ms);
42384
42385- return !atomic_read(&default_mirror->error_count);
42386+ return !atomic_read_unchecked(&default_mirror->error_count);
42387 }
42388
42389 static int mirror_available(struct mirror_set *ms, struct bio *bio)
42390@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
42391 */
42392 if (likely(region_in_sync(ms, region, 1)))
42393 m = choose_mirror(ms, bio->bi_sector);
42394- else if (m && atomic_read(&m->error_count))
42395+ else if (m && atomic_read_unchecked(&m->error_count))
42396 m = NULL;
42397
42398 if (likely(m))
42399@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
42400 }
42401
42402 ms->mirror[mirror].ms = ms;
42403- atomic_set(&(ms->mirror[mirror].error_count), 0);
42404+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
42405 ms->mirror[mirror].error_type = 0;
42406 ms->mirror[mirror].offset = offset;
42407
42408@@ -1340,7 +1340,7 @@ static void mirror_resume(struct dm_target *ti)
42409 */
42410 static char device_status_char(struct mirror *m)
42411 {
42412- if (!atomic_read(&(m->error_count)))
42413+ if (!atomic_read_unchecked(&(m->error_count)))
42414 return 'A';
42415
42416 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
42417diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
42418index d907ca6..cfb8384 100644
42419--- a/drivers/md/dm-stripe.c
42420+++ b/drivers/md/dm-stripe.c
42421@@ -20,7 +20,7 @@ struct stripe {
42422 struct dm_dev *dev;
42423 sector_t physical_start;
42424
42425- atomic_t error_count;
42426+ atomic_unchecked_t error_count;
42427 };
42428
42429 struct stripe_c {
42430@@ -185,7 +185,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
42431 kfree(sc);
42432 return r;
42433 }
42434- atomic_set(&(sc->stripe[i].error_count), 0);
42435+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
42436 }
42437
42438 ti->private = sc;
42439@@ -326,7 +326,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
42440 DMEMIT("%d ", sc->stripes);
42441 for (i = 0; i < sc->stripes; i++) {
42442 DMEMIT("%s ", sc->stripe[i].dev->name);
42443- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
42444+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
42445 'D' : 'A';
42446 }
42447 buffer[i] = '\0';
42448@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
42449 */
42450 for (i = 0; i < sc->stripes; i++)
42451 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
42452- atomic_inc(&(sc->stripe[i].error_count));
42453- if (atomic_read(&(sc->stripe[i].error_count)) <
42454+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
42455+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
42456 DM_IO_ERROR_THRESHOLD)
42457 schedule_work(&sc->trigger_event);
42458 }
42459diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
42460index f221812..aca962b 100644
42461--- a/drivers/md/dm-table.c
42462+++ b/drivers/md/dm-table.c
42463@@ -354,7 +354,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
42464 if (!dev_size)
42465 return 0;
42466
42467- if ((start >= dev_size) || (start + len > dev_size)) {
42468+ if ((start >= dev_size) || (len > dev_size - start)) {
42469 DMWARN("%s: %s too small for target: "
42470 "start=%llu, len=%llu, dev_size=%llu",
42471 dm_device_name(ti->table->md), bdevname(bdev, b),
42472diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
42473index 60bce43..9b997d0 100644
42474--- a/drivers/md/dm-thin-metadata.c
42475+++ b/drivers/md/dm-thin-metadata.c
42476@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42477 {
42478 pmd->info.tm = pmd->tm;
42479 pmd->info.levels = 2;
42480- pmd->info.value_type.context = pmd->data_sm;
42481+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42482 pmd->info.value_type.size = sizeof(__le64);
42483 pmd->info.value_type.inc = data_block_inc;
42484 pmd->info.value_type.dec = data_block_dec;
42485@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42486
42487 pmd->bl_info.tm = pmd->tm;
42488 pmd->bl_info.levels = 1;
42489- pmd->bl_info.value_type.context = pmd->data_sm;
42490+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42491 pmd->bl_info.value_type.size = sizeof(__le64);
42492 pmd->bl_info.value_type.inc = data_block_inc;
42493 pmd->bl_info.value_type.dec = data_block_dec;
42494diff --git a/drivers/md/dm.c b/drivers/md/dm.c
42495index 9e39d2b..fb879a7 100644
42496--- a/drivers/md/dm.c
42497+++ b/drivers/md/dm.c
42498@@ -178,9 +178,9 @@ struct mapped_device {
42499 /*
42500 * Event handling.
42501 */
42502- atomic_t event_nr;
42503+ atomic_unchecked_t event_nr;
42504 wait_queue_head_t eventq;
42505- atomic_t uevent_seq;
42506+ atomic_unchecked_t uevent_seq;
42507 struct list_head uevent_list;
42508 spinlock_t uevent_lock; /* Protect access to uevent_list */
42509
42510@@ -1916,8 +1916,8 @@ static struct mapped_device *alloc_dev(int minor)
42511 spin_lock_init(&md->deferred_lock);
42512 atomic_set(&md->holders, 1);
42513 atomic_set(&md->open_count, 0);
42514- atomic_set(&md->event_nr, 0);
42515- atomic_set(&md->uevent_seq, 0);
42516+ atomic_set_unchecked(&md->event_nr, 0);
42517+ atomic_set_unchecked(&md->uevent_seq, 0);
42518 INIT_LIST_HEAD(&md->uevent_list);
42519 spin_lock_init(&md->uevent_lock);
42520
42521@@ -2068,7 +2068,7 @@ static void event_callback(void *context)
42522
42523 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
42524
42525- atomic_inc(&md->event_nr);
42526+ atomic_inc_unchecked(&md->event_nr);
42527 wake_up(&md->eventq);
42528 }
42529
42530@@ -2716,18 +2716,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
42531
42532 uint32_t dm_next_uevent_seq(struct mapped_device *md)
42533 {
42534- return atomic_add_return(1, &md->uevent_seq);
42535+ return atomic_add_return_unchecked(1, &md->uevent_seq);
42536 }
42537
42538 uint32_t dm_get_event_nr(struct mapped_device *md)
42539 {
42540- return atomic_read(&md->event_nr);
42541+ return atomic_read_unchecked(&md->event_nr);
42542 }
42543
42544 int dm_wait_event(struct mapped_device *md, int event_nr)
42545 {
42546 return wait_event_interruptible(md->eventq,
42547- (event_nr != atomic_read(&md->event_nr)));
42548+ (event_nr != atomic_read_unchecked(&md->event_nr)));
42549 }
42550
42551 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
42552diff --git a/drivers/md/md.c b/drivers/md/md.c
42553index 9f13e13..411a5b8 100644
42554--- a/drivers/md/md.c
42555+++ b/drivers/md/md.c
42556@@ -234,10 +234,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
42557 * start build, activate spare
42558 */
42559 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
42560-static atomic_t md_event_count;
42561+static atomic_unchecked_t md_event_count;
42562 void md_new_event(struct mddev *mddev)
42563 {
42564- atomic_inc(&md_event_count);
42565+ atomic_inc_unchecked(&md_event_count);
42566 wake_up(&md_event_waiters);
42567 }
42568 EXPORT_SYMBOL_GPL(md_new_event);
42569@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
42570 */
42571 static void md_new_event_inintr(struct mddev *mddev)
42572 {
42573- atomic_inc(&md_event_count);
42574+ atomic_inc_unchecked(&md_event_count);
42575 wake_up(&md_event_waiters);
42576 }
42577
42578@@ -1502,7 +1502,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
42579 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
42580 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
42581 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
42582- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42583+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42584
42585 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
42586 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
42587@@ -1746,7 +1746,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
42588 else
42589 sb->resync_offset = cpu_to_le64(0);
42590
42591- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
42592+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
42593
42594 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
42595 sb->size = cpu_to_le64(mddev->dev_sectors);
42596@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
42597 static ssize_t
42598 errors_show(struct md_rdev *rdev, char *page)
42599 {
42600- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
42601+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
42602 }
42603
42604 static ssize_t
42605@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
42606 char *e;
42607 unsigned long n = simple_strtoul(buf, &e, 10);
42608 if (*buf && (*e == 0 || *e == '\n')) {
42609- atomic_set(&rdev->corrected_errors, n);
42610+ atomic_set_unchecked(&rdev->corrected_errors, n);
42611 return len;
42612 }
42613 return -EINVAL;
42614@@ -3208,8 +3208,8 @@ int md_rdev_init(struct md_rdev *rdev)
42615 rdev->sb_loaded = 0;
42616 rdev->bb_page = NULL;
42617 atomic_set(&rdev->nr_pending, 0);
42618- atomic_set(&rdev->read_errors, 0);
42619- atomic_set(&rdev->corrected_errors, 0);
42620+ atomic_set_unchecked(&rdev->read_errors, 0);
42621+ atomic_set_unchecked(&rdev->corrected_errors, 0);
42622
42623 INIT_LIST_HEAD(&rdev->same_set);
42624 init_waitqueue_head(&rdev->blocked_wait);
42625@@ -7024,7 +7024,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
42626
42627 spin_unlock(&pers_lock);
42628 seq_printf(seq, "\n");
42629- seq->poll_event = atomic_read(&md_event_count);
42630+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42631 return 0;
42632 }
42633 if (v == (void*)2) {
42634@@ -7127,7 +7127,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
42635 return error;
42636
42637 seq = file->private_data;
42638- seq->poll_event = atomic_read(&md_event_count);
42639+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42640 return error;
42641 }
42642
42643@@ -7141,7 +7141,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
42644 /* always allow read */
42645 mask = POLLIN | POLLRDNORM;
42646
42647- if (seq->poll_event != atomic_read(&md_event_count))
42648+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
42649 mask |= POLLERR | POLLPRI;
42650 return mask;
42651 }
42652@@ -7185,7 +7185,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
42653 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
42654 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
42655 (int)part_stat_read(&disk->part0, sectors[1]) -
42656- atomic_read(&disk->sync_io);
42657+ atomic_read_unchecked(&disk->sync_io);
42658 /* sync IO will cause sync_io to increase before the disk_stats
42659 * as sync_io is counted when a request starts, and
42660 * disk_stats is counted when it completes.
42661diff --git a/drivers/md/md.h b/drivers/md/md.h
42662index 20f02c0..fd8c821 100644
42663--- a/drivers/md/md.h
42664+++ b/drivers/md/md.h
42665@@ -94,13 +94,13 @@ struct md_rdev {
42666 * only maintained for arrays that
42667 * support hot removal
42668 */
42669- atomic_t read_errors; /* number of consecutive read errors that
42670+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
42671 * we have tried to ignore.
42672 */
42673 struct timespec last_read_error; /* monotonic time since our
42674 * last read error
42675 */
42676- atomic_t corrected_errors; /* number of corrected read errors,
42677+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
42678 * for reporting to userspace and storing
42679 * in superblock.
42680 */
42681@@ -442,7 +442,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
42682
42683 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
42684 {
42685- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42686+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42687 }
42688
42689 struct md_personality
42690diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
42691index 3e6d115..ffecdeb 100644
42692--- a/drivers/md/persistent-data/dm-space-map.h
42693+++ b/drivers/md/persistent-data/dm-space-map.h
42694@@ -71,6 +71,7 @@ struct dm_space_map {
42695 dm_sm_threshold_fn fn,
42696 void *context);
42697 };
42698+typedef struct dm_space_map __no_const dm_space_map_no_const;
42699
42700 /*----------------------------------------------------------------*/
42701
42702diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
42703index d60412c..8d4c982 100644
42704--- a/drivers/md/raid1.c
42705+++ b/drivers/md/raid1.c
42706@@ -1823,7 +1823,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
42707 if (r1_sync_page_io(rdev, sect, s,
42708 bio->bi_io_vec[idx].bv_page,
42709 READ) != 0)
42710- atomic_add(s, &rdev->corrected_errors);
42711+ atomic_add_unchecked(s, &rdev->corrected_errors);
42712 }
42713 sectors -= s;
42714 sect += s;
42715@@ -2050,7 +2050,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
42716 test_bit(In_sync, &rdev->flags)) {
42717 if (r1_sync_page_io(rdev, sect, s,
42718 conf->tmppage, READ)) {
42719- atomic_add(s, &rdev->corrected_errors);
42720+ atomic_add_unchecked(s, &rdev->corrected_errors);
42721 printk(KERN_INFO
42722 "md/raid1:%s: read error corrected "
42723 "(%d sectors at %llu on %s)\n",
42724diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
42725index df7b0a0..a257495 100644
42726--- a/drivers/md/raid10.c
42727+++ b/drivers/md/raid10.c
42728@@ -1962,7 +1962,7 @@ static void end_sync_read(struct bio *bio, int error)
42729 /* The write handler will notice the lack of
42730 * R10BIO_Uptodate and record any errors etc
42731 */
42732- atomic_add(r10_bio->sectors,
42733+ atomic_add_unchecked(r10_bio->sectors,
42734 &conf->mirrors[d].rdev->corrected_errors);
42735
42736 /* for reconstruct, we always reschedule after a read.
42737@@ -2320,7 +2320,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42738 {
42739 struct timespec cur_time_mon;
42740 unsigned long hours_since_last;
42741- unsigned int read_errors = atomic_read(&rdev->read_errors);
42742+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
42743
42744 ktime_get_ts(&cur_time_mon);
42745
42746@@ -2342,9 +2342,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42747 * overflowing the shift of read_errors by hours_since_last.
42748 */
42749 if (hours_since_last >= 8 * sizeof(read_errors))
42750- atomic_set(&rdev->read_errors, 0);
42751+ atomic_set_unchecked(&rdev->read_errors, 0);
42752 else
42753- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
42754+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
42755 }
42756
42757 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
42758@@ -2398,8 +2398,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42759 return;
42760
42761 check_decay_read_errors(mddev, rdev);
42762- atomic_inc(&rdev->read_errors);
42763- if (atomic_read(&rdev->read_errors) > max_read_errors) {
42764+ atomic_inc_unchecked(&rdev->read_errors);
42765+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
42766 char b[BDEVNAME_SIZE];
42767 bdevname(rdev->bdev, b);
42768
42769@@ -2407,7 +2407,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42770 "md/raid10:%s: %s: Raid device exceeded "
42771 "read_error threshold [cur %d:max %d]\n",
42772 mdname(mddev), b,
42773- atomic_read(&rdev->read_errors), max_read_errors);
42774+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
42775 printk(KERN_NOTICE
42776 "md/raid10:%s: %s: Failing raid device\n",
42777 mdname(mddev), b);
42778@@ -2562,7 +2562,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42779 sect +
42780 choose_data_offset(r10_bio, rdev)),
42781 bdevname(rdev->bdev, b));
42782- atomic_add(s, &rdev->corrected_errors);
42783+ atomic_add_unchecked(s, &rdev->corrected_errors);
42784 }
42785
42786 rdev_dec_pending(rdev, mddev);
42787diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
42788index 78ea443..7d57513 100644
42789--- a/drivers/md/raid5.c
42790+++ b/drivers/md/raid5.c
42791@@ -1764,21 +1764,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
42792 mdname(conf->mddev), STRIPE_SECTORS,
42793 (unsigned long long)s,
42794 bdevname(rdev->bdev, b));
42795- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
42796+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
42797 clear_bit(R5_ReadError, &sh->dev[i].flags);
42798 clear_bit(R5_ReWrite, &sh->dev[i].flags);
42799 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
42800 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
42801
42802- if (atomic_read(&rdev->read_errors))
42803- atomic_set(&rdev->read_errors, 0);
42804+ if (atomic_read_unchecked(&rdev->read_errors))
42805+ atomic_set_unchecked(&rdev->read_errors, 0);
42806 } else {
42807 const char *bdn = bdevname(rdev->bdev, b);
42808 int retry = 0;
42809 int set_bad = 0;
42810
42811 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
42812- atomic_inc(&rdev->read_errors);
42813+ atomic_inc_unchecked(&rdev->read_errors);
42814 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
42815 printk_ratelimited(
42816 KERN_WARNING
42817@@ -1806,7 +1806,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
42818 mdname(conf->mddev),
42819 (unsigned long long)s,
42820 bdn);
42821- } else if (atomic_read(&rdev->read_errors)
42822+ } else if (atomic_read_unchecked(&rdev->read_errors)
42823 > conf->max_nr_stripes)
42824 printk(KERN_WARNING
42825 "md/raid:%s: Too many read errors, failing device %s.\n",
42826diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
42827index 401ef64..836e563 100644
42828--- a/drivers/media/dvb-core/dvbdev.c
42829+++ b/drivers/media/dvb-core/dvbdev.c
42830@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
42831 const struct dvb_device *template, void *priv, int type)
42832 {
42833 struct dvb_device *dvbdev;
42834- struct file_operations *dvbdevfops;
42835+ file_operations_no_const *dvbdevfops;
42836 struct device *clsdev;
42837 int minor;
42838 int id;
42839diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
42840index 9b6c3bb..baeb5c7 100644
42841--- a/drivers/media/dvb-frontends/dib3000.h
42842+++ b/drivers/media/dvb-frontends/dib3000.h
42843@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
42844 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
42845 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
42846 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
42847-};
42848+} __no_const;
42849
42850 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
42851 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
42852diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
42853index ecf21d9..b992428d 100644
42854--- a/drivers/media/pci/cx88/cx88-video.c
42855+++ b/drivers/media/pci/cx88/cx88-video.c
42856@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
42857
42858 /* ------------------------------------------------------------------ */
42859
42860-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42861-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42862-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42863+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42864+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42865+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42866
42867 module_param_array(video_nr, int, NULL, 0444);
42868 module_param_array(vbi_nr, int, NULL, 0444);
42869diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
42870index c08ae3e..eb59af1 100644
42871--- a/drivers/media/pci/ivtv/ivtv-driver.c
42872+++ b/drivers/media/pci/ivtv/ivtv-driver.c
42873@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
42874 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
42875
42876 /* ivtv instance counter */
42877-static atomic_t ivtv_instance = ATOMIC_INIT(0);
42878+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
42879
42880 /* Parameter declarations */
42881 static int cardtype[IVTV_MAX_CARDS];
42882diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
42883index dfd0a21..6bbb465 100644
42884--- a/drivers/media/platform/omap/omap_vout.c
42885+++ b/drivers/media/platform/omap/omap_vout.c
42886@@ -63,7 +63,6 @@ enum omap_vout_channels {
42887 OMAP_VIDEO2,
42888 };
42889
42890-static struct videobuf_queue_ops video_vbq_ops;
42891 /* Variables configurable through module params*/
42892 static u32 video1_numbuffers = 3;
42893 static u32 video2_numbuffers = 3;
42894@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
42895 {
42896 struct videobuf_queue *q;
42897 struct omap_vout_device *vout = NULL;
42898+ static struct videobuf_queue_ops video_vbq_ops = {
42899+ .buf_setup = omap_vout_buffer_setup,
42900+ .buf_prepare = omap_vout_buffer_prepare,
42901+ .buf_release = omap_vout_buffer_release,
42902+ .buf_queue = omap_vout_buffer_queue,
42903+ };
42904
42905 vout = video_drvdata(file);
42906 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
42907@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
42908 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
42909
42910 q = &vout->vbq;
42911- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
42912- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
42913- video_vbq_ops.buf_release = omap_vout_buffer_release;
42914- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
42915 spin_lock_init(&vout->vbq_lock);
42916
42917 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
42918diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
42919index 04e6490..2df65bf 100644
42920--- a/drivers/media/platform/s5p-tv/mixer.h
42921+++ b/drivers/media/platform/s5p-tv/mixer.h
42922@@ -156,7 +156,7 @@ struct mxr_layer {
42923 /** layer index (unique identifier) */
42924 int idx;
42925 /** callbacks for layer methods */
42926- struct mxr_layer_ops ops;
42927+ struct mxr_layer_ops *ops;
42928 /** format array */
42929 const struct mxr_format **fmt_array;
42930 /** size of format array */
42931diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42932index b93a21f..2535195 100644
42933--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42934+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42935@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
42936 {
42937 struct mxr_layer *layer;
42938 int ret;
42939- struct mxr_layer_ops ops = {
42940+ static struct mxr_layer_ops ops = {
42941 .release = mxr_graph_layer_release,
42942 .buffer_set = mxr_graph_buffer_set,
42943 .stream_set = mxr_graph_stream_set,
42944diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
42945index b713403..53cb5ad 100644
42946--- a/drivers/media/platform/s5p-tv/mixer_reg.c
42947+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
42948@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
42949 layer->update_buf = next;
42950 }
42951
42952- layer->ops.buffer_set(layer, layer->update_buf);
42953+ layer->ops->buffer_set(layer, layer->update_buf);
42954
42955 if (done && done != layer->shadow_buf)
42956 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
42957diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
42958index 641b1f0..49cff30 100644
42959--- a/drivers/media/platform/s5p-tv/mixer_video.c
42960+++ b/drivers/media/platform/s5p-tv/mixer_video.c
42961@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
42962 layer->geo.src.height = layer->geo.src.full_height;
42963
42964 mxr_geometry_dump(mdev, &layer->geo);
42965- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42966+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42967 mxr_geometry_dump(mdev, &layer->geo);
42968 }
42969
42970@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
42971 layer->geo.dst.full_width = mbus_fmt.width;
42972 layer->geo.dst.full_height = mbus_fmt.height;
42973 layer->geo.dst.field = mbus_fmt.field;
42974- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42975+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42976
42977 mxr_geometry_dump(mdev, &layer->geo);
42978 }
42979@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
42980 /* set source size to highest accepted value */
42981 geo->src.full_width = max(geo->dst.full_width, pix->width);
42982 geo->src.full_height = max(geo->dst.full_height, pix->height);
42983- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42984+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42985 mxr_geometry_dump(mdev, &layer->geo);
42986 /* set cropping to total visible screen */
42987 geo->src.width = pix->width;
42988@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
42989 geo->src.x_offset = 0;
42990 geo->src.y_offset = 0;
42991 /* assure consistency of geometry */
42992- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
42993+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
42994 mxr_geometry_dump(mdev, &layer->geo);
42995 /* set full size to lowest possible value */
42996 geo->src.full_width = 0;
42997 geo->src.full_height = 0;
42998- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42999+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43000 mxr_geometry_dump(mdev, &layer->geo);
43001
43002 /* returning results */
43003@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
43004 target->width = s->r.width;
43005 target->height = s->r.height;
43006
43007- layer->ops.fix_geometry(layer, stage, s->flags);
43008+ layer->ops->fix_geometry(layer, stage, s->flags);
43009
43010 /* retrieve update selection rectangle */
43011 res.left = target->x_offset;
43012@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
43013 mxr_output_get(mdev);
43014
43015 mxr_layer_update_output(layer);
43016- layer->ops.format_set(layer);
43017+ layer->ops->format_set(layer);
43018 /* enabling layer in hardware */
43019 spin_lock_irqsave(&layer->enq_slock, flags);
43020 layer->state = MXR_LAYER_STREAMING;
43021 spin_unlock_irqrestore(&layer->enq_slock, flags);
43022
43023- layer->ops.stream_set(layer, MXR_ENABLE);
43024+ layer->ops->stream_set(layer, MXR_ENABLE);
43025 mxr_streamer_get(mdev);
43026
43027 return 0;
43028@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
43029 spin_unlock_irqrestore(&layer->enq_slock, flags);
43030
43031 /* disabling layer in hardware */
43032- layer->ops.stream_set(layer, MXR_DISABLE);
43033+ layer->ops->stream_set(layer, MXR_DISABLE);
43034 /* remove one streamer */
43035 mxr_streamer_put(mdev);
43036 /* allow changes in output configuration */
43037@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
43038
43039 void mxr_layer_release(struct mxr_layer *layer)
43040 {
43041- if (layer->ops.release)
43042- layer->ops.release(layer);
43043+ if (layer->ops->release)
43044+ layer->ops->release(layer);
43045 }
43046
43047 void mxr_base_layer_release(struct mxr_layer *layer)
43048@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
43049
43050 layer->mdev = mdev;
43051 layer->idx = idx;
43052- layer->ops = *ops;
43053+ layer->ops = ops;
43054
43055 spin_lock_init(&layer->enq_slock);
43056 INIT_LIST_HEAD(&layer->enq_list);
43057diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43058index 3d13a63..da31bf1 100644
43059--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43060+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43061@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
43062 {
43063 struct mxr_layer *layer;
43064 int ret;
43065- struct mxr_layer_ops ops = {
43066+ static struct mxr_layer_ops ops = {
43067 .release = mxr_vp_layer_release,
43068 .buffer_set = mxr_vp_buffer_set,
43069 .stream_set = mxr_vp_stream_set,
43070diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
43071index 545c04c..a14bded 100644
43072--- a/drivers/media/radio/radio-cadet.c
43073+++ b/drivers/media/radio/radio-cadet.c
43074@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43075 unsigned char readbuf[RDS_BUFFER];
43076 int i = 0;
43077
43078+ if (count > RDS_BUFFER)
43079+ return -EFAULT;
43080 mutex_lock(&dev->lock);
43081 if (dev->rdsstat == 0)
43082 cadet_start_rds(dev);
43083@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43084 while (i < count && dev->rdsin != dev->rdsout)
43085 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
43086
43087- if (i && copy_to_user(data, readbuf, i))
43088+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
43089 i = -EFAULT;
43090 unlock:
43091 mutex_unlock(&dev->lock);
43092diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
43093index bd4d3a7..ffc0b9d 100644
43094--- a/drivers/media/radio/radio-maxiradio.c
43095+++ b/drivers/media/radio/radio-maxiradio.c
43096@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
43097 /* TEA5757 pin mappings */
43098 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
43099
43100-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
43101+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
43102
43103 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
43104 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
43105diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
43106index 8fa18ab..caee70f 100644
43107--- a/drivers/media/radio/radio-shark.c
43108+++ b/drivers/media/radio/radio-shark.c
43109@@ -79,7 +79,7 @@ struct shark_device {
43110 u32 last_val;
43111 };
43112
43113-static atomic_t shark_instance = ATOMIC_INIT(0);
43114+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43115
43116 static void shark_write_val(struct snd_tea575x *tea, u32 val)
43117 {
43118diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
43119index 9fb6697..f167415 100644
43120--- a/drivers/media/radio/radio-shark2.c
43121+++ b/drivers/media/radio/radio-shark2.c
43122@@ -74,7 +74,7 @@ struct shark_device {
43123 u8 *transfer_buffer;
43124 };
43125
43126-static atomic_t shark_instance = ATOMIC_INIT(0);
43127+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43128
43129 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
43130 {
43131diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
43132index 9c9084c..a9e8dfb 100644
43133--- a/drivers/media/radio/radio-si476x.c
43134+++ b/drivers/media/radio/radio-si476x.c
43135@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
43136 struct si476x_radio *radio;
43137 struct v4l2_ctrl *ctrl;
43138
43139- static atomic_t instance = ATOMIC_INIT(0);
43140+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
43141
43142 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
43143 if (!radio)
43144diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
43145index 1cf382a..c22998c 100644
43146--- a/drivers/media/rc/rc-main.c
43147+++ b/drivers/media/rc/rc-main.c
43148@@ -1030,7 +1030,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
43149 int rc_register_device(struct rc_dev *dev)
43150 {
43151 static bool raw_init = false; /* raw decoders loaded? */
43152- static atomic_t devno = ATOMIC_INIT(0);
43153+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
43154 struct rc_map *rc_map;
43155 const char *path;
43156 int rc;
43157@@ -1061,7 +1061,7 @@ int rc_register_device(struct rc_dev *dev)
43158 */
43159 mutex_lock(&dev->lock);
43160
43161- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
43162+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
43163 dev_set_name(&dev->dev, "rc%ld", dev->devno);
43164 dev_set_drvdata(&dev->dev, dev);
43165 rc = device_add(&dev->dev);
43166diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
43167index 3940bb0..fb3952a 100644
43168--- a/drivers/media/usb/dvb-usb/cxusb.c
43169+++ b/drivers/media/usb/dvb-usb/cxusb.c
43170@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
43171
43172 struct dib0700_adapter_state {
43173 int (*set_param_save) (struct dvb_frontend *);
43174-};
43175+} __no_const;
43176
43177 static int dib7070_set_param_override(struct dvb_frontend *fe)
43178 {
43179diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
43180index 6e237b6..dc25556 100644
43181--- a/drivers/media/usb/dvb-usb/dw2102.c
43182+++ b/drivers/media/usb/dvb-usb/dw2102.c
43183@@ -118,7 +118,7 @@ struct su3000_state {
43184
43185 struct s6x0_state {
43186 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
43187-};
43188+} __no_const;
43189
43190 /* debug */
43191 static int dvb_usb_dw2102_debug;
43192diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43193index 8f7a6a4..59502dd 100644
43194--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43195+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43196@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
43197 __u32 reserved;
43198 };
43199
43200-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43201+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43202 enum v4l2_memory memory)
43203 {
43204 void __user *up_pln;
43205@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43206 return 0;
43207 }
43208
43209-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43210+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43211 enum v4l2_memory memory)
43212 {
43213 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
43214@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
43215 put_user(kp->start_block, &up->start_block) ||
43216 put_user(kp->blocks, &up->blocks) ||
43217 put_user(tmp, &up->edid) ||
43218- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
43219+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
43220 return -EFAULT;
43221 return 0;
43222 }
43223diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
43224index 02d1b63..5fd6b16 100644
43225--- a/drivers/media/v4l2-core/v4l2-device.c
43226+++ b/drivers/media/v4l2-core/v4l2-device.c
43227@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
43228 EXPORT_SYMBOL_GPL(v4l2_device_put);
43229
43230 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
43231- atomic_t *instance)
43232+ atomic_unchecked_t *instance)
43233 {
43234- int num = atomic_inc_return(instance) - 1;
43235+ int num = atomic_inc_return_unchecked(instance) - 1;
43236 int len = strlen(basename);
43237
43238 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
43239diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
43240index 68e6b5e..d8b923e 100644
43241--- a/drivers/media/v4l2-core/v4l2-ioctl.c
43242+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
43243@@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
43244 struct file *file, void *fh, void *p);
43245 } u;
43246 void (*debug)(const void *arg, bool write_only);
43247-};
43248+} __do_const;
43249+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
43250
43251 /* This control needs a priority check */
43252 #define INFO_FL_PRIO (1 << 0)
43253@@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
43254 struct video_device *vfd = video_devdata(file);
43255 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
43256 bool write_only = false;
43257- struct v4l2_ioctl_info default_info;
43258+ v4l2_ioctl_info_no_const default_info;
43259 const struct v4l2_ioctl_info *info;
43260 void *fh = file->private_data;
43261 struct v4l2_fh *vfh = NULL;
43262@@ -2194,7 +2195,7 @@ done:
43263 }
43264
43265 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43266- void * __user *user_ptr, void ***kernel_ptr)
43267+ void __user **user_ptr, void ***kernel_ptr)
43268 {
43269 int ret = 0;
43270
43271@@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43272 ret = -EINVAL;
43273 break;
43274 }
43275- *user_ptr = (void __user *)buf->m.planes;
43276+ *user_ptr = (void __force_user *)buf->m.planes;
43277 *kernel_ptr = (void *)&buf->m.planes;
43278 *array_size = sizeof(struct v4l2_plane) * buf->length;
43279 ret = 1;
43280@@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43281 ret = -EINVAL;
43282 break;
43283 }
43284- *user_ptr = (void __user *)ctrls->controls;
43285+ *user_ptr = (void __force_user *)ctrls->controls;
43286 *kernel_ptr = (void *)&ctrls->controls;
43287 *array_size = sizeof(struct v4l2_ext_control)
43288 * ctrls->count;
43289diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
43290index 767ff4d..c69d259 100644
43291--- a/drivers/message/fusion/mptbase.c
43292+++ b/drivers/message/fusion/mptbase.c
43293@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43294 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
43295 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
43296
43297+#ifdef CONFIG_GRKERNSEC_HIDESYM
43298+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
43299+#else
43300 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
43301 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
43302+#endif
43303+
43304 /*
43305 * Rounding UP to nearest 4-kB boundary here...
43306 */
43307@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43308 ioc->facts.GlobalCredits);
43309
43310 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
43311+#ifdef CONFIG_GRKERNSEC_HIDESYM
43312+ NULL, NULL);
43313+#else
43314 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
43315+#endif
43316 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
43317 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
43318 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
43319diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
43320index dd239bd..689c4f7 100644
43321--- a/drivers/message/fusion/mptsas.c
43322+++ b/drivers/message/fusion/mptsas.c
43323@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
43324 return 0;
43325 }
43326
43327+static inline void
43328+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43329+{
43330+ if (phy_info->port_details) {
43331+ phy_info->port_details->rphy = rphy;
43332+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43333+ ioc->name, rphy));
43334+ }
43335+
43336+ if (rphy) {
43337+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43338+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43339+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43340+ ioc->name, rphy, rphy->dev.release));
43341+ }
43342+}
43343+
43344 /* no mutex */
43345 static void
43346 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
43347@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
43348 return NULL;
43349 }
43350
43351-static inline void
43352-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43353-{
43354- if (phy_info->port_details) {
43355- phy_info->port_details->rphy = rphy;
43356- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43357- ioc->name, rphy));
43358- }
43359-
43360- if (rphy) {
43361- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43362- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43363- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43364- ioc->name, rphy, rphy->dev.release));
43365- }
43366-}
43367-
43368 static inline struct sas_port *
43369 mptsas_get_port(struct mptsas_phyinfo *phy_info)
43370 {
43371diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
43372index 727819c..ad74694 100644
43373--- a/drivers/message/fusion/mptscsih.c
43374+++ b/drivers/message/fusion/mptscsih.c
43375@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
43376
43377 h = shost_priv(SChost);
43378
43379- if (h) {
43380- if (h->info_kbuf == NULL)
43381- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43382- return h->info_kbuf;
43383- h->info_kbuf[0] = '\0';
43384+ if (!h)
43385+ return NULL;
43386
43387- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43388- h->info_kbuf[size-1] = '\0';
43389- }
43390+ if (h->info_kbuf == NULL)
43391+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43392+ return h->info_kbuf;
43393+ h->info_kbuf[0] = '\0';
43394+
43395+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43396+ h->info_kbuf[size-1] = '\0';
43397
43398 return h->info_kbuf;
43399 }
43400diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
43401index b7d87cd..9890039 100644
43402--- a/drivers/message/i2o/i2o_proc.c
43403+++ b/drivers/message/i2o/i2o_proc.c
43404@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
43405 "Array Controller Device"
43406 };
43407
43408-static char *chtostr(char *tmp, u8 *chars, int n)
43409-{
43410- tmp[0] = 0;
43411- return strncat(tmp, (char *)chars, n);
43412-}
43413-
43414 static int i2o_report_query_status(struct seq_file *seq, int block_status,
43415 char *group)
43416 {
43417@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43418 } *result;
43419
43420 i2o_exec_execute_ddm_table ddm_table;
43421- char tmp[28 + 1];
43422
43423 result = kmalloc(sizeof(*result), GFP_KERNEL);
43424 if (!result)
43425@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43426
43427 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
43428 seq_printf(seq, "%-#8x", ddm_table.module_id);
43429- seq_printf(seq, "%-29s",
43430- chtostr(tmp, ddm_table.module_name_version, 28));
43431+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
43432 seq_printf(seq, "%9d ", ddm_table.data_size);
43433 seq_printf(seq, "%8d", ddm_table.code_size);
43434
43435@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43436
43437 i2o_driver_result_table *result;
43438 i2o_driver_store_table *dst;
43439- char tmp[28 + 1];
43440
43441 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
43442 if (result == NULL)
43443@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43444
43445 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
43446 seq_printf(seq, "%-#8x", dst->module_id);
43447- seq_printf(seq, "%-29s",
43448- chtostr(tmp, dst->module_name_version, 28));
43449- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
43450+ seq_printf(seq, "%-.28s", dst->module_name_version);
43451+ seq_printf(seq, "%-.8s", dst->date);
43452 seq_printf(seq, "%8d ", dst->module_size);
43453 seq_printf(seq, "%8d ", dst->mpb_size);
43454 seq_printf(seq, "0x%04x", dst->module_flags);
43455@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43456 // == (allow) 512d bytes (max)
43457 static u16 *work16 = (u16 *) work32;
43458 int token;
43459- char tmp[16 + 1];
43460
43461 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
43462
43463@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43464 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
43465 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
43466 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
43467- seq_printf(seq, "Vendor info : %s\n",
43468- chtostr(tmp, (u8 *) (work32 + 2), 16));
43469- seq_printf(seq, "Product info : %s\n",
43470- chtostr(tmp, (u8 *) (work32 + 6), 16));
43471- seq_printf(seq, "Description : %s\n",
43472- chtostr(tmp, (u8 *) (work32 + 10), 16));
43473- seq_printf(seq, "Product rev. : %s\n",
43474- chtostr(tmp, (u8 *) (work32 + 14), 8));
43475+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
43476+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
43477+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
43478+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
43479
43480 seq_printf(seq, "Serial number : ");
43481 print_serial_number(seq, (u8 *) (work32 + 16),
43482@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43483 u8 pad[256]; // allow up to 256 byte (max) serial number
43484 } result;
43485
43486- char tmp[24 + 1];
43487-
43488 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
43489
43490 if (token < 0) {
43491@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43492 }
43493
43494 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
43495- seq_printf(seq, "Module name : %s\n",
43496- chtostr(tmp, result.module_name, 24));
43497- seq_printf(seq, "Module revision : %s\n",
43498- chtostr(tmp, result.module_rev, 8));
43499+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
43500+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
43501
43502 seq_printf(seq, "Serial number : ");
43503 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
43504@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43505 u8 instance_number[4];
43506 } result;
43507
43508- char tmp[64 + 1];
43509-
43510 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
43511
43512 if (token < 0) {
43513@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43514 return 0;
43515 }
43516
43517- seq_printf(seq, "Device name : %s\n",
43518- chtostr(tmp, result.device_name, 64));
43519- seq_printf(seq, "Service name : %s\n",
43520- chtostr(tmp, result.service_name, 64));
43521- seq_printf(seq, "Physical name : %s\n",
43522- chtostr(tmp, result.physical_location, 64));
43523- seq_printf(seq, "Instance number : %s\n",
43524- chtostr(tmp, result.instance_number, 4));
43525+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
43526+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
43527+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
43528+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
43529
43530 return 0;
43531 }
43532diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
43533index a8c08f3..155fe3d 100644
43534--- a/drivers/message/i2o/iop.c
43535+++ b/drivers/message/i2o/iop.c
43536@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
43537
43538 spin_lock_irqsave(&c->context_list_lock, flags);
43539
43540- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
43541- atomic_inc(&c->context_list_counter);
43542+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
43543+ atomic_inc_unchecked(&c->context_list_counter);
43544
43545- entry->context = atomic_read(&c->context_list_counter);
43546+ entry->context = atomic_read_unchecked(&c->context_list_counter);
43547
43548 list_add(&entry->list, &c->context_list);
43549
43550@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
43551
43552 #if BITS_PER_LONG == 64
43553 spin_lock_init(&c->context_list_lock);
43554- atomic_set(&c->context_list_counter, 0);
43555+ atomic_set_unchecked(&c->context_list_counter, 0);
43556 INIT_LIST_HEAD(&c->context_list);
43557 #endif
43558
43559diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
43560index fcbb2e9..2635e11 100644
43561--- a/drivers/mfd/janz-cmodio.c
43562+++ b/drivers/mfd/janz-cmodio.c
43563@@ -13,6 +13,7 @@
43564
43565 #include <linux/kernel.h>
43566 #include <linux/module.h>
43567+#include <linux/slab.h>
43568 #include <linux/init.h>
43569 #include <linux/pci.h>
43570 #include <linux/interrupt.h>
43571diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
43572index 9aa6d1e..1631bfc 100644
43573--- a/drivers/mfd/twl4030-irq.c
43574+++ b/drivers/mfd/twl4030-irq.c
43575@@ -35,6 +35,7 @@
43576 #include <linux/of.h>
43577 #include <linux/irqdomain.h>
43578 #include <linux/i2c/twl.h>
43579+#include <asm/pgtable.h>
43580
43581 #include "twl-core.h"
43582
43583@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
43584 * Install an irq handler for each of the SIH modules;
43585 * clone dummy irq_chip since PIH can't *do* anything
43586 */
43587- twl4030_irq_chip = dummy_irq_chip;
43588- twl4030_irq_chip.name = "twl4030";
43589+ pax_open_kernel();
43590+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
43591+ *(const char **)&twl4030_irq_chip.name = "twl4030";
43592
43593- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43594+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43595+ pax_close_kernel();
43596
43597 for (i = irq_base; i < irq_end; i++) {
43598 irq_set_chip_and_handler(i, &twl4030_irq_chip,
43599diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
43600index 277a8db..0e0b754 100644
43601--- a/drivers/mfd/twl6030-irq.c
43602+++ b/drivers/mfd/twl6030-irq.c
43603@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
43604 * install an irq handler for each of the modules;
43605 * clone dummy irq_chip since PIH can't *do* anything
43606 */
43607- twl6030_irq_chip = dummy_irq_chip;
43608- twl6030_irq_chip.name = "twl6030";
43609- twl6030_irq_chip.irq_set_type = NULL;
43610- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43611+ pax_open_kernel();
43612+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
43613+ *(const char **)&twl6030_irq_chip.name = "twl6030";
43614+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
43615+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43616+ pax_close_kernel();
43617
43618 for (i = irq_base; i < irq_end; i++) {
43619 irq_set_chip_and_handler(i, &twl6030_irq_chip,
43620diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
43621index f32550a..e3e52a2 100644
43622--- a/drivers/misc/c2port/core.c
43623+++ b/drivers/misc/c2port/core.c
43624@@ -920,7 +920,9 @@ struct c2port_device *c2port_device_register(char *name,
43625 mutex_init(&c2dev->mutex);
43626
43627 /* Create binary file */
43628- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43629+ pax_open_kernel();
43630+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43631+ pax_close_kernel();
43632 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
43633 if (unlikely(ret))
43634 goto error_device_create_bin_file;
43635diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
43636index 36f5d52..32311c3 100644
43637--- a/drivers/misc/kgdbts.c
43638+++ b/drivers/misc/kgdbts.c
43639@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
43640 char before[BREAK_INSTR_SIZE];
43641 char after[BREAK_INSTR_SIZE];
43642
43643- probe_kernel_read(before, (char *)kgdbts_break_test,
43644+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
43645 BREAK_INSTR_SIZE);
43646 init_simple_test();
43647 ts.tst = plant_and_detach_test;
43648@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
43649 /* Activate test with initial breakpoint */
43650 if (!is_early)
43651 kgdb_breakpoint();
43652- probe_kernel_read(after, (char *)kgdbts_break_test,
43653+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
43654 BREAK_INSTR_SIZE);
43655 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
43656 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
43657diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
43658index 036effe..b3a6336 100644
43659--- a/drivers/misc/lis3lv02d/lis3lv02d.c
43660+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
43661@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
43662 * the lid is closed. This leads to interrupts as soon as a little move
43663 * is done.
43664 */
43665- atomic_inc(&lis3->count);
43666+ atomic_inc_unchecked(&lis3->count);
43667
43668 wake_up_interruptible(&lis3->misc_wait);
43669 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
43670@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
43671 if (lis3->pm_dev)
43672 pm_runtime_get_sync(lis3->pm_dev);
43673
43674- atomic_set(&lis3->count, 0);
43675+ atomic_set_unchecked(&lis3->count, 0);
43676 return 0;
43677 }
43678
43679@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
43680 add_wait_queue(&lis3->misc_wait, &wait);
43681 while (true) {
43682 set_current_state(TASK_INTERRUPTIBLE);
43683- data = atomic_xchg(&lis3->count, 0);
43684+ data = atomic_xchg_unchecked(&lis3->count, 0);
43685 if (data)
43686 break;
43687
43688@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
43689 struct lis3lv02d, miscdev);
43690
43691 poll_wait(file, &lis3->misc_wait, wait);
43692- if (atomic_read(&lis3->count))
43693+ if (atomic_read_unchecked(&lis3->count))
43694 return POLLIN | POLLRDNORM;
43695 return 0;
43696 }
43697diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
43698index c439c82..1f20f57 100644
43699--- a/drivers/misc/lis3lv02d/lis3lv02d.h
43700+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
43701@@ -297,7 +297,7 @@ struct lis3lv02d {
43702 struct input_polled_dev *idev; /* input device */
43703 struct platform_device *pdev; /* platform device */
43704 struct regulator_bulk_data regulators[2];
43705- atomic_t count; /* interrupt count after last read */
43706+ atomic_unchecked_t count; /* interrupt count after last read */
43707 union axis_conversion ac; /* hw -> logical axis */
43708 int mapped_btns[3];
43709
43710diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
43711index 2f30bad..c4c13d0 100644
43712--- a/drivers/misc/sgi-gru/gruhandles.c
43713+++ b/drivers/misc/sgi-gru/gruhandles.c
43714@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
43715 unsigned long nsec;
43716
43717 nsec = CLKS2NSEC(clks);
43718- atomic_long_inc(&mcs_op_statistics[op].count);
43719- atomic_long_add(nsec, &mcs_op_statistics[op].total);
43720+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
43721+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
43722 if (mcs_op_statistics[op].max < nsec)
43723 mcs_op_statistics[op].max = nsec;
43724 }
43725diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
43726index 4f76359..cdfcb2e 100644
43727--- a/drivers/misc/sgi-gru/gruprocfs.c
43728+++ b/drivers/misc/sgi-gru/gruprocfs.c
43729@@ -32,9 +32,9 @@
43730
43731 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
43732
43733-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
43734+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
43735 {
43736- unsigned long val = atomic_long_read(v);
43737+ unsigned long val = atomic_long_read_unchecked(v);
43738
43739 seq_printf(s, "%16lu %s\n", val, id);
43740 }
43741@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
43742
43743 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
43744 for (op = 0; op < mcsop_last; op++) {
43745- count = atomic_long_read(&mcs_op_statistics[op].count);
43746- total = atomic_long_read(&mcs_op_statistics[op].total);
43747+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
43748+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
43749 max = mcs_op_statistics[op].max;
43750 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
43751 count ? total / count : 0, max);
43752diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
43753index 5c3ce24..4915ccb 100644
43754--- a/drivers/misc/sgi-gru/grutables.h
43755+++ b/drivers/misc/sgi-gru/grutables.h
43756@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
43757 * GRU statistics.
43758 */
43759 struct gru_stats_s {
43760- atomic_long_t vdata_alloc;
43761- atomic_long_t vdata_free;
43762- atomic_long_t gts_alloc;
43763- atomic_long_t gts_free;
43764- atomic_long_t gms_alloc;
43765- atomic_long_t gms_free;
43766- atomic_long_t gts_double_allocate;
43767- atomic_long_t assign_context;
43768- atomic_long_t assign_context_failed;
43769- atomic_long_t free_context;
43770- atomic_long_t load_user_context;
43771- atomic_long_t load_kernel_context;
43772- atomic_long_t lock_kernel_context;
43773- atomic_long_t unlock_kernel_context;
43774- atomic_long_t steal_user_context;
43775- atomic_long_t steal_kernel_context;
43776- atomic_long_t steal_context_failed;
43777- atomic_long_t nopfn;
43778- atomic_long_t asid_new;
43779- atomic_long_t asid_next;
43780- atomic_long_t asid_wrap;
43781- atomic_long_t asid_reuse;
43782- atomic_long_t intr;
43783- atomic_long_t intr_cbr;
43784- atomic_long_t intr_tfh;
43785- atomic_long_t intr_spurious;
43786- atomic_long_t intr_mm_lock_failed;
43787- atomic_long_t call_os;
43788- atomic_long_t call_os_wait_queue;
43789- atomic_long_t user_flush_tlb;
43790- atomic_long_t user_unload_context;
43791- atomic_long_t user_exception;
43792- atomic_long_t set_context_option;
43793- atomic_long_t check_context_retarget_intr;
43794- atomic_long_t check_context_unload;
43795- atomic_long_t tlb_dropin;
43796- atomic_long_t tlb_preload_page;
43797- atomic_long_t tlb_dropin_fail_no_asid;
43798- atomic_long_t tlb_dropin_fail_upm;
43799- atomic_long_t tlb_dropin_fail_invalid;
43800- atomic_long_t tlb_dropin_fail_range_active;
43801- atomic_long_t tlb_dropin_fail_idle;
43802- atomic_long_t tlb_dropin_fail_fmm;
43803- atomic_long_t tlb_dropin_fail_no_exception;
43804- atomic_long_t tfh_stale_on_fault;
43805- atomic_long_t mmu_invalidate_range;
43806- atomic_long_t mmu_invalidate_page;
43807- atomic_long_t flush_tlb;
43808- atomic_long_t flush_tlb_gru;
43809- atomic_long_t flush_tlb_gru_tgh;
43810- atomic_long_t flush_tlb_gru_zero_asid;
43811+ atomic_long_unchecked_t vdata_alloc;
43812+ atomic_long_unchecked_t vdata_free;
43813+ atomic_long_unchecked_t gts_alloc;
43814+ atomic_long_unchecked_t gts_free;
43815+ atomic_long_unchecked_t gms_alloc;
43816+ atomic_long_unchecked_t gms_free;
43817+ atomic_long_unchecked_t gts_double_allocate;
43818+ atomic_long_unchecked_t assign_context;
43819+ atomic_long_unchecked_t assign_context_failed;
43820+ atomic_long_unchecked_t free_context;
43821+ atomic_long_unchecked_t load_user_context;
43822+ atomic_long_unchecked_t load_kernel_context;
43823+ atomic_long_unchecked_t lock_kernel_context;
43824+ atomic_long_unchecked_t unlock_kernel_context;
43825+ atomic_long_unchecked_t steal_user_context;
43826+ atomic_long_unchecked_t steal_kernel_context;
43827+ atomic_long_unchecked_t steal_context_failed;
43828+ atomic_long_unchecked_t nopfn;
43829+ atomic_long_unchecked_t asid_new;
43830+ atomic_long_unchecked_t asid_next;
43831+ atomic_long_unchecked_t asid_wrap;
43832+ atomic_long_unchecked_t asid_reuse;
43833+ atomic_long_unchecked_t intr;
43834+ atomic_long_unchecked_t intr_cbr;
43835+ atomic_long_unchecked_t intr_tfh;
43836+ atomic_long_unchecked_t intr_spurious;
43837+ atomic_long_unchecked_t intr_mm_lock_failed;
43838+ atomic_long_unchecked_t call_os;
43839+ atomic_long_unchecked_t call_os_wait_queue;
43840+ atomic_long_unchecked_t user_flush_tlb;
43841+ atomic_long_unchecked_t user_unload_context;
43842+ atomic_long_unchecked_t user_exception;
43843+ atomic_long_unchecked_t set_context_option;
43844+ atomic_long_unchecked_t check_context_retarget_intr;
43845+ atomic_long_unchecked_t check_context_unload;
43846+ atomic_long_unchecked_t tlb_dropin;
43847+ atomic_long_unchecked_t tlb_preload_page;
43848+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
43849+ atomic_long_unchecked_t tlb_dropin_fail_upm;
43850+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
43851+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
43852+ atomic_long_unchecked_t tlb_dropin_fail_idle;
43853+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
43854+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
43855+ atomic_long_unchecked_t tfh_stale_on_fault;
43856+ atomic_long_unchecked_t mmu_invalidate_range;
43857+ atomic_long_unchecked_t mmu_invalidate_page;
43858+ atomic_long_unchecked_t flush_tlb;
43859+ atomic_long_unchecked_t flush_tlb_gru;
43860+ atomic_long_unchecked_t flush_tlb_gru_tgh;
43861+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
43862
43863- atomic_long_t copy_gpa;
43864- atomic_long_t read_gpa;
43865+ atomic_long_unchecked_t copy_gpa;
43866+ atomic_long_unchecked_t read_gpa;
43867
43868- atomic_long_t mesq_receive;
43869- atomic_long_t mesq_receive_none;
43870- atomic_long_t mesq_send;
43871- atomic_long_t mesq_send_failed;
43872- atomic_long_t mesq_noop;
43873- atomic_long_t mesq_send_unexpected_error;
43874- atomic_long_t mesq_send_lb_overflow;
43875- atomic_long_t mesq_send_qlimit_reached;
43876- atomic_long_t mesq_send_amo_nacked;
43877- atomic_long_t mesq_send_put_nacked;
43878- atomic_long_t mesq_page_overflow;
43879- atomic_long_t mesq_qf_locked;
43880- atomic_long_t mesq_qf_noop_not_full;
43881- atomic_long_t mesq_qf_switch_head_failed;
43882- atomic_long_t mesq_qf_unexpected_error;
43883- atomic_long_t mesq_noop_unexpected_error;
43884- atomic_long_t mesq_noop_lb_overflow;
43885- atomic_long_t mesq_noop_qlimit_reached;
43886- atomic_long_t mesq_noop_amo_nacked;
43887- atomic_long_t mesq_noop_put_nacked;
43888- atomic_long_t mesq_noop_page_overflow;
43889+ atomic_long_unchecked_t mesq_receive;
43890+ atomic_long_unchecked_t mesq_receive_none;
43891+ atomic_long_unchecked_t mesq_send;
43892+ atomic_long_unchecked_t mesq_send_failed;
43893+ atomic_long_unchecked_t mesq_noop;
43894+ atomic_long_unchecked_t mesq_send_unexpected_error;
43895+ atomic_long_unchecked_t mesq_send_lb_overflow;
43896+ atomic_long_unchecked_t mesq_send_qlimit_reached;
43897+ atomic_long_unchecked_t mesq_send_amo_nacked;
43898+ atomic_long_unchecked_t mesq_send_put_nacked;
43899+ atomic_long_unchecked_t mesq_page_overflow;
43900+ atomic_long_unchecked_t mesq_qf_locked;
43901+ atomic_long_unchecked_t mesq_qf_noop_not_full;
43902+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
43903+ atomic_long_unchecked_t mesq_qf_unexpected_error;
43904+ atomic_long_unchecked_t mesq_noop_unexpected_error;
43905+ atomic_long_unchecked_t mesq_noop_lb_overflow;
43906+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
43907+ atomic_long_unchecked_t mesq_noop_amo_nacked;
43908+ atomic_long_unchecked_t mesq_noop_put_nacked;
43909+ atomic_long_unchecked_t mesq_noop_page_overflow;
43910
43911 };
43912
43913@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
43914 tghop_invalidate, mcsop_last};
43915
43916 struct mcs_op_statistic {
43917- atomic_long_t count;
43918- atomic_long_t total;
43919+ atomic_long_unchecked_t count;
43920+ atomic_long_unchecked_t total;
43921 unsigned long max;
43922 };
43923
43924@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
43925
43926 #define STAT(id) do { \
43927 if (gru_options & OPT_STATS) \
43928- atomic_long_inc(&gru_stats.id); \
43929+ atomic_long_inc_unchecked(&gru_stats.id); \
43930 } while (0)
43931
43932 #ifdef CONFIG_SGI_GRU_DEBUG
43933diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
43934index c862cd4..0d176fe 100644
43935--- a/drivers/misc/sgi-xp/xp.h
43936+++ b/drivers/misc/sgi-xp/xp.h
43937@@ -288,7 +288,7 @@ struct xpc_interface {
43938 xpc_notify_func, void *);
43939 void (*received) (short, int, void *);
43940 enum xp_retval (*partid_to_nasids) (short, void *);
43941-};
43942+} __no_const;
43943
43944 extern struct xpc_interface xpc_interface;
43945
43946diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
43947index b94d5f7..7f494c5 100644
43948--- a/drivers/misc/sgi-xp/xpc.h
43949+++ b/drivers/misc/sgi-xp/xpc.h
43950@@ -835,6 +835,7 @@ struct xpc_arch_operations {
43951 void (*received_payload) (struct xpc_channel *, void *);
43952 void (*notify_senders_of_disconnect) (struct xpc_channel *);
43953 };
43954+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
43955
43956 /* struct xpc_partition act_state values (for XPC HB) */
43957
43958@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
43959 /* found in xpc_main.c */
43960 extern struct device *xpc_part;
43961 extern struct device *xpc_chan;
43962-extern struct xpc_arch_operations xpc_arch_ops;
43963+extern xpc_arch_operations_no_const xpc_arch_ops;
43964 extern int xpc_disengage_timelimit;
43965 extern int xpc_disengage_timedout;
43966 extern int xpc_activate_IRQ_rcvd;
43967diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
43968index 82dc574..8539ab2 100644
43969--- a/drivers/misc/sgi-xp/xpc_main.c
43970+++ b/drivers/misc/sgi-xp/xpc_main.c
43971@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
43972 .notifier_call = xpc_system_die,
43973 };
43974
43975-struct xpc_arch_operations xpc_arch_ops;
43976+xpc_arch_operations_no_const xpc_arch_ops;
43977
43978 /*
43979 * Timer function to enforce the timelimit on the partition disengage.
43980@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
43981
43982 if (((die_args->trapnr == X86_TRAP_MF) ||
43983 (die_args->trapnr == X86_TRAP_XF)) &&
43984- !user_mode_vm(die_args->regs))
43985+ !user_mode(die_args->regs))
43986 xpc_die_deactivate();
43987
43988 break;
43989diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
43990index 837fc73..acb5862 100644
43991--- a/drivers/mmc/core/mmc_ops.c
43992+++ b/drivers/mmc/core/mmc_ops.c
43993@@ -213,7 +213,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
43994 void *data_buf;
43995 int is_on_stack;
43996
43997- is_on_stack = object_is_on_stack(buf);
43998+ is_on_stack = object_starts_on_stack(buf);
43999 if (is_on_stack) {
44000 /*
44001 * dma onto stack is unsafe/nonportable, but callers to this
44002diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
44003index 81b2994..dce857e 100644
44004--- a/drivers/mmc/host/dw_mmc.h
44005+++ b/drivers/mmc/host/dw_mmc.h
44006@@ -203,5 +203,5 @@ struct dw_mci_drv_data {
44007 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
44008 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
44009 int (*parse_dt)(struct dw_mci *host);
44010-};
44011+} __do_const;
44012 #endif /* _DW_MMC_H_ */
44013diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
44014index 926aaf6..8e153e2 100644
44015--- a/drivers/mmc/host/sdhci-s3c.c
44016+++ b/drivers/mmc/host/sdhci-s3c.c
44017@@ -664,9 +664,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
44018 * we can use overriding functions instead of default.
44019 */
44020 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
44021- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44022- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44023- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44024+ pax_open_kernel();
44025+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44026+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44027+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44028+ pax_close_kernel();
44029 }
44030
44031 /* It supports additional host capabilities if needed */
44032diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
44033index 0c8bb6b..6f35deb 100644
44034--- a/drivers/mtd/nand/denali.c
44035+++ b/drivers/mtd/nand/denali.c
44036@@ -24,6 +24,7 @@
44037 #include <linux/slab.h>
44038 #include <linux/mtd/mtd.h>
44039 #include <linux/module.h>
44040+#include <linux/slab.h>
44041
44042 #include "denali.h"
44043
44044diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
44045index 51b9d6a..52af9a7 100644
44046--- a/drivers/mtd/nftlmount.c
44047+++ b/drivers/mtd/nftlmount.c
44048@@ -24,6 +24,7 @@
44049 #include <asm/errno.h>
44050 #include <linux/delay.h>
44051 #include <linux/slab.h>
44052+#include <linux/sched.h>
44053 #include <linux/mtd/mtd.h>
44054 #include <linux/mtd/nand.h>
44055 #include <linux/mtd/nftl.h>
44056diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
44057index f9d5615..99dd95f 100644
44058--- a/drivers/mtd/sm_ftl.c
44059+++ b/drivers/mtd/sm_ftl.c
44060@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
44061 #define SM_CIS_VENDOR_OFFSET 0x59
44062 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
44063 {
44064- struct attribute_group *attr_group;
44065+ attribute_group_no_const *attr_group;
44066 struct attribute **attributes;
44067 struct sm_sysfs_attribute *vendor_attribute;
44068
44069diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
44070index e48cb33..72e73fc 100644
44071--- a/drivers/net/bonding/bond_main.c
44072+++ b/drivers/net/bonding/bond_main.c
44073@@ -4832,7 +4832,7 @@ static unsigned int bond_get_num_tx_queues(void)
44074 return tx_queues;
44075 }
44076
44077-static struct rtnl_link_ops bond_link_ops __read_mostly = {
44078+static struct rtnl_link_ops bond_link_ops = {
44079 .kind = "bond",
44080 .priv_size = sizeof(struct bonding),
44081 .setup = bond_setup,
44082@@ -4957,8 +4957,8 @@ static void __exit bonding_exit(void)
44083
44084 bond_destroy_debugfs();
44085
44086- rtnl_link_unregister(&bond_link_ops);
44087 unregister_pernet_subsys(&bond_net_ops);
44088+ rtnl_link_unregister(&bond_link_ops);
44089
44090 #ifdef CONFIG_NET_POLL_CONTROLLER
44091 /*
44092diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
44093index e1d2643..7f4133b 100644
44094--- a/drivers/net/ethernet/8390/ax88796.c
44095+++ b/drivers/net/ethernet/8390/ax88796.c
44096@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
44097 if (ax->plat->reg_offsets)
44098 ei_local->reg_offset = ax->plat->reg_offsets;
44099 else {
44100+ resource_size_t _mem_size = mem_size;
44101+ do_div(_mem_size, 0x18);
44102 ei_local->reg_offset = ax->reg_offsets;
44103 for (ret = 0; ret < 0x18; ret++)
44104- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
44105+ ax->reg_offsets[ret] = _mem_size * ret;
44106 }
44107
44108 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
44109diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44110index c07a6d0..ca88c45 100644
44111--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44112+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44113@@ -1137,7 +1137,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
44114 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
44115 {
44116 /* RX_MODE controlling object */
44117- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
44118+ bnx2x_init_rx_mode_obj(bp);
44119
44120 /* multicast configuration controlling object */
44121 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
44122diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44123index 8f03c98..dd0ef10 100644
44124--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44125+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44126@@ -2345,15 +2345,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
44127 return rc;
44128 }
44129
44130-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44131- struct bnx2x_rx_mode_obj *o)
44132+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
44133 {
44134 if (CHIP_IS_E1x(bp)) {
44135- o->wait_comp = bnx2x_empty_rx_mode_wait;
44136- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
44137+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
44138+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
44139 } else {
44140- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
44141- o->config_rx_mode = bnx2x_set_rx_mode_e2;
44142+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
44143+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
44144 }
44145 }
44146
44147diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44148index 798dfe9..05d0a44 100644
44149--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44150+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44151@@ -1311,8 +1311,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
44152
44153 /********************* RX MODE ****************/
44154
44155-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44156- struct bnx2x_rx_mode_obj *o);
44157+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
44158
44159 /**
44160 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
44161diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
44162index cd63d11..b67dd78 100644
44163--- a/drivers/net/ethernet/broadcom/tg3.h
44164+++ b/drivers/net/ethernet/broadcom/tg3.h
44165@@ -147,6 +147,7 @@
44166 #define CHIPREV_ID_5750_A0 0x4000
44167 #define CHIPREV_ID_5750_A1 0x4001
44168 #define CHIPREV_ID_5750_A3 0x4003
44169+#define CHIPREV_ID_5750_C1 0x4201
44170 #define CHIPREV_ID_5750_C2 0x4202
44171 #define CHIPREV_ID_5752_A0_HW 0x5000
44172 #define CHIPREV_ID_5752_A0 0x6000
44173diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44174index 8cffcdf..aadf043 100644
44175--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44176+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44177@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
44178 */
44179 struct l2t_skb_cb {
44180 arp_failure_handler_func arp_failure_handler;
44181-};
44182+} __no_const;
44183
44184 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
44185
44186diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
44187index 4c83003..2a2a5b9 100644
44188--- a/drivers/net/ethernet/dec/tulip/de4x5.c
44189+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
44190@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
44191 for (i=0; i<ETH_ALEN; i++) {
44192 tmp.addr[i] = dev->dev_addr[i];
44193 }
44194- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
44195+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
44196 break;
44197
44198 case DE4X5_SET_HWADDR: /* Set the hardware address */
44199@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
44200 spin_lock_irqsave(&lp->lock, flags);
44201 memcpy(&statbuf, &lp->pktStats, ioc->len);
44202 spin_unlock_irqrestore(&lp->lock, flags);
44203- if (copy_to_user(ioc->data, &statbuf, ioc->len))
44204+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
44205 return -EFAULT;
44206 break;
44207 }
44208diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
44209index 3d91a5e..1014702 100644
44210--- a/drivers/net/ethernet/emulex/benet/be_main.c
44211+++ b/drivers/net/ethernet/emulex/benet/be_main.c
44212@@ -469,7 +469,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
44213
44214 if (wrapped)
44215 newacc += 65536;
44216- ACCESS_ONCE(*acc) = newacc;
44217+ ACCESS_ONCE_RW(*acc) = newacc;
44218 }
44219
44220 void populate_erx_stats(struct be_adapter *adapter,
44221diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
44222index 934e1ae..b262e6b 100644
44223--- a/drivers/net/ethernet/faraday/ftgmac100.c
44224+++ b/drivers/net/ethernet/faraday/ftgmac100.c
44225@@ -31,6 +31,8 @@
44226 #include <linux/netdevice.h>
44227 #include <linux/phy.h>
44228 #include <linux/platform_device.h>
44229+#include <linux/interrupt.h>
44230+#include <linux/irqreturn.h>
44231 #include <net/ip.h>
44232
44233 #include "ftgmac100.h"
44234diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
44235index 4658f4c..407d155 100644
44236--- a/drivers/net/ethernet/faraday/ftmac100.c
44237+++ b/drivers/net/ethernet/faraday/ftmac100.c
44238@@ -31,6 +31,8 @@
44239 #include <linux/module.h>
44240 #include <linux/netdevice.h>
44241 #include <linux/platform_device.h>
44242+#include <linux/interrupt.h>
44243+#include <linux/irqreturn.h>
44244
44245 #include "ftmac100.h"
44246
44247diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44248index 331987d..3be1135 100644
44249--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44250+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44251@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
44252 }
44253
44254 /* update the base incval used to calculate frequency adjustment */
44255- ACCESS_ONCE(adapter->base_incval) = incval;
44256+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
44257 smp_mb();
44258
44259 /* need lock to prevent incorrect read while modifying cyclecounter */
44260diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44261index fbe5363..266b4e3 100644
44262--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
44263+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44264@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44265 struct __vxge_hw_fifo *fifo;
44266 struct vxge_hw_fifo_config *config;
44267 u32 txdl_size, txdl_per_memblock;
44268- struct vxge_hw_mempool_cbs fifo_mp_callback;
44269+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
44270+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
44271+ };
44272+
44273 struct __vxge_hw_virtualpath *vpath;
44274
44275 if ((vp == NULL) || (attr == NULL)) {
44276@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44277 goto exit;
44278 }
44279
44280- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
44281-
44282 fifo->mempool =
44283 __vxge_hw_mempool_create(vpath->hldev,
44284 fifo->config->memblock_size,
44285diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44286index 345d987..af69721 100644
44287--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44288+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44289@@ -2011,7 +2011,9 @@ int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
44290 op_mode = QLC_83XX_DEFAULT_OPMODE;
44291
44292 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
44293- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44294+ pax_open_kernel();
44295+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44296+ pax_close_kernel();
44297 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44298 } else {
44299 return -EIO;
44300diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44301index 599d1fd..59868fe 100644
44302--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44303+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44304@@ -191,17 +191,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
44305 case QLCNIC_NON_PRIV_FUNC:
44306 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
44307 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44308- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44309+ pax_open_kernel();
44310+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44311+ pax_close_kernel();
44312 break;
44313 case QLCNIC_PRIV_FUNC:
44314 ahw->op_mode = QLCNIC_PRIV_FUNC;
44315 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
44316- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44317+ pax_open_kernel();
44318+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44319+ pax_close_kernel();
44320 break;
44321 case QLCNIC_MGMT_FUNC:
44322 ahw->op_mode = QLCNIC_MGMT_FUNC;
44323 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44324- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44325+ pax_open_kernel();
44326+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44327+ pax_close_kernel();
44328 break;
44329 default:
44330 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
44331diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
44332index 85e5c97..76f97ec 100644
44333--- a/drivers/net/ethernet/realtek/r8169.c
44334+++ b/drivers/net/ethernet/realtek/r8169.c
44335@@ -759,22 +759,22 @@ struct rtl8169_private {
44336 struct mdio_ops {
44337 void (*write)(struct rtl8169_private *, int, int);
44338 int (*read)(struct rtl8169_private *, int);
44339- } mdio_ops;
44340+ } __no_const mdio_ops;
44341
44342 struct pll_power_ops {
44343 void (*down)(struct rtl8169_private *);
44344 void (*up)(struct rtl8169_private *);
44345- } pll_power_ops;
44346+ } __no_const pll_power_ops;
44347
44348 struct jumbo_ops {
44349 void (*enable)(struct rtl8169_private *);
44350 void (*disable)(struct rtl8169_private *);
44351- } jumbo_ops;
44352+ } __no_const jumbo_ops;
44353
44354 struct csi_ops {
44355 void (*write)(struct rtl8169_private *, int, int);
44356 u32 (*read)(struct rtl8169_private *, int);
44357- } csi_ops;
44358+ } __no_const csi_ops;
44359
44360 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
44361 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
44362diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
44363index b495394..0748c54 100644
44364--- a/drivers/net/ethernet/sfc/ptp.c
44365+++ b/drivers/net/ethernet/sfc/ptp.c
44366@@ -535,7 +535,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
44367 (u32)((u64)ptp->start.dma_addr >> 32));
44368
44369 /* Clear flag that signals MC ready */
44370- ACCESS_ONCE(*start) = 0;
44371+ ACCESS_ONCE_RW(*start) = 0;
44372 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
44373 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
44374
44375diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44376index 50617c5..b13724c 100644
44377--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44378+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44379@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
44380
44381 writel(value, ioaddr + MMC_CNTRL);
44382
44383- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44384- MMC_CNTRL, value);
44385+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44386+// MMC_CNTRL, value);
44387 }
44388
44389 /* To mask all all interrupts.*/
44390diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
44391index e6fe0d8..2b7d752 100644
44392--- a/drivers/net/hyperv/hyperv_net.h
44393+++ b/drivers/net/hyperv/hyperv_net.h
44394@@ -101,7 +101,7 @@ struct rndis_device {
44395
44396 enum rndis_device_state state;
44397 bool link_state;
44398- atomic_t new_req_id;
44399+ atomic_unchecked_t new_req_id;
44400
44401 spinlock_t request_lock;
44402 struct list_head req_list;
44403diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
44404index 0775f0a..d4fb316 100644
44405--- a/drivers/net/hyperv/rndis_filter.c
44406+++ b/drivers/net/hyperv/rndis_filter.c
44407@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
44408 * template
44409 */
44410 set = &rndis_msg->msg.set_req;
44411- set->req_id = atomic_inc_return(&dev->new_req_id);
44412+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44413
44414 /* Add to the request list */
44415 spin_lock_irqsave(&dev->request_lock, flags);
44416@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
44417
44418 /* Setup the rndis set */
44419 halt = &request->request_msg.msg.halt_req;
44420- halt->req_id = atomic_inc_return(&dev->new_req_id);
44421+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44422
44423 /* Ignore return since this msg is optional. */
44424 rndis_filter_send_request(dev, request);
44425diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
44426index bf0d55e..82bcfbd1 100644
44427--- a/drivers/net/ieee802154/fakehard.c
44428+++ b/drivers/net/ieee802154/fakehard.c
44429@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
44430 phy->transmit_power = 0xbf;
44431
44432 dev->netdev_ops = &fake_ops;
44433- dev->ml_priv = &fake_mlme;
44434+ dev->ml_priv = (void *)&fake_mlme;
44435
44436 priv = netdev_priv(dev);
44437 priv->phy = phy;
44438diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
44439index 16b43bf..ead0c35 100644
44440--- a/drivers/net/macvlan.c
44441+++ b/drivers/net/macvlan.c
44442@@ -934,13 +934,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
44443 int macvlan_link_register(struct rtnl_link_ops *ops)
44444 {
44445 /* common fields */
44446- ops->priv_size = sizeof(struct macvlan_dev);
44447- ops->validate = macvlan_validate;
44448- ops->maxtype = IFLA_MACVLAN_MAX;
44449- ops->policy = macvlan_policy;
44450- ops->changelink = macvlan_changelink;
44451- ops->get_size = macvlan_get_size;
44452- ops->fill_info = macvlan_fill_info;
44453+ pax_open_kernel();
44454+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
44455+ *(void **)&ops->validate = macvlan_validate;
44456+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
44457+ *(const void **)&ops->policy = macvlan_policy;
44458+ *(void **)&ops->changelink = macvlan_changelink;
44459+ *(void **)&ops->get_size = macvlan_get_size;
44460+ *(void **)&ops->fill_info = macvlan_fill_info;
44461+ pax_close_kernel();
44462
44463 return rtnl_link_register(ops);
44464 };
44465@@ -996,7 +998,7 @@ static int macvlan_device_event(struct notifier_block *unused,
44466 return NOTIFY_DONE;
44467 }
44468
44469-static struct notifier_block macvlan_notifier_block __read_mostly = {
44470+static struct notifier_block macvlan_notifier_block = {
44471 .notifier_call = macvlan_device_event,
44472 };
44473
44474diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
44475index ea53abb..2e4d087 100644
44476--- a/drivers/net/macvtap.c
44477+++ b/drivers/net/macvtap.c
44478@@ -1286,7 +1286,7 @@ static int macvtap_device_event(struct notifier_block *unused,
44479 return NOTIFY_DONE;
44480 }
44481
44482-static struct notifier_block macvtap_notifier_block __read_mostly = {
44483+static struct notifier_block macvtap_notifier_block = {
44484 .notifier_call = macvtap_device_event,
44485 };
44486
44487diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
44488index daec9b0..6428fcb 100644
44489--- a/drivers/net/phy/mdio-bitbang.c
44490+++ b/drivers/net/phy/mdio-bitbang.c
44491@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
44492 struct mdiobb_ctrl *ctrl = bus->priv;
44493
44494 module_put(ctrl->ops->owner);
44495+ mdiobus_unregister(bus);
44496 mdiobus_free(bus);
44497 }
44498 EXPORT_SYMBOL(free_mdio_bitbang);
44499diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
44500index 72ff14b..11d442d 100644
44501--- a/drivers/net/ppp/ppp_generic.c
44502+++ b/drivers/net/ppp/ppp_generic.c
44503@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44504 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
44505 struct ppp_stats stats;
44506 struct ppp_comp_stats cstats;
44507- char *vers;
44508
44509 switch (cmd) {
44510 case SIOCGPPPSTATS:
44511@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44512 break;
44513
44514 case SIOCGPPPVER:
44515- vers = PPP_VERSION;
44516- if (copy_to_user(addr, vers, strlen(vers) + 1))
44517+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
44518 break;
44519 err = 0;
44520 break;
44521diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
44522index 1252d9c..80e660b 100644
44523--- a/drivers/net/slip/slhc.c
44524+++ b/drivers/net/slip/slhc.c
44525@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
44526 register struct tcphdr *thp;
44527 register struct iphdr *ip;
44528 register struct cstate *cs;
44529- int len, hdrlen;
44530+ long len, hdrlen;
44531 unsigned char *cp = icp;
44532
44533 /* We've got a compressed packet; read the change byte */
44534diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
44535index bff7e0b..7315137 100644
44536--- a/drivers/net/team/team.c
44537+++ b/drivers/net/team/team.c
44538@@ -2702,7 +2702,7 @@ static int team_device_event(struct notifier_block *unused,
44539 return NOTIFY_DONE;
44540 }
44541
44542-static struct notifier_block team_notifier_block __read_mostly = {
44543+static struct notifier_block team_notifier_block = {
44544 .notifier_call = team_device_event,
44545 };
44546
44547diff --git a/drivers/net/tun.c b/drivers/net/tun.c
44548index 71af122..b3c20f3 100644
44549--- a/drivers/net/tun.c
44550+++ b/drivers/net/tun.c
44551@@ -1691,11 +1691,11 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
44552 INIT_LIST_HEAD(&tun->disabled);
44553 err = tun_attach(tun, file);
44554 if (err < 0)
44555- goto err_free_dev;
44556+ goto err_free_flow;
44557
44558 err = register_netdevice(tun->dev);
44559 if (err < 0)
44560- goto err_free_dev;
44561+ goto err_detach;
44562
44563 if (device_create_file(&tun->dev->dev, &dev_attr_tun_flags) ||
44564 device_create_file(&tun->dev->dev, &dev_attr_owner) ||
44565@@ -1739,7 +1739,12 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
44566 strcpy(ifr->ifr_name, tun->dev->name);
44567 return 0;
44568
44569- err_free_dev:
44570+err_detach:
44571+ tun_detach_all(dev);
44572+err_free_flow:
44573+ tun_flow_uninit(tun);
44574+ security_tun_dev_free_security(tun->security);
44575+err_free_dev:
44576 free_netdev(dev);
44577 return err;
44578 }
44579@@ -1869,7 +1874,7 @@ unlock:
44580 }
44581
44582 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44583- unsigned long arg, int ifreq_len)
44584+ unsigned long arg, size_t ifreq_len)
44585 {
44586 struct tun_file *tfile = file->private_data;
44587 struct tun_struct *tun;
44588@@ -1881,6 +1886,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44589 int vnet_hdr_sz;
44590 int ret;
44591
44592+ if (ifreq_len > sizeof ifr)
44593+ return -EFAULT;
44594+
44595 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
44596 if (copy_from_user(&ifr, argp, ifreq_len))
44597 return -EFAULT;
44598diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
44599index 86292e6..8d34433 100644
44600--- a/drivers/net/usb/hso.c
44601+++ b/drivers/net/usb/hso.c
44602@@ -71,7 +71,7 @@
44603 #include <asm/byteorder.h>
44604 #include <linux/serial_core.h>
44605 #include <linux/serial.h>
44606-
44607+#include <asm/local.h>
44608
44609 #define MOD_AUTHOR "Option Wireless"
44610 #define MOD_DESCRIPTION "USB High Speed Option driver"
44611@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
44612 struct urb *urb;
44613
44614 urb = serial->rx_urb[0];
44615- if (serial->port.count > 0) {
44616+ if (atomic_read(&serial->port.count) > 0) {
44617 count = put_rxbuf_data(urb, serial);
44618 if (count == -1)
44619 return;
44620@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
44621 DUMP1(urb->transfer_buffer, urb->actual_length);
44622
44623 /* Anyone listening? */
44624- if (serial->port.count == 0)
44625+ if (atomic_read(&serial->port.count) == 0)
44626 return;
44627
44628 if (status == 0) {
44629@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44630 tty_port_tty_set(&serial->port, tty);
44631
44632 /* check for port already opened, if not set the termios */
44633- serial->port.count++;
44634- if (serial->port.count == 1) {
44635+ if (atomic_inc_return(&serial->port.count) == 1) {
44636 serial->rx_state = RX_IDLE;
44637 /* Force default termio settings */
44638 _hso_serial_set_termios(tty, NULL);
44639@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44640 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
44641 if (result) {
44642 hso_stop_serial_device(serial->parent);
44643- serial->port.count--;
44644+ atomic_dec(&serial->port.count);
44645 kref_put(&serial->parent->ref, hso_serial_ref_free);
44646 }
44647 } else {
44648@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
44649
44650 /* reset the rts and dtr */
44651 /* do the actual close */
44652- serial->port.count--;
44653+ atomic_dec(&serial->port.count);
44654
44655- if (serial->port.count <= 0) {
44656- serial->port.count = 0;
44657+ if (atomic_read(&serial->port.count) <= 0) {
44658+ atomic_set(&serial->port.count, 0);
44659 tty_port_tty_set(&serial->port, NULL);
44660 if (!usb_gone)
44661 hso_stop_serial_device(serial->parent);
44662@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
44663
44664 /* the actual setup */
44665 spin_lock_irqsave(&serial->serial_lock, flags);
44666- if (serial->port.count)
44667+ if (atomic_read(&serial->port.count))
44668 _hso_serial_set_termios(tty, old);
44669 else
44670 tty->termios = *old;
44671@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
44672 D1("Pending read interrupt on port %d\n", i);
44673 spin_lock(&serial->serial_lock);
44674 if (serial->rx_state == RX_IDLE &&
44675- serial->port.count > 0) {
44676+ atomic_read(&serial->port.count) > 0) {
44677 /* Setup and send a ctrl req read on
44678 * port i */
44679 if (!serial->rx_urb_filled[0]) {
44680@@ -3062,7 +3061,7 @@ static int hso_resume(struct usb_interface *iface)
44681 /* Start all serial ports */
44682 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
44683 if (serial_table[i] && (serial_table[i]->interface == iface)) {
44684- if (dev2ser(serial_table[i])->port.count) {
44685+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
44686 result =
44687 hso_start_serial_device(serial_table[i], GFP_NOIO);
44688 hso_kick_transmit(dev2ser(serial_table[i]));
44689diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
44690index a79e9d3..78cd4fa 100644
44691--- a/drivers/net/usb/sierra_net.c
44692+++ b/drivers/net/usb/sierra_net.c
44693@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
44694 /* atomic counter partially included in MAC address to make sure 2 devices
44695 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
44696 */
44697-static atomic_t iface_counter = ATOMIC_INIT(0);
44698+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
44699
44700 /*
44701 * SYNC Timer Delay definition used to set the expiry time
44702@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
44703 dev->net->netdev_ops = &sierra_net_device_ops;
44704
44705 /* change MAC addr to include, ifacenum, and to be unique */
44706- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
44707+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
44708 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
44709
44710 /* we will have to manufacture ethernet headers, prepare template */
44711diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
44712index 767f7af..8162b9d 100644
44713--- a/drivers/net/vxlan.c
44714+++ b/drivers/net/vxlan.c
44715@@ -1868,7 +1868,7 @@ nla_put_failure:
44716 return -EMSGSIZE;
44717 }
44718
44719-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
44720+static struct rtnl_link_ops vxlan_link_ops = {
44721 .kind = "vxlan",
44722 .maxtype = IFLA_VXLAN_MAX,
44723 .policy = vxlan_policy,
44724diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
44725index 0b60295..b8bfa5b 100644
44726--- a/drivers/net/wimax/i2400m/rx.c
44727+++ b/drivers/net/wimax/i2400m/rx.c
44728@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
44729 if (i2400m->rx_roq == NULL)
44730 goto error_roq_alloc;
44731
44732- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
44733+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
44734 GFP_KERNEL);
44735 if (rd == NULL) {
44736 result = -ENOMEM;
44737diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
44738index 34c8a33..3261fdc 100644
44739--- a/drivers/net/wireless/at76c50x-usb.c
44740+++ b/drivers/net/wireless/at76c50x-usb.c
44741@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
44742 }
44743
44744 /* Convert timeout from the DFU status to jiffies */
44745-static inline unsigned long at76_get_timeout(struct dfu_status *s)
44746+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
44747 {
44748 return msecs_to_jiffies((s->poll_timeout[2] << 16)
44749 | (s->poll_timeout[1] << 8)
44750diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c
44751index 2b3426b..1f564be 100644
44752--- a/drivers/net/wireless/ath/ath10k/core.c
44753+++ b/drivers/net/wireless/ath/ath10k/core.c
44754@@ -507,7 +507,9 @@ EXPORT_SYMBOL(ath10k_core_destroy);
44755
44756 int ath10k_core_register(struct ath10k *ar)
44757 {
44758- struct ath10k_htc_ops htc_ops;
44759+ static struct ath10k_htc_ops htc_ops = {
44760+ .target_send_suspend_complete = ath10k_send_suspend_complete,
44761+ };
44762 struct bmi_target_info target_info;
44763 int status;
44764
44765@@ -536,8 +538,6 @@ int ath10k_core_register(struct ath10k *ar)
44766 if (status)
44767 goto err;
44768
44769- htc_ops.target_send_suspend_complete = ath10k_send_suspend_complete;
44770-
44771 ar->htc = ath10k_htc_create(ar, &htc_ops);
44772 if (IS_ERR(ar->htc)) {
44773 status = PTR_ERR(ar->htc);
44774diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
44775index 74363c9..237b926 100644
44776--- a/drivers/net/wireless/ath/ath10k/htc.c
44777+++ b/drivers/net/wireless/ath/ath10k/htc.c
44778@@ -963,7 +963,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
44779 struct ath10k_htc *ath10k_htc_create(struct ath10k *ar,
44780 struct ath10k_htc_ops *htc_ops)
44781 {
44782- struct ath10k_hif_cb htc_callbacks;
44783+ static struct ath10k_hif_cb htc_callbacks = {
44784+ .rx_completion = ath10k_htc_rx_completion_handler,
44785+ .tx_completion = ath10k_htc_tx_completion_handler,
44786+ };
44787 struct ath10k_htc_ep *ep = NULL;
44788 struct ath10k_htc *htc = NULL;
44789
44790@@ -979,8 +982,6 @@ struct ath10k_htc *ath10k_htc_create(struct ath10k *ar,
44791 ath10k_htc_reset_endpoint_states(htc);
44792
44793 /* setup HIF layer callbacks */
44794- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
44795- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
44796 htc->ar = ar;
44797
44798 /* Get HIF default pipe for HTC message exchange */
44799diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44800index 8d78253..bebbb68 100644
44801--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44802+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44803@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44804 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
44805 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
44806
44807- ACCESS_ONCE(ads->ds_link) = i->link;
44808- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
44809+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
44810+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
44811
44812 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
44813 ctl6 = SM(i->keytype, AR_EncrType);
44814@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44815
44816 if ((i->is_first || i->is_last) &&
44817 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
44818- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
44819+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
44820 | set11nTries(i->rates, 1)
44821 | set11nTries(i->rates, 2)
44822 | set11nTries(i->rates, 3)
44823 | (i->dur_update ? AR_DurUpdateEna : 0)
44824 | SM(0, AR_BurstDur);
44825
44826- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
44827+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
44828 | set11nRate(i->rates, 1)
44829 | set11nRate(i->rates, 2)
44830 | set11nRate(i->rates, 3);
44831 } else {
44832- ACCESS_ONCE(ads->ds_ctl2) = 0;
44833- ACCESS_ONCE(ads->ds_ctl3) = 0;
44834+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
44835+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
44836 }
44837
44838 if (!i->is_first) {
44839- ACCESS_ONCE(ads->ds_ctl0) = 0;
44840- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44841- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44842+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
44843+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44844+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44845 return;
44846 }
44847
44848@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44849 break;
44850 }
44851
44852- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44853+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44854 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44855 | SM(i->txpower, AR_XmitPower)
44856 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44857@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44858 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
44859 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
44860
44861- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44862- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44863+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44864+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44865
44866 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
44867 return;
44868
44869- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44870+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44871 | set11nPktDurRTSCTS(i->rates, 1);
44872
44873- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44874+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44875 | set11nPktDurRTSCTS(i->rates, 3);
44876
44877- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44878+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44879 | set11nRateFlags(i->rates, 1)
44880 | set11nRateFlags(i->rates, 2)
44881 | set11nRateFlags(i->rates, 3)
44882diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44883index 5163abd..3ada4c2 100644
44884--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44885+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44886@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44887 (i->qcu << AR_TxQcuNum_S) | desc_len;
44888
44889 checksum += val;
44890- ACCESS_ONCE(ads->info) = val;
44891+ ACCESS_ONCE_RW(ads->info) = val;
44892
44893 checksum += i->link;
44894- ACCESS_ONCE(ads->link) = i->link;
44895+ ACCESS_ONCE_RW(ads->link) = i->link;
44896
44897 checksum += i->buf_addr[0];
44898- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
44899+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
44900 checksum += i->buf_addr[1];
44901- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
44902+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
44903 checksum += i->buf_addr[2];
44904- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
44905+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
44906 checksum += i->buf_addr[3];
44907- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
44908+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
44909
44910 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
44911- ACCESS_ONCE(ads->ctl3) = val;
44912+ ACCESS_ONCE_RW(ads->ctl3) = val;
44913 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
44914- ACCESS_ONCE(ads->ctl5) = val;
44915+ ACCESS_ONCE_RW(ads->ctl5) = val;
44916 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
44917- ACCESS_ONCE(ads->ctl7) = val;
44918+ ACCESS_ONCE_RW(ads->ctl7) = val;
44919 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
44920- ACCESS_ONCE(ads->ctl9) = val;
44921+ ACCESS_ONCE_RW(ads->ctl9) = val;
44922
44923 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
44924- ACCESS_ONCE(ads->ctl10) = checksum;
44925+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
44926
44927 if (i->is_first || i->is_last) {
44928- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
44929+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
44930 | set11nTries(i->rates, 1)
44931 | set11nTries(i->rates, 2)
44932 | set11nTries(i->rates, 3)
44933 | (i->dur_update ? AR_DurUpdateEna : 0)
44934 | SM(0, AR_BurstDur);
44935
44936- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
44937+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
44938 | set11nRate(i->rates, 1)
44939 | set11nRate(i->rates, 2)
44940 | set11nRate(i->rates, 3);
44941 } else {
44942- ACCESS_ONCE(ads->ctl13) = 0;
44943- ACCESS_ONCE(ads->ctl14) = 0;
44944+ ACCESS_ONCE_RW(ads->ctl13) = 0;
44945+ ACCESS_ONCE_RW(ads->ctl14) = 0;
44946 }
44947
44948 ads->ctl20 = 0;
44949@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44950
44951 ctl17 = SM(i->keytype, AR_EncrType);
44952 if (!i->is_first) {
44953- ACCESS_ONCE(ads->ctl11) = 0;
44954- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44955- ACCESS_ONCE(ads->ctl15) = 0;
44956- ACCESS_ONCE(ads->ctl16) = 0;
44957- ACCESS_ONCE(ads->ctl17) = ctl17;
44958- ACCESS_ONCE(ads->ctl18) = 0;
44959- ACCESS_ONCE(ads->ctl19) = 0;
44960+ ACCESS_ONCE_RW(ads->ctl11) = 0;
44961+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44962+ ACCESS_ONCE_RW(ads->ctl15) = 0;
44963+ ACCESS_ONCE_RW(ads->ctl16) = 0;
44964+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44965+ ACCESS_ONCE_RW(ads->ctl18) = 0;
44966+ ACCESS_ONCE_RW(ads->ctl19) = 0;
44967 return;
44968 }
44969
44970- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
44971+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
44972 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44973 | SM(i->txpower, AR_XmitPower)
44974 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44975@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44976 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
44977 ctl12 |= SM(val, AR_PAPRDChainMask);
44978
44979- ACCESS_ONCE(ads->ctl12) = ctl12;
44980- ACCESS_ONCE(ads->ctl17) = ctl17;
44981+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
44982+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44983
44984- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
44985+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
44986 | set11nPktDurRTSCTS(i->rates, 1);
44987
44988- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
44989+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
44990 | set11nPktDurRTSCTS(i->rates, 3);
44991
44992- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
44993+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
44994 | set11nRateFlags(i->rates, 1)
44995 | set11nRateFlags(i->rates, 2)
44996 | set11nRateFlags(i->rates, 3)
44997 | SM(i->rtscts_rate, AR_RTSCTSRate);
44998
44999- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
45000+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
45001 }
45002
45003 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
45004diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
45005index cd74b3a..6a28d24 100644
45006--- a/drivers/net/wireless/ath/ath9k/hw.h
45007+++ b/drivers/net/wireless/ath/ath9k/hw.h
45008@@ -652,7 +652,7 @@ struct ath_hw_private_ops {
45009
45010 /* ANI */
45011 void (*ani_cache_ini_regs)(struct ath_hw *ah);
45012-};
45013+} __no_const;
45014
45015 /**
45016 * struct ath_spec_scan - parameters for Atheros spectral scan
45017@@ -721,7 +721,7 @@ struct ath_hw_ops {
45018 struct ath_spec_scan *param);
45019 void (*spectral_scan_trigger)(struct ath_hw *ah);
45020 void (*spectral_scan_wait)(struct ath_hw *ah);
45021-};
45022+} __no_const;
45023
45024 struct ath_nf_limits {
45025 s16 max;
45026diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
45027index 9581d07..84f6a76 100644
45028--- a/drivers/net/wireless/iwlegacy/3945-mac.c
45029+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
45030@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
45031 */
45032 if (il3945_mod_params.disable_hw_scan) {
45033 D_INFO("Disabling hw_scan\n");
45034- il3945_mac_ops.hw_scan = NULL;
45035+ pax_open_kernel();
45036+ *(void **)&il3945_mac_ops.hw_scan = NULL;
45037+ pax_close_kernel();
45038 }
45039
45040 D_INFO("*** LOAD DRIVER ***\n");
45041diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45042index d532948..e0d8bb1 100644
45043--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45044+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45045@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
45046 {
45047 struct iwl_priv *priv = file->private_data;
45048 char buf[64];
45049- int buf_size;
45050+ size_t buf_size;
45051 u32 offset, len;
45052
45053 memset(buf, 0, sizeof(buf));
45054@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
45055 struct iwl_priv *priv = file->private_data;
45056
45057 char buf[8];
45058- int buf_size;
45059+ size_t buf_size;
45060 u32 reset_flag;
45061
45062 memset(buf, 0, sizeof(buf));
45063@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
45064 {
45065 struct iwl_priv *priv = file->private_data;
45066 char buf[8];
45067- int buf_size;
45068+ size_t buf_size;
45069 int ht40;
45070
45071 memset(buf, 0, sizeof(buf));
45072@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
45073 {
45074 struct iwl_priv *priv = file->private_data;
45075 char buf[8];
45076- int buf_size;
45077+ size_t buf_size;
45078 int value;
45079
45080 memset(buf, 0, sizeof(buf));
45081@@ -698,10 +698,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
45082 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
45083 DEBUGFS_READ_FILE_OPS(current_sleep_command);
45084
45085-static const char *fmt_value = " %-30s %10u\n";
45086-static const char *fmt_hex = " %-30s 0x%02X\n";
45087-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
45088-static const char *fmt_header =
45089+static const char fmt_value[] = " %-30s %10u\n";
45090+static const char fmt_hex[] = " %-30s 0x%02X\n";
45091+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
45092+static const char fmt_header[] =
45093 "%-32s current cumulative delta max\n";
45094
45095 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
45096@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
45097 {
45098 struct iwl_priv *priv = file->private_data;
45099 char buf[8];
45100- int buf_size;
45101+ size_t buf_size;
45102 int clear;
45103
45104 memset(buf, 0, sizeof(buf));
45105@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
45106 {
45107 struct iwl_priv *priv = file->private_data;
45108 char buf[8];
45109- int buf_size;
45110+ size_t buf_size;
45111 int trace;
45112
45113 memset(buf, 0, sizeof(buf));
45114@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
45115 {
45116 struct iwl_priv *priv = file->private_data;
45117 char buf[8];
45118- int buf_size;
45119+ size_t buf_size;
45120 int missed;
45121
45122 memset(buf, 0, sizeof(buf));
45123@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
45124
45125 struct iwl_priv *priv = file->private_data;
45126 char buf[8];
45127- int buf_size;
45128+ size_t buf_size;
45129 int plcp;
45130
45131 memset(buf, 0, sizeof(buf));
45132@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
45133
45134 struct iwl_priv *priv = file->private_data;
45135 char buf[8];
45136- int buf_size;
45137+ size_t buf_size;
45138 int flush;
45139
45140 memset(buf, 0, sizeof(buf));
45141@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
45142
45143 struct iwl_priv *priv = file->private_data;
45144 char buf[8];
45145- int buf_size;
45146+ size_t buf_size;
45147 int rts;
45148
45149 if (!priv->cfg->ht_params)
45150@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
45151 {
45152 struct iwl_priv *priv = file->private_data;
45153 char buf[8];
45154- int buf_size;
45155+ size_t buf_size;
45156
45157 memset(buf, 0, sizeof(buf));
45158 buf_size = min(count, sizeof(buf) - 1);
45159@@ -2254,7 +2254,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
45160 struct iwl_priv *priv = file->private_data;
45161 u32 event_log_flag;
45162 char buf[8];
45163- int buf_size;
45164+ size_t buf_size;
45165
45166 /* check that the interface is up */
45167 if (!iwl_is_ready(priv))
45168@@ -2308,7 +2308,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
45169 struct iwl_priv *priv = file->private_data;
45170 char buf[8];
45171 u32 calib_disabled;
45172- int buf_size;
45173+ size_t buf_size;
45174
45175 memset(buf, 0, sizeof(buf));
45176 buf_size = min(count, sizeof(buf) - 1);
45177diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
45178index 1531a4f..21d2641 100644
45179--- a/drivers/net/wireless/iwlwifi/dvm/main.c
45180+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
45181@@ -1180,7 +1180,7 @@ static void iwl_option_config(struct iwl_priv *priv)
45182 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
45183 {
45184 struct iwl_nvm_data *data = priv->nvm_data;
45185- char *debug_msg;
45186+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
45187
45188 if (data->sku_cap_11n_enable &&
45189 !priv->cfg->ht_params) {
45190@@ -1194,7 +1194,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
45191 return -EINVAL;
45192 }
45193
45194- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
45195 IWL_DEBUG_INFO(priv, debug_msg,
45196 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
45197 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
45198diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
45199index 390e2f0..75cfbaf 100644
45200--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
45201+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
45202@@ -1350,7 +1350,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
45203 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
45204
45205 char buf[8];
45206- int buf_size;
45207+ size_t buf_size;
45208 u32 reset_flag;
45209
45210 memset(buf, 0, sizeof(buf));
45211@@ -1371,7 +1371,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
45212 {
45213 struct iwl_trans *trans = file->private_data;
45214 char buf[8];
45215- int buf_size;
45216+ size_t buf_size;
45217 int csr;
45218
45219 memset(buf, 0, sizeof(buf));
45220diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
45221index cb34c78..9fec0dc 100644
45222--- a/drivers/net/wireless/mac80211_hwsim.c
45223+++ b/drivers/net/wireless/mac80211_hwsim.c
45224@@ -2195,25 +2195,19 @@ static int __init init_mac80211_hwsim(void)
45225
45226 if (channels > 1) {
45227 hwsim_if_comb.num_different_channels = channels;
45228- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45229- mac80211_hwsim_ops.cancel_hw_scan =
45230- mac80211_hwsim_cancel_hw_scan;
45231- mac80211_hwsim_ops.sw_scan_start = NULL;
45232- mac80211_hwsim_ops.sw_scan_complete = NULL;
45233- mac80211_hwsim_ops.remain_on_channel =
45234- mac80211_hwsim_roc;
45235- mac80211_hwsim_ops.cancel_remain_on_channel =
45236- mac80211_hwsim_croc;
45237- mac80211_hwsim_ops.add_chanctx =
45238- mac80211_hwsim_add_chanctx;
45239- mac80211_hwsim_ops.remove_chanctx =
45240- mac80211_hwsim_remove_chanctx;
45241- mac80211_hwsim_ops.change_chanctx =
45242- mac80211_hwsim_change_chanctx;
45243- mac80211_hwsim_ops.assign_vif_chanctx =
45244- mac80211_hwsim_assign_vif_chanctx;
45245- mac80211_hwsim_ops.unassign_vif_chanctx =
45246- mac80211_hwsim_unassign_vif_chanctx;
45247+ pax_open_kernel();
45248+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45249+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
45250+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
45251+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
45252+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
45253+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
45254+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
45255+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
45256+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
45257+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
45258+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
45259+ pax_close_kernel();
45260 }
45261
45262 spin_lock_init(&hwsim_radio_lock);
45263diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
45264index 8169a85..7fa3b47 100644
45265--- a/drivers/net/wireless/rndis_wlan.c
45266+++ b/drivers/net/wireless/rndis_wlan.c
45267@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
45268
45269 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
45270
45271- if (rts_threshold < 0 || rts_threshold > 2347)
45272+ if (rts_threshold > 2347)
45273 rts_threshold = 2347;
45274
45275 tmp = cpu_to_le32(rts_threshold);
45276diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
45277index ee3fc57..ed5ddc9 100644
45278--- a/drivers/net/wireless/rt2x00/rt2x00.h
45279+++ b/drivers/net/wireless/rt2x00/rt2x00.h
45280@@ -386,7 +386,7 @@ struct rt2x00_intf {
45281 * for hardware which doesn't support hardware
45282 * sequence counting.
45283 */
45284- atomic_t seqno;
45285+ atomic_unchecked_t seqno;
45286 };
45287
45288 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
45289diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
45290index aa95c6c..a59dd67 100644
45291--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
45292+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
45293@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
45294 * sequence counter given by mac80211.
45295 */
45296 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
45297- seqno = atomic_add_return(0x10, &intf->seqno);
45298+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
45299 else
45300- seqno = atomic_read(&intf->seqno);
45301+ seqno = atomic_read_unchecked(&intf->seqno);
45302
45303 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
45304 hdr->seq_ctrl |= cpu_to_le16(seqno);
45305diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
45306index e2b3d9c..67a5184 100644
45307--- a/drivers/net/wireless/ti/wl1251/sdio.c
45308+++ b/drivers/net/wireless/ti/wl1251/sdio.c
45309@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
45310
45311 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
45312
45313- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45314- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45315+ pax_open_kernel();
45316+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45317+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45318+ pax_close_kernel();
45319
45320 wl1251_info("using dedicated interrupt line");
45321 } else {
45322- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45323- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45324+ pax_open_kernel();
45325+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45326+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45327+ pax_close_kernel();
45328
45329 wl1251_info("using SDIO interrupt");
45330 }
45331diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
45332index 1c627da..69f7d17 100644
45333--- a/drivers/net/wireless/ti/wl12xx/main.c
45334+++ b/drivers/net/wireless/ti/wl12xx/main.c
45335@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45336 sizeof(wl->conf.mem));
45337
45338 /* read data preparation is only needed by wl127x */
45339- wl->ops->prepare_read = wl127x_prepare_read;
45340+ pax_open_kernel();
45341+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45342+ pax_close_kernel();
45343
45344 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45345 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45346@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45347 sizeof(wl->conf.mem));
45348
45349 /* read data preparation is only needed by wl127x */
45350- wl->ops->prepare_read = wl127x_prepare_read;
45351+ pax_open_kernel();
45352+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45353+ pax_close_kernel();
45354
45355 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45356 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45357diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
45358index 7aa0eb8..5a9ef38 100644
45359--- a/drivers/net/wireless/ti/wl18xx/main.c
45360+++ b/drivers/net/wireless/ti/wl18xx/main.c
45361@@ -1730,8 +1730,10 @@ static int wl18xx_setup(struct wl1271 *wl)
45362 }
45363
45364 if (!checksum_param) {
45365- wl18xx_ops.set_rx_csum = NULL;
45366- wl18xx_ops.init_vif = NULL;
45367+ pax_open_kernel();
45368+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
45369+ *(void **)&wl18xx_ops.init_vif = NULL;
45370+ pax_close_kernel();
45371 }
45372
45373 /* Enable 11a Band only if we have 5G antennas */
45374diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
45375index 7ef0b4a..ff65c28 100644
45376--- a/drivers/net/wireless/zd1211rw/zd_usb.c
45377+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
45378@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
45379 {
45380 struct zd_usb *usb = urb->context;
45381 struct zd_usb_interrupt *intr = &usb->intr;
45382- int len;
45383+ unsigned int len;
45384 u16 int_num;
45385
45386 ZD_ASSERT(in_interrupt());
45387diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
45388index d93b2b6..ae50401 100644
45389--- a/drivers/oprofile/buffer_sync.c
45390+++ b/drivers/oprofile/buffer_sync.c
45391@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
45392 if (cookie == NO_COOKIE)
45393 offset = pc;
45394 if (cookie == INVALID_COOKIE) {
45395- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45396+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45397 offset = pc;
45398 }
45399 if (cookie != last_cookie) {
45400@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
45401 /* add userspace sample */
45402
45403 if (!mm) {
45404- atomic_inc(&oprofile_stats.sample_lost_no_mm);
45405+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
45406 return 0;
45407 }
45408
45409 cookie = lookup_dcookie(mm, s->eip, &offset);
45410
45411 if (cookie == INVALID_COOKIE) {
45412- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45413+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45414 return 0;
45415 }
45416
45417@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
45418 /* ignore backtraces if failed to add a sample */
45419 if (state == sb_bt_start) {
45420 state = sb_bt_ignore;
45421- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
45422+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
45423 }
45424 }
45425 release_mm(mm);
45426diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
45427index c0cc4e7..44d4e54 100644
45428--- a/drivers/oprofile/event_buffer.c
45429+++ b/drivers/oprofile/event_buffer.c
45430@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
45431 }
45432
45433 if (buffer_pos == buffer_size) {
45434- atomic_inc(&oprofile_stats.event_lost_overflow);
45435+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
45436 return;
45437 }
45438
45439diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
45440index ed2c3ec..deda85a 100644
45441--- a/drivers/oprofile/oprof.c
45442+++ b/drivers/oprofile/oprof.c
45443@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
45444 if (oprofile_ops.switch_events())
45445 return;
45446
45447- atomic_inc(&oprofile_stats.multiplex_counter);
45448+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
45449 start_switch_worker();
45450 }
45451
45452diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
45453index 84a208d..d61b0a1 100644
45454--- a/drivers/oprofile/oprofile_files.c
45455+++ b/drivers/oprofile/oprofile_files.c
45456@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
45457
45458 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
45459
45460-static ssize_t timeout_read(struct file *file, char __user *buf,
45461+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
45462 size_t count, loff_t *offset)
45463 {
45464 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
45465diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
45466index 917d28e..d62d981 100644
45467--- a/drivers/oprofile/oprofile_stats.c
45468+++ b/drivers/oprofile/oprofile_stats.c
45469@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
45470 cpu_buf->sample_invalid_eip = 0;
45471 }
45472
45473- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
45474- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
45475- atomic_set(&oprofile_stats.event_lost_overflow, 0);
45476- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
45477- atomic_set(&oprofile_stats.multiplex_counter, 0);
45478+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
45479+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
45480+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
45481+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
45482+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
45483 }
45484
45485
45486diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
45487index 38b6fc0..b5cbfce 100644
45488--- a/drivers/oprofile/oprofile_stats.h
45489+++ b/drivers/oprofile/oprofile_stats.h
45490@@ -13,11 +13,11 @@
45491 #include <linux/atomic.h>
45492
45493 struct oprofile_stat_struct {
45494- atomic_t sample_lost_no_mm;
45495- atomic_t sample_lost_no_mapping;
45496- atomic_t bt_lost_no_mapping;
45497- atomic_t event_lost_overflow;
45498- atomic_t multiplex_counter;
45499+ atomic_unchecked_t sample_lost_no_mm;
45500+ atomic_unchecked_t sample_lost_no_mapping;
45501+ atomic_unchecked_t bt_lost_no_mapping;
45502+ atomic_unchecked_t event_lost_overflow;
45503+ atomic_unchecked_t multiplex_counter;
45504 };
45505
45506 extern struct oprofile_stat_struct oprofile_stats;
45507diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
45508index 7c12d9c..558bf3bb 100644
45509--- a/drivers/oprofile/oprofilefs.c
45510+++ b/drivers/oprofile/oprofilefs.c
45511@@ -190,7 +190,7 @@ static const struct file_operations atomic_ro_fops = {
45512
45513
45514 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
45515- char const *name, atomic_t *val)
45516+ char const *name, atomic_unchecked_t *val)
45517 {
45518 return __oprofilefs_create_file(sb, root, name,
45519 &atomic_ro_fops, 0444, val);
45520diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
45521index 61be1d9..dec05d7 100644
45522--- a/drivers/oprofile/timer_int.c
45523+++ b/drivers/oprofile/timer_int.c
45524@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
45525 return NOTIFY_OK;
45526 }
45527
45528-static struct notifier_block __refdata oprofile_cpu_notifier = {
45529+static struct notifier_block oprofile_cpu_notifier = {
45530 .notifier_call = oprofile_cpu_notify,
45531 };
45532
45533diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
45534index 92ed045..62d39bd7 100644
45535--- a/drivers/parport/procfs.c
45536+++ b/drivers/parport/procfs.c
45537@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
45538
45539 *ppos += len;
45540
45541- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
45542+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
45543 }
45544
45545 #ifdef CONFIG_PARPORT_1284
45546@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
45547
45548 *ppos += len;
45549
45550- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
45551+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
45552 }
45553 #endif /* IEEE1284.3 support. */
45554
45555diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
45556index c35e8ad..fc33beb 100644
45557--- a/drivers/pci/hotplug/acpiphp_ibm.c
45558+++ b/drivers/pci/hotplug/acpiphp_ibm.c
45559@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
45560 goto init_cleanup;
45561 }
45562
45563- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45564+ pax_open_kernel();
45565+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45566+ pax_close_kernel();
45567 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
45568
45569 return retval;
45570diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
45571index a6a71c4..c91097b 100644
45572--- a/drivers/pci/hotplug/cpcihp_generic.c
45573+++ b/drivers/pci/hotplug/cpcihp_generic.c
45574@@ -73,7 +73,6 @@ static u16 port;
45575 static unsigned int enum_bit;
45576 static u8 enum_mask;
45577
45578-static struct cpci_hp_controller_ops generic_hpc_ops;
45579 static struct cpci_hp_controller generic_hpc;
45580
45581 static int __init validate_parameters(void)
45582@@ -139,6 +138,10 @@ static int query_enum(void)
45583 return ((value & enum_mask) == enum_mask);
45584 }
45585
45586+static struct cpci_hp_controller_ops generic_hpc_ops = {
45587+ .query_enum = query_enum,
45588+};
45589+
45590 static int __init cpcihp_generic_init(void)
45591 {
45592 int status;
45593@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
45594 pci_dev_put(dev);
45595
45596 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
45597- generic_hpc_ops.query_enum = query_enum;
45598 generic_hpc.ops = &generic_hpc_ops;
45599
45600 status = cpci_hp_register_controller(&generic_hpc);
45601diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
45602index 449b4bb..257e2e8 100644
45603--- a/drivers/pci/hotplug/cpcihp_zt5550.c
45604+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
45605@@ -59,7 +59,6 @@
45606 /* local variables */
45607 static bool debug;
45608 static bool poll;
45609-static struct cpci_hp_controller_ops zt5550_hpc_ops;
45610 static struct cpci_hp_controller zt5550_hpc;
45611
45612 /* Primary cPCI bus bridge device */
45613@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
45614 return 0;
45615 }
45616
45617+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
45618+ .query_enum = zt5550_hc_query_enum,
45619+};
45620+
45621 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
45622 {
45623 int status;
45624@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
45625 dbg("returned from zt5550_hc_config");
45626
45627 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
45628- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
45629 zt5550_hpc.ops = &zt5550_hpc_ops;
45630 if(!poll) {
45631 zt5550_hpc.irq = hc_dev->irq;
45632 zt5550_hpc.irq_flags = IRQF_SHARED;
45633 zt5550_hpc.dev_id = hc_dev;
45634
45635- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45636- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45637- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45638+ pax_open_kernel();
45639+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45640+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45641+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45642+ pax_open_kernel();
45643 } else {
45644 info("using ENUM# polling mode");
45645 }
45646diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
45647index 76ba8a1..20ca857 100644
45648--- a/drivers/pci/hotplug/cpqphp_nvram.c
45649+++ b/drivers/pci/hotplug/cpqphp_nvram.c
45650@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
45651
45652 void compaq_nvram_init (void __iomem *rom_start)
45653 {
45654+
45655+#ifndef CONFIG_PAX_KERNEXEC
45656 if (rom_start) {
45657 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
45658 }
45659+#endif
45660+
45661 dbg("int15 entry = %p\n", compaq_int15_entry_point);
45662
45663 /* initialize our int15 lock */
45664diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
45665index ec20f74..c1d961e 100644
45666--- a/drivers/pci/hotplug/pci_hotplug_core.c
45667+++ b/drivers/pci/hotplug/pci_hotplug_core.c
45668@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
45669 return -EINVAL;
45670 }
45671
45672- slot->ops->owner = owner;
45673- slot->ops->mod_name = mod_name;
45674+ pax_open_kernel();
45675+ *(struct module **)&slot->ops->owner = owner;
45676+ *(const char **)&slot->ops->mod_name = mod_name;
45677+ pax_close_kernel();
45678
45679 mutex_lock(&pci_hp_mutex);
45680 /*
45681diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
45682index 7d72c5e..edce02c 100644
45683--- a/drivers/pci/hotplug/pciehp_core.c
45684+++ b/drivers/pci/hotplug/pciehp_core.c
45685@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
45686 struct slot *slot = ctrl->slot;
45687 struct hotplug_slot *hotplug = NULL;
45688 struct hotplug_slot_info *info = NULL;
45689- struct hotplug_slot_ops *ops = NULL;
45690+ hotplug_slot_ops_no_const *ops = NULL;
45691 char name[SLOT_NAME_SIZE];
45692 int retval = -ENOMEM;
45693
45694diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
45695index c0dbe1f..94cf3d8 100644
45696--- a/drivers/pci/pci-sysfs.c
45697+++ b/drivers/pci/pci-sysfs.c
45698@@ -1073,7 +1073,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
45699 {
45700 /* allocate attribute structure, piggyback attribute name */
45701 int name_len = write_combine ? 13 : 10;
45702- struct bin_attribute *res_attr;
45703+ bin_attribute_no_const *res_attr;
45704 int retval;
45705
45706 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
45707@@ -1258,7 +1258,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
45708 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
45709 {
45710 int retval;
45711- struct bin_attribute *attr;
45712+ bin_attribute_no_const *attr;
45713
45714 /* If the device has VPD, try to expose it in sysfs. */
45715 if (dev->vpd) {
45716@@ -1305,7 +1305,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
45717 {
45718 int retval;
45719 int rom_size = 0;
45720- struct bin_attribute *attr;
45721+ bin_attribute_no_const *attr;
45722
45723 if (!sysfs_initialized)
45724 return -EACCES;
45725diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
45726index d1182c4..2a138ec 100644
45727--- a/drivers/pci/pci.h
45728+++ b/drivers/pci/pci.h
45729@@ -92,7 +92,7 @@ struct pci_vpd_ops {
45730 struct pci_vpd {
45731 unsigned int len;
45732 const struct pci_vpd_ops *ops;
45733- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
45734+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
45735 };
45736
45737 int pci_vpd_pci22_init(struct pci_dev *dev);
45738diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
45739index 403a443..034e050 100644
45740--- a/drivers/pci/pcie/aspm.c
45741+++ b/drivers/pci/pcie/aspm.c
45742@@ -27,9 +27,9 @@
45743 #define MODULE_PARAM_PREFIX "pcie_aspm."
45744
45745 /* Note: those are not register definitions */
45746-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
45747-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
45748-#define ASPM_STATE_L1 (4) /* L1 state */
45749+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
45750+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
45751+#define ASPM_STATE_L1 (4U) /* L1 state */
45752 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
45753 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
45754
45755diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
45756index 46ada5c..20da716 100644
45757--- a/drivers/pci/probe.c
45758+++ b/drivers/pci/probe.c
45759@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
45760 struct pci_bus_region region, inverted_region;
45761 bool bar_too_big = false, bar_disabled = false;
45762
45763- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
45764+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
45765
45766 /* No printks while decoding is disabled! */
45767 if (!dev->mmio_always_on) {
45768diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
45769index cdc7836..528635c 100644
45770--- a/drivers/pci/proc.c
45771+++ b/drivers/pci/proc.c
45772@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
45773 static int __init pci_proc_init(void)
45774 {
45775 struct pci_dev *dev = NULL;
45776+
45777+#ifdef CONFIG_GRKERNSEC_PROC_ADD
45778+#ifdef CONFIG_GRKERNSEC_PROC_USER
45779+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
45780+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45781+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
45782+#endif
45783+#else
45784 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
45785+#endif
45786 proc_create("devices", 0, proc_bus_pci_dir,
45787 &proc_bus_pci_dev_operations);
45788 proc_initialized = 1;
45789diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
45790index 3e5b4497..dcdfb70 100644
45791--- a/drivers/platform/x86/chromeos_laptop.c
45792+++ b/drivers/platform/x86/chromeos_laptop.c
45793@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
45794 return 0;
45795 }
45796
45797-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
45798+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
45799 {
45800 .ident = "Samsung Series 5 550 - Touchpad",
45801 .matches = {
45802diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
45803index 62f8030..c7f2a45 100644
45804--- a/drivers/platform/x86/msi-laptop.c
45805+++ b/drivers/platform/x86/msi-laptop.c
45806@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
45807
45808 if (!quirks->ec_read_only) {
45809 /* allow userland write sysfs file */
45810- dev_attr_bluetooth.store = store_bluetooth;
45811- dev_attr_wlan.store = store_wlan;
45812- dev_attr_threeg.store = store_threeg;
45813- dev_attr_bluetooth.attr.mode |= S_IWUSR;
45814- dev_attr_wlan.attr.mode |= S_IWUSR;
45815- dev_attr_threeg.attr.mode |= S_IWUSR;
45816+ pax_open_kernel();
45817+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
45818+ *(void **)&dev_attr_wlan.store = store_wlan;
45819+ *(void **)&dev_attr_threeg.store = store_threeg;
45820+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
45821+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
45822+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
45823+ pax_close_kernel();
45824 }
45825
45826 /* disable hardware control by fn key */
45827diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
45828index 3a1b6bf..b453930 100644
45829--- a/drivers/platform/x86/sony-laptop.c
45830+++ b/drivers/platform/x86/sony-laptop.c
45831@@ -2486,7 +2486,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
45832 }
45833
45834 /* High speed charging function */
45835-static struct device_attribute *hsc_handle;
45836+static device_attribute_no_const *hsc_handle;
45837
45838 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
45839 struct device_attribute *attr,
45840diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
45841index 54d31c0..3f896d3 100644
45842--- a/drivers/platform/x86/thinkpad_acpi.c
45843+++ b/drivers/platform/x86/thinkpad_acpi.c
45844@@ -2093,7 +2093,7 @@ static int hotkey_mask_get(void)
45845 return 0;
45846 }
45847
45848-void static hotkey_mask_warn_incomplete_mask(void)
45849+static void hotkey_mask_warn_incomplete_mask(void)
45850 {
45851 /* log only what the user can fix... */
45852 const u32 wantedmask = hotkey_driver_mask &
45853@@ -2324,11 +2324,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
45854 }
45855 }
45856
45857-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45858- struct tp_nvram_state *newn,
45859- const u32 event_mask)
45860-{
45861-
45862 #define TPACPI_COMPARE_KEY(__scancode, __member) \
45863 do { \
45864 if ((event_mask & (1 << __scancode)) && \
45865@@ -2342,36 +2337,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45866 tpacpi_hotkey_send_key(__scancode); \
45867 } while (0)
45868
45869- void issue_volchange(const unsigned int oldvol,
45870- const unsigned int newvol)
45871- {
45872- unsigned int i = oldvol;
45873+static void issue_volchange(const unsigned int oldvol,
45874+ const unsigned int newvol,
45875+ const u32 event_mask)
45876+{
45877+ unsigned int i = oldvol;
45878
45879- while (i > newvol) {
45880- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45881- i--;
45882- }
45883- while (i < newvol) {
45884- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45885- i++;
45886- }
45887+ while (i > newvol) {
45888+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45889+ i--;
45890 }
45891+ while (i < newvol) {
45892+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45893+ i++;
45894+ }
45895+}
45896
45897- void issue_brightnesschange(const unsigned int oldbrt,
45898- const unsigned int newbrt)
45899- {
45900- unsigned int i = oldbrt;
45901+static void issue_brightnesschange(const unsigned int oldbrt,
45902+ const unsigned int newbrt,
45903+ const u32 event_mask)
45904+{
45905+ unsigned int i = oldbrt;
45906
45907- while (i > newbrt) {
45908- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45909- i--;
45910- }
45911- while (i < newbrt) {
45912- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45913- i++;
45914- }
45915+ while (i > newbrt) {
45916+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45917+ i--;
45918+ }
45919+ while (i < newbrt) {
45920+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45921+ i++;
45922 }
45923+}
45924
45925+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45926+ struct tp_nvram_state *newn,
45927+ const u32 event_mask)
45928+{
45929 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
45930 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
45931 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
45932@@ -2405,7 +2406,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45933 oldn->volume_level != newn->volume_level) {
45934 /* recently muted, or repeated mute keypress, or
45935 * multiple presses ending in mute */
45936- issue_volchange(oldn->volume_level, newn->volume_level);
45937+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45938 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
45939 }
45940 } else {
45941@@ -2415,7 +2416,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45942 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45943 }
45944 if (oldn->volume_level != newn->volume_level) {
45945- issue_volchange(oldn->volume_level, newn->volume_level);
45946+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45947 } else if (oldn->volume_toggle != newn->volume_toggle) {
45948 /* repeated vol up/down keypress at end of scale ? */
45949 if (newn->volume_level == 0)
45950@@ -2428,7 +2429,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45951 /* handle brightness */
45952 if (oldn->brightness_level != newn->brightness_level) {
45953 issue_brightnesschange(oldn->brightness_level,
45954- newn->brightness_level);
45955+ newn->brightness_level,
45956+ event_mask);
45957 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
45958 /* repeated key presses that didn't change state */
45959 if (newn->brightness_level == 0)
45960@@ -2437,10 +2439,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45961 && !tp_features.bright_unkfw)
45962 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45963 }
45964+}
45965
45966 #undef TPACPI_COMPARE_KEY
45967 #undef TPACPI_MAY_SEND_KEY
45968-}
45969
45970 /*
45971 * Polling driver
45972diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
45973index 769d265..a3a05ca 100644
45974--- a/drivers/pnp/pnpbios/bioscalls.c
45975+++ b/drivers/pnp/pnpbios/bioscalls.c
45976@@ -58,7 +58,7 @@ do { \
45977 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
45978 } while(0)
45979
45980-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
45981+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
45982 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
45983
45984 /*
45985@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
45986
45987 cpu = get_cpu();
45988 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
45989+
45990+ pax_open_kernel();
45991 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
45992+ pax_close_kernel();
45993
45994 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
45995 spin_lock_irqsave(&pnp_bios_lock, flags);
45996@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
45997 :"memory");
45998 spin_unlock_irqrestore(&pnp_bios_lock, flags);
45999
46000+ pax_open_kernel();
46001 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
46002+ pax_close_kernel();
46003+
46004 put_cpu();
46005
46006 /* If we get here and this is set then the PnP BIOS faulted on us. */
46007@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
46008 return status;
46009 }
46010
46011-void pnpbios_calls_init(union pnp_bios_install_struct *header)
46012+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
46013 {
46014 int i;
46015
46016@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
46017 pnp_bios_callpoint.offset = header->fields.pm16offset;
46018 pnp_bios_callpoint.segment = PNP_CS16;
46019
46020+ pax_open_kernel();
46021+
46022 for_each_possible_cpu(i) {
46023 struct desc_struct *gdt = get_cpu_gdt_table(i);
46024 if (!gdt)
46025@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
46026 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
46027 (unsigned long)__va(header->fields.pm16dseg));
46028 }
46029+
46030+ pax_close_kernel();
46031 }
46032diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
46033index d95e101..67f0c3f 100644
46034--- a/drivers/pnp/resource.c
46035+++ b/drivers/pnp/resource.c
46036@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
46037 return 1;
46038
46039 /* check if the resource is valid */
46040- if (*irq < 0 || *irq > 15)
46041+ if (*irq > 15)
46042 return 0;
46043
46044 /* check if the resource is reserved */
46045@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
46046 return 1;
46047
46048 /* check if the resource is valid */
46049- if (*dma < 0 || *dma == 4 || *dma > 7)
46050+ if (*dma == 4 || *dma > 7)
46051 return 0;
46052
46053 /* check if the resource is reserved */
46054diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
46055index 0c52e2a..3421ab7 100644
46056--- a/drivers/power/pda_power.c
46057+++ b/drivers/power/pda_power.c
46058@@ -37,7 +37,11 @@ static int polling;
46059
46060 #if IS_ENABLED(CONFIG_USB_PHY)
46061 static struct usb_phy *transceiver;
46062-static struct notifier_block otg_nb;
46063+static int otg_handle_notification(struct notifier_block *nb,
46064+ unsigned long event, void *unused);
46065+static struct notifier_block otg_nb = {
46066+ .notifier_call = otg_handle_notification
46067+};
46068 #endif
46069
46070 static struct regulator *ac_draw;
46071@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
46072
46073 #if IS_ENABLED(CONFIG_USB_PHY)
46074 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
46075- otg_nb.notifier_call = otg_handle_notification;
46076 ret = usb_register_notifier(transceiver, &otg_nb);
46077 if (ret) {
46078 dev_err(dev, "failure to register otg notifier\n");
46079diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
46080index cc439fd..8fa30df 100644
46081--- a/drivers/power/power_supply.h
46082+++ b/drivers/power/power_supply.h
46083@@ -16,12 +16,12 @@ struct power_supply;
46084
46085 #ifdef CONFIG_SYSFS
46086
46087-extern void power_supply_init_attrs(struct device_type *dev_type);
46088+extern void power_supply_init_attrs(void);
46089 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
46090
46091 #else
46092
46093-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
46094+static inline void power_supply_init_attrs(void) {}
46095 #define power_supply_uevent NULL
46096
46097 #endif /* CONFIG_SYSFS */
46098diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
46099index 3b2d5df..3207114 100644
46100--- a/drivers/power/power_supply_core.c
46101+++ b/drivers/power/power_supply_core.c
46102@@ -24,7 +24,10 @@
46103 struct class *power_supply_class;
46104 EXPORT_SYMBOL_GPL(power_supply_class);
46105
46106-static struct device_type power_supply_dev_type;
46107+extern const struct attribute_group *power_supply_attr_groups[];
46108+static struct device_type power_supply_dev_type = {
46109+ .groups = power_supply_attr_groups,
46110+};
46111
46112 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
46113 struct power_supply *supply)
46114@@ -558,7 +561,7 @@ static int __init power_supply_class_init(void)
46115 return PTR_ERR(power_supply_class);
46116
46117 power_supply_class->dev_uevent = power_supply_uevent;
46118- power_supply_init_attrs(&power_supply_dev_type);
46119+ power_supply_init_attrs();
46120
46121 return 0;
46122 }
46123diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
46124index 29178f7..c65f324 100644
46125--- a/drivers/power/power_supply_sysfs.c
46126+++ b/drivers/power/power_supply_sysfs.c
46127@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
46128 .is_visible = power_supply_attr_is_visible,
46129 };
46130
46131-static const struct attribute_group *power_supply_attr_groups[] = {
46132+const struct attribute_group *power_supply_attr_groups[] = {
46133 &power_supply_attr_group,
46134 NULL,
46135 };
46136
46137-void power_supply_init_attrs(struct device_type *dev_type)
46138+void power_supply_init_attrs(void)
46139 {
46140 int i;
46141
46142- dev_type->groups = power_supply_attr_groups;
46143-
46144 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
46145 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
46146 }
46147diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
46148index 288c75a..065bc84 100644
46149--- a/drivers/regulator/core.c
46150+++ b/drivers/regulator/core.c
46151@@ -3544,7 +3544,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
46152 {
46153 const struct regulation_constraints *constraints = NULL;
46154 const struct regulator_init_data *init_data;
46155- static atomic_t regulator_no = ATOMIC_INIT(0);
46156+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
46157 struct regulator_dev *rdev;
46158 struct device *dev;
46159 int ret, i;
46160@@ -3614,7 +3614,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
46161 rdev->dev.of_node = config->of_node;
46162 rdev->dev.parent = dev;
46163 dev_set_name(&rdev->dev, "regulator.%d",
46164- atomic_inc_return(&regulator_no) - 1);
46165+ atomic_inc_return_unchecked(&regulator_no) - 1);
46166 ret = device_register(&rdev->dev);
46167 if (ret != 0) {
46168 put_device(&rdev->dev);
46169diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
46170index d428ef9..fdc0357 100644
46171--- a/drivers/regulator/max8660.c
46172+++ b/drivers/regulator/max8660.c
46173@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
46174 max8660->shadow_regs[MAX8660_OVER1] = 5;
46175 } else {
46176 /* Otherwise devices can be toggled via software */
46177- max8660_dcdc_ops.enable = max8660_dcdc_enable;
46178- max8660_dcdc_ops.disable = max8660_dcdc_disable;
46179+ pax_open_kernel();
46180+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
46181+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
46182+ pax_close_kernel();
46183 }
46184
46185 /*
46186diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
46187index 0c5195a..637a453d 100644
46188--- a/drivers/regulator/max8973-regulator.c
46189+++ b/drivers/regulator/max8973-regulator.c
46190@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
46191 if (!pdata || !pdata->enable_ext_control) {
46192 max->desc.enable_reg = MAX8973_VOUT;
46193 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
46194- max->ops.enable = regulator_enable_regmap;
46195- max->ops.disable = regulator_disable_regmap;
46196- max->ops.is_enabled = regulator_is_enabled_regmap;
46197+ pax_open_kernel();
46198+ *(void **)&max->ops.enable = regulator_enable_regmap;
46199+ *(void **)&max->ops.disable = regulator_disable_regmap;
46200+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
46201+ pax_close_kernel();
46202 }
46203
46204 if (pdata) {
46205diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
46206index 1037e07..e64dea1 100644
46207--- a/drivers/regulator/mc13892-regulator.c
46208+++ b/drivers/regulator/mc13892-regulator.c
46209@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
46210 }
46211 mc13xxx_unlock(mc13892);
46212
46213- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
46214+ pax_open_kernel();
46215+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
46216 = mc13892_vcam_set_mode;
46217- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
46218+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
46219 = mc13892_vcam_get_mode;
46220+ pax_close_kernel();
46221
46222 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
46223 ARRAY_SIZE(mc13892_regulators));
46224diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
46225index be06d71..264aee9 100644
46226--- a/drivers/rtc/rtc-cmos.c
46227+++ b/drivers/rtc/rtc-cmos.c
46228@@ -731,7 +731,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
46229 hpet_rtc_timer_init();
46230
46231 /* export at least the first block of NVRAM */
46232- nvram.size = address_space - NVRAM_OFFSET;
46233+ pax_open_kernel();
46234+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
46235+ pax_close_kernel();
46236 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
46237 if (retval < 0) {
46238 dev_dbg(dev, "can't create nvram file? %d\n", retval);
46239diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
46240index d049393..bb20be0 100644
46241--- a/drivers/rtc/rtc-dev.c
46242+++ b/drivers/rtc/rtc-dev.c
46243@@ -16,6 +16,7 @@
46244 #include <linux/module.h>
46245 #include <linux/rtc.h>
46246 #include <linux/sched.h>
46247+#include <linux/grsecurity.h>
46248 #include "rtc-core.h"
46249
46250 static dev_t rtc_devt;
46251@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
46252 if (copy_from_user(&tm, uarg, sizeof(tm)))
46253 return -EFAULT;
46254
46255+ gr_log_timechange();
46256+
46257 return rtc_set_time(rtc, &tm);
46258
46259 case RTC_PIE_ON:
46260diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
46261index ca18fd1..055e42d 100644
46262--- a/drivers/rtc/rtc-ds1307.c
46263+++ b/drivers/rtc/rtc-ds1307.c
46264@@ -107,7 +107,7 @@ struct ds1307 {
46265 u8 offset; /* register's offset */
46266 u8 regs[11];
46267 u16 nvram_offset;
46268- struct bin_attribute *nvram;
46269+ bin_attribute_no_const *nvram;
46270 enum ds_type type;
46271 unsigned long flags;
46272 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
46273diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
46274index fcb0329..d77b7f2 100644
46275--- a/drivers/rtc/rtc-m48t59.c
46276+++ b/drivers/rtc/rtc-m48t59.c
46277@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
46278 if (IS_ERR(m48t59->rtc))
46279 return PTR_ERR(m48t59->rtc);
46280
46281- m48t59_nvram_attr.size = pdata->offset;
46282+ pax_open_kernel();
46283+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
46284+ pax_close_kernel();
46285
46286 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
46287 if (ret)
46288diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
46289index e693af6..2e525b6 100644
46290--- a/drivers/scsi/bfa/bfa_fcpim.h
46291+++ b/drivers/scsi/bfa/bfa_fcpim.h
46292@@ -36,7 +36,7 @@ struct bfa_iotag_s {
46293
46294 struct bfa_itn_s {
46295 bfa_isr_func_t isr;
46296-};
46297+} __no_const;
46298
46299 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
46300 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
46301diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
46302index 90814fe..4384138 100644
46303--- a/drivers/scsi/bfa/bfa_ioc.h
46304+++ b/drivers/scsi/bfa/bfa_ioc.h
46305@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
46306 bfa_ioc_disable_cbfn_t disable_cbfn;
46307 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
46308 bfa_ioc_reset_cbfn_t reset_cbfn;
46309-};
46310+} __no_const;
46311
46312 /*
46313 * IOC event notification mechanism.
46314@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
46315 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
46316 enum bfi_ioc_state fwstate);
46317 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
46318-};
46319+} __no_const;
46320
46321 /*
46322 * Queue element to wait for room in request queue. FIFO order is
46323diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
46324index c9382d6..6619864 100644
46325--- a/drivers/scsi/fcoe/fcoe_sysfs.c
46326+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
46327@@ -33,8 +33,8 @@
46328 */
46329 #include "libfcoe.h"
46330
46331-static atomic_t ctlr_num;
46332-static atomic_t fcf_num;
46333+static atomic_unchecked_t ctlr_num;
46334+static atomic_unchecked_t fcf_num;
46335
46336 /*
46337 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
46338@@ -681,7 +681,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
46339 if (!ctlr)
46340 goto out;
46341
46342- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
46343+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
46344 ctlr->f = f;
46345 ctlr->mode = FIP_CONN_TYPE_FABRIC;
46346 INIT_LIST_HEAD(&ctlr->fcfs);
46347@@ -898,7 +898,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
46348 fcf->dev.parent = &ctlr->dev;
46349 fcf->dev.bus = &fcoe_bus_type;
46350 fcf->dev.type = &fcoe_fcf_device_type;
46351- fcf->id = atomic_inc_return(&fcf_num) - 1;
46352+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
46353 fcf->state = FCOE_FCF_STATE_UNKNOWN;
46354
46355 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
46356@@ -934,8 +934,8 @@ int __init fcoe_sysfs_setup(void)
46357 {
46358 int error;
46359
46360- atomic_set(&ctlr_num, 0);
46361- atomic_set(&fcf_num, 0);
46362+ atomic_set_unchecked(&ctlr_num, 0);
46363+ atomic_set_unchecked(&fcf_num, 0);
46364
46365 error = bus_register(&fcoe_bus_type);
46366 if (error)
46367diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
46368index df0c3c7..b00e1d0 100644
46369--- a/drivers/scsi/hosts.c
46370+++ b/drivers/scsi/hosts.c
46371@@ -42,7 +42,7 @@
46372 #include "scsi_logging.h"
46373
46374
46375-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46376+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46377
46378
46379 static void scsi_host_cls_release(struct device *dev)
46380@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
46381 * subtract one because we increment first then return, but we need to
46382 * know what the next host number was before increment
46383 */
46384- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
46385+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
46386 shost->dma_channel = 0xff;
46387
46388 /* These three are default values which can be overridden */
46389diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
46390index 7f4f790..b75b92a 100644
46391--- a/drivers/scsi/hpsa.c
46392+++ b/drivers/scsi/hpsa.c
46393@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
46394 unsigned long flags;
46395
46396 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
46397- return h->access.command_completed(h, q);
46398+ return h->access->command_completed(h, q);
46399
46400 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
46401 a = rq->head[rq->current_entry];
46402@@ -3422,7 +3422,7 @@ static void start_io(struct ctlr_info *h)
46403 while (!list_empty(&h->reqQ)) {
46404 c = list_entry(h->reqQ.next, struct CommandList, list);
46405 /* can't do anything if fifo is full */
46406- if ((h->access.fifo_full(h))) {
46407+ if ((h->access->fifo_full(h))) {
46408 dev_warn(&h->pdev->dev, "fifo full\n");
46409 break;
46410 }
46411@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
46412
46413 /* Tell the controller execute command */
46414 spin_unlock_irqrestore(&h->lock, flags);
46415- h->access.submit_command(h, c);
46416+ h->access->submit_command(h, c);
46417 spin_lock_irqsave(&h->lock, flags);
46418 }
46419 spin_unlock_irqrestore(&h->lock, flags);
46420@@ -3452,17 +3452,17 @@ static void start_io(struct ctlr_info *h)
46421
46422 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
46423 {
46424- return h->access.command_completed(h, q);
46425+ return h->access->command_completed(h, q);
46426 }
46427
46428 static inline bool interrupt_pending(struct ctlr_info *h)
46429 {
46430- return h->access.intr_pending(h);
46431+ return h->access->intr_pending(h);
46432 }
46433
46434 static inline long interrupt_not_for_us(struct ctlr_info *h)
46435 {
46436- return (h->access.intr_pending(h) == 0) ||
46437+ return (h->access->intr_pending(h) == 0) ||
46438 (h->interrupts_enabled == 0);
46439 }
46440
46441@@ -4364,7 +4364,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
46442 if (prod_index < 0)
46443 return -ENODEV;
46444 h->product_name = products[prod_index].product_name;
46445- h->access = *(products[prod_index].access);
46446+ h->access = products[prod_index].access;
46447
46448 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
46449 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
46450@@ -4646,7 +4646,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
46451
46452 assert_spin_locked(&lockup_detector_lock);
46453 remove_ctlr_from_lockup_detector_list(h);
46454- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46455+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46456 spin_lock_irqsave(&h->lock, flags);
46457 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
46458 spin_unlock_irqrestore(&h->lock, flags);
46459@@ -4823,7 +4823,7 @@ reinit_after_soft_reset:
46460 }
46461
46462 /* make sure the board interrupts are off */
46463- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46464+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46465
46466 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
46467 goto clean2;
46468@@ -4857,7 +4857,7 @@ reinit_after_soft_reset:
46469 * fake ones to scoop up any residual completions.
46470 */
46471 spin_lock_irqsave(&h->lock, flags);
46472- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46473+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46474 spin_unlock_irqrestore(&h->lock, flags);
46475 free_irqs(h);
46476 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
46477@@ -4876,9 +4876,9 @@ reinit_after_soft_reset:
46478 dev_info(&h->pdev->dev, "Board READY.\n");
46479 dev_info(&h->pdev->dev,
46480 "Waiting for stale completions to drain.\n");
46481- h->access.set_intr_mask(h, HPSA_INTR_ON);
46482+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46483 msleep(10000);
46484- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46485+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46486
46487 rc = controller_reset_failed(h->cfgtable);
46488 if (rc)
46489@@ -4899,7 +4899,7 @@ reinit_after_soft_reset:
46490 }
46491
46492 /* Turn the interrupts on so we can service requests */
46493- h->access.set_intr_mask(h, HPSA_INTR_ON);
46494+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46495
46496 hpsa_hba_inquiry(h);
46497 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
46498@@ -4954,7 +4954,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
46499 * To write all data in the battery backed cache to disks
46500 */
46501 hpsa_flush_cache(h);
46502- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46503+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46504 hpsa_free_irqs_and_disable_msix(h);
46505 }
46506
46507@@ -5122,7 +5122,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
46508 return;
46509 }
46510 /* Change the access methods to the performant access methods */
46511- h->access = SA5_performant_access;
46512+ h->access = &SA5_performant_access;
46513 h->transMethod = CFGTBL_Trans_Performant;
46514 }
46515
46516diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
46517index 9816479..c5d4e97 100644
46518--- a/drivers/scsi/hpsa.h
46519+++ b/drivers/scsi/hpsa.h
46520@@ -79,7 +79,7 @@ struct ctlr_info {
46521 unsigned int msix_vector;
46522 unsigned int msi_vector;
46523 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
46524- struct access_method access;
46525+ struct access_method *access;
46526
46527 /* queue and queue Info */
46528 struct list_head reqQ;
46529diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
46530index 5879929..32b241d 100644
46531--- a/drivers/scsi/libfc/fc_exch.c
46532+++ b/drivers/scsi/libfc/fc_exch.c
46533@@ -100,12 +100,12 @@ struct fc_exch_mgr {
46534 u16 pool_max_index;
46535
46536 struct {
46537- atomic_t no_free_exch;
46538- atomic_t no_free_exch_xid;
46539- atomic_t xid_not_found;
46540- atomic_t xid_busy;
46541- atomic_t seq_not_found;
46542- atomic_t non_bls_resp;
46543+ atomic_unchecked_t no_free_exch;
46544+ atomic_unchecked_t no_free_exch_xid;
46545+ atomic_unchecked_t xid_not_found;
46546+ atomic_unchecked_t xid_busy;
46547+ atomic_unchecked_t seq_not_found;
46548+ atomic_unchecked_t non_bls_resp;
46549 } stats;
46550 };
46551
46552@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
46553 /* allocate memory for exchange */
46554 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
46555 if (!ep) {
46556- atomic_inc(&mp->stats.no_free_exch);
46557+ atomic_inc_unchecked(&mp->stats.no_free_exch);
46558 goto out;
46559 }
46560 memset(ep, 0, sizeof(*ep));
46561@@ -797,7 +797,7 @@ out:
46562 return ep;
46563 err:
46564 spin_unlock_bh(&pool->lock);
46565- atomic_inc(&mp->stats.no_free_exch_xid);
46566+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
46567 mempool_free(ep, mp->ep_pool);
46568 return NULL;
46569 }
46570@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46571 xid = ntohs(fh->fh_ox_id); /* we originated exch */
46572 ep = fc_exch_find(mp, xid);
46573 if (!ep) {
46574- atomic_inc(&mp->stats.xid_not_found);
46575+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46576 reject = FC_RJT_OX_ID;
46577 goto out;
46578 }
46579@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46580 ep = fc_exch_find(mp, xid);
46581 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
46582 if (ep) {
46583- atomic_inc(&mp->stats.xid_busy);
46584+ atomic_inc_unchecked(&mp->stats.xid_busy);
46585 reject = FC_RJT_RX_ID;
46586 goto rel;
46587 }
46588@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46589 }
46590 xid = ep->xid; /* get our XID */
46591 } else if (!ep) {
46592- atomic_inc(&mp->stats.xid_not_found);
46593+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46594 reject = FC_RJT_RX_ID; /* XID not found */
46595 goto out;
46596 }
46597@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46598 } else {
46599 sp = &ep->seq;
46600 if (sp->id != fh->fh_seq_id) {
46601- atomic_inc(&mp->stats.seq_not_found);
46602+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46603 if (f_ctl & FC_FC_END_SEQ) {
46604 /*
46605 * Update sequence_id based on incoming last
46606@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46607
46608 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
46609 if (!ep) {
46610- atomic_inc(&mp->stats.xid_not_found);
46611+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46612 goto out;
46613 }
46614 if (ep->esb_stat & ESB_ST_COMPLETE) {
46615- atomic_inc(&mp->stats.xid_not_found);
46616+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46617 goto rel;
46618 }
46619 if (ep->rxid == FC_XID_UNKNOWN)
46620 ep->rxid = ntohs(fh->fh_rx_id);
46621 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
46622- atomic_inc(&mp->stats.xid_not_found);
46623+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46624 goto rel;
46625 }
46626 if (ep->did != ntoh24(fh->fh_s_id) &&
46627 ep->did != FC_FID_FLOGI) {
46628- atomic_inc(&mp->stats.xid_not_found);
46629+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46630 goto rel;
46631 }
46632 sof = fr_sof(fp);
46633@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46634 sp->ssb_stat |= SSB_ST_RESP;
46635 sp->id = fh->fh_seq_id;
46636 } else if (sp->id != fh->fh_seq_id) {
46637- atomic_inc(&mp->stats.seq_not_found);
46638+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46639 goto rel;
46640 }
46641
46642@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46643 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
46644
46645 if (!sp)
46646- atomic_inc(&mp->stats.xid_not_found);
46647+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46648 else
46649- atomic_inc(&mp->stats.non_bls_resp);
46650+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
46651
46652 fc_frame_free(fp);
46653 }
46654@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
46655
46656 list_for_each_entry(ema, &lport->ema_list, ema_list) {
46657 mp = ema->mp;
46658- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
46659+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
46660 st->fc_no_free_exch_xid +=
46661- atomic_read(&mp->stats.no_free_exch_xid);
46662- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
46663- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
46664- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
46665- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
46666+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
46667+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
46668+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
46669+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
46670+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
46671 }
46672 }
46673 EXPORT_SYMBOL(fc_exch_update_stats);
46674diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
46675index 161c98e..6d563b3 100644
46676--- a/drivers/scsi/libsas/sas_ata.c
46677+++ b/drivers/scsi/libsas/sas_ata.c
46678@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
46679 .postreset = ata_std_postreset,
46680 .error_handler = ata_std_error_handler,
46681 .post_internal_cmd = sas_ata_post_internal,
46682- .qc_defer = ata_std_qc_defer,
46683+ .qc_defer = ata_std_qc_defer,
46684 .qc_prep = ata_noop_qc_prep,
46685 .qc_issue = sas_ata_qc_issue,
46686 .qc_fill_rtf = sas_ata_qc_fill_rtf,
46687diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
46688index 93f222d..73e977b 100644
46689--- a/drivers/scsi/lpfc/lpfc.h
46690+++ b/drivers/scsi/lpfc/lpfc.h
46691@@ -431,7 +431,7 @@ struct lpfc_vport {
46692 struct dentry *debug_nodelist;
46693 struct dentry *vport_debugfs_root;
46694 struct lpfc_debugfs_trc *disc_trc;
46695- atomic_t disc_trc_cnt;
46696+ atomic_unchecked_t disc_trc_cnt;
46697 #endif
46698 uint8_t stat_data_enabled;
46699 uint8_t stat_data_blocked;
46700@@ -865,8 +865,8 @@ struct lpfc_hba {
46701 struct timer_list fabric_block_timer;
46702 unsigned long bit_flags;
46703 #define FABRIC_COMANDS_BLOCKED 0
46704- atomic_t num_rsrc_err;
46705- atomic_t num_cmd_success;
46706+ atomic_unchecked_t num_rsrc_err;
46707+ atomic_unchecked_t num_cmd_success;
46708 unsigned long last_rsrc_error_time;
46709 unsigned long last_ramp_down_time;
46710 unsigned long last_ramp_up_time;
46711@@ -902,7 +902,7 @@ struct lpfc_hba {
46712
46713 struct dentry *debug_slow_ring_trc;
46714 struct lpfc_debugfs_trc *slow_ring_trc;
46715- atomic_t slow_ring_trc_cnt;
46716+ atomic_unchecked_t slow_ring_trc_cnt;
46717 /* iDiag debugfs sub-directory */
46718 struct dentry *idiag_root;
46719 struct dentry *idiag_pci_cfg;
46720diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
46721index 60084e6..0e2e700 100644
46722--- a/drivers/scsi/lpfc/lpfc_debugfs.c
46723+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
46724@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
46725
46726 #include <linux/debugfs.h>
46727
46728-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46729+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46730 static unsigned long lpfc_debugfs_start_time = 0L;
46731
46732 /* iDiag */
46733@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
46734 lpfc_debugfs_enable = 0;
46735
46736 len = 0;
46737- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
46738+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
46739 (lpfc_debugfs_max_disc_trc - 1);
46740 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
46741 dtp = vport->disc_trc + i;
46742@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
46743 lpfc_debugfs_enable = 0;
46744
46745 len = 0;
46746- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
46747+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
46748 (lpfc_debugfs_max_slow_ring_trc - 1);
46749 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
46750 dtp = phba->slow_ring_trc + i;
46751@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
46752 !vport || !vport->disc_trc)
46753 return;
46754
46755- index = atomic_inc_return(&vport->disc_trc_cnt) &
46756+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
46757 (lpfc_debugfs_max_disc_trc - 1);
46758 dtp = vport->disc_trc + index;
46759 dtp->fmt = fmt;
46760 dtp->data1 = data1;
46761 dtp->data2 = data2;
46762 dtp->data3 = data3;
46763- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46764+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46765 dtp->jif = jiffies;
46766 #endif
46767 return;
46768@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
46769 !phba || !phba->slow_ring_trc)
46770 return;
46771
46772- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
46773+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
46774 (lpfc_debugfs_max_slow_ring_trc - 1);
46775 dtp = phba->slow_ring_trc + index;
46776 dtp->fmt = fmt;
46777 dtp->data1 = data1;
46778 dtp->data2 = data2;
46779 dtp->data3 = data3;
46780- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46781+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46782 dtp->jif = jiffies;
46783 #endif
46784 return;
46785@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46786 "slow_ring buffer\n");
46787 goto debug_failed;
46788 }
46789- atomic_set(&phba->slow_ring_trc_cnt, 0);
46790+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
46791 memset(phba->slow_ring_trc, 0,
46792 (sizeof(struct lpfc_debugfs_trc) *
46793 lpfc_debugfs_max_slow_ring_trc));
46794@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46795 "buffer\n");
46796 goto debug_failed;
46797 }
46798- atomic_set(&vport->disc_trc_cnt, 0);
46799+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
46800
46801 snprintf(name, sizeof(name), "discovery_trace");
46802 vport->debug_disc_trc =
46803diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
46804index e0b20fa..30c2c0d 100644
46805--- a/drivers/scsi/lpfc/lpfc_init.c
46806+++ b/drivers/scsi/lpfc/lpfc_init.c
46807@@ -10936,8 +10936,10 @@ lpfc_init(void)
46808 "misc_register returned with status %d", error);
46809
46810 if (lpfc_enable_npiv) {
46811- lpfc_transport_functions.vport_create = lpfc_vport_create;
46812- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46813+ pax_open_kernel();
46814+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
46815+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46816+ pax_close_kernel();
46817 }
46818 lpfc_transport_template =
46819 fc_attach_transport(&lpfc_transport_functions);
46820diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
46821index 243de1d..f40e3e5 100644
46822--- a/drivers/scsi/lpfc/lpfc_scsi.c
46823+++ b/drivers/scsi/lpfc/lpfc_scsi.c
46824@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
46825 uint32_t evt_posted;
46826
46827 spin_lock_irqsave(&phba->hbalock, flags);
46828- atomic_inc(&phba->num_rsrc_err);
46829+ atomic_inc_unchecked(&phba->num_rsrc_err);
46830 phba->last_rsrc_error_time = jiffies;
46831
46832 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
46833@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
46834 unsigned long flags;
46835 struct lpfc_hba *phba = vport->phba;
46836 uint32_t evt_posted;
46837- atomic_inc(&phba->num_cmd_success);
46838+ atomic_inc_unchecked(&phba->num_cmd_success);
46839
46840 if (vport->cfg_lun_queue_depth <= queue_depth)
46841 return;
46842@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46843 unsigned long num_rsrc_err, num_cmd_success;
46844 int i;
46845
46846- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
46847- num_cmd_success = atomic_read(&phba->num_cmd_success);
46848+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
46849+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
46850
46851 /*
46852 * The error and success command counters are global per
46853@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46854 }
46855 }
46856 lpfc_destroy_vport_work_array(phba, vports);
46857- atomic_set(&phba->num_rsrc_err, 0);
46858- atomic_set(&phba->num_cmd_success, 0);
46859+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46860+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46861 }
46862
46863 /**
46864@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
46865 }
46866 }
46867 lpfc_destroy_vport_work_array(phba, vports);
46868- atomic_set(&phba->num_rsrc_err, 0);
46869- atomic_set(&phba->num_cmd_success, 0);
46870+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46871+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46872 }
46873
46874 /**
46875diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
46876index 1eb7b028..b2a6080 100644
46877--- a/drivers/scsi/pmcraid.c
46878+++ b/drivers/scsi/pmcraid.c
46879@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
46880 res->scsi_dev = scsi_dev;
46881 scsi_dev->hostdata = res;
46882 res->change_detected = 0;
46883- atomic_set(&res->read_failures, 0);
46884- atomic_set(&res->write_failures, 0);
46885+ atomic_set_unchecked(&res->read_failures, 0);
46886+ atomic_set_unchecked(&res->write_failures, 0);
46887 rc = 0;
46888 }
46889 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
46890@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
46891
46892 /* If this was a SCSI read/write command keep count of errors */
46893 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
46894- atomic_inc(&res->read_failures);
46895+ atomic_inc_unchecked(&res->read_failures);
46896 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
46897- atomic_inc(&res->write_failures);
46898+ atomic_inc_unchecked(&res->write_failures);
46899
46900 if (!RES_IS_GSCSI(res->cfg_entry) &&
46901 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
46902@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
46903 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46904 * hrrq_id assigned here in queuecommand
46905 */
46906- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46907+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46908 pinstance->num_hrrq;
46909 cmd->cmd_done = pmcraid_io_done;
46910
46911@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
46912 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46913 * hrrq_id assigned here in queuecommand
46914 */
46915- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46916+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46917 pinstance->num_hrrq;
46918
46919 if (request_size) {
46920@@ -4483,7 +4483,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
46921
46922 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
46923 /* add resources only after host is added into system */
46924- if (!atomic_read(&pinstance->expose_resources))
46925+ if (!atomic_read_unchecked(&pinstance->expose_resources))
46926 return;
46927
46928 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
46929@@ -5310,8 +5310,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
46930 init_waitqueue_head(&pinstance->reset_wait_q);
46931
46932 atomic_set(&pinstance->outstanding_cmds, 0);
46933- atomic_set(&pinstance->last_message_id, 0);
46934- atomic_set(&pinstance->expose_resources, 0);
46935+ atomic_set_unchecked(&pinstance->last_message_id, 0);
46936+ atomic_set_unchecked(&pinstance->expose_resources, 0);
46937
46938 INIT_LIST_HEAD(&pinstance->free_res_q);
46939 INIT_LIST_HEAD(&pinstance->used_res_q);
46940@@ -6024,7 +6024,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
46941 /* Schedule worker thread to handle CCN and take care of adding and
46942 * removing devices to OS
46943 */
46944- atomic_set(&pinstance->expose_resources, 1);
46945+ atomic_set_unchecked(&pinstance->expose_resources, 1);
46946 schedule_work(&pinstance->worker_q);
46947 return rc;
46948
46949diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
46950index e1d150f..6c6df44 100644
46951--- a/drivers/scsi/pmcraid.h
46952+++ b/drivers/scsi/pmcraid.h
46953@@ -748,7 +748,7 @@ struct pmcraid_instance {
46954 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
46955
46956 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
46957- atomic_t last_message_id;
46958+ atomic_unchecked_t last_message_id;
46959
46960 /* configuration table */
46961 struct pmcraid_config_table *cfg_table;
46962@@ -777,7 +777,7 @@ struct pmcraid_instance {
46963 atomic_t outstanding_cmds;
46964
46965 /* should add/delete resources to mid-layer now ?*/
46966- atomic_t expose_resources;
46967+ atomic_unchecked_t expose_resources;
46968
46969
46970
46971@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
46972 struct pmcraid_config_table_entry_ext cfg_entry_ext;
46973 };
46974 struct scsi_device *scsi_dev; /* Link scsi_device structure */
46975- atomic_t read_failures; /* count of failed READ commands */
46976- atomic_t write_failures; /* count of failed WRITE commands */
46977+ atomic_unchecked_t read_failures; /* count of failed READ commands */
46978+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
46979
46980 /* To indicate add/delete/modify during CCN */
46981 u8 change_detected;
46982diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
46983index d7a99ae..801df70 100644
46984--- a/drivers/scsi/qla2xxx/qla_attr.c
46985+++ b/drivers/scsi/qla2xxx/qla_attr.c
46986@@ -2004,7 +2004,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
46987 return 0;
46988 }
46989
46990-struct fc_function_template qla2xxx_transport_functions = {
46991+fc_function_template_no_const qla2xxx_transport_functions = {
46992
46993 .show_host_node_name = 1,
46994 .show_host_port_name = 1,
46995@@ -2051,7 +2051,7 @@ struct fc_function_template qla2xxx_transport_functions = {
46996 .bsg_timeout = qla24xx_bsg_timeout,
46997 };
46998
46999-struct fc_function_template qla2xxx_transport_vport_functions = {
47000+fc_function_template_no_const qla2xxx_transport_vport_functions = {
47001
47002 .show_host_node_name = 1,
47003 .show_host_port_name = 1,
47004diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
47005index 2d98232..a84298e 100644
47006--- a/drivers/scsi/qla2xxx/qla_gbl.h
47007+++ b/drivers/scsi/qla2xxx/qla_gbl.h
47008@@ -528,8 +528,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
47009 struct device_attribute;
47010 extern struct device_attribute *qla2x00_host_attrs[];
47011 struct fc_function_template;
47012-extern struct fc_function_template qla2xxx_transport_functions;
47013-extern struct fc_function_template qla2xxx_transport_vport_functions;
47014+extern fc_function_template_no_const qla2xxx_transport_functions;
47015+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
47016 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
47017 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
47018 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
47019diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
47020index 3e21e9f..426ba79 100644
47021--- a/drivers/scsi/qla2xxx/qla_os.c
47022+++ b/drivers/scsi/qla2xxx/qla_os.c
47023@@ -1570,8 +1570,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
47024 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
47025 /* Ok, a 64bit DMA mask is applicable. */
47026 ha->flags.enable_64bit_addressing = 1;
47027- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
47028- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
47029+ pax_open_kernel();
47030+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
47031+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
47032+ pax_close_kernel();
47033 return;
47034 }
47035 }
47036diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
47037index ddf16a8..80f4dd0 100644
47038--- a/drivers/scsi/qla4xxx/ql4_def.h
47039+++ b/drivers/scsi/qla4xxx/ql4_def.h
47040@@ -291,7 +291,7 @@ struct ddb_entry {
47041 * (4000 only) */
47042 atomic_t relogin_timer; /* Max Time to wait for
47043 * relogin to complete */
47044- atomic_t relogin_retry_count; /* Num of times relogin has been
47045+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
47046 * retried */
47047 uint32_t default_time2wait; /* Default Min time between
47048 * relogins (+aens) */
47049diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
47050index b246b3c..897004d 100644
47051--- a/drivers/scsi/qla4xxx/ql4_os.c
47052+++ b/drivers/scsi/qla4xxx/ql4_os.c
47053@@ -2971,12 +2971,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
47054 */
47055 if (!iscsi_is_session_online(cls_sess)) {
47056 /* Reset retry relogin timer */
47057- atomic_inc(&ddb_entry->relogin_retry_count);
47058+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
47059 DEBUG2(ql4_printk(KERN_INFO, ha,
47060 "%s: index[%d] relogin timed out-retrying"
47061 " relogin (%d), retry (%d)\n", __func__,
47062 ddb_entry->fw_ddb_index,
47063- atomic_read(&ddb_entry->relogin_retry_count),
47064+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
47065 ddb_entry->default_time2wait + 4));
47066 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
47067 atomic_set(&ddb_entry->retry_relogin_timer,
47068@@ -5081,7 +5081,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
47069
47070 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
47071 atomic_set(&ddb_entry->relogin_timer, 0);
47072- atomic_set(&ddb_entry->relogin_retry_count, 0);
47073+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
47074 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
47075 ddb_entry->default_relogin_timeout =
47076 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
47077diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
47078index eaa808e..95f8841 100644
47079--- a/drivers/scsi/scsi.c
47080+++ b/drivers/scsi/scsi.c
47081@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
47082 unsigned long timeout;
47083 int rtn = 0;
47084
47085- atomic_inc(&cmd->device->iorequest_cnt);
47086+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
47087
47088 /* check if the device is still usable */
47089 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
47090diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
47091index 124392f..75eb43e 100644
47092--- a/drivers/scsi/scsi_lib.c
47093+++ b/drivers/scsi/scsi_lib.c
47094@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
47095 shost = sdev->host;
47096 scsi_init_cmd_errh(cmd);
47097 cmd->result = DID_NO_CONNECT << 16;
47098- atomic_inc(&cmd->device->iorequest_cnt);
47099+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
47100
47101 /*
47102 * SCSI request completion path will do scsi_device_unbusy(),
47103@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
47104
47105 INIT_LIST_HEAD(&cmd->eh_entry);
47106
47107- atomic_inc(&cmd->device->iodone_cnt);
47108+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
47109 if (cmd->result)
47110- atomic_inc(&cmd->device->ioerr_cnt);
47111+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
47112
47113 disposition = scsi_decide_disposition(cmd);
47114 if (disposition != SUCCESS &&
47115diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
47116index 7e50061..71db7a6 100644
47117--- a/drivers/scsi/scsi_sysfs.c
47118+++ b/drivers/scsi/scsi_sysfs.c
47119@@ -687,7 +687,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
47120 char *buf) \
47121 { \
47122 struct scsi_device *sdev = to_scsi_device(dev); \
47123- unsigned long long count = atomic_read(&sdev->field); \
47124+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
47125 return snprintf(buf, 20, "0x%llx\n", count); \
47126 } \
47127 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
47128diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
47129index 84a1fdf..693b0d6 100644
47130--- a/drivers/scsi/scsi_tgt_lib.c
47131+++ b/drivers/scsi/scsi_tgt_lib.c
47132@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
47133 int err;
47134
47135 dprintk("%lx %u\n", uaddr, len);
47136- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
47137+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
47138 if (err) {
47139 /*
47140 * TODO: need to fixup sg_tablesize, max_segment_size,
47141diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
47142index 4628fd5..a94a1c2 100644
47143--- a/drivers/scsi/scsi_transport_fc.c
47144+++ b/drivers/scsi/scsi_transport_fc.c
47145@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
47146 * Netlink Infrastructure
47147 */
47148
47149-static atomic_t fc_event_seq;
47150+static atomic_unchecked_t fc_event_seq;
47151
47152 /**
47153 * fc_get_event_number - Obtain the next sequential FC event number
47154@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
47155 u32
47156 fc_get_event_number(void)
47157 {
47158- return atomic_add_return(1, &fc_event_seq);
47159+ return atomic_add_return_unchecked(1, &fc_event_seq);
47160 }
47161 EXPORT_SYMBOL(fc_get_event_number);
47162
47163@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
47164 {
47165 int error;
47166
47167- atomic_set(&fc_event_seq, 0);
47168+ atomic_set_unchecked(&fc_event_seq, 0);
47169
47170 error = transport_class_register(&fc_host_class);
47171 if (error)
47172@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
47173 char *cp;
47174
47175 *val = simple_strtoul(buf, &cp, 0);
47176- if ((*cp && (*cp != '\n')) || (*val < 0))
47177+ if (*cp && (*cp != '\n'))
47178 return -EINVAL;
47179 /*
47180 * Check for overflow; dev_loss_tmo is u32
47181diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
47182index abf7c40..c3240ed 100644
47183--- a/drivers/scsi/scsi_transport_iscsi.c
47184+++ b/drivers/scsi/scsi_transport_iscsi.c
47185@@ -80,7 +80,7 @@ struct iscsi_internal {
47186 struct transport_container session_cont;
47187 };
47188
47189-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
47190+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
47191 static struct workqueue_struct *iscsi_eh_timer_workq;
47192
47193 static DEFINE_IDA(iscsi_sess_ida);
47194@@ -1738,7 +1738,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
47195 int err;
47196
47197 ihost = shost->shost_data;
47198- session->sid = atomic_add_return(1, &iscsi_session_nr);
47199+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
47200
47201 if (target_id == ISCSI_MAX_TARGET) {
47202 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
47203@@ -3956,7 +3956,7 @@ static __init int iscsi_transport_init(void)
47204 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
47205 ISCSI_TRANSPORT_VERSION);
47206
47207- atomic_set(&iscsi_session_nr, 0);
47208+ atomic_set_unchecked(&iscsi_session_nr, 0);
47209
47210 err = class_register(&iscsi_transport_class);
47211 if (err)
47212diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
47213index f379c7f..e8fc69c 100644
47214--- a/drivers/scsi/scsi_transport_srp.c
47215+++ b/drivers/scsi/scsi_transport_srp.c
47216@@ -33,7 +33,7 @@
47217 #include "scsi_transport_srp_internal.h"
47218
47219 struct srp_host_attrs {
47220- atomic_t next_port_id;
47221+ atomic_unchecked_t next_port_id;
47222 };
47223 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
47224
47225@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
47226 struct Scsi_Host *shost = dev_to_shost(dev);
47227 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
47228
47229- atomic_set(&srp_host->next_port_id, 0);
47230+ atomic_set_unchecked(&srp_host->next_port_id, 0);
47231 return 0;
47232 }
47233
47234@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
47235 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
47236 rport->roles = ids->roles;
47237
47238- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
47239+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
47240 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
47241
47242 transport_setup_device(&rport->dev);
47243diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
47244index 86fcf2c..26d8594 100644
47245--- a/drivers/scsi/sd.c
47246+++ b/drivers/scsi/sd.c
47247@@ -2938,7 +2938,7 @@ static int sd_probe(struct device *dev)
47248 sdkp->disk = gd;
47249 sdkp->index = index;
47250 atomic_set(&sdkp->openers, 0);
47251- atomic_set(&sdkp->device->ioerr_cnt, 0);
47252+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
47253
47254 if (!sdp->request_queue->rq_timeout) {
47255 if (sdp->type != TYPE_MOD)
47256diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
47257index df5e961..df6b97f 100644
47258--- a/drivers/scsi/sg.c
47259+++ b/drivers/scsi/sg.c
47260@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
47261 sdp->disk->disk_name,
47262 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
47263 NULL,
47264- (char *)arg);
47265+ (char __user *)arg);
47266 case BLKTRACESTART:
47267 return blk_trace_startstop(sdp->device->request_queue, 1);
47268 case BLKTRACESTOP:
47269diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
47270index 978dda2..cb19aa0 100644
47271--- a/drivers/spi/spi.c
47272+++ b/drivers/spi/spi.c
47273@@ -1631,7 +1631,7 @@ int spi_bus_unlock(struct spi_master *master)
47274 EXPORT_SYMBOL_GPL(spi_bus_unlock);
47275
47276 /* portable code must never pass more than 32 bytes */
47277-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
47278+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
47279
47280 static u8 *buf;
47281
47282diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
47283index ee3a57f..18368c1 100644
47284--- a/drivers/staging/android/timed_output.c
47285+++ b/drivers/staging/android/timed_output.c
47286@@ -25,7 +25,7 @@
47287 #include "timed_output.h"
47288
47289 static struct class *timed_output_class;
47290-static atomic_t device_count;
47291+static atomic_unchecked_t device_count;
47292
47293 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
47294 char *buf)
47295@@ -59,7 +59,7 @@ static int create_timed_output_class(void)
47296 timed_output_class = class_create(THIS_MODULE, "timed_output");
47297 if (IS_ERR(timed_output_class))
47298 return PTR_ERR(timed_output_class);
47299- atomic_set(&device_count, 0);
47300+ atomic_set_unchecked(&device_count, 0);
47301 }
47302
47303 return 0;
47304@@ -76,7 +76,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
47305 if (ret < 0)
47306 return ret;
47307
47308- tdev->index = atomic_inc_return(&device_count);
47309+ tdev->index = atomic_inc_return_unchecked(&device_count);
47310 tdev->dev = device_create(timed_output_class, NULL,
47311 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
47312 if (IS_ERR(tdev->dev))
47313diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
47314index 3675020..e80d92c 100644
47315--- a/drivers/staging/media/solo6x10/solo6x10-core.c
47316+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
47317@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
47318
47319 static int solo_sysfs_init(struct solo_dev *solo_dev)
47320 {
47321- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
47322+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
47323 struct device *dev = &solo_dev->dev;
47324 const char *driver;
47325 int i;
47326diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47327index 3335941..2b26186 100644
47328--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
47329+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47330@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
47331
47332 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
47333 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
47334- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
47335+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
47336 if (p2m_id < 0)
47337 p2m_id = -p2m_id;
47338 }
47339diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
47340index 6f91d2e..3f011d2 100644
47341--- a/drivers/staging/media/solo6x10/solo6x10.h
47342+++ b/drivers/staging/media/solo6x10/solo6x10.h
47343@@ -238,7 +238,7 @@ struct solo_dev {
47344
47345 /* P2M DMA Engine */
47346 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
47347- atomic_t p2m_count;
47348+ atomic_unchecked_t p2m_count;
47349 int p2m_jiffies;
47350 unsigned int p2m_timeouts;
47351
47352diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
47353index 34afc16..ffe44dd 100644
47354--- a/drivers/staging/octeon/ethernet-rx.c
47355+++ b/drivers/staging/octeon/ethernet-rx.c
47356@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47357 /* Increment RX stats for virtual ports */
47358 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
47359 #ifdef CONFIG_64BIT
47360- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
47361- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
47362+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
47363+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
47364 #else
47365- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
47366- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
47367+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
47368+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
47369 #endif
47370 }
47371 netif_receive_skb(skb);
47372@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47373 dev->name);
47374 */
47375 #ifdef CONFIG_64BIT
47376- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
47377+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47378 #else
47379- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
47380+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
47381 #endif
47382 dev_kfree_skb_irq(skb);
47383 }
47384diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
47385index c3a90e7..023619a 100644
47386--- a/drivers/staging/octeon/ethernet.c
47387+++ b/drivers/staging/octeon/ethernet.c
47388@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
47389 * since the RX tasklet also increments it.
47390 */
47391 #ifdef CONFIG_64BIT
47392- atomic64_add(rx_status.dropped_packets,
47393- (atomic64_t *)&priv->stats.rx_dropped);
47394+ atomic64_add_unchecked(rx_status.dropped_packets,
47395+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47396 #else
47397- atomic_add(rx_status.dropped_packets,
47398- (atomic_t *)&priv->stats.rx_dropped);
47399+ atomic_add_unchecked(rx_status.dropped_packets,
47400+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
47401 #endif
47402 }
47403
47404diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
47405index dc23395..cf7e9b1 100644
47406--- a/drivers/staging/rtl8712/rtl871x_io.h
47407+++ b/drivers/staging/rtl8712/rtl871x_io.h
47408@@ -108,7 +108,7 @@ struct _io_ops {
47409 u8 *pmem);
47410 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
47411 u8 *pmem);
47412-};
47413+} __no_const;
47414
47415 struct io_req {
47416 struct list_head list;
47417diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
47418index 1f5088b..0e59820 100644
47419--- a/drivers/staging/sbe-2t3e3/netdev.c
47420+++ b/drivers/staging/sbe-2t3e3/netdev.c
47421@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
47422 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
47423
47424 if (rlen)
47425- if (copy_to_user(data, &resp, rlen))
47426+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
47427 return -EFAULT;
47428
47429 return 0;
47430diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
47431index a863a98..d272795 100644
47432--- a/drivers/staging/usbip/vhci.h
47433+++ b/drivers/staging/usbip/vhci.h
47434@@ -83,7 +83,7 @@ struct vhci_hcd {
47435 unsigned resuming:1;
47436 unsigned long re_timeout;
47437
47438- atomic_t seqnum;
47439+ atomic_unchecked_t seqnum;
47440
47441 /*
47442 * NOTE:
47443diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
47444index d7974cb..d78076b 100644
47445--- a/drivers/staging/usbip/vhci_hcd.c
47446+++ b/drivers/staging/usbip/vhci_hcd.c
47447@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
47448
47449 spin_lock(&vdev->priv_lock);
47450
47451- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
47452+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47453 if (priv->seqnum == 0xffff)
47454 dev_info(&urb->dev->dev, "seqnum max\n");
47455
47456@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
47457 return -ENOMEM;
47458 }
47459
47460- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
47461+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47462 if (unlink->seqnum == 0xffff)
47463 pr_info("seqnum max\n");
47464
47465@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
47466 vdev->rhport = rhport;
47467 }
47468
47469- atomic_set(&vhci->seqnum, 0);
47470+ atomic_set_unchecked(&vhci->seqnum, 0);
47471 spin_lock_init(&vhci->lock);
47472
47473 hcd->power_budget = 0; /* no limit */
47474diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
47475index d07fcb5..358e1e1 100644
47476--- a/drivers/staging/usbip/vhci_rx.c
47477+++ b/drivers/staging/usbip/vhci_rx.c
47478@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
47479 if (!urb) {
47480 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
47481 pr_info("max seqnum %d\n",
47482- atomic_read(&the_controller->seqnum));
47483+ atomic_read_unchecked(&the_controller->seqnum));
47484 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
47485 return;
47486 }
47487diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
47488index 57a08c5..5b4bb7c 100644
47489--- a/drivers/staging/vt6655/hostap.c
47490+++ b/drivers/staging/vt6655/hostap.c
47491@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
47492 *
47493 */
47494
47495+static net_device_ops_no_const apdev_netdev_ops;
47496+
47497 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47498 {
47499 PSDevice apdev_priv;
47500 struct net_device *dev = pDevice->dev;
47501 int ret;
47502- const struct net_device_ops apdev_netdev_ops = {
47503- .ndo_start_xmit = pDevice->tx_80211,
47504- };
47505
47506 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47507
47508@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47509 *apdev_priv = *pDevice;
47510 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47511
47512+ /* only half broken now */
47513+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47514 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47515
47516 pDevice->apdev->type = ARPHRD_IEEE80211;
47517diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
47518index c699a30..b90a5fd 100644
47519--- a/drivers/staging/vt6656/hostap.c
47520+++ b/drivers/staging/vt6656/hostap.c
47521@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
47522 *
47523 */
47524
47525+static net_device_ops_no_const apdev_netdev_ops;
47526+
47527 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47528 {
47529 struct vnt_private *apdev_priv;
47530 struct net_device *dev = pDevice->dev;
47531 int ret;
47532- const struct net_device_ops apdev_netdev_ops = {
47533- .ndo_start_xmit = pDevice->tx_80211,
47534- };
47535
47536 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47537
47538@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47539 *apdev_priv = *pDevice;
47540 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47541
47542+ /* only half broken now */
47543+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47544 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47545
47546 pDevice->apdev->type = ARPHRD_IEEE80211;
47547diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
47548index d128ce2..fc1f9a1 100644
47549--- a/drivers/staging/zcache/tmem.h
47550+++ b/drivers/staging/zcache/tmem.h
47551@@ -225,7 +225,7 @@ struct tmem_pamops {
47552 bool (*is_remote)(void *);
47553 int (*replace_in_obj)(void *, struct tmem_obj *);
47554 #endif
47555-};
47556+} __no_const;
47557 extern void tmem_register_pamops(struct tmem_pamops *m);
47558
47559 /* memory allocation methods provided by the host implementation */
47560@@ -234,7 +234,7 @@ struct tmem_hostops {
47561 void (*obj_free)(struct tmem_obj *, struct tmem_pool *);
47562 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
47563 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
47564-};
47565+} __no_const;
47566 extern void tmem_register_hostops(struct tmem_hostops *m);
47567
47568 /* core tmem accessor functions */
47569diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
47570index e51b09a..5ebac31 100644
47571--- a/drivers/target/sbp/sbp_target.c
47572+++ b/drivers/target/sbp/sbp_target.c
47573@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
47574
47575 #define SESSION_MAINTENANCE_INTERVAL HZ
47576
47577-static atomic_t login_id = ATOMIC_INIT(0);
47578+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
47579
47580 static void session_maintenance_work(struct work_struct *);
47581 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
47582@@ -444,7 +444,7 @@ static void sbp_management_request_login(
47583 login->lun = se_lun;
47584 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
47585 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
47586- login->login_id = atomic_inc_return(&login_id);
47587+ login->login_id = atomic_inc_return_unchecked(&login_id);
47588
47589 login->tgt_agt = sbp_target_agent_register(login);
47590 if (IS_ERR(login->tgt_agt)) {
47591diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
47592index 8f4142f..b127f7d 100644
47593--- a/drivers/target/target_core_device.c
47594+++ b/drivers/target/target_core_device.c
47595@@ -1400,7 +1400,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
47596 spin_lock_init(&dev->se_port_lock);
47597 spin_lock_init(&dev->se_tmr_lock);
47598 spin_lock_init(&dev->qf_cmd_lock);
47599- atomic_set(&dev->dev_ordered_id, 0);
47600+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
47601 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
47602 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
47603 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
47604diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
47605index d8e49d7..6fcfdec 100644
47606--- a/drivers/target/target_core_transport.c
47607+++ b/drivers/target/target_core_transport.c
47608@@ -1080,7 +1080,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
47609 * Used to determine when ORDERED commands should go from
47610 * Dormant to Active status.
47611 */
47612- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
47613+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
47614 smp_mb__after_atomic_inc();
47615 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
47616 cmd->se_ordered_id, cmd->sam_task_attr,
47617diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
47618index 33f83fe..d80f8e1 100644
47619--- a/drivers/tty/cyclades.c
47620+++ b/drivers/tty/cyclades.c
47621@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
47622 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
47623 info->port.count);
47624 #endif
47625- info->port.count++;
47626+ atomic_inc(&info->port.count);
47627 #ifdef CY_DEBUG_COUNT
47628 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
47629- current->pid, info->port.count);
47630+ current->pid, atomic_read(&info->port.count));
47631 #endif
47632
47633 /*
47634@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
47635 for (j = 0; j < cy_card[i].nports; j++) {
47636 info = &cy_card[i].ports[j];
47637
47638- if (info->port.count) {
47639+ if (atomic_read(&info->port.count)) {
47640 /* XXX is the ldisc num worth this? */
47641 struct tty_struct *tty;
47642 struct tty_ldisc *ld;
47643diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
47644index eb255e8..f637a57 100644
47645--- a/drivers/tty/hvc/hvc_console.c
47646+++ b/drivers/tty/hvc/hvc_console.c
47647@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
47648
47649 spin_lock_irqsave(&hp->port.lock, flags);
47650 /* Check and then increment for fast path open. */
47651- if (hp->port.count++ > 0) {
47652+ if (atomic_inc_return(&hp->port.count) > 1) {
47653 spin_unlock_irqrestore(&hp->port.lock, flags);
47654 hvc_kick();
47655 return 0;
47656@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47657
47658 spin_lock_irqsave(&hp->port.lock, flags);
47659
47660- if (--hp->port.count == 0) {
47661+ if (atomic_dec_return(&hp->port.count) == 0) {
47662 spin_unlock_irqrestore(&hp->port.lock, flags);
47663 /* We are done with the tty pointer now. */
47664 tty_port_tty_set(&hp->port, NULL);
47665@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47666 */
47667 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
47668 } else {
47669- if (hp->port.count < 0)
47670+ if (atomic_read(&hp->port.count) < 0)
47671 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
47672- hp->vtermno, hp->port.count);
47673+ hp->vtermno, atomic_read(&hp->port.count));
47674 spin_unlock_irqrestore(&hp->port.lock, flags);
47675 }
47676 }
47677@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
47678 * open->hangup case this can be called after the final close so prevent
47679 * that from happening for now.
47680 */
47681- if (hp->port.count <= 0) {
47682+ if (atomic_read(&hp->port.count) <= 0) {
47683 spin_unlock_irqrestore(&hp->port.lock, flags);
47684 return;
47685 }
47686
47687- hp->port.count = 0;
47688+ atomic_set(&hp->port.count, 0);
47689 spin_unlock_irqrestore(&hp->port.lock, flags);
47690 tty_port_tty_set(&hp->port, NULL);
47691
47692@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
47693 return -EPIPE;
47694
47695 /* FIXME what's this (unprotected) check for? */
47696- if (hp->port.count <= 0)
47697+ if (atomic_read(&hp->port.count) <= 0)
47698 return -EIO;
47699
47700 spin_lock_irqsave(&hp->lock, flags);
47701diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
47702index 81e939e..95ead10 100644
47703--- a/drivers/tty/hvc/hvcs.c
47704+++ b/drivers/tty/hvc/hvcs.c
47705@@ -83,6 +83,7 @@
47706 #include <asm/hvcserver.h>
47707 #include <asm/uaccess.h>
47708 #include <asm/vio.h>
47709+#include <asm/local.h>
47710
47711 /*
47712 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
47713@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
47714
47715 spin_lock_irqsave(&hvcsd->lock, flags);
47716
47717- if (hvcsd->port.count > 0) {
47718+ if (atomic_read(&hvcsd->port.count) > 0) {
47719 spin_unlock_irqrestore(&hvcsd->lock, flags);
47720 printk(KERN_INFO "HVCS: vterm state unchanged. "
47721 "The hvcs device node is still in use.\n");
47722@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
47723 }
47724 }
47725
47726- hvcsd->port.count = 0;
47727+ atomic_set(&hvcsd->port.count, 0);
47728 hvcsd->port.tty = tty;
47729 tty->driver_data = hvcsd;
47730
47731@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
47732 unsigned long flags;
47733
47734 spin_lock_irqsave(&hvcsd->lock, flags);
47735- hvcsd->port.count++;
47736+ atomic_inc(&hvcsd->port.count);
47737 hvcsd->todo_mask |= HVCS_SCHED_READ;
47738 spin_unlock_irqrestore(&hvcsd->lock, flags);
47739
47740@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47741 hvcsd = tty->driver_data;
47742
47743 spin_lock_irqsave(&hvcsd->lock, flags);
47744- if (--hvcsd->port.count == 0) {
47745+ if (atomic_dec_and_test(&hvcsd->port.count)) {
47746
47747 vio_disable_interrupts(hvcsd->vdev);
47748
47749@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47750
47751 free_irq(irq, hvcsd);
47752 return;
47753- } else if (hvcsd->port.count < 0) {
47754+ } else if (atomic_read(&hvcsd->port.count) < 0) {
47755 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
47756 " is missmanaged.\n",
47757- hvcsd->vdev->unit_address, hvcsd->port.count);
47758+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
47759 }
47760
47761 spin_unlock_irqrestore(&hvcsd->lock, flags);
47762@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47763
47764 spin_lock_irqsave(&hvcsd->lock, flags);
47765 /* Preserve this so that we know how many kref refs to put */
47766- temp_open_count = hvcsd->port.count;
47767+ temp_open_count = atomic_read(&hvcsd->port.count);
47768
47769 /*
47770 * Don't kref put inside the spinlock because the destruction
47771@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47772 tty->driver_data = NULL;
47773 hvcsd->port.tty = NULL;
47774
47775- hvcsd->port.count = 0;
47776+ atomic_set(&hvcsd->port.count, 0);
47777
47778 /* This will drop any buffered data on the floor which is OK in a hangup
47779 * scenario. */
47780@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
47781 * the middle of a write operation? This is a crummy place to do this
47782 * but we want to keep it all in the spinlock.
47783 */
47784- if (hvcsd->port.count <= 0) {
47785+ if (atomic_read(&hvcsd->port.count) <= 0) {
47786 spin_unlock_irqrestore(&hvcsd->lock, flags);
47787 return -ENODEV;
47788 }
47789@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
47790 {
47791 struct hvcs_struct *hvcsd = tty->driver_data;
47792
47793- if (!hvcsd || hvcsd->port.count <= 0)
47794+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
47795 return 0;
47796
47797 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
47798diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
47799index 4190199..48f2920 100644
47800--- a/drivers/tty/hvc/hvsi.c
47801+++ b/drivers/tty/hvc/hvsi.c
47802@@ -85,7 +85,7 @@ struct hvsi_struct {
47803 int n_outbuf;
47804 uint32_t vtermno;
47805 uint32_t virq;
47806- atomic_t seqno; /* HVSI packet sequence number */
47807+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
47808 uint16_t mctrl;
47809 uint8_t state; /* HVSI protocol state */
47810 uint8_t flags;
47811@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
47812
47813 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
47814 packet.hdr.len = sizeof(struct hvsi_query_response);
47815- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47816+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47817 packet.verb = VSV_SEND_VERSION_NUMBER;
47818 packet.u.version = HVSI_VERSION;
47819 packet.query_seqno = query_seqno+1;
47820@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
47821
47822 packet.hdr.type = VS_QUERY_PACKET_HEADER;
47823 packet.hdr.len = sizeof(struct hvsi_query);
47824- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47825+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47826 packet.verb = verb;
47827
47828 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
47829@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
47830 int wrote;
47831
47832 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
47833- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47834+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47835 packet.hdr.len = sizeof(struct hvsi_control);
47836 packet.verb = VSV_SET_MODEM_CTL;
47837 packet.mask = HVSI_TSDTR;
47838@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
47839 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
47840
47841 packet.hdr.type = VS_DATA_PACKET_HEADER;
47842- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47843+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47844 packet.hdr.len = count + sizeof(struct hvsi_header);
47845 memcpy(&packet.data, buf, count);
47846
47847@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
47848 struct hvsi_control packet __ALIGNED__;
47849
47850 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
47851- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47852+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47853 packet.hdr.len = 6;
47854 packet.verb = VSV_CLOSE_PROTOCOL;
47855
47856diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
47857index ac27671..0f627ee 100644
47858--- a/drivers/tty/hvc/hvsi_lib.c
47859+++ b/drivers/tty/hvc/hvsi_lib.c
47860@@ -9,7 +9,7 @@
47861
47862 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
47863 {
47864- packet->seqno = atomic_inc_return(&pv->seqno);
47865+ packet->seqno = atomic_inc_return_unchecked(&pv->seqno);
47866
47867 /* Assumes that always succeeds, works in practice */
47868 return pv->put_chars(pv->termno, (char *)packet, packet->len);
47869@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
47870
47871 /* Reset state */
47872 pv->established = 0;
47873- atomic_set(&pv->seqno, 0);
47874+ atomic_set_unchecked(&pv->seqno, 0);
47875
47876 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
47877
47878@@ -265,7 +265,7 @@ int hvsilib_read_mctrl(struct hvsi_priv *pv)
47879 pv->mctrl_update = 0;
47880 q.hdr.type = VS_QUERY_PACKET_HEADER;
47881 q.hdr.len = sizeof(struct hvsi_query);
47882- q.hdr.seqno = atomic_inc_return(&pv->seqno);
47883+ q.hdr.seqno = atomic_inc_return_unchecked(&pv->seqno);
47884 q.verb = VSV_SEND_MODEM_CTL_STATUS;
47885 rc = hvsi_send_packet(pv, &q.hdr);
47886 if (rc <= 0) {
47887diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
47888index 8fd72ff..34a0bed 100644
47889--- a/drivers/tty/ipwireless/tty.c
47890+++ b/drivers/tty/ipwireless/tty.c
47891@@ -29,6 +29,7 @@
47892 #include <linux/tty_driver.h>
47893 #include <linux/tty_flip.h>
47894 #include <linux/uaccess.h>
47895+#include <asm/local.h>
47896
47897 #include "tty.h"
47898 #include "network.h"
47899@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47900 mutex_unlock(&tty->ipw_tty_mutex);
47901 return -ENODEV;
47902 }
47903- if (tty->port.count == 0)
47904+ if (atomic_read(&tty->port.count) == 0)
47905 tty->tx_bytes_queued = 0;
47906
47907- tty->port.count++;
47908+ atomic_inc(&tty->port.count);
47909
47910 tty->port.tty = linux_tty;
47911 linux_tty->driver_data = tty;
47912@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47913
47914 static void do_ipw_close(struct ipw_tty *tty)
47915 {
47916- tty->port.count--;
47917-
47918- if (tty->port.count == 0) {
47919+ if (atomic_dec_return(&tty->port.count) == 0) {
47920 struct tty_struct *linux_tty = tty->port.tty;
47921
47922 if (linux_tty != NULL) {
47923@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
47924 return;
47925
47926 mutex_lock(&tty->ipw_tty_mutex);
47927- if (tty->port.count == 0) {
47928+ if (atomic_read(&tty->port.count) == 0) {
47929 mutex_unlock(&tty->ipw_tty_mutex);
47930 return;
47931 }
47932@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
47933
47934 mutex_lock(&tty->ipw_tty_mutex);
47935
47936- if (!tty->port.count) {
47937+ if (!atomic_read(&tty->port.count)) {
47938 mutex_unlock(&tty->ipw_tty_mutex);
47939 return;
47940 }
47941@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
47942 return -ENODEV;
47943
47944 mutex_lock(&tty->ipw_tty_mutex);
47945- if (!tty->port.count) {
47946+ if (!atomic_read(&tty->port.count)) {
47947 mutex_unlock(&tty->ipw_tty_mutex);
47948 return -EINVAL;
47949 }
47950@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
47951 if (!tty)
47952 return -ENODEV;
47953
47954- if (!tty->port.count)
47955+ if (!atomic_read(&tty->port.count))
47956 return -EINVAL;
47957
47958 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
47959@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
47960 if (!tty)
47961 return 0;
47962
47963- if (!tty->port.count)
47964+ if (!atomic_read(&tty->port.count))
47965 return 0;
47966
47967 return tty->tx_bytes_queued;
47968@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
47969 if (!tty)
47970 return -ENODEV;
47971
47972- if (!tty->port.count)
47973+ if (!atomic_read(&tty->port.count))
47974 return -EINVAL;
47975
47976 return get_control_lines(tty);
47977@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
47978 if (!tty)
47979 return -ENODEV;
47980
47981- if (!tty->port.count)
47982+ if (!atomic_read(&tty->port.count))
47983 return -EINVAL;
47984
47985 return set_control_lines(tty, set, clear);
47986@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
47987 if (!tty)
47988 return -ENODEV;
47989
47990- if (!tty->port.count)
47991+ if (!atomic_read(&tty->port.count))
47992 return -EINVAL;
47993
47994 /* FIXME: Exactly how is the tty object locked here .. */
47995@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
47996 * are gone */
47997 mutex_lock(&ttyj->ipw_tty_mutex);
47998 }
47999- while (ttyj->port.count)
48000+ while (atomic_read(&ttyj->port.count))
48001 do_ipw_close(ttyj);
48002 ipwireless_disassociate_network_ttys(network,
48003 ttyj->channel_idx);
48004diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
48005index 1deaca4..c8582d4 100644
48006--- a/drivers/tty/moxa.c
48007+++ b/drivers/tty/moxa.c
48008@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
48009 }
48010
48011 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
48012- ch->port.count++;
48013+ atomic_inc(&ch->port.count);
48014 tty->driver_data = ch;
48015 tty_port_tty_set(&ch->port, tty);
48016 mutex_lock(&ch->port.mutex);
48017diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
48018index 6422390..49003ac8 100644
48019--- a/drivers/tty/n_gsm.c
48020+++ b/drivers/tty/n_gsm.c
48021@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
48022 spin_lock_init(&dlci->lock);
48023 mutex_init(&dlci->mutex);
48024 dlci->fifo = &dlci->_fifo;
48025- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
48026+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
48027 kfree(dlci);
48028 return NULL;
48029 }
48030@@ -2932,7 +2932,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
48031 struct gsm_dlci *dlci = tty->driver_data;
48032 struct tty_port *port = &dlci->port;
48033
48034- port->count++;
48035+ atomic_inc(&port->count);
48036 dlci_get(dlci);
48037 dlci_get(dlci->gsm->dlci[0]);
48038 mux_get(dlci->gsm);
48039diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
48040index 4bf0fc0..433bd58 100644
48041--- a/drivers/tty/n_tty.c
48042+++ b/drivers/tty/n_tty.c
48043@@ -2217,6 +2217,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
48044 {
48045 *ops = tty_ldisc_N_TTY;
48046 ops->owner = NULL;
48047- ops->refcount = ops->flags = 0;
48048+ atomic_set(&ops->refcount, 0);
48049+ ops->flags = 0;
48050 }
48051 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
48052diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
48053index abfd990..5ab5da9 100644
48054--- a/drivers/tty/pty.c
48055+++ b/drivers/tty/pty.c
48056@@ -796,8 +796,10 @@ static void __init unix98_pty_init(void)
48057 panic("Couldn't register Unix98 pts driver");
48058
48059 /* Now create the /dev/ptmx special device */
48060+ pax_open_kernel();
48061 tty_default_fops(&ptmx_fops);
48062- ptmx_fops.open = ptmx_open;
48063+ *(void **)&ptmx_fops.open = ptmx_open;
48064+ pax_close_kernel();
48065
48066 cdev_init(&ptmx_cdev, &ptmx_fops);
48067 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
48068diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
48069index 354564e..fe50d9a 100644
48070--- a/drivers/tty/rocket.c
48071+++ b/drivers/tty/rocket.c
48072@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
48073 tty->driver_data = info;
48074 tty_port_tty_set(port, tty);
48075
48076- if (port->count++ == 0) {
48077+ if (atomic_inc_return(&port->count) == 1) {
48078 atomic_inc(&rp_num_ports_open);
48079
48080 #ifdef ROCKET_DEBUG_OPEN
48081@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
48082 #endif
48083 }
48084 #ifdef ROCKET_DEBUG_OPEN
48085- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
48086+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
48087 #endif
48088
48089 /*
48090@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
48091 spin_unlock_irqrestore(&info->port.lock, flags);
48092 return;
48093 }
48094- if (info->port.count)
48095+ if (atomic_read(&info->port.count))
48096 atomic_dec(&rp_num_ports_open);
48097 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
48098 spin_unlock_irqrestore(&info->port.lock, flags);
48099diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
48100index e2520ab..034e20b 100644
48101--- a/drivers/tty/serial/ioc4_serial.c
48102+++ b/drivers/tty/serial/ioc4_serial.c
48103@@ -437,7 +437,7 @@ struct ioc4_soft {
48104 } is_intr_info[MAX_IOC4_INTR_ENTS];
48105
48106 /* Number of entries active in the above array */
48107- atomic_t is_num_intrs;
48108+ atomic_unchecked_t is_num_intrs;
48109 } is_intr_type[IOC4_NUM_INTR_TYPES];
48110
48111 /* is_ir_lock must be held while
48112@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
48113 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
48114 || (type == IOC4_OTHER_INTR_TYPE)));
48115
48116- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
48117+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
48118 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
48119
48120 /* Save off the lower level interrupt handler */
48121@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
48122
48123 soft = arg;
48124 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
48125- num_intrs = (int)atomic_read(
48126+ num_intrs = (int)atomic_read_unchecked(
48127 &soft->is_intr_type[intr_type].is_num_intrs);
48128
48129 this_mir = this_ir = pending_intrs(soft, intr_type);
48130diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
48131index 1002054..dd644a8 100644
48132--- a/drivers/tty/serial/kgdboc.c
48133+++ b/drivers/tty/serial/kgdboc.c
48134@@ -24,8 +24,9 @@
48135 #define MAX_CONFIG_LEN 40
48136
48137 static struct kgdb_io kgdboc_io_ops;
48138+static struct kgdb_io kgdboc_io_ops_console;
48139
48140-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
48141+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
48142 static int configured = -1;
48143
48144 static char config[MAX_CONFIG_LEN];
48145@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
48146 kgdboc_unregister_kbd();
48147 if (configured == 1)
48148 kgdb_unregister_io_module(&kgdboc_io_ops);
48149+ else if (configured == 2)
48150+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
48151 }
48152
48153 static int configure_kgdboc(void)
48154@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
48155 int err;
48156 char *cptr = config;
48157 struct console *cons;
48158+ int is_console = 0;
48159
48160 err = kgdboc_option_setup(config);
48161 if (err || !strlen(config) || isspace(config[0]))
48162 goto noconfig;
48163
48164 err = -ENODEV;
48165- kgdboc_io_ops.is_console = 0;
48166 kgdb_tty_driver = NULL;
48167
48168 kgdboc_use_kms = 0;
48169@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
48170 int idx;
48171 if (cons->device && cons->device(cons, &idx) == p &&
48172 idx == tty_line) {
48173- kgdboc_io_ops.is_console = 1;
48174+ is_console = 1;
48175 break;
48176 }
48177 cons = cons->next;
48178@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
48179 kgdb_tty_line = tty_line;
48180
48181 do_register:
48182- err = kgdb_register_io_module(&kgdboc_io_ops);
48183+ if (is_console) {
48184+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
48185+ configured = 2;
48186+ } else {
48187+ err = kgdb_register_io_module(&kgdboc_io_ops);
48188+ configured = 1;
48189+ }
48190 if (err)
48191 goto noconfig;
48192
48193@@ -205,8 +214,6 @@ do_register:
48194 if (err)
48195 goto nmi_con_failed;
48196
48197- configured = 1;
48198-
48199 return 0;
48200
48201 nmi_con_failed:
48202@@ -223,7 +230,7 @@ noconfig:
48203 static int __init init_kgdboc(void)
48204 {
48205 /* Already configured? */
48206- if (configured == 1)
48207+ if (configured >= 1)
48208 return 0;
48209
48210 return configure_kgdboc();
48211@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
48212 if (config[len - 1] == '\n')
48213 config[len - 1] = '\0';
48214
48215- if (configured == 1)
48216+ if (configured >= 1)
48217 cleanup_kgdboc();
48218
48219 /* Go and configure with the new params. */
48220@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
48221 .post_exception = kgdboc_post_exp_handler,
48222 };
48223
48224+static struct kgdb_io kgdboc_io_ops_console = {
48225+ .name = "kgdboc",
48226+ .read_char = kgdboc_get_char,
48227+ .write_char = kgdboc_put_char,
48228+ .pre_exception = kgdboc_pre_exp_handler,
48229+ .post_exception = kgdboc_post_exp_handler,
48230+ .is_console = 1
48231+};
48232+
48233 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
48234 /* This is only available if kgdboc is a built in for early debugging */
48235 static int __init kgdboc_early_init(char *opt)
48236diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
48237index 2c6cfb3..048274e 100644
48238--- a/drivers/tty/serial/msm_serial.c
48239+++ b/drivers/tty/serial/msm_serial.c
48240@@ -857,7 +857,7 @@ static struct uart_driver msm_uart_driver = {
48241 .cons = MSM_CONSOLE,
48242 };
48243
48244-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
48245+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
48246
48247 static int __init msm_serial_probe(struct platform_device *pdev)
48248 {
48249@@ -867,7 +867,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
48250 int irq;
48251
48252 if (pdev->id == -1)
48253- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
48254+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
48255
48256 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
48257 return -ENXIO;
48258diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
48259index 376079b..d8de7aa 100644
48260--- a/drivers/tty/serial/samsung.c
48261+++ b/drivers/tty/serial/samsung.c
48262@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
48263 }
48264 }
48265
48266+static int s3c64xx_serial_startup(struct uart_port *port);
48267 static int s3c24xx_serial_startup(struct uart_port *port)
48268 {
48269 struct s3c24xx_uart_port *ourport = to_ourport(port);
48270 int ret;
48271
48272+ /* Startup sequence is different for s3c64xx and higher SoC's */
48273+ if (s3c24xx_serial_has_interrupt_mask(port))
48274+ return s3c64xx_serial_startup(port);
48275+
48276 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
48277 port->mapbase, port->membase);
48278
48279@@ -1124,10 +1129,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
48280 /* setup info for port */
48281 port->dev = &platdev->dev;
48282
48283- /* Startup sequence is different for s3c64xx and higher SoC's */
48284- if (s3c24xx_serial_has_interrupt_mask(port))
48285- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
48286-
48287 port->uartclk = 1;
48288
48289 if (cfg->uart_flags & UPF_CONS_FLOW) {
48290diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
48291index 28cdd28..56f1d60 100644
48292--- a/drivers/tty/serial/serial_core.c
48293+++ b/drivers/tty/serial/serial_core.c
48294@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
48295 uart_flush_buffer(tty);
48296 uart_shutdown(tty, state);
48297 spin_lock_irqsave(&port->lock, flags);
48298- port->count = 0;
48299+ atomic_set(&port->count, 0);
48300 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
48301 spin_unlock_irqrestore(&port->lock, flags);
48302 tty_port_tty_set(port, NULL);
48303@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48304 goto end;
48305 }
48306
48307- port->count++;
48308+ atomic_inc(&port->count);
48309 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
48310 retval = -ENXIO;
48311 goto err_dec_count;
48312@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48313 /*
48314 * Make sure the device is in D0 state.
48315 */
48316- if (port->count == 1)
48317+ if (atomic_read(&port->count) == 1)
48318 uart_change_pm(state, UART_PM_STATE_ON);
48319
48320 /*
48321@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48322 end:
48323 return retval;
48324 err_dec_count:
48325- port->count--;
48326+ atomic_inc(&port->count);
48327 mutex_unlock(&port->mutex);
48328 goto end;
48329 }
48330diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
48331index 8eaf1ab..85c030d 100644
48332--- a/drivers/tty/synclink.c
48333+++ b/drivers/tty/synclink.c
48334@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48335
48336 if (debug_level >= DEBUG_LEVEL_INFO)
48337 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
48338- __FILE__,__LINE__, info->device_name, info->port.count);
48339+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48340
48341 if (tty_port_close_start(&info->port, tty, filp) == 0)
48342 goto cleanup;
48343@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48344 cleanup:
48345 if (debug_level >= DEBUG_LEVEL_INFO)
48346 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
48347- tty->driver->name, info->port.count);
48348+ tty->driver->name, atomic_read(&info->port.count));
48349
48350 } /* end of mgsl_close() */
48351
48352@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
48353
48354 mgsl_flush_buffer(tty);
48355 shutdown(info);
48356-
48357- info->port.count = 0;
48358+
48359+ atomic_set(&info->port.count, 0);
48360 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48361 info->port.tty = NULL;
48362
48363@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48364
48365 if (debug_level >= DEBUG_LEVEL_INFO)
48366 printk("%s(%d):block_til_ready before block on %s count=%d\n",
48367- __FILE__,__LINE__, tty->driver->name, port->count );
48368+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48369
48370 spin_lock_irqsave(&info->irq_spinlock, flags);
48371 if (!tty_hung_up_p(filp)) {
48372 extra_count = true;
48373- port->count--;
48374+ atomic_dec(&port->count);
48375 }
48376 spin_unlock_irqrestore(&info->irq_spinlock, flags);
48377 port->blocked_open++;
48378@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48379
48380 if (debug_level >= DEBUG_LEVEL_INFO)
48381 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
48382- __FILE__,__LINE__, tty->driver->name, port->count );
48383+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48384
48385 tty_unlock(tty);
48386 schedule();
48387@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48388
48389 /* FIXME: Racy on hangup during close wait */
48390 if (extra_count)
48391- port->count++;
48392+ atomic_inc(&port->count);
48393 port->blocked_open--;
48394
48395 if (debug_level >= DEBUG_LEVEL_INFO)
48396 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
48397- __FILE__,__LINE__, tty->driver->name, port->count );
48398+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48399
48400 if (!retval)
48401 port->flags |= ASYNC_NORMAL_ACTIVE;
48402@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48403
48404 if (debug_level >= DEBUG_LEVEL_INFO)
48405 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
48406- __FILE__,__LINE__,tty->driver->name, info->port.count);
48407+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48408
48409 /* If port is closing, signal caller to try again */
48410 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48411@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48412 spin_unlock_irqrestore(&info->netlock, flags);
48413 goto cleanup;
48414 }
48415- info->port.count++;
48416+ atomic_inc(&info->port.count);
48417 spin_unlock_irqrestore(&info->netlock, flags);
48418
48419- if (info->port.count == 1) {
48420+ if (atomic_read(&info->port.count) == 1) {
48421 /* 1st open on this device, init hardware */
48422 retval = startup(info);
48423 if (retval < 0)
48424@@ -3446,8 +3446,8 @@ cleanup:
48425 if (retval) {
48426 if (tty->count == 1)
48427 info->port.tty = NULL; /* tty layer will release tty struct */
48428- if(info->port.count)
48429- info->port.count--;
48430+ if (atomic_read(&info->port.count))
48431+ atomic_dec(&info->port.count);
48432 }
48433
48434 return retval;
48435@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48436 unsigned short new_crctype;
48437
48438 /* return error if TTY interface open */
48439- if (info->port.count)
48440+ if (atomic_read(&info->port.count))
48441 return -EBUSY;
48442
48443 switch (encoding)
48444@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
48445
48446 /* arbitrate between network and tty opens */
48447 spin_lock_irqsave(&info->netlock, flags);
48448- if (info->port.count != 0 || info->netcount != 0) {
48449+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48450 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48451 spin_unlock_irqrestore(&info->netlock, flags);
48452 return -EBUSY;
48453@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48454 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48455
48456 /* return error if TTY interface open */
48457- if (info->port.count)
48458+ if (atomic_read(&info->port.count))
48459 return -EBUSY;
48460
48461 if (cmd != SIOCWANDEV)
48462diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
48463index 1abf946..1ee34fc 100644
48464--- a/drivers/tty/synclink_gt.c
48465+++ b/drivers/tty/synclink_gt.c
48466@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48467 tty->driver_data = info;
48468 info->port.tty = tty;
48469
48470- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
48471+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
48472
48473 /* If port is closing, signal caller to try again */
48474 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48475@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48476 mutex_unlock(&info->port.mutex);
48477 goto cleanup;
48478 }
48479- info->port.count++;
48480+ atomic_inc(&info->port.count);
48481 spin_unlock_irqrestore(&info->netlock, flags);
48482
48483- if (info->port.count == 1) {
48484+ if (atomic_read(&info->port.count) == 1) {
48485 /* 1st open on this device, init hardware */
48486 retval = startup(info);
48487 if (retval < 0) {
48488@@ -715,8 +715,8 @@ cleanup:
48489 if (retval) {
48490 if (tty->count == 1)
48491 info->port.tty = NULL; /* tty layer will release tty struct */
48492- if(info->port.count)
48493- info->port.count--;
48494+ if(atomic_read(&info->port.count))
48495+ atomic_dec(&info->port.count);
48496 }
48497
48498 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
48499@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48500
48501 if (sanity_check(info, tty->name, "close"))
48502 return;
48503- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
48504+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
48505
48506 if (tty_port_close_start(&info->port, tty, filp) == 0)
48507 goto cleanup;
48508@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48509 tty_port_close_end(&info->port, tty);
48510 info->port.tty = NULL;
48511 cleanup:
48512- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
48513+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
48514 }
48515
48516 static void hangup(struct tty_struct *tty)
48517@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
48518 shutdown(info);
48519
48520 spin_lock_irqsave(&info->port.lock, flags);
48521- info->port.count = 0;
48522+ atomic_set(&info->port.count, 0);
48523 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48524 info->port.tty = NULL;
48525 spin_unlock_irqrestore(&info->port.lock, flags);
48526@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48527 unsigned short new_crctype;
48528
48529 /* return error if TTY interface open */
48530- if (info->port.count)
48531+ if (atomic_read(&info->port.count))
48532 return -EBUSY;
48533
48534 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
48535@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
48536
48537 /* arbitrate between network and tty opens */
48538 spin_lock_irqsave(&info->netlock, flags);
48539- if (info->port.count != 0 || info->netcount != 0) {
48540+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48541 DBGINFO(("%s hdlc_open busy\n", dev->name));
48542 spin_unlock_irqrestore(&info->netlock, flags);
48543 return -EBUSY;
48544@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48545 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
48546
48547 /* return error if TTY interface open */
48548- if (info->port.count)
48549+ if (atomic_read(&info->port.count))
48550 return -EBUSY;
48551
48552 if (cmd != SIOCWANDEV)
48553@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
48554 if (port == NULL)
48555 continue;
48556 spin_lock(&port->lock);
48557- if ((port->port.count || port->netcount) &&
48558+ if ((atomic_read(&port->port.count) || port->netcount) &&
48559 port->pending_bh && !port->bh_running &&
48560 !port->bh_requested) {
48561 DBGISR(("%s bh queued\n", port->device_name));
48562@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48563 spin_lock_irqsave(&info->lock, flags);
48564 if (!tty_hung_up_p(filp)) {
48565 extra_count = true;
48566- port->count--;
48567+ atomic_dec(&port->count);
48568 }
48569 spin_unlock_irqrestore(&info->lock, flags);
48570 port->blocked_open++;
48571@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48572 remove_wait_queue(&port->open_wait, &wait);
48573
48574 if (extra_count)
48575- port->count++;
48576+ atomic_inc(&port->count);
48577 port->blocked_open--;
48578
48579 if (!retval)
48580diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
48581index dc6e969..5dc8786 100644
48582--- a/drivers/tty/synclinkmp.c
48583+++ b/drivers/tty/synclinkmp.c
48584@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48585
48586 if (debug_level >= DEBUG_LEVEL_INFO)
48587 printk("%s(%d):%s open(), old ref count = %d\n",
48588- __FILE__,__LINE__,tty->driver->name, info->port.count);
48589+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48590
48591 /* If port is closing, signal caller to try again */
48592 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48593@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48594 spin_unlock_irqrestore(&info->netlock, flags);
48595 goto cleanup;
48596 }
48597- info->port.count++;
48598+ atomic_inc(&info->port.count);
48599 spin_unlock_irqrestore(&info->netlock, flags);
48600
48601- if (info->port.count == 1) {
48602+ if (atomic_read(&info->port.count) == 1) {
48603 /* 1st open on this device, init hardware */
48604 retval = startup(info);
48605 if (retval < 0)
48606@@ -796,8 +796,8 @@ cleanup:
48607 if (retval) {
48608 if (tty->count == 1)
48609 info->port.tty = NULL; /* tty layer will release tty struct */
48610- if(info->port.count)
48611- info->port.count--;
48612+ if(atomic_read(&info->port.count))
48613+ atomic_dec(&info->port.count);
48614 }
48615
48616 return retval;
48617@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48618
48619 if (debug_level >= DEBUG_LEVEL_INFO)
48620 printk("%s(%d):%s close() entry, count=%d\n",
48621- __FILE__,__LINE__, info->device_name, info->port.count);
48622+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48623
48624 if (tty_port_close_start(&info->port, tty, filp) == 0)
48625 goto cleanup;
48626@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48627 cleanup:
48628 if (debug_level >= DEBUG_LEVEL_INFO)
48629 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
48630- tty->driver->name, info->port.count);
48631+ tty->driver->name, atomic_read(&info->port.count));
48632 }
48633
48634 /* Called by tty_hangup() when a hangup is signaled.
48635@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
48636 shutdown(info);
48637
48638 spin_lock_irqsave(&info->port.lock, flags);
48639- info->port.count = 0;
48640+ atomic_set(&info->port.count, 0);
48641 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48642 info->port.tty = NULL;
48643 spin_unlock_irqrestore(&info->port.lock, flags);
48644@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48645 unsigned short new_crctype;
48646
48647 /* return error if TTY interface open */
48648- if (info->port.count)
48649+ if (atomic_read(&info->port.count))
48650 return -EBUSY;
48651
48652 switch (encoding)
48653@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
48654
48655 /* arbitrate between network and tty opens */
48656 spin_lock_irqsave(&info->netlock, flags);
48657- if (info->port.count != 0 || info->netcount != 0) {
48658+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48659 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48660 spin_unlock_irqrestore(&info->netlock, flags);
48661 return -EBUSY;
48662@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48663 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48664
48665 /* return error if TTY interface open */
48666- if (info->port.count)
48667+ if (atomic_read(&info->port.count))
48668 return -EBUSY;
48669
48670 if (cmd != SIOCWANDEV)
48671@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
48672 * do not request bottom half processing if the
48673 * device is not open in a normal mode.
48674 */
48675- if ( port && (port->port.count || port->netcount) &&
48676+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
48677 port->pending_bh && !port->bh_running &&
48678 !port->bh_requested ) {
48679 if ( debug_level >= DEBUG_LEVEL_ISR )
48680@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48681
48682 if (debug_level >= DEBUG_LEVEL_INFO)
48683 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
48684- __FILE__,__LINE__, tty->driver->name, port->count );
48685+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48686
48687 spin_lock_irqsave(&info->lock, flags);
48688 if (!tty_hung_up_p(filp)) {
48689 extra_count = true;
48690- port->count--;
48691+ atomic_dec(&port->count);
48692 }
48693 spin_unlock_irqrestore(&info->lock, flags);
48694 port->blocked_open++;
48695@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48696
48697 if (debug_level >= DEBUG_LEVEL_INFO)
48698 printk("%s(%d):%s block_til_ready() count=%d\n",
48699- __FILE__,__LINE__, tty->driver->name, port->count );
48700+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48701
48702 tty_unlock(tty);
48703 schedule();
48704@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48705 remove_wait_queue(&port->open_wait, &wait);
48706
48707 if (extra_count)
48708- port->count++;
48709+ atomic_inc(&port->count);
48710 port->blocked_open--;
48711
48712 if (debug_level >= DEBUG_LEVEL_INFO)
48713 printk("%s(%d):%s block_til_ready() after, count=%d\n",
48714- __FILE__,__LINE__, tty->driver->name, port->count );
48715+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48716
48717 if (!retval)
48718 port->flags |= ASYNC_NORMAL_ACTIVE;
48719diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
48720index d5cc3ac..3263411 100644
48721--- a/drivers/tty/sysrq.c
48722+++ b/drivers/tty/sysrq.c
48723@@ -1033,7 +1033,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
48724 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
48725 size_t count, loff_t *ppos)
48726 {
48727- if (count) {
48728+ if (count && capable(CAP_SYS_ADMIN)) {
48729 char c;
48730
48731 if (get_user(c, buf))
48732diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
48733index 366af83..6db51c3 100644
48734--- a/drivers/tty/tty_io.c
48735+++ b/drivers/tty/tty_io.c
48736@@ -3467,7 +3467,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
48737
48738 void tty_default_fops(struct file_operations *fops)
48739 {
48740- *fops = tty_fops;
48741+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
48742 }
48743
48744 /*
48745diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
48746index 1afe192..73d2c20 100644
48747--- a/drivers/tty/tty_ldisc.c
48748+++ b/drivers/tty/tty_ldisc.c
48749@@ -66,7 +66,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
48750 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48751 tty_ldiscs[disc] = new_ldisc;
48752 new_ldisc->num = disc;
48753- new_ldisc->refcount = 0;
48754+ atomic_set(&new_ldisc->refcount, 0);
48755 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48756
48757 return ret;
48758@@ -94,7 +94,7 @@ int tty_unregister_ldisc(int disc)
48759 return -EINVAL;
48760
48761 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48762- if (tty_ldiscs[disc]->refcount)
48763+ if (atomic_read(&tty_ldiscs[disc]->refcount))
48764 ret = -EBUSY;
48765 else
48766 tty_ldiscs[disc] = NULL;
48767@@ -115,7 +115,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
48768 if (ldops) {
48769 ret = ERR_PTR(-EAGAIN);
48770 if (try_module_get(ldops->owner)) {
48771- ldops->refcount++;
48772+ atomic_inc(&ldops->refcount);
48773 ret = ldops;
48774 }
48775 }
48776@@ -128,7 +128,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
48777 unsigned long flags;
48778
48779 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48780- ldops->refcount--;
48781+ atomic_dec(&ldops->refcount);
48782 module_put(ldops->owner);
48783 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48784 }
48785@@ -196,7 +196,7 @@ static inline void tty_ldisc_put(struct tty_ldisc *ld)
48786 /* unreleased reader reference(s) will cause this WARN */
48787 WARN_ON(!atomic_dec_and_test(&ld->users));
48788
48789- ld->ops->refcount--;
48790+ atomic_dec(&ld->ops->refcount);
48791 module_put(ld->ops->owner);
48792 kfree(ld);
48793 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48794diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
48795index f597e88..b7f68ed 100644
48796--- a/drivers/tty/tty_port.c
48797+++ b/drivers/tty/tty_port.c
48798@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
48799 unsigned long flags;
48800
48801 spin_lock_irqsave(&port->lock, flags);
48802- port->count = 0;
48803+ atomic_set(&port->count, 0);
48804 port->flags &= ~ASYNC_NORMAL_ACTIVE;
48805 tty = port->tty;
48806 if (tty)
48807@@ -390,7 +390,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48808 /* The port lock protects the port counts */
48809 spin_lock_irqsave(&port->lock, flags);
48810 if (!tty_hung_up_p(filp))
48811- port->count--;
48812+ atomic_dec(&port->count);
48813 port->blocked_open++;
48814 spin_unlock_irqrestore(&port->lock, flags);
48815
48816@@ -432,7 +432,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48817 we must not mess that up further */
48818 spin_lock_irqsave(&port->lock, flags);
48819 if (!tty_hung_up_p(filp))
48820- port->count++;
48821+ atomic_inc(&port->count);
48822 port->blocked_open--;
48823 if (retval == 0)
48824 port->flags |= ASYNC_NORMAL_ACTIVE;
48825@@ -466,19 +466,19 @@ int tty_port_close_start(struct tty_port *port,
48826 return 0;
48827 }
48828
48829- if (tty->count == 1 && port->count != 1) {
48830+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
48831 printk(KERN_WARNING
48832 "tty_port_close_start: tty->count = 1 port count = %d.\n",
48833- port->count);
48834- port->count = 1;
48835+ atomic_read(&port->count));
48836+ atomic_set(&port->count, 1);
48837 }
48838- if (--port->count < 0) {
48839+ if (atomic_dec_return(&port->count) < 0) {
48840 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
48841- port->count);
48842- port->count = 0;
48843+ atomic_read(&port->count));
48844+ atomic_set(&port->count, 0);
48845 }
48846
48847- if (port->count) {
48848+ if (atomic_read(&port->count)) {
48849 spin_unlock_irqrestore(&port->lock, flags);
48850 if (port->ops->drop)
48851 port->ops->drop(port);
48852@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
48853 {
48854 spin_lock_irq(&port->lock);
48855 if (!tty_hung_up_p(filp))
48856- ++port->count;
48857+ atomic_inc(&port->count);
48858 spin_unlock_irq(&port->lock);
48859 tty_port_tty_set(port, tty);
48860
48861diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
48862index a9af1b9a..1e08e7f 100644
48863--- a/drivers/tty/vt/keyboard.c
48864+++ b/drivers/tty/vt/keyboard.c
48865@@ -647,6 +647,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
48866 kbd->kbdmode == VC_OFF) &&
48867 value != KVAL(K_SAK))
48868 return; /* SAK is allowed even in raw mode */
48869+
48870+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48871+ {
48872+ void *func = fn_handler[value];
48873+ if (func == fn_show_state || func == fn_show_ptregs ||
48874+ func == fn_show_mem)
48875+ return;
48876+ }
48877+#endif
48878+
48879 fn_handler[value](vc);
48880 }
48881
48882@@ -1795,9 +1805,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48883 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
48884 return -EFAULT;
48885
48886- if (!capable(CAP_SYS_TTY_CONFIG))
48887- perm = 0;
48888-
48889 switch (cmd) {
48890 case KDGKBENT:
48891 /* Ensure another thread doesn't free it under us */
48892@@ -1812,6 +1819,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48893 spin_unlock_irqrestore(&kbd_event_lock, flags);
48894 return put_user(val, &user_kbe->kb_value);
48895 case KDSKBENT:
48896+ if (!capable(CAP_SYS_TTY_CONFIG))
48897+ perm = 0;
48898+
48899 if (!perm)
48900 return -EPERM;
48901 if (!i && v == K_NOSUCHMAP) {
48902@@ -1902,9 +1912,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48903 int i, j, k;
48904 int ret;
48905
48906- if (!capable(CAP_SYS_TTY_CONFIG))
48907- perm = 0;
48908-
48909 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
48910 if (!kbs) {
48911 ret = -ENOMEM;
48912@@ -1938,6 +1945,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48913 kfree(kbs);
48914 return ((p && *p) ? -EOVERFLOW : 0);
48915 case KDSKBSENT:
48916+ if (!capable(CAP_SYS_TTY_CONFIG))
48917+ perm = 0;
48918+
48919 if (!perm) {
48920 ret = -EPERM;
48921 goto reterr;
48922diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
48923index 3b96f18..026a9bf 100644
48924--- a/drivers/uio/uio.c
48925+++ b/drivers/uio/uio.c
48926@@ -25,6 +25,7 @@
48927 #include <linux/kobject.h>
48928 #include <linux/cdev.h>
48929 #include <linux/uio_driver.h>
48930+#include <asm/local.h>
48931
48932 #define UIO_MAX_DEVICES (1U << MINORBITS)
48933
48934@@ -32,10 +33,10 @@ struct uio_device {
48935 struct module *owner;
48936 struct device *dev;
48937 int minor;
48938- atomic_t event;
48939+ atomic_unchecked_t event;
48940 struct fasync_struct *async_queue;
48941 wait_queue_head_t wait;
48942- int vma_count;
48943+ local_t vma_count;
48944 struct uio_info *info;
48945 struct kobject *map_dir;
48946 struct kobject *portio_dir;
48947@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
48948 struct device_attribute *attr, char *buf)
48949 {
48950 struct uio_device *idev = dev_get_drvdata(dev);
48951- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
48952+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
48953 }
48954
48955 static struct device_attribute uio_class_attributes[] = {
48956@@ -398,7 +399,7 @@ void uio_event_notify(struct uio_info *info)
48957 {
48958 struct uio_device *idev = info->uio_dev;
48959
48960- atomic_inc(&idev->event);
48961+ atomic_inc_unchecked(&idev->event);
48962 wake_up_interruptible(&idev->wait);
48963 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
48964 }
48965@@ -451,7 +452,7 @@ static int uio_open(struct inode *inode, struct file *filep)
48966 }
48967
48968 listener->dev = idev;
48969- listener->event_count = atomic_read(&idev->event);
48970+ listener->event_count = atomic_read_unchecked(&idev->event);
48971 filep->private_data = listener;
48972
48973 if (idev->info->open) {
48974@@ -502,7 +503,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
48975 return -EIO;
48976
48977 poll_wait(filep, &idev->wait, wait);
48978- if (listener->event_count != atomic_read(&idev->event))
48979+ if (listener->event_count != atomic_read_unchecked(&idev->event))
48980 return POLLIN | POLLRDNORM;
48981 return 0;
48982 }
48983@@ -527,7 +528,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
48984 do {
48985 set_current_state(TASK_INTERRUPTIBLE);
48986
48987- event_count = atomic_read(&idev->event);
48988+ event_count = atomic_read_unchecked(&idev->event);
48989 if (event_count != listener->event_count) {
48990 if (copy_to_user(buf, &event_count, count))
48991 retval = -EFAULT;
48992@@ -596,13 +597,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
48993 static void uio_vma_open(struct vm_area_struct *vma)
48994 {
48995 struct uio_device *idev = vma->vm_private_data;
48996- idev->vma_count++;
48997+ local_inc(&idev->vma_count);
48998 }
48999
49000 static void uio_vma_close(struct vm_area_struct *vma)
49001 {
49002 struct uio_device *idev = vma->vm_private_data;
49003- idev->vma_count--;
49004+ local_dec(&idev->vma_count);
49005 }
49006
49007 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
49008@@ -809,7 +810,7 @@ int __uio_register_device(struct module *owner,
49009 idev->owner = owner;
49010 idev->info = info;
49011 init_waitqueue_head(&idev->wait);
49012- atomic_set(&idev->event, 0);
49013+ atomic_set_unchecked(&idev->event, 0);
49014
49015 ret = uio_get_minor(idev);
49016 if (ret)
49017diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
49018index 8a7eb77..c00402f 100644
49019--- a/drivers/usb/atm/cxacru.c
49020+++ b/drivers/usb/atm/cxacru.c
49021@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
49022 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
49023 if (ret < 2)
49024 return -EINVAL;
49025- if (index < 0 || index > 0x7f)
49026+ if (index > 0x7f)
49027 return -EINVAL;
49028 pos += tmp;
49029
49030diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
49031index 5e0d33a..cc10579 100644
49032--- a/drivers/usb/atm/usbatm.c
49033+++ b/drivers/usb/atm/usbatm.c
49034@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49035 if (printk_ratelimit())
49036 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
49037 __func__, vpi, vci);
49038- atomic_inc(&vcc->stats->rx_err);
49039+ atomic_inc_unchecked(&vcc->stats->rx_err);
49040 return;
49041 }
49042
49043@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49044 if (length > ATM_MAX_AAL5_PDU) {
49045 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
49046 __func__, length, vcc);
49047- atomic_inc(&vcc->stats->rx_err);
49048+ atomic_inc_unchecked(&vcc->stats->rx_err);
49049 goto out;
49050 }
49051
49052@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49053 if (sarb->len < pdu_length) {
49054 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
49055 __func__, pdu_length, sarb->len, vcc);
49056- atomic_inc(&vcc->stats->rx_err);
49057+ atomic_inc_unchecked(&vcc->stats->rx_err);
49058 goto out;
49059 }
49060
49061 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
49062 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
49063 __func__, vcc);
49064- atomic_inc(&vcc->stats->rx_err);
49065+ atomic_inc_unchecked(&vcc->stats->rx_err);
49066 goto out;
49067 }
49068
49069@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49070 if (printk_ratelimit())
49071 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
49072 __func__, length);
49073- atomic_inc(&vcc->stats->rx_drop);
49074+ atomic_inc_unchecked(&vcc->stats->rx_drop);
49075 goto out;
49076 }
49077
49078@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49079
49080 vcc->push(vcc, skb);
49081
49082- atomic_inc(&vcc->stats->rx);
49083+ atomic_inc_unchecked(&vcc->stats->rx);
49084 out:
49085 skb_trim(sarb, 0);
49086 }
49087@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
49088 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
49089
49090 usbatm_pop(vcc, skb);
49091- atomic_inc(&vcc->stats->tx);
49092+ atomic_inc_unchecked(&vcc->stats->tx);
49093
49094 skb = skb_dequeue(&instance->sndqueue);
49095 }
49096@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
49097 if (!left--)
49098 return sprintf(page,
49099 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
49100- atomic_read(&atm_dev->stats.aal5.tx),
49101- atomic_read(&atm_dev->stats.aal5.tx_err),
49102- atomic_read(&atm_dev->stats.aal5.rx),
49103- atomic_read(&atm_dev->stats.aal5.rx_err),
49104- atomic_read(&atm_dev->stats.aal5.rx_drop));
49105+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
49106+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
49107+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
49108+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
49109+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
49110
49111 if (!left--) {
49112 if (instance->disconnected)
49113diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
49114index 2a3bbdf..91d72cf 100644
49115--- a/drivers/usb/core/devices.c
49116+++ b/drivers/usb/core/devices.c
49117@@ -126,7 +126,7 @@ static const char format_endpt[] =
49118 * time it gets called.
49119 */
49120 static struct device_connect_event {
49121- atomic_t count;
49122+ atomic_unchecked_t count;
49123 wait_queue_head_t wait;
49124 } device_event = {
49125 .count = ATOMIC_INIT(1),
49126@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
49127
49128 void usbfs_conn_disc_event(void)
49129 {
49130- atomic_add(2, &device_event.count);
49131+ atomic_add_unchecked(2, &device_event.count);
49132 wake_up(&device_event.wait);
49133 }
49134
49135@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
49136
49137 poll_wait(file, &device_event.wait, wait);
49138
49139- event_count = atomic_read(&device_event.count);
49140+ event_count = atomic_read_unchecked(&device_event.count);
49141 if (file->f_version != event_count) {
49142 file->f_version = event_count;
49143 return POLLIN | POLLRDNORM;
49144diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
49145index 014dc99..4d25fd7 100644
49146--- a/drivers/usb/core/hcd.c
49147+++ b/drivers/usb/core/hcd.c
49148@@ -1551,7 +1551,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
49149 */
49150 usb_get_urb(urb);
49151 atomic_inc(&urb->use_count);
49152- atomic_inc(&urb->dev->urbnum);
49153+ atomic_inc_unchecked(&urb->dev->urbnum);
49154 usbmon_urb_submit(&hcd->self, urb);
49155
49156 /* NOTE requirements on root-hub callers (usbfs and the hub
49157@@ -1578,7 +1578,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
49158 urb->hcpriv = NULL;
49159 INIT_LIST_HEAD(&urb->urb_list);
49160 atomic_dec(&urb->use_count);
49161- atomic_dec(&urb->dev->urbnum);
49162+ atomic_dec_unchecked(&urb->dev->urbnum);
49163 if (atomic_read(&urb->reject))
49164 wake_up(&usb_kill_urb_queue);
49165 usb_put_urb(urb);
49166diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
49167index 558313d..8cadfa5 100644
49168--- a/drivers/usb/core/hub.c
49169+++ b/drivers/usb/core/hub.c
49170@@ -27,6 +27,7 @@
49171 #include <linux/freezer.h>
49172 #include <linux/random.h>
49173 #include <linux/pm_qos.h>
49174+#include <linux/grsecurity.h>
49175
49176 #include <asm/uaccess.h>
49177 #include <asm/byteorder.h>
49178@@ -4426,6 +4427,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
49179 goto done;
49180 return;
49181 }
49182+
49183+ if (gr_handle_new_usb())
49184+ goto done;
49185+
49186 if (hub_is_superspeed(hub->hdev))
49187 unit_load = 150;
49188 else
49189diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
49190index e7ee1e4..1dfc9ea4 100644
49191--- a/drivers/usb/core/message.c
49192+++ b/drivers/usb/core/message.c
49193@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
49194 * method can wait for it to complete. Since you don't have a handle on the
49195 * URB used, you can't cancel the request.
49196 */
49197-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
49198+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
49199 __u8 requesttype, __u16 value, __u16 index, void *data,
49200 __u16 size, int timeout)
49201 {
49202diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
49203index d9284b9..17023c7 100644
49204--- a/drivers/usb/core/sysfs.c
49205+++ b/drivers/usb/core/sysfs.c
49206@@ -239,7 +239,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
49207 struct usb_device *udev;
49208
49209 udev = to_usb_device(dev);
49210- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
49211+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
49212 }
49213 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
49214
49215diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
49216index 7dad603..350f7a9 100644
49217--- a/drivers/usb/core/usb.c
49218+++ b/drivers/usb/core/usb.c
49219@@ -422,7 +422,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
49220 set_dev_node(&dev->dev, dev_to_node(bus->controller));
49221 dev->state = USB_STATE_ATTACHED;
49222 dev->lpm_disable_count = 1;
49223- atomic_set(&dev->urbnum, 0);
49224+ atomic_set_unchecked(&dev->urbnum, 0);
49225
49226 INIT_LIST_HEAD(&dev->ep0.urb_list);
49227 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
49228diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
49229index f77083f..f3e2e34 100644
49230--- a/drivers/usb/dwc3/gadget.c
49231+++ b/drivers/usb/dwc3/gadget.c
49232@@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
49233 if (!usb_endpoint_xfer_isoc(desc))
49234 return 0;
49235
49236- memset(&trb_link, 0, sizeof(trb_link));
49237-
49238 /* Link TRB for ISOC. The HWO bit is never reset */
49239 trb_st_hw = &dep->trb_pool[0];
49240
49241diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
49242index 5e29dde..eca992f 100644
49243--- a/drivers/usb/early/ehci-dbgp.c
49244+++ b/drivers/usb/early/ehci-dbgp.c
49245@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
49246
49247 #ifdef CONFIG_KGDB
49248 static struct kgdb_io kgdbdbgp_io_ops;
49249-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
49250+static struct kgdb_io kgdbdbgp_io_ops_console;
49251+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
49252 #else
49253 #define dbgp_kgdb_mode (0)
49254 #endif
49255@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
49256 .write_char = kgdbdbgp_write_char,
49257 };
49258
49259+static struct kgdb_io kgdbdbgp_io_ops_console = {
49260+ .name = "kgdbdbgp",
49261+ .read_char = kgdbdbgp_read_char,
49262+ .write_char = kgdbdbgp_write_char,
49263+ .is_console = 1
49264+};
49265+
49266 static int kgdbdbgp_wait_time;
49267
49268 static int __init kgdbdbgp_parse_config(char *str)
49269@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
49270 ptr++;
49271 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
49272 }
49273- kgdb_register_io_module(&kgdbdbgp_io_ops);
49274- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
49275+ if (early_dbgp_console.index != -1)
49276+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
49277+ else
49278+ kgdb_register_io_module(&kgdbdbgp_io_ops);
49279
49280 return 0;
49281 }
49282diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
49283index b369292..9f3ba40 100644
49284--- a/drivers/usb/gadget/u_serial.c
49285+++ b/drivers/usb/gadget/u_serial.c
49286@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49287 spin_lock_irq(&port->port_lock);
49288
49289 /* already open? Great. */
49290- if (port->port.count) {
49291+ if (atomic_read(&port->port.count)) {
49292 status = 0;
49293- port->port.count++;
49294+ atomic_inc(&port->port.count);
49295
49296 /* currently opening/closing? wait ... */
49297 } else if (port->openclose) {
49298@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49299 tty->driver_data = port;
49300 port->port.tty = tty;
49301
49302- port->port.count = 1;
49303+ atomic_set(&port->port.count, 1);
49304 port->openclose = false;
49305
49306 /* if connected, start the I/O stream */
49307@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49308
49309 spin_lock_irq(&port->port_lock);
49310
49311- if (port->port.count != 1) {
49312- if (port->port.count == 0)
49313+ if (atomic_read(&port->port.count) != 1) {
49314+ if (atomic_read(&port->port.count) == 0)
49315 WARN_ON(1);
49316 else
49317- --port->port.count;
49318+ atomic_dec(&port->port.count);
49319 goto exit;
49320 }
49321
49322@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49323 * and sleep if necessary
49324 */
49325 port->openclose = true;
49326- port->port.count = 0;
49327+ atomic_set(&port->port.count, 0);
49328
49329 gser = port->port_usb;
49330 if (gser && gser->disconnect)
49331@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
49332 int cond;
49333
49334 spin_lock_irq(&port->port_lock);
49335- cond = (port->port.count == 0) && !port->openclose;
49336+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
49337 spin_unlock_irq(&port->port_lock);
49338 return cond;
49339 }
49340@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
49341 /* if it's already open, start I/O ... and notify the serial
49342 * protocol about open/close status (connect/disconnect).
49343 */
49344- if (port->port.count) {
49345+ if (atomic_read(&port->port.count)) {
49346 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
49347 gs_start_io(port);
49348 if (gser->connect)
49349@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
49350
49351 port->port_usb = NULL;
49352 gser->ioport = NULL;
49353- if (port->port.count > 0 || port->openclose) {
49354+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
49355 wake_up_interruptible(&port->drain_wait);
49356 if (port->port.tty)
49357 tty_hangup(port->port.tty);
49358@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
49359
49360 /* finally, free any unused/unusable I/O buffers */
49361 spin_lock_irqsave(&port->port_lock, flags);
49362- if (port->port.count == 0 && !port->openclose)
49363+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
49364 gs_buf_free(&port->port_write_buf);
49365 gs_free_requests(gser->out, &port->read_pool, NULL);
49366 gs_free_requests(gser->out, &port->read_queue, NULL);
49367diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
49368index ba6a5d6..f88f7f3 100644
49369--- a/drivers/usb/misc/appledisplay.c
49370+++ b/drivers/usb/misc/appledisplay.c
49371@@ -83,7 +83,7 @@ struct appledisplay {
49372 spinlock_t lock;
49373 };
49374
49375-static atomic_t count_displays = ATOMIC_INIT(0);
49376+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
49377 static struct workqueue_struct *wq;
49378
49379 static void appledisplay_complete(struct urb *urb)
49380@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
49381
49382 /* Register backlight device */
49383 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
49384- atomic_inc_return(&count_displays) - 1);
49385+ atomic_inc_return_unchecked(&count_displays) - 1);
49386 memset(&props, 0, sizeof(struct backlight_properties));
49387 props.type = BACKLIGHT_RAW;
49388 props.max_brightness = 0xff;
49389diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
49390index afb50ea..7b0b1cf 100644
49391--- a/drivers/usb/serial/console.c
49392+++ b/drivers/usb/serial/console.c
49393@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
49394
49395 info->port = port;
49396
49397- ++port->port.count;
49398+ atomic_inc(&port->port.count);
49399 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
49400 if (serial->type->set_termios) {
49401 /*
49402@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
49403 }
49404 /* Now that any required fake tty operations are completed restore
49405 * the tty port count */
49406- --port->port.count;
49407+ atomic_dec(&port->port.count);
49408 /* The console is special in terms of closing the device so
49409 * indicate this port is now acting as a system console. */
49410 port->port.console = 1;
49411@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
49412 free_tty:
49413 kfree(tty);
49414 reset_open_count:
49415- port->port.count = 0;
49416+ atomic_set(&port->port.count, 0);
49417 usb_autopm_put_interface(serial->interface);
49418 error_get_interface:
49419 usb_serial_put(serial);
49420diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
49421index 75f70f0..d467e1a 100644
49422--- a/drivers/usb/storage/usb.h
49423+++ b/drivers/usb/storage/usb.h
49424@@ -63,7 +63,7 @@ struct us_unusual_dev {
49425 __u8 useProtocol;
49426 __u8 useTransport;
49427 int (*initFunction)(struct us_data *);
49428-};
49429+} __do_const;
49430
49431
49432 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
49433diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
49434index d6bea3e..60b250e 100644
49435--- a/drivers/usb/wusbcore/wa-hc.h
49436+++ b/drivers/usb/wusbcore/wa-hc.h
49437@@ -192,7 +192,7 @@ struct wahc {
49438 struct list_head xfer_delayed_list;
49439 spinlock_t xfer_list_lock;
49440 struct work_struct xfer_work;
49441- atomic_t xfer_id_count;
49442+ atomic_unchecked_t xfer_id_count;
49443 };
49444
49445
49446@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
49447 INIT_LIST_HEAD(&wa->xfer_delayed_list);
49448 spin_lock_init(&wa->xfer_list_lock);
49449 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
49450- atomic_set(&wa->xfer_id_count, 1);
49451+ atomic_set_unchecked(&wa->xfer_id_count, 1);
49452 }
49453
49454 /**
49455diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
49456index d3493ca..0c33b7e 100644
49457--- a/drivers/usb/wusbcore/wa-xfer.c
49458+++ b/drivers/usb/wusbcore/wa-xfer.c
49459@@ -297,7 +297,7 @@ out:
49460 */
49461 static void wa_xfer_id_init(struct wa_xfer *xfer)
49462 {
49463- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
49464+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
49465 }
49466
49467 /*
49468diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
49469index 842f450..d1d7409 100644
49470--- a/drivers/vfio/vfio.c
49471+++ b/drivers/vfio/vfio.c
49472@@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
49473 return 0;
49474
49475 /* TODO Prevent device auto probing */
49476- WARN("Device %s added to live group %d!\n", dev_name(dev),
49477+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
49478 iommu_group_id(group->iommu_group));
49479
49480 return 0;
49481diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
49482index 5174eba..86e764a 100644
49483--- a/drivers/vhost/vringh.c
49484+++ b/drivers/vhost/vringh.c
49485@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
49486
49487 static inline int putu16_kern(u16 *p, u16 val)
49488 {
49489- ACCESS_ONCE(*p) = val;
49490+ ACCESS_ONCE_RW(*p) = val;
49491 return 0;
49492 }
49493
49494diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
49495index a4dfe8c..297ddd9 100644
49496--- a/drivers/video/aty/aty128fb.c
49497+++ b/drivers/video/aty/aty128fb.c
49498@@ -149,7 +149,7 @@ enum {
49499 };
49500
49501 /* Must match above enum */
49502-static char * const r128_family[] = {
49503+static const char * const r128_family[] = {
49504 "AGP",
49505 "PCI",
49506 "PRO AGP",
49507diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
49508index 9b0f12c..024673d 100644
49509--- a/drivers/video/aty/atyfb_base.c
49510+++ b/drivers/video/aty/atyfb_base.c
49511@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
49512 par->accel_flags = var->accel_flags; /* hack */
49513
49514 if (var->accel_flags) {
49515- info->fbops->fb_sync = atyfb_sync;
49516+ pax_open_kernel();
49517+ *(void **)&info->fbops->fb_sync = atyfb_sync;
49518+ pax_close_kernel();
49519 info->flags &= ~FBINFO_HWACCEL_DISABLED;
49520 } else {
49521- info->fbops->fb_sync = NULL;
49522+ pax_open_kernel();
49523+ *(void **)&info->fbops->fb_sync = NULL;
49524+ pax_close_kernel();
49525 info->flags |= FBINFO_HWACCEL_DISABLED;
49526 }
49527
49528diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
49529index 95ec042..e6affdd 100644
49530--- a/drivers/video/aty/mach64_cursor.c
49531+++ b/drivers/video/aty/mach64_cursor.c
49532@@ -7,6 +7,7 @@
49533 #include <linux/string.h>
49534
49535 #include <asm/io.h>
49536+#include <asm/pgtable.h>
49537
49538 #ifdef __sparc__
49539 #include <asm/fbio.h>
49540@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
49541 info->sprite.buf_align = 16; /* and 64 lines tall. */
49542 info->sprite.flags = FB_PIXMAP_IO;
49543
49544- info->fbops->fb_cursor = atyfb_cursor;
49545+ pax_open_kernel();
49546+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
49547+ pax_close_kernel();
49548
49549 return 0;
49550 }
49551diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
49552index bca6ccc..252107e 100644
49553--- a/drivers/video/backlight/kb3886_bl.c
49554+++ b/drivers/video/backlight/kb3886_bl.c
49555@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
49556 static unsigned long kb3886bl_flags;
49557 #define KB3886BL_SUSPENDED 0x01
49558
49559-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
49560+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
49561 {
49562 .ident = "Sahara Touch-iT",
49563 .matches = {
49564diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
49565index 900aa4e..6d49418 100644
49566--- a/drivers/video/fb_defio.c
49567+++ b/drivers/video/fb_defio.c
49568@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
49569
49570 BUG_ON(!fbdefio);
49571 mutex_init(&fbdefio->lock);
49572- info->fbops->fb_mmap = fb_deferred_io_mmap;
49573+ pax_open_kernel();
49574+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
49575+ pax_close_kernel();
49576 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
49577 INIT_LIST_HEAD(&fbdefio->pagelist);
49578 if (fbdefio->delay == 0) /* set a default of 1 s */
49579@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
49580 page->mapping = NULL;
49581 }
49582
49583- info->fbops->fb_mmap = NULL;
49584+ *(void **)&info->fbops->fb_mmap = NULL;
49585 mutex_destroy(&fbdefio->lock);
49586 }
49587 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
49588diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
49589index 5c3960d..15cf8fc 100644
49590--- a/drivers/video/fbcmap.c
49591+++ b/drivers/video/fbcmap.c
49592@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
49593 rc = -ENODEV;
49594 goto out;
49595 }
49596- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
49597- !info->fbops->fb_setcmap)) {
49598+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
49599 rc = -EINVAL;
49600 goto out1;
49601 }
49602diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
49603index 36e1fe2..c744820 100644
49604--- a/drivers/video/fbmem.c
49605+++ b/drivers/video/fbmem.c
49606@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49607 image->dx += image->width + 8;
49608 }
49609 } else if (rotate == FB_ROTATE_UD) {
49610- for (x = 0; x < num && image->dx >= 0; x++) {
49611+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
49612 info->fbops->fb_imageblit(info, image);
49613 image->dx -= image->width + 8;
49614 }
49615@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49616 image->dy += image->height + 8;
49617 }
49618 } else if (rotate == FB_ROTATE_CCW) {
49619- for (x = 0; x < num && image->dy >= 0; x++) {
49620+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
49621 info->fbops->fb_imageblit(info, image);
49622 image->dy -= image->height + 8;
49623 }
49624@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
49625 return -EFAULT;
49626 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
49627 return -EINVAL;
49628- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
49629+ if (con2fb.framebuffer >= FB_MAX)
49630 return -EINVAL;
49631 if (!registered_fb[con2fb.framebuffer])
49632 request_module("fb%d", con2fb.framebuffer);
49633diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
49634index d4d2c5f..ebbd113 100644
49635--- a/drivers/video/hyperv_fb.c
49636+++ b/drivers/video/hyperv_fb.c
49637@@ -233,7 +233,7 @@ static uint screen_fb_size;
49638 static inline int synthvid_send(struct hv_device *hdev,
49639 struct synthvid_msg *msg)
49640 {
49641- static atomic64_t request_id = ATOMIC64_INIT(0);
49642+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
49643 int ret;
49644
49645 msg->pipe_hdr.type = PIPE_MSG_DATA;
49646@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
49647
49648 ret = vmbus_sendpacket(hdev->channel, msg,
49649 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
49650- atomic64_inc_return(&request_id),
49651+ atomic64_inc_return_unchecked(&request_id),
49652 VM_PKT_DATA_INBAND, 0);
49653
49654 if (ret)
49655diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
49656index 7672d2e..b56437f 100644
49657--- a/drivers/video/i810/i810_accel.c
49658+++ b/drivers/video/i810/i810_accel.c
49659@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
49660 }
49661 }
49662 printk("ringbuffer lockup!!!\n");
49663+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
49664 i810_report_error(mmio);
49665 par->dev_flags |= LOCKUP;
49666 info->pixmap.scan_align = 1;
49667diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
49668index 285d552..eafa544 100644
49669--- a/drivers/video/logo/logo_linux_clut224.ppm
49670+++ b/drivers/video/logo/logo_linux_clut224.ppm
49671@@ -1,883 +1,1123 @@
49672 P3
49673 80 80
49674 255
49675-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49676-0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 33 49 54 59 85 92 73 97 106
49677-83 116 129 105 131 142 115 114 122 74 88 93 20 29 31 0 0 0 0 0 0 0 0 0
49678-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49679-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 10 10 10 10 10 10
49680-10 10 10 6 6 6 6 6 6 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49681-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49682-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49683-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49684-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49685-
49686-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49687-0 0 0 0 0 0 2 3 3 17 23 26 50 67 72 73 97 106 59 85 92 73 97 106
49688-105 131 142 124 127 131 105 131 142 105 131 142 53 75 83 6 8 8 0 0 0 0 0 0
49689-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49690-0 0 0 6 6 6 10 10 10 14 14 14 22 22 22 26 26 26 30 30 30 34 34 34
49691-30 30 30 30 30 30 26 26 26 18 18 18 14 14 14 10 10 10 6 6 6 0 0 0
49692-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49693-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49694-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49695-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49696-
49697-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0
49698-0 0 0 1 1 1 26 35 39 59 85 92 59 85 92 59 85 92 29 43 47 53 75 83
49699-108 122 132 132 98 104 108 122 132 105 131 142 101 101 101 43 45 48 6 8 8 0 0 0
49700-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49701-6 6 6 14 14 14 26 26 26 42 42 42 54 54 54 66 66 66 78 78 78 78 78 78
49702-78 78 78 74 74 74 66 66 66 54 54 54 42 42 42 26 26 26 18 18 18 10 10 10
49703-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49704-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49705-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49706-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49707-
49708-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0
49709-11 15 17 27 40 45 59 85 92 59 85 92 27 40 45 31 45 49 73 97 106 93 121 133
49710-108 122 132 108 122 132 105 131 142 108 122 132 105 131 142 73 97 106 26 35 39 0 0 0
49711-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
49712-22 22 22 42 42 42 66 66 66 86 86 86 66 66 66 38 38 38 38 38 38 22 22 22
49713-26 26 26 34 34 34 54 54 54 66 66 66 86 86 86 70 70 70 46 46 46 26 26 26
49714-14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49715-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49716-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49717-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49718-
49719-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 7 12 13 21 31 35 42 59 64
49720-53 75 83 53 75 83 50 67 72 42 59 64 32 40 45 42 59 64 73 97 106 116 116 116
49721-132 98 104 116 116 116 108 122 132 117 104 110 105 131 142 83 116 129 50 67 72 7 12 13
49722-1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
49723-50 50 50 82 82 82 58 58 58 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
49724-2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 54 54 54 86 86 86 66 66 66
49725-38 38 38 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49726-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49727-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49728-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49729-
49730-0 0 0 1 1 1 6 8 8 15 22 25 26 35 39 36 54 60 53 75 83 59 85 92
49731-59 85 92 48 63 69 15 22 25 12 17 20 52 67 79 94 94 94 132 98 104 132 98 104
49732-117 104 110 108 122 132 108 122 132 115 114 122 105 131 142 77 105 114 59 85 92 36 54 60
49733-7 12 13 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 50 50 50
49734-78 78 78 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49735-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 70 70 70
49736-78 78 78 46 46 46 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49737-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49738-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49739-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49740-
49741-0 0 0 15 22 25 29 43 47 36 54 60 42 59 64 42 59 64 48 63 69 21 31 35
49742-6 8 8 29 43 47 36 50 56 43 45 48 79 78 84 132 98 104 165 78 79 132 98 104
49743-108 122 132 117 104 110 117 104 110 108 122 132 77 105 114 73 97 106 95 131 149 78 102 129
49744-36 50 56 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18 42 42 42 82 82 82
49745-26 26 26 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49746-2 2 6 2 2 6 2 2 6 14 14 14 46 46 46 34 34 34 6 6 6 2 2 6
49747-42 42 42 78 78 78 42 42 42 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
49748-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49749-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49750-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49751-
49752-27 40 45 53 75 83 48 63 69 24 31 37 6 8 12 0 0 0 18 25 28 26 35 39
49753-12 17 20 26 35 39 65 78 84 112 81 86 152 81 83 137 83 86 132 98 104 117 104 110
49754-117 104 110 132 98 104 132 98 104 115 114 122 73 97 106 53 75 83 95 131 149 93 124 152
49755-68 78 128 15 22 25 0 0 0 0 0 0 10 10 10 30 30 30 66 66 66 58 58 58
49756-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49757-2 2 6 2 2 6 2 2 6 26 26 26 86 86 86 101 101 101 46 46 46 10 10 10
49758-2 2 6 58 58 58 70 70 70 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
49759-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49760-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49761-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49762-
49763-36 50 56 21 30 33 4 7 7 0 0 0 1 1 1 17 12 12 69 31 31 68 59 64
49764-57 59 63 21 31 35 32 40 45 86 73 69 152 81 83 152 81 83 117 104 110 132 98 104
49765-152 81 83 132 98 104 108 122 132 77 105 114 77 105 114 93 121 133 95 131 149 93 124 152
49766-95 131 149 53 75 83 11 15 17 0 0 0 14 14 14 42 42 42 86 86 86 10 10 10
49767-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49768-2 2 6 2 2 6 2 2 6 30 30 30 94 94 94 94 94 94 58 58 58 26 26 26
49769-2 2 6 6 6 6 78 78 78 54 54 54 22 22 22 6 6 6 0 0 0 0 0 0
49770-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49771-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49772-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49773-
49774-17 23 26 2 3 3 0 0 0 17 12 12 69 31 31 123 55 55 123 55 55 152 81 83
49775-86 73 69 17 23 26 7 12 13 45 54 57 101 101 101 137 83 86 132 98 104 132 98 104
49776-137 83 86 117 104 110 77 105 114 42 59 64 50 67 72 78 102 129 91 117 157 91 117 157
49777-95 131 149 83 116 129 40 48 73 6 6 6 22 22 22 62 62 62 62 62 62 2 2 6
49778-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49779-2 2 6 2 2 6 2 2 6 26 26 26 54 54 54 38 38 38 18 18 18 10 10 10
49780-2 2 6 2 2 6 34 34 34 82 82 82 38 38 38 14 14 14 0 0 0 0 0 0
49781-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49782-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49783-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49784-
49785-1 1 1 1 2 2 2 3 3 28 12 12 123 55 55 174 79 79 174 79 79 174 79 79
49786-152 81 83 68 59 64 26 35 39 27 40 45 79 78 84 137 83 86 165 78 79 137 83 86
49787-94 94 94 48 63 69 36 50 56 50 67 72 73 97 106 93 121 133 93 124 152 93 124 152
49788-95 131 149 91 118 149 78 102 129 27 40 45 30 30 30 78 78 78 30 30 30 2 2 6
49789-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49790-2 2 6 2 2 6 2 2 6 10 10 10 10 10 10 2 2 6 2 2 6 2 2 6
49791-2 2 6 2 2 6 2 2 6 78 78 78 50 50 50 18 18 18 6 6 6 0 0 0
49792-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49793-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49794-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49795-
49796-4 5 3 24 53 24 19 31 15 8 7 3 90 61 47 165 78 79 174 79 79 174 79 79
49797-174 79 79 137 83 86 60 52 57 7 12 13 17 23 26 70 70 70 132 98 104 112 81 86
49798-79 78 84 31 45 49 15 22 25 53 75 83 91 118 149 86 106 160 91 117 157 93 124 152
49799-91 117 157 93 124 152 95 131 149 53 75 83 50 50 50 86 86 86 14 14 14 2 2 6
49800-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49801-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49802-2 2 6 2 2 6 2 2 6 54 54 54 66 66 66 26 26 26 6 6 6 0 0 0
49803-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49804-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49805-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49806-
49807-19 31 15 34 76 34 34 76 34 19 31 15 28 12 12 123 55 55 174 79 79 174 79 79
49808-174 79 79 165 78 79 112 81 86 32 40 45 15 22 25 38 53 58 65 78 84 29 31 32
49809-21 30 33 42 59 64 60 80 103 78 102 129 87 112 149 84 96 162 91 117 157 93 124 152
49810-91 117 157 93 124 152 93 121 133 59 85 92 57 68 71 82 85 86 2 2 6 2 2 6
49811-2 2 6 6 6 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49812-2 2 6 2 2 6 2 2 6 6 6 6 14 14 14 10 10 10 2 2 6 2 2 6
49813-2 2 6 2 2 6 2 2 6 18 18 18 82 82 82 34 34 34 10 10 10 0 0 0
49814-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49815-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49816-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49817-
49818-34 76 34 40 89 40 40 89 40 34 76 34 8 15 6 48 26 18 123 55 55 174 79 79
49819-174 79 79 174 79 79 137 83 86 68 59 64 32 40 45 21 30 33 31 45 49 21 31 35
49820-12 17 20 48 63 69 78 102 129 81 88 166 84 96 162 91 117 157 93 124 152 91 117 157
49821-93 124 152 95 131 149 83 116 129 59 85 92 57 68 71 86 86 86 2 2 6 2 2 6
49822-6 6 6 6 6 6 22 22 22 34 34 34 6 6 6 2 2 6 2 2 6 2 2 6
49823-2 2 6 2 2 6 18 18 18 34 34 34 10 10 10 50 50 50 22 22 22 2 2 6
49824-2 2 6 2 2 6 2 2 6 10 10 10 86 86 86 42 42 42 14 14 14 0 0 0
49825-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49826-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49827-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49828-
49829-40 89 40 40 89 40 40 89 40 40 89 40 24 53 24 6 6 6 69 31 31 123 55 55
49830-123 55 55 90 61 47 69 31 31 36 32 33 21 31 35 7 12 13 18 25 28 48 63 69
49831-60 80 103 68 78 128 84 101 153 84 96 162 84 96 162 91 117 157 91 117 157 84 96 162
49832-91 117 157 73 97 106 48 63 69 50 67 72 57 59 63 86 86 86 2 2 6 2 2 6
49833-38 38 38 116 116 116 94 94 94 22 22 22 22 22 22 2 2 6 2 2 6 2 2 6
49834-14 14 14 86 86 86 124 131 137 170 170 170 151 151 151 38 38 38 26 26 26 6 6 6
49835-2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 46 46 46 14 14 14 0 0 0
49836-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49837-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49838-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49839-
49840-34 76 34 40 89 40 40 89 40 40 89 40 34 76 34 19 31 15 17 12 12 48 26 18
49841-48 26 18 8 7 3 10 10 22 23 29 47 51 61 92 42 59 64 21 30 33 34 45 54
49842-68 78 128 81 88 166 81 82 173 86 106 160 86 106 160 84 96 162 86 106 160 87 112 149
49843-91 118 149 77 105 114 52 67 79 32 40 45 50 50 50 86 86 86 2 2 6 14 14 14
49844-124 131 137 198 198 198 195 195 195 116 116 116 10 10 10 2 2 6 2 2 6 6 6 6
49845-101 98 89 187 187 187 210 210 210 218 218 218 214 214 214 124 131 137 14 14 14 6 6 6
49846-2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 50 50 50 18 18 18 6 6 6
49847-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49848-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49849-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49850-
49851-19 31 15 34 76 34 40 89 40 40 89 40 40 89 40 24 53 24 8 7 3 0 0 0
49852-6 8 12 28 32 52 51 61 92 54 54 122 74 77 160 68 78 128 26 35 39 6 8 8
49853-34 45 54 68 78 128 84 96 162 86 106 160 86 106 160 81 88 166 84 96 162 87 112 149
49854-73 97 106 36 50 56 33 49 54 18 18 18 46 46 46 86 86 86 2 2 6 54 54 54
49855-218 218 218 195 195 195 226 226 226 246 246 246 58 58 58 2 2 6 2 2 6 30 30 30
49856-210 210 210 253 253 253 170 170 170 124 127 131 221 221 221 234 234 234 74 74 74 2 2 6
49857-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 22 22 22 6 6 6
49858-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49859-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49860-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49861-
49862-4 5 3 24 53 24 40 89 40 40 89 40 34 76 34 12 22 15 4 5 3 4 5 3
49863-13 17 26 54 54 122 78 78 174 78 78 174 78 78 174 74 77 160 51 61 92 21 31 35
49864-26 35 39 53 75 83 84 101 153 81 82 173 81 88 166 84 101 153 60 80 103 60 80 103
49865-53 75 83 38 53 58 42 59 64 22 22 22 46 46 46 82 82 82 2 2 6 106 106 106
49866-170 170 170 26 26 26 86 86 86 226 226 226 124 127 131 10 10 10 14 14 14 46 46 46
49867-231 231 231 190 190 190 6 6 6 70 70 70 90 90 90 238 238 238 151 151 151 2 2 6
49868-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 22 22 22 6 6 6
49869-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49870-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49871-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49872-
49873-1 2 2 8 15 6 24 53 24 34 76 34 19 31 15 8 15 6 63 55 20 63 55 20
49874-18 18 18 40 48 73 74 77 160 78 78 174 78 78 174 81 82 173 74 77 160 52 67 79
49875-17 23 26 21 31 35 60 80 103 81 88 166 74 77 160 78 102 129 36 54 60 12 17 20
49876-42 59 64 48 63 69 21 31 35 18 18 18 42 42 42 86 86 86 6 6 6 116 116 116
49877-106 106 106 6 6 6 70 70 70 151 151 151 124 127 131 18 18 18 38 38 38 54 54 54
49878-221 221 221 106 106 106 2 2 6 14 14 14 46 46 46 190 190 190 198 198 198 2 2 6
49879-2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 6 6 6
49880-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49881-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49882-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49883-
49884-11 15 17 0 0 0 12 22 15 19 31 15 8 15 6 63 55 20 149 139 69 149 139 69
49885-63 55 20 10 10 22 54 54 122 78 78 174 78 78 174 78 78 174 81 82 173 68 78 128
49886-24 31 37 6 6 6 36 50 56 60 80 103 51 61 92 42 59 64 36 50 56 31 45 49
49887-29 43 47 27 40 45 6 8 8 14 14 14 42 42 42 94 94 94 14 14 14 101 101 101
49888-124 127 131 2 2 6 18 18 18 116 116 116 106 107 48 121 92 8 121 92 8 98 70 6
49889-170 170 170 106 106 106 2 2 6 2 2 6 2 2 6 195 195 195 195 195 195 6 6 6
49890-2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 6 6 6
49891-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49892-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49893-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49894-
49895-26 35 39 3 5 6 1 1 1 2 3 3 35 31 12 133 118 54 175 176 80 175 176 80
49896-133 118 54 35 31 12 23 29 47 54 54 122 78 78 174 78 78 174 74 77 160 68 78 128
49897-51 61 92 31 45 49 26 35 39 36 50 56 29 43 47 7 12 13 21 30 33 42 59 64
49898-18 25 28 7 12 13 1 1 1 10 10 10 38 38 38 90 90 90 14 14 14 58 58 58
49899-210 210 210 26 26 26 62 42 6 154 114 10 226 170 11 237 188 10 220 174 15 184 138 11
49900-220 174 15 174 140 55 35 31 12 2 2 6 70 70 70 246 246 246 124 131 137 2 2 6
49901-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 66 66 66 26 26 26 6 6 6
49902-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49903-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49904-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49905-
49906-27 40 45 17 23 26 2 3 3 1 1 1 56 77 35 165 152 80 175 176 80 175 176 80
49907-175 176 80 106 107 48 22 22 22 28 32 52 54 54 122 54 54 122 51 61 92 28 32 52
49908-20 27 34 31 45 49 11 15 17 7 12 13 36 50 56 31 45 49 29 43 47 36 50 56
49909-6 8 8 0 0 0 0 0 0 10 10 10 38 38 38 86 86 86 14 14 14 10 10 10
49910-195 195 195 198 179 130 192 133 9 220 174 15 239 182 13 237 188 10 232 195 16 239 207 25
49911-237 201 50 241 208 19 232 195 16 184 138 11 198 179 130 208 206 196 42 42 42 2 2 6
49912-2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 74 74 74 30 30 30 6 6 6
49913-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49914-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49915-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49916-
49917-15 22 25 26 35 39 15 22 25 0 0 0 35 31 12 133 118 54 175 176 80 175 176 80
49918-175 176 80 165 152 80 56 77 35 6 8 12 23 29 47 13 17 26 2 2 6 0 0 0
49919-1 2 2 26 35 39 26 35 39 26 35 39 42 59 64 42 59 64 20 29 31 6 8 8
49920-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 86 86 86 14 14 14 2 2 6
49921-121 92 8 192 133 9 219 162 10 239 182 13 237 188 10 232 195 16 241 208 19 237 201 50
49922-237 201 50 239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 121 92 8 2 2 6
49923-2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 82 82 82 34 34 34 10 10 10
49924-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49925-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49926-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49927-
49928-1 2 2 15 22 25 31 45 49 6 8 12 4 5 3 63 55 20 149 139 69 175 176 80
49929-175 176 80 175 176 80 106 107 48 20 16 6 1 1 1 0 0 0 2 3 3 11 15 17
49930-21 30 33 36 50 56 36 50 56 24 31 37 15 22 25 6 8 8 0 0 0 0 0 0
49931-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 82 82 82 30 30 30 62 42 6
49932-180 123 7 206 145 10 230 174 11 239 182 13 237 188 10 238 202 15 241 208 19 237 201 50
49933-239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 220 174 15 184 138 11 6 6 6
49934-2 2 6 2 2 6 2 2 6 2 2 6 26 26 26 94 94 94 42 42 42 14 14 14
49935-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49936-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49937-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49938-
49939-0 0 0 1 2 2 29 43 47 26 35 39 3 5 6 8 7 3 106 107 48 165 152 80
49940-175 176 80 149 139 69 63 55 20 4 5 3 2 3 3 12 17 20 26 35 39 26 35 39
49941-17 23 26 7 12 13 6 8 8 3 5 6 1 2 2 0 0 0 0 0 0 0 0 0
49942-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 78 78 78 50 50 50 104 69 6
49943-192 133 9 216 158 10 236 178 12 237 188 10 232 195 16 241 208 19 237 201 50 237 201 50
49944-241 208 19 241 208 19 241 208 19 204 160 10 200 144 11 216 158 10 156 118 10 2 2 6
49945-2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 90 90 90 54 54 54 18 18 18
49946-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49947-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49948-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49949-
49950-0 0 0 0 0 0 12 17 20 27 40 45 18 25 28 1 1 1 35 31 12 106 107 48
49951-149 139 69 56 77 35 8 7 3 1 2 2 12 17 20 26 35 39 21 31 35 11 15 17
49952-3 5 6 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49953-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 78 78 78 46 46 46 22 22 22
49954-137 92 6 204 160 10 239 182 13 237 188 10 238 202 15 241 208 19 241 208 19 241 208 19
49955-241 208 19 204 160 10 184 138 11 210 150 10 216 158 10 210 150 10 98 70 6 2 2 6
49956-6 6 6 54 54 54 14 14 14 2 2 6 2 2 6 62 62 62 74 74 74 30 30 30
49957-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49958-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49959-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49960-
49961-0 0 0 0 0 0 1 1 1 15 22 25 33 49 54 12 17 20 2 3 3 35 31 12
49962-56 77 35 20 16 6 1 1 1 18 25 28 21 31 35 11 15 17 1 1 1 0 0 0
49963-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49964-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 78 78 78 50 50 50 6 6 6
49965-88 55 22 139 102 15 190 146 13 230 187 11 239 207 25 232 195 16 220 174 15 190 146 13
49966-171 120 8 192 133 9 210 150 10 213 154 11 185 146 40 165 152 80 101 98 89 2 2 6
49967-2 2 6 78 78 78 116 116 116 58 58 58 2 2 6 22 22 22 90 90 90 46 46 46
49968-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49969-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49970-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49971-
49972-0 0 0 0 0 0 0 0 0 1 1 1 27 40 45 29 43 47 3 5 6 2 3 3
49973-8 7 3 1 1 1 17 23 26 31 45 49 15 22 25 0 0 0 0 0 0 0 0 0
49974-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49975-0 0 0 0 0 0 0 0 0 10 10 10 38 38 38 86 86 86 50 50 50 6 6 6
49976-124 127 131 168 158 138 156 107 11 171 120 8 204 160 10 184 138 11 197 138 11 200 144 11
49977-206 145 10 206 145 10 197 138 11 198 179 130 195 195 195 198 198 198 170 170 170 14 14 14
49978-2 2 6 22 22 22 116 116 116 116 116 116 22 22 22 2 2 6 74 74 74 70 70 70
49979-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49980-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49981-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49982-
49983-0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 31 45 49 26 35 39 3 5 6
49984-0 0 0 7 12 13 27 40 45 18 25 28 0 0 0 0 0 0 0 0 0 0 0 0
49985-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49986-0 0 0 0 0 0 6 6 6 18 18 18 50 50 50 101 101 101 26 26 26 10 10 10
49987-124 131 137 190 190 190 168 158 138 156 107 11 197 138 11 200 144 11 197 138 11 192 133 9
49988-180 123 7 185 146 40 198 179 130 187 187 187 202 202 202 221 221 221 214 214 214 66 66 66
49989-2 2 6 2 2 6 50 50 50 62 62 62 6 6 6 2 2 6 10 10 10 90 90 90
49990-50 50 50 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49991-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49992-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49993-
49994-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 15 22 25 36 54 60 18 25 28
49995-0 0 0 21 30 33 27 40 45 2 3 3 0 0 0 0 0 0 0 0 0 0 0 0
49996-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49997-0 0 0 0 0 0 10 10 10 34 34 34 74 74 74 74 74 74 2 2 6 6 6 6
49998-151 151 151 198 198 198 190 190 190 168 158 138 148 132 55 156 107 11 156 107 11 169 125 40
49999-168 158 138 187 187 187 190 190 190 210 210 210 246 246 246 253 253 253 253 253 253 180 180 180
50000-6 6 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62
50001-74 74 74 34 34 34 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50002-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50003-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50004-
50005-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 27 40 45 35 52 58
50006-18 25 28 35 52 58 17 23 26 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50007-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50008-0 0 0 10 10 10 22 22 22 54 54 54 94 94 94 18 18 18 2 2 6 46 46 46
50009-234 234 234 221 221 221 190 190 190 190 190 190 190 190 190 187 187 187 187 187 187 190 190 190
50010-190 190 190 195 195 195 214 214 214 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50011-82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 14 14 14
50012-86 86 86 54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50013-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50014-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50015-
50016-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 12 13 33 49 54
50017-52 72 81 36 54 60 6 8 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50018-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50019-6 6 6 18 18 18 46 46 46 90 90 90 46 46 46 18 18 18 6 6 6 180 180 180
50020-253 253 253 246 246 246 202 202 202 190 190 190 190 190 190 190 190 190 190 190 190 190 190 190
50021-202 202 202 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50022-202 202 202 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50023-42 42 42 86 86 86 42 42 42 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50024-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50025-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50026-
50027-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 17 20
50028-36 54 60 29 43 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50029-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50030-14 14 14 38 38 38 74 74 74 66 66 66 2 2 6 6 6 6 90 90 90 250 250 250
50031-253 253 253 253 253 253 238 238 238 198 198 198 190 190 190 190 190 190 195 195 195 221 221 221
50032-246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50033-253 253 253 82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50034-2 2 6 78 78 78 70 70 70 34 34 34 14 14 14 6 6 6 0 0 0 0 0 0
50035-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50036-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50037-
50038-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50039-21 30 33 35 52 58 6 8 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50040-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50041-34 34 34 66 66 66 78 78 78 6 6 6 2 2 6 18 18 18 218 218 218 253 253 253
50042-253 253 253 253 253 253 253 253 253 246 246 246 226 226 226 231 231 231 246 246 246 253 253 253
50043-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50044-253 253 253 180 180 180 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50045-2 2 6 18 18 18 90 90 90 62 62 62 30 30 30 10 10 10 0 0 0 0 0 0
50046-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50047-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50048-
50049-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50050-12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50051-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
50052-58 58 58 90 90 90 18 18 18 2 2 6 2 2 6 106 106 106 253 253 253 253 253 253
50053-253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 253 253 253 253 253 253 253 253 253
50054-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50055-253 253 253 231 231 231 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50056-2 2 6 2 2 6 18 18 18 94 94 94 54 54 54 26 26 26 10 10 10 0 0 0
50057-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50058-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50059-
50060-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50061-0 0 0 21 30 33 35 52 58 6 8 12 0 0 0 0 0 0 0 0 0 0 0 0
50062-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 50 50 50
50063-90 90 90 26 26 26 2 2 6 2 2 6 14 14 14 195 195 195 250 250 250 253 253 253
50064-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50065-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50066-250 250 250 242 242 242 54 54 54 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50067-2 2 6 2 2 6 2 2 6 38 38 38 86 86 86 50 50 50 22 22 22 6 6 6
50068-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50069-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50070-
50071-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50072-0 0 0 0 0 0 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0
50073-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 38 38 38 82 82 82
50074-34 34 34 2 2 6 2 2 6 2 2 6 42 42 42 195 195 195 246 246 246 253 253 253
50075-253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 242 242 242 250 250 250 253 253 253
50076-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 246 246 246 238 238 238
50077-226 226 226 231 231 231 101 101 101 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
50078-2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 82 82 82 42 42 42 14 14 14
50079-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50080-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50081-
50082-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50083-0 0 0 0 0 0 0 0 0 21 30 33 35 52 58 6 8 12 0 0 0 0 0 0
50084-0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26 62 62 62 66 66 66
50085-2 2 6 2 2 6 2 2 6 6 6 6 70 70 70 170 170 170 202 202 202 234 234 234
50086-246 246 246 250 250 250 250 250 250 238 238 238 226 226 226 231 231 231 238 238 238 250 250 250
50087-250 250 250 250 250 250 246 246 246 231 231 231 214 214 214 202 202 202 202 202 202 202 202 202
50088-198 198 198 202 202 202 180 180 180 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6
50089-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66 30 30 30
50090-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50091-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50092-
50093-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50094-0 0 0 0 0 0 0 0 0 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0
50095-0 0 0 0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 82 82 82 18 18 18
50096-2 2 6 2 2 6 2 2 6 10 10 10 94 94 94 180 180 180 218 218 218 242 242 242
50097-250 250 250 253 253 253 253 253 253 250 250 250 234 234 234 253 253 253 253 253 253 253 253 253
50098-253 253 253 253 253 253 253 253 253 246 246 246 238 238 238 226 226 226 210 210 210 202 202 202
50099-195 195 195 195 195 195 210 210 210 151 151 151 6 6 6 14 14 14 50 50 50 14 14 14
50100-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 86 86 86 46 46 46
50101-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50102-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50103-
50104-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50105-0 0 0 0 0 0 0 0 0 0 0 0 21 30 33 35 52 58 6 8 12 0 0 0
50106-0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 54 54 54 70 70 70 2 2 6
50107-2 2 6 10 10 10 2 2 6 22 22 22 170 170 170 231 231 231 250 250 250 253 253 253
50108-253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 253 253 253 253 253 253 253 253 253
50109-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 246 246 246
50110-231 231 231 202 202 202 198 198 198 226 226 226 94 94 94 2 2 6 6 6 6 38 38 38
50111-30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66
50112-26 26 26 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50113-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50114-
50115-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50116-0 0 0 0 0 0 0 0 0 0 0 0 6 8 8 33 49 54 29 43 47 6 8 12
50117-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 74 74 74 50 50 50 2 2 6
50118-26 26 26 26 26 26 2 2 6 106 106 106 238 238 238 253 253 253 253 253 253 253 253 253
50119-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50120-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50121-253 253 253 246 246 246 218 218 218 202 202 202 210 210 210 14 14 14 2 2 6 2 2 6
50122-30 30 30 22 22 22 2 2 6 2 2 6 2 2 6 2 2 6 18 18 18 86 86 86
50123-42 42 42 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50124-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50125-
50126-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50127-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 17 20 33 49 54 17 23 26
50128-0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 90 90 90 22 22 22 2 2 6
50129-42 42 42 2 2 6 18 18 18 218 218 218 253 253 253 253 253 253 253 253 253 253 253 253
50130-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50131-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50132-253 253 253 253 253 253 250 250 250 221 221 221 218 218 218 101 101 101 2 2 6 14 14 14
50133-18 18 18 38 38 38 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 78 78 78
50134-58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50135-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50136-
50137-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50138-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 22 25 36 54 60
50139-0 0 0 0 0 0 0 0 0 18 18 18 54 54 54 82 82 82 2 2 6 26 26 26
50140-22 22 22 2 2 6 124 127 131 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50141-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50142-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50143-253 253 253 253 253 253 253 253 253 250 250 250 238 238 238 198 198 198 6 6 6 38 38 38
50144-58 58 58 26 26 26 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6 46 46 46
50145-78 78 78 30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50146-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50147-
50148-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50149-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 21 30 33
50150-36 54 60 0 0 0 0 0 0 30 30 30 74 74 74 58 58 58 2 2 6 42 42 42
50151-2 2 6 22 22 22 231 231 231 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50152-253 253 253 253 253 253 253 253 253 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
50153-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50154-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 246 246 246 46 46 46 38 38 38
50155-42 42 42 14 14 14 38 38 38 14 14 14 2 2 6 2 2 6 2 2 6 6 6 6
50156-86 86 86 46 46 46 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50157-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50158-
50159-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50160-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50161-36 54 60 0 0 0 0 0 0 42 42 42 90 90 90 18 18 18 18 18 18 26 26 26
50162-2 2 6 116 116 116 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50163-253 253 253 253 253 253 250 250 250 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253
50164-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50165-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 94 94 94 6 6 6
50166-2 2 6 2 2 6 10 10 10 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6
50167-74 74 74 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50168-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50169-
50170-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50171-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50172-0 0 0 36 54 60 26 26 26 66 66 66 82 82 82 2 2 6 38 38 38 6 6 6
50173-14 14 14 210 210 210 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50174-253 253 253 253 253 253 246 246 246 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50175-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50176-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 151 151 151 2 2 6
50177-2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
50178-42 42 42 74 74 74 30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0
50179-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50180-
50181-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50182-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50183-6 6 6 36 54 60 21 30 33 90 90 90 26 26 26 6 6 6 42 42 42 2 2 6
50184-74 74 74 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50185-253 253 253 253 253 253 242 242 242 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50186-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50187-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 180 180 180 2 2 6
50188-2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
50189-10 10 10 86 86 86 38 38 38 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0
50190-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50191-
50192-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50193-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50194-10 10 10 26 26 26 36 54 60 82 82 82 2 2 6 22 22 22 18 18 18 2 2 6
50195-151 151 151 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50196-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50197-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50198-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 202 202 202 2 2 6
50199-2 2 6 2 2 6 2 2 6 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6
50200-6 6 6 86 86 86 46 46 46 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0
50201-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50202-
50203-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50204-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50205-18 18 18 46 46 46 86 86 86 36 54 60 2 2 6 34 34 34 10 10 10 6 6 6
50206-210 210 210 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50207-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50208-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50209-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 221 221 221 6 6 6
50210-2 2 6 2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
50211-2 2 6 82 82 82 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50212-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50213-
50214-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50215-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50216-26 26 26 66 66 66 62 62 62 2 2 6 2 2 6 38 38 38 10 10 10 26 26 26
50217-238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50218-253 253 253 253 253 253 231 231 231 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253
50219-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50220-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 231 231 231 6 6 6
50221-2 2 6 2 2 6 10 10 10 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
50222-2 2 6 66 66 66 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50223-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50224-
50225-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50226-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50227-38 38 38 78 78 78 6 6 6 2 2 6 2 2 6 46 46 46 14 14 14 42 42 42
50228-246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50229-253 253 253 253 253 253 231 231 231 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50230-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50231-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 234 234 234 10 10 10
50232-2 2 6 2 2 6 22 22 22 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6
50233-2 2 6 66 66 66 62 62 62 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50234-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50235-
50236-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50237-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50238-50 50 50 74 74 74 2 2 6 2 2 6 14 14 14 70 70 70 34 34 34 62 62 62
50239-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50240-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50241-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50242-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 234 234 234 14 14 14
50243-2 2 6 2 2 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50244-2 2 6 66 66 66 62 62 62 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50245-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50246-
50247-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50248-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50249-54 54 54 62 62 62 2 2 6 2 2 6 2 2 6 30 30 30 46 46 46 70 70 70
50250-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50251-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50252-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50253-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 226 226 226 10 10 10
50254-2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50255-2 2 6 66 66 66 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50256-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50257-
50258-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50259-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50260-58 58 58 62 62 62 2 2 6 2 2 6 2 2 6 2 2 6 30 30 30 78 78 78
50261-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50262-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50263-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50264-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 202 202 202 2 2 6
50265-22 22 22 34 34 34 20 16 6 22 22 22 26 26 26 18 18 18 6 6 6 2 2 6
50266-2 2 6 82 82 82 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50267-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50268-
50269-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50270-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 26 26 26
50271-62 62 62 106 106 106 63 55 20 184 138 11 204 160 10 121 92 8 6 6 6 62 62 62
50272-238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50273-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50274-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50275-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 151 151 151 18 18 18
50276-14 14 14 2 2 6 2 2 6 2 2 6 6 6 6 18 18 18 66 66 66 38 38 38
50277-6 6 6 94 94 94 50 50 50 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50278-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50279-
50280-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50281-0 0 0 0 0 0 0 0 0 6 6 6 10 10 10 10 10 10 18 18 18 38 38 38
50282-78 78 78 138 132 106 216 158 10 242 186 14 246 190 14 246 190 14 156 118 10 10 10 10
50283-90 90 90 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50284-253 253 253 253 253 253 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
50285-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50286-253 253 253 253 253 253 253 253 253 246 230 190 214 187 87 214 187 87 185 146 40 35 31 12
50287-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 46 46 46
50288-26 26 26 106 106 106 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50289-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50290-
50291-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50292-0 0 0 6 6 6 14 14 14 22 22 22 30 30 30 38 38 38 50 50 50 70 70 70
50293-106 106 106 185 146 40 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 154 114 10
50294-6 6 6 74 74 74 226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50295-253 253 253 253 253 253 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
50296-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50297-253 253 253 253 253 253 253 253 253 237 201 50 241 196 14 241 208 19 232 195 16 35 31 12
50298-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 30 30 30 26 26 26
50299-204 160 10 165 152 80 66 66 66 26 26 26 6 6 6 0 0 0 0 0 0 0 0 0
50300-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50301-
50302-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50303-6 6 6 18 18 18 38 38 38 58 58 58 78 78 78 86 86 86 101 101 101 124 127 131
50304-174 140 55 210 150 10 234 174 13 246 186 14 246 190 14 246 190 14 246 190 14 237 188 10
50305-98 70 6 2 2 6 46 46 46 198 198 198 253 253 253 253 253 253 253 253 253 253 253 253
50306-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50307-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50308-253 253 253 253 253 253 253 253 253 214 187 87 242 186 14 241 196 14 204 160 10 20 16 6
50309-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 121 92 8
50310-238 202 15 232 195 16 82 82 82 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
50311-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50312-
50313-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50314-14 14 14 38 38 38 70 70 70 148 132 55 185 146 40 200 144 11 197 138 11 197 138 11
50315-213 154 11 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50316-220 174 15 35 31 12 2 2 6 22 22 22 151 151 151 250 250 250 253 253 253 253 253 253
50317-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50318-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50319-253 253 253 250 250 250 242 242 242 214 187 87 239 182 13 237 188 10 213 154 11 35 31 12
50320-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 42 6 220 174 15
50321-237 188 10 237 188 10 113 101 86 42 42 42 14 14 14 0 0 0 0 0 0 0 0 0
50322-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50323-
50324-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50325-22 22 22 54 54 54 148 132 55 213 154 11 226 170 11 230 174 11 226 170 11 226 170 11
50326-236 178 12 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50327-241 196 14 184 138 11 10 10 10 2 2 6 6 6 6 116 116 116 242 242 242 253 253 253
50328-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50329-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50330-253 253 253 231 231 231 198 198 198 213 164 39 236 178 12 236 178 12 210 150 10 137 92 6
50331-20 16 6 2 2 6 2 2 6 2 2 6 6 6 6 62 42 6 200 144 11 236 178 12
50332-239 182 13 239 182 13 124 112 88 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0
50333-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50334-
50335-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50336-30 30 30 70 70 70 169 125 40 226 170 11 239 182 13 242 186 14 242 186 14 246 186 14
50337-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50338-246 190 14 232 195 16 98 70 6 2 2 6 2 2 6 2 2 6 66 66 66 221 221 221
50339-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50340-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50341-253 253 253 202 202 202 198 198 198 213 164 39 230 174 11 230 174 11 216 158 10 192 133 9
50342-163 110 8 120 80 7 98 70 6 120 80 7 167 114 7 197 138 11 226 170 11 239 182 13
50343-242 186 14 242 186 14 165 152 80 78 78 78 34 34 34 14 14 14 6 6 6 0 0 0
50344-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50345-
50346-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50347-30 30 30 78 78 78 185 146 40 226 170 11 239 182 13 246 190 14 246 190 14 246 190 14
50348-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50349-246 190 14 241 196 14 204 160 10 20 16 6 2 2 6 2 2 6 2 2 6 38 38 38
50350-218 218 218 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50351-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50352-250 250 250 202 202 202 198 198 198 213 164 39 226 170 11 236 178 12 224 166 10 210 150 10
50353-200 144 11 197 138 11 192 133 9 197 138 11 210 150 10 226 170 11 242 186 14 246 190 14
50354-246 190 14 246 186 14 220 174 15 124 112 88 62 62 62 30 30 30 14 14 14 6 6 6
50355-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50356-
50357-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50358-30 30 30 78 78 78 174 140 55 224 166 10 239 182 13 246 190 14 246 190 14 246 190 14
50359-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50360-246 190 14 246 190 14 241 196 14 139 102 15 2 2 6 2 2 6 2 2 6 2 2 6
50361-78 78 78 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50362-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50363-250 250 250 214 214 214 198 198 198 185 146 40 219 162 10 236 178 12 234 174 13 224 166 10
50364-216 158 10 213 154 11 213 154 11 216 158 10 226 170 11 239 182 13 246 190 14 246 190 14
50365-246 190 14 246 190 14 242 186 14 213 164 39 101 101 101 58 58 58 30 30 30 14 14 14
50366-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50367-
50368-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50369-30 30 30 74 74 74 174 140 55 216 158 10 236 178 12 246 190 14 246 190 14 246 190 14
50370-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50371-246 190 14 246 190 14 241 196 14 230 187 11 62 42 6 2 2 6 2 2 6 2 2 6
50372-22 22 22 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50373-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50374-253 253 253 226 226 226 187 187 187 169 125 40 216 158 10 236 178 12 239 182 13 236 178 12
50375-230 174 11 226 170 11 226 170 11 230 174 11 236 178 12 242 186 14 246 190 14 246 190 14
50376-246 190 14 246 190 14 246 186 14 239 182 13 213 164 39 106 106 106 66 66 66 34 34 34
50377-14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50378-
50379-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50380-26 26 26 70 70 70 149 139 69 213 154 11 236 178 12 246 190 14 246 190 14 246 190 14
50381-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50382-246 190 14 246 190 14 246 190 14 241 196 14 190 146 13 20 16 6 2 2 6 2 2 6
50383-46 46 46 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50384-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50385-253 253 253 221 221 221 86 86 86 156 107 11 216 158 10 236 178 12 242 186 14 246 186 14
50386-242 186 14 239 182 13 239 182 13 242 186 14 242 186 14 246 186 14 246 190 14 246 190 14
50387-246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 220 174 15 149 139 69 66 66 66
50388-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50389-
50390-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50391-26 26 26 70 70 70 149 139 69 210 150 10 236 178 12 246 190 14 246 190 14 246 190 14
50392-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50393-246 190 14 246 190 14 246 190 14 246 190 14 232 195 16 121 92 8 34 34 34 106 106 106
50394-221 221 221 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50395-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50396-242 242 242 82 82 82 20 16 6 163 110 8 216 158 10 236 178 12 242 186 14 246 190 14
50397-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50398-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 149 139 69
50399-46 46 46 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50400-
50401-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50402-30 30 30 78 78 78 149 139 69 210 150 10 236 178 12 246 186 14 246 190 14 246 190 14
50403-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50404-246 190 14 246 190 14 246 190 14 246 190 14 241 196 14 220 174 15 198 179 130 253 253 253
50405-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50406-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 218 218 218
50407-58 58 58 2 2 6 20 16 6 167 114 7 216 158 10 236 178 12 246 186 14 246 190 14
50408-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50409-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 242 186 14 185 146 40
50410-54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50411-
50412-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50413-38 38 38 86 86 86 169 125 40 213 154 11 236 178 12 246 186 14 246 190 14 246 190 14
50414-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50415-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 232 195 16 190 146 13 214 214 214
50416-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50417-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 170 170 170 26 26 26
50418-2 2 6 2 2 6 35 31 12 163 110 8 219 162 10 239 182 13 246 186 14 246 190 14
50419-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50420-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 224 166 10 149 139 69
50421-46 46 46 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50422-
50423-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50424-50 50 50 113 101 86 192 133 9 224 166 10 242 186 14 246 190 14 246 190 14 246 190 14
50425-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50426-246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 230 187 11 204 160 10 133 118 54
50427-226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50428-253 253 253 253 253 253 253 253 253 253 253 253 198 198 198 66 66 66 2 2 6 2 2 6
50429-2 2 6 2 2 6 62 42 6 156 107 11 219 162 10 239 182 13 246 186 14 246 190 14
50430-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50431-246 190 14 246 190 14 246 190 14 242 186 14 234 174 13 213 154 11 148 132 55 66 66 66
50432-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50433-
50434-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50435-58 58 58 148 132 55 206 145 10 234 174 13 242 186 14 246 186 14 246 190 14 246 190 14
50436-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50437-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 204 160 10 163 110 8
50438-62 42 6 124 131 137 218 218 218 250 250 250 253 253 253 253 253 253 253 253 253 250 250 250
50439-242 242 242 210 210 210 151 151 151 66 66 66 6 6 6 2 2 6 2 2 6 2 2 6
50440-2 2 6 2 2 6 62 42 6 163 110 8 216 158 10 236 178 12 246 190 14 246 190 14
50441-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50442-246 190 14 239 182 13 230 174 11 216 158 10 185 146 40 124 112 88 70 70 70 38 38 38
50443-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50444-
50445-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50446-62 62 62 169 125 40 206 145 10 224 166 10 236 178 12 239 182 13 242 186 14 242 186 14
50447-246 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50448-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 236 178 12 216 158 10 171 120 8
50449-85 57 6 2 2 6 6 6 6 30 30 30 54 54 54 62 62 62 50 50 50 38 38 38
50450-14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50451-2 2 6 6 6 6 85 57 6 167 114 7 213 154 11 236 178 12 246 190 14 246 190 14
50452-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 239 182 13 239 182 13
50453-230 174 11 210 150 10 174 140 55 124 112 88 82 82 82 54 54 54 34 34 34 18 18 18
50454-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50455-
50456-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50457-50 50 50 169 125 40 192 133 9 200 144 11 216 158 10 219 162 10 224 166 10 226 170 11
50458-230 174 11 236 178 12 239 182 13 239 182 13 242 186 14 246 186 14 246 190 14 246 190 14
50459-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 230 174 11 210 150 10 163 110 8
50460-104 69 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50461-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50462-2 2 6 6 6 6 85 57 6 167 114 7 206 145 10 230 174 11 242 186 14 246 190 14
50463-246 190 14 246 190 14 246 186 14 242 186 14 239 182 13 230 174 11 224 166 10 213 154 11
50464-169 125 40 124 112 88 86 86 86 58 58 58 38 38 38 22 22 22 10 10 10 6 6 6
50465-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50466-
50467-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50468-34 34 34 70 70 70 133 118 54 169 125 40 167 114 7 180 123 7 192 133 9 197 138 11
50469-200 144 11 206 145 10 213 154 11 219 162 10 224 166 10 230 174 11 239 182 13 242 186 14
50470-246 186 14 246 186 14 246 186 14 246 186 14 239 182 13 216 158 10 184 138 11 152 99 6
50471-104 69 6 20 16 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50472-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50473-2 2 6 6 6 6 85 57 6 152 99 6 192 133 9 219 162 10 236 178 12 239 182 13
50474-246 186 14 242 186 14 239 182 13 236 178 12 224 166 10 206 145 10 192 133 9 148 132 55
50475-94 94 94 62 62 62 42 42 42 22 22 22 14 14 14 6 6 6 0 0 0 0 0 0
50476-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50477-
50478-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50479-18 18 18 34 34 34 58 58 58 78 78 78 101 98 89 124 112 88 133 118 54 156 107 11
50480-163 110 8 167 114 7 171 120 8 180 123 7 184 138 11 197 138 11 210 150 10 219 162 10
50481-226 170 11 236 178 12 236 178 12 234 174 13 219 162 10 197 138 11 163 110 8 134 84 6
50482-85 57 6 10 10 10 2 2 6 2 2 6 18 18 18 38 38 38 38 38 38 38 38 38
50483-38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 26 26 26 2 2 6
50484-2 2 6 6 6 6 62 42 6 137 92 6 171 120 8 200 144 11 219 162 10 230 174 11
50485-234 174 13 230 174 11 219 162 10 210 150 10 192 133 9 163 110 8 124 112 88 82 82 82
50486-50 50 50 30 30 30 14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50487-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50488-
50489-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50490-6 6 6 14 14 14 22 22 22 34 34 34 42 42 42 58 58 58 74 74 74 86 86 86
50491-101 98 89 113 101 86 133 118 54 121 92 8 137 92 6 152 99 6 163 110 8 180 123 7
50492-184 138 11 197 138 11 206 145 10 200 144 11 180 123 7 156 107 11 134 84 6 104 69 6
50493-62 42 6 54 54 54 106 106 106 101 98 89 86 86 86 82 82 82 78 78 78 78 78 78
50494-78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 82 82 82 86 86 86 94 94 94
50495-106 106 106 101 101 101 90 61 47 120 80 7 156 107 11 180 123 7 192 133 9 200 144 11
50496-206 145 10 200 144 11 192 133 9 171 120 8 139 102 15 113 101 86 70 70 70 42 42 42
50497-22 22 22 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50498-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50499-
50500-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50501-0 0 0 0 0 0 6 6 6 10 10 10 14 14 14 22 22 22 30 30 30 38 38 38
50502-50 50 50 62 62 62 74 74 74 90 90 90 101 98 89 113 101 86 121 92 8 120 80 7
50503-137 92 6 152 99 6 152 99 6 152 99 6 134 84 6 120 80 7 98 70 6 88 55 22
50504-101 98 89 82 82 82 58 58 58 46 46 46 38 38 38 34 34 34 34 34 34 34 34 34
50505-34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 38 38 38 42 42 42
50506-54 54 54 82 82 82 94 86 71 85 57 6 134 84 6 156 107 11 167 114 7 171 120 8
50507-171 120 8 167 114 7 152 99 6 121 92 8 101 98 89 62 62 62 34 34 34 18 18 18
50508-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50509-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50510-
50511-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50512-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 10 10 10
50513-18 18 18 22 22 22 30 30 30 42 42 42 50 50 50 66 66 66 86 86 86 101 98 89
50514-94 86 71 98 70 6 104 69 6 104 69 6 104 69 6 85 57 6 88 55 22 90 90 90
50515-62 62 62 38 38 38 22 22 22 14 14 14 10 10 10 10 10 10 10 10 10 10 10 10
50516-10 10 10 10 10 10 6 6 6 10 10 10 10 10 10 10 10 10 10 10 10 14 14 14
50517-22 22 22 42 42 42 70 70 70 94 86 71 85 57 6 104 69 6 120 80 7 137 92 6
50518-134 84 6 120 80 7 94 86 71 86 86 86 58 58 58 30 30 30 14 14 14 6 6 6
50519-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50520-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50521-
50522-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50523-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50524-0 0 0 6 6 6 10 10 10 14 14 14 18 18 18 26 26 26 38 38 38 54 54 54
50525-70 70 70 86 86 86 94 86 71 94 86 71 94 86 71 86 86 86 74 74 74 50 50 50
50526-30 30 30 14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50527-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50528-6 6 6 18 18 18 34 34 34 58 58 58 82 82 82 94 86 71 94 86 71 94 86 71
50529-94 86 71 94 86 71 74 74 74 50 50 50 26 26 26 14 14 14 6 6 6 0 0 0
50530-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50531-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50532-
50533-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50534-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50535-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 14 14 14 18 18 18
50536-30 30 30 38 38 38 46 46 46 54 54 54 50 50 50 42 42 42 30 30 30 18 18 18
50537-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50538-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50539-0 0 0 6 6 6 14 14 14 26 26 26 38 38 38 50 50 50 58 58 58 58 58 58
50540-54 54 54 42 42 42 30 30 30 18 18 18 10 10 10 0 0 0 0 0 0 0 0 0
50541-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50542-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50543-
50544-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50545-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50546-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50547-6 6 6 10 10 10 14 14 14 18 18 18 18 18 18 14 14 14 10 10 10 6 6 6
50548-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50549-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50550-0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 18 18 18 22 22 22 22 22 22
50551-18 18 18 14 14 14 10 10 10 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50552-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50553-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50554-
50555+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50557+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50558+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50559+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50560+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50561+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50562+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50564+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50565+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50566+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50567+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50568+4 4 4 4 4 4
50569+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50571+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50572+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50573+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50574+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50575+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50576+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50578+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50579+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50580+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50581+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50582+4 4 4 4 4 4
50583+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50585+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50586+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50587+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50588+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50589+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50590+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50592+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50593+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50594+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50596+4 4 4 4 4 4
50597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50599+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50600+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50601+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50607+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50610+4 4 4 4 4 4
50611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50615+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50624+4 4 4 4 4 4
50625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50629+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50638+4 4 4 4 4 4
50639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50643+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
50644+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
50645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50648+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
50649+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50650+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
50651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50652+4 4 4 4 4 4
50653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50657+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
50658+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
50659+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50662+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
50663+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
50664+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
50665+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50666+4 4 4 4 4 4
50667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50671+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
50672+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
50673+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50676+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
50677+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
50678+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
50679+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
50680+4 4 4 4 4 4
50681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50684+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
50685+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
50686+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
50687+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
50688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50689+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
50690+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
50691+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
50692+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
50693+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
50694+4 4 4 4 4 4
50695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50698+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
50699+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
50700+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
50701+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
50702+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
50703+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
50704+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
50705+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
50706+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
50707+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
50708+4 4 4 4 4 4
50709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
50712+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
50713+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
50714+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
50715+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
50716+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
50717+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
50718+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
50719+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
50720+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
50721+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
50722+4 4 4 4 4 4
50723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50725+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
50726+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
50727+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
50728+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
50729+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
50730+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
50731+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
50732+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
50733+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
50734+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
50735+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
50736+4 4 4 4 4 4
50737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50739+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
50740+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
50741+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
50742+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
50743+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
50744+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
50745+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
50746+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
50747+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
50748+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
50749+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
50750+4 4 4 4 4 4
50751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50753+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
50754+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
50755+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
50756+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
50757+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
50758+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
50759+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
50760+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
50761+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
50762+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
50763+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50764+4 4 4 4 4 4
50765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50767+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
50768+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
50769+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
50770+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
50771+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
50772+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
50773+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
50774+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
50775+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
50776+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
50777+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
50778+4 4 4 4 4 4
50779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50780+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
50781+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
50782+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
50783+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
50784+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
50785+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
50786+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
50787+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
50788+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
50789+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
50790+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
50791+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
50792+4 4 4 4 4 4
50793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50794+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
50795+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
50796+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
50797+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
50798+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
50799+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
50800+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
50801+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
50802+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
50803+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
50804+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
50805+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
50806+0 0 0 4 4 4
50807+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
50808+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
50809+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
50810+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
50811+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
50812+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
50813+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
50814+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
50815+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
50816+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
50817+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
50818+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
50819+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
50820+2 0 0 0 0 0
50821+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
50822+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
50823+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
50824+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
50825+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
50826+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
50827+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
50828+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
50829+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
50830+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
50831+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
50832+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
50833+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
50834+37 38 37 0 0 0
50835+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
50836+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
50837+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
50838+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
50839+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
50840+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
50841+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
50842+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
50843+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
50844+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
50845+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
50846+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
50847+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
50848+85 115 134 4 0 0
50849+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
50850+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
50851+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
50852+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
50853+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
50854+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
50855+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
50856+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
50857+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
50858+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
50859+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
50860+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
50861+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
50862+60 73 81 4 0 0
50863+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
50864+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
50865+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
50866+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
50867+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
50868+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
50869+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
50870+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
50871+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
50872+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
50873+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
50874+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
50875+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
50876+16 19 21 4 0 0
50877+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
50878+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
50879+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
50880+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
50881+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
50882+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
50883+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
50884+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
50885+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
50886+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
50887+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
50888+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
50889+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
50890+4 0 0 4 3 3
50891+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
50892+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
50893+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
50894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
50895+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
50896+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
50897+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
50898+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
50899+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
50900+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
50901+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
50902+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
50903+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
50904+3 2 2 4 4 4
50905+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
50906+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
50907+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
50908+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
50909+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
50910+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
50911+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50912+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
50913+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
50914+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
50915+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
50916+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
50917+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
50918+4 4 4 4 4 4
50919+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
50920+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
50921+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
50922+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
50923+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
50924+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
50925+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
50926+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
50927+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
50928+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
50929+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
50930+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
50931+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
50932+4 4 4 4 4 4
50933+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
50934+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
50935+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
50936+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
50937+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
50938+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
50939+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
50940+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
50941+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
50942+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
50943+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
50944+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
50945+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
50946+5 5 5 5 5 5
50947+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
50948+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
50949+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
50950+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
50951+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
50952+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50953+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
50954+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
50955+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
50956+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
50957+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
50958+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
50959+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
50960+5 5 5 4 4 4
50961+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
50962+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
50963+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
50964+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
50965+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50966+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
50967+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
50968+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
50969+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
50970+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
50971+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
50972+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
50973+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50974+4 4 4 4 4 4
50975+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
50976+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
50977+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
50978+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
50979+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
50980+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50981+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50982+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
50983+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
50984+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
50985+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
50986+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
50987+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50988+4 4 4 4 4 4
50989+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
50990+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
50991+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
50992+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
50993+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50994+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
50995+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
50996+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
50997+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
50998+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
50999+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
51000+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51002+4 4 4 4 4 4
51003+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
51004+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
51005+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
51006+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
51007+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51008+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51009+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51010+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
51011+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
51012+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
51013+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
51014+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51016+4 4 4 4 4 4
51017+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
51018+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
51019+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
51020+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
51021+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51022+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
51023+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
51024+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
51025+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
51026+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
51027+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51028+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51030+4 4 4 4 4 4
51031+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
51032+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
51033+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
51034+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
51035+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51036+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
51037+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
51038+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
51039+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
51040+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
51041+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
51042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51044+4 4 4 4 4 4
51045+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
51046+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
51047+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
51048+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
51049+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
51050+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
51051+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
51052+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
51053+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
51054+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
51055+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
51056+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51058+4 4 4 4 4 4
51059+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
51060+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
51061+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
51062+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
51063+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
51064+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
51065+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
51066+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
51067+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
51068+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
51069+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51072+4 4 4 4 4 4
51073+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
51074+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
51075+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
51076+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
51077+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51078+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
51079+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
51080+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
51081+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
51082+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
51083+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51084+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51085+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51086+4 4 4 4 4 4
51087+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
51088+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
51089+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
51090+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
51091+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51092+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
51093+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
51094+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
51095+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
51096+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
51097+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51098+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51099+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51100+4 4 4 4 4 4
51101+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
51102+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
51103+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
51104+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
51105+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51106+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
51107+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
51108+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
51109+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
51110+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51111+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51112+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51113+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51114+4 4 4 4 4 4
51115+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
51116+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
51117+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
51118+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
51119+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
51120+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
51121+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
51122+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
51123+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51124+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51125+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51126+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51127+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51128+4 4 4 4 4 4
51129+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
51130+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
51131+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
51132+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
51133+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51134+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
51135+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
51136+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
51137+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51138+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51139+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51140+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51141+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51142+4 4 4 4 4 4
51143+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
51144+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
51145+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
51146+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
51147+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
51148+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
51149+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
51150+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
51151+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51152+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51153+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51154+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51155+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51156+4 4 4 4 4 4
51157+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
51158+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
51159+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51160+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
51161+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
51162+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
51163+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
51164+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
51165+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
51166+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51167+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51168+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51170+4 4 4 4 4 4
51171+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
51172+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
51173+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
51174+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
51175+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
51176+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
51177+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
51178+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
51179+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51180+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51181+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51182+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51183+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51184+4 4 4 4 4 4
51185+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
51186+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
51187+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51188+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
51189+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
51190+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
51191+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
51192+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
51193+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
51194+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51195+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51196+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51197+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51198+4 4 4 4 4 4
51199+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
51200+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
51201+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
51202+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
51203+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
51204+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
51205+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
51206+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
51207+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51208+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51209+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51210+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51211+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51212+4 4 4 4 4 4
51213+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51214+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
51215+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51216+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
51217+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
51218+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
51219+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
51220+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
51221+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51222+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51223+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51224+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51225+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51226+4 4 4 4 4 4
51227+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51228+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
51229+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
51230+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
51231+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
51232+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
51233+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51234+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
51235+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51236+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51237+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51238+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51239+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51240+4 4 4 4 4 4
51241+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51242+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
51243+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
51244+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51245+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
51246+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
51247+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51248+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
51249+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51250+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51251+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51252+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51254+4 4 4 4 4 4
51255+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51256+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
51257+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
51258+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
51259+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
51260+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
51261+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
51262+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
51263+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
51264+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51265+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51266+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51267+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51268+4 4 4 4 4 4
51269+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51270+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
51271+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
51272+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
51273+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
51274+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
51275+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
51276+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
51277+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
51278+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51279+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51280+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51281+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51282+4 4 4 4 4 4
51283+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
51284+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
51285+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
51286+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
51287+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51288+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
51289+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
51290+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
51291+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
51292+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51293+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51294+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51296+4 4 4 4 4 4
51297+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51298+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
51299+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
51300+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
51301+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
51302+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
51303+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
51304+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
51305+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
51306+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51307+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51308+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51309+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51310+4 4 4 4 4 4
51311+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
51312+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
51313+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
51314+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
51315+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
51316+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
51317+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
51318+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
51319+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
51320+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
51321+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51322+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51323+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51324+4 4 4 4 4 4
51325+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
51326+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51327+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
51328+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
51329+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
51330+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
51331+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
51332+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
51333+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
51334+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
51335+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51336+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51338+4 4 4 4 4 4
51339+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
51340+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51341+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
51342+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
51343+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
51344+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
51345+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51346+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
51347+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
51348+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
51349+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51350+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51351+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51352+4 4 4 4 4 4
51353+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
51354+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
51355+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
51356+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
51357+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
51358+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
51359+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
51360+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
51361+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
51362+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
51363+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51364+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51365+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51366+4 4 4 4 4 4
51367+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
51368+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
51369+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51370+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
51371+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
51372+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
51373+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
51374+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
51375+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
51376+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
51377+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51378+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51379+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51380+4 4 4 4 4 4
51381+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51382+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
51383+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
51384+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
51385+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
51386+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
51387+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
51388+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
51389+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
51390+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
51391+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51392+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51393+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51394+4 4 4 4 4 4
51395+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
51396+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
51397+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
51398+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
51399+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
51400+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
51401+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
51402+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
51403+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
51404+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
51405+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51406+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51407+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51408+4 4 4 4 4 4
51409+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
51410+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
51411+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
51412+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
51413+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
51414+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
51415+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
51416+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
51417+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
51418+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51419+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51420+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51421+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51422+4 4 4 4 4 4
51423+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
51424+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51425+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
51426+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51427+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
51428+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
51429+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
51430+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
51431+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
51432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51433+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51434+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51435+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51436+4 4 4 4 4 4
51437+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
51438+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
51439+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
51440+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
51441+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
51442+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
51443+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
51444+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
51445+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
51446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51447+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51448+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51449+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51450+4 4 4 4 4 4
51451+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
51452+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
51453+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
51454+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
51455+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
51456+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
51457+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
51458+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
51459+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51461+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51462+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51463+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51464+4 4 4 4 4 4
51465+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
51466+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
51467+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51468+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
51469+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
51470+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
51471+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
51472+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
51473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51475+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51476+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51477+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51478+4 4 4 4 4 4
51479+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51480+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
51481+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
51482+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
51483+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
51484+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
51485+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
51486+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
51487+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51488+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51489+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51490+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51491+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51492+4 4 4 4 4 4
51493+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51494+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
51495+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51496+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
51497+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
51498+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
51499+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
51500+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
51501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51502+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51503+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51504+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51505+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51506+4 4 4 4 4 4
51507+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51508+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
51509+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
51510+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
51511+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
51512+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
51513+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
51514+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
51515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51516+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51517+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51518+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51519+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51520+4 4 4 4 4 4
51521+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51522+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
51523+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
51524+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51525+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
51526+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
51527+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
51528+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51530+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51531+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51532+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51533+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51534+4 4 4 4 4 4
51535+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51536+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51537+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51538+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
51539+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
51540+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
51541+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
51542+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51543+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51544+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51545+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51546+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51547+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51548+4 4 4 4 4 4
51549+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51550+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51551+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51552+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51553+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
51554+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
51555+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
51556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51557+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51558+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51559+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51560+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51561+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51562+4 4 4 4 4 4
51563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51564+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51565+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51566+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51567+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51568+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
51569+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
51570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51571+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51572+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51573+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51574+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51575+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51576+4 4 4 4 4 4
51577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51578+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51579+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51580+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
51581+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51582+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51583+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
51584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51585+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51586+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51587+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51588+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51589+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51590+4 4 4 4 4 4
51591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51592+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51593+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51594+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
51595+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
51596+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
51597+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
51598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51599+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51600+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51601+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51604+4 4 4 4 4 4
51605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51607+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51609+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
51610+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51611+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51615+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51618+4 4 4 4 4 4
51619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51623+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
51624+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
51625+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
51626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51629+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51632+4 4 4 4 4 4
51633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51637+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
51638+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
51639+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51643+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51646+4 4 4 4 4 4
51647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51651+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
51652+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
51653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51657+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51660+4 4 4 4 4 4
51661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51665+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51666+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
51667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51674+4 4 4 4 4 4
51675diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
51676index fe92eed..106e085 100644
51677--- a/drivers/video/mb862xx/mb862xxfb_accel.c
51678+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
51679@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
51680 struct mb862xxfb_par *par = info->par;
51681
51682 if (info->var.bits_per_pixel == 32) {
51683- info->fbops->fb_fillrect = cfb_fillrect;
51684- info->fbops->fb_copyarea = cfb_copyarea;
51685- info->fbops->fb_imageblit = cfb_imageblit;
51686+ pax_open_kernel();
51687+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
51688+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
51689+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
51690+ pax_close_kernel();
51691 } else {
51692 outreg(disp, GC_L0EM, 3);
51693- info->fbops->fb_fillrect = mb86290fb_fillrect;
51694- info->fbops->fb_copyarea = mb86290fb_copyarea;
51695- info->fbops->fb_imageblit = mb86290fb_imageblit;
51696+ pax_open_kernel();
51697+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
51698+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
51699+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
51700+ pax_close_kernel();
51701 }
51702 outreg(draw, GDC_REG_DRAW_BASE, 0);
51703 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
51704diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
51705index ff22871..b129bed 100644
51706--- a/drivers/video/nvidia/nvidia.c
51707+++ b/drivers/video/nvidia/nvidia.c
51708@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
51709 info->fix.line_length = (info->var.xres_virtual *
51710 info->var.bits_per_pixel) >> 3;
51711 if (info->var.accel_flags) {
51712- info->fbops->fb_imageblit = nvidiafb_imageblit;
51713- info->fbops->fb_fillrect = nvidiafb_fillrect;
51714- info->fbops->fb_copyarea = nvidiafb_copyarea;
51715- info->fbops->fb_sync = nvidiafb_sync;
51716+ pax_open_kernel();
51717+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
51718+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
51719+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
51720+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
51721+ pax_close_kernel();
51722 info->pixmap.scan_align = 4;
51723 info->flags &= ~FBINFO_HWACCEL_DISABLED;
51724 info->flags |= FBINFO_READS_FAST;
51725 NVResetGraphics(info);
51726 } else {
51727- info->fbops->fb_imageblit = cfb_imageblit;
51728- info->fbops->fb_fillrect = cfb_fillrect;
51729- info->fbops->fb_copyarea = cfb_copyarea;
51730- info->fbops->fb_sync = NULL;
51731+ pax_open_kernel();
51732+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
51733+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
51734+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
51735+ *(void **)&info->fbops->fb_sync = NULL;
51736+ pax_close_kernel();
51737 info->pixmap.scan_align = 1;
51738 info->flags |= FBINFO_HWACCEL_DISABLED;
51739 info->flags &= ~FBINFO_READS_FAST;
51740@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
51741 info->pixmap.size = 8 * 1024;
51742 info->pixmap.flags = FB_PIXMAP_SYSTEM;
51743
51744- if (!hwcur)
51745- info->fbops->fb_cursor = NULL;
51746+ if (!hwcur) {
51747+ pax_open_kernel();
51748+ *(void **)&info->fbops->fb_cursor = NULL;
51749+ pax_close_kernel();
51750+ }
51751
51752 info->var.accel_flags = (!noaccel);
51753
51754diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
51755index 05c2dc3..ea1f391 100644
51756--- a/drivers/video/s1d13xxxfb.c
51757+++ b/drivers/video/s1d13xxxfb.c
51758@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
51759
51760 switch(prod_id) {
51761 case S1D13506_PROD_ID: /* activate acceleration */
51762- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
51763- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
51764+ pax_open_kernel();
51765+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
51766+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
51767+ pax_close_kernel();
51768 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
51769 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
51770 break;
51771diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
51772index e188ada..aac63c8 100644
51773--- a/drivers/video/smscufx.c
51774+++ b/drivers/video/smscufx.c
51775@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
51776 fb_deferred_io_cleanup(info);
51777 kfree(info->fbdefio);
51778 info->fbdefio = NULL;
51779- info->fbops->fb_mmap = ufx_ops_mmap;
51780+ pax_open_kernel();
51781+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
51782+ pax_close_kernel();
51783 }
51784
51785 pr_debug("released /dev/fb%d user=%d count=%d",
51786diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
51787index d2e5bc3..4cb05d1 100644
51788--- a/drivers/video/udlfb.c
51789+++ b/drivers/video/udlfb.c
51790@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
51791 dlfb_urb_completion(urb);
51792
51793 error:
51794- atomic_add(bytes_sent, &dev->bytes_sent);
51795- atomic_add(bytes_identical, &dev->bytes_identical);
51796- atomic_add(width*height*2, &dev->bytes_rendered);
51797+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
51798+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
51799+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
51800 end_cycles = get_cycles();
51801- atomic_add(((unsigned int) ((end_cycles - start_cycles)
51802+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
51803 >> 10)), /* Kcycles */
51804 &dev->cpu_kcycles_used);
51805
51806@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
51807 dlfb_urb_completion(urb);
51808
51809 error:
51810- atomic_add(bytes_sent, &dev->bytes_sent);
51811- atomic_add(bytes_identical, &dev->bytes_identical);
51812- atomic_add(bytes_rendered, &dev->bytes_rendered);
51813+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
51814+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
51815+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
51816 end_cycles = get_cycles();
51817- atomic_add(((unsigned int) ((end_cycles - start_cycles)
51818+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
51819 >> 10)), /* Kcycles */
51820 &dev->cpu_kcycles_used);
51821 }
51822@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
51823 fb_deferred_io_cleanup(info);
51824 kfree(info->fbdefio);
51825 info->fbdefio = NULL;
51826- info->fbops->fb_mmap = dlfb_ops_mmap;
51827+ pax_open_kernel();
51828+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
51829+ pax_close_kernel();
51830 }
51831
51832 pr_warn("released /dev/fb%d user=%d count=%d\n",
51833@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
51834 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51835 struct dlfb_data *dev = fb_info->par;
51836 return snprintf(buf, PAGE_SIZE, "%u\n",
51837- atomic_read(&dev->bytes_rendered));
51838+ atomic_read_unchecked(&dev->bytes_rendered));
51839 }
51840
51841 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
51842@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
51843 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51844 struct dlfb_data *dev = fb_info->par;
51845 return snprintf(buf, PAGE_SIZE, "%u\n",
51846- atomic_read(&dev->bytes_identical));
51847+ atomic_read_unchecked(&dev->bytes_identical));
51848 }
51849
51850 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
51851@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
51852 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51853 struct dlfb_data *dev = fb_info->par;
51854 return snprintf(buf, PAGE_SIZE, "%u\n",
51855- atomic_read(&dev->bytes_sent));
51856+ atomic_read_unchecked(&dev->bytes_sent));
51857 }
51858
51859 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
51860@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
51861 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51862 struct dlfb_data *dev = fb_info->par;
51863 return snprintf(buf, PAGE_SIZE, "%u\n",
51864- atomic_read(&dev->cpu_kcycles_used));
51865+ atomic_read_unchecked(&dev->cpu_kcycles_used));
51866 }
51867
51868 static ssize_t edid_show(
51869@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
51870 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51871 struct dlfb_data *dev = fb_info->par;
51872
51873- atomic_set(&dev->bytes_rendered, 0);
51874- atomic_set(&dev->bytes_identical, 0);
51875- atomic_set(&dev->bytes_sent, 0);
51876- atomic_set(&dev->cpu_kcycles_used, 0);
51877+ atomic_set_unchecked(&dev->bytes_rendered, 0);
51878+ atomic_set_unchecked(&dev->bytes_identical, 0);
51879+ atomic_set_unchecked(&dev->bytes_sent, 0);
51880+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
51881
51882 return count;
51883 }
51884diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
51885index 7aec6f3..e3b2d55 100644
51886--- a/drivers/video/uvesafb.c
51887+++ b/drivers/video/uvesafb.c
51888@@ -19,6 +19,7 @@
51889 #include <linux/io.h>
51890 #include <linux/mutex.h>
51891 #include <linux/slab.h>
51892+#include <linux/moduleloader.h>
51893 #include <video/edid.h>
51894 #include <video/uvesafb.h>
51895 #ifdef CONFIG_X86
51896@@ -566,10 +567,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
51897 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
51898 par->pmi_setpal = par->ypan = 0;
51899 } else {
51900+
51901+#ifdef CONFIG_PAX_KERNEXEC
51902+#ifdef CONFIG_MODULES
51903+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
51904+#endif
51905+ if (!par->pmi_code) {
51906+ par->pmi_setpal = par->ypan = 0;
51907+ return 0;
51908+ }
51909+#endif
51910+
51911 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
51912 + task->t.regs.edi);
51913+
51914+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51915+ pax_open_kernel();
51916+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
51917+ pax_close_kernel();
51918+
51919+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
51920+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
51921+#else
51922 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
51923 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
51924+#endif
51925+
51926 printk(KERN_INFO "uvesafb: protected mode interface info at "
51927 "%04x:%04x\n",
51928 (u16)task->t.regs.es, (u16)task->t.regs.edi);
51929@@ -814,13 +837,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
51930 par->ypan = ypan;
51931
51932 if (par->pmi_setpal || par->ypan) {
51933+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
51934 if (__supported_pte_mask & _PAGE_NX) {
51935 par->pmi_setpal = par->ypan = 0;
51936 printk(KERN_WARNING "uvesafb: NX protection is active, "
51937 "better not use the PMI.\n");
51938- } else {
51939+ } else
51940+#endif
51941 uvesafb_vbe_getpmi(task, par);
51942- }
51943 }
51944 #else
51945 /* The protected mode interface is not available on non-x86. */
51946@@ -1454,8 +1478,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
51947 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
51948
51949 /* Disable blanking if the user requested so. */
51950- if (!blank)
51951- info->fbops->fb_blank = NULL;
51952+ if (!blank) {
51953+ pax_open_kernel();
51954+ *(void **)&info->fbops->fb_blank = NULL;
51955+ pax_close_kernel();
51956+ }
51957
51958 /*
51959 * Find out how much IO memory is required for the mode with
51960@@ -1531,8 +1558,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
51961 info->flags = FBINFO_FLAG_DEFAULT |
51962 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
51963
51964- if (!par->ypan)
51965- info->fbops->fb_pan_display = NULL;
51966+ if (!par->ypan) {
51967+ pax_open_kernel();
51968+ *(void **)&info->fbops->fb_pan_display = NULL;
51969+ pax_close_kernel();
51970+ }
51971 }
51972
51973 static void uvesafb_init_mtrr(struct fb_info *info)
51974@@ -1796,6 +1826,11 @@ out:
51975 if (par->vbe_modes)
51976 kfree(par->vbe_modes);
51977
51978+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51979+ if (par->pmi_code)
51980+ module_free_exec(NULL, par->pmi_code);
51981+#endif
51982+
51983 framebuffer_release(info);
51984 return err;
51985 }
51986@@ -1823,6 +1858,12 @@ static int uvesafb_remove(struct platform_device *dev)
51987 kfree(par->vbe_state_orig);
51988 if (par->vbe_state_saved)
51989 kfree(par->vbe_state_saved);
51990+
51991+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51992+ if (par->pmi_code)
51993+ module_free_exec(NULL, par->pmi_code);
51994+#endif
51995+
51996 }
51997
51998 framebuffer_release(info);
51999diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
52000index 501b340..d80aa17 100644
52001--- a/drivers/video/vesafb.c
52002+++ b/drivers/video/vesafb.c
52003@@ -9,6 +9,7 @@
52004 */
52005
52006 #include <linux/module.h>
52007+#include <linux/moduleloader.h>
52008 #include <linux/kernel.h>
52009 #include <linux/errno.h>
52010 #include <linux/string.h>
52011@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
52012 static int vram_total __initdata; /* Set total amount of memory */
52013 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
52014 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
52015-static void (*pmi_start)(void) __read_mostly;
52016-static void (*pmi_pal) (void) __read_mostly;
52017+static void (*pmi_start)(void) __read_only;
52018+static void (*pmi_pal) (void) __read_only;
52019 static int depth __read_mostly;
52020 static int vga_compat __read_mostly;
52021 /* --------------------------------------------------------------------- */
52022@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
52023 unsigned int size_vmode;
52024 unsigned int size_remap;
52025 unsigned int size_total;
52026+ void *pmi_code = NULL;
52027
52028 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
52029 return -ENODEV;
52030@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
52031 size_remap = size_total;
52032 vesafb_fix.smem_len = size_remap;
52033
52034-#ifndef __i386__
52035- screen_info.vesapm_seg = 0;
52036-#endif
52037-
52038 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
52039 printk(KERN_WARNING
52040 "vesafb: cannot reserve video memory at 0x%lx\n",
52041@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
52042 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
52043 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
52044
52045+#ifdef __i386__
52046+
52047+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52048+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
52049+ if (!pmi_code)
52050+#elif !defined(CONFIG_PAX_KERNEXEC)
52051+ if (0)
52052+#endif
52053+
52054+#endif
52055+ screen_info.vesapm_seg = 0;
52056+
52057 if (screen_info.vesapm_seg) {
52058- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
52059- screen_info.vesapm_seg,screen_info.vesapm_off);
52060+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
52061+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
52062 }
52063
52064 if (screen_info.vesapm_seg < 0xc000)
52065@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
52066
52067 if (ypan || pmi_setpal) {
52068 unsigned short *pmi_base;
52069+
52070 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
52071- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
52072- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
52073+
52074+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52075+ pax_open_kernel();
52076+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
52077+#else
52078+ pmi_code = pmi_base;
52079+#endif
52080+
52081+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
52082+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
52083+
52084+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52085+ pmi_start = ktva_ktla(pmi_start);
52086+ pmi_pal = ktva_ktla(pmi_pal);
52087+ pax_close_kernel();
52088+#endif
52089+
52090 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
52091 if (pmi_base[3]) {
52092 printk(KERN_INFO "vesafb: pmi: ports = ");
52093@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
52094 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
52095 (ypan ? FBINFO_HWACCEL_YPAN : 0);
52096
52097- if (!ypan)
52098- info->fbops->fb_pan_display = NULL;
52099+ if (!ypan) {
52100+ pax_open_kernel();
52101+ *(void **)&info->fbops->fb_pan_display = NULL;
52102+ pax_close_kernel();
52103+ }
52104
52105 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
52106 err = -ENOMEM;
52107@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
52108 info->node, info->fix.id);
52109 return 0;
52110 err:
52111+
52112+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52113+ module_free_exec(NULL, pmi_code);
52114+#endif
52115+
52116 if (info->screen_base)
52117 iounmap(info->screen_base);
52118 framebuffer_release(info);
52119diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
52120index 88714ae..16c2e11 100644
52121--- a/drivers/video/via/via_clock.h
52122+++ b/drivers/video/via/via_clock.h
52123@@ -56,7 +56,7 @@ struct via_clock {
52124
52125 void (*set_engine_pll_state)(u8 state);
52126 void (*set_engine_pll)(struct via_pll_config config);
52127-};
52128+} __no_const;
52129
52130
52131 static inline u32 get_pll_internal_frequency(u32 ref_freq,
52132diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
52133index fef20db..d28b1ab 100644
52134--- a/drivers/xen/xenfs/xenstored.c
52135+++ b/drivers/xen/xenfs/xenstored.c
52136@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
52137 static int xsd_kva_open(struct inode *inode, struct file *file)
52138 {
52139 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
52140+#ifdef CONFIG_GRKERNSEC_HIDESYM
52141+ NULL);
52142+#else
52143 xen_store_interface);
52144+#endif
52145+
52146 if (!file->private_data)
52147 return -ENOMEM;
52148 return 0;
52149diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
52150index 9ff073f..05cef23 100644
52151--- a/fs/9p/vfs_addr.c
52152+++ b/fs/9p/vfs_addr.c
52153@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
52154
52155 retval = v9fs_file_write_internal(inode,
52156 v9inode->writeback_fid,
52157- (__force const char __user *)buffer,
52158+ (const char __force_user *)buffer,
52159 len, &offset, 0);
52160 if (retval > 0)
52161 retval = 0;
52162diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
52163index 25b018e..b941525 100644
52164--- a/fs/9p/vfs_inode.c
52165+++ b/fs/9p/vfs_inode.c
52166@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
52167 void
52168 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52169 {
52170- char *s = nd_get_link(nd);
52171+ const char *s = nd_get_link(nd);
52172
52173 p9_debug(P9_DEBUG_VFS, " %s %s\n",
52174 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
52175diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
52176index 370b24c..ff0be7b 100644
52177--- a/fs/Kconfig.binfmt
52178+++ b/fs/Kconfig.binfmt
52179@@ -103,7 +103,7 @@ config HAVE_AOUT
52180
52181 config BINFMT_AOUT
52182 tristate "Kernel support for a.out and ECOFF binaries"
52183- depends on HAVE_AOUT
52184+ depends on HAVE_AOUT && BROKEN
52185 ---help---
52186 A.out (Assembler.OUTput) is a set of formats for libraries and
52187 executables used in the earliest versions of UNIX. Linux used
52188diff --git a/fs/afs/inode.c b/fs/afs/inode.c
52189index 789bc25..fafaeea 100644
52190--- a/fs/afs/inode.c
52191+++ b/fs/afs/inode.c
52192@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
52193 struct afs_vnode *vnode;
52194 struct super_block *sb;
52195 struct inode *inode;
52196- static atomic_t afs_autocell_ino;
52197+ static atomic_unchecked_t afs_autocell_ino;
52198
52199 _enter("{%x:%u},%*.*s,",
52200 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
52201@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
52202 data.fid.unique = 0;
52203 data.fid.vnode = 0;
52204
52205- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
52206+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
52207 afs_iget5_autocell_test, afs_iget5_set,
52208 &data);
52209 if (!inode) {
52210diff --git a/fs/aio.c b/fs/aio.c
52211index 9b5ca11..c530886 100644
52212--- a/fs/aio.c
52213+++ b/fs/aio.c
52214@@ -162,7 +162,7 @@ static int aio_setup_ring(struct kioctx *ctx)
52215 size += sizeof(struct io_event) * nr_events;
52216 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
52217
52218- if (nr_pages < 0)
52219+ if (nr_pages <= 0)
52220 return -EINVAL;
52221
52222 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
52223@@ -952,6 +952,7 @@ static ssize_t aio_rw_vect_retry(struct kiocb *iocb, int rw, aio_rw_op *rw_op)
52224 static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
52225 {
52226 ssize_t ret;
52227+ struct iovec iovstack;
52228
52229 kiocb->ki_nr_segs = kiocb->ki_nbytes;
52230
52231@@ -959,17 +960,22 @@ static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
52232 if (compat)
52233 ret = compat_rw_copy_check_uvector(rw,
52234 (struct compat_iovec __user *)kiocb->ki_buf,
52235- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
52236+ kiocb->ki_nr_segs, 1, &iovstack,
52237 &kiocb->ki_iovec);
52238 else
52239 #endif
52240 ret = rw_copy_check_uvector(rw,
52241 (struct iovec __user *)kiocb->ki_buf,
52242- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
52243+ kiocb->ki_nr_segs, 1, &iovstack,
52244 &kiocb->ki_iovec);
52245 if (ret < 0)
52246 return ret;
52247
52248+ if (kiocb->ki_iovec == &iovstack) {
52249+ kiocb->ki_inline_vec = iovstack;
52250+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
52251+ }
52252+
52253 /* ki_nbytes now reflect bytes instead of segs */
52254 kiocb->ki_nbytes = ret;
52255 return 0;
52256diff --git a/fs/attr.c b/fs/attr.c
52257index 1449adb..a2038c2 100644
52258--- a/fs/attr.c
52259+++ b/fs/attr.c
52260@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
52261 unsigned long limit;
52262
52263 limit = rlimit(RLIMIT_FSIZE);
52264+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
52265 if (limit != RLIM_INFINITY && offset > limit)
52266 goto out_sig;
52267 if (offset > inode->i_sb->s_maxbytes)
52268diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
52269index 3db70da..7aeec5b 100644
52270--- a/fs/autofs4/waitq.c
52271+++ b/fs/autofs4/waitq.c
52272@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
52273 {
52274 unsigned long sigpipe, flags;
52275 mm_segment_t fs;
52276- const char *data = (const char *)addr;
52277+ const char __user *data = (const char __force_user *)addr;
52278 ssize_t wr = 0;
52279
52280 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
52281@@ -346,6 +346,10 @@ static int validate_request(struct autofs_wait_queue **wait,
52282 return 1;
52283 }
52284
52285+#ifdef CONFIG_GRKERNSEC_HIDESYM
52286+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
52287+#endif
52288+
52289 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52290 enum autofs_notify notify)
52291 {
52292@@ -379,7 +383,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52293
52294 /* If this is a direct mount request create a dummy name */
52295 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
52296+#ifdef CONFIG_GRKERNSEC_HIDESYM
52297+ /* this name does get written to userland via autofs4_write() */
52298+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
52299+#else
52300 qstr.len = sprintf(name, "%p", dentry);
52301+#endif
52302 else {
52303 qstr.len = autofs4_getpath(sbi, dentry, &name);
52304 if (!qstr.len) {
52305diff --git a/fs/befs/endian.h b/fs/befs/endian.h
52306index 2722387..c8dd2a7 100644
52307--- a/fs/befs/endian.h
52308+++ b/fs/befs/endian.h
52309@@ -11,7 +11,7 @@
52310
52311 #include <asm/byteorder.h>
52312
52313-static inline u64
52314+static inline u64 __intentional_overflow(-1)
52315 fs64_to_cpu(const struct super_block *sb, fs64 n)
52316 {
52317 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52318@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
52319 return (__force fs64)cpu_to_be64(n);
52320 }
52321
52322-static inline u32
52323+static inline u32 __intentional_overflow(-1)
52324 fs32_to_cpu(const struct super_block *sb, fs32 n)
52325 {
52326 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52327diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
52328index e9c75e2..1baece1 100644
52329--- a/fs/befs/linuxvfs.c
52330+++ b/fs/befs/linuxvfs.c
52331@@ -514,7 +514,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52332 {
52333 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
52334 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
52335- char *link = nd_get_link(nd);
52336+ const char *link = nd_get_link(nd);
52337 if (!IS_ERR(link))
52338 kfree(link);
52339 }
52340diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
52341index 89dec7f..361b0d75 100644
52342--- a/fs/binfmt_aout.c
52343+++ b/fs/binfmt_aout.c
52344@@ -16,6 +16,7 @@
52345 #include <linux/string.h>
52346 #include <linux/fs.h>
52347 #include <linux/file.h>
52348+#include <linux/security.h>
52349 #include <linux/stat.h>
52350 #include <linux/fcntl.h>
52351 #include <linux/ptrace.h>
52352@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
52353 #endif
52354 # define START_STACK(u) ((void __user *)u.start_stack)
52355
52356+ memset(&dump, 0, sizeof(dump));
52357+
52358 fs = get_fs();
52359 set_fs(KERNEL_DS);
52360 has_dumped = 1;
52361@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
52362
52363 /* If the size of the dump file exceeds the rlimit, then see what would happen
52364 if we wrote the stack, but not the data area. */
52365+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
52366 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
52367 dump.u_dsize = 0;
52368
52369 /* Make sure we have enough room to write the stack and data areas. */
52370+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
52371 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
52372 dump.u_ssize = 0;
52373
52374@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
52375 rlim = rlimit(RLIMIT_DATA);
52376 if (rlim >= RLIM_INFINITY)
52377 rlim = ~0;
52378+
52379+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
52380 if (ex.a_data + ex.a_bss > rlim)
52381 return -ENOMEM;
52382
52383@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
52384
52385 install_exec_creds(bprm);
52386
52387+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52388+ current->mm->pax_flags = 0UL;
52389+#endif
52390+
52391+#ifdef CONFIG_PAX_PAGEEXEC
52392+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
52393+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
52394+
52395+#ifdef CONFIG_PAX_EMUTRAMP
52396+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
52397+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
52398+#endif
52399+
52400+#ifdef CONFIG_PAX_MPROTECT
52401+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
52402+ current->mm->pax_flags |= MF_PAX_MPROTECT;
52403+#endif
52404+
52405+ }
52406+#endif
52407+
52408 if (N_MAGIC(ex) == OMAGIC) {
52409 unsigned long text_addr, map_size;
52410 loff_t pos;
52411@@ -322,7 +350,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
52412 }
52413
52414 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
52415- PROT_READ | PROT_WRITE | PROT_EXEC,
52416+ PROT_READ | PROT_WRITE,
52417 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
52418 fd_offset + ex.a_text);
52419 if (error != N_DATADDR(ex)) {
52420diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
52421index 100edcc..ed95731 100644
52422--- a/fs/binfmt_elf.c
52423+++ b/fs/binfmt_elf.c
52424@@ -34,6 +34,7 @@
52425 #include <linux/utsname.h>
52426 #include <linux/coredump.h>
52427 #include <linux/sched.h>
52428+#include <linux/xattr.h>
52429 #include <asm/uaccess.h>
52430 #include <asm/param.h>
52431 #include <asm/page.h>
52432@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
52433 #define elf_core_dump NULL
52434 #endif
52435
52436+#ifdef CONFIG_PAX_MPROTECT
52437+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
52438+#endif
52439+
52440+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52441+static void elf_handle_mmap(struct file *file);
52442+#endif
52443+
52444 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
52445 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
52446 #else
52447@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
52448 .load_binary = load_elf_binary,
52449 .load_shlib = load_elf_library,
52450 .core_dump = elf_core_dump,
52451+
52452+#ifdef CONFIG_PAX_MPROTECT
52453+ .handle_mprotect= elf_handle_mprotect,
52454+#endif
52455+
52456+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52457+ .handle_mmap = elf_handle_mmap,
52458+#endif
52459+
52460 .min_coredump = ELF_EXEC_PAGESIZE,
52461 };
52462
52463@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
52464
52465 static int set_brk(unsigned long start, unsigned long end)
52466 {
52467+ unsigned long e = end;
52468+
52469 start = ELF_PAGEALIGN(start);
52470 end = ELF_PAGEALIGN(end);
52471 if (end > start) {
52472@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
52473 if (BAD_ADDR(addr))
52474 return addr;
52475 }
52476- current->mm->start_brk = current->mm->brk = end;
52477+ current->mm->start_brk = current->mm->brk = e;
52478 return 0;
52479 }
52480
52481@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52482 elf_addr_t __user *u_rand_bytes;
52483 const char *k_platform = ELF_PLATFORM;
52484 const char *k_base_platform = ELF_BASE_PLATFORM;
52485- unsigned char k_rand_bytes[16];
52486+ u32 k_rand_bytes[4];
52487 int items;
52488 elf_addr_t *elf_info;
52489 int ei_index = 0;
52490 const struct cred *cred = current_cred();
52491 struct vm_area_struct *vma;
52492+ unsigned long saved_auxv[AT_VECTOR_SIZE];
52493
52494 /*
52495 * In some cases (e.g. Hyper-Threading), we want to avoid L1
52496@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52497 * Generate 16 random bytes for userspace PRNG seeding.
52498 */
52499 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
52500- u_rand_bytes = (elf_addr_t __user *)
52501- STACK_ALLOC(p, sizeof(k_rand_bytes));
52502+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
52503+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
52504+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
52505+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
52506+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
52507+ u_rand_bytes = (elf_addr_t __user *) p;
52508 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
52509 return -EFAULT;
52510
52511@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52512 return -EFAULT;
52513 current->mm->env_end = p;
52514
52515+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
52516+
52517 /* Put the elf_info on the stack in the right place. */
52518 sp = (elf_addr_t __user *)envp + 1;
52519- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
52520+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
52521 return -EFAULT;
52522 return 0;
52523 }
52524@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
52525 an ELF header */
52526
52527 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52528- struct file *interpreter, unsigned long *interp_map_addr,
52529- unsigned long no_base)
52530+ struct file *interpreter, unsigned long no_base)
52531 {
52532 struct elf_phdr *elf_phdata;
52533 struct elf_phdr *eppnt;
52534- unsigned long load_addr = 0;
52535+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
52536 int load_addr_set = 0;
52537 unsigned long last_bss = 0, elf_bss = 0;
52538- unsigned long error = ~0UL;
52539+ unsigned long error = -EINVAL;
52540 unsigned long total_size;
52541 int retval, i, size;
52542
52543@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52544 goto out_close;
52545 }
52546
52547+#ifdef CONFIG_PAX_SEGMEXEC
52548+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
52549+ pax_task_size = SEGMEXEC_TASK_SIZE;
52550+#endif
52551+
52552 eppnt = elf_phdata;
52553 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
52554 if (eppnt->p_type == PT_LOAD) {
52555@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52556 map_addr = elf_map(interpreter, load_addr + vaddr,
52557 eppnt, elf_prot, elf_type, total_size);
52558 total_size = 0;
52559- if (!*interp_map_addr)
52560- *interp_map_addr = map_addr;
52561 error = map_addr;
52562 if (BAD_ADDR(map_addr))
52563 goto out_close;
52564@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52565 k = load_addr + eppnt->p_vaddr;
52566 if (BAD_ADDR(k) ||
52567 eppnt->p_filesz > eppnt->p_memsz ||
52568- eppnt->p_memsz > TASK_SIZE ||
52569- TASK_SIZE - eppnt->p_memsz < k) {
52570+ eppnt->p_memsz > pax_task_size ||
52571+ pax_task_size - eppnt->p_memsz < k) {
52572 error = -ENOMEM;
52573 goto out_close;
52574 }
52575@@ -538,6 +567,315 @@ out:
52576 return error;
52577 }
52578
52579+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52580+#ifdef CONFIG_PAX_SOFTMODE
52581+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
52582+{
52583+ unsigned long pax_flags = 0UL;
52584+
52585+#ifdef CONFIG_PAX_PAGEEXEC
52586+ if (elf_phdata->p_flags & PF_PAGEEXEC)
52587+ pax_flags |= MF_PAX_PAGEEXEC;
52588+#endif
52589+
52590+#ifdef CONFIG_PAX_SEGMEXEC
52591+ if (elf_phdata->p_flags & PF_SEGMEXEC)
52592+ pax_flags |= MF_PAX_SEGMEXEC;
52593+#endif
52594+
52595+#ifdef CONFIG_PAX_EMUTRAMP
52596+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52597+ pax_flags |= MF_PAX_EMUTRAMP;
52598+#endif
52599+
52600+#ifdef CONFIG_PAX_MPROTECT
52601+ if (elf_phdata->p_flags & PF_MPROTECT)
52602+ pax_flags |= MF_PAX_MPROTECT;
52603+#endif
52604+
52605+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52606+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
52607+ pax_flags |= MF_PAX_RANDMMAP;
52608+#endif
52609+
52610+ return pax_flags;
52611+}
52612+#endif
52613+
52614+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
52615+{
52616+ unsigned long pax_flags = 0UL;
52617+
52618+#ifdef CONFIG_PAX_PAGEEXEC
52619+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
52620+ pax_flags |= MF_PAX_PAGEEXEC;
52621+#endif
52622+
52623+#ifdef CONFIG_PAX_SEGMEXEC
52624+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
52625+ pax_flags |= MF_PAX_SEGMEXEC;
52626+#endif
52627+
52628+#ifdef CONFIG_PAX_EMUTRAMP
52629+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
52630+ pax_flags |= MF_PAX_EMUTRAMP;
52631+#endif
52632+
52633+#ifdef CONFIG_PAX_MPROTECT
52634+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
52635+ pax_flags |= MF_PAX_MPROTECT;
52636+#endif
52637+
52638+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52639+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
52640+ pax_flags |= MF_PAX_RANDMMAP;
52641+#endif
52642+
52643+ return pax_flags;
52644+}
52645+#endif
52646+
52647+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
52648+#ifdef CONFIG_PAX_SOFTMODE
52649+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
52650+{
52651+ unsigned long pax_flags = 0UL;
52652+
52653+#ifdef CONFIG_PAX_PAGEEXEC
52654+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
52655+ pax_flags |= MF_PAX_PAGEEXEC;
52656+#endif
52657+
52658+#ifdef CONFIG_PAX_SEGMEXEC
52659+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
52660+ pax_flags |= MF_PAX_SEGMEXEC;
52661+#endif
52662+
52663+#ifdef CONFIG_PAX_EMUTRAMP
52664+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52665+ pax_flags |= MF_PAX_EMUTRAMP;
52666+#endif
52667+
52668+#ifdef CONFIG_PAX_MPROTECT
52669+ if (pax_flags_softmode & MF_PAX_MPROTECT)
52670+ pax_flags |= MF_PAX_MPROTECT;
52671+#endif
52672+
52673+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52674+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
52675+ pax_flags |= MF_PAX_RANDMMAP;
52676+#endif
52677+
52678+ return pax_flags;
52679+}
52680+#endif
52681+
52682+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
52683+{
52684+ unsigned long pax_flags = 0UL;
52685+
52686+#ifdef CONFIG_PAX_PAGEEXEC
52687+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
52688+ pax_flags |= MF_PAX_PAGEEXEC;
52689+#endif
52690+
52691+#ifdef CONFIG_PAX_SEGMEXEC
52692+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
52693+ pax_flags |= MF_PAX_SEGMEXEC;
52694+#endif
52695+
52696+#ifdef CONFIG_PAX_EMUTRAMP
52697+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
52698+ pax_flags |= MF_PAX_EMUTRAMP;
52699+#endif
52700+
52701+#ifdef CONFIG_PAX_MPROTECT
52702+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
52703+ pax_flags |= MF_PAX_MPROTECT;
52704+#endif
52705+
52706+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52707+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
52708+ pax_flags |= MF_PAX_RANDMMAP;
52709+#endif
52710+
52711+ return pax_flags;
52712+}
52713+#endif
52714+
52715+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52716+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
52717+{
52718+ unsigned long pax_flags = 0UL;
52719+
52720+#ifdef CONFIG_PAX_EI_PAX
52721+
52722+#ifdef CONFIG_PAX_PAGEEXEC
52723+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
52724+ pax_flags |= MF_PAX_PAGEEXEC;
52725+#endif
52726+
52727+#ifdef CONFIG_PAX_SEGMEXEC
52728+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
52729+ pax_flags |= MF_PAX_SEGMEXEC;
52730+#endif
52731+
52732+#ifdef CONFIG_PAX_EMUTRAMP
52733+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
52734+ pax_flags |= MF_PAX_EMUTRAMP;
52735+#endif
52736+
52737+#ifdef CONFIG_PAX_MPROTECT
52738+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
52739+ pax_flags |= MF_PAX_MPROTECT;
52740+#endif
52741+
52742+#ifdef CONFIG_PAX_ASLR
52743+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
52744+ pax_flags |= MF_PAX_RANDMMAP;
52745+#endif
52746+
52747+#else
52748+
52749+#ifdef CONFIG_PAX_PAGEEXEC
52750+ pax_flags |= MF_PAX_PAGEEXEC;
52751+#endif
52752+
52753+#ifdef CONFIG_PAX_SEGMEXEC
52754+ pax_flags |= MF_PAX_SEGMEXEC;
52755+#endif
52756+
52757+#ifdef CONFIG_PAX_MPROTECT
52758+ pax_flags |= MF_PAX_MPROTECT;
52759+#endif
52760+
52761+#ifdef CONFIG_PAX_RANDMMAP
52762+ if (randomize_va_space)
52763+ pax_flags |= MF_PAX_RANDMMAP;
52764+#endif
52765+
52766+#endif
52767+
52768+ return pax_flags;
52769+}
52770+
52771+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
52772+{
52773+
52774+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52775+ unsigned long i;
52776+
52777+ for (i = 0UL; i < elf_ex->e_phnum; i++)
52778+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
52779+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
52780+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
52781+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
52782+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
52783+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
52784+ return ~0UL;
52785+
52786+#ifdef CONFIG_PAX_SOFTMODE
52787+ if (pax_softmode)
52788+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
52789+ else
52790+#endif
52791+
52792+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
52793+ break;
52794+ }
52795+#endif
52796+
52797+ return ~0UL;
52798+}
52799+
52800+static unsigned long pax_parse_xattr_pax(struct file * const file)
52801+{
52802+
52803+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
52804+ ssize_t xattr_size, i;
52805+ unsigned char xattr_value[sizeof("pemrs") - 1];
52806+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
52807+
52808+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
52809+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
52810+ return ~0UL;
52811+
52812+ for (i = 0; i < xattr_size; i++)
52813+ switch (xattr_value[i]) {
52814+ default:
52815+ return ~0UL;
52816+
52817+#define parse_flag(option1, option2, flag) \
52818+ case option1: \
52819+ if (pax_flags_hardmode & MF_PAX_##flag) \
52820+ return ~0UL; \
52821+ pax_flags_hardmode |= MF_PAX_##flag; \
52822+ break; \
52823+ case option2: \
52824+ if (pax_flags_softmode & MF_PAX_##flag) \
52825+ return ~0UL; \
52826+ pax_flags_softmode |= MF_PAX_##flag; \
52827+ break;
52828+
52829+ parse_flag('p', 'P', PAGEEXEC);
52830+ parse_flag('e', 'E', EMUTRAMP);
52831+ parse_flag('m', 'M', MPROTECT);
52832+ parse_flag('r', 'R', RANDMMAP);
52833+ parse_flag('s', 'S', SEGMEXEC);
52834+
52835+#undef parse_flag
52836+ }
52837+
52838+ if (pax_flags_hardmode & pax_flags_softmode)
52839+ return ~0UL;
52840+
52841+#ifdef CONFIG_PAX_SOFTMODE
52842+ if (pax_softmode)
52843+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
52844+ else
52845+#endif
52846+
52847+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
52848+#else
52849+ return ~0UL;
52850+#endif
52851+
52852+}
52853+
52854+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
52855+{
52856+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
52857+
52858+ pax_flags = pax_parse_ei_pax(elf_ex);
52859+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
52860+ xattr_pax_flags = pax_parse_xattr_pax(file);
52861+
52862+ if (pt_pax_flags == ~0UL)
52863+ pt_pax_flags = xattr_pax_flags;
52864+ else if (xattr_pax_flags == ~0UL)
52865+ xattr_pax_flags = pt_pax_flags;
52866+ if (pt_pax_flags != xattr_pax_flags)
52867+ return -EINVAL;
52868+ if (pt_pax_flags != ~0UL)
52869+ pax_flags = pt_pax_flags;
52870+
52871+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
52872+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52873+ if ((__supported_pte_mask & _PAGE_NX))
52874+ pax_flags &= ~MF_PAX_SEGMEXEC;
52875+ else
52876+ pax_flags &= ~MF_PAX_PAGEEXEC;
52877+ }
52878+#endif
52879+
52880+ if (0 > pax_check_flags(&pax_flags))
52881+ return -EINVAL;
52882+
52883+ current->mm->pax_flags = pax_flags;
52884+ return 0;
52885+}
52886+#endif
52887+
52888 /*
52889 * These are the functions used to load ELF style executables and shared
52890 * libraries. There is no binary dependent code anywhere else.
52891@@ -554,6 +892,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
52892 {
52893 unsigned int random_variable = 0;
52894
52895+#ifdef CONFIG_PAX_RANDUSTACK
52896+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
52897+ return stack_top - current->mm->delta_stack;
52898+#endif
52899+
52900 if ((current->flags & PF_RANDOMIZE) &&
52901 !(current->personality & ADDR_NO_RANDOMIZE)) {
52902 random_variable = get_random_int() & STACK_RND_MASK;
52903@@ -572,7 +915,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
52904 unsigned long load_addr = 0, load_bias = 0;
52905 int load_addr_set = 0;
52906 char * elf_interpreter = NULL;
52907- unsigned long error;
52908+ unsigned long error = 0;
52909 struct elf_phdr *elf_ppnt, *elf_phdata;
52910 unsigned long elf_bss, elf_brk;
52911 int retval, i;
52912@@ -582,12 +925,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
52913 unsigned long start_code, end_code, start_data, end_data;
52914 unsigned long reloc_func_desc __maybe_unused = 0;
52915 int executable_stack = EXSTACK_DEFAULT;
52916- unsigned long def_flags = 0;
52917 struct pt_regs *regs = current_pt_regs();
52918 struct {
52919 struct elfhdr elf_ex;
52920 struct elfhdr interp_elf_ex;
52921 } *loc;
52922+ unsigned long pax_task_size = TASK_SIZE;
52923
52924 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
52925 if (!loc) {
52926@@ -723,11 +1066,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
52927 goto out_free_dentry;
52928
52929 /* OK, This is the point of no return */
52930- current->mm->def_flags = def_flags;
52931+
52932+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52933+ current->mm->pax_flags = 0UL;
52934+#endif
52935+
52936+#ifdef CONFIG_PAX_DLRESOLVE
52937+ current->mm->call_dl_resolve = 0UL;
52938+#endif
52939+
52940+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
52941+ current->mm->call_syscall = 0UL;
52942+#endif
52943+
52944+#ifdef CONFIG_PAX_ASLR
52945+ current->mm->delta_mmap = 0UL;
52946+ current->mm->delta_stack = 0UL;
52947+#endif
52948+
52949+ current->mm->def_flags = 0;
52950+
52951+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52952+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
52953+ send_sig(SIGKILL, current, 0);
52954+ goto out_free_dentry;
52955+ }
52956+#endif
52957+
52958+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
52959+ pax_set_initial_flags(bprm);
52960+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
52961+ if (pax_set_initial_flags_func)
52962+ (pax_set_initial_flags_func)(bprm);
52963+#endif
52964+
52965+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52966+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
52967+ current->mm->context.user_cs_limit = PAGE_SIZE;
52968+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
52969+ }
52970+#endif
52971+
52972+#ifdef CONFIG_PAX_SEGMEXEC
52973+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
52974+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
52975+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
52976+ pax_task_size = SEGMEXEC_TASK_SIZE;
52977+ current->mm->def_flags |= VM_NOHUGEPAGE;
52978+ }
52979+#endif
52980+
52981+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
52982+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52983+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
52984+ put_cpu();
52985+ }
52986+#endif
52987
52988 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
52989 may depend on the personality. */
52990 SET_PERSONALITY(loc->elf_ex);
52991+
52992+#ifdef CONFIG_PAX_ASLR
52993+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
52994+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
52995+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
52996+ }
52997+#endif
52998+
52999+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
53000+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53001+ executable_stack = EXSTACK_DISABLE_X;
53002+ current->personality &= ~READ_IMPLIES_EXEC;
53003+ } else
53004+#endif
53005+
53006 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
53007 current->personality |= READ_IMPLIES_EXEC;
53008
53009@@ -817,6 +1230,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
53010 #else
53011 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
53012 #endif
53013+
53014+#ifdef CONFIG_PAX_RANDMMAP
53015+ /* PaX: randomize base address at the default exe base if requested */
53016+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
53017+#ifdef CONFIG_SPARC64
53018+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
53019+#else
53020+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
53021+#endif
53022+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
53023+ elf_flags |= MAP_FIXED;
53024+ }
53025+#endif
53026+
53027 }
53028
53029 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
53030@@ -849,9 +1276,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
53031 * allowed task size. Note that p_filesz must always be
53032 * <= p_memsz so it is only necessary to check p_memsz.
53033 */
53034- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
53035- elf_ppnt->p_memsz > TASK_SIZE ||
53036- TASK_SIZE - elf_ppnt->p_memsz < k) {
53037+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
53038+ elf_ppnt->p_memsz > pax_task_size ||
53039+ pax_task_size - elf_ppnt->p_memsz < k) {
53040 /* set_brk can never work. Avoid overflows. */
53041 send_sig(SIGKILL, current, 0);
53042 retval = -EINVAL;
53043@@ -890,17 +1317,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
53044 goto out_free_dentry;
53045 }
53046 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
53047- send_sig(SIGSEGV, current, 0);
53048- retval = -EFAULT; /* Nobody gets to see this, but.. */
53049- goto out_free_dentry;
53050+ /*
53051+ * This bss-zeroing can fail if the ELF
53052+ * file specifies odd protections. So
53053+ * we don't check the return value
53054+ */
53055 }
53056
53057+#ifdef CONFIG_PAX_RANDMMAP
53058+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
53059+ unsigned long start, size, flags;
53060+ vm_flags_t vm_flags;
53061+
53062+ start = ELF_PAGEALIGN(elf_brk);
53063+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
53064+ flags = MAP_FIXED | MAP_PRIVATE;
53065+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
53066+
53067+ down_write(&current->mm->mmap_sem);
53068+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
53069+ retval = -ENOMEM;
53070+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
53071+// if (current->personality & ADDR_NO_RANDOMIZE)
53072+// vm_flags |= VM_READ | VM_MAYREAD;
53073+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
53074+ retval = IS_ERR_VALUE(start) ? start : 0;
53075+ }
53076+ up_write(&current->mm->mmap_sem);
53077+ if (retval == 0)
53078+ retval = set_brk(start + size, start + size + PAGE_SIZE);
53079+ if (retval < 0) {
53080+ send_sig(SIGKILL, current, 0);
53081+ goto out_free_dentry;
53082+ }
53083+ }
53084+#endif
53085+
53086 if (elf_interpreter) {
53087- unsigned long interp_map_addr = 0;
53088-
53089 elf_entry = load_elf_interp(&loc->interp_elf_ex,
53090 interpreter,
53091- &interp_map_addr,
53092 load_bias);
53093 if (!IS_ERR((void *)elf_entry)) {
53094 /*
53095@@ -1122,7 +1577,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
53096 * Decide what to dump of a segment, part, all or none.
53097 */
53098 static unsigned long vma_dump_size(struct vm_area_struct *vma,
53099- unsigned long mm_flags)
53100+ unsigned long mm_flags, long signr)
53101 {
53102 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
53103
53104@@ -1160,7 +1615,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
53105 if (vma->vm_file == NULL)
53106 return 0;
53107
53108- if (FILTER(MAPPED_PRIVATE))
53109+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
53110 goto whole;
53111
53112 /*
53113@@ -1385,9 +1840,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
53114 {
53115 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
53116 int i = 0;
53117- do
53118+ do {
53119 i += 2;
53120- while (auxv[i - 2] != AT_NULL);
53121+ } while (auxv[i - 2] != AT_NULL);
53122 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
53123 }
53124
53125@@ -1396,7 +1851,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
53126 {
53127 mm_segment_t old_fs = get_fs();
53128 set_fs(KERNEL_DS);
53129- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
53130+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
53131 set_fs(old_fs);
53132 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
53133 }
53134@@ -2017,14 +2472,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
53135 }
53136
53137 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
53138- unsigned long mm_flags)
53139+ struct coredump_params *cprm)
53140 {
53141 struct vm_area_struct *vma;
53142 size_t size = 0;
53143
53144 for (vma = first_vma(current, gate_vma); vma != NULL;
53145 vma = next_vma(vma, gate_vma))
53146- size += vma_dump_size(vma, mm_flags);
53147+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53148 return size;
53149 }
53150
53151@@ -2117,7 +2572,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53152
53153 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
53154
53155- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
53156+ offset += elf_core_vma_data_size(gate_vma, cprm);
53157 offset += elf_core_extra_data_size();
53158 e_shoff = offset;
53159
53160@@ -2131,10 +2586,12 @@ static int elf_core_dump(struct coredump_params *cprm)
53161 offset = dataoff;
53162
53163 size += sizeof(*elf);
53164+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53165 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
53166 goto end_coredump;
53167
53168 size += sizeof(*phdr4note);
53169+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53170 if (size > cprm->limit
53171 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
53172 goto end_coredump;
53173@@ -2148,7 +2605,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53174 phdr.p_offset = offset;
53175 phdr.p_vaddr = vma->vm_start;
53176 phdr.p_paddr = 0;
53177- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
53178+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53179 phdr.p_memsz = vma->vm_end - vma->vm_start;
53180 offset += phdr.p_filesz;
53181 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
53182@@ -2159,6 +2616,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53183 phdr.p_align = ELF_EXEC_PAGESIZE;
53184
53185 size += sizeof(phdr);
53186+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53187 if (size > cprm->limit
53188 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
53189 goto end_coredump;
53190@@ -2183,7 +2641,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53191 unsigned long addr;
53192 unsigned long end;
53193
53194- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
53195+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53196
53197 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
53198 struct page *page;
53199@@ -2192,6 +2650,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53200 page = get_dump_page(addr);
53201 if (page) {
53202 void *kaddr = kmap(page);
53203+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
53204 stop = ((size += PAGE_SIZE) > cprm->limit) ||
53205 !dump_write(cprm->file, kaddr,
53206 PAGE_SIZE);
53207@@ -2209,6 +2668,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53208
53209 if (e_phnum == PN_XNUM) {
53210 size += sizeof(*shdr4extnum);
53211+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53212 if (size > cprm->limit
53213 || !dump_write(cprm->file, shdr4extnum,
53214 sizeof(*shdr4extnum)))
53215@@ -2229,6 +2689,167 @@ out:
53216
53217 #endif /* CONFIG_ELF_CORE */
53218
53219+#ifdef CONFIG_PAX_MPROTECT
53220+/* PaX: non-PIC ELF libraries need relocations on their executable segments
53221+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
53222+ * we'll remove VM_MAYWRITE for good on RELRO segments.
53223+ *
53224+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
53225+ * basis because we want to allow the common case and not the special ones.
53226+ */
53227+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
53228+{
53229+ struct elfhdr elf_h;
53230+ struct elf_phdr elf_p;
53231+ unsigned long i;
53232+ unsigned long oldflags;
53233+ bool is_textrel_rw, is_textrel_rx, is_relro;
53234+
53235+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
53236+ return;
53237+
53238+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
53239+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
53240+
53241+#ifdef CONFIG_PAX_ELFRELOCS
53242+ /* possible TEXTREL */
53243+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
53244+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
53245+#else
53246+ is_textrel_rw = false;
53247+ is_textrel_rx = false;
53248+#endif
53249+
53250+ /* possible RELRO */
53251+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
53252+
53253+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
53254+ return;
53255+
53256+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53257+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53258+
53259+#ifdef CONFIG_PAX_ETEXECRELOCS
53260+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53261+#else
53262+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
53263+#endif
53264+
53265+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53266+ !elf_check_arch(&elf_h) ||
53267+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53268+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53269+ return;
53270+
53271+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53272+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53273+ return;
53274+ switch (elf_p.p_type) {
53275+ case PT_DYNAMIC:
53276+ if (!is_textrel_rw && !is_textrel_rx)
53277+ continue;
53278+ i = 0UL;
53279+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
53280+ elf_dyn dyn;
53281+
53282+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
53283+ break;
53284+ if (dyn.d_tag == DT_NULL)
53285+ break;
53286+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
53287+ gr_log_textrel(vma);
53288+ if (is_textrel_rw)
53289+ vma->vm_flags |= VM_MAYWRITE;
53290+ else
53291+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
53292+ vma->vm_flags &= ~VM_MAYWRITE;
53293+ break;
53294+ }
53295+ i++;
53296+ }
53297+ is_textrel_rw = false;
53298+ is_textrel_rx = false;
53299+ continue;
53300+
53301+ case PT_GNU_RELRO:
53302+ if (!is_relro)
53303+ continue;
53304+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
53305+ vma->vm_flags &= ~VM_MAYWRITE;
53306+ is_relro = false;
53307+ continue;
53308+
53309+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53310+ case PT_PAX_FLAGS: {
53311+ const char *msg_mprotect = "", *msg_emutramp = "";
53312+ char *buffer_lib, *buffer_exe;
53313+
53314+ if (elf_p.p_flags & PF_NOMPROTECT)
53315+ msg_mprotect = "MPROTECT disabled";
53316+
53317+#ifdef CONFIG_PAX_EMUTRAMP
53318+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
53319+ msg_emutramp = "EMUTRAMP enabled";
53320+#endif
53321+
53322+ if (!msg_mprotect[0] && !msg_emutramp[0])
53323+ continue;
53324+
53325+ if (!printk_ratelimit())
53326+ continue;
53327+
53328+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
53329+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
53330+ if (buffer_lib && buffer_exe) {
53331+ char *path_lib, *path_exe;
53332+
53333+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
53334+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
53335+
53336+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
53337+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
53338+
53339+ }
53340+ free_page((unsigned long)buffer_exe);
53341+ free_page((unsigned long)buffer_lib);
53342+ continue;
53343+ }
53344+#endif
53345+
53346+ }
53347+ }
53348+}
53349+#endif
53350+
53351+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
53352+
53353+extern int grsec_enable_log_rwxmaps;
53354+
53355+static void elf_handle_mmap(struct file *file)
53356+{
53357+ struct elfhdr elf_h;
53358+ struct elf_phdr elf_p;
53359+ unsigned long i;
53360+
53361+ if (!grsec_enable_log_rwxmaps)
53362+ return;
53363+
53364+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53365+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53366+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
53367+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53368+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53369+ return;
53370+
53371+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53372+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53373+ return;
53374+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
53375+ gr_log_ptgnustack(file);
53376+ }
53377+}
53378+#endif
53379+
53380 static int __init init_elf_binfmt(void)
53381 {
53382 register_binfmt(&elf_format);
53383diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
53384index d50bbe5..af3b649 100644
53385--- a/fs/binfmt_flat.c
53386+++ b/fs/binfmt_flat.c
53387@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
53388 realdatastart = (unsigned long) -ENOMEM;
53389 printk("Unable to allocate RAM for process data, errno %d\n",
53390 (int)-realdatastart);
53391+ down_write(&current->mm->mmap_sem);
53392 vm_munmap(textpos, text_len);
53393+ up_write(&current->mm->mmap_sem);
53394 ret = realdatastart;
53395 goto err;
53396 }
53397@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53398 }
53399 if (IS_ERR_VALUE(result)) {
53400 printk("Unable to read data+bss, errno %d\n", (int)-result);
53401+ down_write(&current->mm->mmap_sem);
53402 vm_munmap(textpos, text_len);
53403 vm_munmap(realdatastart, len);
53404+ up_write(&current->mm->mmap_sem);
53405 ret = result;
53406 goto err;
53407 }
53408@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53409 }
53410 if (IS_ERR_VALUE(result)) {
53411 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
53412+ down_write(&current->mm->mmap_sem);
53413 vm_munmap(textpos, text_len + data_len + extra +
53414 MAX_SHARED_LIBS * sizeof(unsigned long));
53415+ up_write(&current->mm->mmap_sem);
53416 ret = result;
53417 goto err;
53418 }
53419diff --git a/fs/bio.c b/fs/bio.c
53420index c5eae72..599e3cf 100644
53421--- a/fs/bio.c
53422+++ b/fs/bio.c
53423@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
53424 /*
53425 * Overflow, abort
53426 */
53427- if (end < start)
53428+ if (end < start || end - start > INT_MAX - nr_pages)
53429 return ERR_PTR(-EINVAL);
53430
53431 nr_pages += end - start;
53432@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
53433 /*
53434 * Overflow, abort
53435 */
53436- if (end < start)
53437+ if (end < start || end - start > INT_MAX - nr_pages)
53438 return ERR_PTR(-EINVAL);
53439
53440 nr_pages += end - start;
53441@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
53442 const int read = bio_data_dir(bio) == READ;
53443 struct bio_map_data *bmd = bio->bi_private;
53444 int i;
53445- char *p = bmd->sgvecs[0].iov_base;
53446+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
53447
53448 bio_for_each_segment_all(bvec, bio, i) {
53449 char *addr = page_address(bvec->bv_page);
53450diff --git a/fs/block_dev.c b/fs/block_dev.c
53451index c7bda5c..2121e94 100644
53452--- a/fs/block_dev.c
53453+++ b/fs/block_dev.c
53454@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
53455 else if (bdev->bd_contains == bdev)
53456 return true; /* is a whole device which isn't held */
53457
53458- else if (whole->bd_holder == bd_may_claim)
53459+ else if (whole->bd_holder == (void *)bd_may_claim)
53460 return true; /* is a partition of a device that is being partitioned */
53461 else if (whole->bd_holder != NULL)
53462 return false; /* is a partition of a held device */
53463diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
53464index ed50460..fe84385 100644
53465--- a/fs/btrfs/ctree.c
53466+++ b/fs/btrfs/ctree.c
53467@@ -1076,9 +1076,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
53468 free_extent_buffer(buf);
53469 add_root_to_dirty_list(root);
53470 } else {
53471- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
53472- parent_start = parent->start;
53473- else
53474+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
53475+ if (parent)
53476+ parent_start = parent->start;
53477+ else
53478+ parent_start = 0;
53479+ } else
53480 parent_start = 0;
53481
53482 WARN_ON(trans->transid != btrfs_header_generation(parent));
53483diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
53484index 3755109..e3d457f 100644
53485--- a/fs/btrfs/delayed-inode.c
53486+++ b/fs/btrfs/delayed-inode.c
53487@@ -458,7 +458,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
53488
53489 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
53490 {
53491- int seq = atomic_inc_return(&delayed_root->items_seq);
53492+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
53493 if ((atomic_dec_return(&delayed_root->items) <
53494 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
53495 waitqueue_active(&delayed_root->wait))
53496@@ -1377,7 +1377,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
53497 static int refs_newer(struct btrfs_delayed_root *delayed_root,
53498 int seq, int count)
53499 {
53500- int val = atomic_read(&delayed_root->items_seq);
53501+ int val = atomic_read_unchecked(&delayed_root->items_seq);
53502
53503 if (val < seq || val >= seq + count)
53504 return 1;
53505@@ -1394,7 +1394,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
53506 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
53507 return;
53508
53509- seq = atomic_read(&delayed_root->items_seq);
53510+ seq = atomic_read_unchecked(&delayed_root->items_seq);
53511
53512 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
53513 int ret;
53514diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
53515index a4b38f9..f86a509 100644
53516--- a/fs/btrfs/delayed-inode.h
53517+++ b/fs/btrfs/delayed-inode.h
53518@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
53519 */
53520 struct list_head prepare_list;
53521 atomic_t items; /* for delayed items */
53522- atomic_t items_seq; /* for delayed items */
53523+ atomic_unchecked_t items_seq; /* for delayed items */
53524 int nodes; /* for delayed nodes */
53525 wait_queue_head_t wait;
53526 };
53527@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
53528 struct btrfs_delayed_root *delayed_root)
53529 {
53530 atomic_set(&delayed_root->items, 0);
53531- atomic_set(&delayed_root->items_seq, 0);
53532+ atomic_set_unchecked(&delayed_root->items_seq, 0);
53533 delayed_root->nodes = 0;
53534 spin_lock_init(&delayed_root->lock);
53535 init_waitqueue_head(&delayed_root->wait);
53536diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
53537index 238a055..1e33cd5 100644
53538--- a/fs/btrfs/ioctl.c
53539+++ b/fs/btrfs/ioctl.c
53540@@ -3097,9 +3097,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53541 for (i = 0; i < num_types; i++) {
53542 struct btrfs_space_info *tmp;
53543
53544+ /* Don't copy in more than we allocated */
53545 if (!slot_count)
53546 break;
53547
53548+ slot_count--;
53549+
53550 info = NULL;
53551 rcu_read_lock();
53552 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
53553@@ -3121,10 +3124,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53554 memcpy(dest, &space, sizeof(space));
53555 dest++;
53556 space_args.total_spaces++;
53557- slot_count--;
53558 }
53559- if (!slot_count)
53560- break;
53561 }
53562 up_read(&info->groups_sem);
53563 }
53564diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
53565index 8eb6191..eda91e2 100644
53566--- a/fs/btrfs/super.c
53567+++ b/fs/btrfs/super.c
53568@@ -264,7 +264,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
53569 function, line, errstr);
53570 return;
53571 }
53572- ACCESS_ONCE(trans->transaction->aborted) = errno;
53573+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
53574 /* Wake up anybody who may be waiting on this transaction */
53575 wake_up(&root->fs_info->transaction_wait);
53576 wake_up(&root->fs_info->transaction_blocked_wait);
53577diff --git a/fs/buffer.c b/fs/buffer.c
53578index 4d74335..b0df7f9 100644
53579--- a/fs/buffer.c
53580+++ b/fs/buffer.c
53581@@ -3416,7 +3416,7 @@ void __init buffer_init(void)
53582 bh_cachep = kmem_cache_create("buffer_head",
53583 sizeof(struct buffer_head), 0,
53584 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
53585- SLAB_MEM_SPREAD),
53586+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
53587 NULL);
53588
53589 /*
53590diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
53591index 622f469..e8d2d55 100644
53592--- a/fs/cachefiles/bind.c
53593+++ b/fs/cachefiles/bind.c
53594@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
53595 args);
53596
53597 /* start by checking things over */
53598- ASSERT(cache->fstop_percent >= 0 &&
53599- cache->fstop_percent < cache->fcull_percent &&
53600+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
53601 cache->fcull_percent < cache->frun_percent &&
53602 cache->frun_percent < 100);
53603
53604- ASSERT(cache->bstop_percent >= 0 &&
53605- cache->bstop_percent < cache->bcull_percent &&
53606+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
53607 cache->bcull_percent < cache->brun_percent &&
53608 cache->brun_percent < 100);
53609
53610diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
53611index 0a1467b..6a53245 100644
53612--- a/fs/cachefiles/daemon.c
53613+++ b/fs/cachefiles/daemon.c
53614@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
53615 if (n > buflen)
53616 return -EMSGSIZE;
53617
53618- if (copy_to_user(_buffer, buffer, n) != 0)
53619+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
53620 return -EFAULT;
53621
53622 return n;
53623@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
53624 if (test_bit(CACHEFILES_DEAD, &cache->flags))
53625 return -EIO;
53626
53627- if (datalen < 0 || datalen > PAGE_SIZE - 1)
53628+ if (datalen > PAGE_SIZE - 1)
53629 return -EOPNOTSUPP;
53630
53631 /* drag the command string into the kernel so we can parse it */
53632@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
53633 if (args[0] != '%' || args[1] != '\0')
53634 return -EINVAL;
53635
53636- if (fstop < 0 || fstop >= cache->fcull_percent)
53637+ if (fstop >= cache->fcull_percent)
53638 return cachefiles_daemon_range_error(cache, args);
53639
53640 cache->fstop_percent = fstop;
53641@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
53642 if (args[0] != '%' || args[1] != '\0')
53643 return -EINVAL;
53644
53645- if (bstop < 0 || bstop >= cache->bcull_percent)
53646+ if (bstop >= cache->bcull_percent)
53647 return cachefiles_daemon_range_error(cache, args);
53648
53649 cache->bstop_percent = bstop;
53650diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
53651index 4938251..7e01445 100644
53652--- a/fs/cachefiles/internal.h
53653+++ b/fs/cachefiles/internal.h
53654@@ -59,7 +59,7 @@ struct cachefiles_cache {
53655 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
53656 struct rb_root active_nodes; /* active nodes (can't be culled) */
53657 rwlock_t active_lock; /* lock for active_nodes */
53658- atomic_t gravecounter; /* graveyard uniquifier */
53659+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
53660 unsigned frun_percent; /* when to stop culling (% files) */
53661 unsigned fcull_percent; /* when to start culling (% files) */
53662 unsigned fstop_percent; /* when to stop allocating (% files) */
53663@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
53664 * proc.c
53665 */
53666 #ifdef CONFIG_CACHEFILES_HISTOGRAM
53667-extern atomic_t cachefiles_lookup_histogram[HZ];
53668-extern atomic_t cachefiles_mkdir_histogram[HZ];
53669-extern atomic_t cachefiles_create_histogram[HZ];
53670+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
53671+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
53672+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
53673
53674 extern int __init cachefiles_proc_init(void);
53675 extern void cachefiles_proc_cleanup(void);
53676 static inline
53677-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
53678+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
53679 {
53680 unsigned long jif = jiffies - start_jif;
53681 if (jif >= HZ)
53682 jif = HZ - 1;
53683- atomic_inc(&histogram[jif]);
53684+ atomic_inc_unchecked(&histogram[jif]);
53685 }
53686
53687 #else
53688diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
53689index 25badd1..d70d918 100644
53690--- a/fs/cachefiles/namei.c
53691+++ b/fs/cachefiles/namei.c
53692@@ -317,7 +317,7 @@ try_again:
53693 /* first step is to make up a grave dentry in the graveyard */
53694 sprintf(nbuffer, "%08x%08x",
53695 (uint32_t) get_seconds(),
53696- (uint32_t) atomic_inc_return(&cache->gravecounter));
53697+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
53698
53699 /* do the multiway lock magic */
53700 trap = lock_rename(cache->graveyard, dir);
53701diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
53702index eccd339..4c1d995 100644
53703--- a/fs/cachefiles/proc.c
53704+++ b/fs/cachefiles/proc.c
53705@@ -14,9 +14,9 @@
53706 #include <linux/seq_file.h>
53707 #include "internal.h"
53708
53709-atomic_t cachefiles_lookup_histogram[HZ];
53710-atomic_t cachefiles_mkdir_histogram[HZ];
53711-atomic_t cachefiles_create_histogram[HZ];
53712+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
53713+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
53714+atomic_unchecked_t cachefiles_create_histogram[HZ];
53715
53716 /*
53717 * display the latency histogram
53718@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
53719 return 0;
53720 default:
53721 index = (unsigned long) v - 3;
53722- x = atomic_read(&cachefiles_lookup_histogram[index]);
53723- y = atomic_read(&cachefiles_mkdir_histogram[index]);
53724- z = atomic_read(&cachefiles_create_histogram[index]);
53725+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
53726+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
53727+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
53728 if (x == 0 && y == 0 && z == 0)
53729 return 0;
53730
53731diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
53732index ebaff36..7e3ea26 100644
53733--- a/fs/cachefiles/rdwr.c
53734+++ b/fs/cachefiles/rdwr.c
53735@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
53736 old_fs = get_fs();
53737 set_fs(KERNEL_DS);
53738 ret = file->f_op->write(
53739- file, (const void __user *) data, len, &pos);
53740+ file, (const void __force_user *) data, len, &pos);
53741 set_fs(old_fs);
53742 kunmap(page);
53743 file_end_write(file);
53744diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
53745index a40ceda..f43d17c 100644
53746--- a/fs/ceph/dir.c
53747+++ b/fs/ceph/dir.c
53748@@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
53749 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
53750 struct ceph_mds_client *mdsc = fsc->mdsc;
53751 unsigned frag = fpos_frag(ctx->pos);
53752- int off = fpos_off(ctx->pos);
53753+ unsigned int off = fpos_off(ctx->pos);
53754 int err;
53755 u32 ftype;
53756 struct ceph_mds_reply_info_parsed *rinfo;
53757diff --git a/fs/ceph/super.c b/fs/ceph/super.c
53758index 6627b26..634ec4b 100644
53759--- a/fs/ceph/super.c
53760+++ b/fs/ceph/super.c
53761@@ -839,7 +839,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
53762 /*
53763 * construct our own bdi so we can control readahead, etc.
53764 */
53765-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
53766+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
53767
53768 static int ceph_register_bdi(struct super_block *sb,
53769 struct ceph_fs_client *fsc)
53770@@ -856,7 +856,7 @@ static int ceph_register_bdi(struct super_block *sb,
53771 default_backing_dev_info.ra_pages;
53772
53773 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
53774- atomic_long_inc_return(&bdi_seq));
53775+ atomic_long_inc_return_unchecked(&bdi_seq));
53776 if (!err)
53777 sb->s_bdi = &fsc->backing_dev_info;
53778 return err;
53779diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
53780index f3ac415..3d2420c 100644
53781--- a/fs/cifs/cifs_debug.c
53782+++ b/fs/cifs/cifs_debug.c
53783@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
53784
53785 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
53786 #ifdef CONFIG_CIFS_STATS2
53787- atomic_set(&totBufAllocCount, 0);
53788- atomic_set(&totSmBufAllocCount, 0);
53789+ atomic_set_unchecked(&totBufAllocCount, 0);
53790+ atomic_set_unchecked(&totSmBufAllocCount, 0);
53791 #endif /* CONFIG_CIFS_STATS2 */
53792 spin_lock(&cifs_tcp_ses_lock);
53793 list_for_each(tmp1, &cifs_tcp_ses_list) {
53794@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
53795 tcon = list_entry(tmp3,
53796 struct cifs_tcon,
53797 tcon_list);
53798- atomic_set(&tcon->num_smbs_sent, 0);
53799+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
53800 if (server->ops->clear_stats)
53801 server->ops->clear_stats(tcon);
53802 }
53803@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
53804 smBufAllocCount.counter, cifs_min_small);
53805 #ifdef CONFIG_CIFS_STATS2
53806 seq_printf(m, "Total Large %d Small %d Allocations\n",
53807- atomic_read(&totBufAllocCount),
53808- atomic_read(&totSmBufAllocCount));
53809+ atomic_read_unchecked(&totBufAllocCount),
53810+ atomic_read_unchecked(&totSmBufAllocCount));
53811 #endif /* CONFIG_CIFS_STATS2 */
53812
53813 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
53814@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
53815 if (tcon->need_reconnect)
53816 seq_puts(m, "\tDISCONNECTED ");
53817 seq_printf(m, "\nSMBs: %d",
53818- atomic_read(&tcon->num_smbs_sent));
53819+ atomic_read_unchecked(&tcon->num_smbs_sent));
53820 if (server->ops->print_stats)
53821 server->ops->print_stats(m, tcon);
53822 }
53823diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
53824index 85ea98d..b3ed4d6 100644
53825--- a/fs/cifs/cifsfs.c
53826+++ b/fs/cifs/cifsfs.c
53827@@ -1037,7 +1037,7 @@ cifs_init_request_bufs(void)
53828 */
53829 cifs_req_cachep = kmem_cache_create("cifs_request",
53830 CIFSMaxBufSize + max_hdr_size, 0,
53831- SLAB_HWCACHE_ALIGN, NULL);
53832+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
53833 if (cifs_req_cachep == NULL)
53834 return -ENOMEM;
53835
53836@@ -1064,7 +1064,7 @@ cifs_init_request_bufs(void)
53837 efficient to alloc 1 per page off the slab compared to 17K (5page)
53838 alloc of large cifs buffers even when page debugging is on */
53839 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
53840- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
53841+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
53842 NULL);
53843 if (cifs_sm_req_cachep == NULL) {
53844 mempool_destroy(cifs_req_poolp);
53845@@ -1149,8 +1149,8 @@ init_cifs(void)
53846 atomic_set(&bufAllocCount, 0);
53847 atomic_set(&smBufAllocCount, 0);
53848 #ifdef CONFIG_CIFS_STATS2
53849- atomic_set(&totBufAllocCount, 0);
53850- atomic_set(&totSmBufAllocCount, 0);
53851+ atomic_set_unchecked(&totBufAllocCount, 0);
53852+ atomic_set_unchecked(&totSmBufAllocCount, 0);
53853 #endif /* CONFIG_CIFS_STATS2 */
53854
53855 atomic_set(&midCount, 0);
53856diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
53857index 52ca861..47f309c 100644
53858--- a/fs/cifs/cifsglob.h
53859+++ b/fs/cifs/cifsglob.h
53860@@ -756,35 +756,35 @@ struct cifs_tcon {
53861 __u16 Flags; /* optional support bits */
53862 enum statusEnum tidStatus;
53863 #ifdef CONFIG_CIFS_STATS
53864- atomic_t num_smbs_sent;
53865+ atomic_unchecked_t num_smbs_sent;
53866 union {
53867 struct {
53868- atomic_t num_writes;
53869- atomic_t num_reads;
53870- atomic_t num_flushes;
53871- atomic_t num_oplock_brks;
53872- atomic_t num_opens;
53873- atomic_t num_closes;
53874- atomic_t num_deletes;
53875- atomic_t num_mkdirs;
53876- atomic_t num_posixopens;
53877- atomic_t num_posixmkdirs;
53878- atomic_t num_rmdirs;
53879- atomic_t num_renames;
53880- atomic_t num_t2renames;
53881- atomic_t num_ffirst;
53882- atomic_t num_fnext;
53883- atomic_t num_fclose;
53884- atomic_t num_hardlinks;
53885- atomic_t num_symlinks;
53886- atomic_t num_locks;
53887- atomic_t num_acl_get;
53888- atomic_t num_acl_set;
53889+ atomic_unchecked_t num_writes;
53890+ atomic_unchecked_t num_reads;
53891+ atomic_unchecked_t num_flushes;
53892+ atomic_unchecked_t num_oplock_brks;
53893+ atomic_unchecked_t num_opens;
53894+ atomic_unchecked_t num_closes;
53895+ atomic_unchecked_t num_deletes;
53896+ atomic_unchecked_t num_mkdirs;
53897+ atomic_unchecked_t num_posixopens;
53898+ atomic_unchecked_t num_posixmkdirs;
53899+ atomic_unchecked_t num_rmdirs;
53900+ atomic_unchecked_t num_renames;
53901+ atomic_unchecked_t num_t2renames;
53902+ atomic_unchecked_t num_ffirst;
53903+ atomic_unchecked_t num_fnext;
53904+ atomic_unchecked_t num_fclose;
53905+ atomic_unchecked_t num_hardlinks;
53906+ atomic_unchecked_t num_symlinks;
53907+ atomic_unchecked_t num_locks;
53908+ atomic_unchecked_t num_acl_get;
53909+ atomic_unchecked_t num_acl_set;
53910 } cifs_stats;
53911 #ifdef CONFIG_CIFS_SMB2
53912 struct {
53913- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
53914- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
53915+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
53916+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
53917 } smb2_stats;
53918 #endif /* CONFIG_CIFS_SMB2 */
53919 } stats;
53920@@ -1096,7 +1096,7 @@ convert_delimiter(char *path, char delim)
53921 }
53922
53923 #ifdef CONFIG_CIFS_STATS
53924-#define cifs_stats_inc atomic_inc
53925+#define cifs_stats_inc atomic_inc_unchecked
53926
53927 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
53928 unsigned int bytes)
53929@@ -1461,8 +1461,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
53930 /* Various Debug counters */
53931 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
53932 #ifdef CONFIG_CIFS_STATS2
53933-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
53934-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
53935+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
53936+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
53937 #endif
53938 GLOBAL_EXTERN atomic_t smBufAllocCount;
53939 GLOBAL_EXTERN atomic_t midCount;
53940diff --git a/fs/cifs/link.c b/fs/cifs/link.c
53941index 562044f..4af6a17 100644
53942--- a/fs/cifs/link.c
53943+++ b/fs/cifs/link.c
53944@@ -638,7 +638,7 @@ symlink_exit:
53945
53946 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
53947 {
53948- char *p = nd_get_link(nd);
53949+ const char *p = nd_get_link(nd);
53950 if (!IS_ERR(p))
53951 kfree(p);
53952 }
53953diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
53954index f7d4b22..1254377 100644
53955--- a/fs/cifs/misc.c
53956+++ b/fs/cifs/misc.c
53957@@ -169,7 +169,7 @@ cifs_buf_get(void)
53958 memset(ret_buf, 0, buf_size + 3);
53959 atomic_inc(&bufAllocCount);
53960 #ifdef CONFIG_CIFS_STATS2
53961- atomic_inc(&totBufAllocCount);
53962+ atomic_inc_unchecked(&totBufAllocCount);
53963 #endif /* CONFIG_CIFS_STATS2 */
53964 }
53965
53966@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
53967 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
53968 atomic_inc(&smBufAllocCount);
53969 #ifdef CONFIG_CIFS_STATS2
53970- atomic_inc(&totSmBufAllocCount);
53971+ atomic_inc_unchecked(&totSmBufAllocCount);
53972 #endif /* CONFIG_CIFS_STATS2 */
53973
53974 }
53975diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
53976index 6094397..51e576f 100644
53977--- a/fs/cifs/smb1ops.c
53978+++ b/fs/cifs/smb1ops.c
53979@@ -590,27 +590,27 @@ static void
53980 cifs_clear_stats(struct cifs_tcon *tcon)
53981 {
53982 #ifdef CONFIG_CIFS_STATS
53983- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
53984- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
53985- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
53986- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
53987- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
53988- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
53989- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
53990- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
53991- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
53992- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
53993- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
53994- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
53995- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
53996- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
53997- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
53998- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
53999- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
54000- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
54001- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
54002- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
54003- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
54004+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
54005+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
54006+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
54007+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
54008+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
54009+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
54010+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
54011+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
54012+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
54013+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
54014+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
54015+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
54016+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
54017+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
54018+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
54019+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
54020+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
54021+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
54022+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
54023+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
54024+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
54025 #endif
54026 }
54027
54028@@ -619,36 +619,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
54029 {
54030 #ifdef CONFIG_CIFS_STATS
54031 seq_printf(m, " Oplocks breaks: %d",
54032- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
54033+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
54034 seq_printf(m, "\nReads: %d Bytes: %llu",
54035- atomic_read(&tcon->stats.cifs_stats.num_reads),
54036+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
54037 (long long)(tcon->bytes_read));
54038 seq_printf(m, "\nWrites: %d Bytes: %llu",
54039- atomic_read(&tcon->stats.cifs_stats.num_writes),
54040+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
54041 (long long)(tcon->bytes_written));
54042 seq_printf(m, "\nFlushes: %d",
54043- atomic_read(&tcon->stats.cifs_stats.num_flushes));
54044+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
54045 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
54046- atomic_read(&tcon->stats.cifs_stats.num_locks),
54047- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
54048- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
54049+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
54050+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
54051+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
54052 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
54053- atomic_read(&tcon->stats.cifs_stats.num_opens),
54054- atomic_read(&tcon->stats.cifs_stats.num_closes),
54055- atomic_read(&tcon->stats.cifs_stats.num_deletes));
54056+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
54057+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
54058+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
54059 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
54060- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
54061- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
54062+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
54063+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
54064 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
54065- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
54066- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
54067+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
54068+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
54069 seq_printf(m, "\nRenames: %d T2 Renames %d",
54070- atomic_read(&tcon->stats.cifs_stats.num_renames),
54071- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
54072+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
54073+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
54074 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
54075- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
54076- atomic_read(&tcon->stats.cifs_stats.num_fnext),
54077- atomic_read(&tcon->stats.cifs_stats.num_fclose));
54078+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
54079+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
54080+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
54081 #endif
54082 }
54083
54084diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
54085index f259e6c..ca948ff 100644
54086--- a/fs/cifs/smb2ops.c
54087+++ b/fs/cifs/smb2ops.c
54088@@ -281,8 +281,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
54089 #ifdef CONFIG_CIFS_STATS
54090 int i;
54091 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
54092- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
54093- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
54094+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
54095+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
54096 }
54097 #endif
54098 }
54099@@ -310,65 +310,65 @@ static void
54100 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
54101 {
54102 #ifdef CONFIG_CIFS_STATS
54103- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
54104- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
54105+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
54106+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
54107 seq_printf(m, "\nNegotiates: %d sent %d failed",
54108- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
54109- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
54110+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
54111+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
54112 seq_printf(m, "\nSessionSetups: %d sent %d failed",
54113- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
54114- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
54115+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
54116+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
54117 seq_printf(m, "\nLogoffs: %d sent %d failed",
54118- atomic_read(&sent[SMB2_LOGOFF_HE]),
54119- atomic_read(&failed[SMB2_LOGOFF_HE]));
54120+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
54121+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
54122 seq_printf(m, "\nTreeConnects: %d sent %d failed",
54123- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
54124- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
54125+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
54126+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
54127 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
54128- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
54129- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
54130+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
54131+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
54132 seq_printf(m, "\nCreates: %d sent %d failed",
54133- atomic_read(&sent[SMB2_CREATE_HE]),
54134- atomic_read(&failed[SMB2_CREATE_HE]));
54135+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
54136+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
54137 seq_printf(m, "\nCloses: %d sent %d failed",
54138- atomic_read(&sent[SMB2_CLOSE_HE]),
54139- atomic_read(&failed[SMB2_CLOSE_HE]));
54140+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
54141+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
54142 seq_printf(m, "\nFlushes: %d sent %d failed",
54143- atomic_read(&sent[SMB2_FLUSH_HE]),
54144- atomic_read(&failed[SMB2_FLUSH_HE]));
54145+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
54146+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
54147 seq_printf(m, "\nReads: %d sent %d failed",
54148- atomic_read(&sent[SMB2_READ_HE]),
54149- atomic_read(&failed[SMB2_READ_HE]));
54150+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
54151+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
54152 seq_printf(m, "\nWrites: %d sent %d failed",
54153- atomic_read(&sent[SMB2_WRITE_HE]),
54154- atomic_read(&failed[SMB2_WRITE_HE]));
54155+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
54156+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
54157 seq_printf(m, "\nLocks: %d sent %d failed",
54158- atomic_read(&sent[SMB2_LOCK_HE]),
54159- atomic_read(&failed[SMB2_LOCK_HE]));
54160+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
54161+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
54162 seq_printf(m, "\nIOCTLs: %d sent %d failed",
54163- atomic_read(&sent[SMB2_IOCTL_HE]),
54164- atomic_read(&failed[SMB2_IOCTL_HE]));
54165+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
54166+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
54167 seq_printf(m, "\nCancels: %d sent %d failed",
54168- atomic_read(&sent[SMB2_CANCEL_HE]),
54169- atomic_read(&failed[SMB2_CANCEL_HE]));
54170+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
54171+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
54172 seq_printf(m, "\nEchos: %d sent %d failed",
54173- atomic_read(&sent[SMB2_ECHO_HE]),
54174- atomic_read(&failed[SMB2_ECHO_HE]));
54175+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
54176+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
54177 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
54178- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
54179- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
54180+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
54181+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
54182 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
54183- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
54184- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
54185+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
54186+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
54187 seq_printf(m, "\nQueryInfos: %d sent %d failed",
54188- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
54189- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
54190+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
54191+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
54192 seq_printf(m, "\nSetInfos: %d sent %d failed",
54193- atomic_read(&sent[SMB2_SET_INFO_HE]),
54194- atomic_read(&failed[SMB2_SET_INFO_HE]));
54195+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
54196+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
54197 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
54198- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
54199- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
54200+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
54201+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
54202 #endif
54203 }
54204
54205diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
54206index abc9c28..3fdae28 100644
54207--- a/fs/cifs/smb2pdu.c
54208+++ b/fs/cifs/smb2pdu.c
54209@@ -1946,8 +1946,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
54210 default:
54211 cifs_dbg(VFS, "info level %u isn't supported\n",
54212 srch_inf->info_level);
54213- rc = -EINVAL;
54214- goto qdir_exit;
54215+ return -EINVAL;
54216 }
54217
54218 req->FileIndex = cpu_to_le32(index);
54219diff --git a/fs/coda/cache.c b/fs/coda/cache.c
54220index 1da168c..8bc7ff6 100644
54221--- a/fs/coda/cache.c
54222+++ b/fs/coda/cache.c
54223@@ -24,7 +24,7 @@
54224 #include "coda_linux.h"
54225 #include "coda_cache.h"
54226
54227-static atomic_t permission_epoch = ATOMIC_INIT(0);
54228+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
54229
54230 /* replace or extend an acl cache hit */
54231 void coda_cache_enter(struct inode *inode, int mask)
54232@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
54233 struct coda_inode_info *cii = ITOC(inode);
54234
54235 spin_lock(&cii->c_lock);
54236- cii->c_cached_epoch = atomic_read(&permission_epoch);
54237+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
54238 if (!uid_eq(cii->c_uid, current_fsuid())) {
54239 cii->c_uid = current_fsuid();
54240 cii->c_cached_perm = mask;
54241@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
54242 {
54243 struct coda_inode_info *cii = ITOC(inode);
54244 spin_lock(&cii->c_lock);
54245- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
54246+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
54247 spin_unlock(&cii->c_lock);
54248 }
54249
54250 /* remove all acl caches */
54251 void coda_cache_clear_all(struct super_block *sb)
54252 {
54253- atomic_inc(&permission_epoch);
54254+ atomic_inc_unchecked(&permission_epoch);
54255 }
54256
54257
54258@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
54259 spin_lock(&cii->c_lock);
54260 hit = (mask & cii->c_cached_perm) == mask &&
54261 uid_eq(cii->c_uid, current_fsuid()) &&
54262- cii->c_cached_epoch == atomic_read(&permission_epoch);
54263+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
54264 spin_unlock(&cii->c_lock);
54265
54266 return hit;
54267diff --git a/fs/compat.c b/fs/compat.c
54268index 6af20de..fec3fbb 100644
54269--- a/fs/compat.c
54270+++ b/fs/compat.c
54271@@ -54,7 +54,7 @@
54272 #include <asm/ioctls.h>
54273 #include "internal.h"
54274
54275-int compat_log = 1;
54276+int compat_log = 0;
54277
54278 int compat_printk(const char *fmt, ...)
54279 {
54280@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
54281
54282 set_fs(KERNEL_DS);
54283 /* The __user pointer cast is valid because of the set_fs() */
54284- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
54285+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
54286 set_fs(oldfs);
54287 /* truncating is ok because it's a user address */
54288 if (!ret)
54289@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
54290 goto out;
54291
54292 ret = -EINVAL;
54293- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
54294+ if (nr_segs > UIO_MAXIOV)
54295 goto out;
54296 if (nr_segs > fast_segs) {
54297 ret = -ENOMEM;
54298@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
54299 struct compat_readdir_callback {
54300 struct dir_context ctx;
54301 struct compat_old_linux_dirent __user *dirent;
54302+ struct file * file;
54303 int result;
54304 };
54305
54306@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
54307 buf->result = -EOVERFLOW;
54308 return -EOVERFLOW;
54309 }
54310+
54311+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54312+ return 0;
54313+
54314 buf->result++;
54315 dirent = buf->dirent;
54316 if (!access_ok(VERIFY_WRITE, dirent,
54317@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
54318 if (!f.file)
54319 return -EBADF;
54320
54321+ buf.file = f.file;
54322 error = iterate_dir(f.file, &buf.ctx);
54323 if (buf.result)
54324 error = buf.result;
54325@@ -901,6 +907,7 @@ struct compat_getdents_callback {
54326 struct dir_context ctx;
54327 struct compat_linux_dirent __user *current_dir;
54328 struct compat_linux_dirent __user *previous;
54329+ struct file * file;
54330 int count;
54331 int error;
54332 };
54333@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
54334 buf->error = -EOVERFLOW;
54335 return -EOVERFLOW;
54336 }
54337+
54338+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54339+ return 0;
54340+
54341 dirent = buf->previous;
54342 if (dirent) {
54343 if (__put_user(offset, &dirent->d_off))
54344@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
54345 if (!f.file)
54346 return -EBADF;
54347
54348+ buf.file = f.file;
54349 error = iterate_dir(f.file, &buf.ctx);
54350 if (error >= 0)
54351 error = buf.error;
54352@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
54353 struct dir_context ctx;
54354 struct linux_dirent64 __user *current_dir;
54355 struct linux_dirent64 __user *previous;
54356+ struct file * file;
54357 int count;
54358 int error;
54359 };
54360@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
54361 buf->error = -EINVAL; /* only used if we fail.. */
54362 if (reclen > buf->count)
54363 return -EINVAL;
54364+
54365+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54366+ return 0;
54367+
54368 dirent = buf->previous;
54369
54370 if (dirent) {
54371@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
54372 if (!f.file)
54373 return -EBADF;
54374
54375+ buf.file = f.file;
54376 error = iterate_dir(f.file, &buf.ctx);
54377 if (error >= 0)
54378 error = buf.error;
54379diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
54380index a81147e..20bf2b5 100644
54381--- a/fs/compat_binfmt_elf.c
54382+++ b/fs/compat_binfmt_elf.c
54383@@ -30,11 +30,13 @@
54384 #undef elf_phdr
54385 #undef elf_shdr
54386 #undef elf_note
54387+#undef elf_dyn
54388 #undef elf_addr_t
54389 #define elfhdr elf32_hdr
54390 #define elf_phdr elf32_phdr
54391 #define elf_shdr elf32_shdr
54392 #define elf_note elf32_note
54393+#define elf_dyn Elf32_Dyn
54394 #define elf_addr_t Elf32_Addr
54395
54396 /*
54397diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
54398index 5d19acf..9ab093b 100644
54399--- a/fs/compat_ioctl.c
54400+++ b/fs/compat_ioctl.c
54401@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
54402 return -EFAULT;
54403 if (__get_user(udata, &ss32->iomem_base))
54404 return -EFAULT;
54405- ss.iomem_base = compat_ptr(udata);
54406+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
54407 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
54408 __get_user(ss.port_high, &ss32->port_high))
54409 return -EFAULT;
54410@@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
54411 for (i = 0; i < nmsgs; i++) {
54412 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
54413 return -EFAULT;
54414- if (get_user(datap, &umsgs[i].buf) ||
54415- put_user(compat_ptr(datap), &tmsgs[i].buf))
54416+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
54417+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
54418 return -EFAULT;
54419 }
54420 return sys_ioctl(fd, cmd, (unsigned long)tdata);
54421@@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
54422 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
54423 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
54424 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
54425- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54426+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54427 return -EFAULT;
54428
54429 return ioctl_preallocate(file, p);
54430@@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
54431 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
54432 {
54433 unsigned int a, b;
54434- a = *(unsigned int *)p;
54435- b = *(unsigned int *)q;
54436+ a = *(const unsigned int *)p;
54437+ b = *(const unsigned int *)q;
54438 if (a > b)
54439 return 1;
54440 if (a < b)
54441diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
54442index 277bd1b..f312c9e 100644
54443--- a/fs/configfs/dir.c
54444+++ b/fs/configfs/dir.c
54445@@ -1546,7 +1546,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54446 }
54447 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
54448 struct configfs_dirent *next;
54449- const char *name;
54450+ const unsigned char * name;
54451+ char d_name[sizeof(next->s_dentry->d_iname)];
54452 int len;
54453 struct inode *inode = NULL;
54454
54455@@ -1555,7 +1556,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54456 continue;
54457
54458 name = configfs_get_name(next);
54459- len = strlen(name);
54460+ if (next->s_dentry && name == next->s_dentry->d_iname) {
54461+ len = next->s_dentry->d_name.len;
54462+ memcpy(d_name, name, len);
54463+ name = d_name;
54464+ } else
54465+ len = strlen(name);
54466
54467 /*
54468 * We'll have a dentry and an inode for
54469diff --git a/fs/coredump.c b/fs/coredump.c
54470index 72f816d..1ba8eff 100644
54471--- a/fs/coredump.c
54472+++ b/fs/coredump.c
54473@@ -433,8 +433,8 @@ static void wait_for_dump_helpers(struct file *file)
54474 struct pipe_inode_info *pipe = file->private_data;
54475
54476 pipe_lock(pipe);
54477- pipe->readers++;
54478- pipe->writers--;
54479+ atomic_inc(&pipe->readers);
54480+ atomic_dec(&pipe->writers);
54481 wake_up_interruptible_sync(&pipe->wait);
54482 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54483 pipe_unlock(pipe);
54484@@ -443,11 +443,11 @@ static void wait_for_dump_helpers(struct file *file)
54485 * We actually want wait_event_freezable() but then we need
54486 * to clear TIF_SIGPENDING and improve dump_interrupted().
54487 */
54488- wait_event_interruptible(pipe->wait, pipe->readers == 1);
54489+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
54490
54491 pipe_lock(pipe);
54492- pipe->readers--;
54493- pipe->writers++;
54494+ atomic_dec(&pipe->readers);
54495+ atomic_inc(&pipe->writers);
54496 pipe_unlock(pipe);
54497 }
54498
54499@@ -494,7 +494,8 @@ void do_coredump(siginfo_t *siginfo)
54500 struct files_struct *displaced;
54501 bool need_nonrelative = false;
54502 bool core_dumped = false;
54503- static atomic_t core_dump_count = ATOMIC_INIT(0);
54504+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
54505+ long signr = siginfo->si_signo;
54506 struct coredump_params cprm = {
54507 .siginfo = siginfo,
54508 .regs = signal_pt_regs(),
54509@@ -507,7 +508,10 @@ void do_coredump(siginfo_t *siginfo)
54510 .mm_flags = mm->flags,
54511 };
54512
54513- audit_core_dumps(siginfo->si_signo);
54514+ audit_core_dumps(signr);
54515+
54516+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
54517+ gr_handle_brute_attach(cprm.mm_flags);
54518
54519 binfmt = mm->binfmt;
54520 if (!binfmt || !binfmt->core_dump)
54521@@ -531,7 +535,7 @@ void do_coredump(siginfo_t *siginfo)
54522 need_nonrelative = true;
54523 }
54524
54525- retval = coredump_wait(siginfo->si_signo, &core_state);
54526+ retval = coredump_wait(signr, &core_state);
54527 if (retval < 0)
54528 goto fail_creds;
54529
54530@@ -574,7 +578,7 @@ void do_coredump(siginfo_t *siginfo)
54531 }
54532 cprm.limit = RLIM_INFINITY;
54533
54534- dump_count = atomic_inc_return(&core_dump_count);
54535+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
54536 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
54537 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
54538 task_tgid_vnr(current), current->comm);
54539@@ -606,6 +610,8 @@ void do_coredump(siginfo_t *siginfo)
54540 } else {
54541 struct inode *inode;
54542
54543+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
54544+
54545 if (cprm.limit < binfmt->min_coredump)
54546 goto fail_unlock;
54547
54548@@ -664,7 +670,7 @@ close_fail:
54549 filp_close(cprm.file, NULL);
54550 fail_dropcount:
54551 if (ispipe)
54552- atomic_dec(&core_dump_count);
54553+ atomic_dec_unchecked(&core_dump_count);
54554 fail_unlock:
54555 kfree(cn.corename);
54556 coredump_finish(mm, core_dumped);
54557@@ -684,7 +690,7 @@ int dump_write(struct file *file, const void *addr, int nr)
54558 {
54559 return !dump_interrupted() &&
54560 access_ok(VERIFY_READ, addr, nr) &&
54561- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
54562+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
54563 }
54564 EXPORT_SYMBOL(dump_write);
54565
54566diff --git a/fs/dcache.c b/fs/dcache.c
54567index b949af8..5978926 100644
54568--- a/fs/dcache.c
54569+++ b/fs/dcache.c
54570@@ -3073,7 +3073,8 @@ void __init vfs_caches_init(unsigned long mempages)
54571 mempages -= reserve;
54572
54573 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
54574- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
54575+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
54576+ SLAB_NO_SANITIZE, NULL);
54577
54578 dcache_init();
54579 inode_init();
54580diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
54581index c7c83ff..bda9461 100644
54582--- a/fs/debugfs/inode.c
54583+++ b/fs/debugfs/inode.c
54584@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
54585 */
54586 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
54587 {
54588+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
54589+ return __create_file(name, S_IFDIR | S_IRWXU,
54590+#else
54591 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
54592+#endif
54593 parent, NULL, NULL);
54594 }
54595 EXPORT_SYMBOL_GPL(debugfs_create_dir);
54596diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
54597index 67e9b63..a9adb68 100644
54598--- a/fs/ecryptfs/inode.c
54599+++ b/fs/ecryptfs/inode.c
54600@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
54601 old_fs = get_fs();
54602 set_fs(get_ds());
54603 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
54604- (char __user *)lower_buf,
54605+ (char __force_user *)lower_buf,
54606 PATH_MAX);
54607 set_fs(old_fs);
54608 if (rc < 0)
54609@@ -706,7 +706,7 @@ out:
54610 static void
54611 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
54612 {
54613- char *buf = nd_get_link(nd);
54614+ const char *buf = nd_get_link(nd);
54615 if (!IS_ERR(buf)) {
54616 /* Free the char* */
54617 kfree(buf);
54618diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
54619index e4141f2..d8263e8 100644
54620--- a/fs/ecryptfs/miscdev.c
54621+++ b/fs/ecryptfs/miscdev.c
54622@@ -304,7 +304,7 @@ check_list:
54623 goto out_unlock_msg_ctx;
54624 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
54625 if (msg_ctx->msg) {
54626- if (copy_to_user(&buf[i], packet_length, packet_length_size))
54627+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
54628 goto out_unlock_msg_ctx;
54629 i += packet_length_size;
54630 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
54631diff --git a/fs/exec.c b/fs/exec.c
54632index fd774c7..1c6a7bf 100644
54633--- a/fs/exec.c
54634+++ b/fs/exec.c
54635@@ -55,8 +55,20 @@
54636 #include <linux/pipe_fs_i.h>
54637 #include <linux/oom.h>
54638 #include <linux/compat.h>
54639+#include <linux/random.h>
54640+#include <linux/seq_file.h>
54641+#include <linux/coredump.h>
54642+#include <linux/mman.h>
54643+
54644+#ifdef CONFIG_PAX_REFCOUNT
54645+#include <linux/kallsyms.h>
54646+#include <linux/kdebug.h>
54647+#endif
54648+
54649+#include <trace/events/fs.h>
54650
54651 #include <asm/uaccess.h>
54652+#include <asm/sections.h>
54653 #include <asm/mmu_context.h>
54654 #include <asm/tlb.h>
54655
54656@@ -66,17 +78,32 @@
54657
54658 #include <trace/events/sched.h>
54659
54660+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
54661+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
54662+{
54663+ 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");
54664+}
54665+#endif
54666+
54667+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
54668+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
54669+EXPORT_SYMBOL(pax_set_initial_flags_func);
54670+#endif
54671+
54672 int suid_dumpable = 0;
54673
54674 static LIST_HEAD(formats);
54675 static DEFINE_RWLOCK(binfmt_lock);
54676
54677+extern int gr_process_kernel_exec_ban(void);
54678+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
54679+
54680 void __register_binfmt(struct linux_binfmt * fmt, int insert)
54681 {
54682 BUG_ON(!fmt);
54683 write_lock(&binfmt_lock);
54684- insert ? list_add(&fmt->lh, &formats) :
54685- list_add_tail(&fmt->lh, &formats);
54686+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
54687+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
54688 write_unlock(&binfmt_lock);
54689 }
54690
54691@@ -85,7 +112,7 @@ EXPORT_SYMBOL(__register_binfmt);
54692 void unregister_binfmt(struct linux_binfmt * fmt)
54693 {
54694 write_lock(&binfmt_lock);
54695- list_del(&fmt->lh);
54696+ pax_list_del((struct list_head *)&fmt->lh);
54697 write_unlock(&binfmt_lock);
54698 }
54699
54700@@ -181,18 +208,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
54701 int write)
54702 {
54703 struct page *page;
54704- int ret;
54705
54706-#ifdef CONFIG_STACK_GROWSUP
54707- if (write) {
54708- ret = expand_downwards(bprm->vma, pos);
54709- if (ret < 0)
54710- return NULL;
54711- }
54712-#endif
54713- ret = get_user_pages(current, bprm->mm, pos,
54714- 1, write, 1, &page, NULL);
54715- if (ret <= 0)
54716+ if (0 > expand_downwards(bprm->vma, pos))
54717+ return NULL;
54718+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
54719 return NULL;
54720
54721 if (write) {
54722@@ -208,6 +227,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
54723 if (size <= ARG_MAX)
54724 return page;
54725
54726+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54727+ // only allow 512KB for argv+env on suid/sgid binaries
54728+ // to prevent easy ASLR exhaustion
54729+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
54730+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
54731+ (size > (512 * 1024))) {
54732+ put_page(page);
54733+ return NULL;
54734+ }
54735+#endif
54736+
54737 /*
54738 * Limit to 1/4-th the stack size for the argv+env strings.
54739 * This ensures that:
54740@@ -267,6 +297,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
54741 vma->vm_end = STACK_TOP_MAX;
54742 vma->vm_start = vma->vm_end - PAGE_SIZE;
54743 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
54744+
54745+#ifdef CONFIG_PAX_SEGMEXEC
54746+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
54747+#endif
54748+
54749 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
54750 INIT_LIST_HEAD(&vma->anon_vma_chain);
54751
54752@@ -277,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
54753 mm->stack_vm = mm->total_vm = 1;
54754 up_write(&mm->mmap_sem);
54755 bprm->p = vma->vm_end - sizeof(void *);
54756+
54757+#ifdef CONFIG_PAX_RANDUSTACK
54758+ if (randomize_va_space)
54759+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
54760+#endif
54761+
54762 return 0;
54763 err:
54764 up_write(&mm->mmap_sem);
54765@@ -397,7 +438,7 @@ struct user_arg_ptr {
54766 } ptr;
54767 };
54768
54769-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54770+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54771 {
54772 const char __user *native;
54773
54774@@ -406,14 +447,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54775 compat_uptr_t compat;
54776
54777 if (get_user(compat, argv.ptr.compat + nr))
54778- return ERR_PTR(-EFAULT);
54779+ return (const char __force_user *)ERR_PTR(-EFAULT);
54780
54781 return compat_ptr(compat);
54782 }
54783 #endif
54784
54785 if (get_user(native, argv.ptr.native + nr))
54786- return ERR_PTR(-EFAULT);
54787+ return (const char __force_user *)ERR_PTR(-EFAULT);
54788
54789 return native;
54790 }
54791@@ -432,7 +473,7 @@ static int count(struct user_arg_ptr argv, int max)
54792 if (!p)
54793 break;
54794
54795- if (IS_ERR(p))
54796+ if (IS_ERR((const char __force_kernel *)p))
54797 return -EFAULT;
54798
54799 if (i >= max)
54800@@ -467,7 +508,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
54801
54802 ret = -EFAULT;
54803 str = get_user_arg_ptr(argv, argc);
54804- if (IS_ERR(str))
54805+ if (IS_ERR((const char __force_kernel *)str))
54806 goto out;
54807
54808 len = strnlen_user(str, MAX_ARG_STRLEN);
54809@@ -549,7 +590,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
54810 int r;
54811 mm_segment_t oldfs = get_fs();
54812 struct user_arg_ptr argv = {
54813- .ptr.native = (const char __user *const __user *)__argv,
54814+ .ptr.native = (const char __force_user * const __force_user *)__argv,
54815 };
54816
54817 set_fs(KERNEL_DS);
54818@@ -584,7 +625,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
54819 unsigned long new_end = old_end - shift;
54820 struct mmu_gather tlb;
54821
54822- BUG_ON(new_start > new_end);
54823+ if (new_start >= new_end || new_start < mmap_min_addr)
54824+ return -ENOMEM;
54825
54826 /*
54827 * ensure there are no vmas between where we want to go
54828@@ -593,6 +635,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
54829 if (vma != find_vma(mm, new_start))
54830 return -EFAULT;
54831
54832+#ifdef CONFIG_PAX_SEGMEXEC
54833+ BUG_ON(pax_find_mirror_vma(vma));
54834+#endif
54835+
54836 /*
54837 * cover the whole range: [new_start, old_end)
54838 */
54839@@ -673,10 +719,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
54840 stack_top = arch_align_stack(stack_top);
54841 stack_top = PAGE_ALIGN(stack_top);
54842
54843- if (unlikely(stack_top < mmap_min_addr) ||
54844- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
54845- return -ENOMEM;
54846-
54847 stack_shift = vma->vm_end - stack_top;
54848
54849 bprm->p -= stack_shift;
54850@@ -688,8 +730,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
54851 bprm->exec -= stack_shift;
54852
54853 down_write(&mm->mmap_sem);
54854+
54855+ /* Move stack pages down in memory. */
54856+ if (stack_shift) {
54857+ ret = shift_arg_pages(vma, stack_shift);
54858+ if (ret)
54859+ goto out_unlock;
54860+ }
54861+
54862 vm_flags = VM_STACK_FLAGS;
54863
54864+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
54865+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
54866+ vm_flags &= ~VM_EXEC;
54867+
54868+#ifdef CONFIG_PAX_MPROTECT
54869+ if (mm->pax_flags & MF_PAX_MPROTECT)
54870+ vm_flags &= ~VM_MAYEXEC;
54871+#endif
54872+
54873+ }
54874+#endif
54875+
54876 /*
54877 * Adjust stack execute permissions; explicitly enable for
54878 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
54879@@ -708,13 +770,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
54880 goto out_unlock;
54881 BUG_ON(prev != vma);
54882
54883- /* Move stack pages down in memory. */
54884- if (stack_shift) {
54885- ret = shift_arg_pages(vma, stack_shift);
54886- if (ret)
54887- goto out_unlock;
54888- }
54889-
54890 /* mprotect_fixup is overkill to remove the temporary stack flags */
54891 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
54892
54893@@ -738,6 +793,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
54894 #endif
54895 current->mm->start_stack = bprm->p;
54896 ret = expand_stack(vma, stack_base);
54897+
54898+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
54899+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
54900+ unsigned long size;
54901+ vm_flags_t vm_flags;
54902+
54903+ size = STACK_TOP - vma->vm_end;
54904+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
54905+
54906+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
54907+
54908+#ifdef CONFIG_X86
54909+ if (!ret) {
54910+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
54911+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
54912+ }
54913+#endif
54914+
54915+ }
54916+#endif
54917+
54918 if (ret)
54919 ret = -EFAULT;
54920
54921@@ -774,6 +850,8 @@ struct file *open_exec(const char *name)
54922
54923 fsnotify_open(file);
54924
54925+ trace_open_exec(name);
54926+
54927 err = deny_write_access(file);
54928 if (err)
54929 goto exit;
54930@@ -797,7 +875,7 @@ int kernel_read(struct file *file, loff_t offset,
54931 old_fs = get_fs();
54932 set_fs(get_ds());
54933 /* The cast to a user pointer is valid due to the set_fs() */
54934- result = vfs_read(file, (void __user *)addr, count, &pos);
54935+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
54936 set_fs(old_fs);
54937 return result;
54938 }
54939@@ -1253,7 +1331,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
54940 }
54941 rcu_read_unlock();
54942
54943- if (p->fs->users > n_fs) {
54944+ if (atomic_read(&p->fs->users) > n_fs) {
54945 bprm->unsafe |= LSM_UNSAFE_SHARE;
54946 } else {
54947 res = -EAGAIN;
54948@@ -1453,6 +1531,31 @@ int search_binary_handler(struct linux_binprm *bprm)
54949
54950 EXPORT_SYMBOL(search_binary_handler);
54951
54952+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54953+static DEFINE_PER_CPU(u64, exec_counter);
54954+static int __init init_exec_counters(void)
54955+{
54956+ unsigned int cpu;
54957+
54958+ for_each_possible_cpu(cpu) {
54959+ per_cpu(exec_counter, cpu) = (u64)cpu;
54960+ }
54961+
54962+ return 0;
54963+}
54964+early_initcall(init_exec_counters);
54965+static inline void increment_exec_counter(void)
54966+{
54967+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
54968+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
54969+}
54970+#else
54971+static inline void increment_exec_counter(void) {}
54972+#endif
54973+
54974+extern void gr_handle_exec_args(struct linux_binprm *bprm,
54975+ struct user_arg_ptr argv);
54976+
54977 /*
54978 * sys_execve() executes a new program.
54979 */
54980@@ -1460,12 +1563,19 @@ static int do_execve_common(const char *filename,
54981 struct user_arg_ptr argv,
54982 struct user_arg_ptr envp)
54983 {
54984+#ifdef CONFIG_GRKERNSEC
54985+ struct file *old_exec_file;
54986+ struct acl_subject_label *old_acl;
54987+ struct rlimit old_rlim[RLIM_NLIMITS];
54988+#endif
54989 struct linux_binprm *bprm;
54990 struct file *file;
54991 struct files_struct *displaced;
54992 bool clear_in_exec;
54993 int retval;
54994
54995+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
54996+
54997 /*
54998 * We move the actual failure in case of RLIMIT_NPROC excess from
54999 * set*uid() to execve() because too many poorly written programs
55000@@ -1506,12 +1616,22 @@ static int do_execve_common(const char *filename,
55001 if (IS_ERR(file))
55002 goto out_unmark;
55003
55004+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
55005+ retval = -EPERM;
55006+ goto out_file;
55007+ }
55008+
55009 sched_exec();
55010
55011 bprm->file = file;
55012 bprm->filename = filename;
55013 bprm->interp = filename;
55014
55015+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
55016+ retval = -EACCES;
55017+ goto out_file;
55018+ }
55019+
55020 retval = bprm_mm_init(bprm);
55021 if (retval)
55022 goto out_file;
55023@@ -1528,24 +1648,70 @@ static int do_execve_common(const char *filename,
55024 if (retval < 0)
55025 goto out;
55026
55027+#ifdef CONFIG_GRKERNSEC
55028+ old_acl = current->acl;
55029+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
55030+ old_exec_file = current->exec_file;
55031+ get_file(file);
55032+ current->exec_file = file;
55033+#endif
55034+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55035+ /* limit suid stack to 8MB
55036+ * we saved the old limits above and will restore them if this exec fails
55037+ */
55038+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
55039+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
55040+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
55041+#endif
55042+
55043+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
55044+ retval = -EPERM;
55045+ goto out_fail;
55046+ }
55047+
55048+ if (!gr_tpe_allow(file)) {
55049+ retval = -EACCES;
55050+ goto out_fail;
55051+ }
55052+
55053+ if (gr_check_crash_exec(file)) {
55054+ retval = -EACCES;
55055+ goto out_fail;
55056+ }
55057+
55058+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
55059+ bprm->unsafe);
55060+ if (retval < 0)
55061+ goto out_fail;
55062+
55063 retval = copy_strings_kernel(1, &bprm->filename, bprm);
55064 if (retval < 0)
55065- goto out;
55066+ goto out_fail;
55067
55068 bprm->exec = bprm->p;
55069 retval = copy_strings(bprm->envc, envp, bprm);
55070 if (retval < 0)
55071- goto out;
55072+ goto out_fail;
55073
55074 retval = copy_strings(bprm->argc, argv, bprm);
55075 if (retval < 0)
55076- goto out;
55077+ goto out_fail;
55078+
55079+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
55080+
55081+ gr_handle_exec_args(bprm, argv);
55082
55083 retval = search_binary_handler(bprm);
55084 if (retval < 0)
55085- goto out;
55086+ goto out_fail;
55087+#ifdef CONFIG_GRKERNSEC
55088+ if (old_exec_file)
55089+ fput(old_exec_file);
55090+#endif
55091
55092 /* execve succeeded */
55093+
55094+ increment_exec_counter();
55095 current->fs->in_exec = 0;
55096 current->in_execve = 0;
55097 acct_update_integrals(current);
55098@@ -1554,6 +1720,14 @@ static int do_execve_common(const char *filename,
55099 put_files_struct(displaced);
55100 return retval;
55101
55102+out_fail:
55103+#ifdef CONFIG_GRKERNSEC
55104+ current->acl = old_acl;
55105+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
55106+ fput(current->exec_file);
55107+ current->exec_file = old_exec_file;
55108+#endif
55109+
55110 out:
55111 if (bprm->mm) {
55112 acct_arg_size(bprm, 0);
55113@@ -1702,3 +1876,287 @@ asmlinkage long compat_sys_execve(const char __user * filename,
55114 return error;
55115 }
55116 #endif
55117+
55118+int pax_check_flags(unsigned long *flags)
55119+{
55120+ int retval = 0;
55121+
55122+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
55123+ if (*flags & MF_PAX_SEGMEXEC)
55124+ {
55125+ *flags &= ~MF_PAX_SEGMEXEC;
55126+ retval = -EINVAL;
55127+ }
55128+#endif
55129+
55130+ if ((*flags & MF_PAX_PAGEEXEC)
55131+
55132+#ifdef CONFIG_PAX_PAGEEXEC
55133+ && (*flags & MF_PAX_SEGMEXEC)
55134+#endif
55135+
55136+ )
55137+ {
55138+ *flags &= ~MF_PAX_PAGEEXEC;
55139+ retval = -EINVAL;
55140+ }
55141+
55142+ if ((*flags & MF_PAX_MPROTECT)
55143+
55144+#ifdef CONFIG_PAX_MPROTECT
55145+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
55146+#endif
55147+
55148+ )
55149+ {
55150+ *flags &= ~MF_PAX_MPROTECT;
55151+ retval = -EINVAL;
55152+ }
55153+
55154+ if ((*flags & MF_PAX_EMUTRAMP)
55155+
55156+#ifdef CONFIG_PAX_EMUTRAMP
55157+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
55158+#endif
55159+
55160+ )
55161+ {
55162+ *flags &= ~MF_PAX_EMUTRAMP;
55163+ retval = -EINVAL;
55164+ }
55165+
55166+ return retval;
55167+}
55168+
55169+EXPORT_SYMBOL(pax_check_flags);
55170+
55171+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55172+char *pax_get_path(const struct path *path, char *buf, int buflen)
55173+{
55174+ char *pathname = d_path(path, buf, buflen);
55175+
55176+ if (IS_ERR(pathname))
55177+ goto toolong;
55178+
55179+ pathname = mangle_path(buf, pathname, "\t\n\\");
55180+ if (!pathname)
55181+ goto toolong;
55182+
55183+ *pathname = 0;
55184+ return buf;
55185+
55186+toolong:
55187+ return "<path too long>";
55188+}
55189+EXPORT_SYMBOL(pax_get_path);
55190+
55191+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
55192+{
55193+ struct task_struct *tsk = current;
55194+ struct mm_struct *mm = current->mm;
55195+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
55196+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
55197+ char *path_exec = NULL;
55198+ char *path_fault = NULL;
55199+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
55200+ siginfo_t info = { };
55201+
55202+ if (buffer_exec && buffer_fault) {
55203+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
55204+
55205+ down_read(&mm->mmap_sem);
55206+ vma = mm->mmap;
55207+ while (vma && (!vma_exec || !vma_fault)) {
55208+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
55209+ vma_exec = vma;
55210+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
55211+ vma_fault = vma;
55212+ vma = vma->vm_next;
55213+ }
55214+ if (vma_exec)
55215+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
55216+ if (vma_fault) {
55217+ start = vma_fault->vm_start;
55218+ end = vma_fault->vm_end;
55219+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
55220+ if (vma_fault->vm_file)
55221+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
55222+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
55223+ path_fault = "<heap>";
55224+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
55225+ path_fault = "<stack>";
55226+ else
55227+ path_fault = "<anonymous mapping>";
55228+ }
55229+ up_read(&mm->mmap_sem);
55230+ }
55231+ if (tsk->signal->curr_ip)
55232+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
55233+ else
55234+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
55235+ 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),
55236+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
55237+ free_page((unsigned long)buffer_exec);
55238+ free_page((unsigned long)buffer_fault);
55239+ pax_report_insns(regs, pc, sp);
55240+ info.si_signo = SIGKILL;
55241+ info.si_errno = 0;
55242+ info.si_code = SI_KERNEL;
55243+ info.si_pid = 0;
55244+ info.si_uid = 0;
55245+ do_coredump(&info);
55246+}
55247+#endif
55248+
55249+#ifdef CONFIG_PAX_REFCOUNT
55250+void pax_report_refcount_overflow(struct pt_regs *regs)
55251+{
55252+ if (current->signal->curr_ip)
55253+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
55254+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
55255+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55256+ else
55257+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
55258+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55259+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
55260+ preempt_disable();
55261+ show_regs(regs);
55262+ preempt_enable();
55263+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
55264+}
55265+#endif
55266+
55267+#ifdef CONFIG_PAX_USERCOPY
55268+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
55269+static noinline int check_stack_object(const void *obj, unsigned long len)
55270+{
55271+ const void * const stack = task_stack_page(current);
55272+ const void * const stackend = stack + THREAD_SIZE;
55273+
55274+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55275+ const void *frame = NULL;
55276+ const void *oldframe;
55277+#endif
55278+
55279+ if (obj + len < obj)
55280+ return -1;
55281+
55282+ if (obj + len <= stack || stackend <= obj)
55283+ return 0;
55284+
55285+ if (obj < stack || stackend < obj + len)
55286+ return -1;
55287+
55288+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55289+ oldframe = __builtin_frame_address(1);
55290+ if (oldframe)
55291+ frame = __builtin_frame_address(2);
55292+ /*
55293+ low ----------------------------------------------> high
55294+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
55295+ ^----------------^
55296+ allow copies only within here
55297+ */
55298+ while (stack <= frame && frame < stackend) {
55299+ /* if obj + len extends past the last frame, this
55300+ check won't pass and the next frame will be 0,
55301+ causing us to bail out and correctly report
55302+ the copy as invalid
55303+ */
55304+ if (obj + len <= frame)
55305+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
55306+ oldframe = frame;
55307+ frame = *(const void * const *)frame;
55308+ }
55309+ return -1;
55310+#else
55311+ return 1;
55312+#endif
55313+}
55314+
55315+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
55316+{
55317+ if (current->signal->curr_ip)
55318+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55319+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55320+ else
55321+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55322+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55323+ dump_stack();
55324+ gr_handle_kernel_exploit();
55325+ do_group_exit(SIGKILL);
55326+}
55327+#endif
55328+
55329+#ifdef CONFIG_PAX_USERCOPY
55330+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
55331+{
55332+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
55333+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
55334+#ifdef CONFIG_MODULES
55335+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
55336+#else
55337+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
55338+#endif
55339+
55340+#else
55341+ unsigned long textlow = (unsigned long)_stext;
55342+ unsigned long texthigh = (unsigned long)_etext;
55343+#endif
55344+
55345+ if (high <= textlow || low > texthigh)
55346+ return false;
55347+ else
55348+ return true;
55349+}
55350+#endif
55351+
55352+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
55353+{
55354+
55355+#ifdef CONFIG_PAX_USERCOPY
55356+ const char *type;
55357+
55358+ if (!n)
55359+ return;
55360+
55361+ type = check_heap_object(ptr, n);
55362+ if (!type) {
55363+ int ret = check_stack_object(ptr, n);
55364+ if (ret == 1 || ret == 2)
55365+ return;
55366+ if (ret == 0) {
55367+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
55368+ type = "<kernel text>";
55369+ else
55370+ return;
55371+ } else
55372+ type = "<process stack>";
55373+ }
55374+
55375+ pax_report_usercopy(ptr, n, to_user, type);
55376+#endif
55377+
55378+}
55379+EXPORT_SYMBOL(__check_object_size);
55380+
55381+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
55382+void pax_track_stack(void)
55383+{
55384+ unsigned long sp = (unsigned long)&sp;
55385+ if (sp < current_thread_info()->lowest_stack &&
55386+ sp > (unsigned long)task_stack_page(current))
55387+ current_thread_info()->lowest_stack = sp;
55388+}
55389+EXPORT_SYMBOL(pax_track_stack);
55390+#endif
55391+
55392+#ifdef CONFIG_PAX_SIZE_OVERFLOW
55393+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
55394+{
55395+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
55396+ dump_stack();
55397+ do_group_exit(SIGKILL);
55398+}
55399+EXPORT_SYMBOL(report_size_overflow);
55400+#endif
55401diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
55402index 9f9992b..8b59411 100644
55403--- a/fs/ext2/balloc.c
55404+++ b/fs/ext2/balloc.c
55405@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
55406
55407 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55408 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55409- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55410+ if (free_blocks < root_blocks + 1 &&
55411 !uid_eq(sbi->s_resuid, current_fsuid()) &&
55412 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55413- !in_group_p (sbi->s_resgid))) {
55414+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55415 return 0;
55416 }
55417 return 1;
55418diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
55419index 22548f5..41521d8 100644
55420--- a/fs/ext3/balloc.c
55421+++ b/fs/ext3/balloc.c
55422@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
55423
55424 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55425 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55426- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55427+ if (free_blocks < root_blocks + 1 &&
55428 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
55429 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55430- !in_group_p (sbi->s_resgid))) {
55431+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55432 return 0;
55433 }
55434 return 1;
55435diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
55436index ddd715e..c772f88 100644
55437--- a/fs/ext4/balloc.c
55438+++ b/fs/ext4/balloc.c
55439@@ -528,8 +528,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
55440 /* Hm, nope. Are (enough) root reserved clusters available? */
55441 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
55442 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
55443- capable(CAP_SYS_RESOURCE) ||
55444- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
55445+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
55446+ capable_nolog(CAP_SYS_RESOURCE)) {
55447
55448 if (free_clusters >= (nclusters + dirty_clusters +
55449 resv_clusters))
55450diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
55451index 0ab26fb..b6ecb39 100644
55452--- a/fs/ext4/ext4.h
55453+++ b/fs/ext4/ext4.h
55454@@ -1247,19 +1247,19 @@ struct ext4_sb_info {
55455 unsigned long s_mb_last_start;
55456
55457 /* stats for buddy allocator */
55458- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
55459- atomic_t s_bal_success; /* we found long enough chunks */
55460- atomic_t s_bal_allocated; /* in blocks */
55461- atomic_t s_bal_ex_scanned; /* total extents scanned */
55462- atomic_t s_bal_goals; /* goal hits */
55463- atomic_t s_bal_breaks; /* too long searches */
55464- atomic_t s_bal_2orders; /* 2^order hits */
55465+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
55466+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
55467+ atomic_unchecked_t s_bal_allocated; /* in blocks */
55468+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
55469+ atomic_unchecked_t s_bal_goals; /* goal hits */
55470+ atomic_unchecked_t s_bal_breaks; /* too long searches */
55471+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
55472 spinlock_t s_bal_lock;
55473 unsigned long s_mb_buddies_generated;
55474 unsigned long long s_mb_generation_time;
55475- atomic_t s_mb_lost_chunks;
55476- atomic_t s_mb_preallocated;
55477- atomic_t s_mb_discarded;
55478+ atomic_unchecked_t s_mb_lost_chunks;
55479+ atomic_unchecked_t s_mb_preallocated;
55480+ atomic_unchecked_t s_mb_discarded;
55481 atomic_t s_lock_busy;
55482
55483 /* locality groups */
55484diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
55485index 4bbbf13b..dcceaeb 100644
55486--- a/fs/ext4/mballoc.c
55487+++ b/fs/ext4/mballoc.c
55488@@ -1865,7 +1865,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
55489 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
55490
55491 if (EXT4_SB(sb)->s_mb_stats)
55492- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
55493+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
55494
55495 break;
55496 }
55497@@ -2171,7 +2171,7 @@ repeat:
55498 ac->ac_status = AC_STATUS_CONTINUE;
55499 ac->ac_flags |= EXT4_MB_HINT_FIRST;
55500 cr = 3;
55501- atomic_inc(&sbi->s_mb_lost_chunks);
55502+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
55503 goto repeat;
55504 }
55505 }
55506@@ -2679,25 +2679,25 @@ int ext4_mb_release(struct super_block *sb)
55507 if (sbi->s_mb_stats) {
55508 ext4_msg(sb, KERN_INFO,
55509 "mballoc: %u blocks %u reqs (%u success)",
55510- atomic_read(&sbi->s_bal_allocated),
55511- atomic_read(&sbi->s_bal_reqs),
55512- atomic_read(&sbi->s_bal_success));
55513+ atomic_read_unchecked(&sbi->s_bal_allocated),
55514+ atomic_read_unchecked(&sbi->s_bal_reqs),
55515+ atomic_read_unchecked(&sbi->s_bal_success));
55516 ext4_msg(sb, KERN_INFO,
55517 "mballoc: %u extents scanned, %u goal hits, "
55518 "%u 2^N hits, %u breaks, %u lost",
55519- atomic_read(&sbi->s_bal_ex_scanned),
55520- atomic_read(&sbi->s_bal_goals),
55521- atomic_read(&sbi->s_bal_2orders),
55522- atomic_read(&sbi->s_bal_breaks),
55523- atomic_read(&sbi->s_mb_lost_chunks));
55524+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
55525+ atomic_read_unchecked(&sbi->s_bal_goals),
55526+ atomic_read_unchecked(&sbi->s_bal_2orders),
55527+ atomic_read_unchecked(&sbi->s_bal_breaks),
55528+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
55529 ext4_msg(sb, KERN_INFO,
55530 "mballoc: %lu generated and it took %Lu",
55531 sbi->s_mb_buddies_generated,
55532 sbi->s_mb_generation_time);
55533 ext4_msg(sb, KERN_INFO,
55534 "mballoc: %u preallocated, %u discarded",
55535- atomic_read(&sbi->s_mb_preallocated),
55536- atomic_read(&sbi->s_mb_discarded));
55537+ atomic_read_unchecked(&sbi->s_mb_preallocated),
55538+ atomic_read_unchecked(&sbi->s_mb_discarded));
55539 }
55540
55541 free_percpu(sbi->s_locality_groups);
55542@@ -3151,16 +3151,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
55543 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
55544
55545 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
55546- atomic_inc(&sbi->s_bal_reqs);
55547- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55548+ atomic_inc_unchecked(&sbi->s_bal_reqs);
55549+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55550 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
55551- atomic_inc(&sbi->s_bal_success);
55552- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
55553+ atomic_inc_unchecked(&sbi->s_bal_success);
55554+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
55555 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
55556 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
55557- atomic_inc(&sbi->s_bal_goals);
55558+ atomic_inc_unchecked(&sbi->s_bal_goals);
55559 if (ac->ac_found > sbi->s_mb_max_to_scan)
55560- atomic_inc(&sbi->s_bal_breaks);
55561+ atomic_inc_unchecked(&sbi->s_bal_breaks);
55562 }
55563
55564 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
55565@@ -3560,7 +3560,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
55566 trace_ext4_mb_new_inode_pa(ac, pa);
55567
55568 ext4_mb_use_inode_pa(ac, pa);
55569- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
55570+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
55571
55572 ei = EXT4_I(ac->ac_inode);
55573 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
55574@@ -3620,7 +3620,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
55575 trace_ext4_mb_new_group_pa(ac, pa);
55576
55577 ext4_mb_use_group_pa(ac, pa);
55578- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
55579+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
55580
55581 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
55582 lg = ac->ac_lg;
55583@@ -3709,7 +3709,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
55584 * from the bitmap and continue.
55585 */
55586 }
55587- atomic_add(free, &sbi->s_mb_discarded);
55588+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
55589
55590 return err;
55591 }
55592@@ -3727,7 +3727,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
55593 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
55594 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
55595 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
55596- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
55597+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
55598 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
55599
55600 return 0;
55601diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
55602index 214461e..3614c89 100644
55603--- a/fs/ext4/mmp.c
55604+++ b/fs/ext4/mmp.c
55605@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
55606 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
55607 const char *function, unsigned int line, const char *msg)
55608 {
55609- __ext4_warning(sb, function, line, msg);
55610+ __ext4_warning(sb, function, line, "%s", msg);
55611 __ext4_warning(sb, function, line,
55612 "MMP failure info: last update time: %llu, last update "
55613 "node: %s, last update device: %s\n",
55614diff --git a/fs/ext4/super.c b/fs/ext4/super.c
55615index b59373b..f41c2b5 100644
55616--- a/fs/ext4/super.c
55617+++ b/fs/ext4/super.c
55618@@ -1254,7 +1254,7 @@ static ext4_fsblk_t get_sb_block(void **data)
55619 }
55620
55621 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
55622-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
55623+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
55624 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
55625
55626 #ifdef CONFIG_QUOTA
55627@@ -2394,7 +2394,7 @@ struct ext4_attr {
55628 int offset;
55629 int deprecated_val;
55630 } u;
55631-};
55632+} __do_const;
55633
55634 static int parse_strtoull(const char *buf,
55635 unsigned long long max, unsigned long long *value)
55636diff --git a/fs/fcntl.c b/fs/fcntl.c
55637index 65343c3..9969dcf 100644
55638--- a/fs/fcntl.c
55639+++ b/fs/fcntl.c
55640@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
55641 if (err)
55642 return err;
55643
55644+ if (gr_handle_chroot_fowner(pid, type))
55645+ return -ENOENT;
55646+ if (gr_check_protected_task_fowner(pid, type))
55647+ return -EACCES;
55648+
55649 f_modown(filp, pid, type, force);
55650 return 0;
55651 }
55652diff --git a/fs/fhandle.c b/fs/fhandle.c
55653index 999ff5c..41f4109 100644
55654--- a/fs/fhandle.c
55655+++ b/fs/fhandle.c
55656@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
55657 } else
55658 retval = 0;
55659 /* copy the mount id */
55660- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
55661- sizeof(*mnt_id)) ||
55662+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
55663 copy_to_user(ufh, handle,
55664 sizeof(struct file_handle) + handle_bytes))
55665 retval = -EFAULT;
55666diff --git a/fs/file.c b/fs/file.c
55667index 4a78f98..9447397 100644
55668--- a/fs/file.c
55669+++ b/fs/file.c
55670@@ -16,6 +16,7 @@
55671 #include <linux/slab.h>
55672 #include <linux/vmalloc.h>
55673 #include <linux/file.h>
55674+#include <linux/security.h>
55675 #include <linux/fdtable.h>
55676 #include <linux/bitops.h>
55677 #include <linux/interrupt.h>
55678@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
55679 if (!file)
55680 return __close_fd(files, fd);
55681
55682+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
55683 if (fd >= rlimit(RLIMIT_NOFILE))
55684 return -EBADF;
55685
55686@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
55687 if (unlikely(oldfd == newfd))
55688 return -EINVAL;
55689
55690+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
55691 if (newfd >= rlimit(RLIMIT_NOFILE))
55692 return -EBADF;
55693
55694@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
55695 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
55696 {
55697 int err;
55698+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
55699 if (from >= rlimit(RLIMIT_NOFILE))
55700 return -EINVAL;
55701 err = alloc_fd(from, flags);
55702diff --git a/fs/filesystems.c b/fs/filesystems.c
55703index 92567d9..fcd8cbf 100644
55704--- a/fs/filesystems.c
55705+++ b/fs/filesystems.c
55706@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
55707 int len = dot ? dot - name : strlen(name);
55708
55709 fs = __get_fs_type(name, len);
55710+#ifdef CONFIG_GRKERNSEC_MODHARDEN
55711+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
55712+#else
55713 if (!fs && (request_module("fs-%.*s", len, name) == 0))
55714+#endif
55715 fs = __get_fs_type(name, len);
55716
55717 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
55718diff --git a/fs/fs_struct.c b/fs/fs_struct.c
55719index d8ac61d..79a36f0 100644
55720--- a/fs/fs_struct.c
55721+++ b/fs/fs_struct.c
55722@@ -4,6 +4,7 @@
55723 #include <linux/path.h>
55724 #include <linux/slab.h>
55725 #include <linux/fs_struct.h>
55726+#include <linux/grsecurity.h>
55727 #include "internal.h"
55728
55729 /*
55730@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
55731 write_seqcount_begin(&fs->seq);
55732 old_root = fs->root;
55733 fs->root = *path;
55734+ gr_set_chroot_entries(current, path);
55735 write_seqcount_end(&fs->seq);
55736 spin_unlock(&fs->lock);
55737 if (old_root.dentry)
55738@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
55739 int hits = 0;
55740 spin_lock(&fs->lock);
55741 write_seqcount_begin(&fs->seq);
55742+ /* this root replacement is only done by pivot_root,
55743+ leave grsec's chroot tagging alone for this task
55744+ so that a pivoted root isn't treated as a chroot
55745+ */
55746 hits += replace_path(&fs->root, old_root, new_root);
55747 hits += replace_path(&fs->pwd, old_root, new_root);
55748 write_seqcount_end(&fs->seq);
55749@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
55750 task_lock(tsk);
55751 spin_lock(&fs->lock);
55752 tsk->fs = NULL;
55753- kill = !--fs->users;
55754+ gr_clear_chroot_entries(tsk);
55755+ kill = !atomic_dec_return(&fs->users);
55756 spin_unlock(&fs->lock);
55757 task_unlock(tsk);
55758 if (kill)
55759@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
55760 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
55761 /* We don't need to lock fs - think why ;-) */
55762 if (fs) {
55763- fs->users = 1;
55764+ atomic_set(&fs->users, 1);
55765 fs->in_exec = 0;
55766 spin_lock_init(&fs->lock);
55767 seqcount_init(&fs->seq);
55768@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
55769 spin_lock(&old->lock);
55770 fs->root = old->root;
55771 path_get(&fs->root);
55772+ /* instead of calling gr_set_chroot_entries here,
55773+ we call it from every caller of this function
55774+ */
55775 fs->pwd = old->pwd;
55776 path_get(&fs->pwd);
55777 spin_unlock(&old->lock);
55778@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
55779
55780 task_lock(current);
55781 spin_lock(&fs->lock);
55782- kill = !--fs->users;
55783+ kill = !atomic_dec_return(&fs->users);
55784 current->fs = new_fs;
55785+ gr_set_chroot_entries(current, &new_fs->root);
55786 spin_unlock(&fs->lock);
55787 task_unlock(current);
55788
55789@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
55790
55791 int current_umask(void)
55792 {
55793- return current->fs->umask;
55794+ return current->fs->umask | gr_acl_umask();
55795 }
55796 EXPORT_SYMBOL(current_umask);
55797
55798 /* to be mentioned only in INIT_TASK */
55799 struct fs_struct init_fs = {
55800- .users = 1,
55801+ .users = ATOMIC_INIT(1),
55802 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
55803 .seq = SEQCNT_ZERO,
55804 .umask = 0022,
55805diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
55806index 0e91a3c..6c6d2e0 100644
55807--- a/fs/fscache/cookie.c
55808+++ b/fs/fscache/cookie.c
55809@@ -19,7 +19,7 @@
55810
55811 struct kmem_cache *fscache_cookie_jar;
55812
55813-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
55814+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
55815
55816 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
55817 static int fscache_alloc_object(struct fscache_cache *cache,
55818@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
55819 parent ? (char *) parent->def->name : "<no-parent>",
55820 def->name, netfs_data);
55821
55822- fscache_stat(&fscache_n_acquires);
55823+ fscache_stat_unchecked(&fscache_n_acquires);
55824
55825 /* if there's no parent cookie, then we don't create one here either */
55826 if (!parent) {
55827- fscache_stat(&fscache_n_acquires_null);
55828+ fscache_stat_unchecked(&fscache_n_acquires_null);
55829 _leave(" [no parent]");
55830 return NULL;
55831 }
55832@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
55833 /* allocate and initialise a cookie */
55834 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
55835 if (!cookie) {
55836- fscache_stat(&fscache_n_acquires_oom);
55837+ fscache_stat_unchecked(&fscache_n_acquires_oom);
55838 _leave(" [ENOMEM]");
55839 return NULL;
55840 }
55841@@ -114,13 +114,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
55842
55843 switch (cookie->def->type) {
55844 case FSCACHE_COOKIE_TYPE_INDEX:
55845- fscache_stat(&fscache_n_cookie_index);
55846+ fscache_stat_unchecked(&fscache_n_cookie_index);
55847 break;
55848 case FSCACHE_COOKIE_TYPE_DATAFILE:
55849- fscache_stat(&fscache_n_cookie_data);
55850+ fscache_stat_unchecked(&fscache_n_cookie_data);
55851 break;
55852 default:
55853- fscache_stat(&fscache_n_cookie_special);
55854+ fscache_stat_unchecked(&fscache_n_cookie_special);
55855 break;
55856 }
55857
55858@@ -131,13 +131,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
55859 if (fscache_acquire_non_index_cookie(cookie) < 0) {
55860 atomic_dec(&parent->n_children);
55861 __fscache_cookie_put(cookie);
55862- fscache_stat(&fscache_n_acquires_nobufs);
55863+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
55864 _leave(" = NULL");
55865 return NULL;
55866 }
55867 }
55868
55869- fscache_stat(&fscache_n_acquires_ok);
55870+ fscache_stat_unchecked(&fscache_n_acquires_ok);
55871 _leave(" = %p", cookie);
55872 return cookie;
55873 }
55874@@ -173,7 +173,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
55875 cache = fscache_select_cache_for_object(cookie->parent);
55876 if (!cache) {
55877 up_read(&fscache_addremove_sem);
55878- fscache_stat(&fscache_n_acquires_no_cache);
55879+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
55880 _leave(" = -ENOMEDIUM [no cache]");
55881 return -ENOMEDIUM;
55882 }
55883@@ -259,14 +259,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
55884 object = cache->ops->alloc_object(cache, cookie);
55885 fscache_stat_d(&fscache_n_cop_alloc_object);
55886 if (IS_ERR(object)) {
55887- fscache_stat(&fscache_n_object_no_alloc);
55888+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
55889 ret = PTR_ERR(object);
55890 goto error;
55891 }
55892
55893- fscache_stat(&fscache_n_object_alloc);
55894+ fscache_stat_unchecked(&fscache_n_object_alloc);
55895
55896- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
55897+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
55898
55899 _debug("ALLOC OBJ%x: %s {%lx}",
55900 object->debug_id, cookie->def->name, object->events);
55901@@ -380,7 +380,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
55902
55903 _enter("{%s}", cookie->def->name);
55904
55905- fscache_stat(&fscache_n_invalidates);
55906+ fscache_stat_unchecked(&fscache_n_invalidates);
55907
55908 /* Only permit invalidation of data files. Invalidating an index will
55909 * require the caller to release all its attachments to the tree rooted
55910@@ -438,10 +438,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
55911 {
55912 struct fscache_object *object;
55913
55914- fscache_stat(&fscache_n_updates);
55915+ fscache_stat_unchecked(&fscache_n_updates);
55916
55917 if (!cookie) {
55918- fscache_stat(&fscache_n_updates_null);
55919+ fscache_stat_unchecked(&fscache_n_updates_null);
55920 _leave(" [no cookie]");
55921 return;
55922 }
55923@@ -473,12 +473,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
55924 {
55925 struct fscache_object *object;
55926
55927- fscache_stat(&fscache_n_relinquishes);
55928+ fscache_stat_unchecked(&fscache_n_relinquishes);
55929 if (retire)
55930- fscache_stat(&fscache_n_relinquishes_retire);
55931+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
55932
55933 if (!cookie) {
55934- fscache_stat(&fscache_n_relinquishes_null);
55935+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
55936 _leave(" [no cookie]");
55937 return;
55938 }
55939diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
55940index 12d505b..86473a3 100644
55941--- a/fs/fscache/internal.h
55942+++ b/fs/fscache/internal.h
55943@@ -147,101 +147,101 @@ extern void fscache_proc_cleanup(void);
55944 * stats.c
55945 */
55946 #ifdef CONFIG_FSCACHE_STATS
55947-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
55948-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
55949+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
55950+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
55951
55952-extern atomic_t fscache_n_op_pend;
55953-extern atomic_t fscache_n_op_run;
55954-extern atomic_t fscache_n_op_enqueue;
55955-extern atomic_t fscache_n_op_deferred_release;
55956-extern atomic_t fscache_n_op_release;
55957-extern atomic_t fscache_n_op_gc;
55958-extern atomic_t fscache_n_op_cancelled;
55959-extern atomic_t fscache_n_op_rejected;
55960+extern atomic_unchecked_t fscache_n_op_pend;
55961+extern atomic_unchecked_t fscache_n_op_run;
55962+extern atomic_unchecked_t fscache_n_op_enqueue;
55963+extern atomic_unchecked_t fscache_n_op_deferred_release;
55964+extern atomic_unchecked_t fscache_n_op_release;
55965+extern atomic_unchecked_t fscache_n_op_gc;
55966+extern atomic_unchecked_t fscache_n_op_cancelled;
55967+extern atomic_unchecked_t fscache_n_op_rejected;
55968
55969-extern atomic_t fscache_n_attr_changed;
55970-extern atomic_t fscache_n_attr_changed_ok;
55971-extern atomic_t fscache_n_attr_changed_nobufs;
55972-extern atomic_t fscache_n_attr_changed_nomem;
55973-extern atomic_t fscache_n_attr_changed_calls;
55974+extern atomic_unchecked_t fscache_n_attr_changed;
55975+extern atomic_unchecked_t fscache_n_attr_changed_ok;
55976+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
55977+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
55978+extern atomic_unchecked_t fscache_n_attr_changed_calls;
55979
55980-extern atomic_t fscache_n_allocs;
55981-extern atomic_t fscache_n_allocs_ok;
55982-extern atomic_t fscache_n_allocs_wait;
55983-extern atomic_t fscache_n_allocs_nobufs;
55984-extern atomic_t fscache_n_allocs_intr;
55985-extern atomic_t fscache_n_allocs_object_dead;
55986-extern atomic_t fscache_n_alloc_ops;
55987-extern atomic_t fscache_n_alloc_op_waits;
55988+extern atomic_unchecked_t fscache_n_allocs;
55989+extern atomic_unchecked_t fscache_n_allocs_ok;
55990+extern atomic_unchecked_t fscache_n_allocs_wait;
55991+extern atomic_unchecked_t fscache_n_allocs_nobufs;
55992+extern atomic_unchecked_t fscache_n_allocs_intr;
55993+extern atomic_unchecked_t fscache_n_allocs_object_dead;
55994+extern atomic_unchecked_t fscache_n_alloc_ops;
55995+extern atomic_unchecked_t fscache_n_alloc_op_waits;
55996
55997-extern atomic_t fscache_n_retrievals;
55998-extern atomic_t fscache_n_retrievals_ok;
55999-extern atomic_t fscache_n_retrievals_wait;
56000-extern atomic_t fscache_n_retrievals_nodata;
56001-extern atomic_t fscache_n_retrievals_nobufs;
56002-extern atomic_t fscache_n_retrievals_intr;
56003-extern atomic_t fscache_n_retrievals_nomem;
56004-extern atomic_t fscache_n_retrievals_object_dead;
56005-extern atomic_t fscache_n_retrieval_ops;
56006-extern atomic_t fscache_n_retrieval_op_waits;
56007+extern atomic_unchecked_t fscache_n_retrievals;
56008+extern atomic_unchecked_t fscache_n_retrievals_ok;
56009+extern atomic_unchecked_t fscache_n_retrievals_wait;
56010+extern atomic_unchecked_t fscache_n_retrievals_nodata;
56011+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
56012+extern atomic_unchecked_t fscache_n_retrievals_intr;
56013+extern atomic_unchecked_t fscache_n_retrievals_nomem;
56014+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
56015+extern atomic_unchecked_t fscache_n_retrieval_ops;
56016+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
56017
56018-extern atomic_t fscache_n_stores;
56019-extern atomic_t fscache_n_stores_ok;
56020-extern atomic_t fscache_n_stores_again;
56021-extern atomic_t fscache_n_stores_nobufs;
56022-extern atomic_t fscache_n_stores_oom;
56023-extern atomic_t fscache_n_store_ops;
56024-extern atomic_t fscache_n_store_calls;
56025-extern atomic_t fscache_n_store_pages;
56026-extern atomic_t fscache_n_store_radix_deletes;
56027-extern atomic_t fscache_n_store_pages_over_limit;
56028+extern atomic_unchecked_t fscache_n_stores;
56029+extern atomic_unchecked_t fscache_n_stores_ok;
56030+extern atomic_unchecked_t fscache_n_stores_again;
56031+extern atomic_unchecked_t fscache_n_stores_nobufs;
56032+extern atomic_unchecked_t fscache_n_stores_oom;
56033+extern atomic_unchecked_t fscache_n_store_ops;
56034+extern atomic_unchecked_t fscache_n_store_calls;
56035+extern atomic_unchecked_t fscache_n_store_pages;
56036+extern atomic_unchecked_t fscache_n_store_radix_deletes;
56037+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
56038
56039-extern atomic_t fscache_n_store_vmscan_not_storing;
56040-extern atomic_t fscache_n_store_vmscan_gone;
56041-extern atomic_t fscache_n_store_vmscan_busy;
56042-extern atomic_t fscache_n_store_vmscan_cancelled;
56043-extern atomic_t fscache_n_store_vmscan_wait;
56044+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
56045+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
56046+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
56047+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
56048+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
56049
56050-extern atomic_t fscache_n_marks;
56051-extern atomic_t fscache_n_uncaches;
56052+extern atomic_unchecked_t fscache_n_marks;
56053+extern atomic_unchecked_t fscache_n_uncaches;
56054
56055-extern atomic_t fscache_n_acquires;
56056-extern atomic_t fscache_n_acquires_null;
56057-extern atomic_t fscache_n_acquires_no_cache;
56058-extern atomic_t fscache_n_acquires_ok;
56059-extern atomic_t fscache_n_acquires_nobufs;
56060-extern atomic_t fscache_n_acquires_oom;
56061+extern atomic_unchecked_t fscache_n_acquires;
56062+extern atomic_unchecked_t fscache_n_acquires_null;
56063+extern atomic_unchecked_t fscache_n_acquires_no_cache;
56064+extern atomic_unchecked_t fscache_n_acquires_ok;
56065+extern atomic_unchecked_t fscache_n_acquires_nobufs;
56066+extern atomic_unchecked_t fscache_n_acquires_oom;
56067
56068-extern atomic_t fscache_n_invalidates;
56069-extern atomic_t fscache_n_invalidates_run;
56070+extern atomic_unchecked_t fscache_n_invalidates;
56071+extern atomic_unchecked_t fscache_n_invalidates_run;
56072
56073-extern atomic_t fscache_n_updates;
56074-extern atomic_t fscache_n_updates_null;
56075-extern atomic_t fscache_n_updates_run;
56076+extern atomic_unchecked_t fscache_n_updates;
56077+extern atomic_unchecked_t fscache_n_updates_null;
56078+extern atomic_unchecked_t fscache_n_updates_run;
56079
56080-extern atomic_t fscache_n_relinquishes;
56081-extern atomic_t fscache_n_relinquishes_null;
56082-extern atomic_t fscache_n_relinquishes_waitcrt;
56083-extern atomic_t fscache_n_relinquishes_retire;
56084+extern atomic_unchecked_t fscache_n_relinquishes;
56085+extern atomic_unchecked_t fscache_n_relinquishes_null;
56086+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
56087+extern atomic_unchecked_t fscache_n_relinquishes_retire;
56088
56089-extern atomic_t fscache_n_cookie_index;
56090-extern atomic_t fscache_n_cookie_data;
56091-extern atomic_t fscache_n_cookie_special;
56092+extern atomic_unchecked_t fscache_n_cookie_index;
56093+extern atomic_unchecked_t fscache_n_cookie_data;
56094+extern atomic_unchecked_t fscache_n_cookie_special;
56095
56096-extern atomic_t fscache_n_object_alloc;
56097-extern atomic_t fscache_n_object_no_alloc;
56098-extern atomic_t fscache_n_object_lookups;
56099-extern atomic_t fscache_n_object_lookups_negative;
56100-extern atomic_t fscache_n_object_lookups_positive;
56101-extern atomic_t fscache_n_object_lookups_timed_out;
56102-extern atomic_t fscache_n_object_created;
56103-extern atomic_t fscache_n_object_avail;
56104-extern atomic_t fscache_n_object_dead;
56105+extern atomic_unchecked_t fscache_n_object_alloc;
56106+extern atomic_unchecked_t fscache_n_object_no_alloc;
56107+extern atomic_unchecked_t fscache_n_object_lookups;
56108+extern atomic_unchecked_t fscache_n_object_lookups_negative;
56109+extern atomic_unchecked_t fscache_n_object_lookups_positive;
56110+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
56111+extern atomic_unchecked_t fscache_n_object_created;
56112+extern atomic_unchecked_t fscache_n_object_avail;
56113+extern atomic_unchecked_t fscache_n_object_dead;
56114
56115-extern atomic_t fscache_n_checkaux_none;
56116-extern atomic_t fscache_n_checkaux_okay;
56117-extern atomic_t fscache_n_checkaux_update;
56118-extern atomic_t fscache_n_checkaux_obsolete;
56119+extern atomic_unchecked_t fscache_n_checkaux_none;
56120+extern atomic_unchecked_t fscache_n_checkaux_okay;
56121+extern atomic_unchecked_t fscache_n_checkaux_update;
56122+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
56123
56124 extern atomic_t fscache_n_cop_alloc_object;
56125 extern atomic_t fscache_n_cop_lookup_object;
56126@@ -266,6 +266,11 @@ static inline void fscache_stat(atomic_t *stat)
56127 atomic_inc(stat);
56128 }
56129
56130+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
56131+{
56132+ atomic_inc_unchecked(stat);
56133+}
56134+
56135 static inline void fscache_stat_d(atomic_t *stat)
56136 {
56137 atomic_dec(stat);
56138@@ -278,6 +283,7 @@ extern const struct file_operations fscache_stats_fops;
56139
56140 #define __fscache_stat(stat) (NULL)
56141 #define fscache_stat(stat) do {} while (0)
56142+#define fscache_stat_unchecked(stat) do {} while (0)
56143 #define fscache_stat_d(stat) do {} while (0)
56144 #endif
56145
56146diff --git a/fs/fscache/object.c b/fs/fscache/object.c
56147index 86d75a6..5f3d7a0 100644
56148--- a/fs/fscache/object.c
56149+++ b/fs/fscache/object.c
56150@@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56151 _debug("LOOKUP \"%s\" in \"%s\"",
56152 cookie->def->name, object->cache->tag->name);
56153
56154- fscache_stat(&fscache_n_object_lookups);
56155+ fscache_stat_unchecked(&fscache_n_object_lookups);
56156 fscache_stat(&fscache_n_cop_lookup_object);
56157 ret = object->cache->ops->lookup_object(object);
56158 fscache_stat_d(&fscache_n_cop_lookup_object);
56159@@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56160 if (ret == -ETIMEDOUT) {
56161 /* probably stuck behind another object, so move this one to
56162 * the back of the queue */
56163- fscache_stat(&fscache_n_object_lookups_timed_out);
56164+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
56165 _leave(" [timeout]");
56166 return NO_TRANSIT;
56167 }
56168@@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
56169 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
56170
56171 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56172- fscache_stat(&fscache_n_object_lookups_negative);
56173+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
56174
56175 /* Allow write requests to begin stacking up and read requests to begin
56176 * returning ENODATA.
56177@@ -523,7 +523,7 @@ void fscache_obtained_object(struct fscache_object *object)
56178 /* if we were still looking up, then we must have a positive lookup
56179 * result, in which case there may be data available */
56180 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56181- fscache_stat(&fscache_n_object_lookups_positive);
56182+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
56183
56184 /* We do (presumably) have data */
56185 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
56186@@ -534,7 +534,7 @@ void fscache_obtained_object(struct fscache_object *object)
56187 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
56188 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
56189 } else {
56190- fscache_stat(&fscache_n_object_created);
56191+ fscache_stat_unchecked(&fscache_n_object_created);
56192 }
56193
56194 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
56195@@ -570,7 +570,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
56196 fscache_stat_d(&fscache_n_cop_lookup_complete);
56197
56198 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
56199- fscache_stat(&fscache_n_object_avail);
56200+ fscache_stat_unchecked(&fscache_n_object_avail);
56201
56202 _leave("");
56203 return transit_to(JUMPSTART_DEPS);
56204@@ -716,7 +716,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
56205
56206 /* this just shifts the object release to the work processor */
56207 fscache_put_object(object);
56208- fscache_stat(&fscache_n_object_dead);
56209+ fscache_stat_unchecked(&fscache_n_object_dead);
56210
56211 _leave("");
56212 return transit_to(OBJECT_DEAD);
56213@@ -881,7 +881,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56214 enum fscache_checkaux result;
56215
56216 if (!object->cookie->def->check_aux) {
56217- fscache_stat(&fscache_n_checkaux_none);
56218+ fscache_stat_unchecked(&fscache_n_checkaux_none);
56219 return FSCACHE_CHECKAUX_OKAY;
56220 }
56221
56222@@ -890,17 +890,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56223 switch (result) {
56224 /* entry okay as is */
56225 case FSCACHE_CHECKAUX_OKAY:
56226- fscache_stat(&fscache_n_checkaux_okay);
56227+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
56228 break;
56229
56230 /* entry requires update */
56231 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
56232- fscache_stat(&fscache_n_checkaux_update);
56233+ fscache_stat_unchecked(&fscache_n_checkaux_update);
56234 break;
56235
56236 /* entry requires deletion */
56237 case FSCACHE_CHECKAUX_OBSOLETE:
56238- fscache_stat(&fscache_n_checkaux_obsolete);
56239+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
56240 break;
56241
56242 default:
56243@@ -986,7 +986,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
56244 {
56245 const struct fscache_state *s;
56246
56247- fscache_stat(&fscache_n_invalidates_run);
56248+ fscache_stat_unchecked(&fscache_n_invalidates_run);
56249 fscache_stat(&fscache_n_cop_invalidate_object);
56250 s = _fscache_invalidate_object(object, event);
56251 fscache_stat_d(&fscache_n_cop_invalidate_object);
56252@@ -1001,7 +1001,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
56253 {
56254 _enter("{OBJ%x},%d", object->debug_id, event);
56255
56256- fscache_stat(&fscache_n_updates_run);
56257+ fscache_stat_unchecked(&fscache_n_updates_run);
56258 fscache_stat(&fscache_n_cop_update_object);
56259 object->cache->ops->update_object(object);
56260 fscache_stat_d(&fscache_n_cop_update_object);
56261diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
56262index 318071a..379938b 100644
56263--- a/fs/fscache/operation.c
56264+++ b/fs/fscache/operation.c
56265@@ -17,7 +17,7 @@
56266 #include <linux/slab.h>
56267 #include "internal.h"
56268
56269-atomic_t fscache_op_debug_id;
56270+atomic_unchecked_t fscache_op_debug_id;
56271 EXPORT_SYMBOL(fscache_op_debug_id);
56272
56273 /**
56274@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
56275 ASSERTCMP(atomic_read(&op->usage), >, 0);
56276 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
56277
56278- fscache_stat(&fscache_n_op_enqueue);
56279+ fscache_stat_unchecked(&fscache_n_op_enqueue);
56280 switch (op->flags & FSCACHE_OP_TYPE) {
56281 case FSCACHE_OP_ASYNC:
56282 _debug("queue async");
56283@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
56284 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
56285 if (op->processor)
56286 fscache_enqueue_operation(op);
56287- fscache_stat(&fscache_n_op_run);
56288+ fscache_stat_unchecked(&fscache_n_op_run);
56289 }
56290
56291 /*
56292@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56293 if (object->n_in_progress > 0) {
56294 atomic_inc(&op->usage);
56295 list_add_tail(&op->pend_link, &object->pending_ops);
56296- fscache_stat(&fscache_n_op_pend);
56297+ fscache_stat_unchecked(&fscache_n_op_pend);
56298 } else if (!list_empty(&object->pending_ops)) {
56299 atomic_inc(&op->usage);
56300 list_add_tail(&op->pend_link, &object->pending_ops);
56301- fscache_stat(&fscache_n_op_pend);
56302+ fscache_stat_unchecked(&fscache_n_op_pend);
56303 fscache_start_operations(object);
56304 } else {
56305 ASSERTCMP(object->n_in_progress, ==, 0);
56306@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56307 object->n_exclusive++; /* reads and writes must wait */
56308 atomic_inc(&op->usage);
56309 list_add_tail(&op->pend_link, &object->pending_ops);
56310- fscache_stat(&fscache_n_op_pend);
56311+ fscache_stat_unchecked(&fscache_n_op_pend);
56312 ret = 0;
56313 } else {
56314 /* If we're in any other state, there must have been an I/O
56315@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
56316 if (object->n_exclusive > 0) {
56317 atomic_inc(&op->usage);
56318 list_add_tail(&op->pend_link, &object->pending_ops);
56319- fscache_stat(&fscache_n_op_pend);
56320+ fscache_stat_unchecked(&fscache_n_op_pend);
56321 } else if (!list_empty(&object->pending_ops)) {
56322 atomic_inc(&op->usage);
56323 list_add_tail(&op->pend_link, &object->pending_ops);
56324- fscache_stat(&fscache_n_op_pend);
56325+ fscache_stat_unchecked(&fscache_n_op_pend);
56326 fscache_start_operations(object);
56327 } else {
56328 ASSERTCMP(object->n_exclusive, ==, 0);
56329@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
56330 object->n_ops++;
56331 atomic_inc(&op->usage);
56332 list_add_tail(&op->pend_link, &object->pending_ops);
56333- fscache_stat(&fscache_n_op_pend);
56334+ fscache_stat_unchecked(&fscache_n_op_pend);
56335 ret = 0;
56336 } else if (fscache_object_is_dying(object)) {
56337- fscache_stat(&fscache_n_op_rejected);
56338+ fscache_stat_unchecked(&fscache_n_op_rejected);
56339 op->state = FSCACHE_OP_ST_CANCELLED;
56340 ret = -ENOBUFS;
56341 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
56342@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
56343 ret = -EBUSY;
56344 if (op->state == FSCACHE_OP_ST_PENDING) {
56345 ASSERT(!list_empty(&op->pend_link));
56346- fscache_stat(&fscache_n_op_cancelled);
56347+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56348 list_del_init(&op->pend_link);
56349 if (do_cancel)
56350 do_cancel(op);
56351@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
56352 while (!list_empty(&object->pending_ops)) {
56353 op = list_entry(object->pending_ops.next,
56354 struct fscache_operation, pend_link);
56355- fscache_stat(&fscache_n_op_cancelled);
56356+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56357 list_del_init(&op->pend_link);
56358
56359 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
56360@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
56361 op->state, ==, FSCACHE_OP_ST_CANCELLED);
56362 op->state = FSCACHE_OP_ST_DEAD;
56363
56364- fscache_stat(&fscache_n_op_release);
56365+ fscache_stat_unchecked(&fscache_n_op_release);
56366
56367 if (op->release) {
56368 op->release(op);
56369@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
56370 * lock, and defer it otherwise */
56371 if (!spin_trylock(&object->lock)) {
56372 _debug("defer put");
56373- fscache_stat(&fscache_n_op_deferred_release);
56374+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
56375
56376 cache = object->cache;
56377 spin_lock(&cache->op_gc_list_lock);
56378@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
56379
56380 _debug("GC DEFERRED REL OBJ%x OP%x",
56381 object->debug_id, op->debug_id);
56382- fscache_stat(&fscache_n_op_gc);
56383+ fscache_stat_unchecked(&fscache_n_op_gc);
56384
56385 ASSERTCMP(atomic_read(&op->usage), ==, 0);
56386 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
56387diff --git a/fs/fscache/page.c b/fs/fscache/page.c
56388index d479ab3..727a7f2 100644
56389--- a/fs/fscache/page.c
56390+++ b/fs/fscache/page.c
56391@@ -61,7 +61,7 @@ try_again:
56392 val = radix_tree_lookup(&cookie->stores, page->index);
56393 if (!val) {
56394 rcu_read_unlock();
56395- fscache_stat(&fscache_n_store_vmscan_not_storing);
56396+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
56397 __fscache_uncache_page(cookie, page);
56398 return true;
56399 }
56400@@ -91,11 +91,11 @@ try_again:
56401 spin_unlock(&cookie->stores_lock);
56402
56403 if (xpage) {
56404- fscache_stat(&fscache_n_store_vmscan_cancelled);
56405- fscache_stat(&fscache_n_store_radix_deletes);
56406+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
56407+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56408 ASSERTCMP(xpage, ==, page);
56409 } else {
56410- fscache_stat(&fscache_n_store_vmscan_gone);
56411+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
56412 }
56413
56414 wake_up_bit(&cookie->flags, 0);
56415@@ -110,11 +110,11 @@ page_busy:
56416 * sleeping on memory allocation, so we may need to impose a timeout
56417 * too. */
56418 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
56419- fscache_stat(&fscache_n_store_vmscan_busy);
56420+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
56421 return false;
56422 }
56423
56424- fscache_stat(&fscache_n_store_vmscan_wait);
56425+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
56426 __fscache_wait_on_page_write(cookie, page);
56427 gfp &= ~__GFP_WAIT;
56428 goto try_again;
56429@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
56430 FSCACHE_COOKIE_STORING_TAG);
56431 if (!radix_tree_tag_get(&cookie->stores, page->index,
56432 FSCACHE_COOKIE_PENDING_TAG)) {
56433- fscache_stat(&fscache_n_store_radix_deletes);
56434+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56435 xpage = radix_tree_delete(&cookie->stores, page->index);
56436 }
56437 spin_unlock(&cookie->stores_lock);
56438@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
56439
56440 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
56441
56442- fscache_stat(&fscache_n_attr_changed_calls);
56443+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
56444
56445 if (fscache_object_is_active(object) &&
56446 fscache_use_cookie(object)) {
56447@@ -189,11 +189,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56448
56449 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56450
56451- fscache_stat(&fscache_n_attr_changed);
56452+ fscache_stat_unchecked(&fscache_n_attr_changed);
56453
56454 op = kzalloc(sizeof(*op), GFP_KERNEL);
56455 if (!op) {
56456- fscache_stat(&fscache_n_attr_changed_nomem);
56457+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
56458 _leave(" = -ENOMEM");
56459 return -ENOMEM;
56460 }
56461@@ -211,7 +211,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56462 if (fscache_submit_exclusive_op(object, op) < 0)
56463 goto nobufs;
56464 spin_unlock(&cookie->lock);
56465- fscache_stat(&fscache_n_attr_changed_ok);
56466+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
56467 fscache_put_operation(op);
56468 _leave(" = 0");
56469 return 0;
56470@@ -219,7 +219,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56471 nobufs:
56472 spin_unlock(&cookie->lock);
56473 kfree(op);
56474- fscache_stat(&fscache_n_attr_changed_nobufs);
56475+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
56476 _leave(" = %d", -ENOBUFS);
56477 return -ENOBUFS;
56478 }
56479@@ -258,7 +258,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
56480 /* allocate a retrieval operation and attempt to submit it */
56481 op = kzalloc(sizeof(*op), GFP_NOIO);
56482 if (!op) {
56483- fscache_stat(&fscache_n_retrievals_nomem);
56484+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56485 return NULL;
56486 }
56487
56488@@ -289,13 +289,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
56489 return 0;
56490 }
56491
56492- fscache_stat(&fscache_n_retrievals_wait);
56493+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
56494
56495 jif = jiffies;
56496 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
56497 fscache_wait_bit_interruptible,
56498 TASK_INTERRUPTIBLE) != 0) {
56499- fscache_stat(&fscache_n_retrievals_intr);
56500+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56501 _leave(" = -ERESTARTSYS");
56502 return -ERESTARTSYS;
56503 }
56504@@ -324,8 +324,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
56505 */
56506 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56507 struct fscache_retrieval *op,
56508- atomic_t *stat_op_waits,
56509- atomic_t *stat_object_dead)
56510+ atomic_unchecked_t *stat_op_waits,
56511+ atomic_unchecked_t *stat_object_dead)
56512 {
56513 int ret;
56514
56515@@ -333,7 +333,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56516 goto check_if_dead;
56517
56518 _debug(">>> WT");
56519- fscache_stat(stat_op_waits);
56520+ fscache_stat_unchecked(stat_op_waits);
56521 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
56522 fscache_wait_bit_interruptible,
56523 TASK_INTERRUPTIBLE) != 0) {
56524@@ -350,14 +350,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56525
56526 check_if_dead:
56527 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
56528- fscache_stat(stat_object_dead);
56529+ fscache_stat_unchecked(stat_object_dead);
56530 _leave(" = -ENOBUFS [cancelled]");
56531 return -ENOBUFS;
56532 }
56533 if (unlikely(fscache_object_is_dead(object))) {
56534 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
56535 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
56536- fscache_stat(stat_object_dead);
56537+ fscache_stat_unchecked(stat_object_dead);
56538 return -ENOBUFS;
56539 }
56540 return 0;
56541@@ -384,7 +384,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56542
56543 _enter("%p,%p,,,", cookie, page);
56544
56545- fscache_stat(&fscache_n_retrievals);
56546+ fscache_stat_unchecked(&fscache_n_retrievals);
56547
56548 if (hlist_empty(&cookie->backing_objects))
56549 goto nobufs;
56550@@ -424,7 +424,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56551 goto nobufs_unlock_dec;
56552 spin_unlock(&cookie->lock);
56553
56554- fscache_stat(&fscache_n_retrieval_ops);
56555+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
56556
56557 /* pin the netfs read context in case we need to do the actual netfs
56558 * read because we've encountered a cache read failure */
56559@@ -454,15 +454,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56560
56561 error:
56562 if (ret == -ENOMEM)
56563- fscache_stat(&fscache_n_retrievals_nomem);
56564+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56565 else if (ret == -ERESTARTSYS)
56566- fscache_stat(&fscache_n_retrievals_intr);
56567+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56568 else if (ret == -ENODATA)
56569- fscache_stat(&fscache_n_retrievals_nodata);
56570+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
56571 else if (ret < 0)
56572- fscache_stat(&fscache_n_retrievals_nobufs);
56573+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56574 else
56575- fscache_stat(&fscache_n_retrievals_ok);
56576+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
56577
56578 fscache_put_retrieval(op);
56579 _leave(" = %d", ret);
56580@@ -475,7 +475,7 @@ nobufs_unlock:
56581 atomic_dec(&cookie->n_active);
56582 kfree(op);
56583 nobufs:
56584- fscache_stat(&fscache_n_retrievals_nobufs);
56585+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56586 _leave(" = -ENOBUFS");
56587 return -ENOBUFS;
56588 }
56589@@ -513,7 +513,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56590
56591 _enter("%p,,%d,,,", cookie, *nr_pages);
56592
56593- fscache_stat(&fscache_n_retrievals);
56594+ fscache_stat_unchecked(&fscache_n_retrievals);
56595
56596 if (hlist_empty(&cookie->backing_objects))
56597 goto nobufs;
56598@@ -549,7 +549,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56599 goto nobufs_unlock_dec;
56600 spin_unlock(&cookie->lock);
56601
56602- fscache_stat(&fscache_n_retrieval_ops);
56603+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
56604
56605 /* pin the netfs read context in case we need to do the actual netfs
56606 * read because we've encountered a cache read failure */
56607@@ -579,15 +579,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56608
56609 error:
56610 if (ret == -ENOMEM)
56611- fscache_stat(&fscache_n_retrievals_nomem);
56612+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56613 else if (ret == -ERESTARTSYS)
56614- fscache_stat(&fscache_n_retrievals_intr);
56615+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56616 else if (ret == -ENODATA)
56617- fscache_stat(&fscache_n_retrievals_nodata);
56618+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
56619 else if (ret < 0)
56620- fscache_stat(&fscache_n_retrievals_nobufs);
56621+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56622 else
56623- fscache_stat(&fscache_n_retrievals_ok);
56624+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
56625
56626 fscache_put_retrieval(op);
56627 _leave(" = %d", ret);
56628@@ -600,7 +600,7 @@ nobufs_unlock:
56629 atomic_dec(&cookie->n_active);
56630 kfree(op);
56631 nobufs:
56632- fscache_stat(&fscache_n_retrievals_nobufs);
56633+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56634 _leave(" = -ENOBUFS");
56635 return -ENOBUFS;
56636 }
56637@@ -624,7 +624,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56638
56639 _enter("%p,%p,,,", cookie, page);
56640
56641- fscache_stat(&fscache_n_allocs);
56642+ fscache_stat_unchecked(&fscache_n_allocs);
56643
56644 if (hlist_empty(&cookie->backing_objects))
56645 goto nobufs;
56646@@ -656,7 +656,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56647 goto nobufs_unlock;
56648 spin_unlock(&cookie->lock);
56649
56650- fscache_stat(&fscache_n_alloc_ops);
56651+ fscache_stat_unchecked(&fscache_n_alloc_ops);
56652
56653 ret = fscache_wait_for_retrieval_activation(
56654 object, op,
56655@@ -672,11 +672,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56656
56657 error:
56658 if (ret == -ERESTARTSYS)
56659- fscache_stat(&fscache_n_allocs_intr);
56660+ fscache_stat_unchecked(&fscache_n_allocs_intr);
56661 else if (ret < 0)
56662- fscache_stat(&fscache_n_allocs_nobufs);
56663+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
56664 else
56665- fscache_stat(&fscache_n_allocs_ok);
56666+ fscache_stat_unchecked(&fscache_n_allocs_ok);
56667
56668 fscache_put_retrieval(op);
56669 _leave(" = %d", ret);
56670@@ -687,7 +687,7 @@ nobufs_unlock:
56671 atomic_dec(&cookie->n_active);
56672 kfree(op);
56673 nobufs:
56674- fscache_stat(&fscache_n_allocs_nobufs);
56675+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
56676 _leave(" = -ENOBUFS");
56677 return -ENOBUFS;
56678 }
56679@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56680
56681 spin_lock(&cookie->stores_lock);
56682
56683- fscache_stat(&fscache_n_store_calls);
56684+ fscache_stat_unchecked(&fscache_n_store_calls);
56685
56686 /* find a page to store */
56687 page = NULL;
56688@@ -758,7 +758,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56689 page = results[0];
56690 _debug("gang %d [%lx]", n, page->index);
56691 if (page->index > op->store_limit) {
56692- fscache_stat(&fscache_n_store_pages_over_limit);
56693+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
56694 goto superseded;
56695 }
56696
56697@@ -770,7 +770,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56698 spin_unlock(&cookie->stores_lock);
56699 spin_unlock(&object->lock);
56700
56701- fscache_stat(&fscache_n_store_pages);
56702+ fscache_stat_unchecked(&fscache_n_store_pages);
56703 fscache_stat(&fscache_n_cop_write_page);
56704 ret = object->cache->ops->write_page(op, page);
56705 fscache_stat_d(&fscache_n_cop_write_page);
56706@@ -873,7 +873,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56707 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56708 ASSERT(PageFsCache(page));
56709
56710- fscache_stat(&fscache_n_stores);
56711+ fscache_stat_unchecked(&fscache_n_stores);
56712
56713 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
56714 _leave(" = -ENOBUFS [invalidating]");
56715@@ -931,7 +931,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56716 spin_unlock(&cookie->stores_lock);
56717 spin_unlock(&object->lock);
56718
56719- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
56720+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
56721 op->store_limit = object->store_limit;
56722
56723 atomic_inc(&cookie->n_active);
56724@@ -940,8 +940,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56725
56726 spin_unlock(&cookie->lock);
56727 radix_tree_preload_end();
56728- fscache_stat(&fscache_n_store_ops);
56729- fscache_stat(&fscache_n_stores_ok);
56730+ fscache_stat_unchecked(&fscache_n_store_ops);
56731+ fscache_stat_unchecked(&fscache_n_stores_ok);
56732
56733 /* the work queue now carries its own ref on the object */
56734 fscache_put_operation(&op->op);
56735@@ -949,14 +949,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56736 return 0;
56737
56738 already_queued:
56739- fscache_stat(&fscache_n_stores_again);
56740+ fscache_stat_unchecked(&fscache_n_stores_again);
56741 already_pending:
56742 spin_unlock(&cookie->stores_lock);
56743 spin_unlock(&object->lock);
56744 spin_unlock(&cookie->lock);
56745 radix_tree_preload_end();
56746 kfree(op);
56747- fscache_stat(&fscache_n_stores_ok);
56748+ fscache_stat_unchecked(&fscache_n_stores_ok);
56749 _leave(" = 0");
56750 return 0;
56751
56752@@ -976,14 +976,14 @@ nobufs:
56753 spin_unlock(&cookie->lock);
56754 radix_tree_preload_end();
56755 kfree(op);
56756- fscache_stat(&fscache_n_stores_nobufs);
56757+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
56758 _leave(" = -ENOBUFS");
56759 return -ENOBUFS;
56760
56761 nomem_free:
56762 kfree(op);
56763 nomem:
56764- fscache_stat(&fscache_n_stores_oom);
56765+ fscache_stat_unchecked(&fscache_n_stores_oom);
56766 _leave(" = -ENOMEM");
56767 return -ENOMEM;
56768 }
56769@@ -1001,7 +1001,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
56770 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56771 ASSERTCMP(page, !=, NULL);
56772
56773- fscache_stat(&fscache_n_uncaches);
56774+ fscache_stat_unchecked(&fscache_n_uncaches);
56775
56776 /* cache withdrawal may beat us to it */
56777 if (!PageFsCache(page))
56778@@ -1052,7 +1052,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
56779 struct fscache_cookie *cookie = op->op.object->cookie;
56780
56781 #ifdef CONFIG_FSCACHE_STATS
56782- atomic_inc(&fscache_n_marks);
56783+ atomic_inc_unchecked(&fscache_n_marks);
56784 #endif
56785
56786 _debug("- mark %p{%lx}", page, page->index);
56787diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
56788index 40d13c7..ddf52b9 100644
56789--- a/fs/fscache/stats.c
56790+++ b/fs/fscache/stats.c
56791@@ -18,99 +18,99 @@
56792 /*
56793 * operation counters
56794 */
56795-atomic_t fscache_n_op_pend;
56796-atomic_t fscache_n_op_run;
56797-atomic_t fscache_n_op_enqueue;
56798-atomic_t fscache_n_op_requeue;
56799-atomic_t fscache_n_op_deferred_release;
56800-atomic_t fscache_n_op_release;
56801-atomic_t fscache_n_op_gc;
56802-atomic_t fscache_n_op_cancelled;
56803-atomic_t fscache_n_op_rejected;
56804+atomic_unchecked_t fscache_n_op_pend;
56805+atomic_unchecked_t fscache_n_op_run;
56806+atomic_unchecked_t fscache_n_op_enqueue;
56807+atomic_unchecked_t fscache_n_op_requeue;
56808+atomic_unchecked_t fscache_n_op_deferred_release;
56809+atomic_unchecked_t fscache_n_op_release;
56810+atomic_unchecked_t fscache_n_op_gc;
56811+atomic_unchecked_t fscache_n_op_cancelled;
56812+atomic_unchecked_t fscache_n_op_rejected;
56813
56814-atomic_t fscache_n_attr_changed;
56815-atomic_t fscache_n_attr_changed_ok;
56816-atomic_t fscache_n_attr_changed_nobufs;
56817-atomic_t fscache_n_attr_changed_nomem;
56818-atomic_t fscache_n_attr_changed_calls;
56819+atomic_unchecked_t fscache_n_attr_changed;
56820+atomic_unchecked_t fscache_n_attr_changed_ok;
56821+atomic_unchecked_t fscache_n_attr_changed_nobufs;
56822+atomic_unchecked_t fscache_n_attr_changed_nomem;
56823+atomic_unchecked_t fscache_n_attr_changed_calls;
56824
56825-atomic_t fscache_n_allocs;
56826-atomic_t fscache_n_allocs_ok;
56827-atomic_t fscache_n_allocs_wait;
56828-atomic_t fscache_n_allocs_nobufs;
56829-atomic_t fscache_n_allocs_intr;
56830-atomic_t fscache_n_allocs_object_dead;
56831-atomic_t fscache_n_alloc_ops;
56832-atomic_t fscache_n_alloc_op_waits;
56833+atomic_unchecked_t fscache_n_allocs;
56834+atomic_unchecked_t fscache_n_allocs_ok;
56835+atomic_unchecked_t fscache_n_allocs_wait;
56836+atomic_unchecked_t fscache_n_allocs_nobufs;
56837+atomic_unchecked_t fscache_n_allocs_intr;
56838+atomic_unchecked_t fscache_n_allocs_object_dead;
56839+atomic_unchecked_t fscache_n_alloc_ops;
56840+atomic_unchecked_t fscache_n_alloc_op_waits;
56841
56842-atomic_t fscache_n_retrievals;
56843-atomic_t fscache_n_retrievals_ok;
56844-atomic_t fscache_n_retrievals_wait;
56845-atomic_t fscache_n_retrievals_nodata;
56846-atomic_t fscache_n_retrievals_nobufs;
56847-atomic_t fscache_n_retrievals_intr;
56848-atomic_t fscache_n_retrievals_nomem;
56849-atomic_t fscache_n_retrievals_object_dead;
56850-atomic_t fscache_n_retrieval_ops;
56851-atomic_t fscache_n_retrieval_op_waits;
56852+atomic_unchecked_t fscache_n_retrievals;
56853+atomic_unchecked_t fscache_n_retrievals_ok;
56854+atomic_unchecked_t fscache_n_retrievals_wait;
56855+atomic_unchecked_t fscache_n_retrievals_nodata;
56856+atomic_unchecked_t fscache_n_retrievals_nobufs;
56857+atomic_unchecked_t fscache_n_retrievals_intr;
56858+atomic_unchecked_t fscache_n_retrievals_nomem;
56859+atomic_unchecked_t fscache_n_retrievals_object_dead;
56860+atomic_unchecked_t fscache_n_retrieval_ops;
56861+atomic_unchecked_t fscache_n_retrieval_op_waits;
56862
56863-atomic_t fscache_n_stores;
56864-atomic_t fscache_n_stores_ok;
56865-atomic_t fscache_n_stores_again;
56866-atomic_t fscache_n_stores_nobufs;
56867-atomic_t fscache_n_stores_oom;
56868-atomic_t fscache_n_store_ops;
56869-atomic_t fscache_n_store_calls;
56870-atomic_t fscache_n_store_pages;
56871-atomic_t fscache_n_store_radix_deletes;
56872-atomic_t fscache_n_store_pages_over_limit;
56873+atomic_unchecked_t fscache_n_stores;
56874+atomic_unchecked_t fscache_n_stores_ok;
56875+atomic_unchecked_t fscache_n_stores_again;
56876+atomic_unchecked_t fscache_n_stores_nobufs;
56877+atomic_unchecked_t fscache_n_stores_oom;
56878+atomic_unchecked_t fscache_n_store_ops;
56879+atomic_unchecked_t fscache_n_store_calls;
56880+atomic_unchecked_t fscache_n_store_pages;
56881+atomic_unchecked_t fscache_n_store_radix_deletes;
56882+atomic_unchecked_t fscache_n_store_pages_over_limit;
56883
56884-atomic_t fscache_n_store_vmscan_not_storing;
56885-atomic_t fscache_n_store_vmscan_gone;
56886-atomic_t fscache_n_store_vmscan_busy;
56887-atomic_t fscache_n_store_vmscan_cancelled;
56888-atomic_t fscache_n_store_vmscan_wait;
56889+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
56890+atomic_unchecked_t fscache_n_store_vmscan_gone;
56891+atomic_unchecked_t fscache_n_store_vmscan_busy;
56892+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
56893+atomic_unchecked_t fscache_n_store_vmscan_wait;
56894
56895-atomic_t fscache_n_marks;
56896-atomic_t fscache_n_uncaches;
56897+atomic_unchecked_t fscache_n_marks;
56898+atomic_unchecked_t fscache_n_uncaches;
56899
56900-atomic_t fscache_n_acquires;
56901-atomic_t fscache_n_acquires_null;
56902-atomic_t fscache_n_acquires_no_cache;
56903-atomic_t fscache_n_acquires_ok;
56904-atomic_t fscache_n_acquires_nobufs;
56905-atomic_t fscache_n_acquires_oom;
56906+atomic_unchecked_t fscache_n_acquires;
56907+atomic_unchecked_t fscache_n_acquires_null;
56908+atomic_unchecked_t fscache_n_acquires_no_cache;
56909+atomic_unchecked_t fscache_n_acquires_ok;
56910+atomic_unchecked_t fscache_n_acquires_nobufs;
56911+atomic_unchecked_t fscache_n_acquires_oom;
56912
56913-atomic_t fscache_n_invalidates;
56914-atomic_t fscache_n_invalidates_run;
56915+atomic_unchecked_t fscache_n_invalidates;
56916+atomic_unchecked_t fscache_n_invalidates_run;
56917
56918-atomic_t fscache_n_updates;
56919-atomic_t fscache_n_updates_null;
56920-atomic_t fscache_n_updates_run;
56921+atomic_unchecked_t fscache_n_updates;
56922+atomic_unchecked_t fscache_n_updates_null;
56923+atomic_unchecked_t fscache_n_updates_run;
56924
56925-atomic_t fscache_n_relinquishes;
56926-atomic_t fscache_n_relinquishes_null;
56927-atomic_t fscache_n_relinquishes_waitcrt;
56928-atomic_t fscache_n_relinquishes_retire;
56929+atomic_unchecked_t fscache_n_relinquishes;
56930+atomic_unchecked_t fscache_n_relinquishes_null;
56931+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
56932+atomic_unchecked_t fscache_n_relinquishes_retire;
56933
56934-atomic_t fscache_n_cookie_index;
56935-atomic_t fscache_n_cookie_data;
56936-atomic_t fscache_n_cookie_special;
56937+atomic_unchecked_t fscache_n_cookie_index;
56938+atomic_unchecked_t fscache_n_cookie_data;
56939+atomic_unchecked_t fscache_n_cookie_special;
56940
56941-atomic_t fscache_n_object_alloc;
56942-atomic_t fscache_n_object_no_alloc;
56943-atomic_t fscache_n_object_lookups;
56944-atomic_t fscache_n_object_lookups_negative;
56945-atomic_t fscache_n_object_lookups_positive;
56946-atomic_t fscache_n_object_lookups_timed_out;
56947-atomic_t fscache_n_object_created;
56948-atomic_t fscache_n_object_avail;
56949-atomic_t fscache_n_object_dead;
56950+atomic_unchecked_t fscache_n_object_alloc;
56951+atomic_unchecked_t fscache_n_object_no_alloc;
56952+atomic_unchecked_t fscache_n_object_lookups;
56953+atomic_unchecked_t fscache_n_object_lookups_negative;
56954+atomic_unchecked_t fscache_n_object_lookups_positive;
56955+atomic_unchecked_t fscache_n_object_lookups_timed_out;
56956+atomic_unchecked_t fscache_n_object_created;
56957+atomic_unchecked_t fscache_n_object_avail;
56958+atomic_unchecked_t fscache_n_object_dead;
56959
56960-atomic_t fscache_n_checkaux_none;
56961-atomic_t fscache_n_checkaux_okay;
56962-atomic_t fscache_n_checkaux_update;
56963-atomic_t fscache_n_checkaux_obsolete;
56964+atomic_unchecked_t fscache_n_checkaux_none;
56965+atomic_unchecked_t fscache_n_checkaux_okay;
56966+atomic_unchecked_t fscache_n_checkaux_update;
56967+atomic_unchecked_t fscache_n_checkaux_obsolete;
56968
56969 atomic_t fscache_n_cop_alloc_object;
56970 atomic_t fscache_n_cop_lookup_object;
56971@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
56972 seq_puts(m, "FS-Cache statistics\n");
56973
56974 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
56975- atomic_read(&fscache_n_cookie_index),
56976- atomic_read(&fscache_n_cookie_data),
56977- atomic_read(&fscache_n_cookie_special));
56978+ atomic_read_unchecked(&fscache_n_cookie_index),
56979+ atomic_read_unchecked(&fscache_n_cookie_data),
56980+ atomic_read_unchecked(&fscache_n_cookie_special));
56981
56982 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
56983- atomic_read(&fscache_n_object_alloc),
56984- atomic_read(&fscache_n_object_no_alloc),
56985- atomic_read(&fscache_n_object_avail),
56986- atomic_read(&fscache_n_object_dead));
56987+ atomic_read_unchecked(&fscache_n_object_alloc),
56988+ atomic_read_unchecked(&fscache_n_object_no_alloc),
56989+ atomic_read_unchecked(&fscache_n_object_avail),
56990+ atomic_read_unchecked(&fscache_n_object_dead));
56991 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
56992- atomic_read(&fscache_n_checkaux_none),
56993- atomic_read(&fscache_n_checkaux_okay),
56994- atomic_read(&fscache_n_checkaux_update),
56995- atomic_read(&fscache_n_checkaux_obsolete));
56996+ atomic_read_unchecked(&fscache_n_checkaux_none),
56997+ atomic_read_unchecked(&fscache_n_checkaux_okay),
56998+ atomic_read_unchecked(&fscache_n_checkaux_update),
56999+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
57000
57001 seq_printf(m, "Pages : mrk=%u unc=%u\n",
57002- atomic_read(&fscache_n_marks),
57003- atomic_read(&fscache_n_uncaches));
57004+ atomic_read_unchecked(&fscache_n_marks),
57005+ atomic_read_unchecked(&fscache_n_uncaches));
57006
57007 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
57008 " oom=%u\n",
57009- atomic_read(&fscache_n_acquires),
57010- atomic_read(&fscache_n_acquires_null),
57011- atomic_read(&fscache_n_acquires_no_cache),
57012- atomic_read(&fscache_n_acquires_ok),
57013- atomic_read(&fscache_n_acquires_nobufs),
57014- atomic_read(&fscache_n_acquires_oom));
57015+ atomic_read_unchecked(&fscache_n_acquires),
57016+ atomic_read_unchecked(&fscache_n_acquires_null),
57017+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
57018+ atomic_read_unchecked(&fscache_n_acquires_ok),
57019+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
57020+ atomic_read_unchecked(&fscache_n_acquires_oom));
57021
57022 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
57023- atomic_read(&fscache_n_object_lookups),
57024- atomic_read(&fscache_n_object_lookups_negative),
57025- atomic_read(&fscache_n_object_lookups_positive),
57026- atomic_read(&fscache_n_object_created),
57027- atomic_read(&fscache_n_object_lookups_timed_out));
57028+ atomic_read_unchecked(&fscache_n_object_lookups),
57029+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
57030+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
57031+ atomic_read_unchecked(&fscache_n_object_created),
57032+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
57033
57034 seq_printf(m, "Invals : n=%u run=%u\n",
57035- atomic_read(&fscache_n_invalidates),
57036- atomic_read(&fscache_n_invalidates_run));
57037+ atomic_read_unchecked(&fscache_n_invalidates),
57038+ atomic_read_unchecked(&fscache_n_invalidates_run));
57039
57040 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
57041- atomic_read(&fscache_n_updates),
57042- atomic_read(&fscache_n_updates_null),
57043- atomic_read(&fscache_n_updates_run));
57044+ atomic_read_unchecked(&fscache_n_updates),
57045+ atomic_read_unchecked(&fscache_n_updates_null),
57046+ atomic_read_unchecked(&fscache_n_updates_run));
57047
57048 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
57049- atomic_read(&fscache_n_relinquishes),
57050- atomic_read(&fscache_n_relinquishes_null),
57051- atomic_read(&fscache_n_relinquishes_waitcrt),
57052- atomic_read(&fscache_n_relinquishes_retire));
57053+ atomic_read_unchecked(&fscache_n_relinquishes),
57054+ atomic_read_unchecked(&fscache_n_relinquishes_null),
57055+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
57056+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
57057
57058 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
57059- atomic_read(&fscache_n_attr_changed),
57060- atomic_read(&fscache_n_attr_changed_ok),
57061- atomic_read(&fscache_n_attr_changed_nobufs),
57062- atomic_read(&fscache_n_attr_changed_nomem),
57063- atomic_read(&fscache_n_attr_changed_calls));
57064+ atomic_read_unchecked(&fscache_n_attr_changed),
57065+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
57066+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
57067+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
57068+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
57069
57070 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
57071- atomic_read(&fscache_n_allocs),
57072- atomic_read(&fscache_n_allocs_ok),
57073- atomic_read(&fscache_n_allocs_wait),
57074- atomic_read(&fscache_n_allocs_nobufs),
57075- atomic_read(&fscache_n_allocs_intr));
57076+ atomic_read_unchecked(&fscache_n_allocs),
57077+ atomic_read_unchecked(&fscache_n_allocs_ok),
57078+ atomic_read_unchecked(&fscache_n_allocs_wait),
57079+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
57080+ atomic_read_unchecked(&fscache_n_allocs_intr));
57081 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
57082- atomic_read(&fscache_n_alloc_ops),
57083- atomic_read(&fscache_n_alloc_op_waits),
57084- atomic_read(&fscache_n_allocs_object_dead));
57085+ atomic_read_unchecked(&fscache_n_alloc_ops),
57086+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
57087+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
57088
57089 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
57090 " int=%u oom=%u\n",
57091- atomic_read(&fscache_n_retrievals),
57092- atomic_read(&fscache_n_retrievals_ok),
57093- atomic_read(&fscache_n_retrievals_wait),
57094- atomic_read(&fscache_n_retrievals_nodata),
57095- atomic_read(&fscache_n_retrievals_nobufs),
57096- atomic_read(&fscache_n_retrievals_intr),
57097- atomic_read(&fscache_n_retrievals_nomem));
57098+ atomic_read_unchecked(&fscache_n_retrievals),
57099+ atomic_read_unchecked(&fscache_n_retrievals_ok),
57100+ atomic_read_unchecked(&fscache_n_retrievals_wait),
57101+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
57102+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
57103+ atomic_read_unchecked(&fscache_n_retrievals_intr),
57104+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
57105 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
57106- atomic_read(&fscache_n_retrieval_ops),
57107- atomic_read(&fscache_n_retrieval_op_waits),
57108- atomic_read(&fscache_n_retrievals_object_dead));
57109+ atomic_read_unchecked(&fscache_n_retrieval_ops),
57110+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
57111+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
57112
57113 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
57114- atomic_read(&fscache_n_stores),
57115- atomic_read(&fscache_n_stores_ok),
57116- atomic_read(&fscache_n_stores_again),
57117- atomic_read(&fscache_n_stores_nobufs),
57118- atomic_read(&fscache_n_stores_oom));
57119+ atomic_read_unchecked(&fscache_n_stores),
57120+ atomic_read_unchecked(&fscache_n_stores_ok),
57121+ atomic_read_unchecked(&fscache_n_stores_again),
57122+ atomic_read_unchecked(&fscache_n_stores_nobufs),
57123+ atomic_read_unchecked(&fscache_n_stores_oom));
57124 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
57125- atomic_read(&fscache_n_store_ops),
57126- atomic_read(&fscache_n_store_calls),
57127- atomic_read(&fscache_n_store_pages),
57128- atomic_read(&fscache_n_store_radix_deletes),
57129- atomic_read(&fscache_n_store_pages_over_limit));
57130+ atomic_read_unchecked(&fscache_n_store_ops),
57131+ atomic_read_unchecked(&fscache_n_store_calls),
57132+ atomic_read_unchecked(&fscache_n_store_pages),
57133+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
57134+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
57135
57136 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
57137- atomic_read(&fscache_n_store_vmscan_not_storing),
57138- atomic_read(&fscache_n_store_vmscan_gone),
57139- atomic_read(&fscache_n_store_vmscan_busy),
57140- atomic_read(&fscache_n_store_vmscan_cancelled),
57141- atomic_read(&fscache_n_store_vmscan_wait));
57142+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
57143+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
57144+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
57145+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
57146+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
57147
57148 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
57149- atomic_read(&fscache_n_op_pend),
57150- atomic_read(&fscache_n_op_run),
57151- atomic_read(&fscache_n_op_enqueue),
57152- atomic_read(&fscache_n_op_cancelled),
57153- atomic_read(&fscache_n_op_rejected));
57154+ atomic_read_unchecked(&fscache_n_op_pend),
57155+ atomic_read_unchecked(&fscache_n_op_run),
57156+ atomic_read_unchecked(&fscache_n_op_enqueue),
57157+ atomic_read_unchecked(&fscache_n_op_cancelled),
57158+ atomic_read_unchecked(&fscache_n_op_rejected));
57159 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
57160- atomic_read(&fscache_n_op_deferred_release),
57161- atomic_read(&fscache_n_op_release),
57162- atomic_read(&fscache_n_op_gc));
57163+ atomic_read_unchecked(&fscache_n_op_deferred_release),
57164+ atomic_read_unchecked(&fscache_n_op_release),
57165+ atomic_read_unchecked(&fscache_n_op_gc));
57166
57167 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
57168 atomic_read(&fscache_n_cop_alloc_object),
57169diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
57170index aef34b1..59bfd7b 100644
57171--- a/fs/fuse/cuse.c
57172+++ b/fs/fuse/cuse.c
57173@@ -600,10 +600,12 @@ static int __init cuse_init(void)
57174 INIT_LIST_HEAD(&cuse_conntbl[i]);
57175
57176 /* inherit and extend fuse_dev_operations */
57177- cuse_channel_fops = fuse_dev_operations;
57178- cuse_channel_fops.owner = THIS_MODULE;
57179- cuse_channel_fops.open = cuse_channel_open;
57180- cuse_channel_fops.release = cuse_channel_release;
57181+ pax_open_kernel();
57182+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
57183+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
57184+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
57185+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
57186+ pax_close_kernel();
57187
57188 cuse_class = class_create(THIS_MODULE, "cuse");
57189 if (IS_ERR(cuse_class))
57190diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
57191index 1d55f94..088da65 100644
57192--- a/fs/fuse/dev.c
57193+++ b/fs/fuse/dev.c
57194@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57195 ret = 0;
57196 pipe_lock(pipe);
57197
57198- if (!pipe->readers) {
57199+ if (!atomic_read(&pipe->readers)) {
57200 send_sig(SIGPIPE, current, 0);
57201 if (!ret)
57202 ret = -EPIPE;
57203@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57204 page_nr++;
57205 ret += buf->len;
57206
57207- if (pipe->files)
57208+ if (atomic_read(&pipe->files))
57209 do_wakeup = 1;
57210 }
57211
57212diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
57213index 72a5d5b..c991011 100644
57214--- a/fs/fuse/dir.c
57215+++ b/fs/fuse/dir.c
57216@@ -1433,7 +1433,7 @@ static char *read_link(struct dentry *dentry)
57217 return link;
57218 }
57219
57220-static void free_link(char *link)
57221+static void free_link(const char *link)
57222 {
57223 if (!IS_ERR(link))
57224 free_page((unsigned long) link);
57225diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
57226index 64915ee..6bed500 100644
57227--- a/fs/gfs2/inode.c
57228+++ b/fs/gfs2/inode.c
57229@@ -1506,7 +1506,7 @@ out:
57230
57231 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
57232 {
57233- char *s = nd_get_link(nd);
57234+ const char *s = nd_get_link(nd);
57235 if (!IS_ERR(s))
57236 kfree(s);
57237 }
57238diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
57239index d19b30a..ef89c36 100644
57240--- a/fs/hugetlbfs/inode.c
57241+++ b/fs/hugetlbfs/inode.c
57242@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57243 struct mm_struct *mm = current->mm;
57244 struct vm_area_struct *vma;
57245 struct hstate *h = hstate_file(file);
57246+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
57247 struct vm_unmapped_area_info info;
57248
57249 if (len & ~huge_page_mask(h))
57250@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57251 return addr;
57252 }
57253
57254+#ifdef CONFIG_PAX_RANDMMAP
57255+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
57256+#endif
57257+
57258 if (addr) {
57259 addr = ALIGN(addr, huge_page_size(h));
57260 vma = find_vma(mm, addr);
57261- if (TASK_SIZE - len >= addr &&
57262- (!vma || addr + len <= vma->vm_start))
57263+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
57264 return addr;
57265 }
57266
57267 info.flags = 0;
57268 info.length = len;
57269 info.low_limit = TASK_UNMAPPED_BASE;
57270+
57271+#ifdef CONFIG_PAX_RANDMMAP
57272+ if (mm->pax_flags & MF_PAX_RANDMMAP)
57273+ info.low_limit += mm->delta_mmap;
57274+#endif
57275+
57276 info.high_limit = TASK_SIZE;
57277 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
57278 info.align_offset = 0;
57279@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
57280 };
57281 MODULE_ALIAS_FS("hugetlbfs");
57282
57283-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57284+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57285
57286 static int can_do_hugetlb_shm(void)
57287 {
57288diff --git a/fs/inode.c b/fs/inode.c
57289index d6dfb09..602e77e 100644
57290--- a/fs/inode.c
57291+++ b/fs/inode.c
57292@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
57293
57294 #ifdef CONFIG_SMP
57295 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
57296- static atomic_t shared_last_ino;
57297- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
57298+ static atomic_unchecked_t shared_last_ino;
57299+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
57300
57301 res = next - LAST_INO_BATCH;
57302 }
57303diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
57304index 4a6cf28..d3a29d3 100644
57305--- a/fs/jffs2/erase.c
57306+++ b/fs/jffs2/erase.c
57307@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
57308 struct jffs2_unknown_node marker = {
57309 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
57310 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57311- .totlen = cpu_to_je32(c->cleanmarker_size)
57312+ .totlen = cpu_to_je32(c->cleanmarker_size),
57313+ .hdr_crc = cpu_to_je32(0)
57314 };
57315
57316 jffs2_prealloc_raw_node_refs(c, jeb, 1);
57317diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
57318index a6597d6..41b30ec 100644
57319--- a/fs/jffs2/wbuf.c
57320+++ b/fs/jffs2/wbuf.c
57321@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
57322 {
57323 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
57324 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57325- .totlen = constant_cpu_to_je32(8)
57326+ .totlen = constant_cpu_to_je32(8),
57327+ .hdr_crc = constant_cpu_to_je32(0)
57328 };
57329
57330 /*
57331diff --git a/fs/jfs/super.c b/fs/jfs/super.c
57332index 6669aa2..36b033d 100644
57333--- a/fs/jfs/super.c
57334+++ b/fs/jfs/super.c
57335@@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
57336
57337 jfs_inode_cachep =
57338 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
57339- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
57340+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
57341 init_once);
57342 if (jfs_inode_cachep == NULL)
57343 return -ENOMEM;
57344diff --git a/fs/libfs.c b/fs/libfs.c
57345index 3a3a9b5..3a9b074 100644
57346--- a/fs/libfs.c
57347+++ b/fs/libfs.c
57348@@ -150,6 +150,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57349
57350 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
57351 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
57352+ char d_name[sizeof(next->d_iname)];
57353+ const unsigned char *name;
57354+
57355 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
57356 if (!simple_positive(next)) {
57357 spin_unlock(&next->d_lock);
57358@@ -158,7 +161,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57359
57360 spin_unlock(&next->d_lock);
57361 spin_unlock(&dentry->d_lock);
57362- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
57363+ name = next->d_name.name;
57364+ if (name == next->d_iname) {
57365+ memcpy(d_name, name, next->d_name.len);
57366+ name = d_name;
57367+ }
57368+ if (!dir_emit(ctx, name, next->d_name.len,
57369 next->d_inode->i_ino, dt_type(next->d_inode)))
57370 return 0;
57371 spin_lock(&dentry->d_lock);
57372diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
57373index acd3947..1f896e2 100644
57374--- a/fs/lockd/clntproc.c
57375+++ b/fs/lockd/clntproc.c
57376@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
57377 /*
57378 * Cookie counter for NLM requests
57379 */
57380-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
57381+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
57382
57383 void nlmclnt_next_cookie(struct nlm_cookie *c)
57384 {
57385- u32 cookie = atomic_inc_return(&nlm_cookie);
57386+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
57387
57388 memcpy(c->data, &cookie, 4);
57389 c->len=4;
57390diff --git a/fs/locks.c b/fs/locks.c
57391index b27a300..4156d0b 100644
57392--- a/fs/locks.c
57393+++ b/fs/locks.c
57394@@ -2183,16 +2183,16 @@ void locks_remove_flock(struct file *filp)
57395 return;
57396
57397 if (filp->f_op && filp->f_op->flock) {
57398- struct file_lock fl = {
57399+ struct file_lock flock = {
57400 .fl_pid = current->tgid,
57401 .fl_file = filp,
57402 .fl_flags = FL_FLOCK,
57403 .fl_type = F_UNLCK,
57404 .fl_end = OFFSET_MAX,
57405 };
57406- filp->f_op->flock(filp, F_SETLKW, &fl);
57407- if (fl.fl_ops && fl.fl_ops->fl_release_private)
57408- fl.fl_ops->fl_release_private(&fl);
57409+ filp->f_op->flock(filp, F_SETLKW, &flock);
57410+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
57411+ flock.fl_ops->fl_release_private(&flock);
57412 }
57413
57414 spin_lock(&inode->i_lock);
57415diff --git a/fs/namei.c b/fs/namei.c
57416index 7720fbd..7934bb2 100644
57417--- a/fs/namei.c
57418+++ b/fs/namei.c
57419@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
57420 if (ret != -EACCES)
57421 return ret;
57422
57423+#ifdef CONFIG_GRKERNSEC
57424+ /* we'll block if we have to log due to a denied capability use */
57425+ if (mask & MAY_NOT_BLOCK)
57426+ return -ECHILD;
57427+#endif
57428+
57429 if (S_ISDIR(inode->i_mode)) {
57430 /* DACs are overridable for directories */
57431- if (inode_capable(inode, CAP_DAC_OVERRIDE))
57432- return 0;
57433 if (!(mask & MAY_WRITE))
57434- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57435+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57436+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57437 return 0;
57438+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
57439+ return 0;
57440 return -EACCES;
57441 }
57442 /*
57443+ * Searching includes executable on directories, else just read.
57444+ */
57445+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57446+ if (mask == MAY_READ)
57447+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57448+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57449+ return 0;
57450+
57451+ /*
57452 * Read/write DACs are always overridable.
57453 * Executable DACs are overridable when there is
57454 * at least one exec bit set.
57455@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
57456 if (inode_capable(inode, CAP_DAC_OVERRIDE))
57457 return 0;
57458
57459- /*
57460- * Searching includes executable on directories, else just read.
57461- */
57462- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57463- if (mask == MAY_READ)
57464- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57465- return 0;
57466-
57467 return -EACCES;
57468 }
57469
57470@@ -820,7 +828,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57471 {
57472 struct dentry *dentry = link->dentry;
57473 int error;
57474- char *s;
57475+ const char *s;
57476
57477 BUG_ON(nd->flags & LOOKUP_RCU);
57478
57479@@ -841,6 +849,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57480 if (error)
57481 goto out_put_nd_path;
57482
57483+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
57484+ dentry->d_inode, dentry, nd->path.mnt)) {
57485+ error = -EACCES;
57486+ goto out_put_nd_path;
57487+ }
57488+
57489 nd->last_type = LAST_BIND;
57490 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
57491 error = PTR_ERR(*p);
57492@@ -1588,6 +1602,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
57493 if (res)
57494 break;
57495 res = walk_component(nd, path, LOOKUP_FOLLOW);
57496+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
57497+ res = -EACCES;
57498 put_link(nd, &link, cookie);
57499 } while (res > 0);
57500
57501@@ -1686,7 +1702,7 @@ EXPORT_SYMBOL(full_name_hash);
57502 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
57503 {
57504 unsigned long a, b, adata, bdata, mask, hash, len;
57505- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
57506+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
57507
57508 hash = a = 0;
57509 len = -sizeof(unsigned long);
57510@@ -1967,6 +1983,8 @@ static int path_lookupat(int dfd, const char *name,
57511 if (err)
57512 break;
57513 err = lookup_last(nd, &path);
57514+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
57515+ err = -EACCES;
57516 put_link(nd, &link, cookie);
57517 }
57518 }
57519@@ -1974,6 +1992,13 @@ static int path_lookupat(int dfd, const char *name,
57520 if (!err)
57521 err = complete_walk(nd);
57522
57523+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
57524+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
57525+ path_put(&nd->path);
57526+ err = -ENOENT;
57527+ }
57528+ }
57529+
57530 if (!err && nd->flags & LOOKUP_DIRECTORY) {
57531 if (!can_lookup(nd->inode)) {
57532 path_put(&nd->path);
57533@@ -2001,8 +2026,15 @@ static int filename_lookup(int dfd, struct filename *name,
57534 retval = path_lookupat(dfd, name->name,
57535 flags | LOOKUP_REVAL, nd);
57536
57537- if (likely(!retval))
57538+ if (likely(!retval)) {
57539 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
57540+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
57541+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
57542+ path_put(&nd->path);
57543+ return -ENOENT;
57544+ }
57545+ }
57546+ }
57547 return retval;
57548 }
57549
57550@@ -2380,6 +2412,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
57551 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
57552 return -EPERM;
57553
57554+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
57555+ return -EPERM;
57556+ if (gr_handle_rawio(inode))
57557+ return -EPERM;
57558+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
57559+ return -EACCES;
57560+
57561 return 0;
57562 }
57563
57564@@ -2601,7 +2640,7 @@ looked_up:
57565 * cleared otherwise prior to returning.
57566 */
57567 static int lookup_open(struct nameidata *nd, struct path *path,
57568- struct file *file,
57569+ struct path *link, struct file *file,
57570 const struct open_flags *op,
57571 bool got_write, int *opened)
57572 {
57573@@ -2636,6 +2675,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
57574 /* Negative dentry, just create the file */
57575 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
57576 umode_t mode = op->mode;
57577+
57578+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
57579+ error = -EACCES;
57580+ goto out_dput;
57581+ }
57582+
57583+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
57584+ error = -EACCES;
57585+ goto out_dput;
57586+ }
57587+
57588 if (!IS_POSIXACL(dir->d_inode))
57589 mode &= ~current_umask();
57590 /*
57591@@ -2657,6 +2707,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
57592 nd->flags & LOOKUP_EXCL);
57593 if (error)
57594 goto out_dput;
57595+ else
57596+ gr_handle_create(dentry, nd->path.mnt);
57597 }
57598 out_no_open:
57599 path->dentry = dentry;
57600@@ -2671,7 +2723,7 @@ out_dput:
57601 /*
57602 * Handle the last step of open()
57603 */
57604-static int do_last(struct nameidata *nd, struct path *path,
57605+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
57606 struct file *file, const struct open_flags *op,
57607 int *opened, struct filename *name)
57608 {
57609@@ -2721,6 +2773,15 @@ static int do_last(struct nameidata *nd, struct path *path,
57610 if (error)
57611 return error;
57612
57613+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
57614+ error = -ENOENT;
57615+ goto out;
57616+ }
57617+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
57618+ error = -EACCES;
57619+ goto out;
57620+ }
57621+
57622 audit_inode(name, dir, LOOKUP_PARENT);
57623 error = -EISDIR;
57624 /* trailing slashes? */
57625@@ -2740,7 +2801,7 @@ retry_lookup:
57626 */
57627 }
57628 mutex_lock(&dir->d_inode->i_mutex);
57629- error = lookup_open(nd, path, file, op, got_write, opened);
57630+ error = lookup_open(nd, path, link, file, op, got_write, opened);
57631 mutex_unlock(&dir->d_inode->i_mutex);
57632
57633 if (error <= 0) {
57634@@ -2764,11 +2825,28 @@ retry_lookup:
57635 goto finish_open_created;
57636 }
57637
57638+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
57639+ error = -ENOENT;
57640+ goto exit_dput;
57641+ }
57642+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
57643+ error = -EACCES;
57644+ goto exit_dput;
57645+ }
57646+
57647 /*
57648 * create/update audit record if it already exists.
57649 */
57650- if (path->dentry->d_inode)
57651+ if (path->dentry->d_inode) {
57652+ /* only check if O_CREAT is specified, all other checks need to go
57653+ into may_open */
57654+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
57655+ error = -EACCES;
57656+ goto exit_dput;
57657+ }
57658+
57659 audit_inode(name, path->dentry, 0);
57660+ }
57661
57662 /*
57663 * If atomic_open() acquired write access it is dropped now due to
57664@@ -2809,6 +2887,11 @@ finish_lookup:
57665 }
57666 }
57667 BUG_ON(inode != path->dentry->d_inode);
57668+ /* if we're resolving a symlink to another symlink */
57669+ if (link && gr_handle_symlink_owner(link, inode)) {
57670+ error = -EACCES;
57671+ goto out;
57672+ }
57673 return 1;
57674 }
57675
57676@@ -2818,7 +2901,6 @@ finish_lookup:
57677 save_parent.dentry = nd->path.dentry;
57678 save_parent.mnt = mntget(path->mnt);
57679 nd->path.dentry = path->dentry;
57680-
57681 }
57682 nd->inode = inode;
57683 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
57684@@ -2828,7 +2910,18 @@ finish_open:
57685 path_put(&save_parent);
57686 return error;
57687 }
57688+
57689+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
57690+ error = -ENOENT;
57691+ goto out;
57692+ }
57693+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
57694+ error = -EACCES;
57695+ goto out;
57696+ }
57697+
57698 audit_inode(name, nd->path.dentry, 0);
57699+
57700 error = -EISDIR;
57701 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
57702 goto out;
57703@@ -2991,7 +3084,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
57704 if (unlikely(error))
57705 goto out;
57706
57707- error = do_last(nd, &path, file, op, &opened, pathname);
57708+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
57709 while (unlikely(error > 0)) { /* trailing symlink */
57710 struct path link = path;
57711 void *cookie;
57712@@ -3009,7 +3102,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
57713 error = follow_link(&link, nd, &cookie);
57714 if (unlikely(error))
57715 break;
57716- error = do_last(nd, &path, file, op, &opened, pathname);
57717+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
57718 put_link(nd, &link, cookie);
57719 }
57720 out:
57721@@ -3109,8 +3202,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
57722 goto unlock;
57723
57724 error = -EEXIST;
57725- if (dentry->d_inode)
57726+ if (dentry->d_inode) {
57727+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
57728+ error = -ENOENT;
57729+ }
57730 goto fail;
57731+ }
57732 /*
57733 * Special case - lookup gave negative, but... we had foo/bar/
57734 * From the vfs_mknod() POV we just have a negative dentry -
57735@@ -3162,6 +3259,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
57736 }
57737 EXPORT_SYMBOL(user_path_create);
57738
57739+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
57740+{
57741+ struct filename *tmp = getname(pathname);
57742+ struct dentry *res;
57743+ if (IS_ERR(tmp))
57744+ return ERR_CAST(tmp);
57745+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
57746+ if (IS_ERR(res))
57747+ putname(tmp);
57748+ else
57749+ *to = tmp;
57750+ return res;
57751+}
57752+
57753 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
57754 {
57755 int error = may_create(dir, dentry);
57756@@ -3224,6 +3335,17 @@ retry:
57757
57758 if (!IS_POSIXACL(path.dentry->d_inode))
57759 mode &= ~current_umask();
57760+
57761+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
57762+ error = -EPERM;
57763+ goto out;
57764+ }
57765+
57766+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
57767+ error = -EACCES;
57768+ goto out;
57769+ }
57770+
57771 error = security_path_mknod(&path, dentry, mode, dev);
57772 if (error)
57773 goto out;
57774@@ -3240,6 +3362,8 @@ retry:
57775 break;
57776 }
57777 out:
57778+ if (!error)
57779+ gr_handle_create(dentry, path.mnt);
57780 done_path_create(&path, dentry);
57781 if (retry_estale(error, lookup_flags)) {
57782 lookup_flags |= LOOKUP_REVAL;
57783@@ -3292,9 +3416,16 @@ retry:
57784
57785 if (!IS_POSIXACL(path.dentry->d_inode))
57786 mode &= ~current_umask();
57787+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
57788+ error = -EACCES;
57789+ goto out;
57790+ }
57791 error = security_path_mkdir(&path, dentry, mode);
57792 if (!error)
57793 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
57794+ if (!error)
57795+ gr_handle_create(dentry, path.mnt);
57796+out:
57797 done_path_create(&path, dentry);
57798 if (retry_estale(error, lookup_flags)) {
57799 lookup_flags |= LOOKUP_REVAL;
57800@@ -3375,6 +3506,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
57801 struct filename *name;
57802 struct dentry *dentry;
57803 struct nameidata nd;
57804+ ino_t saved_ino = 0;
57805+ dev_t saved_dev = 0;
57806 unsigned int lookup_flags = 0;
57807 retry:
57808 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
57809@@ -3407,10 +3540,21 @@ retry:
57810 error = -ENOENT;
57811 goto exit3;
57812 }
57813+
57814+ saved_ino = dentry->d_inode->i_ino;
57815+ saved_dev = gr_get_dev_from_dentry(dentry);
57816+
57817+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
57818+ error = -EACCES;
57819+ goto exit3;
57820+ }
57821+
57822 error = security_path_rmdir(&nd.path, dentry);
57823 if (error)
57824 goto exit3;
57825 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
57826+ if (!error && (saved_dev || saved_ino))
57827+ gr_handle_delete(saved_ino, saved_dev);
57828 exit3:
57829 dput(dentry);
57830 exit2:
57831@@ -3476,6 +3620,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
57832 struct dentry *dentry;
57833 struct nameidata nd;
57834 struct inode *inode = NULL;
57835+ ino_t saved_ino = 0;
57836+ dev_t saved_dev = 0;
57837 unsigned int lookup_flags = 0;
57838 retry:
57839 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
57840@@ -3502,10 +3648,22 @@ retry:
57841 if (!inode)
57842 goto slashes;
57843 ihold(inode);
57844+
57845+ if (inode->i_nlink <= 1) {
57846+ saved_ino = inode->i_ino;
57847+ saved_dev = gr_get_dev_from_dentry(dentry);
57848+ }
57849+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
57850+ error = -EACCES;
57851+ goto exit2;
57852+ }
57853+
57854 error = security_path_unlink(&nd.path, dentry);
57855 if (error)
57856 goto exit2;
57857 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
57858+ if (!error && (saved_ino || saved_dev))
57859+ gr_handle_delete(saved_ino, saved_dev);
57860 exit2:
57861 dput(dentry);
57862 }
57863@@ -3583,9 +3741,17 @@ retry:
57864 if (IS_ERR(dentry))
57865 goto out_putname;
57866
57867+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
57868+ error = -EACCES;
57869+ goto out;
57870+ }
57871+
57872 error = security_path_symlink(&path, dentry, from->name);
57873 if (!error)
57874 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
57875+ if (!error)
57876+ gr_handle_create(dentry, path.mnt);
57877+out:
57878 done_path_create(&path, dentry);
57879 if (retry_estale(error, lookup_flags)) {
57880 lookup_flags |= LOOKUP_REVAL;
57881@@ -3665,6 +3831,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
57882 {
57883 struct dentry *new_dentry;
57884 struct path old_path, new_path;
57885+ struct filename *to = NULL;
57886 int how = 0;
57887 int error;
57888
57889@@ -3688,7 +3855,7 @@ retry:
57890 if (error)
57891 return error;
57892
57893- new_dentry = user_path_create(newdfd, newname, &new_path,
57894+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
57895 (how & LOOKUP_REVAL));
57896 error = PTR_ERR(new_dentry);
57897 if (IS_ERR(new_dentry))
57898@@ -3700,11 +3867,28 @@ retry:
57899 error = may_linkat(&old_path);
57900 if (unlikely(error))
57901 goto out_dput;
57902+
57903+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
57904+ old_path.dentry->d_inode,
57905+ old_path.dentry->d_inode->i_mode, to)) {
57906+ error = -EACCES;
57907+ goto out_dput;
57908+ }
57909+
57910+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
57911+ old_path.dentry, old_path.mnt, to)) {
57912+ error = -EACCES;
57913+ goto out_dput;
57914+ }
57915+
57916 error = security_path_link(old_path.dentry, &new_path, new_dentry);
57917 if (error)
57918 goto out_dput;
57919 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
57920+ if (!error)
57921+ gr_handle_create(new_dentry, new_path.mnt);
57922 out_dput:
57923+ putname(to);
57924 done_path_create(&new_path, new_dentry);
57925 if (retry_estale(error, how)) {
57926 how |= LOOKUP_REVAL;
57927@@ -3950,12 +4134,21 @@ retry:
57928 if (new_dentry == trap)
57929 goto exit5;
57930
57931+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
57932+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
57933+ to);
57934+ if (error)
57935+ goto exit5;
57936+
57937 error = security_path_rename(&oldnd.path, old_dentry,
57938 &newnd.path, new_dentry);
57939 if (error)
57940 goto exit5;
57941 error = vfs_rename(old_dir->d_inode, old_dentry,
57942 new_dir->d_inode, new_dentry);
57943+ if (!error)
57944+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
57945+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
57946 exit5:
57947 dput(new_dentry);
57948 exit4:
57949@@ -3987,6 +4180,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
57950
57951 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
57952 {
57953+ char tmpbuf[64];
57954+ const char *newlink;
57955 int len;
57956
57957 len = PTR_ERR(link);
57958@@ -3996,7 +4191,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
57959 len = strlen(link);
57960 if (len > (unsigned) buflen)
57961 len = buflen;
57962- if (copy_to_user(buffer, link, len))
57963+
57964+ if (len < sizeof(tmpbuf)) {
57965+ memcpy(tmpbuf, link, len);
57966+ newlink = tmpbuf;
57967+ } else
57968+ newlink = link;
57969+
57970+ if (copy_to_user(buffer, newlink, len))
57971 len = -EFAULT;
57972 out:
57973 return len;
57974diff --git a/fs/namespace.c b/fs/namespace.c
57975index a45ba4f..b4c7d07 100644
57976--- a/fs/namespace.c
57977+++ b/fs/namespace.c
57978@@ -1265,6 +1265,9 @@ static int do_umount(struct mount *mnt, int flags)
57979 if (!(sb->s_flags & MS_RDONLY))
57980 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
57981 up_write(&sb->s_umount);
57982+
57983+ gr_log_remount(mnt->mnt_devname, retval);
57984+
57985 return retval;
57986 }
57987
57988@@ -1283,6 +1286,9 @@ static int do_umount(struct mount *mnt, int flags)
57989 }
57990 br_write_unlock(&vfsmount_lock);
57991 namespace_unlock();
57992+
57993+ gr_log_unmount(mnt->mnt_devname, retval);
57994+
57995 return retval;
57996 }
57997
57998@@ -1302,7 +1308,7 @@ static inline bool may_mount(void)
57999 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
58000 */
58001
58002-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
58003+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
58004 {
58005 struct path path;
58006 struct mount *mnt;
58007@@ -1342,7 +1348,7 @@ out:
58008 /*
58009 * The 2.0 compatible umount. No flags.
58010 */
58011-SYSCALL_DEFINE1(oldumount, char __user *, name)
58012+SYSCALL_DEFINE1(oldumount, const char __user *, name)
58013 {
58014 return sys_umount(name, 0);
58015 }
58016@@ -2313,6 +2319,16 @@ long do_mount(const char *dev_name, const char *dir_name,
58017 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
58018 MS_STRICTATIME);
58019
58020+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
58021+ retval = -EPERM;
58022+ goto dput_out;
58023+ }
58024+
58025+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
58026+ retval = -EPERM;
58027+ goto dput_out;
58028+ }
58029+
58030 if (flags & MS_REMOUNT)
58031 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
58032 data_page);
58033@@ -2327,6 +2343,9 @@ long do_mount(const char *dev_name, const char *dir_name,
58034 dev_name, data_page);
58035 dput_out:
58036 path_put(&path);
58037+
58038+ gr_log_mount(dev_name, dir_name, retval);
58039+
58040 return retval;
58041 }
58042
58043@@ -2344,7 +2363,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
58044 * number incrementing at 10Ghz will take 12,427 years to wrap which
58045 * is effectively never, so we can ignore the possibility.
58046 */
58047-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
58048+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
58049
58050 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58051 {
58052@@ -2359,7 +2378,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58053 kfree(new_ns);
58054 return ERR_PTR(ret);
58055 }
58056- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
58057+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
58058 atomic_set(&new_ns->count, 1);
58059 new_ns->root = NULL;
58060 INIT_LIST_HEAD(&new_ns->list);
58061@@ -2373,7 +2392,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58062 * Allocate a new namespace structure and populate it with contents
58063 * copied from the namespace of the passed in task structure.
58064 */
58065-static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
58066+static __latent_entropy struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
58067 struct user_namespace *user_ns, struct fs_struct *fs)
58068 {
58069 struct mnt_namespace *new_ns;
58070@@ -2500,8 +2519,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
58071 }
58072 EXPORT_SYMBOL(mount_subtree);
58073
58074-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
58075- char __user *, type, unsigned long, flags, void __user *, data)
58076+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
58077+ const char __user *, type, unsigned long, flags, void __user *, data)
58078 {
58079 int ret;
58080 char *kernel_type;
58081@@ -2614,6 +2633,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
58082 if (error)
58083 goto out2;
58084
58085+ if (gr_handle_chroot_pivot()) {
58086+ error = -EPERM;
58087+ goto out2;
58088+ }
58089+
58090 get_fs_root(current->fs, &root);
58091 old_mp = lock_mount(&old);
58092 error = PTR_ERR(old_mp);
58093@@ -2864,7 +2888,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
58094 !nsown_capable(CAP_SYS_ADMIN))
58095 return -EPERM;
58096
58097- if (fs->users != 1)
58098+ if (atomic_read(&fs->users) != 1)
58099 return -EINVAL;
58100
58101 get_mnt_ns(mnt_ns);
58102diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
58103index f4ccfe6..a5cf064 100644
58104--- a/fs/nfs/callback_xdr.c
58105+++ b/fs/nfs/callback_xdr.c
58106@@ -51,7 +51,7 @@ struct callback_op {
58107 callback_decode_arg_t decode_args;
58108 callback_encode_res_t encode_res;
58109 long res_maxsize;
58110-};
58111+} __do_const;
58112
58113 static struct callback_op callback_ops[];
58114
58115diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
58116index 941246f..17d8724 100644
58117--- a/fs/nfs/inode.c
58118+++ b/fs/nfs/inode.c
58119@@ -1138,16 +1138,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
58120 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
58121 }
58122
58123-static atomic_long_t nfs_attr_generation_counter;
58124+static atomic_long_unchecked_t nfs_attr_generation_counter;
58125
58126 static unsigned long nfs_read_attr_generation_counter(void)
58127 {
58128- return atomic_long_read(&nfs_attr_generation_counter);
58129+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
58130 }
58131
58132 unsigned long nfs_inc_attr_generation_counter(void)
58133 {
58134- return atomic_long_inc_return(&nfs_attr_generation_counter);
58135+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
58136 }
58137
58138 void nfs_fattr_init(struct nfs_fattr *fattr)
58139diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
58140index 419572f..5414a23 100644
58141--- a/fs/nfsd/nfs4proc.c
58142+++ b/fs/nfsd/nfs4proc.c
58143@@ -1168,7 +1168,7 @@ struct nfsd4_operation {
58144 nfsd4op_rsize op_rsize_bop;
58145 stateid_getter op_get_currentstateid;
58146 stateid_setter op_set_currentstateid;
58147-};
58148+} __do_const;
58149
58150 static struct nfsd4_operation nfsd4_ops[];
58151
58152diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
58153index c2a4701..fd80e29 100644
58154--- a/fs/nfsd/nfs4xdr.c
58155+++ b/fs/nfsd/nfs4xdr.c
58156@@ -1498,7 +1498,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
58157
58158 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
58159
58160-static nfsd4_dec nfsd4_dec_ops[] = {
58161+static const nfsd4_dec nfsd4_dec_ops[] = {
58162 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58163 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58164 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58165@@ -1538,7 +1538,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
58166 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
58167 };
58168
58169-static nfsd4_dec nfsd41_dec_ops[] = {
58170+static const nfsd4_dec nfsd41_dec_ops[] = {
58171 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58172 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58173 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58174@@ -1600,7 +1600,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
58175 };
58176
58177 struct nfsd4_minorversion_ops {
58178- nfsd4_dec *decoders;
58179+ const nfsd4_dec *decoders;
58180 int nops;
58181 };
58182
58183diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
58184index e76244e..9fe8f2f1 100644
58185--- a/fs/nfsd/nfscache.c
58186+++ b/fs/nfsd/nfscache.c
58187@@ -526,14 +526,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
58188 {
58189 struct svc_cacherep *rp = rqstp->rq_cacherep;
58190 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
58191- int len;
58192+ long len;
58193 size_t bufsize = 0;
58194
58195 if (!rp)
58196 return;
58197
58198- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
58199- len >>= 2;
58200+ if (statp) {
58201+ len = (char*)statp - (char*)resv->iov_base;
58202+ len = resv->iov_len - len;
58203+ len >>= 2;
58204+ }
58205
58206 /* Don't cache excessive amounts of data and XDR failures */
58207 if (!statp || len > (256 >> 2)) {
58208diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
58209index c827acb..b253b77 100644
58210--- a/fs/nfsd/vfs.c
58211+++ b/fs/nfsd/vfs.c
58212@@ -968,7 +968,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58213 } else {
58214 oldfs = get_fs();
58215 set_fs(KERNEL_DS);
58216- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
58217+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
58218 set_fs(oldfs);
58219 }
58220
58221@@ -1055,7 +1055,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58222
58223 /* Write the data. */
58224 oldfs = get_fs(); set_fs(KERNEL_DS);
58225- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
58226+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
58227 set_fs(oldfs);
58228 if (host_err < 0)
58229 goto out_nfserr;
58230@@ -1601,7 +1601,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
58231 */
58232
58233 oldfs = get_fs(); set_fs(KERNEL_DS);
58234- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
58235+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
58236 set_fs(oldfs);
58237
58238 if (host_err < 0)
58239diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
58240index fea6bd5..8ee9d81 100644
58241--- a/fs/nls/nls_base.c
58242+++ b/fs/nls/nls_base.c
58243@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
58244
58245 int register_nls(struct nls_table * nls)
58246 {
58247- struct nls_table ** tmp = &tables;
58248+ struct nls_table *tmp = tables;
58249
58250 if (nls->next)
58251 return -EBUSY;
58252
58253 spin_lock(&nls_lock);
58254- while (*tmp) {
58255- if (nls == *tmp) {
58256+ while (tmp) {
58257+ if (nls == tmp) {
58258 spin_unlock(&nls_lock);
58259 return -EBUSY;
58260 }
58261- tmp = &(*tmp)->next;
58262+ tmp = tmp->next;
58263 }
58264- nls->next = tables;
58265+ pax_open_kernel();
58266+ *(struct nls_table **)&nls->next = tables;
58267+ pax_close_kernel();
58268 tables = nls;
58269 spin_unlock(&nls_lock);
58270 return 0;
58271@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
58272
58273 int unregister_nls(struct nls_table * nls)
58274 {
58275- struct nls_table ** tmp = &tables;
58276+ struct nls_table * const * tmp = &tables;
58277
58278 spin_lock(&nls_lock);
58279 while (*tmp) {
58280 if (nls == *tmp) {
58281- *tmp = nls->next;
58282+ pax_open_kernel();
58283+ *(struct nls_table **)tmp = nls->next;
58284+ pax_close_kernel();
58285 spin_unlock(&nls_lock);
58286 return 0;
58287 }
58288diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
58289index 7424929..35f6be5 100644
58290--- a/fs/nls/nls_euc-jp.c
58291+++ b/fs/nls/nls_euc-jp.c
58292@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
58293 p_nls = load_nls("cp932");
58294
58295 if (p_nls) {
58296- table.charset2upper = p_nls->charset2upper;
58297- table.charset2lower = p_nls->charset2lower;
58298+ pax_open_kernel();
58299+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58300+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58301+ pax_close_kernel();
58302 return register_nls(&table);
58303 }
58304
58305diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
58306index e7bc1d7..06bd4bb 100644
58307--- a/fs/nls/nls_koi8-ru.c
58308+++ b/fs/nls/nls_koi8-ru.c
58309@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
58310 p_nls = load_nls("koi8-u");
58311
58312 if (p_nls) {
58313- table.charset2upper = p_nls->charset2upper;
58314- table.charset2lower = p_nls->charset2lower;
58315+ pax_open_kernel();
58316+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58317+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58318+ pax_close_kernel();
58319 return register_nls(&table);
58320 }
58321
58322diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
58323index e44cb64..4807084 100644
58324--- a/fs/notify/fanotify/fanotify_user.c
58325+++ b/fs/notify/fanotify/fanotify_user.c
58326@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
58327
58328 fd = fanotify_event_metadata.fd;
58329 ret = -EFAULT;
58330- if (copy_to_user(buf, &fanotify_event_metadata,
58331- fanotify_event_metadata.event_len))
58332+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
58333+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
58334 goto out_close_fd;
58335
58336 ret = prepare_for_access_response(group, event, fd);
58337diff --git a/fs/notify/notification.c b/fs/notify/notification.c
58338index 7b51b05..5ea5ef6 100644
58339--- a/fs/notify/notification.c
58340+++ b/fs/notify/notification.c
58341@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
58342 * get set to 0 so it will never get 'freed'
58343 */
58344 static struct fsnotify_event *q_overflow_event;
58345-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58346+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58347
58348 /**
58349 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
58350@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58351 */
58352 u32 fsnotify_get_cookie(void)
58353 {
58354- return atomic_inc_return(&fsnotify_sync_cookie);
58355+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
58356 }
58357 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
58358
58359diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
58360index 9e38daf..5727cae 100644
58361--- a/fs/ntfs/dir.c
58362+++ b/fs/ntfs/dir.c
58363@@ -1310,7 +1310,7 @@ find_next_index_buffer:
58364 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
58365 ~(s64)(ndir->itype.index.block_size - 1)));
58366 /* Bounds checks. */
58367- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58368+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58369 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
58370 "inode 0x%lx or driver bug.", vdir->i_ino);
58371 goto err_out;
58372diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
58373index c5670b8..2b43d9b 100644
58374--- a/fs/ntfs/file.c
58375+++ b/fs/ntfs/file.c
58376@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
58377 char *addr;
58378 size_t total = 0;
58379 unsigned len;
58380- int left;
58381+ unsigned left;
58382
58383 do {
58384 len = PAGE_CACHE_SIZE - ofs;
58385@@ -2241,6 +2241,6 @@ const struct inode_operations ntfs_file_inode_ops = {
58386 #endif /* NTFS_RW */
58387 };
58388
58389-const struct file_operations ntfs_empty_file_ops = {};
58390+const struct file_operations ntfs_empty_file_ops __read_only;
58391
58392-const struct inode_operations ntfs_empty_inode_ops = {};
58393+const struct inode_operations ntfs_empty_inode_ops __read_only;
58394diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
58395index 82650d5..db37dcf 100644
58396--- a/fs/ntfs/super.c
58397+++ b/fs/ntfs/super.c
58398@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58399 if (!silent)
58400 ntfs_error(sb, "Primary boot sector is invalid.");
58401 } else if (!silent)
58402- ntfs_error(sb, read_err_str, "primary");
58403+ ntfs_error(sb, read_err_str, "%s", "primary");
58404 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
58405 if (bh_primary)
58406 brelse(bh_primary);
58407@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58408 goto hotfix_primary_boot_sector;
58409 brelse(bh_backup);
58410 } else if (!silent)
58411- ntfs_error(sb, read_err_str, "backup");
58412+ ntfs_error(sb, read_err_str, "%s", "backup");
58413 /* Try to read NT3.51- backup boot sector. */
58414 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
58415 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
58416@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58417 "sector.");
58418 brelse(bh_backup);
58419 } else if (!silent)
58420- ntfs_error(sb, read_err_str, "backup");
58421+ ntfs_error(sb, read_err_str, "%s", "backup");
58422 /* We failed. Cleanup and return. */
58423 if (bh_primary)
58424 brelse(bh_primary);
58425diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
58426index aebeacd..0dcdd26 100644
58427--- a/fs/ocfs2/localalloc.c
58428+++ b/fs/ocfs2/localalloc.c
58429@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
58430 goto bail;
58431 }
58432
58433- atomic_inc(&osb->alloc_stats.moves);
58434+ atomic_inc_unchecked(&osb->alloc_stats.moves);
58435
58436 bail:
58437 if (handle)
58438diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
58439index 3a90347..c40bef8 100644
58440--- a/fs/ocfs2/ocfs2.h
58441+++ b/fs/ocfs2/ocfs2.h
58442@@ -235,11 +235,11 @@ enum ocfs2_vol_state
58443
58444 struct ocfs2_alloc_stats
58445 {
58446- atomic_t moves;
58447- atomic_t local_data;
58448- atomic_t bitmap_data;
58449- atomic_t bg_allocs;
58450- atomic_t bg_extends;
58451+ atomic_unchecked_t moves;
58452+ atomic_unchecked_t local_data;
58453+ atomic_unchecked_t bitmap_data;
58454+ atomic_unchecked_t bg_allocs;
58455+ atomic_unchecked_t bg_extends;
58456 };
58457
58458 enum ocfs2_local_alloc_state
58459diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
58460index 5397c07..54afc55 100644
58461--- a/fs/ocfs2/suballoc.c
58462+++ b/fs/ocfs2/suballoc.c
58463@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
58464 mlog_errno(status);
58465 goto bail;
58466 }
58467- atomic_inc(&osb->alloc_stats.bg_extends);
58468+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
58469
58470 /* You should never ask for this much metadata */
58471 BUG_ON(bits_wanted >
58472@@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
58473 mlog_errno(status);
58474 goto bail;
58475 }
58476- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58477+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58478
58479 *suballoc_loc = res.sr_bg_blkno;
58480 *suballoc_bit_start = res.sr_bit_offset;
58481@@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
58482 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
58483 res->sr_bits);
58484
58485- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58486+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58487
58488 BUG_ON(res->sr_bits != 1);
58489
58490@@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
58491 mlog_errno(status);
58492 goto bail;
58493 }
58494- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58495+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58496
58497 BUG_ON(res.sr_bits != 1);
58498
58499@@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
58500 cluster_start,
58501 num_clusters);
58502 if (!status)
58503- atomic_inc(&osb->alloc_stats.local_data);
58504+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
58505 } else {
58506 if (min_clusters > (osb->bitmap_cpg - 1)) {
58507 /* The only paths asking for contiguousness
58508@@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
58509 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
58510 res.sr_bg_blkno,
58511 res.sr_bit_offset);
58512- atomic_inc(&osb->alloc_stats.bitmap_data);
58513+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
58514 *num_clusters = res.sr_bits;
58515 }
58516 }
58517diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
58518index 121da2d..a0232bc 100644
58519--- a/fs/ocfs2/super.c
58520+++ b/fs/ocfs2/super.c
58521@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
58522 "%10s => GlobalAllocs: %d LocalAllocs: %d "
58523 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
58524 "Stats",
58525- atomic_read(&osb->alloc_stats.bitmap_data),
58526- atomic_read(&osb->alloc_stats.local_data),
58527- atomic_read(&osb->alloc_stats.bg_allocs),
58528- atomic_read(&osb->alloc_stats.moves),
58529- atomic_read(&osb->alloc_stats.bg_extends));
58530+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
58531+ atomic_read_unchecked(&osb->alloc_stats.local_data),
58532+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
58533+ atomic_read_unchecked(&osb->alloc_stats.moves),
58534+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
58535
58536 out += snprintf(buf + out, len - out,
58537 "%10s => State: %u Descriptor: %llu Size: %u bits "
58538@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
58539 spin_lock_init(&osb->osb_xattr_lock);
58540 ocfs2_init_steal_slots(osb);
58541
58542- atomic_set(&osb->alloc_stats.moves, 0);
58543- atomic_set(&osb->alloc_stats.local_data, 0);
58544- atomic_set(&osb->alloc_stats.bitmap_data, 0);
58545- atomic_set(&osb->alloc_stats.bg_allocs, 0);
58546- atomic_set(&osb->alloc_stats.bg_extends, 0);
58547+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
58548+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
58549+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
58550+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
58551+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
58552
58553 /* Copy the blockcheck stats from the superblock probe */
58554 osb->osb_ecc_stats = *stats;
58555diff --git a/fs/open.c b/fs/open.c
58556index 7931f76..7b03f3b 100644
58557--- a/fs/open.c
58558+++ b/fs/open.c
58559@@ -32,6 +32,8 @@
58560 #include <linux/dnotify.h>
58561 #include <linux/compat.h>
58562
58563+#define CREATE_TRACE_POINTS
58564+#include <trace/events/fs.h>
58565 #include "internal.h"
58566
58567 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
58568@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
58569 error = locks_verify_truncate(inode, NULL, length);
58570 if (!error)
58571 error = security_path_truncate(path);
58572+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
58573+ error = -EACCES;
58574 if (!error)
58575 error = do_truncate(path->dentry, length, 0, NULL);
58576
58577@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
58578 error = locks_verify_truncate(inode, f.file, length);
58579 if (!error)
58580 error = security_path_truncate(&f.file->f_path);
58581+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
58582+ error = -EACCES;
58583 if (!error)
58584 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
58585 sb_end_write(inode->i_sb);
58586@@ -360,6 +366,9 @@ retry:
58587 if (__mnt_is_readonly(path.mnt))
58588 res = -EROFS;
58589
58590+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
58591+ res = -EACCES;
58592+
58593 out_path_release:
58594 path_put(&path);
58595 if (retry_estale(res, lookup_flags)) {
58596@@ -391,6 +400,8 @@ retry:
58597 if (error)
58598 goto dput_and_out;
58599
58600+ gr_log_chdir(path.dentry, path.mnt);
58601+
58602 set_fs_pwd(current->fs, &path);
58603
58604 dput_and_out:
58605@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
58606 goto out_putf;
58607
58608 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
58609+
58610+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
58611+ error = -EPERM;
58612+
58613+ if (!error)
58614+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
58615+
58616 if (!error)
58617 set_fs_pwd(current->fs, &f.file->f_path);
58618 out_putf:
58619@@ -449,7 +467,13 @@ retry:
58620 if (error)
58621 goto dput_and_out;
58622
58623+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
58624+ goto dput_and_out;
58625+
58626 set_fs_root(current->fs, &path);
58627+
58628+ gr_handle_chroot_chdir(&path);
58629+
58630 error = 0;
58631 dput_and_out:
58632 path_put(&path);
58633@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
58634 if (error)
58635 return error;
58636 mutex_lock(&inode->i_mutex);
58637+
58638+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
58639+ error = -EACCES;
58640+ goto out_unlock;
58641+ }
58642+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
58643+ error = -EACCES;
58644+ goto out_unlock;
58645+ }
58646+
58647 error = security_path_chmod(path, mode);
58648 if (error)
58649 goto out_unlock;
58650@@ -531,6 +565,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
58651 uid = make_kuid(current_user_ns(), user);
58652 gid = make_kgid(current_user_ns(), group);
58653
58654+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
58655+ return -EACCES;
58656+
58657 newattrs.ia_valid = ATTR_CTIME;
58658 if (user != (uid_t) -1) {
58659 if (!uid_valid(uid))
58660@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
58661 } else {
58662 fsnotify_open(f);
58663 fd_install(fd, f);
58664+ trace_do_sys_open(tmp->name, flags, mode);
58665 }
58666 }
58667 putname(tmp);
58668diff --git a/fs/pipe.c b/fs/pipe.c
58669index d2c45e1..009fe1c 100644
58670--- a/fs/pipe.c
58671+++ b/fs/pipe.c
58672@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
58673
58674 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
58675 {
58676- if (pipe->files)
58677+ if (atomic_read(&pipe->files))
58678 mutex_lock_nested(&pipe->mutex, subclass);
58679 }
58680
58681@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
58682
58683 void pipe_unlock(struct pipe_inode_info *pipe)
58684 {
58685- if (pipe->files)
58686+ if (atomic_read(&pipe->files))
58687 mutex_unlock(&pipe->mutex);
58688 }
58689 EXPORT_SYMBOL(pipe_unlock);
58690@@ -449,9 +449,9 @@ redo:
58691 }
58692 if (bufs) /* More to do? */
58693 continue;
58694- if (!pipe->writers)
58695+ if (!atomic_read(&pipe->writers))
58696 break;
58697- if (!pipe->waiting_writers) {
58698+ if (!atomic_read(&pipe->waiting_writers)) {
58699 /* syscall merging: Usually we must not sleep
58700 * if O_NONBLOCK is set, or if we got some data.
58701 * But if a writer sleeps in kernel space, then
58702@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
58703 ret = 0;
58704 __pipe_lock(pipe);
58705
58706- if (!pipe->readers) {
58707+ if (!atomic_read(&pipe->readers)) {
58708 send_sig(SIGPIPE, current, 0);
58709 ret = -EPIPE;
58710 goto out;
58711@@ -562,7 +562,7 @@ redo1:
58712 for (;;) {
58713 int bufs;
58714
58715- if (!pipe->readers) {
58716+ if (!atomic_read(&pipe->readers)) {
58717 send_sig(SIGPIPE, current, 0);
58718 if (!ret)
58719 ret = -EPIPE;
58720@@ -653,9 +653,9 @@ redo2:
58721 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58722 do_wakeup = 0;
58723 }
58724- pipe->waiting_writers++;
58725+ atomic_inc(&pipe->waiting_writers);
58726 pipe_wait(pipe);
58727- pipe->waiting_writers--;
58728+ atomic_dec(&pipe->waiting_writers);
58729 }
58730 out:
58731 __pipe_unlock(pipe);
58732@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
58733 mask = 0;
58734 if (filp->f_mode & FMODE_READ) {
58735 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
58736- if (!pipe->writers && filp->f_version != pipe->w_counter)
58737+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
58738 mask |= POLLHUP;
58739 }
58740
58741@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
58742 * Most Unices do not set POLLERR for FIFOs but on Linux they
58743 * behave exactly like pipes for poll().
58744 */
58745- if (!pipe->readers)
58746+ if (!atomic_read(&pipe->readers))
58747 mask |= POLLERR;
58748 }
58749
58750@@ -734,17 +734,17 @@ pipe_release(struct inode *inode, struct file *file)
58751
58752 __pipe_lock(pipe);
58753 if (file->f_mode & FMODE_READ)
58754- pipe->readers--;
58755+ atomic_dec(&pipe->readers);
58756 if (file->f_mode & FMODE_WRITE)
58757- pipe->writers--;
58758+ atomic_dec(&pipe->writers);
58759
58760- if (pipe->readers || pipe->writers) {
58761+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
58762 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
58763 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58764 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
58765 }
58766 spin_lock(&inode->i_lock);
58767- if (!--pipe->files) {
58768+ if (atomic_dec_and_test(&pipe->files)) {
58769 inode->i_pipe = NULL;
58770 kill = 1;
58771 }
58772@@ -811,7 +811,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
58773 kfree(pipe);
58774 }
58775
58776-static struct vfsmount *pipe_mnt __read_mostly;
58777+struct vfsmount *pipe_mnt __read_mostly;
58778
58779 /*
58780 * pipefs_dname() is called from d_path().
58781@@ -841,8 +841,9 @@ static struct inode * get_pipe_inode(void)
58782 goto fail_iput;
58783
58784 inode->i_pipe = pipe;
58785- pipe->files = 2;
58786- pipe->readers = pipe->writers = 1;
58787+ atomic_set(&pipe->files, 2);
58788+ atomic_set(&pipe->readers, 1);
58789+ atomic_set(&pipe->writers, 1);
58790 inode->i_fop = &pipefifo_fops;
58791
58792 /*
58793@@ -1022,17 +1023,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
58794 spin_lock(&inode->i_lock);
58795 if (inode->i_pipe) {
58796 pipe = inode->i_pipe;
58797- pipe->files++;
58798+ atomic_inc(&pipe->files);
58799 spin_unlock(&inode->i_lock);
58800 } else {
58801 spin_unlock(&inode->i_lock);
58802 pipe = alloc_pipe_info();
58803 if (!pipe)
58804 return -ENOMEM;
58805- pipe->files = 1;
58806+ atomic_set(&pipe->files, 1);
58807 spin_lock(&inode->i_lock);
58808 if (unlikely(inode->i_pipe)) {
58809- inode->i_pipe->files++;
58810+ atomic_inc(&inode->i_pipe->files);
58811 spin_unlock(&inode->i_lock);
58812 free_pipe_info(pipe);
58813 pipe = inode->i_pipe;
58814@@ -1057,10 +1058,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
58815 * opened, even when there is no process writing the FIFO.
58816 */
58817 pipe->r_counter++;
58818- if (pipe->readers++ == 0)
58819+ if (atomic_inc_return(&pipe->readers) == 1)
58820 wake_up_partner(pipe);
58821
58822- if (!is_pipe && !pipe->writers) {
58823+ if (!is_pipe && !atomic_read(&pipe->writers)) {
58824 if ((filp->f_flags & O_NONBLOCK)) {
58825 /* suppress POLLHUP until we have
58826 * seen a writer */
58827@@ -1079,14 +1080,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
58828 * errno=ENXIO when there is no process reading the FIFO.
58829 */
58830 ret = -ENXIO;
58831- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
58832+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
58833 goto err;
58834
58835 pipe->w_counter++;
58836- if (!pipe->writers++)
58837+ if (atomic_inc_return(&pipe->writers) == 1)
58838 wake_up_partner(pipe);
58839
58840- if (!is_pipe && !pipe->readers) {
58841+ if (!is_pipe && !atomic_read(&pipe->readers)) {
58842 if (wait_for_partner(pipe, &pipe->r_counter))
58843 goto err_wr;
58844 }
58845@@ -1100,11 +1101,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
58846 * the process can at least talk to itself.
58847 */
58848
58849- pipe->readers++;
58850- pipe->writers++;
58851+ atomic_inc(&pipe->readers);
58852+ atomic_inc(&pipe->writers);
58853 pipe->r_counter++;
58854 pipe->w_counter++;
58855- if (pipe->readers == 1 || pipe->writers == 1)
58856+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
58857 wake_up_partner(pipe);
58858 break;
58859
58860@@ -1118,20 +1119,20 @@ static int fifo_open(struct inode *inode, struct file *filp)
58861 return 0;
58862
58863 err_rd:
58864- if (!--pipe->readers)
58865+ if (atomic_dec_and_test(&pipe->readers))
58866 wake_up_interruptible(&pipe->wait);
58867 ret = -ERESTARTSYS;
58868 goto err;
58869
58870 err_wr:
58871- if (!--pipe->writers)
58872+ if (atomic_dec_and_test(&pipe->writers))
58873 wake_up_interruptible(&pipe->wait);
58874 ret = -ERESTARTSYS;
58875 goto err;
58876
58877 err:
58878 spin_lock(&inode->i_lock);
58879- if (!--pipe->files) {
58880+ if (atomic_dec_and_test(&pipe->files)) {
58881 inode->i_pipe = NULL;
58882 kill = 1;
58883 }
58884diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
58885index 15af622..0e9f4467 100644
58886--- a/fs/proc/Kconfig
58887+++ b/fs/proc/Kconfig
58888@@ -30,12 +30,12 @@ config PROC_FS
58889
58890 config PROC_KCORE
58891 bool "/proc/kcore support" if !ARM
58892- depends on PROC_FS && MMU
58893+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
58894
58895 config PROC_VMCORE
58896 bool "/proc/vmcore support"
58897- depends on PROC_FS && CRASH_DUMP
58898- default y
58899+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
58900+ default n
58901 help
58902 Exports the dump image of crashed kernel in ELF format.
58903
58904@@ -59,8 +59,8 @@ config PROC_SYSCTL
58905 limited in memory.
58906
58907 config PROC_PAGE_MONITOR
58908- default y
58909- depends on PROC_FS && MMU
58910+ default n
58911+ depends on PROC_FS && MMU && !GRKERNSEC
58912 bool "Enable /proc page monitoring" if EXPERT
58913 help
58914 Various /proc files exist to monitor process memory utilization:
58915diff --git a/fs/proc/array.c b/fs/proc/array.c
58916index cbd0f1b..adec3f0 100644
58917--- a/fs/proc/array.c
58918+++ b/fs/proc/array.c
58919@@ -60,6 +60,7 @@
58920 #include <linux/tty.h>
58921 #include <linux/string.h>
58922 #include <linux/mman.h>
58923+#include <linux/grsecurity.h>
58924 #include <linux/proc_fs.h>
58925 #include <linux/ioport.h>
58926 #include <linux/uaccess.h>
58927@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
58928 seq_putc(m, '\n');
58929 }
58930
58931+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58932+static inline void task_pax(struct seq_file *m, struct task_struct *p)
58933+{
58934+ if (p->mm)
58935+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
58936+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
58937+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
58938+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
58939+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
58940+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
58941+ else
58942+ seq_printf(m, "PaX:\t-----\n");
58943+}
58944+#endif
58945+
58946 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
58947 struct pid *pid, struct task_struct *task)
58948 {
58949@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
58950 task_cpus_allowed(m, task);
58951 cpuset_task_status_allowed(m, task);
58952 task_context_switch_counts(m, task);
58953+
58954+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58955+ task_pax(m, task);
58956+#endif
58957+
58958+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
58959+ task_grsec_rbac(m, task);
58960+#endif
58961+
58962 return 0;
58963 }
58964
58965+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58966+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
58967+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
58968+ _mm->pax_flags & MF_PAX_SEGMEXEC))
58969+#endif
58970+
58971 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58972 struct pid *pid, struct task_struct *task, int whole)
58973 {
58974@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58975 char tcomm[sizeof(task->comm)];
58976 unsigned long flags;
58977
58978+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58979+ if (current->exec_id != m->exec_id) {
58980+ gr_log_badprocpid("stat");
58981+ return 0;
58982+ }
58983+#endif
58984+
58985 state = *get_task_state(task);
58986 vsize = eip = esp = 0;
58987 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
58988@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58989 gtime = task_gtime(task);
58990 }
58991
58992+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58993+ if (PAX_RAND_FLAGS(mm)) {
58994+ eip = 0;
58995+ esp = 0;
58996+ wchan = 0;
58997+ }
58998+#endif
58999+#ifdef CONFIG_GRKERNSEC_HIDESYM
59000+ wchan = 0;
59001+ eip =0;
59002+ esp =0;
59003+#endif
59004+
59005 /* scale priority and nice values from timeslices to -20..20 */
59006 /* to make it look like a "normal" Unix priority/nice value */
59007 priority = task_prio(task);
59008@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59009 seq_put_decimal_ull(m, ' ', vsize);
59010 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
59011 seq_put_decimal_ull(m, ' ', rsslim);
59012+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59013+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
59014+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
59015+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
59016+#else
59017 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
59018 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
59019 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
59020+#endif
59021 seq_put_decimal_ull(m, ' ', esp);
59022 seq_put_decimal_ull(m, ' ', eip);
59023 /* The signal information here is obsolete.
59024@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59025 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
59026 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
59027
59028- if (mm && permitted) {
59029+ if (mm && permitted
59030+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59031+ && !PAX_RAND_FLAGS(mm)
59032+#endif
59033+ ) {
59034 seq_put_decimal_ull(m, ' ', mm->start_data);
59035 seq_put_decimal_ull(m, ' ', mm->end_data);
59036 seq_put_decimal_ull(m, ' ', mm->start_brk);
59037@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
59038 struct pid *pid, struct task_struct *task)
59039 {
59040 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
59041- struct mm_struct *mm = get_task_mm(task);
59042+ struct mm_struct *mm;
59043
59044+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59045+ if (current->exec_id != m->exec_id) {
59046+ gr_log_badprocpid("statm");
59047+ return 0;
59048+ }
59049+#endif
59050+ mm = get_task_mm(task);
59051 if (mm) {
59052 size = task_statm(mm, &shared, &text, &data, &resident);
59053 mmput(mm);
59054@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
59055 return 0;
59056 }
59057
59058+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59059+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
59060+{
59061+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
59062+}
59063+#endif
59064+
59065 #ifdef CONFIG_CHECKPOINT_RESTORE
59066 static struct pid *
59067 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
59068diff --git a/fs/proc/base.c b/fs/proc/base.c
59069index 1485e38..8ad4236 100644
59070--- a/fs/proc/base.c
59071+++ b/fs/proc/base.c
59072@@ -113,6 +113,14 @@ struct pid_entry {
59073 union proc_op op;
59074 };
59075
59076+struct getdents_callback {
59077+ struct linux_dirent __user * current_dir;
59078+ struct linux_dirent __user * previous;
59079+ struct file * file;
59080+ int count;
59081+ int error;
59082+};
59083+
59084 #define NOD(NAME, MODE, IOP, FOP, OP) { \
59085 .name = (NAME), \
59086 .len = sizeof(NAME) - 1, \
59087@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
59088 if (!mm->arg_end)
59089 goto out_mm; /* Shh! No looking before we're done */
59090
59091+ if (gr_acl_handle_procpidmem(task))
59092+ goto out_mm;
59093+
59094 len = mm->arg_end - mm->arg_start;
59095
59096 if (len > PAGE_SIZE)
59097@@ -237,12 +248,28 @@ out:
59098 return res;
59099 }
59100
59101+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59102+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59103+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59104+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59105+#endif
59106+
59107 static int proc_pid_auxv(struct task_struct *task, char *buffer)
59108 {
59109 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
59110 int res = PTR_ERR(mm);
59111 if (mm && !IS_ERR(mm)) {
59112 unsigned int nwords = 0;
59113+
59114+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59115+ /* allow if we're currently ptracing this task */
59116+ if (PAX_RAND_FLAGS(mm) &&
59117+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
59118+ mmput(mm);
59119+ return 0;
59120+ }
59121+#endif
59122+
59123 do {
59124 nwords += 2;
59125 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
59126@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
59127 }
59128
59129
59130-#ifdef CONFIG_KALLSYMS
59131+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59132 /*
59133 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
59134 * Returns the resolved symbol. If that fails, simply return the address.
59135@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
59136 mutex_unlock(&task->signal->cred_guard_mutex);
59137 }
59138
59139-#ifdef CONFIG_STACKTRACE
59140+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59141
59142 #define MAX_STACK_TRACE_DEPTH 64
59143
59144@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
59145 return count;
59146 }
59147
59148-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59149+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59150 static int proc_pid_syscall(struct task_struct *task, char *buffer)
59151 {
59152 long nr;
59153@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
59154 /************************************************************************/
59155
59156 /* permission checks */
59157-static int proc_fd_access_allowed(struct inode *inode)
59158+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
59159 {
59160 struct task_struct *task;
59161 int allowed = 0;
59162@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
59163 */
59164 task = get_proc_task(inode);
59165 if (task) {
59166- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59167+ if (log)
59168+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59169+ else
59170+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
59171 put_task_struct(task);
59172 }
59173 return allowed;
59174@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
59175 struct task_struct *task,
59176 int hide_pid_min)
59177 {
59178+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59179+ return false;
59180+
59181+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59182+ rcu_read_lock();
59183+ {
59184+ const struct cred *tmpcred = current_cred();
59185+ const struct cred *cred = __task_cred(task);
59186+
59187+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
59188+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59189+ || in_group_p(grsec_proc_gid)
59190+#endif
59191+ ) {
59192+ rcu_read_unlock();
59193+ return true;
59194+ }
59195+ }
59196+ rcu_read_unlock();
59197+
59198+ if (!pid->hide_pid)
59199+ return false;
59200+#endif
59201+
59202 if (pid->hide_pid < hide_pid_min)
59203 return true;
59204 if (in_group_p(pid->pid_gid))
59205 return true;
59206+
59207 return ptrace_may_access(task, PTRACE_MODE_READ);
59208 }
59209
59210@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
59211 put_task_struct(task);
59212
59213 if (!has_perms) {
59214+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59215+ {
59216+#else
59217 if (pid->hide_pid == 2) {
59218+#endif
59219 /*
59220 * Let's make getdents(), stat(), and open()
59221 * consistent with each other. If a process
59222@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59223 if (!task)
59224 return -ESRCH;
59225
59226+ if (gr_acl_handle_procpidmem(task)) {
59227+ put_task_struct(task);
59228+ return -EPERM;
59229+ }
59230+
59231 mm = mm_access(task, mode);
59232 put_task_struct(task);
59233
59234@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59235
59236 file->private_data = mm;
59237
59238+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59239+ file->f_version = current->exec_id;
59240+#endif
59241+
59242 return 0;
59243 }
59244
59245@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59246 ssize_t copied;
59247 char *page;
59248
59249+#ifdef CONFIG_GRKERNSEC
59250+ if (write)
59251+ return -EPERM;
59252+#endif
59253+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59254+ if (file->f_version != current->exec_id) {
59255+ gr_log_badprocpid("mem");
59256+ return 0;
59257+ }
59258+#endif
59259+
59260 if (!mm)
59261 return 0;
59262
59263@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59264 goto free;
59265
59266 while (count > 0) {
59267- int this_len = min_t(int, count, PAGE_SIZE);
59268+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
59269
59270 if (write && copy_from_user(page, buf, this_len)) {
59271 copied = -EFAULT;
59272@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59273 if (!mm)
59274 return 0;
59275
59276+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59277+ if (file->f_version != current->exec_id) {
59278+ gr_log_badprocpid("environ");
59279+ return 0;
59280+ }
59281+#endif
59282+
59283 page = (char *)__get_free_page(GFP_TEMPORARY);
59284 if (!page)
59285 return -ENOMEM;
59286@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59287 goto free;
59288 while (count > 0) {
59289 size_t this_len, max_len;
59290- int retval;
59291+ ssize_t retval;
59292
59293 if (src >= (mm->env_end - mm->env_start))
59294 break;
59295@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
59296 int error = -EACCES;
59297
59298 /* Are we allowed to snoop on the tasks file descriptors? */
59299- if (!proc_fd_access_allowed(inode))
59300+ if (!proc_fd_access_allowed(inode, 0))
59301 goto out;
59302
59303 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59304@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
59305 struct path path;
59306
59307 /* Are we allowed to snoop on the tasks file descriptors? */
59308- if (!proc_fd_access_allowed(inode))
59309- goto out;
59310+ /* logging this is needed for learning on chromium to work properly,
59311+ but we don't want to flood the logs from 'ps' which does a readlink
59312+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
59313+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
59314+ */
59315+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
59316+ if (!proc_fd_access_allowed(inode,0))
59317+ goto out;
59318+ } else {
59319+ if (!proc_fd_access_allowed(inode,1))
59320+ goto out;
59321+ }
59322
59323 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59324 if (error)
59325@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
59326 rcu_read_lock();
59327 cred = __task_cred(task);
59328 inode->i_uid = cred->euid;
59329+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59330+ inode->i_gid = grsec_proc_gid;
59331+#else
59332 inode->i_gid = cred->egid;
59333+#endif
59334 rcu_read_unlock();
59335 }
59336 security_task_to_inode(task, inode);
59337@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
59338 return -ENOENT;
59339 }
59340 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59341+#ifdef CONFIG_GRKERNSEC_PROC_USER
59342+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59343+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59344+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59345+#endif
59346 task_dumpable(task)) {
59347 cred = __task_cred(task);
59348 stat->uid = cred->euid;
59349+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59350+ stat->gid = grsec_proc_gid;
59351+#else
59352 stat->gid = cred->egid;
59353+#endif
59354 }
59355 }
59356 rcu_read_unlock();
59357@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
59358
59359 if (task) {
59360 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59361+#ifdef CONFIG_GRKERNSEC_PROC_USER
59362+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59363+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59364+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59365+#endif
59366 task_dumpable(task)) {
59367 rcu_read_lock();
59368 cred = __task_cred(task);
59369 inode->i_uid = cred->euid;
59370+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59371+ inode->i_gid = grsec_proc_gid;
59372+#else
59373 inode->i_gid = cred->egid;
59374+#endif
59375 rcu_read_unlock();
59376 } else {
59377 inode->i_uid = GLOBAL_ROOT_UID;
59378@@ -2166,6 +2284,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
59379 if (!task)
59380 goto out_no_task;
59381
59382+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59383+ goto out;
59384+
59385 /*
59386 * Yes, it does not scale. And it should not. Don't add
59387 * new entries into /proc/<tgid>/ without very good reasons.
59388@@ -2196,6 +2317,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
59389 if (!task)
59390 return -ENOENT;
59391
59392+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59393+ goto out;
59394+
59395 if (!dir_emit_dots(file, ctx))
59396 goto out;
59397
59398@@ -2585,7 +2709,7 @@ static const struct pid_entry tgid_base_stuff[] = {
59399 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
59400 #endif
59401 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59402-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59403+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59404 INF("syscall", S_IRUGO, proc_pid_syscall),
59405 #endif
59406 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59407@@ -2610,10 +2734,10 @@ static const struct pid_entry tgid_base_stuff[] = {
59408 #ifdef CONFIG_SECURITY
59409 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59410 #endif
59411-#ifdef CONFIG_KALLSYMS
59412+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59413 INF("wchan", S_IRUGO, proc_pid_wchan),
59414 #endif
59415-#ifdef CONFIG_STACKTRACE
59416+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59417 ONE("stack", S_IRUGO, proc_pid_stack),
59418 #endif
59419 #ifdef CONFIG_SCHEDSTATS
59420@@ -2647,6 +2771,9 @@ static const struct pid_entry tgid_base_stuff[] = {
59421 #ifdef CONFIG_HARDWALL
59422 INF("hardwall", S_IRUGO, proc_pid_hardwall),
59423 #endif
59424+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59425+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
59426+#endif
59427 #ifdef CONFIG_USER_NS
59428 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
59429 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
59430@@ -2777,7 +2904,14 @@ static int proc_pid_instantiate(struct inode *dir,
59431 if (!inode)
59432 goto out;
59433
59434+#ifdef CONFIG_GRKERNSEC_PROC_USER
59435+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
59436+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59437+ inode->i_gid = grsec_proc_gid;
59438+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
59439+#else
59440 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
59441+#endif
59442 inode->i_op = &proc_tgid_base_inode_operations;
59443 inode->i_fop = &proc_tgid_base_operations;
59444 inode->i_flags|=S_IMMUTABLE;
59445@@ -2815,7 +2949,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
59446 if (!task)
59447 goto out;
59448
59449+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59450+ goto out_put_task;
59451+
59452 result = proc_pid_instantiate(dir, dentry, task, NULL);
59453+out_put_task:
59454 put_task_struct(task);
59455 out:
59456 return ERR_PTR(result);
59457@@ -2921,7 +3059,7 @@ static const struct pid_entry tid_base_stuff[] = {
59458 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
59459 #endif
59460 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59461-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59462+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59463 INF("syscall", S_IRUGO, proc_pid_syscall),
59464 #endif
59465 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59466@@ -2948,10 +3086,10 @@ static const struct pid_entry tid_base_stuff[] = {
59467 #ifdef CONFIG_SECURITY
59468 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59469 #endif
59470-#ifdef CONFIG_KALLSYMS
59471+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59472 INF("wchan", S_IRUGO, proc_pid_wchan),
59473 #endif
59474-#ifdef CONFIG_STACKTRACE
59475+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59476 ONE("stack", S_IRUGO, proc_pid_stack),
59477 #endif
59478 #ifdef CONFIG_SCHEDSTATS
59479diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
59480index 82676e3..5f8518a 100644
59481--- a/fs/proc/cmdline.c
59482+++ b/fs/proc/cmdline.c
59483@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
59484
59485 static int __init proc_cmdline_init(void)
59486 {
59487+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59488+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
59489+#else
59490 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
59491+#endif
59492 return 0;
59493 }
59494 module_init(proc_cmdline_init);
59495diff --git a/fs/proc/devices.c b/fs/proc/devices.c
59496index b143471..bb105e5 100644
59497--- a/fs/proc/devices.c
59498+++ b/fs/proc/devices.c
59499@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
59500
59501 static int __init proc_devices_init(void)
59502 {
59503+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59504+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
59505+#else
59506 proc_create("devices", 0, NULL, &proc_devinfo_operations);
59507+#endif
59508 return 0;
59509 }
59510 module_init(proc_devices_init);
59511diff --git a/fs/proc/fd.c b/fs/proc/fd.c
59512index 0ff80f9..a1d7500 100644
59513--- a/fs/proc/fd.c
59514+++ b/fs/proc/fd.c
59515@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
59516 if (!task)
59517 return -ENOENT;
59518
59519- files = get_files_struct(task);
59520+ if (!gr_acl_handle_procpidmem(task))
59521+ files = get_files_struct(task);
59522 put_task_struct(task);
59523
59524 if (files) {
59525@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
59526 */
59527 int proc_fd_permission(struct inode *inode, int mask)
59528 {
59529+ struct task_struct *task;
59530 int rv = generic_permission(inode, mask);
59531- if (rv == 0)
59532- return 0;
59533+
59534 if (task_pid(current) == proc_pid(inode))
59535 rv = 0;
59536+
59537+ task = get_proc_task(inode);
59538+ if (task == NULL)
59539+ return rv;
59540+
59541+ if (gr_acl_handle_procpidmem(task))
59542+ rv = -EACCES;
59543+
59544+ put_task_struct(task);
59545+
59546 return rv;
59547 }
59548
59549diff --git a/fs/proc/inode.c b/fs/proc/inode.c
59550index 073aea6..0630370 100644
59551--- a/fs/proc/inode.c
59552+++ b/fs/proc/inode.c
59553@@ -23,11 +23,17 @@
59554 #include <linux/slab.h>
59555 #include <linux/mount.h>
59556 #include <linux/magic.h>
59557+#include <linux/grsecurity.h>
59558
59559 #include <asm/uaccess.h>
59560
59561 #include "internal.h"
59562
59563+#ifdef CONFIG_PROC_SYSCTL
59564+extern const struct inode_operations proc_sys_inode_operations;
59565+extern const struct inode_operations proc_sys_dir_operations;
59566+#endif
59567+
59568 static void proc_evict_inode(struct inode *inode)
59569 {
59570 struct proc_dir_entry *de;
59571@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
59572 ns = PROC_I(inode)->ns.ns;
59573 if (ns_ops && ns)
59574 ns_ops->put(ns);
59575+
59576+#ifdef CONFIG_PROC_SYSCTL
59577+ if (inode->i_op == &proc_sys_inode_operations ||
59578+ inode->i_op == &proc_sys_dir_operations)
59579+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
59580+#endif
59581+
59582 }
59583
59584 static struct kmem_cache * proc_inode_cachep;
59585@@ -385,7 +398,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
59586 if (de->mode) {
59587 inode->i_mode = de->mode;
59588 inode->i_uid = de->uid;
59589+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59590+ inode->i_gid = grsec_proc_gid;
59591+#else
59592 inode->i_gid = de->gid;
59593+#endif
59594 }
59595 if (de->size)
59596 inode->i_size = de->size;
59597diff --git a/fs/proc/internal.h b/fs/proc/internal.h
59598index 651d09a..60c73ae 100644
59599--- a/fs/proc/internal.h
59600+++ b/fs/proc/internal.h
59601@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
59602 struct pid *, struct task_struct *);
59603 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
59604 struct pid *, struct task_struct *);
59605+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59606+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
59607+#endif
59608
59609 /*
59610 * base.c
59611diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
59612index 06ea155..9a798c7 100644
59613--- a/fs/proc/kcore.c
59614+++ b/fs/proc/kcore.c
59615@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59616 * the addresses in the elf_phdr on our list.
59617 */
59618 start = kc_offset_to_vaddr(*fpos - elf_buflen);
59619- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
59620+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
59621+ if (tsz > buflen)
59622 tsz = buflen;
59623-
59624+
59625 while (buflen) {
59626 struct kcore_list *m;
59627
59628@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59629 kfree(elf_buf);
59630 } else {
59631 if (kern_addr_valid(start)) {
59632- unsigned long n;
59633+ char *elf_buf;
59634+ mm_segment_t oldfs;
59635
59636- n = copy_to_user(buffer, (char *)start, tsz);
59637- /*
59638- * We cannot distinguish between fault on source
59639- * and fault on destination. When this happens
59640- * we clear too and hope it will trigger the
59641- * EFAULT again.
59642- */
59643- if (n) {
59644- if (clear_user(buffer + tsz - n,
59645- n))
59646+ elf_buf = kmalloc(tsz, GFP_KERNEL);
59647+ if (!elf_buf)
59648+ return -ENOMEM;
59649+ oldfs = get_fs();
59650+ set_fs(KERNEL_DS);
59651+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
59652+ set_fs(oldfs);
59653+ if (copy_to_user(buffer, elf_buf, tsz)) {
59654+ kfree(elf_buf);
59655 return -EFAULT;
59656+ }
59657 }
59658+ set_fs(oldfs);
59659+ kfree(elf_buf);
59660 } else {
59661 if (clear_user(buffer, tsz))
59662 return -EFAULT;
59663@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59664
59665 static int open_kcore(struct inode *inode, struct file *filp)
59666 {
59667+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
59668+ return -EPERM;
59669+#endif
59670 if (!capable(CAP_SYS_RAWIO))
59671 return -EPERM;
59672 if (kcore_need_update)
59673diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
59674index 5aa847a..f77c8d4 100644
59675--- a/fs/proc/meminfo.c
59676+++ b/fs/proc/meminfo.c
59677@@ -159,7 +159,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
59678 vmi.used >> 10,
59679 vmi.largest_chunk >> 10
59680 #ifdef CONFIG_MEMORY_FAILURE
59681- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
59682+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
59683 #endif
59684 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
59685 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
59686diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
59687index ccfd99b..1b7e255 100644
59688--- a/fs/proc/nommu.c
59689+++ b/fs/proc/nommu.c
59690@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
59691 if (len < 1)
59692 len = 1;
59693 seq_printf(m, "%*c", len, ' ');
59694- seq_path(m, &file->f_path, "");
59695+ seq_path(m, &file->f_path, "\n\\");
59696 }
59697
59698 seq_putc(m, '\n');
59699diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
59700index 4677bb7..408e936 100644
59701--- a/fs/proc/proc_net.c
59702+++ b/fs/proc/proc_net.c
59703@@ -23,6 +23,7 @@
59704 #include <linux/nsproxy.h>
59705 #include <net/net_namespace.h>
59706 #include <linux/seq_file.h>
59707+#include <linux/grsecurity.h>
59708
59709 #include "internal.h"
59710
59711@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
59712 struct task_struct *task;
59713 struct nsproxy *ns;
59714 struct net *net = NULL;
59715+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59716+ const struct cred *cred = current_cred();
59717+#endif
59718+
59719+#ifdef CONFIG_GRKERNSEC_PROC_USER
59720+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
59721+ return net;
59722+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59723+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
59724+ return net;
59725+#endif
59726
59727 rcu_read_lock();
59728 task = pid_task(proc_pid(dir), PIDTYPE_PID);
59729diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
59730index 7129046..f2779c6 100644
59731--- a/fs/proc/proc_sysctl.c
59732+++ b/fs/proc/proc_sysctl.c
59733@@ -13,11 +13,15 @@
59734 #include <linux/module.h>
59735 #include "internal.h"
59736
59737+extern int gr_handle_chroot_sysctl(const int op);
59738+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
59739+ const int op);
59740+
59741 static const struct dentry_operations proc_sys_dentry_operations;
59742 static const struct file_operations proc_sys_file_operations;
59743-static const struct inode_operations proc_sys_inode_operations;
59744+const struct inode_operations proc_sys_inode_operations;
59745 static const struct file_operations proc_sys_dir_file_operations;
59746-static const struct inode_operations proc_sys_dir_operations;
59747+const struct inode_operations proc_sys_dir_operations;
59748
59749 void proc_sys_poll_notify(struct ctl_table_poll *poll)
59750 {
59751@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
59752
59753 err = NULL;
59754 d_set_d_op(dentry, &proc_sys_dentry_operations);
59755+
59756+ gr_handle_proc_create(dentry, inode);
59757+
59758 d_add(dentry, inode);
59759
59760 out:
59761@@ -482,6 +489,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59762 struct inode *inode = file_inode(filp);
59763 struct ctl_table_header *head = grab_header(inode);
59764 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
59765+ int op = write ? MAY_WRITE : MAY_READ;
59766 ssize_t error;
59767 size_t res;
59768
59769@@ -493,7 +501,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59770 * and won't be until we finish.
59771 */
59772 error = -EPERM;
59773- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
59774+ if (sysctl_perm(head, table, op))
59775 goto out;
59776
59777 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
59778@@ -501,6 +509,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59779 if (!table->proc_handler)
59780 goto out;
59781
59782+#ifdef CONFIG_GRKERNSEC
59783+ error = -EPERM;
59784+ if (gr_handle_chroot_sysctl(op))
59785+ goto out;
59786+ dget(filp->f_path.dentry);
59787+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
59788+ dput(filp->f_path.dentry);
59789+ goto out;
59790+ }
59791+ dput(filp->f_path.dentry);
59792+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
59793+ goto out;
59794+ if (write && !capable(CAP_SYS_ADMIN))
59795+ goto out;
59796+#endif
59797+
59798 /* careful: calling conventions are nasty here */
59799 res = count;
59800 error = table->proc_handler(table, write, buf, &res, ppos);
59801@@ -598,6 +622,9 @@ static bool proc_sys_fill_cache(struct file *file,
59802 return false;
59803 } else {
59804 d_set_d_op(child, &proc_sys_dentry_operations);
59805+
59806+ gr_handle_proc_create(child, inode);
59807+
59808 d_add(child, inode);
59809 }
59810 } else {
59811@@ -641,6 +668,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
59812 if ((*pos)++ < ctx->pos)
59813 return true;
59814
59815+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
59816+ return 0;
59817+
59818 if (unlikely(S_ISLNK(table->mode)))
59819 res = proc_sys_link_fill_cache(file, ctx, head, table);
59820 else
59821@@ -734,6 +764,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
59822 if (IS_ERR(head))
59823 return PTR_ERR(head);
59824
59825+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
59826+ return -ENOENT;
59827+
59828 generic_fillattr(inode, stat);
59829 if (table)
59830 stat->mode = (stat->mode & S_IFMT) | table->mode;
59831@@ -756,13 +789,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
59832 .llseek = generic_file_llseek,
59833 };
59834
59835-static const struct inode_operations proc_sys_inode_operations = {
59836+const struct inode_operations proc_sys_inode_operations = {
59837 .permission = proc_sys_permission,
59838 .setattr = proc_sys_setattr,
59839 .getattr = proc_sys_getattr,
59840 };
59841
59842-static const struct inode_operations proc_sys_dir_operations = {
59843+const struct inode_operations proc_sys_dir_operations = {
59844 .lookup = proc_sys_lookup,
59845 .permission = proc_sys_permission,
59846 .setattr = proc_sys_setattr,
59847@@ -839,7 +872,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
59848 static struct ctl_dir *new_dir(struct ctl_table_set *set,
59849 const char *name, int namelen)
59850 {
59851- struct ctl_table *table;
59852+ ctl_table_no_const *table;
59853 struct ctl_dir *new;
59854 struct ctl_node *node;
59855 char *new_name;
59856@@ -851,7 +884,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
59857 return NULL;
59858
59859 node = (struct ctl_node *)(new + 1);
59860- table = (struct ctl_table *)(node + 1);
59861+ table = (ctl_table_no_const *)(node + 1);
59862 new_name = (char *)(table + 2);
59863 memcpy(new_name, name, namelen);
59864 new_name[namelen] = '\0';
59865@@ -1020,7 +1053,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
59866 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
59867 struct ctl_table_root *link_root)
59868 {
59869- struct ctl_table *link_table, *entry, *link;
59870+ ctl_table_no_const *link_table, *link;
59871+ struct ctl_table *entry;
59872 struct ctl_table_header *links;
59873 struct ctl_node *node;
59874 char *link_name;
59875@@ -1043,7 +1077,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
59876 return NULL;
59877
59878 node = (struct ctl_node *)(links + 1);
59879- link_table = (struct ctl_table *)(node + nr_entries);
59880+ link_table = (ctl_table_no_const *)(node + nr_entries);
59881 link_name = (char *)&link_table[nr_entries + 1];
59882
59883 for (link = link_table, entry = table; entry->procname; link++, entry++) {
59884@@ -1291,8 +1325,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59885 struct ctl_table_header ***subheader, struct ctl_table_set *set,
59886 struct ctl_table *table)
59887 {
59888- struct ctl_table *ctl_table_arg = NULL;
59889- struct ctl_table *entry, *files;
59890+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
59891+ struct ctl_table *entry;
59892 int nr_files = 0;
59893 int nr_dirs = 0;
59894 int err = -ENOMEM;
59895@@ -1304,10 +1338,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59896 nr_files++;
59897 }
59898
59899- files = table;
59900 /* If there are mixed files and directories we need a new table */
59901 if (nr_dirs && nr_files) {
59902- struct ctl_table *new;
59903+ ctl_table_no_const *new;
59904 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
59905 GFP_KERNEL);
59906 if (!files)
59907@@ -1325,7 +1358,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59908 /* Register everything except a directory full of subdirectories */
59909 if (nr_files || !nr_dirs) {
59910 struct ctl_table_header *header;
59911- header = __register_sysctl_table(set, path, files);
59912+ header = __register_sysctl_table(set, path, files ? files : table);
59913 if (!header) {
59914 kfree(ctl_table_arg);
59915 goto out;
59916diff --git a/fs/proc/root.c b/fs/proc/root.c
59917index e0a790d..21e095e 100644
59918--- a/fs/proc/root.c
59919+++ b/fs/proc/root.c
59920@@ -182,7 +182,15 @@ void __init proc_root_init(void)
59921 #ifdef CONFIG_PROC_DEVICETREE
59922 proc_device_tree_init();
59923 #endif
59924+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59925+#ifdef CONFIG_GRKERNSEC_PROC_USER
59926+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
59927+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59928+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
59929+#endif
59930+#else
59931 proc_mkdir("bus", NULL);
59932+#endif
59933 proc_sys_init();
59934 }
59935
59936diff --git a/fs/proc/self.c b/fs/proc/self.c
59937index 6b6a993..807cccc 100644
59938--- a/fs/proc/self.c
59939+++ b/fs/proc/self.c
59940@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
59941 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
59942 void *cookie)
59943 {
59944- char *s = nd_get_link(nd);
59945+ const char *s = nd_get_link(nd);
59946 if (!IS_ERR(s))
59947 kfree(s);
59948 }
59949diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
59950index 107d026..c715aeb 100644
59951--- a/fs/proc/task_mmu.c
59952+++ b/fs/proc/task_mmu.c
59953@@ -12,12 +12,19 @@
59954 #include <linux/swap.h>
59955 #include <linux/swapops.h>
59956 #include <linux/mmu_notifier.h>
59957+#include <linux/grsecurity.h>
59958
59959 #include <asm/elf.h>
59960 #include <asm/uaccess.h>
59961 #include <asm/tlbflush.h>
59962 #include "internal.h"
59963
59964+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59965+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59966+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59967+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59968+#endif
59969+
59970 void task_mem(struct seq_file *m, struct mm_struct *mm)
59971 {
59972 unsigned long data, text, lib, swap;
59973@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
59974 "VmExe:\t%8lu kB\n"
59975 "VmLib:\t%8lu kB\n"
59976 "VmPTE:\t%8lu kB\n"
59977- "VmSwap:\t%8lu kB\n",
59978- hiwater_vm << (PAGE_SHIFT-10),
59979+ "VmSwap:\t%8lu kB\n"
59980+
59981+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59982+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
59983+#endif
59984+
59985+ ,hiwater_vm << (PAGE_SHIFT-10),
59986 total_vm << (PAGE_SHIFT-10),
59987 mm->locked_vm << (PAGE_SHIFT-10),
59988 mm->pinned_vm << (PAGE_SHIFT-10),
59989@@ -63,7 +75,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
59990 data << (PAGE_SHIFT-10),
59991 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
59992 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
59993- swap << (PAGE_SHIFT-10));
59994+ swap << (PAGE_SHIFT-10)
59995+
59996+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59997+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59998+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
59999+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
60000+#else
60001+ , mm->context.user_cs_base
60002+ , mm->context.user_cs_limit
60003+#endif
60004+#endif
60005+
60006+ );
60007 }
60008
60009 unsigned long task_vsize(struct mm_struct *mm)
60010@@ -278,13 +302,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60011 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
60012 }
60013
60014- /* We don't show the stack guard page in /proc/maps */
60015+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60016+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
60017+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
60018+#else
60019 start = vma->vm_start;
60020- if (stack_guard_page_start(vma, start))
60021- start += PAGE_SIZE;
60022 end = vma->vm_end;
60023- if (stack_guard_page_end(vma, end))
60024- end -= PAGE_SIZE;
60025+#endif
60026
60027 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
60028 start,
60029@@ -293,7 +317,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60030 flags & VM_WRITE ? 'w' : '-',
60031 flags & VM_EXEC ? 'x' : '-',
60032 flags & VM_MAYSHARE ? 's' : 'p',
60033+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60034+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
60035+#else
60036 pgoff,
60037+#endif
60038 MAJOR(dev), MINOR(dev), ino, &len);
60039
60040 /*
60041@@ -302,7 +330,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60042 */
60043 if (file) {
60044 pad_len_spaces(m, len);
60045- seq_path(m, &file->f_path, "\n");
60046+ seq_path(m, &file->f_path, "\n\\");
60047 goto done;
60048 }
60049
60050@@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60051 * Thread stack in /proc/PID/task/TID/maps or
60052 * the main process stack.
60053 */
60054- if (!is_pid || (vma->vm_start <= mm->start_stack &&
60055- vma->vm_end >= mm->start_stack)) {
60056+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
60057+ (vma->vm_start <= mm->start_stack &&
60058+ vma->vm_end >= mm->start_stack)) {
60059 name = "[stack]";
60060 } else {
60061 /* Thread stack in /proc/PID/maps */
60062@@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
60063 struct proc_maps_private *priv = m->private;
60064 struct task_struct *task = priv->task;
60065
60066+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60067+ if (current->exec_id != m->exec_id) {
60068+ gr_log_badprocpid("maps");
60069+ return 0;
60070+ }
60071+#endif
60072+
60073 show_map_vma(m, vma, is_pid);
60074
60075 if (m->count < m->size) /* vma is copied successfully */
60076@@ -590,12 +626,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
60077 .private = &mss,
60078 };
60079
60080+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60081+ if (current->exec_id != m->exec_id) {
60082+ gr_log_badprocpid("smaps");
60083+ return 0;
60084+ }
60085+#endif
60086 memset(&mss, 0, sizeof mss);
60087- mss.vma = vma;
60088- /* mmap_sem is held in m_start */
60089- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
60090- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
60091-
60092+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60093+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
60094+#endif
60095+ mss.vma = vma;
60096+ /* mmap_sem is held in m_start */
60097+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
60098+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
60099+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60100+ }
60101+#endif
60102 show_map_vma(m, vma, is_pid);
60103
60104 seq_printf(m,
60105@@ -613,7 +660,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
60106 "KernelPageSize: %8lu kB\n"
60107 "MMUPageSize: %8lu kB\n"
60108 "Locked: %8lu kB\n",
60109+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60110+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
60111+#else
60112 (vma->vm_end - vma->vm_start) >> 10,
60113+#endif
60114 mss.resident >> 10,
60115 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
60116 mss.shared_clean >> 10,
60117@@ -1362,6 +1413,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60118 int n;
60119 char buffer[50];
60120
60121+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60122+ if (current->exec_id != m->exec_id) {
60123+ gr_log_badprocpid("numa_maps");
60124+ return 0;
60125+ }
60126+#endif
60127+
60128 if (!mm)
60129 return 0;
60130
60131@@ -1379,11 +1437,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60132 mpol_to_str(buffer, sizeof(buffer), pol);
60133 mpol_cond_put(pol);
60134
60135+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60136+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
60137+#else
60138 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
60139+#endif
60140
60141 if (file) {
60142 seq_printf(m, " file=");
60143- seq_path(m, &file->f_path, "\n\t= ");
60144+ seq_path(m, &file->f_path, "\n\t\\= ");
60145 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
60146 seq_printf(m, " heap");
60147 } else {
60148diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
60149index 56123a6..5a2f6ec 100644
60150--- a/fs/proc/task_nommu.c
60151+++ b/fs/proc/task_nommu.c
60152@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
60153 else
60154 bytes += kobjsize(mm);
60155
60156- if (current->fs && current->fs->users > 1)
60157+ if (current->fs && atomic_read(&current->fs->users) > 1)
60158 sbytes += kobjsize(current->fs);
60159 else
60160 bytes += kobjsize(current->fs);
60161@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
60162
60163 if (file) {
60164 pad_len_spaces(m, len);
60165- seq_path(m, &file->f_path, "");
60166+ seq_path(m, &file->f_path, "\n\\");
60167 } else if (mm) {
60168 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
60169
60170diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
60171index a1a16eb..6be46ed 100644
60172--- a/fs/proc/vmcore.c
60173+++ b/fs/proc/vmcore.c
60174@@ -104,9 +104,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
60175 nr_bytes = count;
60176
60177 /* If pfn is not ram, return zeros for sparse dump files */
60178- if (pfn_is_ram(pfn) == 0)
60179- memset(buf, 0, nr_bytes);
60180- else {
60181+ if (pfn_is_ram(pfn) == 0) {
60182+ if (userbuf) {
60183+ if (clear_user((char __force_user *)buf, nr_bytes))
60184+ return -EFAULT;
60185+ } else
60186+ memset(buf, 0, nr_bytes);
60187+ } else {
60188 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
60189 offset, userbuf);
60190 if (tmp < 0)
60191@@ -178,7 +182,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
60192 if (*fpos < m->offset + m->size) {
60193 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
60194 start = m->paddr + *fpos - m->offset;
60195- tmp = read_from_oldmem(buffer, tsz, &start, 1);
60196+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
60197 if (tmp < 0)
60198 return tmp;
60199 buflen -= tsz;
60200diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
60201index b00fcc9..e0c6381 100644
60202--- a/fs/qnx6/qnx6.h
60203+++ b/fs/qnx6/qnx6.h
60204@@ -74,7 +74,7 @@ enum {
60205 BYTESEX_BE,
60206 };
60207
60208-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60209+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60210 {
60211 if (sbi->s_bytesex == BYTESEX_LE)
60212 return le64_to_cpu((__force __le64)n);
60213@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
60214 return (__force __fs64)cpu_to_be64(n);
60215 }
60216
60217-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60218+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60219 {
60220 if (sbi->s_bytesex == BYTESEX_LE)
60221 return le32_to_cpu((__force __le32)n);
60222diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
60223index 16e8abb..2dcf914 100644
60224--- a/fs/quota/netlink.c
60225+++ b/fs/quota/netlink.c
60226@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
60227 void quota_send_warning(struct kqid qid, dev_t dev,
60228 const char warntype)
60229 {
60230- static atomic_t seq;
60231+ static atomic_unchecked_t seq;
60232 struct sk_buff *skb;
60233 void *msg_head;
60234 int ret;
60235@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
60236 "VFS: Not enough memory to send quota warning.\n");
60237 return;
60238 }
60239- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
60240+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
60241 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
60242 if (!msg_head) {
60243 printk(KERN_ERR
60244diff --git a/fs/read_write.c b/fs/read_write.c
60245index 122a384..0b7ecf2 100644
60246--- a/fs/read_write.c
60247+++ b/fs/read_write.c
60248@@ -440,7 +440,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
60249
60250 old_fs = get_fs();
60251 set_fs(get_ds());
60252- p = (__force const char __user *)buf;
60253+ p = (const char __force_user *)buf;
60254 if (count > MAX_RW_COUNT)
60255 count = MAX_RW_COUNT;
60256 if (file->f_op->write)
60257diff --git a/fs/readdir.c b/fs/readdir.c
60258index 93d71e5..6a14be8 100644
60259--- a/fs/readdir.c
60260+++ b/fs/readdir.c
60261@@ -17,6 +17,7 @@
60262 #include <linux/security.h>
60263 #include <linux/syscalls.h>
60264 #include <linux/unistd.h>
60265+#include <linux/namei.h>
60266
60267 #include <asm/uaccess.h>
60268
60269@@ -69,6 +70,7 @@ struct old_linux_dirent {
60270 struct readdir_callback {
60271 struct dir_context ctx;
60272 struct old_linux_dirent __user * dirent;
60273+ struct file * file;
60274 int result;
60275 };
60276
60277@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
60278 buf->result = -EOVERFLOW;
60279 return -EOVERFLOW;
60280 }
60281+
60282+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60283+ return 0;
60284+
60285 buf->result++;
60286 dirent = buf->dirent;
60287 if (!access_ok(VERIFY_WRITE, dirent,
60288@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60289 if (!f.file)
60290 return -EBADF;
60291
60292+ buf.file = f.file;
60293 error = iterate_dir(f.file, &buf.ctx);
60294 if (buf.result)
60295 error = buf.result;
60296@@ -142,6 +149,7 @@ struct getdents_callback {
60297 struct dir_context ctx;
60298 struct linux_dirent __user * current_dir;
60299 struct linux_dirent __user * previous;
60300+ struct file * file;
60301 int count;
60302 int error;
60303 };
60304@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
60305 buf->error = -EOVERFLOW;
60306 return -EOVERFLOW;
60307 }
60308+
60309+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60310+ return 0;
60311+
60312 dirent = buf->previous;
60313 if (dirent) {
60314 if (__put_user(offset, &dirent->d_off))
60315@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
60316 if (!f.file)
60317 return -EBADF;
60318
60319+ buf.file = f.file;
60320 error = iterate_dir(f.file, &buf.ctx);
60321 if (error >= 0)
60322 error = buf.error;
60323@@ -226,6 +239,7 @@ struct getdents_callback64 {
60324 struct dir_context ctx;
60325 struct linux_dirent64 __user * current_dir;
60326 struct linux_dirent64 __user * previous;
60327+ struct file *file;
60328 int count;
60329 int error;
60330 };
60331@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
60332 buf->error = -EINVAL; /* only used if we fail.. */
60333 if (reclen > buf->count)
60334 return -EINVAL;
60335+
60336+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60337+ return 0;
60338+
60339 dirent = buf->previous;
60340 if (dirent) {
60341 if (__put_user(offset, &dirent->d_off))
60342@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60343 if (!f.file)
60344 return -EBADF;
60345
60346+ buf.file = f.file;
60347 error = iterate_dir(f.file, &buf.ctx);
60348 if (error >= 0)
60349 error = buf.error;
60350diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
60351index 2b7882b..1c5ef48 100644
60352--- a/fs/reiserfs/do_balan.c
60353+++ b/fs/reiserfs/do_balan.c
60354@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
60355 return;
60356 }
60357
60358- atomic_inc(&(fs_generation(tb->tb_sb)));
60359+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
60360 do_balance_starts(tb);
60361
60362 /* balance leaf returns 0 except if combining L R and S into
60363diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
60364index a958444..42b2323 100644
60365--- a/fs/reiserfs/procfs.c
60366+++ b/fs/reiserfs/procfs.c
60367@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
60368 "SMALL_TAILS " : "NO_TAILS ",
60369 replay_only(sb) ? "REPLAY_ONLY " : "",
60370 convert_reiserfs(sb) ? "CONV " : "",
60371- atomic_read(&r->s_generation_counter),
60372+ atomic_read_unchecked(&r->s_generation_counter),
60373 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
60374 SF(s_do_balance), SF(s_unneeded_left_neighbor),
60375 SF(s_good_search_by_key_reada), SF(s_bmaps),
60376diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
60377index 3df5ce6..8c0f4b0 100644
60378--- a/fs/reiserfs/reiserfs.h
60379+++ b/fs/reiserfs/reiserfs.h
60380@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
60381 /* Comment? -Hans */
60382 wait_queue_head_t s_wait;
60383 /* To be obsoleted soon by per buffer seals.. -Hans */
60384- atomic_t s_generation_counter; // increased by one every time the
60385+ atomic_unchecked_t s_generation_counter; // increased by one every time the
60386 // tree gets re-balanced
60387 unsigned long s_properties; /* File system properties. Currently holds
60388 on-disk FS format */
60389@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
60390 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
60391
60392 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
60393-#define get_generation(s) atomic_read (&fs_generation(s))
60394+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
60395 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
60396 #define __fs_changed(gen,s) (gen != get_generation (s))
60397 #define fs_changed(gen,s) \
60398diff --git a/fs/select.c b/fs/select.c
60399index 35d4adc7..d6c60db 100644
60400--- a/fs/select.c
60401+++ b/fs/select.c
60402@@ -20,6 +20,7 @@
60403 #include <linux/export.h>
60404 #include <linux/slab.h>
60405 #include <linux/poll.h>
60406+#include <linux/security.h>
60407 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
60408 #include <linux/file.h>
60409 #include <linux/fdtable.h>
60410@@ -881,6 +882,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
60411 struct poll_list *walk = head;
60412 unsigned long todo = nfds;
60413
60414+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
60415 if (nfds > rlimit(RLIMIT_NOFILE))
60416 return -EINVAL;
60417
60418diff --git a/fs/seq_file.c b/fs/seq_file.c
60419index 3135c25..d0395dd 100644
60420--- a/fs/seq_file.c
60421+++ b/fs/seq_file.c
60422@@ -10,6 +10,7 @@
60423 #include <linux/seq_file.h>
60424 #include <linux/slab.h>
60425 #include <linux/cred.h>
60426+#include <linux/sched.h>
60427
60428 #include <asm/uaccess.h>
60429 #include <asm/page.h>
60430@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
60431 #ifdef CONFIG_USER_NS
60432 p->user_ns = file->f_cred->user_ns;
60433 #endif
60434+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60435+ p->exec_id = current->exec_id;
60436+#endif
60437
60438 /*
60439 * Wrappers around seq_open(e.g. swaps_open) need to be
60440@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60441 return 0;
60442 }
60443 if (!m->buf) {
60444- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60445+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60446 if (!m->buf)
60447 return -ENOMEM;
60448 }
60449@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60450 Eoverflow:
60451 m->op->stop(m, p);
60452 kfree(m->buf);
60453- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60454+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60455 return !m->buf ? -ENOMEM : -EAGAIN;
60456 }
60457
60458@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60459
60460 /* grab buffer if we didn't have one */
60461 if (!m->buf) {
60462- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60463+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60464 if (!m->buf)
60465 goto Enomem;
60466 }
60467@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60468 goto Fill;
60469 m->op->stop(m, p);
60470 kfree(m->buf);
60471- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60472+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60473 if (!m->buf)
60474 goto Enomem;
60475 m->count = 0;
60476@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
60477 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
60478 void *data)
60479 {
60480- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
60481+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
60482 int res = -ENOMEM;
60483
60484 if (op) {
60485diff --git a/fs/splice.c b/fs/splice.c
60486index 3b7ee65..87fc2e4 100644
60487--- a/fs/splice.c
60488+++ b/fs/splice.c
60489@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60490 pipe_lock(pipe);
60491
60492 for (;;) {
60493- if (!pipe->readers) {
60494+ if (!atomic_read(&pipe->readers)) {
60495 send_sig(SIGPIPE, current, 0);
60496 if (!ret)
60497 ret = -EPIPE;
60498@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60499 page_nr++;
60500 ret += buf->len;
60501
60502- if (pipe->files)
60503+ if (atomic_read(&pipe->files))
60504 do_wakeup = 1;
60505
60506 if (!--spd->nr_pages)
60507@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60508 do_wakeup = 0;
60509 }
60510
60511- pipe->waiting_writers++;
60512+ atomic_inc(&pipe->waiting_writers);
60513 pipe_wait(pipe);
60514- pipe->waiting_writers--;
60515+ atomic_dec(&pipe->waiting_writers);
60516 }
60517
60518 pipe_unlock(pipe);
60519@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
60520 old_fs = get_fs();
60521 set_fs(get_ds());
60522 /* The cast to a user pointer is valid due to the set_fs() */
60523- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
60524+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
60525 set_fs(old_fs);
60526
60527 return res;
60528@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
60529 old_fs = get_fs();
60530 set_fs(get_ds());
60531 /* The cast to a user pointer is valid due to the set_fs() */
60532- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
60533+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
60534 set_fs(old_fs);
60535
60536 return res;
60537@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
60538 goto err;
60539
60540 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
60541- vec[i].iov_base = (void __user *) page_address(page);
60542+ vec[i].iov_base = (void __force_user *) page_address(page);
60543 vec[i].iov_len = this_len;
60544 spd.pages[i] = page;
60545 spd.nr_pages++;
60546@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
60547 ops->release(pipe, buf);
60548 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
60549 pipe->nrbufs--;
60550- if (pipe->files)
60551+ if (atomic_read(&pipe->files))
60552 sd->need_wakeup = true;
60553 }
60554
60555@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
60556 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
60557 {
60558 while (!pipe->nrbufs) {
60559- if (!pipe->writers)
60560+ if (!atomic_read(&pipe->writers))
60561 return 0;
60562
60563- if (!pipe->waiting_writers && sd->num_spliced)
60564+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
60565 return 0;
60566
60567 if (sd->flags & SPLICE_F_NONBLOCK)
60568@@ -1179,7 +1179,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
60569 * out of the pipe right after the splice_to_pipe(). So set
60570 * PIPE_READERS appropriately.
60571 */
60572- pipe->readers = 1;
60573+ atomic_set(&pipe->readers, 1);
60574
60575 current->splice_pipe = pipe;
60576 }
60577@@ -1475,6 +1475,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
60578
60579 partial[buffers].offset = off;
60580 partial[buffers].len = plen;
60581+ partial[buffers].private = 0;
60582
60583 off = 0;
60584 len -= plen;
60585@@ -1777,9 +1778,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60586 ret = -ERESTARTSYS;
60587 break;
60588 }
60589- if (!pipe->writers)
60590+ if (!atomic_read(&pipe->writers))
60591 break;
60592- if (!pipe->waiting_writers) {
60593+ if (!atomic_read(&pipe->waiting_writers)) {
60594 if (flags & SPLICE_F_NONBLOCK) {
60595 ret = -EAGAIN;
60596 break;
60597@@ -1811,7 +1812,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60598 pipe_lock(pipe);
60599
60600 while (pipe->nrbufs >= pipe->buffers) {
60601- if (!pipe->readers) {
60602+ if (!atomic_read(&pipe->readers)) {
60603 send_sig(SIGPIPE, current, 0);
60604 ret = -EPIPE;
60605 break;
60606@@ -1824,9 +1825,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60607 ret = -ERESTARTSYS;
60608 break;
60609 }
60610- pipe->waiting_writers++;
60611+ atomic_inc(&pipe->waiting_writers);
60612 pipe_wait(pipe);
60613- pipe->waiting_writers--;
60614+ atomic_dec(&pipe->waiting_writers);
60615 }
60616
60617 pipe_unlock(pipe);
60618@@ -1862,14 +1863,14 @@ retry:
60619 pipe_double_lock(ipipe, opipe);
60620
60621 do {
60622- if (!opipe->readers) {
60623+ if (!atomic_read(&opipe->readers)) {
60624 send_sig(SIGPIPE, current, 0);
60625 if (!ret)
60626 ret = -EPIPE;
60627 break;
60628 }
60629
60630- if (!ipipe->nrbufs && !ipipe->writers)
60631+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
60632 break;
60633
60634 /*
60635@@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60636 pipe_double_lock(ipipe, opipe);
60637
60638 do {
60639- if (!opipe->readers) {
60640+ if (!atomic_read(&opipe->readers)) {
60641 send_sig(SIGPIPE, current, 0);
60642 if (!ret)
60643 ret = -EPIPE;
60644@@ -2011,7 +2012,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60645 * return EAGAIN if we have the potential of some data in the
60646 * future, otherwise just return 0
60647 */
60648- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
60649+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
60650 ret = -EAGAIN;
60651
60652 pipe_unlock(ipipe);
60653diff --git a/fs/stat.c b/fs/stat.c
60654index 04ce1ac..a13dd1e 100644
60655--- a/fs/stat.c
60656+++ b/fs/stat.c
60657@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
60658 stat->gid = inode->i_gid;
60659 stat->rdev = inode->i_rdev;
60660 stat->size = i_size_read(inode);
60661- stat->atime = inode->i_atime;
60662- stat->mtime = inode->i_mtime;
60663+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60664+ stat->atime = inode->i_ctime;
60665+ stat->mtime = inode->i_ctime;
60666+ } else {
60667+ stat->atime = inode->i_atime;
60668+ stat->mtime = inode->i_mtime;
60669+ }
60670 stat->ctime = inode->i_ctime;
60671 stat->blksize = (1 << inode->i_blkbits);
60672 stat->blocks = inode->i_blocks;
60673@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
60674 if (retval)
60675 return retval;
60676
60677- if (inode->i_op->getattr)
60678- return inode->i_op->getattr(path->mnt, path->dentry, stat);
60679+ if (inode->i_op->getattr) {
60680+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
60681+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60682+ stat->atime = stat->ctime;
60683+ stat->mtime = stat->ctime;
60684+ }
60685+ return retval;
60686+ }
60687
60688 generic_fillattr(inode, stat);
60689 return 0;
60690diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
60691index 15c68f9..36a8b3e 100644
60692--- a/fs/sysfs/bin.c
60693+++ b/fs/sysfs/bin.c
60694@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
60695 return ret;
60696 }
60697
60698-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
60699- void *buf, int len, int write)
60700+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
60701+ void *buf, size_t len, int write)
60702 {
60703 struct file *file = vma->vm_file;
60704 struct bin_buffer *bb = file->private_data;
60705 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
60706- int ret;
60707+ ssize_t ret;
60708
60709 if (!bb->vm_ops)
60710 return -EINVAL;
60711diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
60712index e068e74..92edeb8 100644
60713--- a/fs/sysfs/dir.c
60714+++ b/fs/sysfs/dir.c
60715@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
60716 *
60717 * Returns 31 bit hash of ns + name (so it fits in an off_t )
60718 */
60719-static unsigned int sysfs_name_hash(const void *ns, const char *name)
60720+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
60721 {
60722 unsigned long hash = init_name_hash();
60723 unsigned int len = strlen(name);
60724@@ -679,6 +679,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
60725 struct sysfs_dirent *sd;
60726 int rc;
60727
60728+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60729+ const char *parent_name = parent_sd->s_name;
60730+
60731+ mode = S_IFDIR | S_IRWXU;
60732+
60733+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
60734+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
60735+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
60736+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
60737+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
60738+#endif
60739+
60740 /* allocate */
60741 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
60742 if (!sd)
60743diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
60744index d2bb7ed..fe8c331 100644
60745--- a/fs/sysfs/file.c
60746+++ b/fs/sysfs/file.c
60747@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
60748
60749 struct sysfs_open_dirent {
60750 atomic_t refcnt;
60751- atomic_t event;
60752+ atomic_unchecked_t event;
60753 wait_queue_head_t poll;
60754 struct list_head buffers; /* goes through sysfs_buffer.list */
60755 };
60756@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
60757 if (!sysfs_get_active(attr_sd))
60758 return -ENODEV;
60759
60760- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
60761+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
60762 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
60763
60764 sysfs_put_active(attr_sd);
60765@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
60766 return -ENOMEM;
60767
60768 atomic_set(&new_od->refcnt, 0);
60769- atomic_set(&new_od->event, 1);
60770+ atomic_set_unchecked(&new_od->event, 1);
60771 init_waitqueue_head(&new_od->poll);
60772 INIT_LIST_HEAD(&new_od->buffers);
60773 goto retry;
60774@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
60775
60776 sysfs_put_active(attr_sd);
60777
60778- if (buffer->event != atomic_read(&od->event))
60779+ if (buffer->event != atomic_read_unchecked(&od->event))
60780 goto trigger;
60781
60782 return DEFAULT_POLLMASK;
60783@@ -452,7 +452,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
60784 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
60785 od = sd->s_attr.open;
60786 if (od) {
60787- atomic_inc(&od->event);
60788+ atomic_inc_unchecked(&od->event);
60789 wake_up_interruptible(&od->poll);
60790 }
60791 }
60792diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
60793index 8c940df..25b733e 100644
60794--- a/fs/sysfs/symlink.c
60795+++ b/fs/sysfs/symlink.c
60796@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
60797
60798 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
60799 {
60800- char *page = nd_get_link(nd);
60801+ const char *page = nd_get_link(nd);
60802 if (!IS_ERR(page))
60803 free_page((unsigned long)page);
60804 }
60805diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
60806index 69d4889..a810bd4 100644
60807--- a/fs/sysv/sysv.h
60808+++ b/fs/sysv/sysv.h
60809@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
60810 #endif
60811 }
60812
60813-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60814+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60815 {
60816 if (sbi->s_bytesex == BYTESEX_PDP)
60817 return PDP_swab((__force __u32)n);
60818diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
60819index e18b988..f1d4ad0f 100644
60820--- a/fs/ubifs/io.c
60821+++ b/fs/ubifs/io.c
60822@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
60823 return err;
60824 }
60825
60826-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60827+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60828 {
60829 int err;
60830
60831diff --git a/fs/udf/misc.c b/fs/udf/misc.c
60832index c175b4d..8f36a16 100644
60833--- a/fs/udf/misc.c
60834+++ b/fs/udf/misc.c
60835@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
60836
60837 u8 udf_tag_checksum(const struct tag *t)
60838 {
60839- u8 *data = (u8 *)t;
60840+ const u8 *data = (const u8 *)t;
60841 u8 checksum = 0;
60842 int i;
60843 for (i = 0; i < sizeof(struct tag); ++i)
60844diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
60845index 8d974c4..b82f6ec 100644
60846--- a/fs/ufs/swab.h
60847+++ b/fs/ufs/swab.h
60848@@ -22,7 +22,7 @@ enum {
60849 BYTESEX_BE
60850 };
60851
60852-static inline u64
60853+static inline u64 __intentional_overflow(-1)
60854 fs64_to_cpu(struct super_block *sbp, __fs64 n)
60855 {
60856 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60857@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
60858 return (__force __fs64)cpu_to_be64(n);
60859 }
60860
60861-static inline u32
60862+static inline u32 __intentional_overflow(-1)
60863 fs32_to_cpu(struct super_block *sbp, __fs32 n)
60864 {
60865 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60866diff --git a/fs/utimes.c b/fs/utimes.c
60867index f4fb7ec..3fe03c0 100644
60868--- a/fs/utimes.c
60869+++ b/fs/utimes.c
60870@@ -1,6 +1,7 @@
60871 #include <linux/compiler.h>
60872 #include <linux/file.h>
60873 #include <linux/fs.h>
60874+#include <linux/security.h>
60875 #include <linux/linkage.h>
60876 #include <linux/mount.h>
60877 #include <linux/namei.h>
60878@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
60879 goto mnt_drop_write_and_out;
60880 }
60881 }
60882+
60883+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
60884+ error = -EACCES;
60885+ goto mnt_drop_write_and_out;
60886+ }
60887+
60888 mutex_lock(&inode->i_mutex);
60889 error = notify_change(path->dentry, &newattrs);
60890 mutex_unlock(&inode->i_mutex);
60891diff --git a/fs/xattr.c b/fs/xattr.c
60892index 3377dff..4d074d9 100644
60893--- a/fs/xattr.c
60894+++ b/fs/xattr.c
60895@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
60896 return rc;
60897 }
60898
60899+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
60900+ssize_t
60901+pax_getxattr(struct dentry *dentry, void *value, size_t size)
60902+{
60903+ struct inode *inode = dentry->d_inode;
60904+ ssize_t error;
60905+
60906+ error = inode_permission(inode, MAY_EXEC);
60907+ if (error)
60908+ return error;
60909+
60910+ if (inode->i_op->getxattr)
60911+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
60912+ else
60913+ error = -EOPNOTSUPP;
60914+
60915+ return error;
60916+}
60917+EXPORT_SYMBOL(pax_getxattr);
60918+#endif
60919+
60920 ssize_t
60921 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
60922 {
60923@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
60924 * Extended attribute SET operations
60925 */
60926 static long
60927-setxattr(struct dentry *d, const char __user *name, const void __user *value,
60928+setxattr(struct path *path, const char __user *name, const void __user *value,
60929 size_t size, int flags)
60930 {
60931 int error;
60932@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
60933 posix_acl_fix_xattr_from_user(kvalue, size);
60934 }
60935
60936- error = vfs_setxattr(d, kname, kvalue, size, flags);
60937+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
60938+ error = -EACCES;
60939+ goto out;
60940+ }
60941+
60942+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
60943 out:
60944 if (vvalue)
60945 vfree(vvalue);
60946@@ -377,7 +403,7 @@ retry:
60947 return error;
60948 error = mnt_want_write(path.mnt);
60949 if (!error) {
60950- error = setxattr(path.dentry, name, value, size, flags);
60951+ error = setxattr(&path, name, value, size, flags);
60952 mnt_drop_write(path.mnt);
60953 }
60954 path_put(&path);
60955@@ -401,7 +427,7 @@ retry:
60956 return error;
60957 error = mnt_want_write(path.mnt);
60958 if (!error) {
60959- error = setxattr(path.dentry, name, value, size, flags);
60960+ error = setxattr(&path, name, value, size, flags);
60961 mnt_drop_write(path.mnt);
60962 }
60963 path_put(&path);
60964@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
60965 const void __user *,value, size_t, size, int, flags)
60966 {
60967 struct fd f = fdget(fd);
60968- struct dentry *dentry;
60969 int error = -EBADF;
60970
60971 if (!f.file)
60972 return error;
60973- dentry = f.file->f_path.dentry;
60974- audit_inode(NULL, dentry, 0);
60975+ audit_inode(NULL, f.file->f_path.dentry, 0);
60976 error = mnt_want_write_file(f.file);
60977 if (!error) {
60978- error = setxattr(dentry, name, value, size, flags);
60979+ error = setxattr(&f.file->f_path, name, value, size, flags);
60980 mnt_drop_write_file(f.file);
60981 }
60982 fdput(f);
60983diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
60984index 9fbea87..6b19972 100644
60985--- a/fs/xattr_acl.c
60986+++ b/fs/xattr_acl.c
60987@@ -76,8 +76,8 @@ struct posix_acl *
60988 posix_acl_from_xattr(struct user_namespace *user_ns,
60989 const void *value, size_t size)
60990 {
60991- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
60992- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
60993+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
60994+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
60995 int count;
60996 struct posix_acl *acl;
60997 struct posix_acl_entry *acl_e;
60998diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
60999index 05c698c..6b918af 100644
61000--- a/fs/xfs/xfs_bmap.c
61001+++ b/fs/xfs/xfs_bmap.c
61002@@ -765,7 +765,7 @@ xfs_bmap_validate_ret(
61003
61004 #else
61005 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
61006-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
61007+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
61008 #endif /* DEBUG */
61009
61010 /*
61011diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
61012index 97676a3..399a75d 100644
61013--- a/fs/xfs/xfs_dir2_sf.c
61014+++ b/fs/xfs/xfs_dir2_sf.c
61015@@ -848,7 +848,12 @@ xfs_dir2_sf_getdents(
61016
61017 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
61018 ctx->pos = off & 0x7fffffff;
61019- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
61020+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
61021+ char name[sfep->namelen];
61022+ memcpy(name, sfep->name, sfep->namelen);
61023+ if (!dir_emit(ctx, name, sfep->namelen, ino, DT_UNKNOWN))
61024+ return 0;
61025+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
61026 ino, DT_UNKNOWN))
61027 return 0;
61028 sfep = xfs_dir2_sf_nextentry(sfp, sfep);
61029diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
61030index 6e2bca5..6ce80d3 100644
61031--- a/fs/xfs/xfs_ioctl.c
61032+++ b/fs/xfs/xfs_ioctl.c
61033@@ -127,7 +127,7 @@ xfs_find_handle(
61034 }
61035
61036 error = -EFAULT;
61037- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
61038+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
61039 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
61040 goto out_put;
61041
61042diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
61043index 96dda62..d6c6a52 100644
61044--- a/fs/xfs/xfs_iops.c
61045+++ b/fs/xfs/xfs_iops.c
61046@@ -395,7 +395,7 @@ xfs_vn_put_link(
61047 struct nameidata *nd,
61048 void *p)
61049 {
61050- char *s = nd_get_link(nd);
61051+ const char *s = nd_get_link(nd);
61052
61053 if (!IS_ERR(s))
61054 kfree(s);
61055diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
61056new file mode 100644
61057index 0000000..0fd7c82
61058--- /dev/null
61059+++ b/grsecurity/Kconfig
61060@@ -0,0 +1,1080 @@
61061+#
61062+# grecurity configuration
61063+#
61064+menu "Memory Protections"
61065+depends on GRKERNSEC
61066+
61067+config GRKERNSEC_KMEM
61068+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
61069+ default y if GRKERNSEC_CONFIG_AUTO
61070+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
61071+ help
61072+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
61073+ be written to or read from to modify or leak the contents of the running
61074+ kernel. /dev/port will also not be allowed to be opened and support
61075+ for /dev/cpu/*/msr will be removed. If you have module
61076+ support disabled, enabling this will close up five ways that are
61077+ currently used to insert malicious code into the running kernel.
61078+
61079+ Even with all these features enabled, we still highly recommend that
61080+ you use the RBAC system, as it is still possible for an attacker to
61081+ modify the running kernel through privileged I/O granted by ioperm/iopl.
61082+
61083+ If you are not using XFree86, you may be able to stop this additional
61084+ case by enabling the 'Disable privileged I/O' option. Though nothing
61085+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
61086+ but only to video memory, which is the only writing we allow in this
61087+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
61088+ not be allowed to mprotect it with PROT_WRITE later.
61089+ Enabling this feature will prevent the "cpupower" and "powertop" tools
61090+ from working.
61091+
61092+ It is highly recommended that you say Y here if you meet all the
61093+ conditions above.
61094+
61095+config GRKERNSEC_VM86
61096+ bool "Restrict VM86 mode"
61097+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61098+ depends on X86_32
61099+
61100+ help
61101+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
61102+ make use of a special execution mode on 32bit x86 processors called
61103+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
61104+ video cards and will still work with this option enabled. The purpose
61105+ of the option is to prevent exploitation of emulation errors in
61106+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
61107+ Nearly all users should be able to enable this option.
61108+
61109+config GRKERNSEC_IO
61110+ bool "Disable privileged I/O"
61111+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61112+ depends on X86
61113+ select RTC_CLASS
61114+ select RTC_INTF_DEV
61115+ select RTC_DRV_CMOS
61116+
61117+ help
61118+ If you say Y here, all ioperm and iopl calls will return an error.
61119+ Ioperm and iopl can be used to modify the running kernel.
61120+ Unfortunately, some programs need this access to operate properly,
61121+ the most notable of which are XFree86 and hwclock. hwclock can be
61122+ remedied by having RTC support in the kernel, so real-time
61123+ clock support is enabled if this option is enabled, to ensure
61124+ that hwclock operates correctly. XFree86 still will not
61125+ operate correctly with this option enabled, so DO NOT CHOOSE Y
61126+ IF YOU USE XFree86. If you use XFree86 and you still want to
61127+ protect your kernel against modification, use the RBAC system.
61128+
61129+config GRKERNSEC_JIT_HARDEN
61130+ bool "Harden BPF JIT against spray attacks"
61131+ default y if GRKERNSEC_CONFIG_AUTO
61132+ depends on BPF_JIT
61133+ help
61134+ If you say Y here, the native code generated by the kernel's Berkeley
61135+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
61136+ attacks that attempt to fit attacker-beneficial instructions in
61137+ 32bit immediate fields of JIT-generated native instructions. The
61138+ attacker will generally aim to cause an unintended instruction sequence
61139+ of JIT-generated native code to execute by jumping into the middle of
61140+ a generated instruction. This feature effectively randomizes the 32bit
61141+ immediate constants present in the generated code to thwart such attacks.
61142+
61143+ If you're using KERNEXEC, it's recommended that you enable this option
61144+ to supplement the hardening of the kernel.
61145+
61146+config GRKERNSEC_PERF_HARDEN
61147+ bool "Disable unprivileged PERF_EVENTS usage by default"
61148+ default y if GRKERNSEC_CONFIG_AUTO
61149+ depends on PERF_EVENTS
61150+ help
61151+ If you say Y here, the range of acceptable values for the
61152+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
61153+ default to a new value: 3. When the sysctl is set to this value, no
61154+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
61155+
61156+ Though PERF_EVENTS can be used legitimately for performance monitoring
61157+ and low-level application profiling, it is forced on regardless of
61158+ configuration, has been at fault for several vulnerabilities, and
61159+ creates new opportunities for side channels and other information leaks.
61160+
61161+ This feature puts PERF_EVENTS into a secure default state and permits
61162+ the administrator to change out of it temporarily if unprivileged
61163+ application profiling is needed.
61164+
61165+config GRKERNSEC_RAND_THREADSTACK
61166+ bool "Insert random gaps between thread stacks"
61167+ default y if GRKERNSEC_CONFIG_AUTO
61168+ depends on PAX_RANDMMAP && !PPC
61169+ help
61170+ If you say Y here, a random-sized gap will be enforced between allocated
61171+ thread stacks. Glibc's NPTL and other threading libraries that
61172+ pass MAP_STACK to the kernel for thread stack allocation are supported.
61173+ The implementation currently provides 8 bits of entropy for the gap.
61174+
61175+ Many distributions do not compile threaded remote services with the
61176+ -fstack-check argument to GCC, causing the variable-sized stack-based
61177+ allocator, alloca(), to not probe the stack on allocation. This
61178+ permits an unbounded alloca() to skip over any guard page and potentially
61179+ modify another thread's stack reliably. An enforced random gap
61180+ reduces the reliability of such an attack and increases the chance
61181+ that such a read/write to another thread's stack instead lands in
61182+ an unmapped area, causing a crash and triggering grsecurity's
61183+ anti-bruteforcing logic.
61184+
61185+config GRKERNSEC_PROC_MEMMAP
61186+ bool "Harden ASLR against information leaks and entropy reduction"
61187+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
61188+ depends on PAX_NOEXEC || PAX_ASLR
61189+ help
61190+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
61191+ give no information about the addresses of its mappings if
61192+ PaX features that rely on random addresses are enabled on the task.
61193+ In addition to sanitizing this information and disabling other
61194+ dangerous sources of information, this option causes reads of sensitive
61195+ /proc/<pid> entries where the file descriptor was opened in a different
61196+ task than the one performing the read. Such attempts are logged.
61197+ This option also limits argv/env strings for suid/sgid binaries
61198+ to 512KB to prevent a complete exhaustion of the stack entropy provided
61199+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
61200+ binaries to prevent alternative mmap layouts from being abused.
61201+
61202+ If you use PaX it is essential that you say Y here as it closes up
61203+ several holes that make full ASLR useless locally.
61204+
61205+config GRKERNSEC_BRUTE
61206+ bool "Deter exploit bruteforcing"
61207+ default y if GRKERNSEC_CONFIG_AUTO
61208+ help
61209+ If you say Y here, attempts to bruteforce exploits against forking
61210+ daemons such as apache or sshd, as well as against suid/sgid binaries
61211+ will be deterred. When a child of a forking daemon is killed by PaX
61212+ or crashes due to an illegal instruction or other suspicious signal,
61213+ the parent process will be delayed 30 seconds upon every subsequent
61214+ fork until the administrator is able to assess the situation and
61215+ restart the daemon.
61216+ In the suid/sgid case, the attempt is logged, the user has all their
61217+ existing instances of the suid/sgid binary terminated and will
61218+ be unable to execute any suid/sgid binaries for 15 minutes.
61219+
61220+ It is recommended that you also enable signal logging in the auditing
61221+ section so that logs are generated when a process triggers a suspicious
61222+ signal.
61223+ If the sysctl option is enabled, a sysctl option with name
61224+ "deter_bruteforce" is created.
61225+
61226+
61227+config GRKERNSEC_MODHARDEN
61228+ bool "Harden module auto-loading"
61229+ default y if GRKERNSEC_CONFIG_AUTO
61230+ depends on MODULES
61231+ help
61232+ If you say Y here, module auto-loading in response to use of some
61233+ feature implemented by an unloaded module will be restricted to
61234+ root users. Enabling this option helps defend against attacks
61235+ by unprivileged users who abuse the auto-loading behavior to
61236+ cause a vulnerable module to load that is then exploited.
61237+
61238+ If this option prevents a legitimate use of auto-loading for a
61239+ non-root user, the administrator can execute modprobe manually
61240+ with the exact name of the module mentioned in the alert log.
61241+ Alternatively, the administrator can add the module to the list
61242+ of modules loaded at boot by modifying init scripts.
61243+
61244+ Modification of init scripts will most likely be needed on
61245+ Ubuntu servers with encrypted home directory support enabled,
61246+ as the first non-root user logging in will cause the ecb(aes),
61247+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
61248+
61249+config GRKERNSEC_HIDESYM
61250+ bool "Hide kernel symbols"
61251+ default y if GRKERNSEC_CONFIG_AUTO
61252+ select PAX_USERCOPY_SLABS
61253+ help
61254+ If you say Y here, getting information on loaded modules, and
61255+ displaying all kernel symbols through a syscall will be restricted
61256+ to users with CAP_SYS_MODULE. For software compatibility reasons,
61257+ /proc/kallsyms will be restricted to the root user. The RBAC
61258+ system can hide that entry even from root.
61259+
61260+ This option also prevents leaking of kernel addresses through
61261+ several /proc entries.
61262+
61263+ Note that this option is only effective provided the following
61264+ conditions are met:
61265+ 1) The kernel using grsecurity is not precompiled by some distribution
61266+ 2) You have also enabled GRKERNSEC_DMESG
61267+ 3) You are using the RBAC system and hiding other files such as your
61268+ kernel image and System.map. Alternatively, enabling this option
61269+ causes the permissions on /boot, /lib/modules, and the kernel
61270+ source directory to change at compile time to prevent
61271+ reading by non-root users.
61272+ If the above conditions are met, this option will aid in providing a
61273+ useful protection against local kernel exploitation of overflows
61274+ and arbitrary read/write vulnerabilities.
61275+
61276+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
61277+ in addition to this feature.
61278+
61279+config GRKERNSEC_KERN_LOCKOUT
61280+ bool "Active kernel exploit response"
61281+ default y if GRKERNSEC_CONFIG_AUTO
61282+ depends on X86 || ARM || PPC || SPARC
61283+ help
61284+ If you say Y here, when a PaX alert is triggered due to suspicious
61285+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
61286+ or an OOPS occurs due to bad memory accesses, instead of just
61287+ terminating the offending process (and potentially allowing
61288+ a subsequent exploit from the same user), we will take one of two
61289+ actions:
61290+ If the user was root, we will panic the system
61291+ If the user was non-root, we will log the attempt, terminate
61292+ all processes owned by the user, then prevent them from creating
61293+ any new processes until the system is restarted
61294+ This deters repeated kernel exploitation/bruteforcing attempts
61295+ and is useful for later forensics.
61296+
61297+endmenu
61298+menu "Role Based Access Control Options"
61299+depends on GRKERNSEC
61300+
61301+config GRKERNSEC_RBAC_DEBUG
61302+ bool
61303+
61304+config GRKERNSEC_NO_RBAC
61305+ bool "Disable RBAC system"
61306+ help
61307+ If you say Y here, the /dev/grsec device will be removed from the kernel,
61308+ preventing the RBAC system from being enabled. You should only say Y
61309+ here if you have no intention of using the RBAC system, so as to prevent
61310+ an attacker with root access from misusing the RBAC system to hide files
61311+ and processes when loadable module support and /dev/[k]mem have been
61312+ locked down.
61313+
61314+config GRKERNSEC_ACL_HIDEKERN
61315+ bool "Hide kernel processes"
61316+ help
61317+ If you say Y here, all kernel threads will be hidden to all
61318+ processes but those whose subject has the "view hidden processes"
61319+ flag.
61320+
61321+config GRKERNSEC_ACL_MAXTRIES
61322+ int "Maximum tries before password lockout"
61323+ default 3
61324+ help
61325+ This option enforces the maximum number of times a user can attempt
61326+ to authorize themselves with the grsecurity RBAC system before being
61327+ denied the ability to attempt authorization again for a specified time.
61328+ The lower the number, the harder it will be to brute-force a password.
61329+
61330+config GRKERNSEC_ACL_TIMEOUT
61331+ int "Time to wait after max password tries, in seconds"
61332+ default 30
61333+ help
61334+ This option specifies the time the user must wait after attempting to
61335+ authorize to the RBAC system with the maximum number of invalid
61336+ passwords. The higher the number, the harder it will be to brute-force
61337+ a password.
61338+
61339+endmenu
61340+menu "Filesystem Protections"
61341+depends on GRKERNSEC
61342+
61343+config GRKERNSEC_PROC
61344+ bool "Proc restrictions"
61345+ default y if GRKERNSEC_CONFIG_AUTO
61346+ help
61347+ If you say Y here, the permissions of the /proc filesystem
61348+ will be altered to enhance system security and privacy. You MUST
61349+ choose either a user only restriction or a user and group restriction.
61350+ Depending upon the option you choose, you can either restrict users to
61351+ see only the processes they themselves run, or choose a group that can
61352+ view all processes and files normally restricted to root if you choose
61353+ the "restrict to user only" option. NOTE: If you're running identd or
61354+ ntpd as a non-root user, you will have to run it as the group you
61355+ specify here.
61356+
61357+config GRKERNSEC_PROC_USER
61358+ bool "Restrict /proc to user only"
61359+ depends on GRKERNSEC_PROC
61360+ help
61361+ If you say Y here, non-root users will only be able to view their own
61362+ processes, and restricts them from viewing network-related information,
61363+ and viewing kernel symbol and module information.
61364+
61365+config GRKERNSEC_PROC_USERGROUP
61366+ bool "Allow special group"
61367+ default y if GRKERNSEC_CONFIG_AUTO
61368+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
61369+ help
61370+ If you say Y here, you will be able to select a group that will be
61371+ able to view all processes and network-related information. If you've
61372+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
61373+ remain hidden. This option is useful if you want to run identd as
61374+ a non-root user. The group you select may also be chosen at boot time
61375+ via "grsec_proc_gid=" on the kernel commandline.
61376+
61377+config GRKERNSEC_PROC_GID
61378+ int "GID for special group"
61379+ depends on GRKERNSEC_PROC_USERGROUP
61380+ default 1001
61381+
61382+config GRKERNSEC_PROC_ADD
61383+ bool "Additional restrictions"
61384+ default y if GRKERNSEC_CONFIG_AUTO
61385+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
61386+ help
61387+ If you say Y here, additional restrictions will be placed on
61388+ /proc that keep normal users from viewing device information and
61389+ slabinfo information that could be useful for exploits.
61390+
61391+config GRKERNSEC_LINK
61392+ bool "Linking restrictions"
61393+ default y if GRKERNSEC_CONFIG_AUTO
61394+ help
61395+ If you say Y here, /tmp race exploits will be prevented, since users
61396+ will no longer be able to follow symlinks owned by other users in
61397+ world-writable +t directories (e.g. /tmp), unless the owner of the
61398+ symlink is the owner of the directory. users will also not be
61399+ able to hardlink to files they do not own. If the sysctl option is
61400+ enabled, a sysctl option with name "linking_restrictions" is created.
61401+
61402+config GRKERNSEC_SYMLINKOWN
61403+ bool "Kernel-enforced SymlinksIfOwnerMatch"
61404+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61405+ help
61406+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
61407+ that prevents it from being used as a security feature. As Apache
61408+ verifies the symlink by performing a stat() against the target of
61409+ the symlink before it is followed, an attacker can setup a symlink
61410+ to point to a same-owned file, then replace the symlink with one
61411+ that targets another user's file just after Apache "validates" the
61412+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
61413+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
61414+ will be in place for the group you specify. If the sysctl option
61415+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
61416+ created.
61417+
61418+config GRKERNSEC_SYMLINKOWN_GID
61419+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
61420+ depends on GRKERNSEC_SYMLINKOWN
61421+ default 1006
61422+ help
61423+ Setting this GID determines what group kernel-enforced
61424+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
61425+ is enabled, a sysctl option with name "symlinkown_gid" is created.
61426+
61427+config GRKERNSEC_FIFO
61428+ bool "FIFO restrictions"
61429+ default y if GRKERNSEC_CONFIG_AUTO
61430+ help
61431+ If you say Y here, users will not be able to write to FIFOs they don't
61432+ own in world-writable +t directories (e.g. /tmp), unless the owner of
61433+ the FIFO is the same owner of the directory it's held in. If the sysctl
61434+ option is enabled, a sysctl option with name "fifo_restrictions" is
61435+ created.
61436+
61437+config GRKERNSEC_SYSFS_RESTRICT
61438+ bool "Sysfs/debugfs restriction"
61439+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61440+ depends on SYSFS
61441+ help
61442+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
61443+ any filesystem normally mounted under it (e.g. debugfs) will be
61444+ mostly accessible only by root. These filesystems generally provide access
61445+ to hardware and debug information that isn't appropriate for unprivileged
61446+ users of the system. Sysfs and debugfs have also become a large source
61447+ of new vulnerabilities, ranging from infoleaks to local compromise.
61448+ There has been very little oversight with an eye toward security involved
61449+ in adding new exporters of information to these filesystems, so their
61450+ use is discouraged.
61451+ For reasons of compatibility, a few directories have been whitelisted
61452+ for access by non-root users:
61453+ /sys/fs/selinux
61454+ /sys/fs/fuse
61455+ /sys/devices/system/cpu
61456+
61457+config GRKERNSEC_ROFS
61458+ bool "Runtime read-only mount protection"
61459+ depends on SYSCTL
61460+ help
61461+ If you say Y here, a sysctl option with name "romount_protect" will
61462+ be created. By setting this option to 1 at runtime, filesystems
61463+ will be protected in the following ways:
61464+ * No new writable mounts will be allowed
61465+ * Existing read-only mounts won't be able to be remounted read/write
61466+ * Write operations will be denied on all block devices
61467+ This option acts independently of grsec_lock: once it is set to 1,
61468+ it cannot be turned off. Therefore, please be mindful of the resulting
61469+ behavior if this option is enabled in an init script on a read-only
61470+ filesystem. This feature is mainly intended for secure embedded systems.
61471+
61472+config GRKERNSEC_DEVICE_SIDECHANNEL
61473+ bool "Eliminate stat/notify-based device sidechannels"
61474+ default y if GRKERNSEC_CONFIG_AUTO
61475+ help
61476+ If you say Y here, timing analyses on block or character
61477+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
61478+ will be thwarted for unprivileged users. If a process without
61479+ CAP_MKNOD stats such a device, the last access and last modify times
61480+ will match the device's create time. No access or modify events
61481+ will be triggered through inotify/dnotify/fanotify for such devices.
61482+ This feature will prevent attacks that may at a minimum
61483+ allow an attacker to determine the administrator's password length.
61484+
61485+config GRKERNSEC_CHROOT
61486+ bool "Chroot jail restrictions"
61487+ default y if GRKERNSEC_CONFIG_AUTO
61488+ help
61489+ If you say Y here, you will be able to choose several options that will
61490+ make breaking out of a chrooted jail much more difficult. If you
61491+ encounter no software incompatibilities with the following options, it
61492+ is recommended that you enable each one.
61493+
61494+config GRKERNSEC_CHROOT_MOUNT
61495+ bool "Deny mounts"
61496+ default y if GRKERNSEC_CONFIG_AUTO
61497+ depends on GRKERNSEC_CHROOT
61498+ help
61499+ If you say Y here, processes inside a chroot will not be able to
61500+ mount or remount filesystems. If the sysctl option is enabled, a
61501+ sysctl option with name "chroot_deny_mount" is created.
61502+
61503+config GRKERNSEC_CHROOT_DOUBLE
61504+ bool "Deny double-chroots"
61505+ default y if GRKERNSEC_CONFIG_AUTO
61506+ depends on GRKERNSEC_CHROOT
61507+ help
61508+ If you say Y here, processes inside a chroot will not be able to chroot
61509+ again outside the chroot. This is a widely used method of breaking
61510+ out of a chroot jail and should not be allowed. If the sysctl
61511+ option is enabled, a sysctl option with name
61512+ "chroot_deny_chroot" is created.
61513+
61514+config GRKERNSEC_CHROOT_PIVOT
61515+ bool "Deny pivot_root in chroot"
61516+ default y if GRKERNSEC_CONFIG_AUTO
61517+ depends on GRKERNSEC_CHROOT
61518+ help
61519+ If you say Y here, processes inside a chroot will not be able to use
61520+ a function called pivot_root() that was introduced in Linux 2.3.41. It
61521+ works similar to chroot in that it changes the root filesystem. This
61522+ function could be misused in a chrooted process to attempt to break out
61523+ of the chroot, and therefore should not be allowed. If the sysctl
61524+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
61525+ created.
61526+
61527+config GRKERNSEC_CHROOT_CHDIR
61528+ bool "Enforce chdir(\"/\") on all chroots"
61529+ default y if GRKERNSEC_CONFIG_AUTO
61530+ depends on GRKERNSEC_CHROOT
61531+ help
61532+ If you say Y here, the current working directory of all newly-chrooted
61533+ applications will be set to the the root directory of the chroot.
61534+ The man page on chroot(2) states:
61535+ Note that this call does not change the current working
61536+ directory, so that `.' can be outside the tree rooted at
61537+ `/'. In particular, the super-user can escape from a
61538+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
61539+
61540+ It is recommended that you say Y here, since it's not known to break
61541+ any software. If the sysctl option is enabled, a sysctl option with
61542+ name "chroot_enforce_chdir" is created.
61543+
61544+config GRKERNSEC_CHROOT_CHMOD
61545+ bool "Deny (f)chmod +s"
61546+ default y if GRKERNSEC_CONFIG_AUTO
61547+ depends on GRKERNSEC_CHROOT
61548+ help
61549+ If you say Y here, processes inside a chroot will not be able to chmod
61550+ or fchmod files to make them have suid or sgid bits. This protects
61551+ against another published method of breaking a chroot. If the sysctl
61552+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
61553+ created.
61554+
61555+config GRKERNSEC_CHROOT_FCHDIR
61556+ bool "Deny fchdir out of chroot"
61557+ default y if GRKERNSEC_CONFIG_AUTO
61558+ depends on GRKERNSEC_CHROOT
61559+ help
61560+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
61561+ to a file descriptor of the chrooting process that points to a directory
61562+ outside the filesystem will be stopped. If the sysctl option
61563+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
61564+
61565+config GRKERNSEC_CHROOT_MKNOD
61566+ bool "Deny mknod"
61567+ default y if GRKERNSEC_CONFIG_AUTO
61568+ depends on GRKERNSEC_CHROOT
61569+ help
61570+ If you say Y here, processes inside a chroot will not be allowed to
61571+ mknod. The problem with using mknod inside a chroot is that it
61572+ would allow an attacker to create a device entry that is the same
61573+ as one on the physical root of your system, which could range from
61574+ anything from the console device to a device for your harddrive (which
61575+ they could then use to wipe the drive or steal data). It is recommended
61576+ that you say Y here, unless you run into software incompatibilities.
61577+ If the sysctl option is enabled, a sysctl option with name
61578+ "chroot_deny_mknod" is created.
61579+
61580+config GRKERNSEC_CHROOT_SHMAT
61581+ bool "Deny shmat() out of chroot"
61582+ default y if GRKERNSEC_CONFIG_AUTO
61583+ depends on GRKERNSEC_CHROOT
61584+ help
61585+ If you say Y here, processes inside a chroot will not be able to attach
61586+ to shared memory segments that were created outside of the chroot jail.
61587+ It is recommended that you say Y here. If the sysctl option is enabled,
61588+ a sysctl option with name "chroot_deny_shmat" is created.
61589+
61590+config GRKERNSEC_CHROOT_UNIX
61591+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
61592+ default y if GRKERNSEC_CONFIG_AUTO
61593+ depends on GRKERNSEC_CHROOT
61594+ help
61595+ If you say Y here, processes inside a chroot will not be able to
61596+ connect to abstract (meaning not belonging to a filesystem) Unix
61597+ domain sockets that were bound outside of a chroot. It is recommended
61598+ that you say Y here. If the sysctl option is enabled, a sysctl option
61599+ with name "chroot_deny_unix" is created.
61600+
61601+config GRKERNSEC_CHROOT_FINDTASK
61602+ bool "Protect outside processes"
61603+ default y if GRKERNSEC_CONFIG_AUTO
61604+ depends on GRKERNSEC_CHROOT
61605+ help
61606+ If you say Y here, processes inside a chroot will not be able to
61607+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
61608+ getsid, or view any process outside of the chroot. If the sysctl
61609+ option is enabled, a sysctl option with name "chroot_findtask" is
61610+ created.
61611+
61612+config GRKERNSEC_CHROOT_NICE
61613+ bool "Restrict priority changes"
61614+ default y if GRKERNSEC_CONFIG_AUTO
61615+ depends on GRKERNSEC_CHROOT
61616+ help
61617+ If you say Y here, processes inside a chroot will not be able to raise
61618+ the priority of processes in the chroot, or alter the priority of
61619+ processes outside the chroot. This provides more security than simply
61620+ removing CAP_SYS_NICE from the process' capability set. If the
61621+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
61622+ is created.
61623+
61624+config GRKERNSEC_CHROOT_SYSCTL
61625+ bool "Deny sysctl writes"
61626+ default y if GRKERNSEC_CONFIG_AUTO
61627+ depends on GRKERNSEC_CHROOT
61628+ help
61629+ If you say Y here, an attacker in a chroot will not be able to
61630+ write to sysctl entries, either by sysctl(2) or through a /proc
61631+ interface. It is strongly recommended that you say Y here. If the
61632+ sysctl option is enabled, a sysctl option with name
61633+ "chroot_deny_sysctl" is created.
61634+
61635+config GRKERNSEC_CHROOT_CAPS
61636+ bool "Capability restrictions"
61637+ default y if GRKERNSEC_CONFIG_AUTO
61638+ depends on GRKERNSEC_CHROOT
61639+ help
61640+ If you say Y here, the capabilities on all processes within a
61641+ chroot jail will be lowered to stop module insertion, raw i/o,
61642+ system and net admin tasks, rebooting the system, modifying immutable
61643+ files, modifying IPC owned by another, and changing the system time.
61644+ This is left an option because it can break some apps. Disable this
61645+ if your chrooted apps are having problems performing those kinds of
61646+ tasks. If the sysctl option is enabled, a sysctl option with
61647+ name "chroot_caps" is created.
61648+
61649+config GRKERNSEC_CHROOT_INITRD
61650+ bool "Exempt initrd tasks from restrictions"
61651+ default y if GRKERNSEC_CONFIG_AUTO
61652+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
61653+ help
61654+ If you say Y here, tasks started prior to init will be exempted from
61655+ grsecurity's chroot restrictions. This option is mainly meant to
61656+ resolve Plymouth's performing privileged operations unnecessarily
61657+ in a chroot.
61658+
61659+endmenu
61660+menu "Kernel Auditing"
61661+depends on GRKERNSEC
61662+
61663+config GRKERNSEC_AUDIT_GROUP
61664+ bool "Single group for auditing"
61665+ help
61666+ If you say Y here, the exec and chdir logging features will only operate
61667+ on a group you specify. This option is recommended if you only want to
61668+ watch certain users instead of having a large amount of logs from the
61669+ entire system. If the sysctl option is enabled, a sysctl option with
61670+ name "audit_group" is created.
61671+
61672+config GRKERNSEC_AUDIT_GID
61673+ int "GID for auditing"
61674+ depends on GRKERNSEC_AUDIT_GROUP
61675+ default 1007
61676+
61677+config GRKERNSEC_EXECLOG
61678+ bool "Exec logging"
61679+ help
61680+ If you say Y here, all execve() calls will be logged (since the
61681+ other exec*() calls are frontends to execve(), all execution
61682+ will be logged). Useful for shell-servers that like to keep track
61683+ of their users. If the sysctl option is enabled, a sysctl option with
61684+ name "exec_logging" is created.
61685+ WARNING: This option when enabled will produce a LOT of logs, especially
61686+ on an active system.
61687+
61688+config GRKERNSEC_RESLOG
61689+ bool "Resource logging"
61690+ default y if GRKERNSEC_CONFIG_AUTO
61691+ help
61692+ If you say Y here, all attempts to overstep resource limits will
61693+ be logged with the resource name, the requested size, and the current
61694+ limit. It is highly recommended that you say Y here. If the sysctl
61695+ option is enabled, a sysctl option with name "resource_logging" is
61696+ created. If the RBAC system is enabled, the sysctl value is ignored.
61697+
61698+config GRKERNSEC_CHROOT_EXECLOG
61699+ bool "Log execs within chroot"
61700+ help
61701+ If you say Y here, all executions inside a chroot jail will be logged
61702+ to syslog. This can cause a large amount of logs if certain
61703+ applications (eg. djb's daemontools) are installed on the system, and
61704+ is therefore left as an option. If the sysctl option is enabled, a
61705+ sysctl option with name "chroot_execlog" is created.
61706+
61707+config GRKERNSEC_AUDIT_PTRACE
61708+ bool "Ptrace logging"
61709+ help
61710+ If you say Y here, all attempts to attach to a process via ptrace
61711+ will be logged. If the sysctl option is enabled, a sysctl option
61712+ with name "audit_ptrace" is created.
61713+
61714+config GRKERNSEC_AUDIT_CHDIR
61715+ bool "Chdir logging"
61716+ help
61717+ If you say Y here, all chdir() calls will be logged. If the sysctl
61718+ option is enabled, a sysctl option with name "audit_chdir" is created.
61719+
61720+config GRKERNSEC_AUDIT_MOUNT
61721+ bool "(Un)Mount logging"
61722+ help
61723+ If you say Y here, all mounts and unmounts will be logged. If the
61724+ sysctl option is enabled, a sysctl option with name "audit_mount" is
61725+ created.
61726+
61727+config GRKERNSEC_SIGNAL
61728+ bool "Signal logging"
61729+ default y if GRKERNSEC_CONFIG_AUTO
61730+ help
61731+ If you say Y here, certain important signals will be logged, such as
61732+ SIGSEGV, which will as a result inform you of when a error in a program
61733+ occurred, which in some cases could mean a possible exploit attempt.
61734+ If the sysctl option is enabled, a sysctl option with name
61735+ "signal_logging" is created.
61736+
61737+config GRKERNSEC_FORKFAIL
61738+ bool "Fork failure logging"
61739+ help
61740+ If you say Y here, all failed fork() attempts will be logged.
61741+ This could suggest a fork bomb, or someone attempting to overstep
61742+ their process limit. If the sysctl option is enabled, a sysctl option
61743+ with name "forkfail_logging" is created.
61744+
61745+config GRKERNSEC_TIME
61746+ bool "Time change logging"
61747+ default y if GRKERNSEC_CONFIG_AUTO
61748+ help
61749+ If you say Y here, any changes of the system clock will be logged.
61750+ If the sysctl option is enabled, a sysctl option with name
61751+ "timechange_logging" is created.
61752+
61753+config GRKERNSEC_PROC_IPADDR
61754+ bool "/proc/<pid>/ipaddr support"
61755+ default y if GRKERNSEC_CONFIG_AUTO
61756+ help
61757+ If you say Y here, a new entry will be added to each /proc/<pid>
61758+ directory that contains the IP address of the person using the task.
61759+ The IP is carried across local TCP and AF_UNIX stream sockets.
61760+ This information can be useful for IDS/IPSes to perform remote response
61761+ to a local attack. The entry is readable by only the owner of the
61762+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
61763+ the RBAC system), and thus does not create privacy concerns.
61764+
61765+config GRKERNSEC_RWXMAP_LOG
61766+ bool 'Denied RWX mmap/mprotect logging'
61767+ default y if GRKERNSEC_CONFIG_AUTO
61768+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
61769+ help
61770+ If you say Y here, calls to mmap() and mprotect() with explicit
61771+ usage of PROT_WRITE and PROT_EXEC together will be logged when
61772+ denied by the PAX_MPROTECT feature. This feature will also
61773+ log other problematic scenarios that can occur when PAX_MPROTECT
61774+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
61775+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
61776+ is created.
61777+
61778+endmenu
61779+
61780+menu "Executable Protections"
61781+depends on GRKERNSEC
61782+
61783+config GRKERNSEC_DMESG
61784+ bool "Dmesg(8) restriction"
61785+ default y if GRKERNSEC_CONFIG_AUTO
61786+ help
61787+ If you say Y here, non-root users will not be able to use dmesg(8)
61788+ to view the contents of the kernel's circular log buffer.
61789+ The kernel's log buffer often contains kernel addresses and other
61790+ identifying information useful to an attacker in fingerprinting a
61791+ system for a targeted exploit.
61792+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
61793+ created.
61794+
61795+config GRKERNSEC_HARDEN_PTRACE
61796+ bool "Deter ptrace-based process snooping"
61797+ default y if GRKERNSEC_CONFIG_AUTO
61798+ help
61799+ If you say Y here, TTY sniffers and other malicious monitoring
61800+ programs implemented through ptrace will be defeated. If you
61801+ have been using the RBAC system, this option has already been
61802+ enabled for several years for all users, with the ability to make
61803+ fine-grained exceptions.
61804+
61805+ This option only affects the ability of non-root users to ptrace
61806+ processes that are not a descendent of the ptracing process.
61807+ This means that strace ./binary and gdb ./binary will still work,
61808+ but attaching to arbitrary processes will not. If the sysctl
61809+ option is enabled, a sysctl option with name "harden_ptrace" is
61810+ created.
61811+
61812+config GRKERNSEC_PTRACE_READEXEC
61813+ bool "Require read access to ptrace sensitive binaries"
61814+ default y if GRKERNSEC_CONFIG_AUTO
61815+ help
61816+ If you say Y here, unprivileged users will not be able to ptrace unreadable
61817+ binaries. This option is useful in environments that
61818+ remove the read bits (e.g. file mode 4711) from suid binaries to
61819+ prevent infoleaking of their contents. This option adds
61820+ consistency to the use of that file mode, as the binary could normally
61821+ be read out when run without privileges while ptracing.
61822+
61823+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
61824+ is created.
61825+
61826+config GRKERNSEC_SETXID
61827+ bool "Enforce consistent multithreaded privileges"
61828+ default y if GRKERNSEC_CONFIG_AUTO
61829+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
61830+ help
61831+ If you say Y here, a change from a root uid to a non-root uid
61832+ in a multithreaded application will cause the resulting uids,
61833+ gids, supplementary groups, and capabilities in that thread
61834+ to be propagated to the other threads of the process. In most
61835+ cases this is unnecessary, as glibc will emulate this behavior
61836+ on behalf of the application. Other libcs do not act in the
61837+ same way, allowing the other threads of the process to continue
61838+ running with root privileges. If the sysctl option is enabled,
61839+ a sysctl option with name "consistent_setxid" is created.
61840+
61841+config GRKERNSEC_TPE
61842+ bool "Trusted Path Execution (TPE)"
61843+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61844+ help
61845+ If you say Y here, you will be able to choose a gid to add to the
61846+ supplementary groups of users you want to mark as "untrusted."
61847+ These users will not be able to execute any files that are not in
61848+ root-owned directories writable only by root. If the sysctl option
61849+ is enabled, a sysctl option with name "tpe" is created.
61850+
61851+config GRKERNSEC_TPE_ALL
61852+ bool "Partially restrict all non-root users"
61853+ depends on GRKERNSEC_TPE
61854+ help
61855+ If you say Y here, all non-root users will be covered under
61856+ a weaker TPE restriction. This is separate from, and in addition to,
61857+ the main TPE options that you have selected elsewhere. Thus, if a
61858+ "trusted" GID is chosen, this restriction applies to even that GID.
61859+ Under this restriction, all non-root users will only be allowed to
61860+ execute files in directories they own that are not group or
61861+ world-writable, or in directories owned by root and writable only by
61862+ root. If the sysctl option is enabled, a sysctl option with name
61863+ "tpe_restrict_all" is created.
61864+
61865+config GRKERNSEC_TPE_INVERT
61866+ bool "Invert GID option"
61867+ depends on GRKERNSEC_TPE
61868+ help
61869+ If you say Y here, the group you specify in the TPE configuration will
61870+ decide what group TPE restrictions will be *disabled* for. This
61871+ option is useful if you want TPE restrictions to be applied to most
61872+ users on the system. If the sysctl option is enabled, a sysctl option
61873+ with name "tpe_invert" is created. Unlike other sysctl options, this
61874+ entry will default to on for backward-compatibility.
61875+
61876+config GRKERNSEC_TPE_GID
61877+ int
61878+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
61879+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
61880+
61881+config GRKERNSEC_TPE_UNTRUSTED_GID
61882+ int "GID for TPE-untrusted users"
61883+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
61884+ default 1005
61885+ help
61886+ Setting this GID determines what group TPE restrictions will be
61887+ *enabled* for. If the sysctl option is enabled, a sysctl option
61888+ with name "tpe_gid" is created.
61889+
61890+config GRKERNSEC_TPE_TRUSTED_GID
61891+ int "GID for TPE-trusted users"
61892+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
61893+ default 1005
61894+ help
61895+ Setting this GID determines what group TPE restrictions will be
61896+ *disabled* for. If the sysctl option is enabled, a sysctl option
61897+ with name "tpe_gid" is created.
61898+
61899+endmenu
61900+menu "Network Protections"
61901+depends on GRKERNSEC
61902+
61903+config GRKERNSEC_RANDNET
61904+ bool "Larger entropy pools"
61905+ default y if GRKERNSEC_CONFIG_AUTO
61906+ help
61907+ If you say Y here, the entropy pools used for many features of Linux
61908+ and grsecurity will be doubled in size. Since several grsecurity
61909+ features use additional randomness, it is recommended that you say Y
61910+ here. Saying Y here has a similar effect as modifying
61911+ /proc/sys/kernel/random/poolsize.
61912+
61913+config GRKERNSEC_BLACKHOLE
61914+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
61915+ default y if GRKERNSEC_CONFIG_AUTO
61916+ depends on NET
61917+ help
61918+ If you say Y here, neither TCP resets nor ICMP
61919+ destination-unreachable packets will be sent in response to packets
61920+ sent to ports for which no associated listening process exists.
61921+ This feature supports both IPV4 and IPV6 and exempts the
61922+ loopback interface from blackholing. Enabling this feature
61923+ makes a host more resilient to DoS attacks and reduces network
61924+ visibility against scanners.
61925+
61926+ The blackhole feature as-implemented is equivalent to the FreeBSD
61927+ blackhole feature, as it prevents RST responses to all packets, not
61928+ just SYNs. Under most application behavior this causes no
61929+ problems, but applications (like haproxy) may not close certain
61930+ connections in a way that cleanly terminates them on the remote
61931+ end, leaving the remote host in LAST_ACK state. Because of this
61932+ side-effect and to prevent intentional LAST_ACK DoSes, this
61933+ feature also adds automatic mitigation against such attacks.
61934+ The mitigation drastically reduces the amount of time a socket
61935+ can spend in LAST_ACK state. If you're using haproxy and not
61936+ all servers it connects to have this option enabled, consider
61937+ disabling this feature on the haproxy host.
61938+
61939+ If the sysctl option is enabled, two sysctl options with names
61940+ "ip_blackhole" and "lastack_retries" will be created.
61941+ While "ip_blackhole" takes the standard zero/non-zero on/off
61942+ toggle, "lastack_retries" uses the same kinds of values as
61943+ "tcp_retries1" and "tcp_retries2". The default value of 4
61944+ prevents a socket from lasting more than 45 seconds in LAST_ACK
61945+ state.
61946+
61947+config GRKERNSEC_NO_SIMULT_CONNECT
61948+ bool "Disable TCP Simultaneous Connect"
61949+ default y if GRKERNSEC_CONFIG_AUTO
61950+ depends on NET
61951+ help
61952+ If you say Y here, a feature by Willy Tarreau will be enabled that
61953+ removes a weakness in Linux's strict implementation of TCP that
61954+ allows two clients to connect to each other without either entering
61955+ a listening state. The weakness allows an attacker to easily prevent
61956+ a client from connecting to a known server provided the source port
61957+ for the connection is guessed correctly.
61958+
61959+ As the weakness could be used to prevent an antivirus or IPS from
61960+ fetching updates, or prevent an SSL gateway from fetching a CRL,
61961+ it should be eliminated by enabling this option. Though Linux is
61962+ one of few operating systems supporting simultaneous connect, it
61963+ has no legitimate use in practice and is rarely supported by firewalls.
61964+
61965+config GRKERNSEC_SOCKET
61966+ bool "Socket restrictions"
61967+ depends on NET
61968+ help
61969+ If you say Y here, you will be able to choose from several options.
61970+ If you assign a GID on your system and add it to the supplementary
61971+ groups of users you want to restrict socket access to, this patch
61972+ will perform up to three things, based on the option(s) you choose.
61973+
61974+config GRKERNSEC_SOCKET_ALL
61975+ bool "Deny any sockets to group"
61976+ depends on GRKERNSEC_SOCKET
61977+ help
61978+ If you say Y here, you will be able to choose a GID of whose users will
61979+ be unable to connect to other hosts from your machine or run server
61980+ applications from your machine. If the sysctl option is enabled, a
61981+ sysctl option with name "socket_all" is created.
61982+
61983+config GRKERNSEC_SOCKET_ALL_GID
61984+ int "GID to deny all sockets for"
61985+ depends on GRKERNSEC_SOCKET_ALL
61986+ default 1004
61987+ help
61988+ Here you can choose the GID to disable socket access for. Remember to
61989+ add the users you want socket access disabled for to the GID
61990+ specified here. If the sysctl option is enabled, a sysctl option
61991+ with name "socket_all_gid" is created.
61992+
61993+config GRKERNSEC_SOCKET_CLIENT
61994+ bool "Deny client sockets to group"
61995+ depends on GRKERNSEC_SOCKET
61996+ help
61997+ If you say Y here, you will be able to choose a GID of whose users will
61998+ be unable to connect to other hosts from your machine, but will be
61999+ able to run servers. If this option is enabled, all users in the group
62000+ you specify will have to use passive mode when initiating ftp transfers
62001+ from the shell on your machine. If the sysctl option is enabled, a
62002+ sysctl option with name "socket_client" is created.
62003+
62004+config GRKERNSEC_SOCKET_CLIENT_GID
62005+ int "GID to deny client sockets for"
62006+ depends on GRKERNSEC_SOCKET_CLIENT
62007+ default 1003
62008+ help
62009+ Here you can choose the GID to disable client socket access for.
62010+ Remember to add the users you want client socket access disabled for to
62011+ the GID specified here. If the sysctl option is enabled, a sysctl
62012+ option with name "socket_client_gid" is created.
62013+
62014+config GRKERNSEC_SOCKET_SERVER
62015+ bool "Deny server sockets to group"
62016+ depends on GRKERNSEC_SOCKET
62017+ help
62018+ If you say Y here, you will be able to choose a GID of whose users will
62019+ be unable to run server applications from your machine. If the sysctl
62020+ option is enabled, a sysctl option with name "socket_server" is created.
62021+
62022+config GRKERNSEC_SOCKET_SERVER_GID
62023+ int "GID to deny server sockets for"
62024+ depends on GRKERNSEC_SOCKET_SERVER
62025+ default 1002
62026+ help
62027+ Here you can choose the GID to disable server socket access for.
62028+ Remember to add the users you want server socket access disabled for to
62029+ the GID specified here. If the sysctl option is enabled, a sysctl
62030+ option with name "socket_server_gid" is created.
62031+
62032+endmenu
62033+
62034+menu "Physical Protections"
62035+depends on GRKERNSEC
62036+
62037+config GRKERNSEC_DENYUSB
62038+ bool "Deny new USB connections after toggle"
62039+ default y if GRKERNSEC_CONFIG_AUTO
62040+ depends on SYSCTL && USB_SUPPORT
62041+ help
62042+ If you say Y here, a new sysctl option with name "deny_new_usb"
62043+ will be created. Setting its value to 1 will prevent any new
62044+ USB devices from being recognized by the OS. Any attempted USB
62045+ device insertion will be logged. This option is intended to be
62046+ used against custom USB devices designed to exploit vulnerabilities
62047+ in various USB device drivers.
62048+
62049+ For greatest effectiveness, this sysctl should be set after any
62050+ relevant init scripts. This option is safe to enable in distros
62051+ as each user can choose whether or not to toggle the sysctl.
62052+
62053+config GRKERNSEC_DENYUSB_FORCE
62054+ bool "Reject all USB devices not connected at boot"
62055+ select USB
62056+ depends on GRKERNSEC_DENYUSB
62057+ help
62058+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
62059+ that doesn't involve a sysctl entry. This option should only be
62060+ enabled if you're sure you want to deny all new USB connections
62061+ at runtime and don't want to modify init scripts. This should not
62062+ be enabled by distros. It forces the core USB code to be built
62063+ into the kernel image so that all devices connected at boot time
62064+ can be recognized and new USB device connections can be prevented
62065+ prior to init running.
62066+
62067+endmenu
62068+
62069+menu "Sysctl Support"
62070+depends on GRKERNSEC && SYSCTL
62071+
62072+config GRKERNSEC_SYSCTL
62073+ bool "Sysctl support"
62074+ default y if GRKERNSEC_CONFIG_AUTO
62075+ help
62076+ If you say Y here, you will be able to change the options that
62077+ grsecurity runs with at bootup, without having to recompile your
62078+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
62079+ to enable (1) or disable (0) various features. All the sysctl entries
62080+ are mutable until the "grsec_lock" entry is set to a non-zero value.
62081+ All features enabled in the kernel configuration are disabled at boot
62082+ if you do not say Y to the "Turn on features by default" option.
62083+ All options should be set at startup, and the grsec_lock entry should
62084+ be set to a non-zero value after all the options are set.
62085+ *THIS IS EXTREMELY IMPORTANT*
62086+
62087+config GRKERNSEC_SYSCTL_DISTRO
62088+ bool "Extra sysctl support for distro makers (READ HELP)"
62089+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
62090+ help
62091+ If you say Y here, additional sysctl options will be created
62092+ for features that affect processes running as root. Therefore,
62093+ it is critical when using this option that the grsec_lock entry be
62094+ enabled after boot. Only distros with prebuilt kernel packages
62095+ with this option enabled that can ensure grsec_lock is enabled
62096+ after boot should use this option.
62097+ *Failure to set grsec_lock after boot makes all grsec features
62098+ this option covers useless*
62099+
62100+ Currently this option creates the following sysctl entries:
62101+ "Disable Privileged I/O": "disable_priv_io"
62102+
62103+config GRKERNSEC_SYSCTL_ON
62104+ bool "Turn on features by default"
62105+ default y if GRKERNSEC_CONFIG_AUTO
62106+ depends on GRKERNSEC_SYSCTL
62107+ help
62108+ If you say Y here, instead of having all features enabled in the
62109+ kernel configuration disabled at boot time, the features will be
62110+ enabled at boot time. It is recommended you say Y here unless
62111+ there is some reason you would want all sysctl-tunable features to
62112+ be disabled by default. As mentioned elsewhere, it is important
62113+ to enable the grsec_lock entry once you have finished modifying
62114+ the sysctl entries.
62115+
62116+endmenu
62117+menu "Logging Options"
62118+depends on GRKERNSEC
62119+
62120+config GRKERNSEC_FLOODTIME
62121+ int "Seconds in between log messages (minimum)"
62122+ default 10
62123+ help
62124+ This option allows you to enforce the number of seconds between
62125+ grsecurity log messages. The default should be suitable for most
62126+ people, however, if you choose to change it, choose a value small enough
62127+ to allow informative logs to be produced, but large enough to
62128+ prevent flooding.
62129+
62130+config GRKERNSEC_FLOODBURST
62131+ int "Number of messages in a burst (maximum)"
62132+ default 6
62133+ help
62134+ This option allows you to choose the maximum number of messages allowed
62135+ within the flood time interval you chose in a separate option. The
62136+ default should be suitable for most people, however if you find that
62137+ many of your logs are being interpreted as flooding, you may want to
62138+ raise this value.
62139+
62140+endmenu
62141diff --git a/grsecurity/Makefile b/grsecurity/Makefile
62142new file mode 100644
62143index 0000000..b0b77d5
62144--- /dev/null
62145+++ b/grsecurity/Makefile
62146@@ -0,0 +1,43 @@
62147+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
62148+# during 2001-2009 it has been completely redesigned by Brad Spengler
62149+# into an RBAC system
62150+#
62151+# All code in this directory and various hooks inserted throughout the kernel
62152+# are copyright Brad Spengler - Open Source Security, Inc., and released
62153+# under the GPL v2 or higher
62154+
62155+KBUILD_CFLAGS += -Werror
62156+
62157+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
62158+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
62159+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
62160+ grsec_usb.o
62161+
62162+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
62163+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
62164+ gracl_learn.o grsec_log.o
62165+ifdef CONFIG_COMPAT
62166+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
62167+endif
62168+
62169+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
62170+
62171+ifdef CONFIG_NET
62172+obj-y += grsec_sock.o
62173+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
62174+endif
62175+
62176+ifndef CONFIG_GRKERNSEC
62177+obj-y += grsec_disabled.o
62178+endif
62179+
62180+ifdef CONFIG_GRKERNSEC_HIDESYM
62181+extra-y := grsec_hidesym.o
62182+$(obj)/grsec_hidesym.o:
62183+ @-chmod -f 500 /boot
62184+ @-chmod -f 500 /lib/modules
62185+ @-chmod -f 500 /lib64/modules
62186+ @-chmod -f 500 /lib32/modules
62187+ @-chmod -f 700 .
62188+ @echo ' grsec: protected kernel image paths'
62189+endif
62190diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
62191new file mode 100644
62192index 0000000..c0793fd
62193--- /dev/null
62194+++ b/grsecurity/gracl.c
62195@@ -0,0 +1,4178 @@
62196+#include <linux/kernel.h>
62197+#include <linux/module.h>
62198+#include <linux/sched.h>
62199+#include <linux/mm.h>
62200+#include <linux/file.h>
62201+#include <linux/fs.h>
62202+#include <linux/namei.h>
62203+#include <linux/mount.h>
62204+#include <linux/tty.h>
62205+#include <linux/proc_fs.h>
62206+#include <linux/lglock.h>
62207+#include <linux/slab.h>
62208+#include <linux/vmalloc.h>
62209+#include <linux/types.h>
62210+#include <linux/sysctl.h>
62211+#include <linux/netdevice.h>
62212+#include <linux/ptrace.h>
62213+#include <linux/gracl.h>
62214+#include <linux/gralloc.h>
62215+#include <linux/security.h>
62216+#include <linux/grinternal.h>
62217+#include <linux/pid_namespace.h>
62218+#include <linux/stop_machine.h>
62219+#include <linux/fdtable.h>
62220+#include <linux/percpu.h>
62221+#include <linux/lglock.h>
62222+#include <linux/hugetlb.h>
62223+#include <linux/posix-timers.h>
62224+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62225+#include <linux/magic.h>
62226+#include <linux/pagemap.h>
62227+#include "../fs/btrfs/async-thread.h"
62228+#include "../fs/btrfs/ctree.h"
62229+#include "../fs/btrfs/btrfs_inode.h"
62230+#endif
62231+#include "../fs/mount.h"
62232+
62233+#include <asm/uaccess.h>
62234+#include <asm/errno.h>
62235+#include <asm/mman.h>
62236+
62237+extern struct lglock vfsmount_lock;
62238+
62239+static struct acl_role_db acl_role_set;
62240+static struct name_db name_set;
62241+static struct inodev_db inodev_set;
62242+
62243+/* for keeping track of userspace pointers used for subjects, so we
62244+ can share references in the kernel as well
62245+*/
62246+
62247+static struct path real_root;
62248+
62249+static struct acl_subj_map_db subj_map_set;
62250+
62251+static struct acl_role_label *default_role;
62252+
62253+static struct acl_role_label *role_list;
62254+
62255+static u16 acl_sp_role_value;
62256+
62257+extern char *gr_shared_page[4];
62258+static DEFINE_MUTEX(gr_dev_mutex);
62259+DEFINE_RWLOCK(gr_inode_lock);
62260+
62261+struct gr_arg *gr_usermode;
62262+
62263+static unsigned int gr_status __read_only = GR_STATUS_INIT;
62264+
62265+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
62266+extern void gr_clear_learn_entries(void);
62267+
62268+unsigned char *gr_system_salt;
62269+unsigned char *gr_system_sum;
62270+
62271+static struct sprole_pw **acl_special_roles = NULL;
62272+static __u16 num_sprole_pws = 0;
62273+
62274+static struct acl_role_label *kernel_role = NULL;
62275+
62276+static unsigned int gr_auth_attempts = 0;
62277+static unsigned long gr_auth_expires = 0UL;
62278+
62279+#ifdef CONFIG_NET
62280+extern struct vfsmount *sock_mnt;
62281+#endif
62282+
62283+extern struct vfsmount *pipe_mnt;
62284+extern struct vfsmount *shm_mnt;
62285+
62286+#ifdef CONFIG_HUGETLBFS
62287+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
62288+#endif
62289+
62290+static struct acl_object_label *fakefs_obj_rw;
62291+static struct acl_object_label *fakefs_obj_rwx;
62292+
62293+extern int gr_init_uidset(void);
62294+extern void gr_free_uidset(void);
62295+extern void gr_remove_uid(uid_t uid);
62296+extern int gr_find_uid(uid_t uid);
62297+
62298+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
62299+{
62300+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
62301+ return -EFAULT;
62302+
62303+ return 0;
62304+}
62305+
62306+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
62307+{
62308+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
62309+ return -EFAULT;
62310+
62311+ return 0;
62312+}
62313+
62314+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
62315+{
62316+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
62317+ return -EFAULT;
62318+
62319+ return 0;
62320+}
62321+
62322+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
62323+{
62324+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
62325+ return -EFAULT;
62326+
62327+ return 0;
62328+}
62329+
62330+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
62331+{
62332+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
62333+ return -EFAULT;
62334+
62335+ return 0;
62336+}
62337+
62338+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
62339+{
62340+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
62341+ return -EFAULT;
62342+
62343+ return 0;
62344+}
62345+
62346+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
62347+{
62348+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
62349+ return -EFAULT;
62350+
62351+ return 0;
62352+}
62353+
62354+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
62355+{
62356+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
62357+ return -EFAULT;
62358+
62359+ return 0;
62360+}
62361+
62362+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
62363+{
62364+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
62365+ return -EFAULT;
62366+
62367+ return 0;
62368+}
62369+
62370+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
62371+{
62372+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
62373+ return -EFAULT;
62374+
62375+ if ((uwrap->version != GRSECURITY_VERSION) || (uwrap->size != sizeof(struct gr_arg)))
62376+ return -EINVAL;
62377+
62378+ return 0;
62379+}
62380+
62381+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
62382+{
62383+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
62384+ return -EFAULT;
62385+
62386+ return 0;
62387+}
62388+
62389+static size_t get_gr_arg_wrapper_size_normal(void)
62390+{
62391+ return sizeof(struct gr_arg_wrapper);
62392+}
62393+
62394+#ifdef CONFIG_COMPAT
62395+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
62396+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
62397+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
62398+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
62399+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
62400+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
62401+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
62402+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
62403+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
62404+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
62405+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
62406+extern size_t get_gr_arg_wrapper_size_compat(void);
62407+
62408+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
62409+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
62410+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
62411+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
62412+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
62413+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
62414+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
62415+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
62416+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
62417+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
62418+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
62419+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
62420+
62421+#else
62422+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
62423+#define copy_gr_arg copy_gr_arg_normal
62424+#define copy_gr_hash_struct copy_gr_hash_struct_normal
62425+#define copy_acl_object_label copy_acl_object_label_normal
62426+#define copy_acl_subject_label copy_acl_subject_label_normal
62427+#define copy_acl_role_label copy_acl_role_label_normal
62428+#define copy_acl_ip_label copy_acl_ip_label_normal
62429+#define copy_pointer_from_array copy_pointer_from_array_normal
62430+#define copy_sprole_pw copy_sprole_pw_normal
62431+#define copy_role_transition copy_role_transition_normal
62432+#define copy_role_allowed_ip copy_role_allowed_ip_normal
62433+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
62434+#endif
62435+
62436+__inline__ int
62437+gr_acl_is_enabled(void)
62438+{
62439+ return (gr_status & GR_READY);
62440+}
62441+
62442+static inline dev_t __get_dev(const struct dentry *dentry)
62443+{
62444+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62445+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
62446+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
62447+ else
62448+#endif
62449+ return dentry->d_sb->s_dev;
62450+}
62451+
62452+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
62453+{
62454+ return __get_dev(dentry);
62455+}
62456+
62457+static char gr_task_roletype_to_char(struct task_struct *task)
62458+{
62459+ switch (task->role->roletype &
62460+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
62461+ GR_ROLE_SPECIAL)) {
62462+ case GR_ROLE_DEFAULT:
62463+ return 'D';
62464+ case GR_ROLE_USER:
62465+ return 'U';
62466+ case GR_ROLE_GROUP:
62467+ return 'G';
62468+ case GR_ROLE_SPECIAL:
62469+ return 'S';
62470+ }
62471+
62472+ return 'X';
62473+}
62474+
62475+char gr_roletype_to_char(void)
62476+{
62477+ return gr_task_roletype_to_char(current);
62478+}
62479+
62480+__inline__ int
62481+gr_acl_tpe_check(void)
62482+{
62483+ if (unlikely(!(gr_status & GR_READY)))
62484+ return 0;
62485+ if (current->role->roletype & GR_ROLE_TPE)
62486+ return 1;
62487+ else
62488+ return 0;
62489+}
62490+
62491+int
62492+gr_handle_rawio(const struct inode *inode)
62493+{
62494+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62495+ if (inode && S_ISBLK(inode->i_mode) &&
62496+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
62497+ !capable(CAP_SYS_RAWIO))
62498+ return 1;
62499+#endif
62500+ return 0;
62501+}
62502+
62503+static int
62504+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
62505+{
62506+ if (likely(lena != lenb))
62507+ return 0;
62508+
62509+ return !memcmp(a, b, lena);
62510+}
62511+
62512+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
62513+{
62514+ *buflen -= namelen;
62515+ if (*buflen < 0)
62516+ return -ENAMETOOLONG;
62517+ *buffer -= namelen;
62518+ memcpy(*buffer, str, namelen);
62519+ return 0;
62520+}
62521+
62522+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
62523+{
62524+ return prepend(buffer, buflen, name->name, name->len);
62525+}
62526+
62527+static int prepend_path(const struct path *path, struct path *root,
62528+ char **buffer, int *buflen)
62529+{
62530+ struct dentry *dentry = path->dentry;
62531+ struct vfsmount *vfsmnt = path->mnt;
62532+ struct mount *mnt = real_mount(vfsmnt);
62533+ bool slash = false;
62534+ int error = 0;
62535+
62536+ while (dentry != root->dentry || vfsmnt != root->mnt) {
62537+ struct dentry * parent;
62538+
62539+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
62540+ /* Global root? */
62541+ if (!mnt_has_parent(mnt)) {
62542+ goto out;
62543+ }
62544+ dentry = mnt->mnt_mountpoint;
62545+ mnt = mnt->mnt_parent;
62546+ vfsmnt = &mnt->mnt;
62547+ continue;
62548+ }
62549+ parent = dentry->d_parent;
62550+ prefetch(parent);
62551+ spin_lock(&dentry->d_lock);
62552+ error = prepend_name(buffer, buflen, &dentry->d_name);
62553+ spin_unlock(&dentry->d_lock);
62554+ if (!error)
62555+ error = prepend(buffer, buflen, "/", 1);
62556+ if (error)
62557+ break;
62558+
62559+ slash = true;
62560+ dentry = parent;
62561+ }
62562+
62563+out:
62564+ if (!error && !slash)
62565+ error = prepend(buffer, buflen, "/", 1);
62566+
62567+ return error;
62568+}
62569+
62570+/* this must be called with vfsmount_lock and rename_lock held */
62571+
62572+static char *__our_d_path(const struct path *path, struct path *root,
62573+ char *buf, int buflen)
62574+{
62575+ char *res = buf + buflen;
62576+ int error;
62577+
62578+ prepend(&res, &buflen, "\0", 1);
62579+ error = prepend_path(path, root, &res, &buflen);
62580+ if (error)
62581+ return ERR_PTR(error);
62582+
62583+ return res;
62584+}
62585+
62586+static char *
62587+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
62588+{
62589+ char *retval;
62590+
62591+ retval = __our_d_path(path, root, buf, buflen);
62592+ if (unlikely(IS_ERR(retval)))
62593+ retval = strcpy(buf, "<path too long>");
62594+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
62595+ retval[1] = '\0';
62596+
62597+ return retval;
62598+}
62599+
62600+static char *
62601+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62602+ char *buf, int buflen)
62603+{
62604+ struct path path;
62605+ char *res;
62606+
62607+ path.dentry = (struct dentry *)dentry;
62608+ path.mnt = (struct vfsmount *)vfsmnt;
62609+
62610+ /* we can use real_root.dentry, real_root.mnt, because this is only called
62611+ by the RBAC system */
62612+ res = gen_full_path(&path, &real_root, buf, buflen);
62613+
62614+ return res;
62615+}
62616+
62617+static char *
62618+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62619+ char *buf, int buflen)
62620+{
62621+ char *res;
62622+ struct path path;
62623+ struct path root;
62624+ struct task_struct *reaper = init_pid_ns.child_reaper;
62625+
62626+ path.dentry = (struct dentry *)dentry;
62627+ path.mnt = (struct vfsmount *)vfsmnt;
62628+
62629+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
62630+ get_fs_root(reaper->fs, &root);
62631+
62632+ br_read_lock(&vfsmount_lock);
62633+ write_seqlock(&rename_lock);
62634+ res = gen_full_path(&path, &root, buf, buflen);
62635+ write_sequnlock(&rename_lock);
62636+ br_read_unlock(&vfsmount_lock);
62637+
62638+ path_put(&root);
62639+ return res;
62640+}
62641+
62642+static char *
62643+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62644+{
62645+ char *ret;
62646+ br_read_lock(&vfsmount_lock);
62647+ write_seqlock(&rename_lock);
62648+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62649+ PAGE_SIZE);
62650+ write_sequnlock(&rename_lock);
62651+ br_read_unlock(&vfsmount_lock);
62652+ return ret;
62653+}
62654+
62655+static char *
62656+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62657+{
62658+ char *ret;
62659+ char *buf;
62660+ int buflen;
62661+
62662+ br_read_lock(&vfsmount_lock);
62663+ write_seqlock(&rename_lock);
62664+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
62665+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
62666+ buflen = (int)(ret - buf);
62667+ if (buflen >= 5)
62668+ prepend(&ret, &buflen, "/proc", 5);
62669+ else
62670+ ret = strcpy(buf, "<path too long>");
62671+ write_sequnlock(&rename_lock);
62672+ br_read_unlock(&vfsmount_lock);
62673+ return ret;
62674+}
62675+
62676+char *
62677+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
62678+{
62679+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62680+ PAGE_SIZE);
62681+}
62682+
62683+char *
62684+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
62685+{
62686+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62687+ PAGE_SIZE);
62688+}
62689+
62690+char *
62691+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
62692+{
62693+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
62694+ PAGE_SIZE);
62695+}
62696+
62697+char *
62698+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
62699+{
62700+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
62701+ PAGE_SIZE);
62702+}
62703+
62704+char *
62705+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
62706+{
62707+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
62708+ PAGE_SIZE);
62709+}
62710+
62711+__inline__ __u32
62712+to_gr_audit(const __u32 reqmode)
62713+{
62714+ /* masks off auditable permission flags, then shifts them to create
62715+ auditing flags, and adds the special case of append auditing if
62716+ we're requesting write */
62717+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
62718+}
62719+
62720+struct acl_subject_label *
62721+lookup_subject_map(const struct acl_subject_label *userp)
62722+{
62723+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
62724+ struct subject_map *match;
62725+
62726+ match = subj_map_set.s_hash[index];
62727+
62728+ while (match && match->user != userp)
62729+ match = match->next;
62730+
62731+ if (match != NULL)
62732+ return match->kernel;
62733+ else
62734+ return NULL;
62735+}
62736+
62737+static void
62738+insert_subj_map_entry(struct subject_map *subjmap)
62739+{
62740+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
62741+ struct subject_map **curr;
62742+
62743+ subjmap->prev = NULL;
62744+
62745+ curr = &subj_map_set.s_hash[index];
62746+ if (*curr != NULL)
62747+ (*curr)->prev = subjmap;
62748+
62749+ subjmap->next = *curr;
62750+ *curr = subjmap;
62751+
62752+ return;
62753+}
62754+
62755+static struct acl_role_label *
62756+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
62757+ const gid_t gid)
62758+{
62759+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
62760+ struct acl_role_label *match;
62761+ struct role_allowed_ip *ipp;
62762+ unsigned int x;
62763+ u32 curr_ip = task->signal->curr_ip;
62764+
62765+ task->signal->saved_ip = curr_ip;
62766+
62767+ match = acl_role_set.r_hash[index];
62768+
62769+ while (match) {
62770+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
62771+ for (x = 0; x < match->domain_child_num; x++) {
62772+ if (match->domain_children[x] == uid)
62773+ goto found;
62774+ }
62775+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
62776+ break;
62777+ match = match->next;
62778+ }
62779+found:
62780+ if (match == NULL) {
62781+ try_group:
62782+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
62783+ match = acl_role_set.r_hash[index];
62784+
62785+ while (match) {
62786+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
62787+ for (x = 0; x < match->domain_child_num; x++) {
62788+ if (match->domain_children[x] == gid)
62789+ goto found2;
62790+ }
62791+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
62792+ break;
62793+ match = match->next;
62794+ }
62795+found2:
62796+ if (match == NULL)
62797+ match = default_role;
62798+ if (match->allowed_ips == NULL)
62799+ return match;
62800+ else {
62801+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62802+ if (likely
62803+ ((ntohl(curr_ip) & ipp->netmask) ==
62804+ (ntohl(ipp->addr) & ipp->netmask)))
62805+ return match;
62806+ }
62807+ match = default_role;
62808+ }
62809+ } else if (match->allowed_ips == NULL) {
62810+ return match;
62811+ } else {
62812+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62813+ if (likely
62814+ ((ntohl(curr_ip) & ipp->netmask) ==
62815+ (ntohl(ipp->addr) & ipp->netmask)))
62816+ return match;
62817+ }
62818+ goto try_group;
62819+ }
62820+
62821+ return match;
62822+}
62823+
62824+struct acl_subject_label *
62825+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
62826+ const struct acl_role_label *role)
62827+{
62828+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62829+ struct acl_subject_label *match;
62830+
62831+ match = role->subj_hash[index];
62832+
62833+ while (match && (match->inode != ino || match->device != dev ||
62834+ (match->mode & GR_DELETED))) {
62835+ match = match->next;
62836+ }
62837+
62838+ if (match && !(match->mode & GR_DELETED))
62839+ return match;
62840+ else
62841+ return NULL;
62842+}
62843+
62844+struct acl_subject_label *
62845+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
62846+ const struct acl_role_label *role)
62847+{
62848+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62849+ struct acl_subject_label *match;
62850+
62851+ match = role->subj_hash[index];
62852+
62853+ while (match && (match->inode != ino || match->device != dev ||
62854+ !(match->mode & GR_DELETED))) {
62855+ match = match->next;
62856+ }
62857+
62858+ if (match && (match->mode & GR_DELETED))
62859+ return match;
62860+ else
62861+ return NULL;
62862+}
62863+
62864+static struct acl_object_label *
62865+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
62866+ const struct acl_subject_label *subj)
62867+{
62868+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
62869+ struct acl_object_label *match;
62870+
62871+ match = subj->obj_hash[index];
62872+
62873+ while (match && (match->inode != ino || match->device != dev ||
62874+ (match->mode & GR_DELETED))) {
62875+ match = match->next;
62876+ }
62877+
62878+ if (match && !(match->mode & GR_DELETED))
62879+ return match;
62880+ else
62881+ return NULL;
62882+}
62883+
62884+static struct acl_object_label *
62885+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
62886+ const struct acl_subject_label *subj)
62887+{
62888+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
62889+ struct acl_object_label *match;
62890+
62891+ match = subj->obj_hash[index];
62892+
62893+ while (match && (match->inode != ino || match->device != dev ||
62894+ !(match->mode & GR_DELETED))) {
62895+ match = match->next;
62896+ }
62897+
62898+ if (match && (match->mode & GR_DELETED))
62899+ return match;
62900+
62901+ match = subj->obj_hash[index];
62902+
62903+ while (match && (match->inode != ino || match->device != dev ||
62904+ (match->mode & GR_DELETED))) {
62905+ match = match->next;
62906+ }
62907+
62908+ if (match && !(match->mode & GR_DELETED))
62909+ return match;
62910+ else
62911+ return NULL;
62912+}
62913+
62914+static struct name_entry *
62915+lookup_name_entry(const char *name)
62916+{
62917+ unsigned int len = strlen(name);
62918+ unsigned int key = full_name_hash(name, len);
62919+ unsigned int index = key % name_set.n_size;
62920+ struct name_entry *match;
62921+
62922+ match = name_set.n_hash[index];
62923+
62924+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
62925+ match = match->next;
62926+
62927+ return match;
62928+}
62929+
62930+static struct name_entry *
62931+lookup_name_entry_create(const char *name)
62932+{
62933+ unsigned int len = strlen(name);
62934+ unsigned int key = full_name_hash(name, len);
62935+ unsigned int index = key % name_set.n_size;
62936+ struct name_entry *match;
62937+
62938+ match = name_set.n_hash[index];
62939+
62940+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
62941+ !match->deleted))
62942+ match = match->next;
62943+
62944+ if (match && match->deleted)
62945+ return match;
62946+
62947+ match = name_set.n_hash[index];
62948+
62949+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
62950+ match->deleted))
62951+ match = match->next;
62952+
62953+ if (match && !match->deleted)
62954+ return match;
62955+ else
62956+ return NULL;
62957+}
62958+
62959+static struct inodev_entry *
62960+lookup_inodev_entry(const ino_t ino, const dev_t dev)
62961+{
62962+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
62963+ struct inodev_entry *match;
62964+
62965+ match = inodev_set.i_hash[index];
62966+
62967+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
62968+ match = match->next;
62969+
62970+ return match;
62971+}
62972+
62973+static void
62974+insert_inodev_entry(struct inodev_entry *entry)
62975+{
62976+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
62977+ inodev_set.i_size);
62978+ struct inodev_entry **curr;
62979+
62980+ entry->prev = NULL;
62981+
62982+ curr = &inodev_set.i_hash[index];
62983+ if (*curr != NULL)
62984+ (*curr)->prev = entry;
62985+
62986+ entry->next = *curr;
62987+ *curr = entry;
62988+
62989+ return;
62990+}
62991+
62992+static void
62993+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
62994+{
62995+ unsigned int index =
62996+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
62997+ struct acl_role_label **curr;
62998+ struct acl_role_label *tmp, *tmp2;
62999+
63000+ curr = &acl_role_set.r_hash[index];
63001+
63002+ /* simple case, slot is empty, just set it to our role */
63003+ if (*curr == NULL) {
63004+ *curr = role;
63005+ } else {
63006+ /* example:
63007+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
63008+ 2 -> 3
63009+ */
63010+ /* first check to see if we can already be reached via this slot */
63011+ tmp = *curr;
63012+ while (tmp && tmp != role)
63013+ tmp = tmp->next;
63014+ if (tmp == role) {
63015+ /* we don't need to add ourselves to this slot's chain */
63016+ return;
63017+ }
63018+ /* we need to add ourselves to this chain, two cases */
63019+ if (role->next == NULL) {
63020+ /* simple case, append the current chain to our role */
63021+ role->next = *curr;
63022+ *curr = role;
63023+ } else {
63024+ /* 1 -> 2 -> 3 -> 4
63025+ 2 -> 3 -> 4
63026+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
63027+ */
63028+ /* trickier case: walk our role's chain until we find
63029+ the role for the start of the current slot's chain */
63030+ tmp = role;
63031+ tmp2 = *curr;
63032+ while (tmp->next && tmp->next != tmp2)
63033+ tmp = tmp->next;
63034+ if (tmp->next == tmp2) {
63035+ /* from example above, we found 3, so just
63036+ replace this slot's chain with ours */
63037+ *curr = role;
63038+ } else {
63039+ /* we didn't find a subset of our role's chain
63040+ in the current slot's chain, so append their
63041+ chain to ours, and set us as the first role in
63042+ the slot's chain
63043+
63044+ we could fold this case with the case above,
63045+ but making it explicit for clarity
63046+ */
63047+ tmp->next = tmp2;
63048+ *curr = role;
63049+ }
63050+ }
63051+ }
63052+
63053+ return;
63054+}
63055+
63056+static void
63057+insert_acl_role_label(struct acl_role_label *role)
63058+{
63059+ int i;
63060+
63061+ if (role_list == NULL) {
63062+ role_list = role;
63063+ role->prev = NULL;
63064+ } else {
63065+ role->prev = role_list;
63066+ role_list = role;
63067+ }
63068+
63069+ /* used for hash chains */
63070+ role->next = NULL;
63071+
63072+ if (role->roletype & GR_ROLE_DOMAIN) {
63073+ for (i = 0; i < role->domain_child_num; i++)
63074+ __insert_acl_role_label(role, role->domain_children[i]);
63075+ } else
63076+ __insert_acl_role_label(role, role->uidgid);
63077+}
63078+
63079+static int
63080+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
63081+{
63082+ struct name_entry **curr, *nentry;
63083+ struct inodev_entry *ientry;
63084+ unsigned int len = strlen(name);
63085+ unsigned int key = full_name_hash(name, len);
63086+ unsigned int index = key % name_set.n_size;
63087+
63088+ curr = &name_set.n_hash[index];
63089+
63090+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
63091+ curr = &((*curr)->next);
63092+
63093+ if (*curr != NULL)
63094+ return 1;
63095+
63096+ nentry = acl_alloc(sizeof (struct name_entry));
63097+ if (nentry == NULL)
63098+ return 0;
63099+ ientry = acl_alloc(sizeof (struct inodev_entry));
63100+ if (ientry == NULL)
63101+ return 0;
63102+ ientry->nentry = nentry;
63103+
63104+ nentry->key = key;
63105+ nentry->name = name;
63106+ nentry->inode = inode;
63107+ nentry->device = device;
63108+ nentry->len = len;
63109+ nentry->deleted = deleted;
63110+
63111+ nentry->prev = NULL;
63112+ curr = &name_set.n_hash[index];
63113+ if (*curr != NULL)
63114+ (*curr)->prev = nentry;
63115+ nentry->next = *curr;
63116+ *curr = nentry;
63117+
63118+ /* insert us into the table searchable by inode/dev */
63119+ insert_inodev_entry(ientry);
63120+
63121+ return 1;
63122+}
63123+
63124+static void
63125+insert_acl_obj_label(struct acl_object_label *obj,
63126+ struct acl_subject_label *subj)
63127+{
63128+ unsigned int index =
63129+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
63130+ struct acl_object_label **curr;
63131+
63132+
63133+ obj->prev = NULL;
63134+
63135+ curr = &subj->obj_hash[index];
63136+ if (*curr != NULL)
63137+ (*curr)->prev = obj;
63138+
63139+ obj->next = *curr;
63140+ *curr = obj;
63141+
63142+ return;
63143+}
63144+
63145+static void
63146+insert_acl_subj_label(struct acl_subject_label *obj,
63147+ struct acl_role_label *role)
63148+{
63149+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
63150+ struct acl_subject_label **curr;
63151+
63152+ obj->prev = NULL;
63153+
63154+ curr = &role->subj_hash[index];
63155+ if (*curr != NULL)
63156+ (*curr)->prev = obj;
63157+
63158+ obj->next = *curr;
63159+ *curr = obj;
63160+
63161+ return;
63162+}
63163+
63164+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
63165+
63166+static void *
63167+create_table(__u32 * len, int elementsize)
63168+{
63169+ unsigned int table_sizes[] = {
63170+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
63171+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
63172+ 4194301, 8388593, 16777213, 33554393, 67108859
63173+ };
63174+ void *newtable = NULL;
63175+ unsigned int pwr = 0;
63176+
63177+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
63178+ table_sizes[pwr] <= *len)
63179+ pwr++;
63180+
63181+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
63182+ return newtable;
63183+
63184+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
63185+ newtable =
63186+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
63187+ else
63188+ newtable = vmalloc(table_sizes[pwr] * elementsize);
63189+
63190+ *len = table_sizes[pwr];
63191+
63192+ return newtable;
63193+}
63194+
63195+static int
63196+init_variables(const struct gr_arg *arg)
63197+{
63198+ struct task_struct *reaper = init_pid_ns.child_reaper;
63199+ unsigned int stacksize;
63200+
63201+ subj_map_set.s_size = arg->role_db.num_subjects;
63202+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
63203+ name_set.n_size = arg->role_db.num_objects;
63204+ inodev_set.i_size = arg->role_db.num_objects;
63205+
63206+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
63207+ !name_set.n_size || !inodev_set.i_size)
63208+ return 1;
63209+
63210+ if (!gr_init_uidset())
63211+ return 1;
63212+
63213+ /* set up the stack that holds allocation info */
63214+
63215+ stacksize = arg->role_db.num_pointers + 5;
63216+
63217+ if (!acl_alloc_stack_init(stacksize))
63218+ return 1;
63219+
63220+ /* grab reference for the real root dentry and vfsmount */
63221+ get_fs_root(reaper->fs, &real_root);
63222+
63223+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63224+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
63225+#endif
63226+
63227+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
63228+ if (fakefs_obj_rw == NULL)
63229+ return 1;
63230+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
63231+
63232+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
63233+ if (fakefs_obj_rwx == NULL)
63234+ return 1;
63235+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
63236+
63237+ subj_map_set.s_hash =
63238+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
63239+ acl_role_set.r_hash =
63240+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
63241+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
63242+ inodev_set.i_hash =
63243+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
63244+
63245+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
63246+ !name_set.n_hash || !inodev_set.i_hash)
63247+ return 1;
63248+
63249+ memset(subj_map_set.s_hash, 0,
63250+ sizeof(struct subject_map *) * subj_map_set.s_size);
63251+ memset(acl_role_set.r_hash, 0,
63252+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
63253+ memset(name_set.n_hash, 0,
63254+ sizeof (struct name_entry *) * name_set.n_size);
63255+ memset(inodev_set.i_hash, 0,
63256+ sizeof (struct inodev_entry *) * inodev_set.i_size);
63257+
63258+ return 0;
63259+}
63260+
63261+/* free information not needed after startup
63262+ currently contains user->kernel pointer mappings for subjects
63263+*/
63264+
63265+static void
63266+free_init_variables(void)
63267+{
63268+ __u32 i;
63269+
63270+ if (subj_map_set.s_hash) {
63271+ for (i = 0; i < subj_map_set.s_size; i++) {
63272+ if (subj_map_set.s_hash[i]) {
63273+ kfree(subj_map_set.s_hash[i]);
63274+ subj_map_set.s_hash[i] = NULL;
63275+ }
63276+ }
63277+
63278+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
63279+ PAGE_SIZE)
63280+ kfree(subj_map_set.s_hash);
63281+ else
63282+ vfree(subj_map_set.s_hash);
63283+ }
63284+
63285+ return;
63286+}
63287+
63288+static void
63289+free_variables(void)
63290+{
63291+ struct acl_subject_label *s;
63292+ struct acl_role_label *r;
63293+ struct task_struct *task, *task2;
63294+ unsigned int x;
63295+
63296+ gr_clear_learn_entries();
63297+
63298+ read_lock(&tasklist_lock);
63299+ do_each_thread(task2, task) {
63300+ task->acl_sp_role = 0;
63301+ task->acl_role_id = 0;
63302+ task->acl = NULL;
63303+ task->role = NULL;
63304+ } while_each_thread(task2, task);
63305+ read_unlock(&tasklist_lock);
63306+
63307+ /* release the reference to the real root dentry and vfsmount */
63308+ path_put(&real_root);
63309+ memset(&real_root, 0, sizeof(real_root));
63310+
63311+ /* free all object hash tables */
63312+
63313+ FOR_EACH_ROLE_START(r)
63314+ if (r->subj_hash == NULL)
63315+ goto next_role;
63316+ FOR_EACH_SUBJECT_START(r, s, x)
63317+ if (s->obj_hash == NULL)
63318+ break;
63319+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
63320+ kfree(s->obj_hash);
63321+ else
63322+ vfree(s->obj_hash);
63323+ FOR_EACH_SUBJECT_END(s, x)
63324+ FOR_EACH_NESTED_SUBJECT_START(r, s)
63325+ if (s->obj_hash == NULL)
63326+ break;
63327+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
63328+ kfree(s->obj_hash);
63329+ else
63330+ vfree(s->obj_hash);
63331+ FOR_EACH_NESTED_SUBJECT_END(s)
63332+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
63333+ kfree(r->subj_hash);
63334+ else
63335+ vfree(r->subj_hash);
63336+ r->subj_hash = NULL;
63337+next_role:
63338+ FOR_EACH_ROLE_END(r)
63339+
63340+ acl_free_all();
63341+
63342+ if (acl_role_set.r_hash) {
63343+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
63344+ PAGE_SIZE)
63345+ kfree(acl_role_set.r_hash);
63346+ else
63347+ vfree(acl_role_set.r_hash);
63348+ }
63349+ if (name_set.n_hash) {
63350+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
63351+ PAGE_SIZE)
63352+ kfree(name_set.n_hash);
63353+ else
63354+ vfree(name_set.n_hash);
63355+ }
63356+
63357+ if (inodev_set.i_hash) {
63358+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
63359+ PAGE_SIZE)
63360+ kfree(inodev_set.i_hash);
63361+ else
63362+ vfree(inodev_set.i_hash);
63363+ }
63364+
63365+ gr_free_uidset();
63366+
63367+ memset(&name_set, 0, sizeof (struct name_db));
63368+ memset(&inodev_set, 0, sizeof (struct inodev_db));
63369+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
63370+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
63371+
63372+ default_role = NULL;
63373+ kernel_role = NULL;
63374+ role_list = NULL;
63375+
63376+ return;
63377+}
63378+
63379+static struct acl_subject_label *
63380+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
63381+
63382+static int alloc_and_copy_string(char **name, unsigned int maxlen)
63383+{
63384+ unsigned int len = strnlen_user(*name, maxlen);
63385+ char *tmp;
63386+
63387+ if (!len || len >= maxlen)
63388+ return -EINVAL;
63389+
63390+ if ((tmp = (char *) acl_alloc(len)) == NULL)
63391+ return -ENOMEM;
63392+
63393+ if (copy_from_user(tmp, *name, len))
63394+ return -EFAULT;
63395+
63396+ tmp[len-1] = '\0';
63397+ *name = tmp;
63398+
63399+ return 0;
63400+}
63401+
63402+static int
63403+copy_user_glob(struct acl_object_label *obj)
63404+{
63405+ struct acl_object_label *g_tmp, **guser;
63406+ int error;
63407+
63408+ if (obj->globbed == NULL)
63409+ return 0;
63410+
63411+ guser = &obj->globbed;
63412+ while (*guser) {
63413+ g_tmp = (struct acl_object_label *)
63414+ acl_alloc(sizeof (struct acl_object_label));
63415+ if (g_tmp == NULL)
63416+ return -ENOMEM;
63417+
63418+ if (copy_acl_object_label(g_tmp, *guser))
63419+ return -EFAULT;
63420+
63421+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
63422+ if (error)
63423+ return error;
63424+
63425+ *guser = g_tmp;
63426+ guser = &(g_tmp->next);
63427+ }
63428+
63429+ return 0;
63430+}
63431+
63432+static int
63433+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
63434+ struct acl_role_label *role)
63435+{
63436+ struct acl_object_label *o_tmp;
63437+ int ret;
63438+
63439+ while (userp) {
63440+ if ((o_tmp = (struct acl_object_label *)
63441+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
63442+ return -ENOMEM;
63443+
63444+ if (copy_acl_object_label(o_tmp, userp))
63445+ return -EFAULT;
63446+
63447+ userp = o_tmp->prev;
63448+
63449+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
63450+ if (ret)
63451+ return ret;
63452+
63453+ insert_acl_obj_label(o_tmp, subj);
63454+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
63455+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
63456+ return -ENOMEM;
63457+
63458+ ret = copy_user_glob(o_tmp);
63459+ if (ret)
63460+ return ret;
63461+
63462+ if (o_tmp->nested) {
63463+ int already_copied;
63464+
63465+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
63466+ if (IS_ERR(o_tmp->nested))
63467+ return PTR_ERR(o_tmp->nested);
63468+
63469+ /* insert into nested subject list if we haven't copied this one yet
63470+ to prevent duplicate entries */
63471+ if (!already_copied) {
63472+ o_tmp->nested->next = role->hash->first;
63473+ role->hash->first = o_tmp->nested;
63474+ }
63475+ }
63476+ }
63477+
63478+ return 0;
63479+}
63480+
63481+static __u32
63482+count_user_subjs(struct acl_subject_label *userp)
63483+{
63484+ struct acl_subject_label s_tmp;
63485+ __u32 num = 0;
63486+
63487+ while (userp) {
63488+ if (copy_acl_subject_label(&s_tmp, userp))
63489+ break;
63490+
63491+ userp = s_tmp.prev;
63492+ }
63493+
63494+ return num;
63495+}
63496+
63497+static int
63498+copy_user_allowedips(struct acl_role_label *rolep)
63499+{
63500+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
63501+
63502+ ruserip = rolep->allowed_ips;
63503+
63504+ while (ruserip) {
63505+ rlast = rtmp;
63506+
63507+ if ((rtmp = (struct role_allowed_ip *)
63508+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
63509+ return -ENOMEM;
63510+
63511+ if (copy_role_allowed_ip(rtmp, ruserip))
63512+ return -EFAULT;
63513+
63514+ ruserip = rtmp->prev;
63515+
63516+ if (!rlast) {
63517+ rtmp->prev = NULL;
63518+ rolep->allowed_ips = rtmp;
63519+ } else {
63520+ rlast->next = rtmp;
63521+ rtmp->prev = rlast;
63522+ }
63523+
63524+ if (!ruserip)
63525+ rtmp->next = NULL;
63526+ }
63527+
63528+ return 0;
63529+}
63530+
63531+static int
63532+copy_user_transitions(struct acl_role_label *rolep)
63533+{
63534+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
63535+ int error;
63536+
63537+ rusertp = rolep->transitions;
63538+
63539+ while (rusertp) {
63540+ rlast = rtmp;
63541+
63542+ if ((rtmp = (struct role_transition *)
63543+ acl_alloc(sizeof (struct role_transition))) == NULL)
63544+ return -ENOMEM;
63545+
63546+ if (copy_role_transition(rtmp, rusertp))
63547+ return -EFAULT;
63548+
63549+ rusertp = rtmp->prev;
63550+
63551+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
63552+ if (error)
63553+ return error;
63554+
63555+ if (!rlast) {
63556+ rtmp->prev = NULL;
63557+ rolep->transitions = rtmp;
63558+ } else {
63559+ rlast->next = rtmp;
63560+ rtmp->prev = rlast;
63561+ }
63562+
63563+ if (!rusertp)
63564+ rtmp->next = NULL;
63565+ }
63566+
63567+ return 0;
63568+}
63569+
63570+static __u32 count_user_objs(const struct acl_object_label __user *userp)
63571+{
63572+ struct acl_object_label o_tmp;
63573+ __u32 num = 0;
63574+
63575+ while (userp) {
63576+ if (copy_acl_object_label(&o_tmp, userp))
63577+ break;
63578+
63579+ userp = o_tmp.prev;
63580+ num++;
63581+ }
63582+
63583+ return num;
63584+}
63585+
63586+static struct acl_subject_label *
63587+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
63588+{
63589+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
63590+ __u32 num_objs;
63591+ struct acl_ip_label **i_tmp, *i_utmp2;
63592+ struct gr_hash_struct ghash;
63593+ struct subject_map *subjmap;
63594+ unsigned int i_num;
63595+ int err;
63596+
63597+ if (already_copied != NULL)
63598+ *already_copied = 0;
63599+
63600+ s_tmp = lookup_subject_map(userp);
63601+
63602+ /* we've already copied this subject into the kernel, just return
63603+ the reference to it, and don't copy it over again
63604+ */
63605+ if (s_tmp) {
63606+ if (already_copied != NULL)
63607+ *already_copied = 1;
63608+ return(s_tmp);
63609+ }
63610+
63611+ if ((s_tmp = (struct acl_subject_label *)
63612+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
63613+ return ERR_PTR(-ENOMEM);
63614+
63615+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
63616+ if (subjmap == NULL)
63617+ return ERR_PTR(-ENOMEM);
63618+
63619+ subjmap->user = userp;
63620+ subjmap->kernel = s_tmp;
63621+ insert_subj_map_entry(subjmap);
63622+
63623+ if (copy_acl_subject_label(s_tmp, userp))
63624+ return ERR_PTR(-EFAULT);
63625+
63626+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
63627+ if (err)
63628+ return ERR_PTR(err);
63629+
63630+ if (!strcmp(s_tmp->filename, "/"))
63631+ role->root_label = s_tmp;
63632+
63633+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
63634+ return ERR_PTR(-EFAULT);
63635+
63636+ /* copy user and group transition tables */
63637+
63638+ if (s_tmp->user_trans_num) {
63639+ uid_t *uidlist;
63640+
63641+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
63642+ if (uidlist == NULL)
63643+ return ERR_PTR(-ENOMEM);
63644+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
63645+ return ERR_PTR(-EFAULT);
63646+
63647+ s_tmp->user_transitions = uidlist;
63648+ }
63649+
63650+ if (s_tmp->group_trans_num) {
63651+ gid_t *gidlist;
63652+
63653+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
63654+ if (gidlist == NULL)
63655+ return ERR_PTR(-ENOMEM);
63656+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
63657+ return ERR_PTR(-EFAULT);
63658+
63659+ s_tmp->group_transitions = gidlist;
63660+ }
63661+
63662+ /* set up object hash table */
63663+ num_objs = count_user_objs(ghash.first);
63664+
63665+ s_tmp->obj_hash_size = num_objs;
63666+ s_tmp->obj_hash =
63667+ (struct acl_object_label **)
63668+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
63669+
63670+ if (!s_tmp->obj_hash)
63671+ return ERR_PTR(-ENOMEM);
63672+
63673+ memset(s_tmp->obj_hash, 0,
63674+ s_tmp->obj_hash_size *
63675+ sizeof (struct acl_object_label *));
63676+
63677+ /* add in objects */
63678+ err = copy_user_objs(ghash.first, s_tmp, role);
63679+
63680+ if (err)
63681+ return ERR_PTR(err);
63682+
63683+ /* set pointer for parent subject */
63684+ if (s_tmp->parent_subject) {
63685+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
63686+
63687+ if (IS_ERR(s_tmp2))
63688+ return s_tmp2;
63689+
63690+ s_tmp->parent_subject = s_tmp2;
63691+ }
63692+
63693+ /* add in ip acls */
63694+
63695+ if (!s_tmp->ip_num) {
63696+ s_tmp->ips = NULL;
63697+ goto insert;
63698+ }
63699+
63700+ i_tmp =
63701+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
63702+ sizeof (struct acl_ip_label *));
63703+
63704+ if (!i_tmp)
63705+ return ERR_PTR(-ENOMEM);
63706+
63707+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
63708+ *(i_tmp + i_num) =
63709+ (struct acl_ip_label *)
63710+ acl_alloc(sizeof (struct acl_ip_label));
63711+ if (!*(i_tmp + i_num))
63712+ return ERR_PTR(-ENOMEM);
63713+
63714+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
63715+ return ERR_PTR(-EFAULT);
63716+
63717+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
63718+ return ERR_PTR(-EFAULT);
63719+
63720+ if ((*(i_tmp + i_num))->iface == NULL)
63721+ continue;
63722+
63723+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
63724+ if (err)
63725+ return ERR_PTR(err);
63726+ }
63727+
63728+ s_tmp->ips = i_tmp;
63729+
63730+insert:
63731+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
63732+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
63733+ return ERR_PTR(-ENOMEM);
63734+
63735+ return s_tmp;
63736+}
63737+
63738+static int
63739+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
63740+{
63741+ struct acl_subject_label s_pre;
63742+ struct acl_subject_label * ret;
63743+ int err;
63744+
63745+ while (userp) {
63746+ if (copy_acl_subject_label(&s_pre, userp))
63747+ return -EFAULT;
63748+
63749+ ret = do_copy_user_subj(userp, role, NULL);
63750+
63751+ err = PTR_ERR(ret);
63752+ if (IS_ERR(ret))
63753+ return err;
63754+
63755+ insert_acl_subj_label(ret, role);
63756+
63757+ userp = s_pre.prev;
63758+ }
63759+
63760+ return 0;
63761+}
63762+
63763+static int
63764+copy_user_acl(struct gr_arg *arg)
63765+{
63766+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
63767+ struct acl_subject_label *subj_list;
63768+ struct sprole_pw *sptmp;
63769+ struct gr_hash_struct *ghash;
63770+ uid_t *domainlist;
63771+ unsigned int r_num;
63772+ int err = 0;
63773+ __u16 i;
63774+ __u32 num_subjs;
63775+
63776+ /* we need a default and kernel role */
63777+ if (arg->role_db.num_roles < 2)
63778+ return -EINVAL;
63779+
63780+ /* copy special role authentication info from userspace */
63781+
63782+ num_sprole_pws = arg->num_sprole_pws;
63783+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
63784+
63785+ if (!acl_special_roles && num_sprole_pws)
63786+ return -ENOMEM;
63787+
63788+ for (i = 0; i < num_sprole_pws; i++) {
63789+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
63790+ if (!sptmp)
63791+ return -ENOMEM;
63792+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
63793+ return -EFAULT;
63794+
63795+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
63796+ if (err)
63797+ return err;
63798+
63799+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63800+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
63801+#endif
63802+
63803+ acl_special_roles[i] = sptmp;
63804+ }
63805+
63806+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
63807+
63808+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
63809+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
63810+
63811+ if (!r_tmp)
63812+ return -ENOMEM;
63813+
63814+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
63815+ return -EFAULT;
63816+
63817+ if (copy_acl_role_label(r_tmp, r_utmp2))
63818+ return -EFAULT;
63819+
63820+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
63821+ if (err)
63822+ return err;
63823+
63824+ if (!strcmp(r_tmp->rolename, "default")
63825+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
63826+ default_role = r_tmp;
63827+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
63828+ kernel_role = r_tmp;
63829+ }
63830+
63831+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
63832+ return -ENOMEM;
63833+
63834+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
63835+ return -EFAULT;
63836+
63837+ r_tmp->hash = ghash;
63838+
63839+ num_subjs = count_user_subjs(r_tmp->hash->first);
63840+
63841+ r_tmp->subj_hash_size = num_subjs;
63842+ r_tmp->subj_hash =
63843+ (struct acl_subject_label **)
63844+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
63845+
63846+ if (!r_tmp->subj_hash)
63847+ return -ENOMEM;
63848+
63849+ err = copy_user_allowedips(r_tmp);
63850+ if (err)
63851+ return err;
63852+
63853+ /* copy domain info */
63854+ if (r_tmp->domain_children != NULL) {
63855+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
63856+ if (domainlist == NULL)
63857+ return -ENOMEM;
63858+
63859+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
63860+ return -EFAULT;
63861+
63862+ r_tmp->domain_children = domainlist;
63863+ }
63864+
63865+ err = copy_user_transitions(r_tmp);
63866+ if (err)
63867+ return err;
63868+
63869+ memset(r_tmp->subj_hash, 0,
63870+ r_tmp->subj_hash_size *
63871+ sizeof (struct acl_subject_label *));
63872+
63873+ /* acquire the list of subjects, then NULL out
63874+ the list prior to parsing the subjects for this role,
63875+ as during this parsing the list is replaced with a list
63876+ of *nested* subjects for the role
63877+ */
63878+ subj_list = r_tmp->hash->first;
63879+
63880+ /* set nested subject list to null */
63881+ r_tmp->hash->first = NULL;
63882+
63883+ err = copy_user_subjs(subj_list, r_tmp);
63884+
63885+ if (err)
63886+ return err;
63887+
63888+ insert_acl_role_label(r_tmp);
63889+ }
63890+
63891+ if (default_role == NULL || kernel_role == NULL)
63892+ return -EINVAL;
63893+
63894+ return err;
63895+}
63896+
63897+static int
63898+gracl_init(struct gr_arg *args)
63899+{
63900+ int error = 0;
63901+
63902+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
63903+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
63904+
63905+ if (init_variables(args)) {
63906+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
63907+ error = -ENOMEM;
63908+ free_variables();
63909+ goto out;
63910+ }
63911+
63912+ error = copy_user_acl(args);
63913+ free_init_variables();
63914+ if (error) {
63915+ free_variables();
63916+ goto out;
63917+ }
63918+
63919+ if ((error = gr_set_acls(0))) {
63920+ free_variables();
63921+ goto out;
63922+ }
63923+
63924+ pax_open_kernel();
63925+ gr_status |= GR_READY;
63926+ pax_close_kernel();
63927+
63928+ out:
63929+ return error;
63930+}
63931+
63932+/* derived from glibc fnmatch() 0: match, 1: no match*/
63933+
63934+static int
63935+glob_match(const char *p, const char *n)
63936+{
63937+ char c;
63938+
63939+ while ((c = *p++) != '\0') {
63940+ switch (c) {
63941+ case '?':
63942+ if (*n == '\0')
63943+ return 1;
63944+ else if (*n == '/')
63945+ return 1;
63946+ break;
63947+ case '\\':
63948+ if (*n != c)
63949+ return 1;
63950+ break;
63951+ case '*':
63952+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
63953+ if (*n == '/')
63954+ return 1;
63955+ else if (c == '?') {
63956+ if (*n == '\0')
63957+ return 1;
63958+ else
63959+ ++n;
63960+ }
63961+ }
63962+ if (c == '\0') {
63963+ return 0;
63964+ } else {
63965+ const char *endp;
63966+
63967+ if ((endp = strchr(n, '/')) == NULL)
63968+ endp = n + strlen(n);
63969+
63970+ if (c == '[') {
63971+ for (--p; n < endp; ++n)
63972+ if (!glob_match(p, n))
63973+ return 0;
63974+ } else if (c == '/') {
63975+ while (*n != '\0' && *n != '/')
63976+ ++n;
63977+ if (*n == '/' && !glob_match(p, n + 1))
63978+ return 0;
63979+ } else {
63980+ for (--p; n < endp; ++n)
63981+ if (*n == c && !glob_match(p, n))
63982+ return 0;
63983+ }
63984+
63985+ return 1;
63986+ }
63987+ case '[':
63988+ {
63989+ int not;
63990+ char cold;
63991+
63992+ if (*n == '\0' || *n == '/')
63993+ return 1;
63994+
63995+ not = (*p == '!' || *p == '^');
63996+ if (not)
63997+ ++p;
63998+
63999+ c = *p++;
64000+ for (;;) {
64001+ unsigned char fn = (unsigned char)*n;
64002+
64003+ if (c == '\0')
64004+ return 1;
64005+ else {
64006+ if (c == fn)
64007+ goto matched;
64008+ cold = c;
64009+ c = *p++;
64010+
64011+ if (c == '-' && *p != ']') {
64012+ unsigned char cend = *p++;
64013+
64014+ if (cend == '\0')
64015+ return 1;
64016+
64017+ if (cold <= fn && fn <= cend)
64018+ goto matched;
64019+
64020+ c = *p++;
64021+ }
64022+ }
64023+
64024+ if (c == ']')
64025+ break;
64026+ }
64027+ if (!not)
64028+ return 1;
64029+ break;
64030+ matched:
64031+ while (c != ']') {
64032+ if (c == '\0')
64033+ return 1;
64034+
64035+ c = *p++;
64036+ }
64037+ if (not)
64038+ return 1;
64039+ }
64040+ break;
64041+ default:
64042+ if (c != *n)
64043+ return 1;
64044+ }
64045+
64046+ ++n;
64047+ }
64048+
64049+ if (*n == '\0')
64050+ return 0;
64051+
64052+ if (*n == '/')
64053+ return 0;
64054+
64055+ return 1;
64056+}
64057+
64058+static struct acl_object_label *
64059+chk_glob_label(struct acl_object_label *globbed,
64060+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
64061+{
64062+ struct acl_object_label *tmp;
64063+
64064+ if (*path == NULL)
64065+ *path = gr_to_filename_nolock(dentry, mnt);
64066+
64067+ tmp = globbed;
64068+
64069+ while (tmp) {
64070+ if (!glob_match(tmp->filename, *path))
64071+ return tmp;
64072+ tmp = tmp->next;
64073+ }
64074+
64075+ return NULL;
64076+}
64077+
64078+static struct acl_object_label *
64079+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
64080+ const ino_t curr_ino, const dev_t curr_dev,
64081+ const struct acl_subject_label *subj, char **path, const int checkglob)
64082+{
64083+ struct acl_subject_label *tmpsubj;
64084+ struct acl_object_label *retval;
64085+ struct acl_object_label *retval2;
64086+
64087+ tmpsubj = (struct acl_subject_label *) subj;
64088+ read_lock(&gr_inode_lock);
64089+ do {
64090+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
64091+ if (retval) {
64092+ if (checkglob && retval->globbed) {
64093+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
64094+ if (retval2)
64095+ retval = retval2;
64096+ }
64097+ break;
64098+ }
64099+ } while ((tmpsubj = tmpsubj->parent_subject));
64100+ read_unlock(&gr_inode_lock);
64101+
64102+ return retval;
64103+}
64104+
64105+static __inline__ struct acl_object_label *
64106+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
64107+ struct dentry *curr_dentry,
64108+ const struct acl_subject_label *subj, char **path, const int checkglob)
64109+{
64110+ int newglob = checkglob;
64111+ ino_t inode;
64112+ dev_t device;
64113+
64114+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
64115+ as we don't want a / * rule to match instead of the / object
64116+ don't do this for create lookups that call this function though, since they're looking up
64117+ on the parent and thus need globbing checks on all paths
64118+ */
64119+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
64120+ newglob = GR_NO_GLOB;
64121+
64122+ spin_lock(&curr_dentry->d_lock);
64123+ inode = curr_dentry->d_inode->i_ino;
64124+ device = __get_dev(curr_dentry);
64125+ spin_unlock(&curr_dentry->d_lock);
64126+
64127+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
64128+}
64129+
64130+#ifdef CONFIG_HUGETLBFS
64131+static inline bool
64132+is_hugetlbfs_mnt(const struct vfsmount *mnt)
64133+{
64134+ int i;
64135+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
64136+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
64137+ return true;
64138+ }
64139+
64140+ return false;
64141+}
64142+#endif
64143+
64144+static struct acl_object_label *
64145+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64146+ const struct acl_subject_label *subj, char *path, const int checkglob)
64147+{
64148+ struct dentry *dentry = (struct dentry *) l_dentry;
64149+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64150+ struct mount *real_mnt = real_mount(mnt);
64151+ struct acl_object_label *retval;
64152+ struct dentry *parent;
64153+
64154+ br_read_lock(&vfsmount_lock);
64155+ write_seqlock(&rename_lock);
64156+
64157+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
64158+#ifdef CONFIG_NET
64159+ mnt == sock_mnt ||
64160+#endif
64161+#ifdef CONFIG_HUGETLBFS
64162+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
64163+#endif
64164+ /* ignore Eric Biederman */
64165+ IS_PRIVATE(l_dentry->d_inode))) {
64166+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
64167+ goto out;
64168+ }
64169+
64170+ for (;;) {
64171+ if (dentry == real_root.dentry && mnt == real_root.mnt)
64172+ break;
64173+
64174+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64175+ if (!mnt_has_parent(real_mnt))
64176+ break;
64177+
64178+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64179+ if (retval != NULL)
64180+ goto out;
64181+
64182+ dentry = real_mnt->mnt_mountpoint;
64183+ real_mnt = real_mnt->mnt_parent;
64184+ mnt = &real_mnt->mnt;
64185+ continue;
64186+ }
64187+
64188+ parent = dentry->d_parent;
64189+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64190+ if (retval != NULL)
64191+ goto out;
64192+
64193+ dentry = parent;
64194+ }
64195+
64196+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64197+
64198+ /* real_root is pinned so we don't have to hold a reference */
64199+ if (retval == NULL)
64200+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
64201+out:
64202+ write_sequnlock(&rename_lock);
64203+ br_read_unlock(&vfsmount_lock);
64204+
64205+ BUG_ON(retval == NULL);
64206+
64207+ return retval;
64208+}
64209+
64210+static __inline__ struct acl_object_label *
64211+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64212+ const struct acl_subject_label *subj)
64213+{
64214+ char *path = NULL;
64215+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
64216+}
64217+
64218+static __inline__ struct acl_object_label *
64219+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64220+ const struct acl_subject_label *subj)
64221+{
64222+ char *path = NULL;
64223+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
64224+}
64225+
64226+static __inline__ struct acl_object_label *
64227+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64228+ const struct acl_subject_label *subj, char *path)
64229+{
64230+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
64231+}
64232+
64233+static struct acl_subject_label *
64234+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64235+ const struct acl_role_label *role)
64236+{
64237+ struct dentry *dentry = (struct dentry *) l_dentry;
64238+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64239+ struct mount *real_mnt = real_mount(mnt);
64240+ struct acl_subject_label *retval;
64241+ struct dentry *parent;
64242+
64243+ br_read_lock(&vfsmount_lock);
64244+ write_seqlock(&rename_lock);
64245+
64246+ for (;;) {
64247+ if (dentry == real_root.dentry && mnt == real_root.mnt)
64248+ break;
64249+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64250+ if (!mnt_has_parent(real_mnt))
64251+ break;
64252+
64253+ spin_lock(&dentry->d_lock);
64254+ read_lock(&gr_inode_lock);
64255+ retval =
64256+ lookup_acl_subj_label(dentry->d_inode->i_ino,
64257+ __get_dev(dentry), role);
64258+ read_unlock(&gr_inode_lock);
64259+ spin_unlock(&dentry->d_lock);
64260+ if (retval != NULL)
64261+ goto out;
64262+
64263+ dentry = real_mnt->mnt_mountpoint;
64264+ real_mnt = real_mnt->mnt_parent;
64265+ mnt = &real_mnt->mnt;
64266+ continue;
64267+ }
64268+
64269+ spin_lock(&dentry->d_lock);
64270+ read_lock(&gr_inode_lock);
64271+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64272+ __get_dev(dentry), role);
64273+ read_unlock(&gr_inode_lock);
64274+ parent = dentry->d_parent;
64275+ spin_unlock(&dentry->d_lock);
64276+
64277+ if (retval != NULL)
64278+ goto out;
64279+
64280+ dentry = parent;
64281+ }
64282+
64283+ spin_lock(&dentry->d_lock);
64284+ read_lock(&gr_inode_lock);
64285+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64286+ __get_dev(dentry), role);
64287+ read_unlock(&gr_inode_lock);
64288+ spin_unlock(&dentry->d_lock);
64289+
64290+ if (unlikely(retval == NULL)) {
64291+ /* real_root is pinned, we don't need to hold a reference */
64292+ read_lock(&gr_inode_lock);
64293+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
64294+ __get_dev(real_root.dentry), role);
64295+ read_unlock(&gr_inode_lock);
64296+ }
64297+out:
64298+ write_sequnlock(&rename_lock);
64299+ br_read_unlock(&vfsmount_lock);
64300+
64301+ BUG_ON(retval == NULL);
64302+
64303+ return retval;
64304+}
64305+
64306+static void
64307+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
64308+{
64309+ struct task_struct *task = current;
64310+ const struct cred *cred = current_cred();
64311+
64312+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
64313+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64314+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64315+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
64316+
64317+ return;
64318+}
64319+
64320+static void
64321+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
64322+{
64323+ struct task_struct *task = current;
64324+ const struct cred *cred = current_cred();
64325+
64326+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64327+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64328+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64329+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
64330+
64331+ return;
64332+}
64333+
64334+static void
64335+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
64336+{
64337+ struct task_struct *task = current;
64338+ const struct cred *cred = current_cred();
64339+
64340+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64341+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64342+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64343+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
64344+
64345+ return;
64346+}
64347+
64348+__u32
64349+gr_search_file(const struct dentry * dentry, const __u32 mode,
64350+ const struct vfsmount * mnt)
64351+{
64352+ __u32 retval = mode;
64353+ struct acl_subject_label *curracl;
64354+ struct acl_object_label *currobj;
64355+
64356+ if (unlikely(!(gr_status & GR_READY)))
64357+ return (mode & ~GR_AUDITS);
64358+
64359+ curracl = current->acl;
64360+
64361+ currobj = chk_obj_label(dentry, mnt, curracl);
64362+ retval = currobj->mode & mode;
64363+
64364+ /* if we're opening a specified transfer file for writing
64365+ (e.g. /dev/initctl), then transfer our role to init
64366+ */
64367+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
64368+ current->role->roletype & GR_ROLE_PERSIST)) {
64369+ struct task_struct *task = init_pid_ns.child_reaper;
64370+
64371+ if (task->role != current->role) {
64372+ task->acl_sp_role = 0;
64373+ task->acl_role_id = current->acl_role_id;
64374+ task->role = current->role;
64375+ rcu_read_lock();
64376+ read_lock(&grsec_exec_file_lock);
64377+ gr_apply_subject_to_task(task);
64378+ read_unlock(&grsec_exec_file_lock);
64379+ rcu_read_unlock();
64380+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
64381+ }
64382+ }
64383+
64384+ if (unlikely
64385+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
64386+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
64387+ __u32 new_mode = mode;
64388+
64389+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64390+
64391+ retval = new_mode;
64392+
64393+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
64394+ new_mode |= GR_INHERIT;
64395+
64396+ if (!(mode & GR_NOLEARN))
64397+ gr_log_learn(dentry, mnt, new_mode);
64398+ }
64399+
64400+ return retval;
64401+}
64402+
64403+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
64404+ const struct dentry *parent,
64405+ const struct vfsmount *mnt)
64406+{
64407+ struct name_entry *match;
64408+ struct acl_object_label *matchpo;
64409+ struct acl_subject_label *curracl;
64410+ char *path;
64411+
64412+ if (unlikely(!(gr_status & GR_READY)))
64413+ return NULL;
64414+
64415+ preempt_disable();
64416+ path = gr_to_filename_rbac(new_dentry, mnt);
64417+ match = lookup_name_entry_create(path);
64418+
64419+ curracl = current->acl;
64420+
64421+ if (match) {
64422+ read_lock(&gr_inode_lock);
64423+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
64424+ read_unlock(&gr_inode_lock);
64425+
64426+ if (matchpo) {
64427+ preempt_enable();
64428+ return matchpo;
64429+ }
64430+ }
64431+
64432+ // lookup parent
64433+
64434+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
64435+
64436+ preempt_enable();
64437+ return matchpo;
64438+}
64439+
64440+__u32
64441+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
64442+ const struct vfsmount * mnt, const __u32 mode)
64443+{
64444+ struct acl_object_label *matchpo;
64445+ __u32 retval;
64446+
64447+ if (unlikely(!(gr_status & GR_READY)))
64448+ return (mode & ~GR_AUDITS);
64449+
64450+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
64451+
64452+ retval = matchpo->mode & mode;
64453+
64454+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
64455+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64456+ __u32 new_mode = mode;
64457+
64458+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64459+
64460+ gr_log_learn(new_dentry, mnt, new_mode);
64461+ return new_mode;
64462+ }
64463+
64464+ return retval;
64465+}
64466+
64467+__u32
64468+gr_check_link(const struct dentry * new_dentry,
64469+ const struct dentry * parent_dentry,
64470+ const struct vfsmount * parent_mnt,
64471+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
64472+{
64473+ struct acl_object_label *obj;
64474+ __u32 oldmode, newmode;
64475+ __u32 needmode;
64476+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
64477+ GR_DELETE | GR_INHERIT;
64478+
64479+ if (unlikely(!(gr_status & GR_READY)))
64480+ return (GR_CREATE | GR_LINK);
64481+
64482+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
64483+ oldmode = obj->mode;
64484+
64485+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
64486+ newmode = obj->mode;
64487+
64488+ needmode = newmode & checkmodes;
64489+
64490+ // old name for hardlink must have at least the permissions of the new name
64491+ if ((oldmode & needmode) != needmode)
64492+ goto bad;
64493+
64494+ // if old name had restrictions/auditing, make sure the new name does as well
64495+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
64496+
64497+ // don't allow hardlinking of suid/sgid/fcapped files without permission
64498+ if (is_privileged_binary(old_dentry))
64499+ needmode |= GR_SETID;
64500+
64501+ if ((newmode & needmode) != needmode)
64502+ goto bad;
64503+
64504+ // enforce minimum permissions
64505+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
64506+ return newmode;
64507+bad:
64508+ needmode = oldmode;
64509+ if (is_privileged_binary(old_dentry))
64510+ needmode |= GR_SETID;
64511+
64512+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
64513+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
64514+ return (GR_CREATE | GR_LINK);
64515+ } else if (newmode & GR_SUPPRESS)
64516+ return GR_SUPPRESS;
64517+ else
64518+ return 0;
64519+}
64520+
64521+int
64522+gr_check_hidden_task(const struct task_struct *task)
64523+{
64524+ if (unlikely(!(gr_status & GR_READY)))
64525+ return 0;
64526+
64527+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
64528+ return 1;
64529+
64530+ return 0;
64531+}
64532+
64533+int
64534+gr_check_protected_task(const struct task_struct *task)
64535+{
64536+ if (unlikely(!(gr_status & GR_READY) || !task))
64537+ return 0;
64538+
64539+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64540+ task->acl != current->acl)
64541+ return 1;
64542+
64543+ return 0;
64544+}
64545+
64546+int
64547+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64548+{
64549+ struct task_struct *p;
64550+ int ret = 0;
64551+
64552+ if (unlikely(!(gr_status & GR_READY) || !pid))
64553+ return ret;
64554+
64555+ read_lock(&tasklist_lock);
64556+ do_each_pid_task(pid, type, p) {
64557+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64558+ p->acl != current->acl) {
64559+ ret = 1;
64560+ goto out;
64561+ }
64562+ } while_each_pid_task(pid, type, p);
64563+out:
64564+ read_unlock(&tasklist_lock);
64565+
64566+ return ret;
64567+}
64568+
64569+void
64570+gr_copy_label(struct task_struct *tsk)
64571+{
64572+ tsk->signal->used_accept = 0;
64573+ tsk->acl_sp_role = 0;
64574+ tsk->acl_role_id = current->acl_role_id;
64575+ tsk->acl = current->acl;
64576+ tsk->role = current->role;
64577+ tsk->signal->curr_ip = current->signal->curr_ip;
64578+ tsk->signal->saved_ip = current->signal->saved_ip;
64579+ if (current->exec_file)
64580+ get_file(current->exec_file);
64581+ tsk->exec_file = current->exec_file;
64582+ tsk->is_writable = current->is_writable;
64583+ if (unlikely(current->signal->used_accept)) {
64584+ current->signal->curr_ip = 0;
64585+ current->signal->saved_ip = 0;
64586+ }
64587+
64588+ return;
64589+}
64590+
64591+static void
64592+gr_set_proc_res(struct task_struct *task)
64593+{
64594+ struct acl_subject_label *proc;
64595+ unsigned short i;
64596+
64597+ proc = task->acl;
64598+
64599+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
64600+ return;
64601+
64602+ for (i = 0; i < RLIM_NLIMITS; i++) {
64603+ if (!(proc->resmask & (1U << i)))
64604+ continue;
64605+
64606+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
64607+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
64608+
64609+ if (i == RLIMIT_CPU)
64610+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
64611+ }
64612+
64613+ return;
64614+}
64615+
64616+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
64617+
64618+int
64619+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64620+{
64621+ unsigned int i;
64622+ __u16 num;
64623+ uid_t *uidlist;
64624+ uid_t curuid;
64625+ int realok = 0;
64626+ int effectiveok = 0;
64627+ int fsok = 0;
64628+ uid_t globalreal, globaleffective, globalfs;
64629+
64630+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
64631+ struct user_struct *user;
64632+
64633+ if (!uid_valid(real))
64634+ goto skipit;
64635+
64636+ /* find user based on global namespace */
64637+
64638+ globalreal = GR_GLOBAL_UID(real);
64639+
64640+ user = find_user(make_kuid(&init_user_ns, globalreal));
64641+ if (user == NULL)
64642+ goto skipit;
64643+
64644+ if (gr_process_kernel_setuid_ban(user)) {
64645+ /* for find_user */
64646+ free_uid(user);
64647+ return 1;
64648+ }
64649+
64650+ /* for find_user */
64651+ free_uid(user);
64652+
64653+skipit:
64654+#endif
64655+
64656+ if (unlikely(!(gr_status & GR_READY)))
64657+ return 0;
64658+
64659+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64660+ gr_log_learn_uid_change(real, effective, fs);
64661+
64662+ num = current->acl->user_trans_num;
64663+ uidlist = current->acl->user_transitions;
64664+
64665+ if (uidlist == NULL)
64666+ return 0;
64667+
64668+ if (!uid_valid(real)) {
64669+ realok = 1;
64670+ globalreal = (uid_t)-1;
64671+ } else {
64672+ globalreal = GR_GLOBAL_UID(real);
64673+ }
64674+ if (!uid_valid(effective)) {
64675+ effectiveok = 1;
64676+ globaleffective = (uid_t)-1;
64677+ } else {
64678+ globaleffective = GR_GLOBAL_UID(effective);
64679+ }
64680+ if (!uid_valid(fs)) {
64681+ fsok = 1;
64682+ globalfs = (uid_t)-1;
64683+ } else {
64684+ globalfs = GR_GLOBAL_UID(fs);
64685+ }
64686+
64687+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
64688+ for (i = 0; i < num; i++) {
64689+ curuid = uidlist[i];
64690+ if (globalreal == curuid)
64691+ realok = 1;
64692+ if (globaleffective == curuid)
64693+ effectiveok = 1;
64694+ if (globalfs == curuid)
64695+ fsok = 1;
64696+ }
64697+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
64698+ for (i = 0; i < num; i++) {
64699+ curuid = uidlist[i];
64700+ if (globalreal == curuid)
64701+ break;
64702+ if (globaleffective == curuid)
64703+ break;
64704+ if (globalfs == curuid)
64705+ break;
64706+ }
64707+ /* not in deny list */
64708+ if (i == num) {
64709+ realok = 1;
64710+ effectiveok = 1;
64711+ fsok = 1;
64712+ }
64713+ }
64714+
64715+ if (realok && effectiveok && fsok)
64716+ return 0;
64717+ else {
64718+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64719+ return 1;
64720+ }
64721+}
64722+
64723+int
64724+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64725+{
64726+ unsigned int i;
64727+ __u16 num;
64728+ gid_t *gidlist;
64729+ gid_t curgid;
64730+ int realok = 0;
64731+ int effectiveok = 0;
64732+ int fsok = 0;
64733+ gid_t globalreal, globaleffective, globalfs;
64734+
64735+ if (unlikely(!(gr_status & GR_READY)))
64736+ return 0;
64737+
64738+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64739+ gr_log_learn_gid_change(real, effective, fs);
64740+
64741+ num = current->acl->group_trans_num;
64742+ gidlist = current->acl->group_transitions;
64743+
64744+ if (gidlist == NULL)
64745+ return 0;
64746+
64747+ if (!gid_valid(real)) {
64748+ realok = 1;
64749+ globalreal = (gid_t)-1;
64750+ } else {
64751+ globalreal = GR_GLOBAL_GID(real);
64752+ }
64753+ if (!gid_valid(effective)) {
64754+ effectiveok = 1;
64755+ globaleffective = (gid_t)-1;
64756+ } else {
64757+ globaleffective = GR_GLOBAL_GID(effective);
64758+ }
64759+ if (!gid_valid(fs)) {
64760+ fsok = 1;
64761+ globalfs = (gid_t)-1;
64762+ } else {
64763+ globalfs = GR_GLOBAL_GID(fs);
64764+ }
64765+
64766+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
64767+ for (i = 0; i < num; i++) {
64768+ curgid = gidlist[i];
64769+ if (globalreal == curgid)
64770+ realok = 1;
64771+ if (globaleffective == curgid)
64772+ effectiveok = 1;
64773+ if (globalfs == curgid)
64774+ fsok = 1;
64775+ }
64776+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
64777+ for (i = 0; i < num; i++) {
64778+ curgid = gidlist[i];
64779+ if (globalreal == curgid)
64780+ break;
64781+ if (globaleffective == curgid)
64782+ break;
64783+ if (globalfs == curgid)
64784+ break;
64785+ }
64786+ /* not in deny list */
64787+ if (i == num) {
64788+ realok = 1;
64789+ effectiveok = 1;
64790+ fsok = 1;
64791+ }
64792+ }
64793+
64794+ if (realok && effectiveok && fsok)
64795+ return 0;
64796+ else {
64797+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64798+ return 1;
64799+ }
64800+}
64801+
64802+extern int gr_acl_is_capable(const int cap);
64803+
64804+void
64805+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
64806+{
64807+ struct acl_role_label *role = task->role;
64808+ struct acl_subject_label *subj = NULL;
64809+ struct acl_object_label *obj;
64810+ struct file *filp;
64811+ uid_t uid;
64812+ gid_t gid;
64813+
64814+ if (unlikely(!(gr_status & GR_READY)))
64815+ return;
64816+
64817+ uid = GR_GLOBAL_UID(kuid);
64818+ gid = GR_GLOBAL_GID(kgid);
64819+
64820+ filp = task->exec_file;
64821+
64822+ /* kernel process, we'll give them the kernel role */
64823+ if (unlikely(!filp)) {
64824+ task->role = kernel_role;
64825+ task->acl = kernel_role->root_label;
64826+ return;
64827+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
64828+ role = lookup_acl_role_label(task, uid, gid);
64829+
64830+ /* don't change the role if we're not a privileged process */
64831+ if (role && task->role != role &&
64832+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
64833+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
64834+ return;
64835+
64836+ /* perform subject lookup in possibly new role
64837+ we can use this result below in the case where role == task->role
64838+ */
64839+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
64840+
64841+ /* if we changed uid/gid, but result in the same role
64842+ and are using inheritance, don't lose the inherited subject
64843+ if current subject is other than what normal lookup
64844+ would result in, we arrived via inheritance, don't
64845+ lose subject
64846+ */
64847+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
64848+ (subj == task->acl)))
64849+ task->acl = subj;
64850+
64851+ task->role = role;
64852+
64853+ task->is_writable = 0;
64854+
64855+ /* ignore additional mmap checks for processes that are writable
64856+ by the default ACL */
64857+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
64858+ if (unlikely(obj->mode & GR_WRITE))
64859+ task->is_writable = 1;
64860+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
64861+ if (unlikely(obj->mode & GR_WRITE))
64862+ task->is_writable = 1;
64863+
64864+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64865+ 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);
64866+#endif
64867+
64868+ gr_set_proc_res(task);
64869+
64870+ return;
64871+}
64872+
64873+int
64874+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64875+ const int unsafe_flags)
64876+{
64877+ struct task_struct *task = current;
64878+ struct acl_subject_label *newacl;
64879+ struct acl_object_label *obj;
64880+ __u32 retmode;
64881+
64882+ if (unlikely(!(gr_status & GR_READY)))
64883+ return 0;
64884+
64885+ newacl = chk_subj_label(dentry, mnt, task->role);
64886+
64887+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
64888+ did an exec
64889+ */
64890+ rcu_read_lock();
64891+ read_lock(&tasklist_lock);
64892+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
64893+ (task->parent->acl->mode & GR_POVERRIDE))) {
64894+ read_unlock(&tasklist_lock);
64895+ rcu_read_unlock();
64896+ goto skip_check;
64897+ }
64898+ read_unlock(&tasklist_lock);
64899+ rcu_read_unlock();
64900+
64901+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
64902+ !(task->role->roletype & GR_ROLE_GOD) &&
64903+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
64904+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64905+ if (unsafe_flags & LSM_UNSAFE_SHARE)
64906+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
64907+ else
64908+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
64909+ return -EACCES;
64910+ }
64911+
64912+skip_check:
64913+
64914+ obj = chk_obj_label(dentry, mnt, task->acl);
64915+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
64916+
64917+ if (!(task->acl->mode & GR_INHERITLEARN) &&
64918+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
64919+ if (obj->nested)
64920+ task->acl = obj->nested;
64921+ else
64922+ task->acl = newacl;
64923+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
64924+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
64925+
64926+ task->is_writable = 0;
64927+
64928+ /* ignore additional mmap checks for processes that are writable
64929+ by the default ACL */
64930+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
64931+ if (unlikely(obj->mode & GR_WRITE))
64932+ task->is_writable = 1;
64933+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
64934+ if (unlikely(obj->mode & GR_WRITE))
64935+ task->is_writable = 1;
64936+
64937+ gr_set_proc_res(task);
64938+
64939+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64940+ 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);
64941+#endif
64942+ return 0;
64943+}
64944+
64945+/* always called with valid inodev ptr */
64946+static void
64947+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
64948+{
64949+ struct acl_object_label *matchpo;
64950+ struct acl_subject_label *matchps;
64951+ struct acl_subject_label *subj;
64952+ struct acl_role_label *role;
64953+ unsigned int x;
64954+
64955+ FOR_EACH_ROLE_START(role)
64956+ FOR_EACH_SUBJECT_START(role, subj, x)
64957+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64958+ matchpo->mode |= GR_DELETED;
64959+ FOR_EACH_SUBJECT_END(subj,x)
64960+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
64961+ /* nested subjects aren't in the role's subj_hash table */
64962+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64963+ matchpo->mode |= GR_DELETED;
64964+ FOR_EACH_NESTED_SUBJECT_END(subj)
64965+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
64966+ matchps->mode |= GR_DELETED;
64967+ FOR_EACH_ROLE_END(role)
64968+
64969+ inodev->nentry->deleted = 1;
64970+
64971+ return;
64972+}
64973+
64974+void
64975+gr_handle_delete(const ino_t ino, const dev_t dev)
64976+{
64977+ struct inodev_entry *inodev;
64978+
64979+ if (unlikely(!(gr_status & GR_READY)))
64980+ return;
64981+
64982+ write_lock(&gr_inode_lock);
64983+ inodev = lookup_inodev_entry(ino, dev);
64984+ if (inodev != NULL)
64985+ do_handle_delete(inodev, ino, dev);
64986+ write_unlock(&gr_inode_lock);
64987+
64988+ return;
64989+}
64990+
64991+static void
64992+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
64993+ const ino_t newinode, const dev_t newdevice,
64994+ struct acl_subject_label *subj)
64995+{
64996+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
64997+ struct acl_object_label *match;
64998+
64999+ match = subj->obj_hash[index];
65000+
65001+ while (match && (match->inode != oldinode ||
65002+ match->device != olddevice ||
65003+ !(match->mode & GR_DELETED)))
65004+ match = match->next;
65005+
65006+ if (match && (match->inode == oldinode)
65007+ && (match->device == olddevice)
65008+ && (match->mode & GR_DELETED)) {
65009+ if (match->prev == NULL) {
65010+ subj->obj_hash[index] = match->next;
65011+ if (match->next != NULL)
65012+ match->next->prev = NULL;
65013+ } else {
65014+ match->prev->next = match->next;
65015+ if (match->next != NULL)
65016+ match->next->prev = match->prev;
65017+ }
65018+ match->prev = NULL;
65019+ match->next = NULL;
65020+ match->inode = newinode;
65021+ match->device = newdevice;
65022+ match->mode &= ~GR_DELETED;
65023+
65024+ insert_acl_obj_label(match, subj);
65025+ }
65026+
65027+ return;
65028+}
65029+
65030+static void
65031+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
65032+ const ino_t newinode, const dev_t newdevice,
65033+ struct acl_role_label *role)
65034+{
65035+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
65036+ struct acl_subject_label *match;
65037+
65038+ match = role->subj_hash[index];
65039+
65040+ while (match && (match->inode != oldinode ||
65041+ match->device != olddevice ||
65042+ !(match->mode & GR_DELETED)))
65043+ match = match->next;
65044+
65045+ if (match && (match->inode == oldinode)
65046+ && (match->device == olddevice)
65047+ && (match->mode & GR_DELETED)) {
65048+ if (match->prev == NULL) {
65049+ role->subj_hash[index] = match->next;
65050+ if (match->next != NULL)
65051+ match->next->prev = NULL;
65052+ } else {
65053+ match->prev->next = match->next;
65054+ if (match->next != NULL)
65055+ match->next->prev = match->prev;
65056+ }
65057+ match->prev = NULL;
65058+ match->next = NULL;
65059+ match->inode = newinode;
65060+ match->device = newdevice;
65061+ match->mode &= ~GR_DELETED;
65062+
65063+ insert_acl_subj_label(match, role);
65064+ }
65065+
65066+ return;
65067+}
65068+
65069+static void
65070+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
65071+ const ino_t newinode, const dev_t newdevice)
65072+{
65073+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
65074+ struct inodev_entry *match;
65075+
65076+ match = inodev_set.i_hash[index];
65077+
65078+ while (match && (match->nentry->inode != oldinode ||
65079+ match->nentry->device != olddevice || !match->nentry->deleted))
65080+ match = match->next;
65081+
65082+ if (match && (match->nentry->inode == oldinode)
65083+ && (match->nentry->device == olddevice) &&
65084+ match->nentry->deleted) {
65085+ if (match->prev == NULL) {
65086+ inodev_set.i_hash[index] = match->next;
65087+ if (match->next != NULL)
65088+ match->next->prev = NULL;
65089+ } else {
65090+ match->prev->next = match->next;
65091+ if (match->next != NULL)
65092+ match->next->prev = match->prev;
65093+ }
65094+ match->prev = NULL;
65095+ match->next = NULL;
65096+ match->nentry->inode = newinode;
65097+ match->nentry->device = newdevice;
65098+ match->nentry->deleted = 0;
65099+
65100+ insert_inodev_entry(match);
65101+ }
65102+
65103+ return;
65104+}
65105+
65106+static void
65107+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
65108+{
65109+ struct acl_subject_label *subj;
65110+ struct acl_role_label *role;
65111+ unsigned int x;
65112+
65113+ FOR_EACH_ROLE_START(role)
65114+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
65115+
65116+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
65117+ if ((subj->inode == ino) && (subj->device == dev)) {
65118+ subj->inode = ino;
65119+ subj->device = dev;
65120+ }
65121+ /* nested subjects aren't in the role's subj_hash table */
65122+ update_acl_obj_label(matchn->inode, matchn->device,
65123+ ino, dev, subj);
65124+ FOR_EACH_NESTED_SUBJECT_END(subj)
65125+ FOR_EACH_SUBJECT_START(role, subj, x)
65126+ update_acl_obj_label(matchn->inode, matchn->device,
65127+ ino, dev, subj);
65128+ FOR_EACH_SUBJECT_END(subj,x)
65129+ FOR_EACH_ROLE_END(role)
65130+
65131+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
65132+
65133+ return;
65134+}
65135+
65136+static void
65137+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
65138+ const struct vfsmount *mnt)
65139+{
65140+ ino_t ino = dentry->d_inode->i_ino;
65141+ dev_t dev = __get_dev(dentry);
65142+
65143+ __do_handle_create(matchn, ino, dev);
65144+
65145+ return;
65146+}
65147+
65148+void
65149+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
65150+{
65151+ struct name_entry *matchn;
65152+
65153+ if (unlikely(!(gr_status & GR_READY)))
65154+ return;
65155+
65156+ preempt_disable();
65157+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
65158+
65159+ if (unlikely((unsigned long)matchn)) {
65160+ write_lock(&gr_inode_lock);
65161+ do_handle_create(matchn, dentry, mnt);
65162+ write_unlock(&gr_inode_lock);
65163+ }
65164+ preempt_enable();
65165+
65166+ return;
65167+}
65168+
65169+void
65170+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
65171+{
65172+ struct name_entry *matchn;
65173+
65174+ if (unlikely(!(gr_status & GR_READY)))
65175+ return;
65176+
65177+ preempt_disable();
65178+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
65179+
65180+ if (unlikely((unsigned long)matchn)) {
65181+ write_lock(&gr_inode_lock);
65182+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
65183+ write_unlock(&gr_inode_lock);
65184+ }
65185+ preempt_enable();
65186+
65187+ return;
65188+}
65189+
65190+void
65191+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
65192+ struct dentry *old_dentry,
65193+ struct dentry *new_dentry,
65194+ struct vfsmount *mnt, const __u8 replace)
65195+{
65196+ struct name_entry *matchn;
65197+ struct inodev_entry *inodev;
65198+ struct inode *inode = new_dentry->d_inode;
65199+ ino_t old_ino = old_dentry->d_inode->i_ino;
65200+ dev_t old_dev = __get_dev(old_dentry);
65201+
65202+ /* vfs_rename swaps the name and parent link for old_dentry and
65203+ new_dentry
65204+ at this point, old_dentry has the new name, parent link, and inode
65205+ for the renamed file
65206+ if a file is being replaced by a rename, new_dentry has the inode
65207+ and name for the replaced file
65208+ */
65209+
65210+ if (unlikely(!(gr_status & GR_READY)))
65211+ return;
65212+
65213+ preempt_disable();
65214+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
65215+
65216+ /* we wouldn't have to check d_inode if it weren't for
65217+ NFS silly-renaming
65218+ */
65219+
65220+ write_lock(&gr_inode_lock);
65221+ if (unlikely(replace && inode)) {
65222+ ino_t new_ino = inode->i_ino;
65223+ dev_t new_dev = __get_dev(new_dentry);
65224+
65225+ inodev = lookup_inodev_entry(new_ino, new_dev);
65226+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
65227+ do_handle_delete(inodev, new_ino, new_dev);
65228+ }
65229+
65230+ inodev = lookup_inodev_entry(old_ino, old_dev);
65231+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
65232+ do_handle_delete(inodev, old_ino, old_dev);
65233+
65234+ if (unlikely((unsigned long)matchn))
65235+ do_handle_create(matchn, old_dentry, mnt);
65236+
65237+ write_unlock(&gr_inode_lock);
65238+ preempt_enable();
65239+
65240+ return;
65241+}
65242+
65243+static int
65244+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
65245+ unsigned char **sum)
65246+{
65247+ struct acl_role_label *r;
65248+ struct role_allowed_ip *ipp;
65249+ struct role_transition *trans;
65250+ unsigned int i;
65251+ int found = 0;
65252+ u32 curr_ip = current->signal->curr_ip;
65253+
65254+ current->signal->saved_ip = curr_ip;
65255+
65256+ /* check transition table */
65257+
65258+ for (trans = current->role->transitions; trans; trans = trans->next) {
65259+ if (!strcmp(rolename, trans->rolename)) {
65260+ found = 1;
65261+ break;
65262+ }
65263+ }
65264+
65265+ if (!found)
65266+ return 0;
65267+
65268+ /* handle special roles that do not require authentication
65269+ and check ip */
65270+
65271+ FOR_EACH_ROLE_START(r)
65272+ if (!strcmp(rolename, r->rolename) &&
65273+ (r->roletype & GR_ROLE_SPECIAL)) {
65274+ found = 0;
65275+ if (r->allowed_ips != NULL) {
65276+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
65277+ if ((ntohl(curr_ip) & ipp->netmask) ==
65278+ (ntohl(ipp->addr) & ipp->netmask))
65279+ found = 1;
65280+ }
65281+ } else
65282+ found = 2;
65283+ if (!found)
65284+ return 0;
65285+
65286+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
65287+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
65288+ *salt = NULL;
65289+ *sum = NULL;
65290+ return 1;
65291+ }
65292+ }
65293+ FOR_EACH_ROLE_END(r)
65294+
65295+ for (i = 0; i < num_sprole_pws; i++) {
65296+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
65297+ *salt = acl_special_roles[i]->salt;
65298+ *sum = acl_special_roles[i]->sum;
65299+ return 1;
65300+ }
65301+ }
65302+
65303+ return 0;
65304+}
65305+
65306+static void
65307+assign_special_role(char *rolename)
65308+{
65309+ struct acl_object_label *obj;
65310+ struct acl_role_label *r;
65311+ struct acl_role_label *assigned = NULL;
65312+ struct task_struct *tsk;
65313+ struct file *filp;
65314+
65315+ FOR_EACH_ROLE_START(r)
65316+ if (!strcmp(rolename, r->rolename) &&
65317+ (r->roletype & GR_ROLE_SPECIAL)) {
65318+ assigned = r;
65319+ break;
65320+ }
65321+ FOR_EACH_ROLE_END(r)
65322+
65323+ if (!assigned)
65324+ return;
65325+
65326+ read_lock(&tasklist_lock);
65327+ read_lock(&grsec_exec_file_lock);
65328+
65329+ tsk = current->real_parent;
65330+ if (tsk == NULL)
65331+ goto out_unlock;
65332+
65333+ filp = tsk->exec_file;
65334+ if (filp == NULL)
65335+ goto out_unlock;
65336+
65337+ tsk->is_writable = 0;
65338+
65339+ tsk->acl_sp_role = 1;
65340+ tsk->acl_role_id = ++acl_sp_role_value;
65341+ tsk->role = assigned;
65342+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
65343+
65344+ /* ignore additional mmap checks for processes that are writable
65345+ by the default ACL */
65346+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65347+ if (unlikely(obj->mode & GR_WRITE))
65348+ tsk->is_writable = 1;
65349+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
65350+ if (unlikely(obj->mode & GR_WRITE))
65351+ tsk->is_writable = 1;
65352+
65353+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65354+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
65355+#endif
65356+
65357+out_unlock:
65358+ read_unlock(&grsec_exec_file_lock);
65359+ read_unlock(&tasklist_lock);
65360+ return;
65361+}
65362+
65363+int gr_check_secure_terminal(struct task_struct *task)
65364+{
65365+ struct task_struct *p, *p2, *p3;
65366+ struct files_struct *files;
65367+ struct fdtable *fdt;
65368+ struct file *our_file = NULL, *file;
65369+ int i;
65370+
65371+ if (task->signal->tty == NULL)
65372+ return 1;
65373+
65374+ files = get_files_struct(task);
65375+ if (files != NULL) {
65376+ rcu_read_lock();
65377+ fdt = files_fdtable(files);
65378+ for (i=0; i < fdt->max_fds; i++) {
65379+ file = fcheck_files(files, i);
65380+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
65381+ get_file(file);
65382+ our_file = file;
65383+ }
65384+ }
65385+ rcu_read_unlock();
65386+ put_files_struct(files);
65387+ }
65388+
65389+ if (our_file == NULL)
65390+ return 1;
65391+
65392+ read_lock(&tasklist_lock);
65393+ do_each_thread(p2, p) {
65394+ files = get_files_struct(p);
65395+ if (files == NULL ||
65396+ (p->signal && p->signal->tty == task->signal->tty)) {
65397+ if (files != NULL)
65398+ put_files_struct(files);
65399+ continue;
65400+ }
65401+ rcu_read_lock();
65402+ fdt = files_fdtable(files);
65403+ for (i=0; i < fdt->max_fds; i++) {
65404+ file = fcheck_files(files, i);
65405+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
65406+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
65407+ p3 = task;
65408+ while (task_pid_nr(p3) > 0) {
65409+ if (p3 == p)
65410+ break;
65411+ p3 = p3->real_parent;
65412+ }
65413+ if (p3 == p)
65414+ break;
65415+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
65416+ gr_handle_alertkill(p);
65417+ rcu_read_unlock();
65418+ put_files_struct(files);
65419+ read_unlock(&tasklist_lock);
65420+ fput(our_file);
65421+ return 0;
65422+ }
65423+ }
65424+ rcu_read_unlock();
65425+ put_files_struct(files);
65426+ } while_each_thread(p2, p);
65427+ read_unlock(&tasklist_lock);
65428+
65429+ fput(our_file);
65430+ return 1;
65431+}
65432+
65433+static int gr_rbac_disable(void *unused)
65434+{
65435+ pax_open_kernel();
65436+ gr_status &= ~GR_READY;
65437+ pax_close_kernel();
65438+
65439+ return 0;
65440+}
65441+
65442+ssize_t
65443+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
65444+{
65445+ struct gr_arg_wrapper uwrap;
65446+ unsigned char *sprole_salt = NULL;
65447+ unsigned char *sprole_sum = NULL;
65448+ int error = 0;
65449+ int error2 = 0;
65450+ size_t req_count = 0;
65451+
65452+ mutex_lock(&gr_dev_mutex);
65453+
65454+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
65455+ error = -EPERM;
65456+ goto out;
65457+ }
65458+
65459+#ifdef CONFIG_COMPAT
65460+ pax_open_kernel();
65461+ if (is_compat_task()) {
65462+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
65463+ copy_gr_arg = &copy_gr_arg_compat;
65464+ copy_acl_object_label = &copy_acl_object_label_compat;
65465+ copy_acl_subject_label = &copy_acl_subject_label_compat;
65466+ copy_acl_role_label = &copy_acl_role_label_compat;
65467+ copy_acl_ip_label = &copy_acl_ip_label_compat;
65468+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
65469+ copy_role_transition = &copy_role_transition_compat;
65470+ copy_sprole_pw = &copy_sprole_pw_compat;
65471+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
65472+ copy_pointer_from_array = &copy_pointer_from_array_compat;
65473+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
65474+ } else {
65475+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
65476+ copy_gr_arg = &copy_gr_arg_normal;
65477+ copy_acl_object_label = &copy_acl_object_label_normal;
65478+ copy_acl_subject_label = &copy_acl_subject_label_normal;
65479+ copy_acl_role_label = &copy_acl_role_label_normal;
65480+ copy_acl_ip_label = &copy_acl_ip_label_normal;
65481+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
65482+ copy_role_transition = &copy_role_transition_normal;
65483+ copy_sprole_pw = &copy_sprole_pw_normal;
65484+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
65485+ copy_pointer_from_array = &copy_pointer_from_array_normal;
65486+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
65487+ }
65488+ pax_close_kernel();
65489+#endif
65490+
65491+ req_count = get_gr_arg_wrapper_size();
65492+
65493+ if (count != req_count) {
65494+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
65495+ error = -EINVAL;
65496+ goto out;
65497+ }
65498+
65499+
65500+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
65501+ gr_auth_expires = 0;
65502+ gr_auth_attempts = 0;
65503+ }
65504+
65505+ error = copy_gr_arg_wrapper(buf, &uwrap);
65506+ if (error)
65507+ goto out;
65508+
65509+ error = copy_gr_arg(uwrap.arg, gr_usermode);
65510+ if (error)
65511+ goto out;
65512+
65513+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65514+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65515+ time_after(gr_auth_expires, get_seconds())) {
65516+ error = -EBUSY;
65517+ goto out;
65518+ }
65519+
65520+ /* if non-root trying to do anything other than use a special role,
65521+ do not attempt authentication, do not count towards authentication
65522+ locking
65523+ */
65524+
65525+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
65526+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65527+ gr_is_global_nonroot(current_uid())) {
65528+ error = -EPERM;
65529+ goto out;
65530+ }
65531+
65532+ /* ensure pw and special role name are null terminated */
65533+
65534+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
65535+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
65536+
65537+ /* Okay.
65538+ * We have our enough of the argument structure..(we have yet
65539+ * to copy_from_user the tables themselves) . Copy the tables
65540+ * only if we need them, i.e. for loading operations. */
65541+
65542+ switch (gr_usermode->mode) {
65543+ case GR_STATUS:
65544+ if (gr_status & GR_READY) {
65545+ error = 1;
65546+ if (!gr_check_secure_terminal(current))
65547+ error = 3;
65548+ } else
65549+ error = 2;
65550+ goto out;
65551+ case GR_SHUTDOWN:
65552+ if ((gr_status & GR_READY)
65553+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65554+ stop_machine(gr_rbac_disable, NULL, NULL);
65555+ free_variables();
65556+ memset(gr_usermode, 0, sizeof (struct gr_arg));
65557+ memset(gr_system_salt, 0, GR_SALT_LEN);
65558+ memset(gr_system_sum, 0, GR_SHA_LEN);
65559+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
65560+ } else if (gr_status & GR_READY) {
65561+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
65562+ error = -EPERM;
65563+ } else {
65564+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
65565+ error = -EAGAIN;
65566+ }
65567+ break;
65568+ case GR_ENABLE:
65569+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
65570+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
65571+ else {
65572+ if (gr_status & GR_READY)
65573+ error = -EAGAIN;
65574+ else
65575+ error = error2;
65576+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
65577+ }
65578+ break;
65579+ case GR_RELOAD:
65580+ if (!(gr_status & GR_READY)) {
65581+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
65582+ error = -EAGAIN;
65583+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65584+ stop_machine(gr_rbac_disable, NULL, NULL);
65585+ free_variables();
65586+ error2 = gracl_init(gr_usermode);
65587+ if (!error2)
65588+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
65589+ else {
65590+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65591+ error = error2;
65592+ }
65593+ } else {
65594+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65595+ error = -EPERM;
65596+ }
65597+ break;
65598+ case GR_SEGVMOD:
65599+ if (unlikely(!(gr_status & GR_READY))) {
65600+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
65601+ error = -EAGAIN;
65602+ break;
65603+ }
65604+
65605+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65606+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
65607+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
65608+ struct acl_subject_label *segvacl;
65609+ segvacl =
65610+ lookup_acl_subj_label(gr_usermode->segv_inode,
65611+ gr_usermode->segv_device,
65612+ current->role);
65613+ if (segvacl) {
65614+ segvacl->crashes = 0;
65615+ segvacl->expires = 0;
65616+ }
65617+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
65618+ gr_remove_uid(gr_usermode->segv_uid);
65619+ }
65620+ } else {
65621+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
65622+ error = -EPERM;
65623+ }
65624+ break;
65625+ case GR_SPROLE:
65626+ case GR_SPROLEPAM:
65627+ if (unlikely(!(gr_status & GR_READY))) {
65628+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
65629+ error = -EAGAIN;
65630+ break;
65631+ }
65632+
65633+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
65634+ current->role->expires = 0;
65635+ current->role->auth_attempts = 0;
65636+ }
65637+
65638+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65639+ time_after(current->role->expires, get_seconds())) {
65640+ error = -EBUSY;
65641+ goto out;
65642+ }
65643+
65644+ if (lookup_special_role_auth
65645+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
65646+ && ((!sprole_salt && !sprole_sum)
65647+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
65648+ char *p = "";
65649+ assign_special_role(gr_usermode->sp_role);
65650+ read_lock(&tasklist_lock);
65651+ if (current->real_parent)
65652+ p = current->real_parent->role->rolename;
65653+ read_unlock(&tasklist_lock);
65654+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
65655+ p, acl_sp_role_value);
65656+ } else {
65657+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
65658+ error = -EPERM;
65659+ if(!(current->role->auth_attempts++))
65660+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65661+
65662+ goto out;
65663+ }
65664+ break;
65665+ case GR_UNSPROLE:
65666+ if (unlikely(!(gr_status & GR_READY))) {
65667+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
65668+ error = -EAGAIN;
65669+ break;
65670+ }
65671+
65672+ if (current->role->roletype & GR_ROLE_SPECIAL) {
65673+ char *p = "";
65674+ int i = 0;
65675+
65676+ read_lock(&tasklist_lock);
65677+ if (current->real_parent) {
65678+ p = current->real_parent->role->rolename;
65679+ i = current->real_parent->acl_role_id;
65680+ }
65681+ read_unlock(&tasklist_lock);
65682+
65683+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
65684+ gr_set_acls(1);
65685+ } else {
65686+ error = -EPERM;
65687+ goto out;
65688+ }
65689+ break;
65690+ default:
65691+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
65692+ error = -EINVAL;
65693+ break;
65694+ }
65695+
65696+ if (error != -EPERM)
65697+ goto out;
65698+
65699+ if(!(gr_auth_attempts++))
65700+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65701+
65702+ out:
65703+ mutex_unlock(&gr_dev_mutex);
65704+
65705+ if (!error)
65706+ error = req_count;
65707+
65708+ return error;
65709+}
65710+
65711+/* must be called with
65712+ rcu_read_lock();
65713+ read_lock(&tasklist_lock);
65714+ read_lock(&grsec_exec_file_lock);
65715+*/
65716+int gr_apply_subject_to_task(struct task_struct *task)
65717+{
65718+ struct acl_object_label *obj;
65719+ char *tmpname;
65720+ struct acl_subject_label *tmpsubj;
65721+ struct file *filp;
65722+ struct name_entry *nmatch;
65723+
65724+ filp = task->exec_file;
65725+ if (filp == NULL)
65726+ return 0;
65727+
65728+ /* the following is to apply the correct subject
65729+ on binaries running when the RBAC system
65730+ is enabled, when the binaries have been
65731+ replaced or deleted since their execution
65732+ -----
65733+ when the RBAC system starts, the inode/dev
65734+ from exec_file will be one the RBAC system
65735+ is unaware of. It only knows the inode/dev
65736+ of the present file on disk, or the absence
65737+ of it.
65738+ */
65739+ preempt_disable();
65740+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
65741+
65742+ nmatch = lookup_name_entry(tmpname);
65743+ preempt_enable();
65744+ tmpsubj = NULL;
65745+ if (nmatch) {
65746+ if (nmatch->deleted)
65747+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
65748+ else
65749+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
65750+ if (tmpsubj != NULL)
65751+ task->acl = tmpsubj;
65752+ }
65753+ if (tmpsubj == NULL)
65754+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
65755+ task->role);
65756+ if (task->acl) {
65757+ task->is_writable = 0;
65758+ /* ignore additional mmap checks for processes that are writable
65759+ by the default ACL */
65760+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65761+ if (unlikely(obj->mode & GR_WRITE))
65762+ task->is_writable = 1;
65763+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
65764+ if (unlikely(obj->mode & GR_WRITE))
65765+ task->is_writable = 1;
65766+
65767+ gr_set_proc_res(task);
65768+
65769+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65770+ 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);
65771+#endif
65772+ } else {
65773+ return 1;
65774+ }
65775+
65776+ return 0;
65777+}
65778+
65779+int
65780+gr_set_acls(const int type)
65781+{
65782+ struct task_struct *task, *task2;
65783+ struct acl_role_label *role = current->role;
65784+ __u16 acl_role_id = current->acl_role_id;
65785+ const struct cred *cred;
65786+ int ret;
65787+
65788+ rcu_read_lock();
65789+ read_lock(&tasklist_lock);
65790+ read_lock(&grsec_exec_file_lock);
65791+ do_each_thread(task2, task) {
65792+ /* check to see if we're called from the exit handler,
65793+ if so, only replace ACLs that have inherited the admin
65794+ ACL */
65795+
65796+ if (type && (task->role != role ||
65797+ task->acl_role_id != acl_role_id))
65798+ continue;
65799+
65800+ task->acl_role_id = 0;
65801+ task->acl_sp_role = 0;
65802+
65803+ if (task->exec_file) {
65804+ cred = __task_cred(task);
65805+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
65806+ ret = gr_apply_subject_to_task(task);
65807+ if (ret) {
65808+ read_unlock(&grsec_exec_file_lock);
65809+ read_unlock(&tasklist_lock);
65810+ rcu_read_unlock();
65811+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
65812+ return ret;
65813+ }
65814+ } else {
65815+ // it's a kernel process
65816+ task->role = kernel_role;
65817+ task->acl = kernel_role->root_label;
65818+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
65819+ task->acl->mode &= ~GR_PROCFIND;
65820+#endif
65821+ }
65822+ } while_each_thread(task2, task);
65823+ read_unlock(&grsec_exec_file_lock);
65824+ read_unlock(&tasklist_lock);
65825+ rcu_read_unlock();
65826+
65827+ return 0;
65828+}
65829+
65830+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
65831+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
65832+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
65833+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
65834+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
65835+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
65836+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
65837+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
65838+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
65839+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
65840+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
65841+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
65842+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
65843+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
65844+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
65845+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
65846+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
65847+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
65848+};
65849+
65850+void
65851+gr_learn_resource(const struct task_struct *task,
65852+ const int res, const unsigned long wanted, const int gt)
65853+{
65854+ struct acl_subject_label *acl;
65855+ const struct cred *cred;
65856+
65857+ if (unlikely((gr_status & GR_READY) &&
65858+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
65859+ goto skip_reslog;
65860+
65861+ gr_log_resource(task, res, wanted, gt);
65862+skip_reslog:
65863+
65864+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
65865+ return;
65866+
65867+ acl = task->acl;
65868+
65869+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
65870+ !(acl->resmask & (1U << (unsigned short) res))))
65871+ return;
65872+
65873+ if (wanted >= acl->res[res].rlim_cur) {
65874+ unsigned long res_add;
65875+
65876+ res_add = wanted + res_learn_bumps[res];
65877+
65878+ acl->res[res].rlim_cur = res_add;
65879+
65880+ if (wanted > acl->res[res].rlim_max)
65881+ acl->res[res].rlim_max = res_add;
65882+
65883+ /* only log the subject filename, since resource logging is supported for
65884+ single-subject learning only */
65885+ rcu_read_lock();
65886+ cred = __task_cred(task);
65887+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
65888+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
65889+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
65890+ "", (unsigned long) res, &task->signal->saved_ip);
65891+ rcu_read_unlock();
65892+ }
65893+
65894+ return;
65895+}
65896+EXPORT_SYMBOL(gr_learn_resource);
65897+#endif
65898+
65899+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
65900+void
65901+pax_set_initial_flags(struct linux_binprm *bprm)
65902+{
65903+ struct task_struct *task = current;
65904+ struct acl_subject_label *proc;
65905+ unsigned long flags;
65906+
65907+ if (unlikely(!(gr_status & GR_READY)))
65908+ return;
65909+
65910+ flags = pax_get_flags(task);
65911+
65912+ proc = task->acl;
65913+
65914+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
65915+ flags &= ~MF_PAX_PAGEEXEC;
65916+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
65917+ flags &= ~MF_PAX_SEGMEXEC;
65918+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
65919+ flags &= ~MF_PAX_RANDMMAP;
65920+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
65921+ flags &= ~MF_PAX_EMUTRAMP;
65922+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
65923+ flags &= ~MF_PAX_MPROTECT;
65924+
65925+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
65926+ flags |= MF_PAX_PAGEEXEC;
65927+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
65928+ flags |= MF_PAX_SEGMEXEC;
65929+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
65930+ flags |= MF_PAX_RANDMMAP;
65931+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
65932+ flags |= MF_PAX_EMUTRAMP;
65933+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
65934+ flags |= MF_PAX_MPROTECT;
65935+
65936+ pax_set_flags(task, flags);
65937+
65938+ return;
65939+}
65940+#endif
65941+
65942+int
65943+gr_handle_proc_ptrace(struct task_struct *task)
65944+{
65945+ struct file *filp;
65946+ struct task_struct *tmp = task;
65947+ struct task_struct *curtemp = current;
65948+ __u32 retmode;
65949+
65950+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65951+ if (unlikely(!(gr_status & GR_READY)))
65952+ return 0;
65953+#endif
65954+
65955+ read_lock(&tasklist_lock);
65956+ read_lock(&grsec_exec_file_lock);
65957+ filp = task->exec_file;
65958+
65959+ while (task_pid_nr(tmp) > 0) {
65960+ if (tmp == curtemp)
65961+ break;
65962+ tmp = tmp->real_parent;
65963+ }
65964+
65965+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65966+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
65967+ read_unlock(&grsec_exec_file_lock);
65968+ read_unlock(&tasklist_lock);
65969+ return 1;
65970+ }
65971+
65972+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65973+ if (!(gr_status & GR_READY)) {
65974+ read_unlock(&grsec_exec_file_lock);
65975+ read_unlock(&tasklist_lock);
65976+ return 0;
65977+ }
65978+#endif
65979+
65980+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
65981+ read_unlock(&grsec_exec_file_lock);
65982+ read_unlock(&tasklist_lock);
65983+
65984+ if (retmode & GR_NOPTRACE)
65985+ return 1;
65986+
65987+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
65988+ && (current->acl != task->acl || (current->acl != current->role->root_label
65989+ && task_pid_nr(current) != task_pid_nr(task))))
65990+ return 1;
65991+
65992+ return 0;
65993+}
65994+
65995+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
65996+{
65997+ if (unlikely(!(gr_status & GR_READY)))
65998+ return;
65999+
66000+ if (!(current->role->roletype & GR_ROLE_GOD))
66001+ return;
66002+
66003+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
66004+ p->role->rolename, gr_task_roletype_to_char(p),
66005+ p->acl->filename);
66006+}
66007+
66008+int
66009+gr_handle_ptrace(struct task_struct *task, const long request)
66010+{
66011+ struct task_struct *tmp = task;
66012+ struct task_struct *curtemp = current;
66013+ __u32 retmode;
66014+
66015+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
66016+ if (unlikely(!(gr_status & GR_READY)))
66017+ return 0;
66018+#endif
66019+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
66020+ read_lock(&tasklist_lock);
66021+ while (task_pid_nr(tmp) > 0) {
66022+ if (tmp == curtemp)
66023+ break;
66024+ tmp = tmp->real_parent;
66025+ }
66026+
66027+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
66028+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
66029+ read_unlock(&tasklist_lock);
66030+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
66031+ return 1;
66032+ }
66033+ read_unlock(&tasklist_lock);
66034+ }
66035+
66036+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
66037+ if (!(gr_status & GR_READY))
66038+ return 0;
66039+#endif
66040+
66041+ read_lock(&grsec_exec_file_lock);
66042+ if (unlikely(!task->exec_file)) {
66043+ read_unlock(&grsec_exec_file_lock);
66044+ return 0;
66045+ }
66046+
66047+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
66048+ read_unlock(&grsec_exec_file_lock);
66049+
66050+ if (retmode & GR_NOPTRACE) {
66051+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
66052+ return 1;
66053+ }
66054+
66055+ if (retmode & GR_PTRACERD) {
66056+ switch (request) {
66057+ case PTRACE_SEIZE:
66058+ case PTRACE_POKETEXT:
66059+ case PTRACE_POKEDATA:
66060+ case PTRACE_POKEUSR:
66061+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
66062+ case PTRACE_SETREGS:
66063+ case PTRACE_SETFPREGS:
66064+#endif
66065+#ifdef CONFIG_X86
66066+ case PTRACE_SETFPXREGS:
66067+#endif
66068+#ifdef CONFIG_ALTIVEC
66069+ case PTRACE_SETVRREGS:
66070+#endif
66071+ return 1;
66072+ default:
66073+ return 0;
66074+ }
66075+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
66076+ !(current->role->roletype & GR_ROLE_GOD) &&
66077+ (current->acl != task->acl)) {
66078+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
66079+ return 1;
66080+ }
66081+
66082+ return 0;
66083+}
66084+
66085+static int is_writable_mmap(const struct file *filp)
66086+{
66087+ struct task_struct *task = current;
66088+ struct acl_object_label *obj, *obj2;
66089+
66090+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
66091+ !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))) {
66092+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
66093+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
66094+ task->role->root_label);
66095+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
66096+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
66097+ return 1;
66098+ }
66099+ }
66100+ return 0;
66101+}
66102+
66103+int
66104+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
66105+{
66106+ __u32 mode;
66107+
66108+ if (unlikely(!file || !(prot & PROT_EXEC)))
66109+ return 1;
66110+
66111+ if (is_writable_mmap(file))
66112+ return 0;
66113+
66114+ mode =
66115+ gr_search_file(file->f_path.dentry,
66116+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66117+ file->f_path.mnt);
66118+
66119+ if (!gr_tpe_allow(file))
66120+ return 0;
66121+
66122+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66123+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66124+ return 0;
66125+ } else if (unlikely(!(mode & GR_EXEC))) {
66126+ return 0;
66127+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66128+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66129+ return 1;
66130+ }
66131+
66132+ return 1;
66133+}
66134+
66135+int
66136+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
66137+{
66138+ __u32 mode;
66139+
66140+ if (unlikely(!file || !(prot & PROT_EXEC)))
66141+ return 1;
66142+
66143+ if (is_writable_mmap(file))
66144+ return 0;
66145+
66146+ mode =
66147+ gr_search_file(file->f_path.dentry,
66148+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66149+ file->f_path.mnt);
66150+
66151+ if (!gr_tpe_allow(file))
66152+ return 0;
66153+
66154+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66155+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66156+ return 0;
66157+ } else if (unlikely(!(mode & GR_EXEC))) {
66158+ return 0;
66159+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66160+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66161+ return 1;
66162+ }
66163+
66164+ return 1;
66165+}
66166+
66167+void
66168+gr_acl_handle_psacct(struct task_struct *task, const long code)
66169+{
66170+ unsigned long runtime;
66171+ unsigned long cputime;
66172+ unsigned int wday, cday;
66173+ __u8 whr, chr;
66174+ __u8 wmin, cmin;
66175+ __u8 wsec, csec;
66176+ struct timespec timeval;
66177+
66178+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
66179+ !(task->acl->mode & GR_PROCACCT)))
66180+ return;
66181+
66182+ do_posix_clock_monotonic_gettime(&timeval);
66183+ runtime = timeval.tv_sec - task->start_time.tv_sec;
66184+ wday = runtime / (3600 * 24);
66185+ runtime -= wday * (3600 * 24);
66186+ whr = runtime / 3600;
66187+ runtime -= whr * 3600;
66188+ wmin = runtime / 60;
66189+ runtime -= wmin * 60;
66190+ wsec = runtime;
66191+
66192+ cputime = (task->utime + task->stime) / HZ;
66193+ cday = cputime / (3600 * 24);
66194+ cputime -= cday * (3600 * 24);
66195+ chr = cputime / 3600;
66196+ cputime -= chr * 3600;
66197+ cmin = cputime / 60;
66198+ cputime -= cmin * 60;
66199+ csec = cputime;
66200+
66201+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
66202+
66203+ return;
66204+}
66205+
66206+void gr_set_kernel_label(struct task_struct *task)
66207+{
66208+ if (gr_status & GR_READY) {
66209+ task->role = kernel_role;
66210+ task->acl = kernel_role->root_label;
66211+ }
66212+ return;
66213+}
66214+
66215+#ifdef CONFIG_TASKSTATS
66216+int gr_is_taskstats_denied(int pid)
66217+{
66218+ struct task_struct *task;
66219+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66220+ const struct cred *cred;
66221+#endif
66222+ int ret = 0;
66223+
66224+ /* restrict taskstats viewing to un-chrooted root users
66225+ who have the 'view' subject flag if the RBAC system is enabled
66226+ */
66227+
66228+ rcu_read_lock();
66229+ read_lock(&tasklist_lock);
66230+ task = find_task_by_vpid(pid);
66231+ if (task) {
66232+#ifdef CONFIG_GRKERNSEC_CHROOT
66233+ if (proc_is_chrooted(task))
66234+ ret = -EACCES;
66235+#endif
66236+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66237+ cred = __task_cred(task);
66238+#ifdef CONFIG_GRKERNSEC_PROC_USER
66239+ if (gr_is_global_nonroot(cred->uid))
66240+ ret = -EACCES;
66241+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66242+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
66243+ ret = -EACCES;
66244+#endif
66245+#endif
66246+ if (gr_status & GR_READY) {
66247+ if (!(task->acl->mode & GR_VIEW))
66248+ ret = -EACCES;
66249+ }
66250+ } else
66251+ ret = -ENOENT;
66252+
66253+ read_unlock(&tasklist_lock);
66254+ rcu_read_unlock();
66255+
66256+ return ret;
66257+}
66258+#endif
66259+
66260+/* AUXV entries are filled via a descendant of search_binary_handler
66261+ after we've already applied the subject for the target
66262+*/
66263+int gr_acl_enable_at_secure(void)
66264+{
66265+ if (unlikely(!(gr_status & GR_READY)))
66266+ return 0;
66267+
66268+ if (current->acl->mode & GR_ATSECURE)
66269+ return 1;
66270+
66271+ return 0;
66272+}
66273+
66274+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
66275+{
66276+ struct task_struct *task = current;
66277+ struct dentry *dentry = file->f_path.dentry;
66278+ struct vfsmount *mnt = file->f_path.mnt;
66279+ struct acl_object_label *obj, *tmp;
66280+ struct acl_subject_label *subj;
66281+ unsigned int bufsize;
66282+ int is_not_root;
66283+ char *path;
66284+ dev_t dev = __get_dev(dentry);
66285+
66286+ if (unlikely(!(gr_status & GR_READY)))
66287+ return 1;
66288+
66289+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66290+ return 1;
66291+
66292+ /* ignore Eric Biederman */
66293+ if (IS_PRIVATE(dentry->d_inode))
66294+ return 1;
66295+
66296+ subj = task->acl;
66297+ read_lock(&gr_inode_lock);
66298+ do {
66299+ obj = lookup_acl_obj_label(ino, dev, subj);
66300+ if (obj != NULL) {
66301+ read_unlock(&gr_inode_lock);
66302+ return (obj->mode & GR_FIND) ? 1 : 0;
66303+ }
66304+ } while ((subj = subj->parent_subject));
66305+ read_unlock(&gr_inode_lock);
66306+
66307+ /* this is purely an optimization since we're looking for an object
66308+ for the directory we're doing a readdir on
66309+ if it's possible for any globbed object to match the entry we're
66310+ filling into the directory, then the object we find here will be
66311+ an anchor point with attached globbed objects
66312+ */
66313+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
66314+ if (obj->globbed == NULL)
66315+ return (obj->mode & GR_FIND) ? 1 : 0;
66316+
66317+ is_not_root = ((obj->filename[0] == '/') &&
66318+ (obj->filename[1] == '\0')) ? 0 : 1;
66319+ bufsize = PAGE_SIZE - namelen - is_not_root;
66320+
66321+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
66322+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
66323+ return 1;
66324+
66325+ preempt_disable();
66326+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66327+ bufsize);
66328+
66329+ bufsize = strlen(path);
66330+
66331+ /* if base is "/", don't append an additional slash */
66332+ if (is_not_root)
66333+ *(path + bufsize) = '/';
66334+ memcpy(path + bufsize + is_not_root, name, namelen);
66335+ *(path + bufsize + namelen + is_not_root) = '\0';
66336+
66337+ tmp = obj->globbed;
66338+ while (tmp) {
66339+ if (!glob_match(tmp->filename, path)) {
66340+ preempt_enable();
66341+ return (tmp->mode & GR_FIND) ? 1 : 0;
66342+ }
66343+ tmp = tmp->next;
66344+ }
66345+ preempt_enable();
66346+ return (obj->mode & GR_FIND) ? 1 : 0;
66347+}
66348+
66349+void gr_put_exec_file(struct task_struct *task)
66350+{
66351+ struct file *filp;
66352+
66353+ write_lock(&grsec_exec_file_lock);
66354+ filp = task->exec_file;
66355+ task->exec_file = NULL;
66356+ write_unlock(&grsec_exec_file_lock);
66357+
66358+ if (filp)
66359+ fput(filp);
66360+
66361+ return;
66362+}
66363+
66364+
66365+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
66366+EXPORT_SYMBOL(gr_acl_is_enabled);
66367+#endif
66368+EXPORT_SYMBOL(gr_set_kernel_label);
66369+#ifdef CONFIG_SECURITY
66370+EXPORT_SYMBOL(gr_check_user_change);
66371+EXPORT_SYMBOL(gr_check_group_change);
66372+#endif
66373+
66374diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
66375new file mode 100644
66376index 0000000..34fefda
66377--- /dev/null
66378+++ b/grsecurity/gracl_alloc.c
66379@@ -0,0 +1,105 @@
66380+#include <linux/kernel.h>
66381+#include <linux/mm.h>
66382+#include <linux/slab.h>
66383+#include <linux/vmalloc.h>
66384+#include <linux/gracl.h>
66385+#include <linux/grsecurity.h>
66386+
66387+static unsigned long alloc_stack_next = 1;
66388+static unsigned long alloc_stack_size = 1;
66389+static void **alloc_stack;
66390+
66391+static __inline__ int
66392+alloc_pop(void)
66393+{
66394+ if (alloc_stack_next == 1)
66395+ return 0;
66396+
66397+ kfree(alloc_stack[alloc_stack_next - 2]);
66398+
66399+ alloc_stack_next--;
66400+
66401+ return 1;
66402+}
66403+
66404+static __inline__ int
66405+alloc_push(void *buf)
66406+{
66407+ if (alloc_stack_next >= alloc_stack_size)
66408+ return 1;
66409+
66410+ alloc_stack[alloc_stack_next - 1] = buf;
66411+
66412+ alloc_stack_next++;
66413+
66414+ return 0;
66415+}
66416+
66417+void *
66418+acl_alloc(unsigned long len)
66419+{
66420+ void *ret = NULL;
66421+
66422+ if (!len || len > PAGE_SIZE)
66423+ goto out;
66424+
66425+ ret = kmalloc(len, GFP_KERNEL);
66426+
66427+ if (ret) {
66428+ if (alloc_push(ret)) {
66429+ kfree(ret);
66430+ ret = NULL;
66431+ }
66432+ }
66433+
66434+out:
66435+ return ret;
66436+}
66437+
66438+void *
66439+acl_alloc_num(unsigned long num, unsigned long len)
66440+{
66441+ if (!len || (num > (PAGE_SIZE / len)))
66442+ return NULL;
66443+
66444+ return acl_alloc(num * len);
66445+}
66446+
66447+void
66448+acl_free_all(void)
66449+{
66450+ if (gr_acl_is_enabled() || !alloc_stack)
66451+ return;
66452+
66453+ while (alloc_pop()) ;
66454+
66455+ if (alloc_stack) {
66456+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
66457+ kfree(alloc_stack);
66458+ else
66459+ vfree(alloc_stack);
66460+ }
66461+
66462+ alloc_stack = NULL;
66463+ alloc_stack_size = 1;
66464+ alloc_stack_next = 1;
66465+
66466+ return;
66467+}
66468+
66469+int
66470+acl_alloc_stack_init(unsigned long size)
66471+{
66472+ if ((size * sizeof (void *)) <= PAGE_SIZE)
66473+ alloc_stack =
66474+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
66475+ else
66476+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
66477+
66478+ alloc_stack_size = size;
66479+
66480+ if (!alloc_stack)
66481+ return 0;
66482+ else
66483+ return 1;
66484+}
66485diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
66486new file mode 100644
66487index 0000000..bdd51ea
66488--- /dev/null
66489+++ b/grsecurity/gracl_cap.c
66490@@ -0,0 +1,110 @@
66491+#include <linux/kernel.h>
66492+#include <linux/module.h>
66493+#include <linux/sched.h>
66494+#include <linux/gracl.h>
66495+#include <linux/grsecurity.h>
66496+#include <linux/grinternal.h>
66497+
66498+extern const char *captab_log[];
66499+extern int captab_log_entries;
66500+
66501+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
66502+{
66503+ struct acl_subject_label *curracl;
66504+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66505+ kernel_cap_t cap_audit = __cap_empty_set;
66506+
66507+ if (!gr_acl_is_enabled())
66508+ return 1;
66509+
66510+ curracl = task->acl;
66511+
66512+ cap_drop = curracl->cap_lower;
66513+ cap_mask = curracl->cap_mask;
66514+ cap_audit = curracl->cap_invert_audit;
66515+
66516+ while ((curracl = curracl->parent_subject)) {
66517+ /* if the cap isn't specified in the current computed mask but is specified in the
66518+ current level subject, and is lowered in the current level subject, then add
66519+ it to the set of dropped capabilities
66520+ otherwise, add the current level subject's mask to the current computed mask
66521+ */
66522+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66523+ cap_raise(cap_mask, cap);
66524+ if (cap_raised(curracl->cap_lower, cap))
66525+ cap_raise(cap_drop, cap);
66526+ if (cap_raised(curracl->cap_invert_audit, cap))
66527+ cap_raise(cap_audit, cap);
66528+ }
66529+ }
66530+
66531+ if (!cap_raised(cap_drop, cap)) {
66532+ if (cap_raised(cap_audit, cap))
66533+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
66534+ return 1;
66535+ }
66536+
66537+ curracl = task->acl;
66538+
66539+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
66540+ && cap_raised(cred->cap_effective, cap)) {
66541+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
66542+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
66543+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
66544+ gr_to_filename(task->exec_file->f_path.dentry,
66545+ task->exec_file->f_path.mnt) : curracl->filename,
66546+ curracl->filename, 0UL,
66547+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
66548+ return 1;
66549+ }
66550+
66551+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
66552+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
66553+
66554+ return 0;
66555+}
66556+
66557+int
66558+gr_acl_is_capable(const int cap)
66559+{
66560+ return gr_task_acl_is_capable(current, current_cred(), cap);
66561+}
66562+
66563+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
66564+{
66565+ struct acl_subject_label *curracl;
66566+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66567+
66568+ if (!gr_acl_is_enabled())
66569+ return 1;
66570+
66571+ curracl = task->acl;
66572+
66573+ cap_drop = curracl->cap_lower;
66574+ cap_mask = curracl->cap_mask;
66575+
66576+ while ((curracl = curracl->parent_subject)) {
66577+ /* if the cap isn't specified in the current computed mask but is specified in the
66578+ current level subject, and is lowered in the current level subject, then add
66579+ it to the set of dropped capabilities
66580+ otherwise, add the current level subject's mask to the current computed mask
66581+ */
66582+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66583+ cap_raise(cap_mask, cap);
66584+ if (cap_raised(curracl->cap_lower, cap))
66585+ cap_raise(cap_drop, cap);
66586+ }
66587+ }
66588+
66589+ if (!cap_raised(cap_drop, cap))
66590+ return 1;
66591+
66592+ return 0;
66593+}
66594+
66595+int
66596+gr_acl_is_capable_nolog(const int cap)
66597+{
66598+ return gr_task_acl_is_capable_nolog(current, cap);
66599+}
66600+
66601diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
66602new file mode 100644
66603index 0000000..a43dd06
66604--- /dev/null
66605+++ b/grsecurity/gracl_compat.c
66606@@ -0,0 +1,269 @@
66607+#include <linux/kernel.h>
66608+#include <linux/gracl.h>
66609+#include <linux/compat.h>
66610+#include <linux/gracl_compat.h>
66611+
66612+#include <asm/uaccess.h>
66613+
66614+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
66615+{
66616+ struct gr_arg_wrapper_compat uwrapcompat;
66617+
66618+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
66619+ return -EFAULT;
66620+
66621+ if ((uwrapcompat.version != GRSECURITY_VERSION) ||
66622+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
66623+ return -EINVAL;
66624+
66625+ uwrap->arg = compat_ptr(uwrapcompat.arg);
66626+ uwrap->version = uwrapcompat.version;
66627+ uwrap->size = sizeof(struct gr_arg);
66628+
66629+ return 0;
66630+}
66631+
66632+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
66633+{
66634+ struct gr_arg_compat argcompat;
66635+
66636+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
66637+ return -EFAULT;
66638+
66639+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
66640+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
66641+ arg->role_db.num_roles = argcompat.role_db.num_roles;
66642+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
66643+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
66644+ arg->role_db.num_objects = argcompat.role_db.num_objects;
66645+
66646+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
66647+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
66648+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
66649+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
66650+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
66651+ arg->segv_device = argcompat.segv_device;
66652+ arg->segv_inode = argcompat.segv_inode;
66653+ arg->segv_uid = argcompat.segv_uid;
66654+ arg->num_sprole_pws = argcompat.num_sprole_pws;
66655+ arg->mode = argcompat.mode;
66656+
66657+ return 0;
66658+}
66659+
66660+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
66661+{
66662+ struct acl_object_label_compat objcompat;
66663+
66664+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
66665+ return -EFAULT;
66666+
66667+ obj->filename = compat_ptr(objcompat.filename);
66668+ obj->inode = objcompat.inode;
66669+ obj->device = objcompat.device;
66670+ obj->mode = objcompat.mode;
66671+
66672+ obj->nested = compat_ptr(objcompat.nested);
66673+ obj->globbed = compat_ptr(objcompat.globbed);
66674+
66675+ obj->prev = compat_ptr(objcompat.prev);
66676+ obj->next = compat_ptr(objcompat.next);
66677+
66678+ return 0;
66679+}
66680+
66681+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
66682+{
66683+ unsigned int i;
66684+ struct acl_subject_label_compat subjcompat;
66685+
66686+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
66687+ return -EFAULT;
66688+
66689+ subj->filename = compat_ptr(subjcompat.filename);
66690+ subj->inode = subjcompat.inode;
66691+ subj->device = subjcompat.device;
66692+ subj->mode = subjcompat.mode;
66693+ subj->cap_mask = subjcompat.cap_mask;
66694+ subj->cap_lower = subjcompat.cap_lower;
66695+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
66696+
66697+ for (i = 0; i < GR_NLIMITS; i++) {
66698+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
66699+ subj->res[i].rlim_cur = RLIM_INFINITY;
66700+ else
66701+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
66702+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
66703+ subj->res[i].rlim_max = RLIM_INFINITY;
66704+ else
66705+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
66706+ }
66707+ subj->resmask = subjcompat.resmask;
66708+
66709+ subj->user_trans_type = subjcompat.user_trans_type;
66710+ subj->group_trans_type = subjcompat.group_trans_type;
66711+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
66712+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
66713+ subj->user_trans_num = subjcompat.user_trans_num;
66714+ subj->group_trans_num = subjcompat.group_trans_num;
66715+
66716+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
66717+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
66718+ subj->ip_type = subjcompat.ip_type;
66719+ subj->ips = compat_ptr(subjcompat.ips);
66720+ subj->ip_num = subjcompat.ip_num;
66721+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
66722+
66723+ subj->crashes = subjcompat.crashes;
66724+ subj->expires = subjcompat.expires;
66725+
66726+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
66727+ subj->hash = compat_ptr(subjcompat.hash);
66728+ subj->prev = compat_ptr(subjcompat.prev);
66729+ subj->next = compat_ptr(subjcompat.next);
66730+
66731+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
66732+ subj->obj_hash_size = subjcompat.obj_hash_size;
66733+ subj->pax_flags = subjcompat.pax_flags;
66734+
66735+ return 0;
66736+}
66737+
66738+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
66739+{
66740+ struct acl_role_label_compat rolecompat;
66741+
66742+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
66743+ return -EFAULT;
66744+
66745+ role->rolename = compat_ptr(rolecompat.rolename);
66746+ role->uidgid = rolecompat.uidgid;
66747+ role->roletype = rolecompat.roletype;
66748+
66749+ role->auth_attempts = rolecompat.auth_attempts;
66750+ role->expires = rolecompat.expires;
66751+
66752+ role->root_label = compat_ptr(rolecompat.root_label);
66753+ role->hash = compat_ptr(rolecompat.hash);
66754+
66755+ role->prev = compat_ptr(rolecompat.prev);
66756+ role->next = compat_ptr(rolecompat.next);
66757+
66758+ role->transitions = compat_ptr(rolecompat.transitions);
66759+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
66760+ role->domain_children = compat_ptr(rolecompat.domain_children);
66761+ role->domain_child_num = rolecompat.domain_child_num;
66762+
66763+ role->umask = rolecompat.umask;
66764+
66765+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
66766+ role->subj_hash_size = rolecompat.subj_hash_size;
66767+
66768+ return 0;
66769+}
66770+
66771+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
66772+{
66773+ struct role_allowed_ip_compat roleip_compat;
66774+
66775+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
66776+ return -EFAULT;
66777+
66778+ roleip->addr = roleip_compat.addr;
66779+ roleip->netmask = roleip_compat.netmask;
66780+
66781+ roleip->prev = compat_ptr(roleip_compat.prev);
66782+ roleip->next = compat_ptr(roleip_compat.next);
66783+
66784+ return 0;
66785+}
66786+
66787+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
66788+{
66789+ struct role_transition_compat trans_compat;
66790+
66791+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
66792+ return -EFAULT;
66793+
66794+ trans->rolename = compat_ptr(trans_compat.rolename);
66795+
66796+ trans->prev = compat_ptr(trans_compat.prev);
66797+ trans->next = compat_ptr(trans_compat.next);
66798+
66799+ return 0;
66800+
66801+}
66802+
66803+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
66804+{
66805+ struct gr_hash_struct_compat hash_compat;
66806+
66807+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
66808+ return -EFAULT;
66809+
66810+ hash->table = compat_ptr(hash_compat.table);
66811+ hash->nametable = compat_ptr(hash_compat.nametable);
66812+ hash->first = compat_ptr(hash_compat.first);
66813+
66814+ hash->table_size = hash_compat.table_size;
66815+ hash->used_size = hash_compat.used_size;
66816+
66817+ hash->type = hash_compat.type;
66818+
66819+ return 0;
66820+}
66821+
66822+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
66823+{
66824+ compat_uptr_t ptrcompat;
66825+
66826+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
66827+ return -EFAULT;
66828+
66829+ *(void **)ptr = compat_ptr(ptrcompat);
66830+
66831+ return 0;
66832+}
66833+
66834+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
66835+{
66836+ struct acl_ip_label_compat ip_compat;
66837+
66838+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
66839+ return -EFAULT;
66840+
66841+ ip->iface = compat_ptr(ip_compat.iface);
66842+ ip->addr = ip_compat.addr;
66843+ ip->netmask = ip_compat.netmask;
66844+ ip->low = ip_compat.low;
66845+ ip->high = ip_compat.high;
66846+ ip->mode = ip_compat.mode;
66847+ ip->type = ip_compat.type;
66848+
66849+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
66850+
66851+ ip->prev = compat_ptr(ip_compat.prev);
66852+ ip->next = compat_ptr(ip_compat.next);
66853+
66854+ return 0;
66855+}
66856+
66857+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
66858+{
66859+ struct sprole_pw_compat pw_compat;
66860+
66861+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
66862+ return -EFAULT;
66863+
66864+ pw->rolename = compat_ptr(pw_compat.rolename);
66865+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
66866+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
66867+
66868+ return 0;
66869+}
66870+
66871+size_t get_gr_arg_wrapper_size_compat(void)
66872+{
66873+ return sizeof(struct gr_arg_wrapper_compat);
66874+}
66875+
66876diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
66877new file mode 100644
66878index 0000000..a340c17
66879--- /dev/null
66880+++ b/grsecurity/gracl_fs.c
66881@@ -0,0 +1,431 @@
66882+#include <linux/kernel.h>
66883+#include <linux/sched.h>
66884+#include <linux/types.h>
66885+#include <linux/fs.h>
66886+#include <linux/file.h>
66887+#include <linux/stat.h>
66888+#include <linux/grsecurity.h>
66889+#include <linux/grinternal.h>
66890+#include <linux/gracl.h>
66891+
66892+umode_t
66893+gr_acl_umask(void)
66894+{
66895+ if (unlikely(!gr_acl_is_enabled()))
66896+ return 0;
66897+
66898+ return current->role->umask;
66899+}
66900+
66901+__u32
66902+gr_acl_handle_hidden_file(const struct dentry * dentry,
66903+ const struct vfsmount * mnt)
66904+{
66905+ __u32 mode;
66906+
66907+ if (unlikely(!dentry->d_inode))
66908+ return GR_FIND;
66909+
66910+ mode =
66911+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
66912+
66913+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
66914+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66915+ return mode;
66916+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
66917+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66918+ return 0;
66919+ } else if (unlikely(!(mode & GR_FIND)))
66920+ return 0;
66921+
66922+ return GR_FIND;
66923+}
66924+
66925+__u32
66926+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
66927+ int acc_mode)
66928+{
66929+ __u32 reqmode = GR_FIND;
66930+ __u32 mode;
66931+
66932+ if (unlikely(!dentry->d_inode))
66933+ return reqmode;
66934+
66935+ if (acc_mode & MAY_APPEND)
66936+ reqmode |= GR_APPEND;
66937+ else if (acc_mode & MAY_WRITE)
66938+ reqmode |= GR_WRITE;
66939+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
66940+ reqmode |= GR_READ;
66941+
66942+ mode =
66943+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66944+ mnt);
66945+
66946+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66947+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66948+ reqmode & GR_READ ? " reading" : "",
66949+ reqmode & GR_WRITE ? " writing" : reqmode &
66950+ GR_APPEND ? " appending" : "");
66951+ return reqmode;
66952+ } else
66953+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66954+ {
66955+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66956+ reqmode & GR_READ ? " reading" : "",
66957+ reqmode & GR_WRITE ? " writing" : reqmode &
66958+ GR_APPEND ? " appending" : "");
66959+ return 0;
66960+ } else if (unlikely((mode & reqmode) != reqmode))
66961+ return 0;
66962+
66963+ return reqmode;
66964+}
66965+
66966+__u32
66967+gr_acl_handle_creat(const struct dentry * dentry,
66968+ const struct dentry * p_dentry,
66969+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
66970+ const int imode)
66971+{
66972+ __u32 reqmode = GR_WRITE | GR_CREATE;
66973+ __u32 mode;
66974+
66975+ if (acc_mode & MAY_APPEND)
66976+ reqmode |= GR_APPEND;
66977+ // if a directory was required or the directory already exists, then
66978+ // don't count this open as a read
66979+ if ((acc_mode & MAY_READ) &&
66980+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
66981+ reqmode |= GR_READ;
66982+ if ((open_flags & O_CREAT) &&
66983+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
66984+ reqmode |= GR_SETID;
66985+
66986+ mode =
66987+ gr_check_create(dentry, p_dentry, p_mnt,
66988+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
66989+
66990+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66991+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66992+ reqmode & GR_READ ? " reading" : "",
66993+ reqmode & GR_WRITE ? " writing" : reqmode &
66994+ GR_APPEND ? " appending" : "");
66995+ return reqmode;
66996+ } else
66997+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66998+ {
66999+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
67000+ reqmode & GR_READ ? " reading" : "",
67001+ reqmode & GR_WRITE ? " writing" : reqmode &
67002+ GR_APPEND ? " appending" : "");
67003+ return 0;
67004+ } else if (unlikely((mode & reqmode) != reqmode))
67005+ return 0;
67006+
67007+ return reqmode;
67008+}
67009+
67010+__u32
67011+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
67012+ const int fmode)
67013+{
67014+ __u32 mode, reqmode = GR_FIND;
67015+
67016+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
67017+ reqmode |= GR_EXEC;
67018+ if (fmode & S_IWOTH)
67019+ reqmode |= GR_WRITE;
67020+ if (fmode & S_IROTH)
67021+ reqmode |= GR_READ;
67022+
67023+ mode =
67024+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
67025+ mnt);
67026+
67027+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
67028+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
67029+ reqmode & GR_READ ? " reading" : "",
67030+ reqmode & GR_WRITE ? " writing" : "",
67031+ reqmode & GR_EXEC ? " executing" : "");
67032+ return reqmode;
67033+ } else
67034+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
67035+ {
67036+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
67037+ reqmode & GR_READ ? " reading" : "",
67038+ reqmode & GR_WRITE ? " writing" : "",
67039+ reqmode & GR_EXEC ? " executing" : "");
67040+ return 0;
67041+ } else if (unlikely((mode & reqmode) != reqmode))
67042+ return 0;
67043+
67044+ return reqmode;
67045+}
67046+
67047+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
67048+{
67049+ __u32 mode;
67050+
67051+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
67052+
67053+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
67054+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
67055+ return mode;
67056+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
67057+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
67058+ return 0;
67059+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
67060+ return 0;
67061+
67062+ return (reqmode);
67063+}
67064+
67065+__u32
67066+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
67067+{
67068+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
67069+}
67070+
67071+__u32
67072+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
67073+{
67074+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
67075+}
67076+
67077+__u32
67078+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
67079+{
67080+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
67081+}
67082+
67083+__u32
67084+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
67085+{
67086+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
67087+}
67088+
67089+__u32
67090+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
67091+ umode_t *modeptr)
67092+{
67093+ umode_t mode;
67094+
67095+ *modeptr &= ~gr_acl_umask();
67096+ mode = *modeptr;
67097+
67098+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
67099+ return 1;
67100+
67101+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
67102+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
67103+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
67104+ GR_CHMOD_ACL_MSG);
67105+ } else {
67106+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
67107+ }
67108+}
67109+
67110+__u32
67111+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
67112+{
67113+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
67114+}
67115+
67116+__u32
67117+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
67118+{
67119+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
67120+}
67121+
67122+__u32
67123+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
67124+{
67125+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
67126+}
67127+
67128+__u32
67129+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
67130+{
67131+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
67132+ GR_UNIXCONNECT_ACL_MSG);
67133+}
67134+
67135+/* hardlinks require at minimum create and link permission,
67136+ any additional privilege required is based on the
67137+ privilege of the file being linked to
67138+*/
67139+__u32
67140+gr_acl_handle_link(const struct dentry * new_dentry,
67141+ const struct dentry * parent_dentry,
67142+ const struct vfsmount * parent_mnt,
67143+ const struct dentry * old_dentry,
67144+ const struct vfsmount * old_mnt, const struct filename *to)
67145+{
67146+ __u32 mode;
67147+ __u32 needmode = GR_CREATE | GR_LINK;
67148+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
67149+
67150+ mode =
67151+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
67152+ old_mnt);
67153+
67154+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
67155+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67156+ return mode;
67157+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67158+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67159+ return 0;
67160+ } else if (unlikely((mode & needmode) != needmode))
67161+ return 0;
67162+
67163+ return 1;
67164+}
67165+
67166+__u32
67167+gr_acl_handle_symlink(const struct dentry * new_dentry,
67168+ const struct dentry * parent_dentry,
67169+ const struct vfsmount * parent_mnt, const struct filename *from)
67170+{
67171+ __u32 needmode = GR_WRITE | GR_CREATE;
67172+ __u32 mode;
67173+
67174+ mode =
67175+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
67176+ GR_CREATE | GR_AUDIT_CREATE |
67177+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
67178+
67179+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
67180+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67181+ return mode;
67182+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67183+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67184+ return 0;
67185+ } else if (unlikely((mode & needmode) != needmode))
67186+ return 0;
67187+
67188+ return (GR_WRITE | GR_CREATE);
67189+}
67190+
67191+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)
67192+{
67193+ __u32 mode;
67194+
67195+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
67196+
67197+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
67198+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
67199+ return mode;
67200+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
67201+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
67202+ return 0;
67203+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
67204+ return 0;
67205+
67206+ return (reqmode);
67207+}
67208+
67209+__u32
67210+gr_acl_handle_mknod(const struct dentry * new_dentry,
67211+ const struct dentry * parent_dentry,
67212+ const struct vfsmount * parent_mnt,
67213+ const int mode)
67214+{
67215+ __u32 reqmode = GR_WRITE | GR_CREATE;
67216+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
67217+ reqmode |= GR_SETID;
67218+
67219+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67220+ reqmode, GR_MKNOD_ACL_MSG);
67221+}
67222+
67223+__u32
67224+gr_acl_handle_mkdir(const struct dentry *new_dentry,
67225+ const struct dentry *parent_dentry,
67226+ const struct vfsmount *parent_mnt)
67227+{
67228+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67229+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
67230+}
67231+
67232+#define RENAME_CHECK_SUCCESS(old, new) \
67233+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
67234+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
67235+
67236+int
67237+gr_acl_handle_rename(struct dentry *new_dentry,
67238+ struct dentry *parent_dentry,
67239+ const struct vfsmount *parent_mnt,
67240+ struct dentry *old_dentry,
67241+ struct inode *old_parent_inode,
67242+ struct vfsmount *old_mnt, const struct filename *newname)
67243+{
67244+ __u32 comp1, comp2;
67245+ int error = 0;
67246+
67247+ if (unlikely(!gr_acl_is_enabled()))
67248+ return 0;
67249+
67250+ if (!new_dentry->d_inode) {
67251+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
67252+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
67253+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
67254+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
67255+ GR_DELETE | GR_AUDIT_DELETE |
67256+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67257+ GR_SUPPRESS, old_mnt);
67258+ } else {
67259+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
67260+ GR_CREATE | GR_DELETE |
67261+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
67262+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67263+ GR_SUPPRESS, parent_mnt);
67264+ comp2 =
67265+ gr_search_file(old_dentry,
67266+ GR_READ | GR_WRITE | GR_AUDIT_READ |
67267+ GR_DELETE | GR_AUDIT_DELETE |
67268+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
67269+ }
67270+
67271+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
67272+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
67273+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67274+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
67275+ && !(comp2 & GR_SUPPRESS)) {
67276+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67277+ error = -EACCES;
67278+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
67279+ error = -EACCES;
67280+
67281+ return error;
67282+}
67283+
67284+void
67285+gr_acl_handle_exit(void)
67286+{
67287+ u16 id;
67288+ char *rolename;
67289+
67290+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
67291+ !(current->role->roletype & GR_ROLE_PERSIST))) {
67292+ id = current->acl_role_id;
67293+ rolename = current->role->rolename;
67294+ gr_set_acls(1);
67295+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
67296+ }
67297+
67298+ gr_put_exec_file(current);
67299+ return;
67300+}
67301+
67302+int
67303+gr_acl_handle_procpidmem(const struct task_struct *task)
67304+{
67305+ if (unlikely(!gr_acl_is_enabled()))
67306+ return 0;
67307+
67308+ if (task != current && task->acl->mode & GR_PROTPROCFD)
67309+ return -EACCES;
67310+
67311+ return 0;
67312+}
67313diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
67314new file mode 100644
67315index 0000000..8132048
67316--- /dev/null
67317+++ b/grsecurity/gracl_ip.c
67318@@ -0,0 +1,387 @@
67319+#include <linux/kernel.h>
67320+#include <asm/uaccess.h>
67321+#include <asm/errno.h>
67322+#include <net/sock.h>
67323+#include <linux/file.h>
67324+#include <linux/fs.h>
67325+#include <linux/net.h>
67326+#include <linux/in.h>
67327+#include <linux/skbuff.h>
67328+#include <linux/ip.h>
67329+#include <linux/udp.h>
67330+#include <linux/types.h>
67331+#include <linux/sched.h>
67332+#include <linux/netdevice.h>
67333+#include <linux/inetdevice.h>
67334+#include <linux/gracl.h>
67335+#include <linux/grsecurity.h>
67336+#include <linux/grinternal.h>
67337+
67338+#define GR_BIND 0x01
67339+#define GR_CONNECT 0x02
67340+#define GR_INVERT 0x04
67341+#define GR_BINDOVERRIDE 0x08
67342+#define GR_CONNECTOVERRIDE 0x10
67343+#define GR_SOCK_FAMILY 0x20
67344+
67345+static const char * gr_protocols[IPPROTO_MAX] = {
67346+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
67347+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
67348+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
67349+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
67350+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
67351+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
67352+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
67353+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
67354+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
67355+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
67356+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
67357+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
67358+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
67359+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
67360+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
67361+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
67362+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
67363+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
67364+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
67365+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
67366+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
67367+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
67368+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
67369+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
67370+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
67371+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
67372+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
67373+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
67374+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
67375+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
67376+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
67377+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
67378+ };
67379+
67380+static const char * gr_socktypes[SOCK_MAX] = {
67381+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
67382+ "unknown:7", "unknown:8", "unknown:9", "packet"
67383+ };
67384+
67385+static const char * gr_sockfamilies[AF_MAX+1] = {
67386+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
67387+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
67388+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
67389+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
67390+ };
67391+
67392+const char *
67393+gr_proto_to_name(unsigned char proto)
67394+{
67395+ return gr_protocols[proto];
67396+}
67397+
67398+const char *
67399+gr_socktype_to_name(unsigned char type)
67400+{
67401+ return gr_socktypes[type];
67402+}
67403+
67404+const char *
67405+gr_sockfamily_to_name(unsigned char family)
67406+{
67407+ return gr_sockfamilies[family];
67408+}
67409+
67410+int
67411+gr_search_socket(const int domain, const int type, const int protocol)
67412+{
67413+ struct acl_subject_label *curr;
67414+ const struct cred *cred = current_cred();
67415+
67416+ if (unlikely(!gr_acl_is_enabled()))
67417+ goto exit;
67418+
67419+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
67420+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
67421+ goto exit; // let the kernel handle it
67422+
67423+ curr = current->acl;
67424+
67425+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
67426+ /* the family is allowed, if this is PF_INET allow it only if
67427+ the extra sock type/protocol checks pass */
67428+ if (domain == PF_INET)
67429+ goto inet_check;
67430+ goto exit;
67431+ } else {
67432+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67433+ __u32 fakeip = 0;
67434+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67435+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67436+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67437+ gr_to_filename(current->exec_file->f_path.dentry,
67438+ current->exec_file->f_path.mnt) :
67439+ curr->filename, curr->filename,
67440+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
67441+ &current->signal->saved_ip);
67442+ goto exit;
67443+ }
67444+ goto exit_fail;
67445+ }
67446+
67447+inet_check:
67448+ /* the rest of this checking is for IPv4 only */
67449+ if (!curr->ips)
67450+ goto exit;
67451+
67452+ if ((curr->ip_type & (1U << type)) &&
67453+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
67454+ goto exit;
67455+
67456+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67457+ /* we don't place acls on raw sockets , and sometimes
67458+ dgram/ip sockets are opened for ioctl and not
67459+ bind/connect, so we'll fake a bind learn log */
67460+ if (type == SOCK_RAW || type == SOCK_PACKET) {
67461+ __u32 fakeip = 0;
67462+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67463+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67464+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67465+ gr_to_filename(current->exec_file->f_path.dentry,
67466+ current->exec_file->f_path.mnt) :
67467+ curr->filename, curr->filename,
67468+ &fakeip, 0, type,
67469+ protocol, GR_CONNECT, &current->signal->saved_ip);
67470+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
67471+ __u32 fakeip = 0;
67472+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67473+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67474+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67475+ gr_to_filename(current->exec_file->f_path.dentry,
67476+ current->exec_file->f_path.mnt) :
67477+ curr->filename, curr->filename,
67478+ &fakeip, 0, type,
67479+ protocol, GR_BIND, &current->signal->saved_ip);
67480+ }
67481+ /* we'll log when they use connect or bind */
67482+ goto exit;
67483+ }
67484+
67485+exit_fail:
67486+ if (domain == PF_INET)
67487+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
67488+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
67489+ else
67490+#ifndef CONFIG_IPV6
67491+ if (domain != PF_INET6)
67492+#endif
67493+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
67494+ gr_socktype_to_name(type), protocol);
67495+
67496+ return 0;
67497+exit:
67498+ return 1;
67499+}
67500+
67501+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)
67502+{
67503+ if ((ip->mode & mode) &&
67504+ (ip_port >= ip->low) &&
67505+ (ip_port <= ip->high) &&
67506+ ((ntohl(ip_addr) & our_netmask) ==
67507+ (ntohl(our_addr) & our_netmask))
67508+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
67509+ && (ip->type & (1U << type))) {
67510+ if (ip->mode & GR_INVERT)
67511+ return 2; // specifically denied
67512+ else
67513+ return 1; // allowed
67514+ }
67515+
67516+ return 0; // not specifically allowed, may continue parsing
67517+}
67518+
67519+static int
67520+gr_search_connectbind(const int full_mode, struct sock *sk,
67521+ struct sockaddr_in *addr, const int type)
67522+{
67523+ char iface[IFNAMSIZ] = {0};
67524+ struct acl_subject_label *curr;
67525+ struct acl_ip_label *ip;
67526+ struct inet_sock *isk;
67527+ struct net_device *dev;
67528+ struct in_device *idev;
67529+ unsigned long i;
67530+ int ret;
67531+ int mode = full_mode & (GR_BIND | GR_CONNECT);
67532+ __u32 ip_addr = 0;
67533+ __u32 our_addr;
67534+ __u32 our_netmask;
67535+ char *p;
67536+ __u16 ip_port = 0;
67537+ const struct cred *cred = current_cred();
67538+
67539+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
67540+ return 0;
67541+
67542+ curr = current->acl;
67543+ isk = inet_sk(sk);
67544+
67545+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
67546+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
67547+ addr->sin_addr.s_addr = curr->inaddr_any_override;
67548+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
67549+ struct sockaddr_in saddr;
67550+ int err;
67551+
67552+ saddr.sin_family = AF_INET;
67553+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
67554+ saddr.sin_port = isk->inet_sport;
67555+
67556+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67557+ if (err)
67558+ return err;
67559+
67560+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67561+ if (err)
67562+ return err;
67563+ }
67564+
67565+ if (!curr->ips)
67566+ return 0;
67567+
67568+ ip_addr = addr->sin_addr.s_addr;
67569+ ip_port = ntohs(addr->sin_port);
67570+
67571+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67572+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67573+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67574+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67575+ gr_to_filename(current->exec_file->f_path.dentry,
67576+ current->exec_file->f_path.mnt) :
67577+ curr->filename, curr->filename,
67578+ &ip_addr, ip_port, type,
67579+ sk->sk_protocol, mode, &current->signal->saved_ip);
67580+ return 0;
67581+ }
67582+
67583+ for (i = 0; i < curr->ip_num; i++) {
67584+ ip = *(curr->ips + i);
67585+ if (ip->iface != NULL) {
67586+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
67587+ p = strchr(iface, ':');
67588+ if (p != NULL)
67589+ *p = '\0';
67590+ dev = dev_get_by_name(sock_net(sk), iface);
67591+ if (dev == NULL)
67592+ continue;
67593+ idev = in_dev_get(dev);
67594+ if (idev == NULL) {
67595+ dev_put(dev);
67596+ continue;
67597+ }
67598+ rcu_read_lock();
67599+ for_ifa(idev) {
67600+ if (!strcmp(ip->iface, ifa->ifa_label)) {
67601+ our_addr = ifa->ifa_address;
67602+ our_netmask = 0xffffffff;
67603+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67604+ if (ret == 1) {
67605+ rcu_read_unlock();
67606+ in_dev_put(idev);
67607+ dev_put(dev);
67608+ return 0;
67609+ } else if (ret == 2) {
67610+ rcu_read_unlock();
67611+ in_dev_put(idev);
67612+ dev_put(dev);
67613+ goto denied;
67614+ }
67615+ }
67616+ } endfor_ifa(idev);
67617+ rcu_read_unlock();
67618+ in_dev_put(idev);
67619+ dev_put(dev);
67620+ } else {
67621+ our_addr = ip->addr;
67622+ our_netmask = ip->netmask;
67623+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67624+ if (ret == 1)
67625+ return 0;
67626+ else if (ret == 2)
67627+ goto denied;
67628+ }
67629+ }
67630+
67631+denied:
67632+ if (mode == GR_BIND)
67633+ 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));
67634+ else if (mode == GR_CONNECT)
67635+ 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));
67636+
67637+ return -EACCES;
67638+}
67639+
67640+int
67641+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
67642+{
67643+ /* always allow disconnection of dgram sockets with connect */
67644+ if (addr->sin_family == AF_UNSPEC)
67645+ return 0;
67646+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
67647+}
67648+
67649+int
67650+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
67651+{
67652+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
67653+}
67654+
67655+int gr_search_listen(struct socket *sock)
67656+{
67657+ struct sock *sk = sock->sk;
67658+ struct sockaddr_in addr;
67659+
67660+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67661+ addr.sin_port = inet_sk(sk)->inet_sport;
67662+
67663+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67664+}
67665+
67666+int gr_search_accept(struct socket *sock)
67667+{
67668+ struct sock *sk = sock->sk;
67669+ struct sockaddr_in addr;
67670+
67671+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67672+ addr.sin_port = inet_sk(sk)->inet_sport;
67673+
67674+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67675+}
67676+
67677+int
67678+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
67679+{
67680+ if (addr)
67681+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
67682+ else {
67683+ struct sockaddr_in sin;
67684+ const struct inet_sock *inet = inet_sk(sk);
67685+
67686+ sin.sin_addr.s_addr = inet->inet_daddr;
67687+ sin.sin_port = inet->inet_dport;
67688+
67689+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67690+ }
67691+}
67692+
67693+int
67694+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
67695+{
67696+ struct sockaddr_in sin;
67697+
67698+ if (unlikely(skb->len < sizeof (struct udphdr)))
67699+ return 0; // skip this packet
67700+
67701+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
67702+ sin.sin_port = udp_hdr(skb)->source;
67703+
67704+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67705+}
67706diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
67707new file mode 100644
67708index 0000000..25f54ef
67709--- /dev/null
67710+++ b/grsecurity/gracl_learn.c
67711@@ -0,0 +1,207 @@
67712+#include <linux/kernel.h>
67713+#include <linux/mm.h>
67714+#include <linux/sched.h>
67715+#include <linux/poll.h>
67716+#include <linux/string.h>
67717+#include <linux/file.h>
67718+#include <linux/types.h>
67719+#include <linux/vmalloc.h>
67720+#include <linux/grinternal.h>
67721+
67722+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
67723+ size_t count, loff_t *ppos);
67724+extern int gr_acl_is_enabled(void);
67725+
67726+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
67727+static int gr_learn_attached;
67728+
67729+/* use a 512k buffer */
67730+#define LEARN_BUFFER_SIZE (512 * 1024)
67731+
67732+static DEFINE_SPINLOCK(gr_learn_lock);
67733+static DEFINE_MUTEX(gr_learn_user_mutex);
67734+
67735+/* we need to maintain two buffers, so that the kernel context of grlearn
67736+ uses a semaphore around the userspace copying, and the other kernel contexts
67737+ use a spinlock when copying into the buffer, since they cannot sleep
67738+*/
67739+static char *learn_buffer;
67740+static char *learn_buffer_user;
67741+static int learn_buffer_len;
67742+static int learn_buffer_user_len;
67743+
67744+static ssize_t
67745+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
67746+{
67747+ DECLARE_WAITQUEUE(wait, current);
67748+ ssize_t retval = 0;
67749+
67750+ add_wait_queue(&learn_wait, &wait);
67751+ set_current_state(TASK_INTERRUPTIBLE);
67752+ do {
67753+ mutex_lock(&gr_learn_user_mutex);
67754+ spin_lock(&gr_learn_lock);
67755+ if (learn_buffer_len)
67756+ break;
67757+ spin_unlock(&gr_learn_lock);
67758+ mutex_unlock(&gr_learn_user_mutex);
67759+ if (file->f_flags & O_NONBLOCK) {
67760+ retval = -EAGAIN;
67761+ goto out;
67762+ }
67763+ if (signal_pending(current)) {
67764+ retval = -ERESTARTSYS;
67765+ goto out;
67766+ }
67767+
67768+ schedule();
67769+ } while (1);
67770+
67771+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
67772+ learn_buffer_user_len = learn_buffer_len;
67773+ retval = learn_buffer_len;
67774+ learn_buffer_len = 0;
67775+
67776+ spin_unlock(&gr_learn_lock);
67777+
67778+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
67779+ retval = -EFAULT;
67780+
67781+ mutex_unlock(&gr_learn_user_mutex);
67782+out:
67783+ set_current_state(TASK_RUNNING);
67784+ remove_wait_queue(&learn_wait, &wait);
67785+ return retval;
67786+}
67787+
67788+static unsigned int
67789+poll_learn(struct file * file, poll_table * wait)
67790+{
67791+ poll_wait(file, &learn_wait, wait);
67792+
67793+ if (learn_buffer_len)
67794+ return (POLLIN | POLLRDNORM);
67795+
67796+ return 0;
67797+}
67798+
67799+void
67800+gr_clear_learn_entries(void)
67801+{
67802+ char *tmp;
67803+
67804+ mutex_lock(&gr_learn_user_mutex);
67805+ spin_lock(&gr_learn_lock);
67806+ tmp = learn_buffer;
67807+ learn_buffer = NULL;
67808+ spin_unlock(&gr_learn_lock);
67809+ if (tmp)
67810+ vfree(tmp);
67811+ if (learn_buffer_user != NULL) {
67812+ vfree(learn_buffer_user);
67813+ learn_buffer_user = NULL;
67814+ }
67815+ learn_buffer_len = 0;
67816+ mutex_unlock(&gr_learn_user_mutex);
67817+
67818+ return;
67819+}
67820+
67821+void
67822+gr_add_learn_entry(const char *fmt, ...)
67823+{
67824+ va_list args;
67825+ unsigned int len;
67826+
67827+ if (!gr_learn_attached)
67828+ return;
67829+
67830+ spin_lock(&gr_learn_lock);
67831+
67832+ /* leave a gap at the end so we know when it's "full" but don't have to
67833+ compute the exact length of the string we're trying to append
67834+ */
67835+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
67836+ spin_unlock(&gr_learn_lock);
67837+ wake_up_interruptible(&learn_wait);
67838+ return;
67839+ }
67840+ if (learn_buffer == NULL) {
67841+ spin_unlock(&gr_learn_lock);
67842+ return;
67843+ }
67844+
67845+ va_start(args, fmt);
67846+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
67847+ va_end(args);
67848+
67849+ learn_buffer_len += len + 1;
67850+
67851+ spin_unlock(&gr_learn_lock);
67852+ wake_up_interruptible(&learn_wait);
67853+
67854+ return;
67855+}
67856+
67857+static int
67858+open_learn(struct inode *inode, struct file *file)
67859+{
67860+ if (file->f_mode & FMODE_READ && gr_learn_attached)
67861+ return -EBUSY;
67862+ if (file->f_mode & FMODE_READ) {
67863+ int retval = 0;
67864+ mutex_lock(&gr_learn_user_mutex);
67865+ if (learn_buffer == NULL)
67866+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
67867+ if (learn_buffer_user == NULL)
67868+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
67869+ if (learn_buffer == NULL) {
67870+ retval = -ENOMEM;
67871+ goto out_error;
67872+ }
67873+ if (learn_buffer_user == NULL) {
67874+ retval = -ENOMEM;
67875+ goto out_error;
67876+ }
67877+ learn_buffer_len = 0;
67878+ learn_buffer_user_len = 0;
67879+ gr_learn_attached = 1;
67880+out_error:
67881+ mutex_unlock(&gr_learn_user_mutex);
67882+ return retval;
67883+ }
67884+ return 0;
67885+}
67886+
67887+static int
67888+close_learn(struct inode *inode, struct file *file)
67889+{
67890+ if (file->f_mode & FMODE_READ) {
67891+ char *tmp = NULL;
67892+ mutex_lock(&gr_learn_user_mutex);
67893+ spin_lock(&gr_learn_lock);
67894+ tmp = learn_buffer;
67895+ learn_buffer = NULL;
67896+ spin_unlock(&gr_learn_lock);
67897+ if (tmp)
67898+ vfree(tmp);
67899+ if (learn_buffer_user != NULL) {
67900+ vfree(learn_buffer_user);
67901+ learn_buffer_user = NULL;
67902+ }
67903+ learn_buffer_len = 0;
67904+ learn_buffer_user_len = 0;
67905+ gr_learn_attached = 0;
67906+ mutex_unlock(&gr_learn_user_mutex);
67907+ }
67908+
67909+ return 0;
67910+}
67911+
67912+const struct file_operations grsec_fops = {
67913+ .read = read_learn,
67914+ .write = write_grsec_handler,
67915+ .open = open_learn,
67916+ .release = close_learn,
67917+ .poll = poll_learn,
67918+};
67919diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
67920new file mode 100644
67921index 0000000..39645c9
67922--- /dev/null
67923+++ b/grsecurity/gracl_res.c
67924@@ -0,0 +1,68 @@
67925+#include <linux/kernel.h>
67926+#include <linux/sched.h>
67927+#include <linux/gracl.h>
67928+#include <linux/grinternal.h>
67929+
67930+static const char *restab_log[] = {
67931+ [RLIMIT_CPU] = "RLIMIT_CPU",
67932+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
67933+ [RLIMIT_DATA] = "RLIMIT_DATA",
67934+ [RLIMIT_STACK] = "RLIMIT_STACK",
67935+ [RLIMIT_CORE] = "RLIMIT_CORE",
67936+ [RLIMIT_RSS] = "RLIMIT_RSS",
67937+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
67938+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
67939+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
67940+ [RLIMIT_AS] = "RLIMIT_AS",
67941+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
67942+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
67943+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
67944+ [RLIMIT_NICE] = "RLIMIT_NICE",
67945+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
67946+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
67947+ [GR_CRASH_RES] = "RLIMIT_CRASH"
67948+};
67949+
67950+void
67951+gr_log_resource(const struct task_struct *task,
67952+ const int res, const unsigned long wanted, const int gt)
67953+{
67954+ const struct cred *cred;
67955+ unsigned long rlim;
67956+
67957+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
67958+ return;
67959+
67960+ // not yet supported resource
67961+ if (unlikely(!restab_log[res]))
67962+ return;
67963+
67964+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
67965+ rlim = task_rlimit_max(task, res);
67966+ else
67967+ rlim = task_rlimit(task, res);
67968+
67969+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
67970+ return;
67971+
67972+ rcu_read_lock();
67973+ cred = __task_cred(task);
67974+
67975+ if (res == RLIMIT_NPROC &&
67976+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
67977+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
67978+ goto out_rcu_unlock;
67979+ else if (res == RLIMIT_MEMLOCK &&
67980+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
67981+ goto out_rcu_unlock;
67982+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
67983+ goto out_rcu_unlock;
67984+ rcu_read_unlock();
67985+
67986+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
67987+
67988+ return;
67989+out_rcu_unlock:
67990+ rcu_read_unlock();
67991+ return;
67992+}
67993diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
67994new file mode 100644
67995index 0000000..3c38bfe
67996--- /dev/null
67997+++ b/grsecurity/gracl_segv.c
67998@@ -0,0 +1,305 @@
67999+#include <linux/kernel.h>
68000+#include <linux/mm.h>
68001+#include <asm/uaccess.h>
68002+#include <asm/errno.h>
68003+#include <asm/mman.h>
68004+#include <net/sock.h>
68005+#include <linux/file.h>
68006+#include <linux/fs.h>
68007+#include <linux/net.h>
68008+#include <linux/in.h>
68009+#include <linux/slab.h>
68010+#include <linux/types.h>
68011+#include <linux/sched.h>
68012+#include <linux/timer.h>
68013+#include <linux/gracl.h>
68014+#include <linux/grsecurity.h>
68015+#include <linux/grinternal.h>
68016+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
68017+#include <linux/magic.h>
68018+#include <linux/pagemap.h>
68019+#include "../fs/btrfs/async-thread.h"
68020+#include "../fs/btrfs/ctree.h"
68021+#include "../fs/btrfs/btrfs_inode.h"
68022+#endif
68023+
68024+static struct crash_uid *uid_set;
68025+static unsigned short uid_used;
68026+static DEFINE_SPINLOCK(gr_uid_lock);
68027+extern rwlock_t gr_inode_lock;
68028+extern struct acl_subject_label *
68029+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
68030+ struct acl_role_label *role);
68031+
68032+static inline dev_t __get_dev(const struct dentry *dentry)
68033+{
68034+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
68035+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
68036+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
68037+ else
68038+#endif
68039+ return dentry->d_sb->s_dev;
68040+}
68041+
68042+int
68043+gr_init_uidset(void)
68044+{
68045+ uid_set =
68046+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
68047+ uid_used = 0;
68048+
68049+ return uid_set ? 1 : 0;
68050+}
68051+
68052+void
68053+gr_free_uidset(void)
68054+{
68055+ if (uid_set)
68056+ kfree(uid_set);
68057+
68058+ return;
68059+}
68060+
68061+int
68062+gr_find_uid(const uid_t uid)
68063+{
68064+ struct crash_uid *tmp = uid_set;
68065+ uid_t buid;
68066+ int low = 0, high = uid_used - 1, mid;
68067+
68068+ while (high >= low) {
68069+ mid = (low + high) >> 1;
68070+ buid = tmp[mid].uid;
68071+ if (buid == uid)
68072+ return mid;
68073+ if (buid > uid)
68074+ high = mid - 1;
68075+ if (buid < uid)
68076+ low = mid + 1;
68077+ }
68078+
68079+ return -1;
68080+}
68081+
68082+static __inline__ void
68083+gr_insertsort(void)
68084+{
68085+ unsigned short i, j;
68086+ struct crash_uid index;
68087+
68088+ for (i = 1; i < uid_used; i++) {
68089+ index = uid_set[i];
68090+ j = i;
68091+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
68092+ uid_set[j] = uid_set[j - 1];
68093+ j--;
68094+ }
68095+ uid_set[j] = index;
68096+ }
68097+
68098+ return;
68099+}
68100+
68101+static __inline__ void
68102+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
68103+{
68104+ int loc;
68105+ uid_t uid = GR_GLOBAL_UID(kuid);
68106+
68107+ if (uid_used == GR_UIDTABLE_MAX)
68108+ return;
68109+
68110+ loc = gr_find_uid(uid);
68111+
68112+ if (loc >= 0) {
68113+ uid_set[loc].expires = expires;
68114+ return;
68115+ }
68116+
68117+ uid_set[uid_used].uid = uid;
68118+ uid_set[uid_used].expires = expires;
68119+ uid_used++;
68120+
68121+ gr_insertsort();
68122+
68123+ return;
68124+}
68125+
68126+void
68127+gr_remove_uid(const unsigned short loc)
68128+{
68129+ unsigned short i;
68130+
68131+ for (i = loc + 1; i < uid_used; i++)
68132+ uid_set[i - 1] = uid_set[i];
68133+
68134+ uid_used--;
68135+
68136+ return;
68137+}
68138+
68139+int
68140+gr_check_crash_uid(const kuid_t kuid)
68141+{
68142+ int loc;
68143+ int ret = 0;
68144+ uid_t uid;
68145+
68146+ if (unlikely(!gr_acl_is_enabled()))
68147+ return 0;
68148+
68149+ uid = GR_GLOBAL_UID(kuid);
68150+
68151+ spin_lock(&gr_uid_lock);
68152+ loc = gr_find_uid(uid);
68153+
68154+ if (loc < 0)
68155+ goto out_unlock;
68156+
68157+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
68158+ gr_remove_uid(loc);
68159+ else
68160+ ret = 1;
68161+
68162+out_unlock:
68163+ spin_unlock(&gr_uid_lock);
68164+ return ret;
68165+}
68166+
68167+static __inline__ int
68168+proc_is_setxid(const struct cred *cred)
68169+{
68170+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
68171+ !uid_eq(cred->uid, cred->fsuid))
68172+ return 1;
68173+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
68174+ !gid_eq(cred->gid, cred->fsgid))
68175+ return 1;
68176+
68177+ return 0;
68178+}
68179+
68180+extern int gr_fake_force_sig(int sig, struct task_struct *t);
68181+
68182+void
68183+gr_handle_crash(struct task_struct *task, const int sig)
68184+{
68185+ struct acl_subject_label *curr;
68186+ struct task_struct *tsk, *tsk2;
68187+ const struct cred *cred;
68188+ const struct cred *cred2;
68189+
68190+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
68191+ return;
68192+
68193+ if (unlikely(!gr_acl_is_enabled()))
68194+ return;
68195+
68196+ curr = task->acl;
68197+
68198+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
68199+ return;
68200+
68201+ if (time_before_eq(curr->expires, get_seconds())) {
68202+ curr->expires = 0;
68203+ curr->crashes = 0;
68204+ }
68205+
68206+ curr->crashes++;
68207+
68208+ if (!curr->expires)
68209+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
68210+
68211+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
68212+ time_after(curr->expires, get_seconds())) {
68213+ rcu_read_lock();
68214+ cred = __task_cred(task);
68215+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
68216+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
68217+ spin_lock(&gr_uid_lock);
68218+ gr_insert_uid(cred->uid, curr->expires);
68219+ spin_unlock(&gr_uid_lock);
68220+ curr->expires = 0;
68221+ curr->crashes = 0;
68222+ read_lock(&tasklist_lock);
68223+ do_each_thread(tsk2, tsk) {
68224+ cred2 = __task_cred(tsk);
68225+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
68226+ gr_fake_force_sig(SIGKILL, tsk);
68227+ } while_each_thread(tsk2, tsk);
68228+ read_unlock(&tasklist_lock);
68229+ } else {
68230+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
68231+ read_lock(&tasklist_lock);
68232+ read_lock(&grsec_exec_file_lock);
68233+ do_each_thread(tsk2, tsk) {
68234+ if (likely(tsk != task)) {
68235+ // if this thread has the same subject as the one that triggered
68236+ // RES_CRASH and it's the same binary, kill it
68237+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
68238+ gr_fake_force_sig(SIGKILL, tsk);
68239+ }
68240+ } while_each_thread(tsk2, tsk);
68241+ read_unlock(&grsec_exec_file_lock);
68242+ read_unlock(&tasklist_lock);
68243+ }
68244+ rcu_read_unlock();
68245+ }
68246+
68247+ return;
68248+}
68249+
68250+int
68251+gr_check_crash_exec(const struct file *filp)
68252+{
68253+ struct acl_subject_label *curr;
68254+
68255+ if (unlikely(!gr_acl_is_enabled()))
68256+ return 0;
68257+
68258+ read_lock(&gr_inode_lock);
68259+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
68260+ __get_dev(filp->f_path.dentry),
68261+ current->role);
68262+ read_unlock(&gr_inode_lock);
68263+
68264+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
68265+ (!curr->crashes && !curr->expires))
68266+ return 0;
68267+
68268+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
68269+ time_after(curr->expires, get_seconds()))
68270+ return 1;
68271+ else if (time_before_eq(curr->expires, get_seconds())) {
68272+ curr->crashes = 0;
68273+ curr->expires = 0;
68274+ }
68275+
68276+ return 0;
68277+}
68278+
68279+void
68280+gr_handle_alertkill(struct task_struct *task)
68281+{
68282+ struct acl_subject_label *curracl;
68283+ __u32 curr_ip;
68284+ struct task_struct *p, *p2;
68285+
68286+ if (unlikely(!gr_acl_is_enabled()))
68287+ return;
68288+
68289+ curracl = task->acl;
68290+ curr_ip = task->signal->curr_ip;
68291+
68292+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
68293+ read_lock(&tasklist_lock);
68294+ do_each_thread(p2, p) {
68295+ if (p->signal->curr_ip == curr_ip)
68296+ gr_fake_force_sig(SIGKILL, p);
68297+ } while_each_thread(p2, p);
68298+ read_unlock(&tasklist_lock);
68299+ } else if (curracl->mode & GR_KILLPROC)
68300+ gr_fake_force_sig(SIGKILL, task);
68301+
68302+ return;
68303+}
68304diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
68305new file mode 100644
68306index 0000000..98011b0
68307--- /dev/null
68308+++ b/grsecurity/gracl_shm.c
68309@@ -0,0 +1,40 @@
68310+#include <linux/kernel.h>
68311+#include <linux/mm.h>
68312+#include <linux/sched.h>
68313+#include <linux/file.h>
68314+#include <linux/ipc.h>
68315+#include <linux/gracl.h>
68316+#include <linux/grsecurity.h>
68317+#include <linux/grinternal.h>
68318+
68319+int
68320+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68321+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
68322+{
68323+ struct task_struct *task;
68324+
68325+ if (!gr_acl_is_enabled())
68326+ return 1;
68327+
68328+ rcu_read_lock();
68329+ read_lock(&tasklist_lock);
68330+
68331+ task = find_task_by_vpid(shm_cprid);
68332+
68333+ if (unlikely(!task))
68334+ task = find_task_by_vpid(shm_lapid);
68335+
68336+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
68337+ (task_pid_nr(task) == shm_lapid)) &&
68338+ (task->acl->mode & GR_PROTSHM) &&
68339+ (task->acl != current->acl))) {
68340+ read_unlock(&tasklist_lock);
68341+ rcu_read_unlock();
68342+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
68343+ return 0;
68344+ }
68345+ read_unlock(&tasklist_lock);
68346+ rcu_read_unlock();
68347+
68348+ return 1;
68349+}
68350diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
68351new file mode 100644
68352index 0000000..bc0be01
68353--- /dev/null
68354+++ b/grsecurity/grsec_chdir.c
68355@@ -0,0 +1,19 @@
68356+#include <linux/kernel.h>
68357+#include <linux/sched.h>
68358+#include <linux/fs.h>
68359+#include <linux/file.h>
68360+#include <linux/grsecurity.h>
68361+#include <linux/grinternal.h>
68362+
68363+void
68364+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
68365+{
68366+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
68367+ if ((grsec_enable_chdir && grsec_enable_group &&
68368+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
68369+ !grsec_enable_group)) {
68370+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
68371+ }
68372+#endif
68373+ return;
68374+}
68375diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
68376new file mode 100644
68377index 0000000..bd6e105
68378--- /dev/null
68379+++ b/grsecurity/grsec_chroot.c
68380@@ -0,0 +1,370 @@
68381+#include <linux/kernel.h>
68382+#include <linux/module.h>
68383+#include <linux/sched.h>
68384+#include <linux/file.h>
68385+#include <linux/fs.h>
68386+#include <linux/mount.h>
68387+#include <linux/types.h>
68388+#include "../fs/mount.h"
68389+#include <linux/grsecurity.h>
68390+#include <linux/grinternal.h>
68391+
68392+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68393+static int gr_init_ran;
68394+#endif
68395+
68396+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
68397+{
68398+#ifdef CONFIG_GRKERNSEC
68399+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
68400+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
68401+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68402+ && gr_init_ran
68403+#endif
68404+ )
68405+ task->gr_is_chrooted = 1;
68406+ else {
68407+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68408+ if (task_pid_nr(task) == 1 && !gr_init_ran)
68409+ gr_init_ran = 1;
68410+#endif
68411+ task->gr_is_chrooted = 0;
68412+ }
68413+
68414+ task->gr_chroot_dentry = path->dentry;
68415+#endif
68416+ return;
68417+}
68418+
68419+void gr_clear_chroot_entries(struct task_struct *task)
68420+{
68421+#ifdef CONFIG_GRKERNSEC
68422+ task->gr_is_chrooted = 0;
68423+ task->gr_chroot_dentry = NULL;
68424+#endif
68425+ return;
68426+}
68427+
68428+int
68429+gr_handle_chroot_unix(const pid_t pid)
68430+{
68431+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
68432+ struct task_struct *p;
68433+
68434+ if (unlikely(!grsec_enable_chroot_unix))
68435+ return 1;
68436+
68437+ if (likely(!proc_is_chrooted(current)))
68438+ return 1;
68439+
68440+ rcu_read_lock();
68441+ read_lock(&tasklist_lock);
68442+ p = find_task_by_vpid_unrestricted(pid);
68443+ if (unlikely(p && !have_same_root(current, p))) {
68444+ read_unlock(&tasklist_lock);
68445+ rcu_read_unlock();
68446+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
68447+ return 0;
68448+ }
68449+ read_unlock(&tasklist_lock);
68450+ rcu_read_unlock();
68451+#endif
68452+ return 1;
68453+}
68454+
68455+int
68456+gr_handle_chroot_nice(void)
68457+{
68458+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68459+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
68460+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
68461+ return -EPERM;
68462+ }
68463+#endif
68464+ return 0;
68465+}
68466+
68467+int
68468+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
68469+{
68470+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68471+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
68472+ && proc_is_chrooted(current)) {
68473+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
68474+ return -EACCES;
68475+ }
68476+#endif
68477+ return 0;
68478+}
68479+
68480+int
68481+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
68482+{
68483+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68484+ struct task_struct *p;
68485+ int ret = 0;
68486+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
68487+ return ret;
68488+
68489+ read_lock(&tasklist_lock);
68490+ do_each_pid_task(pid, type, p) {
68491+ if (!have_same_root(current, p)) {
68492+ ret = 1;
68493+ goto out;
68494+ }
68495+ } while_each_pid_task(pid, type, p);
68496+out:
68497+ read_unlock(&tasklist_lock);
68498+ return ret;
68499+#endif
68500+ return 0;
68501+}
68502+
68503+int
68504+gr_pid_is_chrooted(struct task_struct *p)
68505+{
68506+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68507+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
68508+ return 0;
68509+
68510+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
68511+ !have_same_root(current, p)) {
68512+ return 1;
68513+ }
68514+#endif
68515+ return 0;
68516+}
68517+
68518+EXPORT_SYMBOL(gr_pid_is_chrooted);
68519+
68520+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
68521+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
68522+{
68523+ struct path path, currentroot;
68524+ int ret = 0;
68525+
68526+ path.dentry = (struct dentry *)u_dentry;
68527+ path.mnt = (struct vfsmount *)u_mnt;
68528+ get_fs_root(current->fs, &currentroot);
68529+ if (path_is_under(&path, &currentroot))
68530+ ret = 1;
68531+ path_put(&currentroot);
68532+
68533+ return ret;
68534+}
68535+#endif
68536+
68537+int
68538+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
68539+{
68540+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
68541+ if (!grsec_enable_chroot_fchdir)
68542+ return 1;
68543+
68544+ if (!proc_is_chrooted(current))
68545+ return 1;
68546+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
68547+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
68548+ return 0;
68549+ }
68550+#endif
68551+ return 1;
68552+}
68553+
68554+int
68555+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68556+ const time_t shm_createtime)
68557+{
68558+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
68559+ struct task_struct *p;
68560+ time_t starttime;
68561+
68562+ if (unlikely(!grsec_enable_chroot_shmat))
68563+ return 1;
68564+
68565+ if (likely(!proc_is_chrooted(current)))
68566+ return 1;
68567+
68568+ rcu_read_lock();
68569+ read_lock(&tasklist_lock);
68570+
68571+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
68572+ starttime = p->start_time.tv_sec;
68573+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
68574+ if (have_same_root(current, p)) {
68575+ goto allow;
68576+ } else {
68577+ read_unlock(&tasklist_lock);
68578+ rcu_read_unlock();
68579+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68580+ return 0;
68581+ }
68582+ }
68583+ /* creator exited, pid reuse, fall through to next check */
68584+ }
68585+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
68586+ if (unlikely(!have_same_root(current, p))) {
68587+ read_unlock(&tasklist_lock);
68588+ rcu_read_unlock();
68589+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68590+ return 0;
68591+ }
68592+ }
68593+
68594+allow:
68595+ read_unlock(&tasklist_lock);
68596+ rcu_read_unlock();
68597+#endif
68598+ return 1;
68599+}
68600+
68601+void
68602+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
68603+{
68604+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
68605+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
68606+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
68607+#endif
68608+ return;
68609+}
68610+
68611+int
68612+gr_handle_chroot_mknod(const struct dentry *dentry,
68613+ const struct vfsmount *mnt, const int mode)
68614+{
68615+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
68616+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
68617+ proc_is_chrooted(current)) {
68618+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
68619+ return -EPERM;
68620+ }
68621+#endif
68622+ return 0;
68623+}
68624+
68625+int
68626+gr_handle_chroot_mount(const struct dentry *dentry,
68627+ const struct vfsmount *mnt, const char *dev_name)
68628+{
68629+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
68630+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
68631+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
68632+ return -EPERM;
68633+ }
68634+#endif
68635+ return 0;
68636+}
68637+
68638+int
68639+gr_handle_chroot_pivot(void)
68640+{
68641+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
68642+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
68643+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
68644+ return -EPERM;
68645+ }
68646+#endif
68647+ return 0;
68648+}
68649+
68650+int
68651+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
68652+{
68653+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
68654+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
68655+ !gr_is_outside_chroot(dentry, mnt)) {
68656+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
68657+ return -EPERM;
68658+ }
68659+#endif
68660+ return 0;
68661+}
68662+
68663+extern const char *captab_log[];
68664+extern int captab_log_entries;
68665+
68666+int
68667+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
68668+{
68669+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68670+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68671+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68672+ if (cap_raised(chroot_caps, cap)) {
68673+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
68674+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
68675+ }
68676+ return 0;
68677+ }
68678+ }
68679+#endif
68680+ return 1;
68681+}
68682+
68683+int
68684+gr_chroot_is_capable(const int cap)
68685+{
68686+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68687+ return gr_task_chroot_is_capable(current, current_cred(), cap);
68688+#endif
68689+ return 1;
68690+}
68691+
68692+int
68693+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
68694+{
68695+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68696+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68697+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68698+ if (cap_raised(chroot_caps, cap)) {
68699+ return 0;
68700+ }
68701+ }
68702+#endif
68703+ return 1;
68704+}
68705+
68706+int
68707+gr_chroot_is_capable_nolog(const int cap)
68708+{
68709+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68710+ return gr_task_chroot_is_capable_nolog(current, cap);
68711+#endif
68712+ return 1;
68713+}
68714+
68715+int
68716+gr_handle_chroot_sysctl(const int op)
68717+{
68718+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
68719+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
68720+ proc_is_chrooted(current))
68721+ return -EACCES;
68722+#endif
68723+ return 0;
68724+}
68725+
68726+void
68727+gr_handle_chroot_chdir(const struct path *path)
68728+{
68729+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
68730+ if (grsec_enable_chroot_chdir)
68731+ set_fs_pwd(current->fs, path);
68732+#endif
68733+ return;
68734+}
68735+
68736+int
68737+gr_handle_chroot_chmod(const struct dentry *dentry,
68738+ const struct vfsmount *mnt, const int mode)
68739+{
68740+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
68741+ /* allow chmod +s on directories, but not files */
68742+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
68743+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
68744+ proc_is_chrooted(current)) {
68745+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
68746+ return -EPERM;
68747+ }
68748+#endif
68749+ return 0;
68750+}
68751diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
68752new file mode 100644
68753index 0000000..ce65ceb
68754--- /dev/null
68755+++ b/grsecurity/grsec_disabled.c
68756@@ -0,0 +1,434 @@
68757+#include <linux/kernel.h>
68758+#include <linux/module.h>
68759+#include <linux/sched.h>
68760+#include <linux/file.h>
68761+#include <linux/fs.h>
68762+#include <linux/kdev_t.h>
68763+#include <linux/net.h>
68764+#include <linux/in.h>
68765+#include <linux/ip.h>
68766+#include <linux/skbuff.h>
68767+#include <linux/sysctl.h>
68768+
68769+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
68770+void
68771+pax_set_initial_flags(struct linux_binprm *bprm)
68772+{
68773+ return;
68774+}
68775+#endif
68776+
68777+#ifdef CONFIG_SYSCTL
68778+__u32
68779+gr_handle_sysctl(const struct ctl_table * table, const int op)
68780+{
68781+ return 0;
68782+}
68783+#endif
68784+
68785+#ifdef CONFIG_TASKSTATS
68786+int gr_is_taskstats_denied(int pid)
68787+{
68788+ return 0;
68789+}
68790+#endif
68791+
68792+int
68793+gr_acl_is_enabled(void)
68794+{
68795+ return 0;
68796+}
68797+
68798+void
68799+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68800+{
68801+ return;
68802+}
68803+
68804+int
68805+gr_handle_rawio(const struct inode *inode)
68806+{
68807+ return 0;
68808+}
68809+
68810+void
68811+gr_acl_handle_psacct(struct task_struct *task, const long code)
68812+{
68813+ return;
68814+}
68815+
68816+int
68817+gr_handle_ptrace(struct task_struct *task, const long request)
68818+{
68819+ return 0;
68820+}
68821+
68822+int
68823+gr_handle_proc_ptrace(struct task_struct *task)
68824+{
68825+ return 0;
68826+}
68827+
68828+int
68829+gr_set_acls(const int type)
68830+{
68831+ return 0;
68832+}
68833+
68834+int
68835+gr_check_hidden_task(const struct task_struct *tsk)
68836+{
68837+ return 0;
68838+}
68839+
68840+int
68841+gr_check_protected_task(const struct task_struct *task)
68842+{
68843+ return 0;
68844+}
68845+
68846+int
68847+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68848+{
68849+ return 0;
68850+}
68851+
68852+void
68853+gr_copy_label(struct task_struct *tsk)
68854+{
68855+ return;
68856+}
68857+
68858+void
68859+gr_set_pax_flags(struct task_struct *task)
68860+{
68861+ return;
68862+}
68863+
68864+int
68865+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68866+ const int unsafe_share)
68867+{
68868+ return 0;
68869+}
68870+
68871+void
68872+gr_handle_delete(const ino_t ino, const dev_t dev)
68873+{
68874+ return;
68875+}
68876+
68877+void
68878+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68879+{
68880+ return;
68881+}
68882+
68883+void
68884+gr_handle_crash(struct task_struct *task, const int sig)
68885+{
68886+ return;
68887+}
68888+
68889+int
68890+gr_check_crash_exec(const struct file *filp)
68891+{
68892+ return 0;
68893+}
68894+
68895+int
68896+gr_check_crash_uid(const kuid_t uid)
68897+{
68898+ return 0;
68899+}
68900+
68901+void
68902+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68903+ struct dentry *old_dentry,
68904+ struct dentry *new_dentry,
68905+ struct vfsmount *mnt, const __u8 replace)
68906+{
68907+ return;
68908+}
68909+
68910+int
68911+gr_search_socket(const int family, const int type, const int protocol)
68912+{
68913+ return 1;
68914+}
68915+
68916+int
68917+gr_search_connectbind(const int mode, const struct socket *sock,
68918+ const struct sockaddr_in *addr)
68919+{
68920+ return 0;
68921+}
68922+
68923+void
68924+gr_handle_alertkill(struct task_struct *task)
68925+{
68926+ return;
68927+}
68928+
68929+__u32
68930+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
68931+{
68932+ return 1;
68933+}
68934+
68935+__u32
68936+gr_acl_handle_hidden_file(const struct dentry * dentry,
68937+ const struct vfsmount * mnt)
68938+{
68939+ return 1;
68940+}
68941+
68942+__u32
68943+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
68944+ int acc_mode)
68945+{
68946+ return 1;
68947+}
68948+
68949+__u32
68950+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
68951+{
68952+ return 1;
68953+}
68954+
68955+__u32
68956+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
68957+{
68958+ return 1;
68959+}
68960+
68961+int
68962+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
68963+ unsigned int *vm_flags)
68964+{
68965+ return 1;
68966+}
68967+
68968+__u32
68969+gr_acl_handle_truncate(const struct dentry * dentry,
68970+ const struct vfsmount * mnt)
68971+{
68972+ return 1;
68973+}
68974+
68975+__u32
68976+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
68977+{
68978+ return 1;
68979+}
68980+
68981+__u32
68982+gr_acl_handle_access(const struct dentry * dentry,
68983+ const struct vfsmount * mnt, const int fmode)
68984+{
68985+ return 1;
68986+}
68987+
68988+__u32
68989+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
68990+ umode_t *mode)
68991+{
68992+ return 1;
68993+}
68994+
68995+__u32
68996+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
68997+{
68998+ return 1;
68999+}
69000+
69001+__u32
69002+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
69003+{
69004+ return 1;
69005+}
69006+
69007+void
69008+grsecurity_init(void)
69009+{
69010+ return;
69011+}
69012+
69013+umode_t gr_acl_umask(void)
69014+{
69015+ return 0;
69016+}
69017+
69018+__u32
69019+gr_acl_handle_mknod(const struct dentry * new_dentry,
69020+ const struct dentry * parent_dentry,
69021+ const struct vfsmount * parent_mnt,
69022+ const int mode)
69023+{
69024+ return 1;
69025+}
69026+
69027+__u32
69028+gr_acl_handle_mkdir(const struct dentry * new_dentry,
69029+ const struct dentry * parent_dentry,
69030+ const struct vfsmount * parent_mnt)
69031+{
69032+ return 1;
69033+}
69034+
69035+__u32
69036+gr_acl_handle_symlink(const struct dentry * new_dentry,
69037+ const struct dentry * parent_dentry,
69038+ const struct vfsmount * parent_mnt, const struct filename *from)
69039+{
69040+ return 1;
69041+}
69042+
69043+__u32
69044+gr_acl_handle_link(const struct dentry * new_dentry,
69045+ const struct dentry * parent_dentry,
69046+ const struct vfsmount * parent_mnt,
69047+ const struct dentry * old_dentry,
69048+ const struct vfsmount * old_mnt, const struct filename *to)
69049+{
69050+ return 1;
69051+}
69052+
69053+int
69054+gr_acl_handle_rename(const struct dentry *new_dentry,
69055+ const struct dentry *parent_dentry,
69056+ const struct vfsmount *parent_mnt,
69057+ const struct dentry *old_dentry,
69058+ const struct inode *old_parent_inode,
69059+ const struct vfsmount *old_mnt, const struct filename *newname)
69060+{
69061+ return 0;
69062+}
69063+
69064+int
69065+gr_acl_handle_filldir(const struct file *file, const char *name,
69066+ const int namelen, const ino_t ino)
69067+{
69068+ return 1;
69069+}
69070+
69071+int
69072+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69073+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
69074+{
69075+ return 1;
69076+}
69077+
69078+int
69079+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
69080+{
69081+ return 0;
69082+}
69083+
69084+int
69085+gr_search_accept(const struct socket *sock)
69086+{
69087+ return 0;
69088+}
69089+
69090+int
69091+gr_search_listen(const struct socket *sock)
69092+{
69093+ return 0;
69094+}
69095+
69096+int
69097+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
69098+{
69099+ return 0;
69100+}
69101+
69102+__u32
69103+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
69104+{
69105+ return 1;
69106+}
69107+
69108+__u32
69109+gr_acl_handle_creat(const struct dentry * dentry,
69110+ const struct dentry * p_dentry,
69111+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
69112+ const int imode)
69113+{
69114+ return 1;
69115+}
69116+
69117+void
69118+gr_acl_handle_exit(void)
69119+{
69120+ return;
69121+}
69122+
69123+int
69124+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69125+{
69126+ return 1;
69127+}
69128+
69129+void
69130+gr_set_role_label(const kuid_t uid, const kgid_t gid)
69131+{
69132+ return;
69133+}
69134+
69135+int
69136+gr_acl_handle_procpidmem(const struct task_struct *task)
69137+{
69138+ return 0;
69139+}
69140+
69141+int
69142+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
69143+{
69144+ return 0;
69145+}
69146+
69147+int
69148+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
69149+{
69150+ return 0;
69151+}
69152+
69153+void
69154+gr_set_kernel_label(struct task_struct *task)
69155+{
69156+ return;
69157+}
69158+
69159+int
69160+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
69161+{
69162+ return 0;
69163+}
69164+
69165+int
69166+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
69167+{
69168+ return 0;
69169+}
69170+
69171+int gr_acl_enable_at_secure(void)
69172+{
69173+ return 0;
69174+}
69175+
69176+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69177+{
69178+ return dentry->d_sb->s_dev;
69179+}
69180+
69181+void gr_put_exec_file(struct task_struct *task)
69182+{
69183+ return;
69184+}
69185+
69186+EXPORT_SYMBOL(gr_set_kernel_label);
69187+#ifdef CONFIG_SECURITY
69188+EXPORT_SYMBOL(gr_check_user_change);
69189+EXPORT_SYMBOL(gr_check_group_change);
69190+#endif
69191diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
69192new file mode 100644
69193index 0000000..387032b
69194--- /dev/null
69195+++ b/grsecurity/grsec_exec.c
69196@@ -0,0 +1,187 @@
69197+#include <linux/kernel.h>
69198+#include <linux/sched.h>
69199+#include <linux/file.h>
69200+#include <linux/binfmts.h>
69201+#include <linux/fs.h>
69202+#include <linux/types.h>
69203+#include <linux/grdefs.h>
69204+#include <linux/grsecurity.h>
69205+#include <linux/grinternal.h>
69206+#include <linux/capability.h>
69207+#include <linux/module.h>
69208+#include <linux/compat.h>
69209+
69210+#include <asm/uaccess.h>
69211+
69212+#ifdef CONFIG_GRKERNSEC_EXECLOG
69213+static char gr_exec_arg_buf[132];
69214+static DEFINE_MUTEX(gr_exec_arg_mutex);
69215+#endif
69216+
69217+struct user_arg_ptr {
69218+#ifdef CONFIG_COMPAT
69219+ bool is_compat;
69220+#endif
69221+ union {
69222+ const char __user *const __user *native;
69223+#ifdef CONFIG_COMPAT
69224+ const compat_uptr_t __user *compat;
69225+#endif
69226+ } ptr;
69227+};
69228+
69229+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
69230+
69231+void
69232+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
69233+{
69234+#ifdef CONFIG_GRKERNSEC_EXECLOG
69235+ char *grarg = gr_exec_arg_buf;
69236+ unsigned int i, x, execlen = 0;
69237+ char c;
69238+
69239+ if (!((grsec_enable_execlog && grsec_enable_group &&
69240+ in_group_p(grsec_audit_gid))
69241+ || (grsec_enable_execlog && !grsec_enable_group)))
69242+ return;
69243+
69244+ mutex_lock(&gr_exec_arg_mutex);
69245+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
69246+
69247+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
69248+ const char __user *p;
69249+ unsigned int len;
69250+
69251+ p = get_user_arg_ptr(argv, i);
69252+ if (IS_ERR(p))
69253+ goto log;
69254+
69255+ len = strnlen_user(p, 128 - execlen);
69256+ if (len > 128 - execlen)
69257+ len = 128 - execlen;
69258+ else if (len > 0)
69259+ len--;
69260+ if (copy_from_user(grarg + execlen, p, len))
69261+ goto log;
69262+
69263+ /* rewrite unprintable characters */
69264+ for (x = 0; x < len; x++) {
69265+ c = *(grarg + execlen + x);
69266+ if (c < 32 || c > 126)
69267+ *(grarg + execlen + x) = ' ';
69268+ }
69269+
69270+ execlen += len;
69271+ *(grarg + execlen) = ' ';
69272+ *(grarg + execlen + 1) = '\0';
69273+ execlen++;
69274+ }
69275+
69276+ log:
69277+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
69278+ bprm->file->f_path.mnt, grarg);
69279+ mutex_unlock(&gr_exec_arg_mutex);
69280+#endif
69281+ return;
69282+}
69283+
69284+#ifdef CONFIG_GRKERNSEC
69285+extern int gr_acl_is_capable(const int cap);
69286+extern int gr_acl_is_capable_nolog(const int cap);
69287+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69288+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
69289+extern int gr_chroot_is_capable(const int cap);
69290+extern int gr_chroot_is_capable_nolog(const int cap);
69291+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69292+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
69293+#endif
69294+
69295+const char *captab_log[] = {
69296+ "CAP_CHOWN",
69297+ "CAP_DAC_OVERRIDE",
69298+ "CAP_DAC_READ_SEARCH",
69299+ "CAP_FOWNER",
69300+ "CAP_FSETID",
69301+ "CAP_KILL",
69302+ "CAP_SETGID",
69303+ "CAP_SETUID",
69304+ "CAP_SETPCAP",
69305+ "CAP_LINUX_IMMUTABLE",
69306+ "CAP_NET_BIND_SERVICE",
69307+ "CAP_NET_BROADCAST",
69308+ "CAP_NET_ADMIN",
69309+ "CAP_NET_RAW",
69310+ "CAP_IPC_LOCK",
69311+ "CAP_IPC_OWNER",
69312+ "CAP_SYS_MODULE",
69313+ "CAP_SYS_RAWIO",
69314+ "CAP_SYS_CHROOT",
69315+ "CAP_SYS_PTRACE",
69316+ "CAP_SYS_PACCT",
69317+ "CAP_SYS_ADMIN",
69318+ "CAP_SYS_BOOT",
69319+ "CAP_SYS_NICE",
69320+ "CAP_SYS_RESOURCE",
69321+ "CAP_SYS_TIME",
69322+ "CAP_SYS_TTY_CONFIG",
69323+ "CAP_MKNOD",
69324+ "CAP_LEASE",
69325+ "CAP_AUDIT_WRITE",
69326+ "CAP_AUDIT_CONTROL",
69327+ "CAP_SETFCAP",
69328+ "CAP_MAC_OVERRIDE",
69329+ "CAP_MAC_ADMIN",
69330+ "CAP_SYSLOG",
69331+ "CAP_WAKE_ALARM"
69332+};
69333+
69334+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
69335+
69336+int gr_is_capable(const int cap)
69337+{
69338+#ifdef CONFIG_GRKERNSEC
69339+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
69340+ return 1;
69341+ return 0;
69342+#else
69343+ return 1;
69344+#endif
69345+}
69346+
69347+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69348+{
69349+#ifdef CONFIG_GRKERNSEC
69350+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
69351+ return 1;
69352+ return 0;
69353+#else
69354+ return 1;
69355+#endif
69356+}
69357+
69358+int gr_is_capable_nolog(const int cap)
69359+{
69360+#ifdef CONFIG_GRKERNSEC
69361+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
69362+ return 1;
69363+ return 0;
69364+#else
69365+ return 1;
69366+#endif
69367+}
69368+
69369+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
69370+{
69371+#ifdef CONFIG_GRKERNSEC
69372+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
69373+ return 1;
69374+ return 0;
69375+#else
69376+ return 1;
69377+#endif
69378+}
69379+
69380+EXPORT_SYMBOL(gr_is_capable);
69381+EXPORT_SYMBOL(gr_is_capable_nolog);
69382+EXPORT_SYMBOL(gr_task_is_capable);
69383+EXPORT_SYMBOL(gr_task_is_capable_nolog);
69384diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
69385new file mode 100644
69386index 0000000..06cc6ea
69387--- /dev/null
69388+++ b/grsecurity/grsec_fifo.c
69389@@ -0,0 +1,24 @@
69390+#include <linux/kernel.h>
69391+#include <linux/sched.h>
69392+#include <linux/fs.h>
69393+#include <linux/file.h>
69394+#include <linux/grinternal.h>
69395+
69396+int
69397+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
69398+ const struct dentry *dir, const int flag, const int acc_mode)
69399+{
69400+#ifdef CONFIG_GRKERNSEC_FIFO
69401+ const struct cred *cred = current_cred();
69402+
69403+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
69404+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
69405+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
69406+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
69407+ if (!inode_permission(dentry->d_inode, acc_mode))
69408+ 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));
69409+ return -EACCES;
69410+ }
69411+#endif
69412+ return 0;
69413+}
69414diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
69415new file mode 100644
69416index 0000000..8ca18bf
69417--- /dev/null
69418+++ b/grsecurity/grsec_fork.c
69419@@ -0,0 +1,23 @@
69420+#include <linux/kernel.h>
69421+#include <linux/sched.h>
69422+#include <linux/grsecurity.h>
69423+#include <linux/grinternal.h>
69424+#include <linux/errno.h>
69425+
69426+void
69427+gr_log_forkfail(const int retval)
69428+{
69429+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69430+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
69431+ switch (retval) {
69432+ case -EAGAIN:
69433+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
69434+ break;
69435+ case -ENOMEM:
69436+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
69437+ break;
69438+ }
69439+ }
69440+#endif
69441+ return;
69442+}
69443diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
69444new file mode 100644
69445index 0000000..99a0cb9
69446--- /dev/null
69447+++ b/grsecurity/grsec_init.c
69448@@ -0,0 +1,283 @@
69449+#include <linux/kernel.h>
69450+#include <linux/sched.h>
69451+#include <linux/mm.h>
69452+#include <linux/gracl.h>
69453+#include <linux/slab.h>
69454+#include <linux/vmalloc.h>
69455+#include <linux/percpu.h>
69456+#include <linux/module.h>
69457+
69458+int grsec_enable_ptrace_readexec;
69459+int grsec_enable_setxid;
69460+int grsec_enable_symlinkown;
69461+kgid_t grsec_symlinkown_gid;
69462+int grsec_enable_brute;
69463+int grsec_enable_link;
69464+int grsec_enable_dmesg;
69465+int grsec_enable_harden_ptrace;
69466+int grsec_enable_fifo;
69467+int grsec_enable_execlog;
69468+int grsec_enable_signal;
69469+int grsec_enable_forkfail;
69470+int grsec_enable_audit_ptrace;
69471+int grsec_enable_time;
69472+int grsec_enable_group;
69473+kgid_t grsec_audit_gid;
69474+int grsec_enable_chdir;
69475+int grsec_enable_mount;
69476+int grsec_enable_rofs;
69477+int grsec_deny_new_usb;
69478+int grsec_enable_chroot_findtask;
69479+int grsec_enable_chroot_mount;
69480+int grsec_enable_chroot_shmat;
69481+int grsec_enable_chroot_fchdir;
69482+int grsec_enable_chroot_double;
69483+int grsec_enable_chroot_pivot;
69484+int grsec_enable_chroot_chdir;
69485+int grsec_enable_chroot_chmod;
69486+int grsec_enable_chroot_mknod;
69487+int grsec_enable_chroot_nice;
69488+int grsec_enable_chroot_execlog;
69489+int grsec_enable_chroot_caps;
69490+int grsec_enable_chroot_sysctl;
69491+int grsec_enable_chroot_unix;
69492+int grsec_enable_tpe;
69493+kgid_t grsec_tpe_gid;
69494+int grsec_enable_blackhole;
69495+#ifdef CONFIG_IPV6_MODULE
69496+EXPORT_SYMBOL(grsec_enable_blackhole);
69497+#endif
69498+int grsec_lastack_retries;
69499+int grsec_enable_tpe_all;
69500+int grsec_enable_tpe_invert;
69501+int grsec_enable_socket_all;
69502+kgid_t grsec_socket_all_gid;
69503+int grsec_enable_socket_client;
69504+kgid_t grsec_socket_client_gid;
69505+int grsec_enable_socket_server;
69506+kgid_t grsec_socket_server_gid;
69507+int grsec_resource_logging;
69508+int grsec_disable_privio;
69509+int grsec_enable_log_rwxmaps;
69510+int grsec_lock;
69511+
69512+DEFINE_SPINLOCK(grsec_alert_lock);
69513+unsigned long grsec_alert_wtime = 0;
69514+unsigned long grsec_alert_fyet = 0;
69515+
69516+DEFINE_SPINLOCK(grsec_audit_lock);
69517+
69518+DEFINE_RWLOCK(grsec_exec_file_lock);
69519+
69520+char *gr_shared_page[4];
69521+
69522+char *gr_alert_log_fmt;
69523+char *gr_audit_log_fmt;
69524+char *gr_alert_log_buf;
69525+char *gr_audit_log_buf;
69526+
69527+extern struct gr_arg *gr_usermode;
69528+extern unsigned char *gr_system_salt;
69529+extern unsigned char *gr_system_sum;
69530+
69531+void __init
69532+grsecurity_init(void)
69533+{
69534+ int j;
69535+ /* create the per-cpu shared pages */
69536+
69537+#ifdef CONFIG_X86
69538+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
69539+#endif
69540+
69541+ for (j = 0; j < 4; j++) {
69542+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
69543+ if (gr_shared_page[j] == NULL) {
69544+ panic("Unable to allocate grsecurity shared page");
69545+ return;
69546+ }
69547+ }
69548+
69549+ /* allocate log buffers */
69550+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
69551+ if (!gr_alert_log_fmt) {
69552+ panic("Unable to allocate grsecurity alert log format buffer");
69553+ return;
69554+ }
69555+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
69556+ if (!gr_audit_log_fmt) {
69557+ panic("Unable to allocate grsecurity audit log format buffer");
69558+ return;
69559+ }
69560+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69561+ if (!gr_alert_log_buf) {
69562+ panic("Unable to allocate grsecurity alert log buffer");
69563+ return;
69564+ }
69565+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69566+ if (!gr_audit_log_buf) {
69567+ panic("Unable to allocate grsecurity audit log buffer");
69568+ return;
69569+ }
69570+
69571+ /* allocate memory for authentication structure */
69572+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
69573+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
69574+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
69575+
69576+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
69577+ panic("Unable to allocate grsecurity authentication structure");
69578+ return;
69579+ }
69580+
69581+
69582+#ifdef CONFIG_GRKERNSEC_IO
69583+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
69584+ grsec_disable_privio = 1;
69585+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69586+ grsec_disable_privio = 1;
69587+#else
69588+ grsec_disable_privio = 0;
69589+#endif
69590+#endif
69591+
69592+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
69593+ /* for backward compatibility, tpe_invert always defaults to on if
69594+ enabled in the kernel
69595+ */
69596+ grsec_enable_tpe_invert = 1;
69597+#endif
69598+
69599+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69600+#ifndef CONFIG_GRKERNSEC_SYSCTL
69601+ grsec_lock = 1;
69602+#endif
69603+
69604+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
69605+ grsec_enable_log_rwxmaps = 1;
69606+#endif
69607+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
69608+ grsec_enable_group = 1;
69609+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
69610+#endif
69611+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
69612+ grsec_enable_ptrace_readexec = 1;
69613+#endif
69614+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
69615+ grsec_enable_chdir = 1;
69616+#endif
69617+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69618+ grsec_enable_harden_ptrace = 1;
69619+#endif
69620+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
69621+ grsec_enable_mount = 1;
69622+#endif
69623+#ifdef CONFIG_GRKERNSEC_LINK
69624+ grsec_enable_link = 1;
69625+#endif
69626+#ifdef CONFIG_GRKERNSEC_BRUTE
69627+ grsec_enable_brute = 1;
69628+#endif
69629+#ifdef CONFIG_GRKERNSEC_DMESG
69630+ grsec_enable_dmesg = 1;
69631+#endif
69632+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
69633+ grsec_enable_blackhole = 1;
69634+ grsec_lastack_retries = 4;
69635+#endif
69636+#ifdef CONFIG_GRKERNSEC_FIFO
69637+ grsec_enable_fifo = 1;
69638+#endif
69639+#ifdef CONFIG_GRKERNSEC_EXECLOG
69640+ grsec_enable_execlog = 1;
69641+#endif
69642+#ifdef CONFIG_GRKERNSEC_SETXID
69643+ grsec_enable_setxid = 1;
69644+#endif
69645+#ifdef CONFIG_GRKERNSEC_SIGNAL
69646+ grsec_enable_signal = 1;
69647+#endif
69648+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69649+ grsec_enable_forkfail = 1;
69650+#endif
69651+#ifdef CONFIG_GRKERNSEC_TIME
69652+ grsec_enable_time = 1;
69653+#endif
69654+#ifdef CONFIG_GRKERNSEC_RESLOG
69655+ grsec_resource_logging = 1;
69656+#endif
69657+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69658+ grsec_enable_chroot_findtask = 1;
69659+#endif
69660+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
69661+ grsec_enable_chroot_unix = 1;
69662+#endif
69663+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
69664+ grsec_enable_chroot_mount = 1;
69665+#endif
69666+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
69667+ grsec_enable_chroot_fchdir = 1;
69668+#endif
69669+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
69670+ grsec_enable_chroot_shmat = 1;
69671+#endif
69672+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
69673+ grsec_enable_audit_ptrace = 1;
69674+#endif
69675+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
69676+ grsec_enable_chroot_double = 1;
69677+#endif
69678+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
69679+ grsec_enable_chroot_pivot = 1;
69680+#endif
69681+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
69682+ grsec_enable_chroot_chdir = 1;
69683+#endif
69684+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
69685+ grsec_enable_chroot_chmod = 1;
69686+#endif
69687+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
69688+ grsec_enable_chroot_mknod = 1;
69689+#endif
69690+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
69691+ grsec_enable_chroot_nice = 1;
69692+#endif
69693+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
69694+ grsec_enable_chroot_execlog = 1;
69695+#endif
69696+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69697+ grsec_enable_chroot_caps = 1;
69698+#endif
69699+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
69700+ grsec_enable_chroot_sysctl = 1;
69701+#endif
69702+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69703+ grsec_enable_symlinkown = 1;
69704+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
69705+#endif
69706+#ifdef CONFIG_GRKERNSEC_TPE
69707+ grsec_enable_tpe = 1;
69708+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
69709+#ifdef CONFIG_GRKERNSEC_TPE_ALL
69710+ grsec_enable_tpe_all = 1;
69711+#endif
69712+#endif
69713+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
69714+ grsec_enable_socket_all = 1;
69715+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
69716+#endif
69717+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
69718+ grsec_enable_socket_client = 1;
69719+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
69720+#endif
69721+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
69722+ grsec_enable_socket_server = 1;
69723+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
69724+#endif
69725+#endif
69726+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
69727+ grsec_deny_new_usb = 1;
69728+#endif
69729+
69730+ return;
69731+}
69732diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
69733new file mode 100644
69734index 0000000..5e05e20
69735--- /dev/null
69736+++ b/grsecurity/grsec_link.c
69737@@ -0,0 +1,58 @@
69738+#include <linux/kernel.h>
69739+#include <linux/sched.h>
69740+#include <linux/fs.h>
69741+#include <linux/file.h>
69742+#include <linux/grinternal.h>
69743+
69744+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
69745+{
69746+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69747+ const struct inode *link_inode = link->dentry->d_inode;
69748+
69749+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
69750+ /* ignore root-owned links, e.g. /proc/self */
69751+ gr_is_global_nonroot(link_inode->i_uid) && target &&
69752+ !uid_eq(link_inode->i_uid, target->i_uid)) {
69753+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
69754+ return 1;
69755+ }
69756+#endif
69757+ return 0;
69758+}
69759+
69760+int
69761+gr_handle_follow_link(const struct inode *parent,
69762+ const struct inode *inode,
69763+ const struct dentry *dentry, const struct vfsmount *mnt)
69764+{
69765+#ifdef CONFIG_GRKERNSEC_LINK
69766+ const struct cred *cred = current_cred();
69767+
69768+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
69769+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
69770+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
69771+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
69772+ return -EACCES;
69773+ }
69774+#endif
69775+ return 0;
69776+}
69777+
69778+int
69779+gr_handle_hardlink(const struct dentry *dentry,
69780+ const struct vfsmount *mnt,
69781+ struct inode *inode, const int mode, const struct filename *to)
69782+{
69783+#ifdef CONFIG_GRKERNSEC_LINK
69784+ const struct cred *cred = current_cred();
69785+
69786+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
69787+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
69788+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
69789+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
69790+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
69791+ return -EPERM;
69792+ }
69793+#endif
69794+ return 0;
69795+}
69796diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
69797new file mode 100644
69798index 0000000..dbe0a6b
69799--- /dev/null
69800+++ b/grsecurity/grsec_log.c
69801@@ -0,0 +1,341 @@
69802+#include <linux/kernel.h>
69803+#include <linux/sched.h>
69804+#include <linux/file.h>
69805+#include <linux/tty.h>
69806+#include <linux/fs.h>
69807+#include <linux/mm.h>
69808+#include <linux/grinternal.h>
69809+
69810+#ifdef CONFIG_TREE_PREEMPT_RCU
69811+#define DISABLE_PREEMPT() preempt_disable()
69812+#define ENABLE_PREEMPT() preempt_enable()
69813+#else
69814+#define DISABLE_PREEMPT()
69815+#define ENABLE_PREEMPT()
69816+#endif
69817+
69818+#define BEGIN_LOCKS(x) \
69819+ DISABLE_PREEMPT(); \
69820+ rcu_read_lock(); \
69821+ read_lock(&tasklist_lock); \
69822+ read_lock(&grsec_exec_file_lock); \
69823+ if (x != GR_DO_AUDIT) \
69824+ spin_lock(&grsec_alert_lock); \
69825+ else \
69826+ spin_lock(&grsec_audit_lock)
69827+
69828+#define END_LOCKS(x) \
69829+ if (x != GR_DO_AUDIT) \
69830+ spin_unlock(&grsec_alert_lock); \
69831+ else \
69832+ spin_unlock(&grsec_audit_lock); \
69833+ read_unlock(&grsec_exec_file_lock); \
69834+ read_unlock(&tasklist_lock); \
69835+ rcu_read_unlock(); \
69836+ ENABLE_PREEMPT(); \
69837+ if (x == GR_DONT_AUDIT) \
69838+ gr_handle_alertkill(current)
69839+
69840+enum {
69841+ FLOODING,
69842+ NO_FLOODING
69843+};
69844+
69845+extern char *gr_alert_log_fmt;
69846+extern char *gr_audit_log_fmt;
69847+extern char *gr_alert_log_buf;
69848+extern char *gr_audit_log_buf;
69849+
69850+static int gr_log_start(int audit)
69851+{
69852+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
69853+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
69854+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69855+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
69856+ unsigned long curr_secs = get_seconds();
69857+
69858+ if (audit == GR_DO_AUDIT)
69859+ goto set_fmt;
69860+
69861+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
69862+ grsec_alert_wtime = curr_secs;
69863+ grsec_alert_fyet = 0;
69864+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
69865+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
69866+ grsec_alert_fyet++;
69867+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
69868+ grsec_alert_wtime = curr_secs;
69869+ grsec_alert_fyet++;
69870+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
69871+ return FLOODING;
69872+ }
69873+ else return FLOODING;
69874+
69875+set_fmt:
69876+#endif
69877+ memset(buf, 0, PAGE_SIZE);
69878+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
69879+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
69880+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
69881+ } else if (current->signal->curr_ip) {
69882+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
69883+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
69884+ } else if (gr_acl_is_enabled()) {
69885+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
69886+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
69887+ } else {
69888+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
69889+ strcpy(buf, fmt);
69890+ }
69891+
69892+ return NO_FLOODING;
69893+}
69894+
69895+static void gr_log_middle(int audit, const char *msg, va_list ap)
69896+ __attribute__ ((format (printf, 2, 0)));
69897+
69898+static void gr_log_middle(int audit, const char *msg, va_list ap)
69899+{
69900+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69901+ unsigned int len = strlen(buf);
69902+
69903+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
69904+
69905+ return;
69906+}
69907+
69908+static void gr_log_middle_varargs(int audit, const char *msg, ...)
69909+ __attribute__ ((format (printf, 2, 3)));
69910+
69911+static void gr_log_middle_varargs(int audit, const char *msg, ...)
69912+{
69913+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69914+ unsigned int len = strlen(buf);
69915+ va_list ap;
69916+
69917+ va_start(ap, msg);
69918+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
69919+ va_end(ap);
69920+
69921+ return;
69922+}
69923+
69924+static void gr_log_end(int audit, int append_default)
69925+{
69926+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69927+ if (append_default) {
69928+ struct task_struct *task = current;
69929+ struct task_struct *parent = task->real_parent;
69930+ const struct cred *cred = __task_cred(task);
69931+ const struct cred *pcred = __task_cred(parent);
69932+ unsigned int len = strlen(buf);
69933+
69934+ 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));
69935+ }
69936+
69937+ printk("%s\n", buf);
69938+
69939+ return;
69940+}
69941+
69942+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
69943+{
69944+ int logtype;
69945+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
69946+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
69947+ void *voidptr = NULL;
69948+ int num1 = 0, num2 = 0;
69949+ unsigned long ulong1 = 0, ulong2 = 0;
69950+ struct dentry *dentry = NULL;
69951+ struct vfsmount *mnt = NULL;
69952+ struct file *file = NULL;
69953+ struct task_struct *task = NULL;
69954+ struct vm_area_struct *vma = NULL;
69955+ const struct cred *cred, *pcred;
69956+ va_list ap;
69957+
69958+ BEGIN_LOCKS(audit);
69959+ logtype = gr_log_start(audit);
69960+ if (logtype == FLOODING) {
69961+ END_LOCKS(audit);
69962+ return;
69963+ }
69964+ va_start(ap, argtypes);
69965+ switch (argtypes) {
69966+ case GR_TTYSNIFF:
69967+ task = va_arg(ap, struct task_struct *);
69968+ 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));
69969+ break;
69970+ case GR_SYSCTL_HIDDEN:
69971+ str1 = va_arg(ap, char *);
69972+ gr_log_middle_varargs(audit, msg, result, str1);
69973+ break;
69974+ case GR_RBAC:
69975+ dentry = va_arg(ap, struct dentry *);
69976+ mnt = va_arg(ap, struct vfsmount *);
69977+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
69978+ break;
69979+ case GR_RBAC_STR:
69980+ dentry = va_arg(ap, struct dentry *);
69981+ mnt = va_arg(ap, struct vfsmount *);
69982+ str1 = va_arg(ap, char *);
69983+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
69984+ break;
69985+ case GR_STR_RBAC:
69986+ str1 = va_arg(ap, char *);
69987+ dentry = va_arg(ap, struct dentry *);
69988+ mnt = va_arg(ap, struct vfsmount *);
69989+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
69990+ break;
69991+ case GR_RBAC_MODE2:
69992+ dentry = va_arg(ap, struct dentry *);
69993+ mnt = va_arg(ap, struct vfsmount *);
69994+ str1 = va_arg(ap, char *);
69995+ str2 = va_arg(ap, char *);
69996+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
69997+ break;
69998+ case GR_RBAC_MODE3:
69999+ dentry = va_arg(ap, struct dentry *);
70000+ mnt = va_arg(ap, struct vfsmount *);
70001+ str1 = va_arg(ap, char *);
70002+ str2 = va_arg(ap, char *);
70003+ str3 = va_arg(ap, char *);
70004+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
70005+ break;
70006+ case GR_FILENAME:
70007+ dentry = va_arg(ap, struct dentry *);
70008+ mnt = va_arg(ap, struct vfsmount *);
70009+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
70010+ break;
70011+ case GR_STR_FILENAME:
70012+ str1 = va_arg(ap, char *);
70013+ dentry = va_arg(ap, struct dentry *);
70014+ mnt = va_arg(ap, struct vfsmount *);
70015+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
70016+ break;
70017+ case GR_FILENAME_STR:
70018+ dentry = va_arg(ap, struct dentry *);
70019+ mnt = va_arg(ap, struct vfsmount *);
70020+ str1 = va_arg(ap, char *);
70021+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
70022+ break;
70023+ case GR_FILENAME_TWO_INT:
70024+ dentry = va_arg(ap, struct dentry *);
70025+ mnt = va_arg(ap, struct vfsmount *);
70026+ num1 = va_arg(ap, int);
70027+ num2 = va_arg(ap, int);
70028+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
70029+ break;
70030+ case GR_FILENAME_TWO_INT_STR:
70031+ dentry = va_arg(ap, struct dentry *);
70032+ mnt = va_arg(ap, struct vfsmount *);
70033+ num1 = va_arg(ap, int);
70034+ num2 = va_arg(ap, int);
70035+ str1 = va_arg(ap, char *);
70036+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
70037+ break;
70038+ case GR_TEXTREL:
70039+ file = va_arg(ap, struct file *);
70040+ ulong1 = va_arg(ap, unsigned long);
70041+ ulong2 = va_arg(ap, unsigned long);
70042+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
70043+ break;
70044+ case GR_PTRACE:
70045+ task = va_arg(ap, struct task_struct *);
70046+ 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));
70047+ break;
70048+ case GR_RESOURCE:
70049+ task = va_arg(ap, struct task_struct *);
70050+ cred = __task_cred(task);
70051+ pcred = __task_cred(task->real_parent);
70052+ ulong1 = va_arg(ap, unsigned long);
70053+ str1 = va_arg(ap, char *);
70054+ ulong2 = va_arg(ap, unsigned long);
70055+ 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));
70056+ break;
70057+ case GR_CAP:
70058+ task = va_arg(ap, struct task_struct *);
70059+ cred = __task_cred(task);
70060+ pcred = __task_cred(task->real_parent);
70061+ str1 = va_arg(ap, char *);
70062+ 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));
70063+ break;
70064+ case GR_SIG:
70065+ str1 = va_arg(ap, char *);
70066+ voidptr = va_arg(ap, void *);
70067+ gr_log_middle_varargs(audit, msg, str1, voidptr);
70068+ break;
70069+ case GR_SIG2:
70070+ task = va_arg(ap, struct task_struct *);
70071+ cred = __task_cred(task);
70072+ pcred = __task_cred(task->real_parent);
70073+ num1 = va_arg(ap, int);
70074+ 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));
70075+ break;
70076+ case GR_CRASH1:
70077+ task = va_arg(ap, struct task_struct *);
70078+ cred = __task_cred(task);
70079+ pcred = __task_cred(task->real_parent);
70080+ ulong1 = va_arg(ap, unsigned long);
70081+ 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);
70082+ break;
70083+ case GR_CRASH2:
70084+ task = va_arg(ap, struct task_struct *);
70085+ cred = __task_cred(task);
70086+ pcred = __task_cred(task->real_parent);
70087+ ulong1 = va_arg(ap, unsigned long);
70088+ 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);
70089+ break;
70090+ case GR_RWXMAP:
70091+ file = va_arg(ap, struct file *);
70092+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
70093+ break;
70094+ case GR_RWXMAPVMA:
70095+ vma = va_arg(ap, struct vm_area_struct *);
70096+ if (vma->vm_file)
70097+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
70098+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
70099+ str1 = "<stack>";
70100+ else if (vma->vm_start <= current->mm->brk &&
70101+ vma->vm_end >= current->mm->start_brk)
70102+ str1 = "<heap>";
70103+ else
70104+ str1 = "<anonymous mapping>";
70105+ gr_log_middle_varargs(audit, msg, str1);
70106+ break;
70107+ case GR_PSACCT:
70108+ {
70109+ unsigned int wday, cday;
70110+ __u8 whr, chr;
70111+ __u8 wmin, cmin;
70112+ __u8 wsec, csec;
70113+ char cur_tty[64] = { 0 };
70114+ char parent_tty[64] = { 0 };
70115+
70116+ task = va_arg(ap, struct task_struct *);
70117+ wday = va_arg(ap, unsigned int);
70118+ cday = va_arg(ap, unsigned int);
70119+ whr = va_arg(ap, int);
70120+ chr = va_arg(ap, int);
70121+ wmin = va_arg(ap, int);
70122+ cmin = va_arg(ap, int);
70123+ wsec = va_arg(ap, int);
70124+ csec = va_arg(ap, int);
70125+ ulong1 = va_arg(ap, unsigned long);
70126+ cred = __task_cred(task);
70127+ pcred = __task_cred(task->real_parent);
70128+
70129+ 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));
70130+ }
70131+ break;
70132+ default:
70133+ gr_log_middle(audit, msg, ap);
70134+ }
70135+ va_end(ap);
70136+ // these don't need DEFAULTSECARGS printed on the end
70137+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
70138+ gr_log_end(audit, 0);
70139+ else
70140+ gr_log_end(audit, 1);
70141+ END_LOCKS(audit);
70142+}
70143diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
70144new file mode 100644
70145index 0000000..f536303
70146--- /dev/null
70147+++ b/grsecurity/grsec_mem.c
70148@@ -0,0 +1,40 @@
70149+#include <linux/kernel.h>
70150+#include <linux/sched.h>
70151+#include <linux/mm.h>
70152+#include <linux/mman.h>
70153+#include <linux/grinternal.h>
70154+
70155+void
70156+gr_handle_ioperm(void)
70157+{
70158+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
70159+ return;
70160+}
70161+
70162+void
70163+gr_handle_iopl(void)
70164+{
70165+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
70166+ return;
70167+}
70168+
70169+void
70170+gr_handle_mem_readwrite(u64 from, u64 to)
70171+{
70172+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
70173+ return;
70174+}
70175+
70176+void
70177+gr_handle_vm86(void)
70178+{
70179+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
70180+ return;
70181+}
70182+
70183+void
70184+gr_log_badprocpid(const char *entry)
70185+{
70186+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
70187+ return;
70188+}
70189diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
70190new file mode 100644
70191index 0000000..2131422
70192--- /dev/null
70193+++ b/grsecurity/grsec_mount.c
70194@@ -0,0 +1,62 @@
70195+#include <linux/kernel.h>
70196+#include <linux/sched.h>
70197+#include <linux/mount.h>
70198+#include <linux/grsecurity.h>
70199+#include <linux/grinternal.h>
70200+
70201+void
70202+gr_log_remount(const char *devname, const int retval)
70203+{
70204+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70205+ if (grsec_enable_mount && (retval >= 0))
70206+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
70207+#endif
70208+ return;
70209+}
70210+
70211+void
70212+gr_log_unmount(const char *devname, const int retval)
70213+{
70214+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70215+ if (grsec_enable_mount && (retval >= 0))
70216+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
70217+#endif
70218+ return;
70219+}
70220+
70221+void
70222+gr_log_mount(const char *from, const char *to, const int retval)
70223+{
70224+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70225+ if (grsec_enable_mount && (retval >= 0))
70226+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
70227+#endif
70228+ return;
70229+}
70230+
70231+int
70232+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
70233+{
70234+#ifdef CONFIG_GRKERNSEC_ROFS
70235+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
70236+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
70237+ return -EPERM;
70238+ } else
70239+ return 0;
70240+#endif
70241+ return 0;
70242+}
70243+
70244+int
70245+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
70246+{
70247+#ifdef CONFIG_GRKERNSEC_ROFS
70248+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
70249+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
70250+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
70251+ return -EPERM;
70252+ } else
70253+ return 0;
70254+#endif
70255+ return 0;
70256+}
70257diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
70258new file mode 100644
70259index 0000000..6ee9d50
70260--- /dev/null
70261+++ b/grsecurity/grsec_pax.c
70262@@ -0,0 +1,45 @@
70263+#include <linux/kernel.h>
70264+#include <linux/sched.h>
70265+#include <linux/mm.h>
70266+#include <linux/file.h>
70267+#include <linux/grinternal.h>
70268+#include <linux/grsecurity.h>
70269+
70270+void
70271+gr_log_textrel(struct vm_area_struct * vma)
70272+{
70273+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70274+ if (grsec_enable_log_rwxmaps)
70275+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
70276+#endif
70277+ return;
70278+}
70279+
70280+void gr_log_ptgnustack(struct file *file)
70281+{
70282+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70283+ if (grsec_enable_log_rwxmaps)
70284+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
70285+#endif
70286+ return;
70287+}
70288+
70289+void
70290+gr_log_rwxmmap(struct file *file)
70291+{
70292+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70293+ if (grsec_enable_log_rwxmaps)
70294+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
70295+#endif
70296+ return;
70297+}
70298+
70299+void
70300+gr_log_rwxmprotect(struct vm_area_struct *vma)
70301+{
70302+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70303+ if (grsec_enable_log_rwxmaps)
70304+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
70305+#endif
70306+ return;
70307+}
70308diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
70309new file mode 100644
70310index 0000000..f7f29aa
70311--- /dev/null
70312+++ b/grsecurity/grsec_ptrace.c
70313@@ -0,0 +1,30 @@
70314+#include <linux/kernel.h>
70315+#include <linux/sched.h>
70316+#include <linux/grinternal.h>
70317+#include <linux/security.h>
70318+
70319+void
70320+gr_audit_ptrace(struct task_struct *task)
70321+{
70322+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
70323+ if (grsec_enable_audit_ptrace)
70324+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
70325+#endif
70326+ return;
70327+}
70328+
70329+int
70330+gr_ptrace_readexec(struct file *file, int unsafe_flags)
70331+{
70332+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70333+ const struct dentry *dentry = file->f_path.dentry;
70334+ const struct vfsmount *mnt = file->f_path.mnt;
70335+
70336+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
70337+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
70338+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
70339+ return -EACCES;
70340+ }
70341+#endif
70342+ return 0;
70343+}
70344diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
70345new file mode 100644
70346index 0000000..4e29cc7
70347--- /dev/null
70348+++ b/grsecurity/grsec_sig.c
70349@@ -0,0 +1,246 @@
70350+#include <linux/kernel.h>
70351+#include <linux/sched.h>
70352+#include <linux/fs.h>
70353+#include <linux/delay.h>
70354+#include <linux/grsecurity.h>
70355+#include <linux/grinternal.h>
70356+#include <linux/hardirq.h>
70357+
70358+char *signames[] = {
70359+ [SIGSEGV] = "Segmentation fault",
70360+ [SIGILL] = "Illegal instruction",
70361+ [SIGABRT] = "Abort",
70362+ [SIGBUS] = "Invalid alignment/Bus error"
70363+};
70364+
70365+void
70366+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
70367+{
70368+#ifdef CONFIG_GRKERNSEC_SIGNAL
70369+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
70370+ (sig == SIGABRT) || (sig == SIGBUS))) {
70371+ if (task_pid_nr(t) == task_pid_nr(current)) {
70372+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
70373+ } else {
70374+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
70375+ }
70376+ }
70377+#endif
70378+ return;
70379+}
70380+
70381+int
70382+gr_handle_signal(const struct task_struct *p, const int sig)
70383+{
70384+#ifdef CONFIG_GRKERNSEC
70385+ /* ignore the 0 signal for protected task checks */
70386+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
70387+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
70388+ return -EPERM;
70389+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
70390+ return -EPERM;
70391+ }
70392+#endif
70393+ return 0;
70394+}
70395+
70396+#ifdef CONFIG_GRKERNSEC
70397+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
70398+
70399+int gr_fake_force_sig(int sig, struct task_struct *t)
70400+{
70401+ unsigned long int flags;
70402+ int ret, blocked, ignored;
70403+ struct k_sigaction *action;
70404+
70405+ spin_lock_irqsave(&t->sighand->siglock, flags);
70406+ action = &t->sighand->action[sig-1];
70407+ ignored = action->sa.sa_handler == SIG_IGN;
70408+ blocked = sigismember(&t->blocked, sig);
70409+ if (blocked || ignored) {
70410+ action->sa.sa_handler = SIG_DFL;
70411+ if (blocked) {
70412+ sigdelset(&t->blocked, sig);
70413+ recalc_sigpending_and_wake(t);
70414+ }
70415+ }
70416+ if (action->sa.sa_handler == SIG_DFL)
70417+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
70418+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
70419+
70420+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
70421+
70422+ return ret;
70423+}
70424+#endif
70425+
70426+#ifdef CONFIG_GRKERNSEC_BRUTE
70427+#define GR_USER_BAN_TIME (15 * 60)
70428+#define GR_DAEMON_BRUTE_TIME (30 * 60)
70429+
70430+static int __get_dumpable(unsigned long mm_flags)
70431+{
70432+ int ret;
70433+
70434+ ret = mm_flags & MMF_DUMPABLE_MASK;
70435+ return (ret >= 2) ? 2 : ret;
70436+}
70437+#endif
70438+
70439+void gr_handle_brute_attach(unsigned long mm_flags)
70440+{
70441+#ifdef CONFIG_GRKERNSEC_BRUTE
70442+ struct task_struct *p = current;
70443+ kuid_t uid = GLOBAL_ROOT_UID;
70444+ int daemon = 0;
70445+
70446+ if (!grsec_enable_brute)
70447+ return;
70448+
70449+ rcu_read_lock();
70450+ read_lock(&tasklist_lock);
70451+ read_lock(&grsec_exec_file_lock);
70452+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
70453+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
70454+ p->real_parent->brute = 1;
70455+ daemon = 1;
70456+ } else {
70457+ const struct cred *cred = __task_cred(p), *cred2;
70458+ struct task_struct *tsk, *tsk2;
70459+
70460+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
70461+ struct user_struct *user;
70462+
70463+ uid = cred->uid;
70464+
70465+ /* this is put upon execution past expiration */
70466+ user = find_user(uid);
70467+ if (user == NULL)
70468+ goto unlock;
70469+ user->suid_banned = 1;
70470+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
70471+ if (user->suid_ban_expires == ~0UL)
70472+ user->suid_ban_expires--;
70473+
70474+ /* only kill other threads of the same binary, from the same user */
70475+ do_each_thread(tsk2, tsk) {
70476+ cred2 = __task_cred(tsk);
70477+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
70478+ gr_fake_force_sig(SIGKILL, tsk);
70479+ } while_each_thread(tsk2, tsk);
70480+ }
70481+ }
70482+unlock:
70483+ read_unlock(&grsec_exec_file_lock);
70484+ read_unlock(&tasklist_lock);
70485+ rcu_read_unlock();
70486+
70487+ if (gr_is_global_nonroot(uid))
70488+ 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);
70489+ else if (daemon)
70490+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
70491+
70492+#endif
70493+ return;
70494+}
70495+
70496+void gr_handle_brute_check(void)
70497+{
70498+#ifdef CONFIG_GRKERNSEC_BRUTE
70499+ struct task_struct *p = current;
70500+
70501+ if (unlikely(p->brute)) {
70502+ if (!grsec_enable_brute)
70503+ p->brute = 0;
70504+ else if (time_before(get_seconds(), p->brute_expires))
70505+ msleep(30 * 1000);
70506+ }
70507+#endif
70508+ return;
70509+}
70510+
70511+void gr_handle_kernel_exploit(void)
70512+{
70513+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70514+ const struct cred *cred;
70515+ struct task_struct *tsk, *tsk2;
70516+ struct user_struct *user;
70517+ kuid_t uid;
70518+
70519+ if (in_irq() || in_serving_softirq() || in_nmi())
70520+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
70521+
70522+ uid = current_uid();
70523+
70524+ if (gr_is_global_root(uid))
70525+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
70526+ else {
70527+ /* kill all the processes of this user, hold a reference
70528+ to their creds struct, and prevent them from creating
70529+ another process until system reset
70530+ */
70531+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
70532+ GR_GLOBAL_UID(uid));
70533+ /* we intentionally leak this ref */
70534+ user = get_uid(current->cred->user);
70535+ if (user)
70536+ user->kernel_banned = 1;
70537+
70538+ /* kill all processes of this user */
70539+ read_lock(&tasklist_lock);
70540+ do_each_thread(tsk2, tsk) {
70541+ cred = __task_cred(tsk);
70542+ if (uid_eq(cred->uid, uid))
70543+ gr_fake_force_sig(SIGKILL, tsk);
70544+ } while_each_thread(tsk2, tsk);
70545+ read_unlock(&tasklist_lock);
70546+ }
70547+#endif
70548+}
70549+
70550+#ifdef CONFIG_GRKERNSEC_BRUTE
70551+static bool suid_ban_expired(struct user_struct *user)
70552+{
70553+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
70554+ user->suid_banned = 0;
70555+ user->suid_ban_expires = 0;
70556+ free_uid(user);
70557+ return true;
70558+ }
70559+
70560+ return false;
70561+}
70562+#endif
70563+
70564+int gr_process_kernel_exec_ban(void)
70565+{
70566+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70567+ if (unlikely(current->cred->user->kernel_banned))
70568+ return -EPERM;
70569+#endif
70570+ return 0;
70571+}
70572+
70573+int gr_process_kernel_setuid_ban(struct user_struct *user)
70574+{
70575+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70576+ if (unlikely(user->kernel_banned))
70577+ gr_fake_force_sig(SIGKILL, current);
70578+#endif
70579+ return 0;
70580+}
70581+
70582+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
70583+{
70584+#ifdef CONFIG_GRKERNSEC_BRUTE
70585+ struct user_struct *user = current->cred->user;
70586+ if (unlikely(user->suid_banned)) {
70587+ if (suid_ban_expired(user))
70588+ return 0;
70589+ /* disallow execution of suid binaries only */
70590+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
70591+ return -EPERM;
70592+ }
70593+#endif
70594+ return 0;
70595+}
70596diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
70597new file mode 100644
70598index 0000000..4030d57
70599--- /dev/null
70600+++ b/grsecurity/grsec_sock.c
70601@@ -0,0 +1,244 @@
70602+#include <linux/kernel.h>
70603+#include <linux/module.h>
70604+#include <linux/sched.h>
70605+#include <linux/file.h>
70606+#include <linux/net.h>
70607+#include <linux/in.h>
70608+#include <linux/ip.h>
70609+#include <net/sock.h>
70610+#include <net/inet_sock.h>
70611+#include <linux/grsecurity.h>
70612+#include <linux/grinternal.h>
70613+#include <linux/gracl.h>
70614+
70615+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
70616+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
70617+
70618+EXPORT_SYMBOL(gr_search_udp_recvmsg);
70619+EXPORT_SYMBOL(gr_search_udp_sendmsg);
70620+
70621+#ifdef CONFIG_UNIX_MODULE
70622+EXPORT_SYMBOL(gr_acl_handle_unix);
70623+EXPORT_SYMBOL(gr_acl_handle_mknod);
70624+EXPORT_SYMBOL(gr_handle_chroot_unix);
70625+EXPORT_SYMBOL(gr_handle_create);
70626+#endif
70627+
70628+#ifdef CONFIG_GRKERNSEC
70629+#define gr_conn_table_size 32749
70630+struct conn_table_entry {
70631+ struct conn_table_entry *next;
70632+ struct signal_struct *sig;
70633+};
70634+
70635+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
70636+DEFINE_SPINLOCK(gr_conn_table_lock);
70637+
70638+extern const char * gr_socktype_to_name(unsigned char type);
70639+extern const char * gr_proto_to_name(unsigned char proto);
70640+extern const char * gr_sockfamily_to_name(unsigned char family);
70641+
70642+static __inline__ int
70643+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
70644+{
70645+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
70646+}
70647+
70648+static __inline__ int
70649+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
70650+ __u16 sport, __u16 dport)
70651+{
70652+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
70653+ sig->gr_sport == sport && sig->gr_dport == dport))
70654+ return 1;
70655+ else
70656+ return 0;
70657+}
70658+
70659+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
70660+{
70661+ struct conn_table_entry **match;
70662+ unsigned int index;
70663+
70664+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70665+ sig->gr_sport, sig->gr_dport,
70666+ gr_conn_table_size);
70667+
70668+ newent->sig = sig;
70669+
70670+ match = &gr_conn_table[index];
70671+ newent->next = *match;
70672+ *match = newent;
70673+
70674+ return;
70675+}
70676+
70677+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
70678+{
70679+ struct conn_table_entry *match, *last = NULL;
70680+ unsigned int index;
70681+
70682+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70683+ sig->gr_sport, sig->gr_dport,
70684+ gr_conn_table_size);
70685+
70686+ match = gr_conn_table[index];
70687+ while (match && !conn_match(match->sig,
70688+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
70689+ sig->gr_dport)) {
70690+ last = match;
70691+ match = match->next;
70692+ }
70693+
70694+ if (match) {
70695+ if (last)
70696+ last->next = match->next;
70697+ else
70698+ gr_conn_table[index] = NULL;
70699+ kfree(match);
70700+ }
70701+
70702+ return;
70703+}
70704+
70705+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
70706+ __u16 sport, __u16 dport)
70707+{
70708+ struct conn_table_entry *match;
70709+ unsigned int index;
70710+
70711+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
70712+
70713+ match = gr_conn_table[index];
70714+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
70715+ match = match->next;
70716+
70717+ if (match)
70718+ return match->sig;
70719+ else
70720+ return NULL;
70721+}
70722+
70723+#endif
70724+
70725+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
70726+{
70727+#ifdef CONFIG_GRKERNSEC
70728+ struct signal_struct *sig = task->signal;
70729+ struct conn_table_entry *newent;
70730+
70731+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
70732+ if (newent == NULL)
70733+ return;
70734+ /* no bh lock needed since we are called with bh disabled */
70735+ spin_lock(&gr_conn_table_lock);
70736+ gr_del_task_from_ip_table_nolock(sig);
70737+ sig->gr_saddr = inet->inet_rcv_saddr;
70738+ sig->gr_daddr = inet->inet_daddr;
70739+ sig->gr_sport = inet->inet_sport;
70740+ sig->gr_dport = inet->inet_dport;
70741+ gr_add_to_task_ip_table_nolock(sig, newent);
70742+ spin_unlock(&gr_conn_table_lock);
70743+#endif
70744+ return;
70745+}
70746+
70747+void gr_del_task_from_ip_table(struct task_struct *task)
70748+{
70749+#ifdef CONFIG_GRKERNSEC
70750+ spin_lock_bh(&gr_conn_table_lock);
70751+ gr_del_task_from_ip_table_nolock(task->signal);
70752+ spin_unlock_bh(&gr_conn_table_lock);
70753+#endif
70754+ return;
70755+}
70756+
70757+void
70758+gr_attach_curr_ip(const struct sock *sk)
70759+{
70760+#ifdef CONFIG_GRKERNSEC
70761+ struct signal_struct *p, *set;
70762+ const struct inet_sock *inet = inet_sk(sk);
70763+
70764+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
70765+ return;
70766+
70767+ set = current->signal;
70768+
70769+ spin_lock_bh(&gr_conn_table_lock);
70770+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
70771+ inet->inet_dport, inet->inet_sport);
70772+ if (unlikely(p != NULL)) {
70773+ set->curr_ip = p->curr_ip;
70774+ set->used_accept = 1;
70775+ gr_del_task_from_ip_table_nolock(p);
70776+ spin_unlock_bh(&gr_conn_table_lock);
70777+ return;
70778+ }
70779+ spin_unlock_bh(&gr_conn_table_lock);
70780+
70781+ set->curr_ip = inet->inet_daddr;
70782+ set->used_accept = 1;
70783+#endif
70784+ return;
70785+}
70786+
70787+int
70788+gr_handle_sock_all(const int family, const int type, const int protocol)
70789+{
70790+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
70791+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
70792+ (family != AF_UNIX)) {
70793+ if (family == AF_INET)
70794+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
70795+ else
70796+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
70797+ return -EACCES;
70798+ }
70799+#endif
70800+ return 0;
70801+}
70802+
70803+int
70804+gr_handle_sock_server(const struct sockaddr *sck)
70805+{
70806+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70807+ if (grsec_enable_socket_server &&
70808+ in_group_p(grsec_socket_server_gid) &&
70809+ sck && (sck->sa_family != AF_UNIX) &&
70810+ (sck->sa_family != AF_LOCAL)) {
70811+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70812+ return -EACCES;
70813+ }
70814+#endif
70815+ return 0;
70816+}
70817+
70818+int
70819+gr_handle_sock_server_other(const struct sock *sck)
70820+{
70821+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70822+ if (grsec_enable_socket_server &&
70823+ in_group_p(grsec_socket_server_gid) &&
70824+ sck && (sck->sk_family != AF_UNIX) &&
70825+ (sck->sk_family != AF_LOCAL)) {
70826+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70827+ return -EACCES;
70828+ }
70829+#endif
70830+ return 0;
70831+}
70832+
70833+int
70834+gr_handle_sock_client(const struct sockaddr *sck)
70835+{
70836+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
70837+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
70838+ sck && (sck->sa_family != AF_UNIX) &&
70839+ (sck->sa_family != AF_LOCAL)) {
70840+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
70841+ return -EACCES;
70842+ }
70843+#endif
70844+ return 0;
70845+}
70846diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
70847new file mode 100644
70848index 0000000..a147ae7
70849--- /dev/null
70850+++ b/grsecurity/grsec_sysctl.c
70851@@ -0,0 +1,470 @@
70852+#include <linux/kernel.h>
70853+#include <linux/sched.h>
70854+#include <linux/sysctl.h>
70855+#include <linux/grsecurity.h>
70856+#include <linux/grinternal.h>
70857+
70858+int
70859+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
70860+{
70861+#ifdef CONFIG_GRKERNSEC_SYSCTL
70862+ if (dirname == NULL || name == NULL)
70863+ return 0;
70864+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
70865+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
70866+ return -EACCES;
70867+ }
70868+#endif
70869+ return 0;
70870+}
70871+
70872+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
70873+static int __maybe_unused __read_only one = 1;
70874+#endif
70875+
70876+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
70877+ defined(CONFIG_GRKERNSEC_DENYUSB)
70878+struct ctl_table grsecurity_table[] = {
70879+#ifdef CONFIG_GRKERNSEC_SYSCTL
70880+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
70881+#ifdef CONFIG_GRKERNSEC_IO
70882+ {
70883+ .procname = "disable_priv_io",
70884+ .data = &grsec_disable_privio,
70885+ .maxlen = sizeof(int),
70886+ .mode = 0600,
70887+ .proc_handler = &proc_dointvec,
70888+ },
70889+#endif
70890+#endif
70891+#ifdef CONFIG_GRKERNSEC_LINK
70892+ {
70893+ .procname = "linking_restrictions",
70894+ .data = &grsec_enable_link,
70895+ .maxlen = sizeof(int),
70896+ .mode = 0600,
70897+ .proc_handler = &proc_dointvec,
70898+ },
70899+#endif
70900+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
70901+ {
70902+ .procname = "enforce_symlinksifowner",
70903+ .data = &grsec_enable_symlinkown,
70904+ .maxlen = sizeof(int),
70905+ .mode = 0600,
70906+ .proc_handler = &proc_dointvec,
70907+ },
70908+ {
70909+ .procname = "symlinkown_gid",
70910+ .data = &grsec_symlinkown_gid,
70911+ .maxlen = sizeof(int),
70912+ .mode = 0600,
70913+ .proc_handler = &proc_dointvec,
70914+ },
70915+#endif
70916+#ifdef CONFIG_GRKERNSEC_BRUTE
70917+ {
70918+ .procname = "deter_bruteforce",
70919+ .data = &grsec_enable_brute,
70920+ .maxlen = sizeof(int),
70921+ .mode = 0600,
70922+ .proc_handler = &proc_dointvec,
70923+ },
70924+#endif
70925+#ifdef CONFIG_GRKERNSEC_FIFO
70926+ {
70927+ .procname = "fifo_restrictions",
70928+ .data = &grsec_enable_fifo,
70929+ .maxlen = sizeof(int),
70930+ .mode = 0600,
70931+ .proc_handler = &proc_dointvec,
70932+ },
70933+#endif
70934+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70935+ {
70936+ .procname = "ptrace_readexec",
70937+ .data = &grsec_enable_ptrace_readexec,
70938+ .maxlen = sizeof(int),
70939+ .mode = 0600,
70940+ .proc_handler = &proc_dointvec,
70941+ },
70942+#endif
70943+#ifdef CONFIG_GRKERNSEC_SETXID
70944+ {
70945+ .procname = "consistent_setxid",
70946+ .data = &grsec_enable_setxid,
70947+ .maxlen = sizeof(int),
70948+ .mode = 0600,
70949+ .proc_handler = &proc_dointvec,
70950+ },
70951+#endif
70952+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
70953+ {
70954+ .procname = "ip_blackhole",
70955+ .data = &grsec_enable_blackhole,
70956+ .maxlen = sizeof(int),
70957+ .mode = 0600,
70958+ .proc_handler = &proc_dointvec,
70959+ },
70960+ {
70961+ .procname = "lastack_retries",
70962+ .data = &grsec_lastack_retries,
70963+ .maxlen = sizeof(int),
70964+ .mode = 0600,
70965+ .proc_handler = &proc_dointvec,
70966+ },
70967+#endif
70968+#ifdef CONFIG_GRKERNSEC_EXECLOG
70969+ {
70970+ .procname = "exec_logging",
70971+ .data = &grsec_enable_execlog,
70972+ .maxlen = sizeof(int),
70973+ .mode = 0600,
70974+ .proc_handler = &proc_dointvec,
70975+ },
70976+#endif
70977+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70978+ {
70979+ .procname = "rwxmap_logging",
70980+ .data = &grsec_enable_log_rwxmaps,
70981+ .maxlen = sizeof(int),
70982+ .mode = 0600,
70983+ .proc_handler = &proc_dointvec,
70984+ },
70985+#endif
70986+#ifdef CONFIG_GRKERNSEC_SIGNAL
70987+ {
70988+ .procname = "signal_logging",
70989+ .data = &grsec_enable_signal,
70990+ .maxlen = sizeof(int),
70991+ .mode = 0600,
70992+ .proc_handler = &proc_dointvec,
70993+ },
70994+#endif
70995+#ifdef CONFIG_GRKERNSEC_FORKFAIL
70996+ {
70997+ .procname = "forkfail_logging",
70998+ .data = &grsec_enable_forkfail,
70999+ .maxlen = sizeof(int),
71000+ .mode = 0600,
71001+ .proc_handler = &proc_dointvec,
71002+ },
71003+#endif
71004+#ifdef CONFIG_GRKERNSEC_TIME
71005+ {
71006+ .procname = "timechange_logging",
71007+ .data = &grsec_enable_time,
71008+ .maxlen = sizeof(int),
71009+ .mode = 0600,
71010+ .proc_handler = &proc_dointvec,
71011+ },
71012+#endif
71013+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
71014+ {
71015+ .procname = "chroot_deny_shmat",
71016+ .data = &grsec_enable_chroot_shmat,
71017+ .maxlen = sizeof(int),
71018+ .mode = 0600,
71019+ .proc_handler = &proc_dointvec,
71020+ },
71021+#endif
71022+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
71023+ {
71024+ .procname = "chroot_deny_unix",
71025+ .data = &grsec_enable_chroot_unix,
71026+ .maxlen = sizeof(int),
71027+ .mode = 0600,
71028+ .proc_handler = &proc_dointvec,
71029+ },
71030+#endif
71031+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
71032+ {
71033+ .procname = "chroot_deny_mount",
71034+ .data = &grsec_enable_chroot_mount,
71035+ .maxlen = sizeof(int),
71036+ .mode = 0600,
71037+ .proc_handler = &proc_dointvec,
71038+ },
71039+#endif
71040+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
71041+ {
71042+ .procname = "chroot_deny_fchdir",
71043+ .data = &grsec_enable_chroot_fchdir,
71044+ .maxlen = sizeof(int),
71045+ .mode = 0600,
71046+ .proc_handler = &proc_dointvec,
71047+ },
71048+#endif
71049+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
71050+ {
71051+ .procname = "chroot_deny_chroot",
71052+ .data = &grsec_enable_chroot_double,
71053+ .maxlen = sizeof(int),
71054+ .mode = 0600,
71055+ .proc_handler = &proc_dointvec,
71056+ },
71057+#endif
71058+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
71059+ {
71060+ .procname = "chroot_deny_pivot",
71061+ .data = &grsec_enable_chroot_pivot,
71062+ .maxlen = sizeof(int),
71063+ .mode = 0600,
71064+ .proc_handler = &proc_dointvec,
71065+ },
71066+#endif
71067+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
71068+ {
71069+ .procname = "chroot_enforce_chdir",
71070+ .data = &grsec_enable_chroot_chdir,
71071+ .maxlen = sizeof(int),
71072+ .mode = 0600,
71073+ .proc_handler = &proc_dointvec,
71074+ },
71075+#endif
71076+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
71077+ {
71078+ .procname = "chroot_deny_chmod",
71079+ .data = &grsec_enable_chroot_chmod,
71080+ .maxlen = sizeof(int),
71081+ .mode = 0600,
71082+ .proc_handler = &proc_dointvec,
71083+ },
71084+#endif
71085+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
71086+ {
71087+ .procname = "chroot_deny_mknod",
71088+ .data = &grsec_enable_chroot_mknod,
71089+ .maxlen = sizeof(int),
71090+ .mode = 0600,
71091+ .proc_handler = &proc_dointvec,
71092+ },
71093+#endif
71094+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
71095+ {
71096+ .procname = "chroot_restrict_nice",
71097+ .data = &grsec_enable_chroot_nice,
71098+ .maxlen = sizeof(int),
71099+ .mode = 0600,
71100+ .proc_handler = &proc_dointvec,
71101+ },
71102+#endif
71103+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
71104+ {
71105+ .procname = "chroot_execlog",
71106+ .data = &grsec_enable_chroot_execlog,
71107+ .maxlen = sizeof(int),
71108+ .mode = 0600,
71109+ .proc_handler = &proc_dointvec,
71110+ },
71111+#endif
71112+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
71113+ {
71114+ .procname = "chroot_caps",
71115+ .data = &grsec_enable_chroot_caps,
71116+ .maxlen = sizeof(int),
71117+ .mode = 0600,
71118+ .proc_handler = &proc_dointvec,
71119+ },
71120+#endif
71121+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
71122+ {
71123+ .procname = "chroot_deny_sysctl",
71124+ .data = &grsec_enable_chroot_sysctl,
71125+ .maxlen = sizeof(int),
71126+ .mode = 0600,
71127+ .proc_handler = &proc_dointvec,
71128+ },
71129+#endif
71130+#ifdef CONFIG_GRKERNSEC_TPE
71131+ {
71132+ .procname = "tpe",
71133+ .data = &grsec_enable_tpe,
71134+ .maxlen = sizeof(int),
71135+ .mode = 0600,
71136+ .proc_handler = &proc_dointvec,
71137+ },
71138+ {
71139+ .procname = "tpe_gid",
71140+ .data = &grsec_tpe_gid,
71141+ .maxlen = sizeof(int),
71142+ .mode = 0600,
71143+ .proc_handler = &proc_dointvec,
71144+ },
71145+#endif
71146+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71147+ {
71148+ .procname = "tpe_invert",
71149+ .data = &grsec_enable_tpe_invert,
71150+ .maxlen = sizeof(int),
71151+ .mode = 0600,
71152+ .proc_handler = &proc_dointvec,
71153+ },
71154+#endif
71155+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71156+ {
71157+ .procname = "tpe_restrict_all",
71158+ .data = &grsec_enable_tpe_all,
71159+ .maxlen = sizeof(int),
71160+ .mode = 0600,
71161+ .proc_handler = &proc_dointvec,
71162+ },
71163+#endif
71164+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
71165+ {
71166+ .procname = "socket_all",
71167+ .data = &grsec_enable_socket_all,
71168+ .maxlen = sizeof(int),
71169+ .mode = 0600,
71170+ .proc_handler = &proc_dointvec,
71171+ },
71172+ {
71173+ .procname = "socket_all_gid",
71174+ .data = &grsec_socket_all_gid,
71175+ .maxlen = sizeof(int),
71176+ .mode = 0600,
71177+ .proc_handler = &proc_dointvec,
71178+ },
71179+#endif
71180+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
71181+ {
71182+ .procname = "socket_client",
71183+ .data = &grsec_enable_socket_client,
71184+ .maxlen = sizeof(int),
71185+ .mode = 0600,
71186+ .proc_handler = &proc_dointvec,
71187+ },
71188+ {
71189+ .procname = "socket_client_gid",
71190+ .data = &grsec_socket_client_gid,
71191+ .maxlen = sizeof(int),
71192+ .mode = 0600,
71193+ .proc_handler = &proc_dointvec,
71194+ },
71195+#endif
71196+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
71197+ {
71198+ .procname = "socket_server",
71199+ .data = &grsec_enable_socket_server,
71200+ .maxlen = sizeof(int),
71201+ .mode = 0600,
71202+ .proc_handler = &proc_dointvec,
71203+ },
71204+ {
71205+ .procname = "socket_server_gid",
71206+ .data = &grsec_socket_server_gid,
71207+ .maxlen = sizeof(int),
71208+ .mode = 0600,
71209+ .proc_handler = &proc_dointvec,
71210+ },
71211+#endif
71212+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
71213+ {
71214+ .procname = "audit_group",
71215+ .data = &grsec_enable_group,
71216+ .maxlen = sizeof(int),
71217+ .mode = 0600,
71218+ .proc_handler = &proc_dointvec,
71219+ },
71220+ {
71221+ .procname = "audit_gid",
71222+ .data = &grsec_audit_gid,
71223+ .maxlen = sizeof(int),
71224+ .mode = 0600,
71225+ .proc_handler = &proc_dointvec,
71226+ },
71227+#endif
71228+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
71229+ {
71230+ .procname = "audit_chdir",
71231+ .data = &grsec_enable_chdir,
71232+ .maxlen = sizeof(int),
71233+ .mode = 0600,
71234+ .proc_handler = &proc_dointvec,
71235+ },
71236+#endif
71237+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71238+ {
71239+ .procname = "audit_mount",
71240+ .data = &grsec_enable_mount,
71241+ .maxlen = sizeof(int),
71242+ .mode = 0600,
71243+ .proc_handler = &proc_dointvec,
71244+ },
71245+#endif
71246+#ifdef CONFIG_GRKERNSEC_DMESG
71247+ {
71248+ .procname = "dmesg",
71249+ .data = &grsec_enable_dmesg,
71250+ .maxlen = sizeof(int),
71251+ .mode = 0600,
71252+ .proc_handler = &proc_dointvec,
71253+ },
71254+#endif
71255+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71256+ {
71257+ .procname = "chroot_findtask",
71258+ .data = &grsec_enable_chroot_findtask,
71259+ .maxlen = sizeof(int),
71260+ .mode = 0600,
71261+ .proc_handler = &proc_dointvec,
71262+ },
71263+#endif
71264+#ifdef CONFIG_GRKERNSEC_RESLOG
71265+ {
71266+ .procname = "resource_logging",
71267+ .data = &grsec_resource_logging,
71268+ .maxlen = sizeof(int),
71269+ .mode = 0600,
71270+ .proc_handler = &proc_dointvec,
71271+ },
71272+#endif
71273+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
71274+ {
71275+ .procname = "audit_ptrace",
71276+ .data = &grsec_enable_audit_ptrace,
71277+ .maxlen = sizeof(int),
71278+ .mode = 0600,
71279+ .proc_handler = &proc_dointvec,
71280+ },
71281+#endif
71282+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71283+ {
71284+ .procname = "harden_ptrace",
71285+ .data = &grsec_enable_harden_ptrace,
71286+ .maxlen = sizeof(int),
71287+ .mode = 0600,
71288+ .proc_handler = &proc_dointvec,
71289+ },
71290+#endif
71291+ {
71292+ .procname = "grsec_lock",
71293+ .data = &grsec_lock,
71294+ .maxlen = sizeof(int),
71295+ .mode = 0600,
71296+ .proc_handler = &proc_dointvec,
71297+ },
71298+#endif
71299+#ifdef CONFIG_GRKERNSEC_ROFS
71300+ {
71301+ .procname = "romount_protect",
71302+ .data = &grsec_enable_rofs,
71303+ .maxlen = sizeof(int),
71304+ .mode = 0600,
71305+ .proc_handler = &proc_dointvec_minmax,
71306+ .extra1 = &one,
71307+ .extra2 = &one,
71308+ },
71309+#endif
71310+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
71311+ {
71312+ .procname = "deny_new_usb",
71313+ .data = &grsec_deny_new_usb,
71314+ .maxlen = sizeof(int),
71315+ .mode = 0600,
71316+ .proc_handler = &proc_dointvec,
71317+ },
71318+#endif
71319+ { }
71320+};
71321+#endif
71322diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
71323new file mode 100644
71324index 0000000..0dc13c3
71325--- /dev/null
71326+++ b/grsecurity/grsec_time.c
71327@@ -0,0 +1,16 @@
71328+#include <linux/kernel.h>
71329+#include <linux/sched.h>
71330+#include <linux/grinternal.h>
71331+#include <linux/module.h>
71332+
71333+void
71334+gr_log_timechange(void)
71335+{
71336+#ifdef CONFIG_GRKERNSEC_TIME
71337+ if (grsec_enable_time)
71338+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
71339+#endif
71340+ return;
71341+}
71342+
71343+EXPORT_SYMBOL(gr_log_timechange);
71344diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
71345new file mode 100644
71346index 0000000..ee57dcf
71347--- /dev/null
71348+++ b/grsecurity/grsec_tpe.c
71349@@ -0,0 +1,73 @@
71350+#include <linux/kernel.h>
71351+#include <linux/sched.h>
71352+#include <linux/file.h>
71353+#include <linux/fs.h>
71354+#include <linux/grinternal.h>
71355+
71356+extern int gr_acl_tpe_check(void);
71357+
71358+int
71359+gr_tpe_allow(const struct file *file)
71360+{
71361+#ifdef CONFIG_GRKERNSEC
71362+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
71363+ const struct cred *cred = current_cred();
71364+ char *msg = NULL;
71365+ char *msg2 = NULL;
71366+
71367+ // never restrict root
71368+ if (gr_is_global_root(cred->uid))
71369+ return 1;
71370+
71371+ if (grsec_enable_tpe) {
71372+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71373+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
71374+ msg = "not being in trusted group";
71375+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
71376+ msg = "being in untrusted group";
71377+#else
71378+ if (in_group_p(grsec_tpe_gid))
71379+ msg = "being in untrusted group";
71380+#endif
71381+ }
71382+ if (!msg && gr_acl_tpe_check())
71383+ msg = "being in untrusted role";
71384+
71385+ // not in any affected group/role
71386+ if (!msg)
71387+ goto next_check;
71388+
71389+ if (gr_is_global_nonroot(inode->i_uid))
71390+ msg2 = "file in non-root-owned directory";
71391+ else if (inode->i_mode & S_IWOTH)
71392+ msg2 = "file in world-writable directory";
71393+ else if (inode->i_mode & S_IWGRP)
71394+ msg2 = "file in group-writable directory";
71395+
71396+ if (msg && msg2) {
71397+ char fullmsg[70] = {0};
71398+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
71399+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
71400+ return 0;
71401+ }
71402+ msg = NULL;
71403+next_check:
71404+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71405+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
71406+ return 1;
71407+
71408+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
71409+ msg = "directory not owned by user";
71410+ else if (inode->i_mode & S_IWOTH)
71411+ msg = "file in world-writable directory";
71412+ else if (inode->i_mode & S_IWGRP)
71413+ msg = "file in group-writable directory";
71414+
71415+ if (msg) {
71416+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
71417+ return 0;
71418+ }
71419+#endif
71420+#endif
71421+ return 1;
71422+}
71423diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
71424new file mode 100644
71425index 0000000..ae02d8e
71426--- /dev/null
71427+++ b/grsecurity/grsec_usb.c
71428@@ -0,0 +1,15 @@
71429+#include <linux/kernel.h>
71430+#include <linux/grinternal.h>
71431+#include <linux/module.h>
71432+
71433+int gr_handle_new_usb(void)
71434+{
71435+#ifdef CONFIG_GRKERNSEC_DENYUSB
71436+ if (grsec_deny_new_usb) {
71437+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
71438+ return 1;
71439+ }
71440+#endif
71441+ return 0;
71442+}
71443+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
71444diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
71445new file mode 100644
71446index 0000000..9f7b1ac
71447--- /dev/null
71448+++ b/grsecurity/grsum.c
71449@@ -0,0 +1,61 @@
71450+#include <linux/err.h>
71451+#include <linux/kernel.h>
71452+#include <linux/sched.h>
71453+#include <linux/mm.h>
71454+#include <linux/scatterlist.h>
71455+#include <linux/crypto.h>
71456+#include <linux/gracl.h>
71457+
71458+
71459+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
71460+#error "crypto and sha256 must be built into the kernel"
71461+#endif
71462+
71463+int
71464+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
71465+{
71466+ char *p;
71467+ struct crypto_hash *tfm;
71468+ struct hash_desc desc;
71469+ struct scatterlist sg;
71470+ unsigned char temp_sum[GR_SHA_LEN];
71471+ volatile int retval = 0;
71472+ volatile int dummy = 0;
71473+ unsigned int i;
71474+
71475+ sg_init_table(&sg, 1);
71476+
71477+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
71478+ if (IS_ERR(tfm)) {
71479+ /* should never happen, since sha256 should be built in */
71480+ return 1;
71481+ }
71482+
71483+ desc.tfm = tfm;
71484+ desc.flags = 0;
71485+
71486+ crypto_hash_init(&desc);
71487+
71488+ p = salt;
71489+ sg_set_buf(&sg, p, GR_SALT_LEN);
71490+ crypto_hash_update(&desc, &sg, sg.length);
71491+
71492+ p = entry->pw;
71493+ sg_set_buf(&sg, p, strlen(p));
71494+
71495+ crypto_hash_update(&desc, &sg, sg.length);
71496+
71497+ crypto_hash_final(&desc, temp_sum);
71498+
71499+ memset(entry->pw, 0, GR_PW_LEN);
71500+
71501+ for (i = 0; i < GR_SHA_LEN; i++)
71502+ if (sum[i] != temp_sum[i])
71503+ retval = 1;
71504+ else
71505+ dummy = 1; // waste a cycle
71506+
71507+ crypto_free_hash(tfm);
71508+
71509+ return retval;
71510+}
71511diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
71512index 77ff547..181834f 100644
71513--- a/include/asm-generic/4level-fixup.h
71514+++ b/include/asm-generic/4level-fixup.h
71515@@ -13,8 +13,10 @@
71516 #define pmd_alloc(mm, pud, address) \
71517 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
71518 NULL: pmd_offset(pud, address))
71519+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
71520
71521 #define pud_alloc(mm, pgd, address) (pgd)
71522+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
71523 #define pud_offset(pgd, start) (pgd)
71524 #define pud_none(pud) 0
71525 #define pud_bad(pud) 0
71526diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
71527index b7babf0..04ad282 100644
71528--- a/include/asm-generic/atomic-long.h
71529+++ b/include/asm-generic/atomic-long.h
71530@@ -22,6 +22,12 @@
71531
71532 typedef atomic64_t atomic_long_t;
71533
71534+#ifdef CONFIG_PAX_REFCOUNT
71535+typedef atomic64_unchecked_t atomic_long_unchecked_t;
71536+#else
71537+typedef atomic64_t atomic_long_unchecked_t;
71538+#endif
71539+
71540 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
71541
71542 static inline long atomic_long_read(atomic_long_t *l)
71543@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71544 return (long)atomic64_read(v);
71545 }
71546
71547+#ifdef CONFIG_PAX_REFCOUNT
71548+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71549+{
71550+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71551+
71552+ return (long)atomic64_read_unchecked(v);
71553+}
71554+#endif
71555+
71556 static inline void atomic_long_set(atomic_long_t *l, long i)
71557 {
71558 atomic64_t *v = (atomic64_t *)l;
71559@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71560 atomic64_set(v, i);
71561 }
71562
71563+#ifdef CONFIG_PAX_REFCOUNT
71564+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71565+{
71566+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71567+
71568+ atomic64_set_unchecked(v, i);
71569+}
71570+#endif
71571+
71572 static inline void atomic_long_inc(atomic_long_t *l)
71573 {
71574 atomic64_t *v = (atomic64_t *)l;
71575@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71576 atomic64_inc(v);
71577 }
71578
71579+#ifdef CONFIG_PAX_REFCOUNT
71580+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71581+{
71582+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71583+
71584+ atomic64_inc_unchecked(v);
71585+}
71586+#endif
71587+
71588 static inline void atomic_long_dec(atomic_long_t *l)
71589 {
71590 atomic64_t *v = (atomic64_t *)l;
71591@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71592 atomic64_dec(v);
71593 }
71594
71595+#ifdef CONFIG_PAX_REFCOUNT
71596+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71597+{
71598+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71599+
71600+ atomic64_dec_unchecked(v);
71601+}
71602+#endif
71603+
71604 static inline void atomic_long_add(long i, atomic_long_t *l)
71605 {
71606 atomic64_t *v = (atomic64_t *)l;
71607@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71608 atomic64_add(i, v);
71609 }
71610
71611+#ifdef CONFIG_PAX_REFCOUNT
71612+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71613+{
71614+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71615+
71616+ atomic64_add_unchecked(i, v);
71617+}
71618+#endif
71619+
71620 static inline void atomic_long_sub(long i, atomic_long_t *l)
71621 {
71622 atomic64_t *v = (atomic64_t *)l;
71623@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71624 atomic64_sub(i, v);
71625 }
71626
71627+#ifdef CONFIG_PAX_REFCOUNT
71628+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71629+{
71630+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71631+
71632+ atomic64_sub_unchecked(i, v);
71633+}
71634+#endif
71635+
71636 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71637 {
71638 atomic64_t *v = (atomic64_t *)l;
71639@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71640 return (long)atomic64_add_return(i, v);
71641 }
71642
71643+#ifdef CONFIG_PAX_REFCOUNT
71644+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71645+{
71646+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71647+
71648+ return (long)atomic64_add_return_unchecked(i, v);
71649+}
71650+#endif
71651+
71652 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71653 {
71654 atomic64_t *v = (atomic64_t *)l;
71655@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71656 return (long)atomic64_inc_return(v);
71657 }
71658
71659+#ifdef CONFIG_PAX_REFCOUNT
71660+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71661+{
71662+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71663+
71664+ return (long)atomic64_inc_return_unchecked(v);
71665+}
71666+#endif
71667+
71668 static inline long atomic_long_dec_return(atomic_long_t *l)
71669 {
71670 atomic64_t *v = (atomic64_t *)l;
71671@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71672
71673 typedef atomic_t atomic_long_t;
71674
71675+#ifdef CONFIG_PAX_REFCOUNT
71676+typedef atomic_unchecked_t atomic_long_unchecked_t;
71677+#else
71678+typedef atomic_t atomic_long_unchecked_t;
71679+#endif
71680+
71681 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
71682 static inline long atomic_long_read(atomic_long_t *l)
71683 {
71684@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71685 return (long)atomic_read(v);
71686 }
71687
71688+#ifdef CONFIG_PAX_REFCOUNT
71689+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71690+{
71691+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71692+
71693+ return (long)atomic_read_unchecked(v);
71694+}
71695+#endif
71696+
71697 static inline void atomic_long_set(atomic_long_t *l, long i)
71698 {
71699 atomic_t *v = (atomic_t *)l;
71700@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71701 atomic_set(v, i);
71702 }
71703
71704+#ifdef CONFIG_PAX_REFCOUNT
71705+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71706+{
71707+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71708+
71709+ atomic_set_unchecked(v, i);
71710+}
71711+#endif
71712+
71713 static inline void atomic_long_inc(atomic_long_t *l)
71714 {
71715 atomic_t *v = (atomic_t *)l;
71716@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71717 atomic_inc(v);
71718 }
71719
71720+#ifdef CONFIG_PAX_REFCOUNT
71721+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71722+{
71723+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71724+
71725+ atomic_inc_unchecked(v);
71726+}
71727+#endif
71728+
71729 static inline void atomic_long_dec(atomic_long_t *l)
71730 {
71731 atomic_t *v = (atomic_t *)l;
71732@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71733 atomic_dec(v);
71734 }
71735
71736+#ifdef CONFIG_PAX_REFCOUNT
71737+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71738+{
71739+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71740+
71741+ atomic_dec_unchecked(v);
71742+}
71743+#endif
71744+
71745 static inline void atomic_long_add(long i, atomic_long_t *l)
71746 {
71747 atomic_t *v = (atomic_t *)l;
71748@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71749 atomic_add(i, v);
71750 }
71751
71752+#ifdef CONFIG_PAX_REFCOUNT
71753+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71754+{
71755+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71756+
71757+ atomic_add_unchecked(i, v);
71758+}
71759+#endif
71760+
71761 static inline void atomic_long_sub(long i, atomic_long_t *l)
71762 {
71763 atomic_t *v = (atomic_t *)l;
71764@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71765 atomic_sub(i, v);
71766 }
71767
71768+#ifdef CONFIG_PAX_REFCOUNT
71769+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71770+{
71771+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71772+
71773+ atomic_sub_unchecked(i, v);
71774+}
71775+#endif
71776+
71777 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71778 {
71779 atomic_t *v = (atomic_t *)l;
71780@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71781 return (long)atomic_add_return(i, v);
71782 }
71783
71784+#ifdef CONFIG_PAX_REFCOUNT
71785+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71786+{
71787+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71788+
71789+ return (long)atomic_add_return_unchecked(i, v);
71790+}
71791+
71792+#endif
71793+
71794 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71795 {
71796 atomic_t *v = (atomic_t *)l;
71797@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71798 return (long)atomic_inc_return(v);
71799 }
71800
71801+#ifdef CONFIG_PAX_REFCOUNT
71802+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71803+{
71804+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71805+
71806+ return (long)atomic_inc_return_unchecked(v);
71807+}
71808+#endif
71809+
71810 static inline long atomic_long_dec_return(atomic_long_t *l)
71811 {
71812 atomic_t *v = (atomic_t *)l;
71813@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71814
71815 #endif /* BITS_PER_LONG == 64 */
71816
71817+#ifdef CONFIG_PAX_REFCOUNT
71818+static inline void pax_refcount_needs_these_functions(void)
71819+{
71820+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
71821+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
71822+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
71823+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
71824+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
71825+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
71826+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
71827+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
71828+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
71829+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
71830+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
71831+#ifdef CONFIG_X86
71832+ atomic_clear_mask_unchecked(0, NULL);
71833+ atomic_set_mask_unchecked(0, NULL);
71834+#endif
71835+
71836+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
71837+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
71838+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
71839+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
71840+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
71841+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
71842+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
71843+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
71844+}
71845+#else
71846+#define atomic_read_unchecked(v) atomic_read(v)
71847+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
71848+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
71849+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
71850+#define atomic_inc_unchecked(v) atomic_inc(v)
71851+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
71852+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
71853+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
71854+#define atomic_dec_unchecked(v) atomic_dec(v)
71855+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
71856+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
71857+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
71858+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
71859+
71860+#define atomic_long_read_unchecked(v) atomic_long_read(v)
71861+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
71862+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
71863+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
71864+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
71865+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
71866+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
71867+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
71868+#endif
71869+
71870 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
71871diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
71872index 33bd2de..f31bff97 100644
71873--- a/include/asm-generic/atomic.h
71874+++ b/include/asm-generic/atomic.h
71875@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
71876 * Atomically clears the bits set in @mask from @v
71877 */
71878 #ifndef atomic_clear_mask
71879-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
71880+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
71881 {
71882 unsigned long flags;
71883
71884diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
71885index b18ce4f..2ee2843 100644
71886--- a/include/asm-generic/atomic64.h
71887+++ b/include/asm-generic/atomic64.h
71888@@ -16,6 +16,8 @@ typedef struct {
71889 long long counter;
71890 } atomic64_t;
71891
71892+typedef atomic64_t atomic64_unchecked_t;
71893+
71894 #define ATOMIC64_INIT(i) { (i) }
71895
71896 extern long long atomic64_read(const atomic64_t *v);
71897@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
71898 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
71899 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
71900
71901+#define atomic64_read_unchecked(v) atomic64_read(v)
71902+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
71903+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
71904+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
71905+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
71906+#define atomic64_inc_unchecked(v) atomic64_inc(v)
71907+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
71908+#define atomic64_dec_unchecked(v) atomic64_dec(v)
71909+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
71910+
71911 #endif /* _ASM_GENERIC_ATOMIC64_H */
71912diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
71913index 1bfcfe5..e04c5c9 100644
71914--- a/include/asm-generic/cache.h
71915+++ b/include/asm-generic/cache.h
71916@@ -6,7 +6,7 @@
71917 * cache lines need to provide their own cache.h.
71918 */
71919
71920-#define L1_CACHE_SHIFT 5
71921-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
71922+#define L1_CACHE_SHIFT 5UL
71923+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
71924
71925 #endif /* __ASM_GENERIC_CACHE_H */
71926diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
71927index 0d68a1e..b74a761 100644
71928--- a/include/asm-generic/emergency-restart.h
71929+++ b/include/asm-generic/emergency-restart.h
71930@@ -1,7 +1,7 @@
71931 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
71932 #define _ASM_GENERIC_EMERGENCY_RESTART_H
71933
71934-static inline void machine_emergency_restart(void)
71935+static inline __noreturn void machine_emergency_restart(void)
71936 {
71937 machine_restart(NULL);
71938 }
71939diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
71940index 90f99c7..00ce236 100644
71941--- a/include/asm-generic/kmap_types.h
71942+++ b/include/asm-generic/kmap_types.h
71943@@ -2,9 +2,9 @@
71944 #define _ASM_GENERIC_KMAP_TYPES_H
71945
71946 #ifdef __WITH_KM_FENCE
71947-# define KM_TYPE_NR 41
71948+# define KM_TYPE_NR 42
71949 #else
71950-# define KM_TYPE_NR 20
71951+# define KM_TYPE_NR 21
71952 #endif
71953
71954 #endif
71955diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
71956index 9ceb03b..62b0b8f 100644
71957--- a/include/asm-generic/local.h
71958+++ b/include/asm-generic/local.h
71959@@ -23,24 +23,37 @@ typedef struct
71960 atomic_long_t a;
71961 } local_t;
71962
71963+typedef struct {
71964+ atomic_long_unchecked_t a;
71965+} local_unchecked_t;
71966+
71967 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
71968
71969 #define local_read(l) atomic_long_read(&(l)->a)
71970+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
71971 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
71972+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
71973 #define local_inc(l) atomic_long_inc(&(l)->a)
71974+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
71975 #define local_dec(l) atomic_long_dec(&(l)->a)
71976+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
71977 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
71978+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
71979 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
71980+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
71981
71982 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
71983 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
71984 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
71985 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
71986 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
71987+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
71988 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
71989 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
71990+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
71991
71992 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
71993+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
71994 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
71995 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
71996 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
71997diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
71998index 725612b..9cc513a 100644
71999--- a/include/asm-generic/pgtable-nopmd.h
72000+++ b/include/asm-generic/pgtable-nopmd.h
72001@@ -1,14 +1,19 @@
72002 #ifndef _PGTABLE_NOPMD_H
72003 #define _PGTABLE_NOPMD_H
72004
72005-#ifndef __ASSEMBLY__
72006-
72007 #include <asm-generic/pgtable-nopud.h>
72008
72009-struct mm_struct;
72010-
72011 #define __PAGETABLE_PMD_FOLDED
72012
72013+#define PMD_SHIFT PUD_SHIFT
72014+#define PTRS_PER_PMD 1
72015+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
72016+#define PMD_MASK (~(PMD_SIZE-1))
72017+
72018+#ifndef __ASSEMBLY__
72019+
72020+struct mm_struct;
72021+
72022 /*
72023 * Having the pmd type consist of a pud gets the size right, and allows
72024 * us to conceptually access the pud entry that this pmd is folded into
72025@@ -16,11 +21,6 @@ struct mm_struct;
72026 */
72027 typedef struct { pud_t pud; } pmd_t;
72028
72029-#define PMD_SHIFT PUD_SHIFT
72030-#define PTRS_PER_PMD 1
72031-#define PMD_SIZE (1UL << PMD_SHIFT)
72032-#define PMD_MASK (~(PMD_SIZE-1))
72033-
72034 /*
72035 * The "pud_xxx()" functions here are trivial for a folded two-level
72036 * setup: the pmd is never bad, and a pmd always exists (as it's folded
72037diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
72038index 810431d..0ec4804f 100644
72039--- a/include/asm-generic/pgtable-nopud.h
72040+++ b/include/asm-generic/pgtable-nopud.h
72041@@ -1,10 +1,15 @@
72042 #ifndef _PGTABLE_NOPUD_H
72043 #define _PGTABLE_NOPUD_H
72044
72045-#ifndef __ASSEMBLY__
72046-
72047 #define __PAGETABLE_PUD_FOLDED
72048
72049+#define PUD_SHIFT PGDIR_SHIFT
72050+#define PTRS_PER_PUD 1
72051+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
72052+#define PUD_MASK (~(PUD_SIZE-1))
72053+
72054+#ifndef __ASSEMBLY__
72055+
72056 /*
72057 * Having the pud type consist of a pgd gets the size right, and allows
72058 * us to conceptually access the pgd entry that this pud is folded into
72059@@ -12,11 +17,6 @@
72060 */
72061 typedef struct { pgd_t pgd; } pud_t;
72062
72063-#define PUD_SHIFT PGDIR_SHIFT
72064-#define PTRS_PER_PUD 1
72065-#define PUD_SIZE (1UL << PUD_SHIFT)
72066-#define PUD_MASK (~(PUD_SIZE-1))
72067-
72068 /*
72069 * The "pgd_xxx()" functions here are trivial for a folded two-level
72070 * setup: the pud is never bad, and a pud always exists (as it's folded
72071@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
72072 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
72073
72074 #define pgd_populate(mm, pgd, pud) do { } while (0)
72075+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
72076 /*
72077 * (puds are folded into pgds so this doesn't get actually called,
72078 * but the define is needed for a generic inline function.)
72079diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
72080index 0807ddf..cd67747 100644
72081--- a/include/asm-generic/pgtable.h
72082+++ b/include/asm-generic/pgtable.h
72083@@ -741,6 +741,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
72084 }
72085 #endif /* CONFIG_NUMA_BALANCING */
72086
72087+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
72088+#ifdef CONFIG_PAX_KERNEXEC
72089+#error KERNEXEC requires pax_open_kernel
72090+#else
72091+static inline unsigned long pax_open_kernel(void) { return 0; }
72092+#endif
72093+#endif
72094+
72095+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
72096+#ifdef CONFIG_PAX_KERNEXEC
72097+#error KERNEXEC requires pax_close_kernel
72098+#else
72099+static inline unsigned long pax_close_kernel(void) { return 0; }
72100+#endif
72101+#endif
72102+
72103 #endif /* CONFIG_MMU */
72104
72105 #endif /* !__ASSEMBLY__ */
72106diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
72107index dc1269c..48a4f51 100644
72108--- a/include/asm-generic/uaccess.h
72109+++ b/include/asm-generic/uaccess.h
72110@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
72111 return __clear_user(to, n);
72112 }
72113
72114+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
72115+#ifdef CONFIG_PAX_MEMORY_UDEREF
72116+#error UDEREF requires pax_open_userland
72117+#else
72118+static inline unsigned long pax_open_userland(void) { return 0; }
72119+#endif
72120+#endif
72121+
72122+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
72123+#ifdef CONFIG_PAX_MEMORY_UDEREF
72124+#error UDEREF requires pax_close_userland
72125+#else
72126+static inline unsigned long pax_close_userland(void) { return 0; }
72127+#endif
72128+#endif
72129+
72130 #endif /* __ASM_GENERIC_UACCESS_H */
72131diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
72132index 69732d2..cbe16d9 100644
72133--- a/include/asm-generic/vmlinux.lds.h
72134+++ b/include/asm-generic/vmlinux.lds.h
72135@@ -227,6 +227,7 @@
72136 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
72137 VMLINUX_SYMBOL(__start_rodata) = .; \
72138 *(.rodata) *(.rodata.*) \
72139+ *(.data..read_only) \
72140 *(__vermagic) /* Kernel version magic */ \
72141 . = ALIGN(8); \
72142 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
72143@@ -710,17 +711,18 @@
72144 * section in the linker script will go there too. @phdr should have
72145 * a leading colon.
72146 *
72147- * Note that this macros defines __per_cpu_load as an absolute symbol.
72148+ * Note that this macros defines per_cpu_load as an absolute symbol.
72149 * If there is no need to put the percpu section at a predetermined
72150 * address, use PERCPU_SECTION.
72151 */
72152 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
72153- VMLINUX_SYMBOL(__per_cpu_load) = .; \
72154- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
72155+ per_cpu_load = .; \
72156+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
72157 - LOAD_OFFSET) { \
72158+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
72159 PERCPU_INPUT(cacheline) \
72160 } phdr \
72161- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
72162+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
72163
72164 /**
72165 * PERCPU_SECTION - define output section for percpu area, simple version
72166diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
72167index 418d270..bfd2794 100644
72168--- a/include/crypto/algapi.h
72169+++ b/include/crypto/algapi.h
72170@@ -34,7 +34,7 @@ struct crypto_type {
72171 unsigned int maskclear;
72172 unsigned int maskset;
72173 unsigned int tfmsize;
72174-};
72175+} __do_const;
72176
72177 struct crypto_instance {
72178 struct crypto_alg alg;
72179diff --git a/include/drm/drmP.h b/include/drm/drmP.h
72180index 12083dc..39740ec 100644
72181--- a/include/drm/drmP.h
72182+++ b/include/drm/drmP.h
72183@@ -69,6 +69,7 @@
72184 #include <linux/workqueue.h>
72185 #include <linux/poll.h>
72186 #include <asm/pgalloc.h>
72187+#include <asm/local.h>
72188 #include <drm/drm.h>
72189 #include <drm/drm_sarea.h>
72190
72191@@ -293,10 +294,12 @@ do { \
72192 * \param cmd command.
72193 * \param arg argument.
72194 */
72195-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
72196+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
72197+ struct drm_file *file_priv);
72198+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
72199 struct drm_file *file_priv);
72200
72201-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
72202+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
72203 unsigned long arg);
72204
72205 #define DRM_IOCTL_NR(n) _IOC_NR(n)
72206@@ -311,10 +314,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
72207 struct drm_ioctl_desc {
72208 unsigned int cmd;
72209 int flags;
72210- drm_ioctl_t *func;
72211+ drm_ioctl_t func;
72212 unsigned int cmd_drv;
72213 const char *name;
72214-};
72215+} __do_const;
72216
72217 /**
72218 * Creates a driver or general drm_ioctl_desc array entry for the given
72219@@ -1015,7 +1018,7 @@ struct drm_info_list {
72220 int (*show)(struct seq_file*, void*); /** show callback */
72221 u32 driver_features; /**< Required driver features for this entry */
72222 void *data;
72223-};
72224+} __do_const;
72225
72226 /**
72227 * debugfs node structure. This structure represents a debugfs file.
72228@@ -1088,7 +1091,7 @@ struct drm_device {
72229
72230 /** \name Usage Counters */
72231 /*@{ */
72232- int open_count; /**< Outstanding files open */
72233+ local_t open_count; /**< Outstanding files open */
72234 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
72235 atomic_t vma_count; /**< Outstanding vma areas open */
72236 int buf_use; /**< Buffers in use -- cannot alloc */
72237@@ -1099,7 +1102,7 @@ struct drm_device {
72238 /*@{ */
72239 unsigned long counters;
72240 enum drm_stat_type types[15];
72241- atomic_t counts[15];
72242+ atomic_unchecked_t counts[15];
72243 /*@} */
72244
72245 struct list_head filelist;
72246diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
72247index f43d556..94d9343 100644
72248--- a/include/drm/drm_crtc_helper.h
72249+++ b/include/drm/drm_crtc_helper.h
72250@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
72251 struct drm_connector *connector);
72252 /* disable encoder when not in use - more explicit than dpms off */
72253 void (*disable)(struct drm_encoder *encoder);
72254-};
72255+} __no_const;
72256
72257 /**
72258 * drm_connector_helper_funcs - helper operations for connectors
72259diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
72260index 72dcbe8..8db58d7 100644
72261--- a/include/drm/ttm/ttm_memory.h
72262+++ b/include/drm/ttm/ttm_memory.h
72263@@ -48,7 +48,7 @@
72264
72265 struct ttm_mem_shrink {
72266 int (*do_shrink) (struct ttm_mem_shrink *);
72267-};
72268+} __no_const;
72269
72270 /**
72271 * struct ttm_mem_global - Global memory accounting structure.
72272diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
72273index 4b840e8..155d235 100644
72274--- a/include/keys/asymmetric-subtype.h
72275+++ b/include/keys/asymmetric-subtype.h
72276@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
72277 /* Verify the signature on a key of this subtype (optional) */
72278 int (*verify_signature)(const struct key *key,
72279 const struct public_key_signature *sig);
72280-};
72281+} __do_const;
72282
72283 /**
72284 * asymmetric_key_subtype - Get the subtype from an asymmetric key
72285diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
72286index c1da539..1dcec55 100644
72287--- a/include/linux/atmdev.h
72288+++ b/include/linux/atmdev.h
72289@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
72290 #endif
72291
72292 struct k_atm_aal_stats {
72293-#define __HANDLE_ITEM(i) atomic_t i
72294+#define __HANDLE_ITEM(i) atomic_unchecked_t i
72295 __AAL_STAT_ITEMS
72296 #undef __HANDLE_ITEM
72297 };
72298@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
72299 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
72300 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
72301 struct module *owner;
72302-};
72303+} __do_const ;
72304
72305 struct atmphy_ops {
72306 int (*start)(struct atm_dev *dev);
72307diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
72308index 70cf138..0418ee2 100644
72309--- a/include/linux/binfmts.h
72310+++ b/include/linux/binfmts.h
72311@@ -73,8 +73,10 @@ struct linux_binfmt {
72312 int (*load_binary)(struct linux_binprm *);
72313 int (*load_shlib)(struct file *);
72314 int (*core_dump)(struct coredump_params *cprm);
72315+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
72316+ void (*handle_mmap)(struct file *);
72317 unsigned long min_coredump; /* minimal dump size */
72318-};
72319+} __do_const;
72320
72321 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
72322
72323diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
72324index 2fdb4a4..54aad7e 100644
72325--- a/include/linux/blkdev.h
72326+++ b/include/linux/blkdev.h
72327@@ -1526,7 +1526,7 @@ struct block_device_operations {
72328 /* this callback is with swap_lock and sometimes page table lock held */
72329 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
72330 struct module *owner;
72331-};
72332+} __do_const;
72333
72334 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
72335 unsigned long);
72336diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
72337index 7c2e030..b72475d 100644
72338--- a/include/linux/blktrace_api.h
72339+++ b/include/linux/blktrace_api.h
72340@@ -23,7 +23,7 @@ struct blk_trace {
72341 struct dentry *dir;
72342 struct dentry *dropped_file;
72343 struct dentry *msg_file;
72344- atomic_t dropped;
72345+ atomic_unchecked_t dropped;
72346 };
72347
72348 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
72349diff --git a/include/linux/cache.h b/include/linux/cache.h
72350index 4c57065..4307975 100644
72351--- a/include/linux/cache.h
72352+++ b/include/linux/cache.h
72353@@ -16,6 +16,10 @@
72354 #define __read_mostly
72355 #endif
72356
72357+#ifndef __read_only
72358+#define __read_only __read_mostly
72359+#endif
72360+
72361 #ifndef ____cacheline_aligned
72362 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
72363 #endif
72364diff --git a/include/linux/capability.h b/include/linux/capability.h
72365index d9a4f7f4..19f77d6 100644
72366--- a/include/linux/capability.h
72367+++ b/include/linux/capability.h
72368@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
72369 extern bool nsown_capable(int cap);
72370 extern bool inode_capable(const struct inode *inode, int cap);
72371 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
72372+extern bool capable_nolog(int cap);
72373+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
72374+extern bool inode_capable_nolog(const struct inode *inode, int cap);
72375
72376 /* audit system wants to get cap info from files as well */
72377 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
72378
72379+extern int is_privileged_binary(const struct dentry *dentry);
72380+
72381 #endif /* !_LINUX_CAPABILITY_H */
72382diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
72383index 8609d57..86e4d79 100644
72384--- a/include/linux/cdrom.h
72385+++ b/include/linux/cdrom.h
72386@@ -87,7 +87,6 @@ struct cdrom_device_ops {
72387
72388 /* driver specifications */
72389 const int capability; /* capability flags */
72390- int n_minors; /* number of active minor devices */
72391 /* handle uniform packets for scsi type devices (scsi,atapi) */
72392 int (*generic_packet) (struct cdrom_device_info *,
72393 struct packet_command *);
72394diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
72395index 4ce9056..86caac6 100644
72396--- a/include/linux/cleancache.h
72397+++ b/include/linux/cleancache.h
72398@@ -31,7 +31,7 @@ struct cleancache_ops {
72399 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
72400 void (*invalidate_inode)(int, struct cleancache_filekey);
72401 void (*invalidate_fs)(int);
72402-};
72403+} __no_const;
72404
72405 extern struct cleancache_ops *
72406 cleancache_register_ops(struct cleancache_ops *ops);
72407diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
72408index 1ec14a7..d0654a2 100644
72409--- a/include/linux/clk-provider.h
72410+++ b/include/linux/clk-provider.h
72411@@ -132,6 +132,7 @@ struct clk_ops {
72412 unsigned long);
72413 void (*init)(struct clk_hw *hw);
72414 };
72415+typedef struct clk_ops __no_const clk_ops_no_const;
72416
72417 /**
72418 * struct clk_init_data - holds init data that's common to all clocks and is
72419diff --git a/include/linux/compat.h b/include/linux/compat.h
72420index 7f0c1dd..206ac34 100644
72421--- a/include/linux/compat.h
72422+++ b/include/linux/compat.h
72423@@ -312,7 +312,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
72424 compat_size_t __user *len_ptr);
72425
72426 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
72427-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
72428+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
72429 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
72430 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
72431 compat_ssize_t msgsz, int msgflg);
72432@@ -419,7 +419,7 @@ extern int compat_ptrace_request(struct task_struct *child,
72433 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
72434 compat_ulong_t addr, compat_ulong_t data);
72435 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
72436- compat_long_t addr, compat_long_t data);
72437+ compat_ulong_t addr, compat_ulong_t data);
72438
72439 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
72440 /*
72441@@ -669,6 +669,7 @@ asmlinkage long compat_sys_sigaltstack(const compat_stack_t __user *uss_ptr,
72442
72443 int compat_restore_altstack(const compat_stack_t __user *uss);
72444 int __compat_save_altstack(compat_stack_t __user *, unsigned long);
72445+void __compat_save_altstack_ex(compat_stack_t __user *, unsigned long);
72446
72447 asmlinkage long compat_sys_sched_rr_get_interval(compat_pid_t pid,
72448 struct compat_timespec __user *interval);
72449diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
72450index 842de22..7f3a41f 100644
72451--- a/include/linux/compiler-gcc4.h
72452+++ b/include/linux/compiler-gcc4.h
72453@@ -39,9 +39,29 @@
72454 # define __compiletime_warning(message) __attribute__((warning(message)))
72455 # define __compiletime_error(message) __attribute__((error(message)))
72456 #endif /* __CHECKER__ */
72457+
72458+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
72459+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
72460+#define __bos0(ptr) __bos((ptr), 0)
72461+#define __bos1(ptr) __bos((ptr), 1)
72462 #endif /* GCC_VERSION >= 40300 */
72463
72464 #if GCC_VERSION >= 40500
72465+
72466+#ifdef CONSTIFY_PLUGIN
72467+#define __no_const __attribute__((no_const))
72468+#define __do_const __attribute__((do_const))
72469+#endif
72470+
72471+#ifdef SIZE_OVERFLOW_PLUGIN
72472+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
72473+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
72474+#endif
72475+
72476+#ifdef LATENT_ENTROPY_PLUGIN
72477+#define __latent_entropy __attribute__((latent_entropy))
72478+#endif
72479+
72480 /*
72481 * Mark a position in code as unreachable. This can be used to
72482 * suppress control flow warnings after asm blocks that transfer
72483diff --git a/include/linux/compiler.h b/include/linux/compiler.h
72484index 92669cd..1771a15 100644
72485--- a/include/linux/compiler.h
72486+++ b/include/linux/compiler.h
72487@@ -5,11 +5,14 @@
72488
72489 #ifdef __CHECKER__
72490 # define __user __attribute__((noderef, address_space(1)))
72491+# define __force_user __force __user
72492 # define __kernel __attribute__((address_space(0)))
72493+# define __force_kernel __force __kernel
72494 # define __safe __attribute__((safe))
72495 # define __force __attribute__((force))
72496 # define __nocast __attribute__((nocast))
72497 # define __iomem __attribute__((noderef, address_space(2)))
72498+# define __force_iomem __force __iomem
72499 # define __must_hold(x) __attribute__((context(x,1,1)))
72500 # define __acquires(x) __attribute__((context(x,0,1)))
72501 # define __releases(x) __attribute__((context(x,1,0)))
72502@@ -17,20 +20,37 @@
72503 # define __release(x) __context__(x,-1)
72504 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
72505 # define __percpu __attribute__((noderef, address_space(3)))
72506+# define __force_percpu __force __percpu
72507 #ifdef CONFIG_SPARSE_RCU_POINTER
72508 # define __rcu __attribute__((noderef, address_space(4)))
72509+# define __force_rcu __force __rcu
72510 #else
72511 # define __rcu
72512+# define __force_rcu
72513 #endif
72514 extern void __chk_user_ptr(const volatile void __user *);
72515 extern void __chk_io_ptr(const volatile void __iomem *);
72516 #else
72517-# define __user
72518-# define __kernel
72519+# ifdef CHECKER_PLUGIN
72520+//# define __user
72521+//# define __force_user
72522+//# define __kernel
72523+//# define __force_kernel
72524+# else
72525+# ifdef STRUCTLEAK_PLUGIN
72526+# define __user __attribute__((user))
72527+# else
72528+# define __user
72529+# endif
72530+# define __force_user
72531+# define __kernel
72532+# define __force_kernel
72533+# endif
72534 # define __safe
72535 # define __force
72536 # define __nocast
72537 # define __iomem
72538+# define __force_iomem
72539 # define __chk_user_ptr(x) (void)0
72540 # define __chk_io_ptr(x) (void)0
72541 # define __builtin_warning(x, y...) (1)
72542@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
72543 # define __release(x) (void)0
72544 # define __cond_lock(x,c) (c)
72545 # define __percpu
72546+# define __force_percpu
72547 # define __rcu
72548+# define __force_rcu
72549 #endif
72550
72551 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
72552@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72553 # define __attribute_const__ /* unimplemented */
72554 #endif
72555
72556+#ifndef __no_const
72557+# define __no_const
72558+#endif
72559+
72560+#ifndef __do_const
72561+# define __do_const
72562+#endif
72563+
72564+#ifndef __size_overflow
72565+# define __size_overflow(...)
72566+#endif
72567+
72568+#ifndef __intentional_overflow
72569+# define __intentional_overflow(...)
72570+#endif
72571+
72572+#ifndef __latent_entropy
72573+# define __latent_entropy
72574+#endif
72575+
72576 /*
72577 * Tell gcc if a function is cold. The compiler will assume any path
72578 * directly leading to the call is unlikely.
72579@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72580 #define __cold
72581 #endif
72582
72583+#ifndef __alloc_size
72584+#define __alloc_size(...)
72585+#endif
72586+
72587+#ifndef __bos
72588+#define __bos(ptr, arg)
72589+#endif
72590+
72591+#ifndef __bos0
72592+#define __bos0(ptr)
72593+#endif
72594+
72595+#ifndef __bos1
72596+#define __bos1(ptr)
72597+#endif
72598+
72599 /* Simple shorthand for a section definition */
72600 #ifndef __section
72601 # define __section(S) __attribute__ ((__section__(#S)))
72602@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72603 * use is to mediate communication between process-level code and irq/NMI
72604 * handlers, all running on the same CPU.
72605 */
72606-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
72607+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
72608+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
72609
72610 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
72611 #ifdef CONFIG_KPROBES
72612diff --git a/include/linux/completion.h b/include/linux/completion.h
72613index 3cd574d..adce5fa 100644
72614--- a/include/linux/completion.h
72615+++ b/include/linux/completion.h
72616@@ -79,15 +79,15 @@ static inline void init_completion(struct completion *x)
72617 extern void wait_for_completion(struct completion *);
72618 extern void wait_for_completion_io(struct completion *);
72619 extern int wait_for_completion_interruptible(struct completion *x);
72620-extern int wait_for_completion_killable(struct completion *x);
72621+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
72622 extern unsigned long wait_for_completion_timeout(struct completion *x,
72623 unsigned long timeout);
72624 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
72625 unsigned long timeout);
72626 extern long wait_for_completion_interruptible_timeout(
72627- struct completion *x, unsigned long timeout);
72628+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72629 extern long wait_for_completion_killable_timeout(
72630- struct completion *x, unsigned long timeout);
72631+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72632 extern bool try_wait_for_completion(struct completion *x);
72633 extern bool completion_done(struct completion *x);
72634
72635diff --git a/include/linux/configfs.h b/include/linux/configfs.h
72636index 34025df..d94bbbc 100644
72637--- a/include/linux/configfs.h
72638+++ b/include/linux/configfs.h
72639@@ -125,7 +125,7 @@ struct configfs_attribute {
72640 const char *ca_name;
72641 struct module *ca_owner;
72642 umode_t ca_mode;
72643-};
72644+} __do_const;
72645
72646 /*
72647 * Users often need to create attribute structures for their configurable
72648diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
72649index 90d5a15..950cb80 100644
72650--- a/include/linux/cpufreq.h
72651+++ b/include/linux/cpufreq.h
72652@@ -266,7 +266,7 @@ struct cpufreq_driver {
72653 int (*suspend) (struct cpufreq_policy *policy);
72654 int (*resume) (struct cpufreq_policy *policy);
72655 struct freq_attr **attr;
72656-};
72657+} __do_const;
72658
72659 /* flags */
72660
72661@@ -325,6 +325,7 @@ struct global_attr {
72662 ssize_t (*store)(struct kobject *a, struct attribute *b,
72663 const char *c, size_t count);
72664 };
72665+typedef struct global_attr __no_const global_attr_no_const;
72666
72667 #define define_one_global_ro(_name) \
72668 static struct global_attr _name = \
72669diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
72670index 0bc4b74..973b368 100644
72671--- a/include/linux/cpuidle.h
72672+++ b/include/linux/cpuidle.h
72673@@ -52,7 +52,8 @@ struct cpuidle_state {
72674 int index);
72675
72676 int (*enter_dead) (struct cpuidle_device *dev, int index);
72677-};
72678+} __do_const;
72679+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
72680
72681 /* Idle State Flags */
72682 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
72683@@ -191,7 +192,7 @@ struct cpuidle_governor {
72684 void (*reflect) (struct cpuidle_device *dev, int index);
72685
72686 struct module *owner;
72687-};
72688+} __do_const;
72689
72690 #ifdef CONFIG_CPU_IDLE
72691
72692diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
72693index d08e4d2..95fad61 100644
72694--- a/include/linux/cpumask.h
72695+++ b/include/linux/cpumask.h
72696@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72697 }
72698
72699 /* Valid inputs for n are -1 and 0. */
72700-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72701+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72702 {
72703 return n+1;
72704 }
72705
72706-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72707+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72708 {
72709 return n+1;
72710 }
72711
72712-static inline unsigned int cpumask_next_and(int n,
72713+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
72714 const struct cpumask *srcp,
72715 const struct cpumask *andp)
72716 {
72717@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72718 *
72719 * Returns >= nr_cpu_ids if no further cpus set.
72720 */
72721-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72722+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72723 {
72724 /* -1 is a legal arg here. */
72725 if (n != -1)
72726@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72727 *
72728 * Returns >= nr_cpu_ids if no further cpus unset.
72729 */
72730-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72731+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72732 {
72733 /* -1 is a legal arg here. */
72734 if (n != -1)
72735@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72736 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
72737 }
72738
72739-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
72740+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
72741 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
72742
72743 /**
72744diff --git a/include/linux/cred.h b/include/linux/cred.h
72745index 04421e8..6bce4ef 100644
72746--- a/include/linux/cred.h
72747+++ b/include/linux/cred.h
72748@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
72749 static inline void validate_process_creds(void)
72750 {
72751 }
72752+static inline void validate_task_creds(struct task_struct *task)
72753+{
72754+}
72755 #endif
72756
72757 /**
72758diff --git a/include/linux/crypto.h b/include/linux/crypto.h
72759index b92eadf..b4ecdc1 100644
72760--- a/include/linux/crypto.h
72761+++ b/include/linux/crypto.h
72762@@ -373,7 +373,7 @@ struct cipher_tfm {
72763 const u8 *key, unsigned int keylen);
72764 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72765 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72766-};
72767+} __no_const;
72768
72769 struct hash_tfm {
72770 int (*init)(struct hash_desc *desc);
72771@@ -394,13 +394,13 @@ struct compress_tfm {
72772 int (*cot_decompress)(struct crypto_tfm *tfm,
72773 const u8 *src, unsigned int slen,
72774 u8 *dst, unsigned int *dlen);
72775-};
72776+} __no_const;
72777
72778 struct rng_tfm {
72779 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
72780 unsigned int dlen);
72781 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
72782-};
72783+} __no_const;
72784
72785 #define crt_ablkcipher crt_u.ablkcipher
72786 #define crt_aead crt_u.aead
72787diff --git a/include/linux/ctype.h b/include/linux/ctype.h
72788index 653589e..4ef254a 100644
72789--- a/include/linux/ctype.h
72790+++ b/include/linux/ctype.h
72791@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
72792 * Fast implementation of tolower() for internal usage. Do not use in your
72793 * code.
72794 */
72795-static inline char _tolower(const char c)
72796+static inline unsigned char _tolower(const unsigned char c)
72797 {
72798 return c | 0x20;
72799 }
72800diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
72801index 7925bf0..d5143d2 100644
72802--- a/include/linux/decompress/mm.h
72803+++ b/include/linux/decompress/mm.h
72804@@ -77,7 +77,7 @@ static void free(void *where)
72805 * warnings when not needed (indeed large_malloc / large_free are not
72806 * needed by inflate */
72807
72808-#define malloc(a) kmalloc(a, GFP_KERNEL)
72809+#define malloc(a) kmalloc((a), GFP_KERNEL)
72810 #define free(a) kfree(a)
72811
72812 #define large_malloc(a) vmalloc(a)
72813diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
72814index 5f1ab92..39c35ae 100644
72815--- a/include/linux/devfreq.h
72816+++ b/include/linux/devfreq.h
72817@@ -114,7 +114,7 @@ struct devfreq_governor {
72818 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
72819 int (*event_handler)(struct devfreq *devfreq,
72820 unsigned int event, void *data);
72821-};
72822+} __do_const;
72823
72824 /**
72825 * struct devfreq - Device devfreq structure
72826diff --git a/include/linux/device.h b/include/linux/device.h
72827index 22b546a..a573dc9 100644
72828--- a/include/linux/device.h
72829+++ b/include/linux/device.h
72830@@ -305,7 +305,7 @@ struct subsys_interface {
72831 struct list_head node;
72832 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
72833 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
72834-};
72835+} __do_const;
72836
72837 int subsys_interface_register(struct subsys_interface *sif);
72838 void subsys_interface_unregister(struct subsys_interface *sif);
72839@@ -493,7 +493,7 @@ struct device_type {
72840 void (*release)(struct device *dev);
72841
72842 const struct dev_pm_ops *pm;
72843-};
72844+} __do_const;
72845
72846 /* interface for exporting device attributes */
72847 struct device_attribute {
72848@@ -503,11 +503,12 @@ struct device_attribute {
72849 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
72850 const char *buf, size_t count);
72851 };
72852+typedef struct device_attribute __no_const device_attribute_no_const;
72853
72854 struct dev_ext_attribute {
72855 struct device_attribute attr;
72856 void *var;
72857-};
72858+} __do_const;
72859
72860 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
72861 char *buf);
72862diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
72863index 94af418..b1ca7a2 100644
72864--- a/include/linux/dma-mapping.h
72865+++ b/include/linux/dma-mapping.h
72866@@ -54,7 +54,7 @@ struct dma_map_ops {
72867 u64 (*get_required_mask)(struct device *dev);
72868 #endif
72869 int is_phys;
72870-};
72871+} __do_const;
72872
72873 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
72874
72875diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
72876index cb286b1..923d066 100644
72877--- a/include/linux/dmaengine.h
72878+++ b/include/linux/dmaengine.h
72879@@ -1030,9 +1030,9 @@ struct dma_pinned_list {
72880 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
72881 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
72882
72883-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
72884+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
72885 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
72886-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
72887+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
72888 struct dma_pinned_list *pinned_list, struct page *page,
72889 unsigned int offset, size_t len);
72890
72891diff --git a/include/linux/efi.h b/include/linux/efi.h
72892index 5f8f176..62a0556 100644
72893--- a/include/linux/efi.h
72894+++ b/include/linux/efi.h
72895@@ -745,6 +745,7 @@ struct efivar_operations {
72896 efi_set_variable_t *set_variable;
72897 efi_query_variable_store_t *query_variable_store;
72898 };
72899+typedef struct efivar_operations __no_const efivar_operations_no_const;
72900
72901 struct efivars {
72902 /*
72903diff --git a/include/linux/elf.h b/include/linux/elf.h
72904index 40a3c0e..4c45a38 100644
72905--- a/include/linux/elf.h
72906+++ b/include/linux/elf.h
72907@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
72908 #define elf_note elf32_note
72909 #define elf_addr_t Elf32_Off
72910 #define Elf_Half Elf32_Half
72911+#define elf_dyn Elf32_Dyn
72912
72913 #else
72914
72915@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
72916 #define elf_note elf64_note
72917 #define elf_addr_t Elf64_Off
72918 #define Elf_Half Elf64_Half
72919+#define elf_dyn Elf64_Dyn
72920
72921 #endif
72922
72923diff --git a/include/linux/err.h b/include/linux/err.h
72924index 221fcfb..f29e5e2 100644
72925--- a/include/linux/err.h
72926+++ b/include/linux/err.h
72927@@ -19,12 +19,12 @@
72928
72929 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
72930
72931-static inline void * __must_check ERR_PTR(long error)
72932+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
72933 {
72934 return (void *) error;
72935 }
72936
72937-static inline long __must_check PTR_ERR(__force const void *ptr)
72938+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
72939 {
72940 return (long) ptr;
72941 }
72942diff --git a/include/linux/extcon.h b/include/linux/extcon.h
72943index fcb51c8..bdafcf6 100644
72944--- a/include/linux/extcon.h
72945+++ b/include/linux/extcon.h
72946@@ -134,7 +134,7 @@ struct extcon_dev {
72947 /* /sys/class/extcon/.../mutually_exclusive/... */
72948 struct attribute_group attr_g_muex;
72949 struct attribute **attrs_muex;
72950- struct device_attribute *d_attrs_muex;
72951+ device_attribute_no_const *d_attrs_muex;
72952 };
72953
72954 /**
72955diff --git a/include/linux/fb.h b/include/linux/fb.h
72956index ffac70a..ca3e711 100644
72957--- a/include/linux/fb.h
72958+++ b/include/linux/fb.h
72959@@ -304,7 +304,7 @@ struct fb_ops {
72960 /* called at KDB enter and leave time to prepare the console */
72961 int (*fb_debug_enter)(struct fb_info *info);
72962 int (*fb_debug_leave)(struct fb_info *info);
72963-};
72964+} __do_const;
72965
72966 #ifdef CONFIG_FB_TILEBLITTING
72967 #define FB_TILE_CURSOR_NONE 0
72968diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
72969index 085197b..0fa6f0b 100644
72970--- a/include/linux/fdtable.h
72971+++ b/include/linux/fdtable.h
72972@@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
72973 void put_files_struct(struct files_struct *fs);
72974 void reset_files_struct(struct files_struct *);
72975 int unshare_files(struct files_struct **);
72976-struct files_struct *dup_fd(struct files_struct *, int *);
72977+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
72978 void do_close_on_exec(struct files_struct *);
72979 int iterate_fd(struct files_struct *, unsigned,
72980 int (*)(const void *, struct file *, unsigned),
72981diff --git a/include/linux/filter.h b/include/linux/filter.h
72982index a6ac848..a104a76 100644
72983--- a/include/linux/filter.h
72984+++ b/include/linux/filter.h
72985@@ -20,6 +20,7 @@ struct compat_sock_fprog {
72986
72987 struct sk_buff;
72988 struct sock;
72989+struct bpf_jit_work;
72990
72991 struct sk_filter
72992 {
72993@@ -27,6 +28,9 @@ struct sk_filter
72994 unsigned int len; /* Number of filter blocks */
72995 unsigned int (*bpf_func)(const struct sk_buff *skb,
72996 const struct sock_filter *filter);
72997+#ifdef CONFIG_BPF_JIT
72998+ struct bpf_jit_work *work;
72999+#endif
73000 struct rcu_head rcu;
73001 struct sock_filter insns[0];
73002 };
73003diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
73004index 8293262..2b3b8bd 100644
73005--- a/include/linux/frontswap.h
73006+++ b/include/linux/frontswap.h
73007@@ -11,7 +11,7 @@ struct frontswap_ops {
73008 int (*load)(unsigned, pgoff_t, struct page *);
73009 void (*invalidate_page)(unsigned, pgoff_t);
73010 void (*invalidate_area)(unsigned);
73011-};
73012+} __no_const;
73013
73014 extern bool frontswap_enabled;
73015 extern struct frontswap_ops *
73016diff --git a/include/linux/fs.h b/include/linux/fs.h
73017index 9818747..788bfbd 100644
73018--- a/include/linux/fs.h
73019+++ b/include/linux/fs.h
73020@@ -1554,7 +1554,8 @@ struct file_operations {
73021 long (*fallocate)(struct file *file, int mode, loff_t offset,
73022 loff_t len);
73023 int (*show_fdinfo)(struct seq_file *m, struct file *f);
73024-};
73025+} __do_const;
73026+typedef struct file_operations __no_const file_operations_no_const;
73027
73028 struct inode_operations {
73029 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
73030@@ -2740,4 +2741,14 @@ static inline bool dir_relax(struct inode *inode)
73031 return !IS_DEADDIR(inode);
73032 }
73033
73034+static inline bool is_sidechannel_device(const struct inode *inode)
73035+{
73036+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
73037+ umode_t mode = inode->i_mode;
73038+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
73039+#else
73040+ return false;
73041+#endif
73042+}
73043+
73044 #endif /* _LINUX_FS_H */
73045diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
73046index 2b93a9a..855d94a 100644
73047--- a/include/linux/fs_struct.h
73048+++ b/include/linux/fs_struct.h
73049@@ -6,7 +6,7 @@
73050 #include <linux/seqlock.h>
73051
73052 struct fs_struct {
73053- int users;
73054+ atomic_t users;
73055 spinlock_t lock;
73056 seqcount_t seq;
73057 int umask;
73058diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
73059index a9ff9a3..1ba1788 100644
73060--- a/include/linux/fscache-cache.h
73061+++ b/include/linux/fscache-cache.h
73062@@ -113,7 +113,7 @@ struct fscache_operation {
73063 fscache_operation_release_t release;
73064 };
73065
73066-extern atomic_t fscache_op_debug_id;
73067+extern atomic_unchecked_t fscache_op_debug_id;
73068 extern void fscache_op_work_func(struct work_struct *work);
73069
73070 extern void fscache_enqueue_operation(struct fscache_operation *);
73071@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
73072 INIT_WORK(&op->work, fscache_op_work_func);
73073 atomic_set(&op->usage, 1);
73074 op->state = FSCACHE_OP_ST_INITIALISED;
73075- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
73076+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
73077 op->processor = processor;
73078 op->release = release;
73079 INIT_LIST_HEAD(&op->pend_link);
73080diff --git a/include/linux/fscache.h b/include/linux/fscache.h
73081index 7a08623..4c07b0f 100644
73082--- a/include/linux/fscache.h
73083+++ b/include/linux/fscache.h
73084@@ -152,7 +152,7 @@ struct fscache_cookie_def {
73085 * - this is mandatory for any object that may have data
73086 */
73087 void (*now_uncached)(void *cookie_netfs_data);
73088-};
73089+} __do_const;
73090
73091 /*
73092 * fscache cached network filesystem type
73093diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
73094index 1c804b0..1432c2b 100644
73095--- a/include/linux/fsnotify.h
73096+++ b/include/linux/fsnotify.h
73097@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
73098 struct inode *inode = file_inode(file);
73099 __u32 mask = FS_ACCESS;
73100
73101+ if (is_sidechannel_device(inode))
73102+ return;
73103+
73104 if (S_ISDIR(inode->i_mode))
73105 mask |= FS_ISDIR;
73106
73107@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
73108 struct inode *inode = file_inode(file);
73109 __u32 mask = FS_MODIFY;
73110
73111+ if (is_sidechannel_device(inode))
73112+ return;
73113+
73114 if (S_ISDIR(inode->i_mode))
73115 mask |= FS_ISDIR;
73116
73117@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
73118 */
73119 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
73120 {
73121- return kstrdup(name, GFP_KERNEL);
73122+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
73123 }
73124
73125 /*
73126diff --git a/include/linux/genhd.h b/include/linux/genhd.h
73127index 9f3c275..911b591 100644
73128--- a/include/linux/genhd.h
73129+++ b/include/linux/genhd.h
73130@@ -194,7 +194,7 @@ struct gendisk {
73131 struct kobject *slave_dir;
73132
73133 struct timer_rand_state *random;
73134- atomic_t sync_io; /* RAID */
73135+ atomic_unchecked_t sync_io; /* RAID */
73136 struct disk_events *ev;
73137 #ifdef CONFIG_BLK_DEV_INTEGRITY
73138 struct blk_integrity *integrity;
73139diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
73140index 023bc34..b02b46a 100644
73141--- a/include/linux/genl_magic_func.h
73142+++ b/include/linux/genl_magic_func.h
73143@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
73144 },
73145
73146 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
73147-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
73148+static struct genl_ops ZZZ_genl_ops[] = {
73149 #include GENL_MAGIC_INCLUDE_FILE
73150 };
73151
73152diff --git a/include/linux/gfp.h b/include/linux/gfp.h
73153index 9b4dd49..61fd41d 100644
73154--- a/include/linux/gfp.h
73155+++ b/include/linux/gfp.h
73156@@ -35,6 +35,13 @@ struct vm_area_struct;
73157 #define ___GFP_NO_KSWAPD 0x400000u
73158 #define ___GFP_OTHER_NODE 0x800000u
73159 #define ___GFP_WRITE 0x1000000u
73160+
73161+#ifdef CONFIG_PAX_USERCOPY_SLABS
73162+#define ___GFP_USERCOPY 0x2000000u
73163+#else
73164+#define ___GFP_USERCOPY 0
73165+#endif
73166+
73167 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
73168
73169 /*
73170@@ -92,6 +99,7 @@ struct vm_area_struct;
73171 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
73172 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
73173 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
73174+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
73175
73176 /*
73177 * This may seem redundant, but it's a way of annotating false positives vs.
73178@@ -99,7 +107,7 @@ struct vm_area_struct;
73179 */
73180 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
73181
73182-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
73183+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
73184 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
73185
73186 /* This equals 0, but use constants in case they ever change */
73187@@ -153,6 +161,8 @@ struct vm_area_struct;
73188 /* 4GB DMA on some platforms */
73189 #define GFP_DMA32 __GFP_DMA32
73190
73191+#define GFP_USERCOPY __GFP_USERCOPY
73192+
73193 /* Convert GFP flags to their corresponding migrate type */
73194 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
73195 {
73196diff --git a/include/linux/gracl.h b/include/linux/gracl.h
73197new file mode 100644
73198index 0000000..ebe6d72
73199--- /dev/null
73200+++ b/include/linux/gracl.h
73201@@ -0,0 +1,319 @@
73202+#ifndef GR_ACL_H
73203+#define GR_ACL_H
73204+
73205+#include <linux/grdefs.h>
73206+#include <linux/resource.h>
73207+#include <linux/capability.h>
73208+#include <linux/dcache.h>
73209+#include <asm/resource.h>
73210+
73211+/* Major status information */
73212+
73213+#define GR_VERSION "grsecurity 2.9.1"
73214+#define GRSECURITY_VERSION 0x2901
73215+
73216+enum {
73217+ GR_SHUTDOWN = 0,
73218+ GR_ENABLE = 1,
73219+ GR_SPROLE = 2,
73220+ GR_RELOAD = 3,
73221+ GR_SEGVMOD = 4,
73222+ GR_STATUS = 5,
73223+ GR_UNSPROLE = 6,
73224+ GR_PASSSET = 7,
73225+ GR_SPROLEPAM = 8,
73226+};
73227+
73228+/* Password setup definitions
73229+ * kernel/grhash.c */
73230+enum {
73231+ GR_PW_LEN = 128,
73232+ GR_SALT_LEN = 16,
73233+ GR_SHA_LEN = 32,
73234+};
73235+
73236+enum {
73237+ GR_SPROLE_LEN = 64,
73238+};
73239+
73240+enum {
73241+ GR_NO_GLOB = 0,
73242+ GR_REG_GLOB,
73243+ GR_CREATE_GLOB
73244+};
73245+
73246+#define GR_NLIMITS 32
73247+
73248+/* Begin Data Structures */
73249+
73250+struct sprole_pw {
73251+ unsigned char *rolename;
73252+ unsigned char salt[GR_SALT_LEN];
73253+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
73254+};
73255+
73256+struct name_entry {
73257+ __u32 key;
73258+ ino_t inode;
73259+ dev_t device;
73260+ char *name;
73261+ __u16 len;
73262+ __u8 deleted;
73263+ struct name_entry *prev;
73264+ struct name_entry *next;
73265+};
73266+
73267+struct inodev_entry {
73268+ struct name_entry *nentry;
73269+ struct inodev_entry *prev;
73270+ struct inodev_entry *next;
73271+};
73272+
73273+struct acl_role_db {
73274+ struct acl_role_label **r_hash;
73275+ __u32 r_size;
73276+};
73277+
73278+struct inodev_db {
73279+ struct inodev_entry **i_hash;
73280+ __u32 i_size;
73281+};
73282+
73283+struct name_db {
73284+ struct name_entry **n_hash;
73285+ __u32 n_size;
73286+};
73287+
73288+struct crash_uid {
73289+ uid_t uid;
73290+ unsigned long expires;
73291+};
73292+
73293+struct gr_hash_struct {
73294+ void **table;
73295+ void **nametable;
73296+ void *first;
73297+ __u32 table_size;
73298+ __u32 used_size;
73299+ int type;
73300+};
73301+
73302+/* Userspace Grsecurity ACL data structures */
73303+
73304+struct acl_subject_label {
73305+ char *filename;
73306+ ino_t inode;
73307+ dev_t device;
73308+ __u32 mode;
73309+ kernel_cap_t cap_mask;
73310+ kernel_cap_t cap_lower;
73311+ kernel_cap_t cap_invert_audit;
73312+
73313+ struct rlimit res[GR_NLIMITS];
73314+ __u32 resmask;
73315+
73316+ __u8 user_trans_type;
73317+ __u8 group_trans_type;
73318+ uid_t *user_transitions;
73319+ gid_t *group_transitions;
73320+ __u16 user_trans_num;
73321+ __u16 group_trans_num;
73322+
73323+ __u32 sock_families[2];
73324+ __u32 ip_proto[8];
73325+ __u32 ip_type;
73326+ struct acl_ip_label **ips;
73327+ __u32 ip_num;
73328+ __u32 inaddr_any_override;
73329+
73330+ __u32 crashes;
73331+ unsigned long expires;
73332+
73333+ struct acl_subject_label *parent_subject;
73334+ struct gr_hash_struct *hash;
73335+ struct acl_subject_label *prev;
73336+ struct acl_subject_label *next;
73337+
73338+ struct acl_object_label **obj_hash;
73339+ __u32 obj_hash_size;
73340+ __u16 pax_flags;
73341+};
73342+
73343+struct role_allowed_ip {
73344+ __u32 addr;
73345+ __u32 netmask;
73346+
73347+ struct role_allowed_ip *prev;
73348+ struct role_allowed_ip *next;
73349+};
73350+
73351+struct role_transition {
73352+ char *rolename;
73353+
73354+ struct role_transition *prev;
73355+ struct role_transition *next;
73356+};
73357+
73358+struct acl_role_label {
73359+ char *rolename;
73360+ uid_t uidgid;
73361+ __u16 roletype;
73362+
73363+ __u16 auth_attempts;
73364+ unsigned long expires;
73365+
73366+ struct acl_subject_label *root_label;
73367+ struct gr_hash_struct *hash;
73368+
73369+ struct acl_role_label *prev;
73370+ struct acl_role_label *next;
73371+
73372+ struct role_transition *transitions;
73373+ struct role_allowed_ip *allowed_ips;
73374+ uid_t *domain_children;
73375+ __u16 domain_child_num;
73376+
73377+ umode_t umask;
73378+
73379+ struct acl_subject_label **subj_hash;
73380+ __u32 subj_hash_size;
73381+};
73382+
73383+struct user_acl_role_db {
73384+ struct acl_role_label **r_table;
73385+ __u32 num_pointers; /* Number of allocations to track */
73386+ __u32 num_roles; /* Number of roles */
73387+ __u32 num_domain_children; /* Number of domain children */
73388+ __u32 num_subjects; /* Number of subjects */
73389+ __u32 num_objects; /* Number of objects */
73390+};
73391+
73392+struct acl_object_label {
73393+ char *filename;
73394+ ino_t inode;
73395+ dev_t device;
73396+ __u32 mode;
73397+
73398+ struct acl_subject_label *nested;
73399+ struct acl_object_label *globbed;
73400+
73401+ /* next two structures not used */
73402+
73403+ struct acl_object_label *prev;
73404+ struct acl_object_label *next;
73405+};
73406+
73407+struct acl_ip_label {
73408+ char *iface;
73409+ __u32 addr;
73410+ __u32 netmask;
73411+ __u16 low, high;
73412+ __u8 mode;
73413+ __u32 type;
73414+ __u32 proto[8];
73415+
73416+ /* next two structures not used */
73417+
73418+ struct acl_ip_label *prev;
73419+ struct acl_ip_label *next;
73420+};
73421+
73422+struct gr_arg {
73423+ struct user_acl_role_db role_db;
73424+ unsigned char pw[GR_PW_LEN];
73425+ unsigned char salt[GR_SALT_LEN];
73426+ unsigned char sum[GR_SHA_LEN];
73427+ unsigned char sp_role[GR_SPROLE_LEN];
73428+ struct sprole_pw *sprole_pws;
73429+ dev_t segv_device;
73430+ ino_t segv_inode;
73431+ uid_t segv_uid;
73432+ __u16 num_sprole_pws;
73433+ __u16 mode;
73434+};
73435+
73436+struct gr_arg_wrapper {
73437+ struct gr_arg *arg;
73438+ __u32 version;
73439+ __u32 size;
73440+};
73441+
73442+struct subject_map {
73443+ struct acl_subject_label *user;
73444+ struct acl_subject_label *kernel;
73445+ struct subject_map *prev;
73446+ struct subject_map *next;
73447+};
73448+
73449+struct acl_subj_map_db {
73450+ struct subject_map **s_hash;
73451+ __u32 s_size;
73452+};
73453+
73454+/* End Data Structures Section */
73455+
73456+/* Hash functions generated by empirical testing by Brad Spengler
73457+ Makes good use of the low bits of the inode. Generally 0-1 times
73458+ in loop for successful match. 0-3 for unsuccessful match.
73459+ Shift/add algorithm with modulus of table size and an XOR*/
73460+
73461+static __inline__ unsigned int
73462+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
73463+{
73464+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
73465+}
73466+
73467+ static __inline__ unsigned int
73468+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
73469+{
73470+ return ((const unsigned long)userp % sz);
73471+}
73472+
73473+static __inline__ unsigned int
73474+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
73475+{
73476+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
73477+}
73478+
73479+static __inline__ unsigned int
73480+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
73481+{
73482+ return full_name_hash((const unsigned char *)name, len) % sz;
73483+}
73484+
73485+#define FOR_EACH_ROLE_START(role) \
73486+ role = role_list; \
73487+ while (role) {
73488+
73489+#define FOR_EACH_ROLE_END(role) \
73490+ role = role->prev; \
73491+ }
73492+
73493+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
73494+ subj = NULL; \
73495+ iter = 0; \
73496+ while (iter < role->subj_hash_size) { \
73497+ if (subj == NULL) \
73498+ subj = role->subj_hash[iter]; \
73499+ if (subj == NULL) { \
73500+ iter++; \
73501+ continue; \
73502+ }
73503+
73504+#define FOR_EACH_SUBJECT_END(subj,iter) \
73505+ subj = subj->next; \
73506+ if (subj == NULL) \
73507+ iter++; \
73508+ }
73509+
73510+
73511+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
73512+ subj = role->hash->first; \
73513+ while (subj != NULL) {
73514+
73515+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
73516+ subj = subj->next; \
73517+ }
73518+
73519+#endif
73520+
73521diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
73522new file mode 100644
73523index 0000000..33ebd1f
73524--- /dev/null
73525+++ b/include/linux/gracl_compat.h
73526@@ -0,0 +1,156 @@
73527+#ifndef GR_ACL_COMPAT_H
73528+#define GR_ACL_COMPAT_H
73529+
73530+#include <linux/resource.h>
73531+#include <asm/resource.h>
73532+
73533+struct sprole_pw_compat {
73534+ compat_uptr_t rolename;
73535+ unsigned char salt[GR_SALT_LEN];
73536+ unsigned char sum[GR_SHA_LEN];
73537+};
73538+
73539+struct gr_hash_struct_compat {
73540+ compat_uptr_t table;
73541+ compat_uptr_t nametable;
73542+ compat_uptr_t first;
73543+ __u32 table_size;
73544+ __u32 used_size;
73545+ int type;
73546+};
73547+
73548+struct acl_subject_label_compat {
73549+ compat_uptr_t filename;
73550+ compat_ino_t inode;
73551+ __u32 device;
73552+ __u32 mode;
73553+ kernel_cap_t cap_mask;
73554+ kernel_cap_t cap_lower;
73555+ kernel_cap_t cap_invert_audit;
73556+
73557+ struct compat_rlimit res[GR_NLIMITS];
73558+ __u32 resmask;
73559+
73560+ __u8 user_trans_type;
73561+ __u8 group_trans_type;
73562+ compat_uptr_t user_transitions;
73563+ compat_uptr_t group_transitions;
73564+ __u16 user_trans_num;
73565+ __u16 group_trans_num;
73566+
73567+ __u32 sock_families[2];
73568+ __u32 ip_proto[8];
73569+ __u32 ip_type;
73570+ compat_uptr_t ips;
73571+ __u32 ip_num;
73572+ __u32 inaddr_any_override;
73573+
73574+ __u32 crashes;
73575+ compat_ulong_t expires;
73576+
73577+ compat_uptr_t parent_subject;
73578+ compat_uptr_t hash;
73579+ compat_uptr_t prev;
73580+ compat_uptr_t next;
73581+
73582+ compat_uptr_t obj_hash;
73583+ __u32 obj_hash_size;
73584+ __u16 pax_flags;
73585+};
73586+
73587+struct role_allowed_ip_compat {
73588+ __u32 addr;
73589+ __u32 netmask;
73590+
73591+ compat_uptr_t prev;
73592+ compat_uptr_t next;
73593+};
73594+
73595+struct role_transition_compat {
73596+ compat_uptr_t rolename;
73597+
73598+ compat_uptr_t prev;
73599+ compat_uptr_t next;
73600+};
73601+
73602+struct acl_role_label_compat {
73603+ compat_uptr_t rolename;
73604+ uid_t uidgid;
73605+ __u16 roletype;
73606+
73607+ __u16 auth_attempts;
73608+ compat_ulong_t expires;
73609+
73610+ compat_uptr_t root_label;
73611+ compat_uptr_t hash;
73612+
73613+ compat_uptr_t prev;
73614+ compat_uptr_t next;
73615+
73616+ compat_uptr_t transitions;
73617+ compat_uptr_t allowed_ips;
73618+ compat_uptr_t domain_children;
73619+ __u16 domain_child_num;
73620+
73621+ umode_t umask;
73622+
73623+ compat_uptr_t subj_hash;
73624+ __u32 subj_hash_size;
73625+};
73626+
73627+struct user_acl_role_db_compat {
73628+ compat_uptr_t r_table;
73629+ __u32 num_pointers;
73630+ __u32 num_roles;
73631+ __u32 num_domain_children;
73632+ __u32 num_subjects;
73633+ __u32 num_objects;
73634+};
73635+
73636+struct acl_object_label_compat {
73637+ compat_uptr_t filename;
73638+ compat_ino_t inode;
73639+ __u32 device;
73640+ __u32 mode;
73641+
73642+ compat_uptr_t nested;
73643+ compat_uptr_t globbed;
73644+
73645+ compat_uptr_t prev;
73646+ compat_uptr_t next;
73647+};
73648+
73649+struct acl_ip_label_compat {
73650+ compat_uptr_t iface;
73651+ __u32 addr;
73652+ __u32 netmask;
73653+ __u16 low, high;
73654+ __u8 mode;
73655+ __u32 type;
73656+ __u32 proto[8];
73657+
73658+ compat_uptr_t prev;
73659+ compat_uptr_t next;
73660+};
73661+
73662+struct gr_arg_compat {
73663+ struct user_acl_role_db_compat role_db;
73664+ unsigned char pw[GR_PW_LEN];
73665+ unsigned char salt[GR_SALT_LEN];
73666+ unsigned char sum[GR_SHA_LEN];
73667+ unsigned char sp_role[GR_SPROLE_LEN];
73668+ compat_uptr_t sprole_pws;
73669+ __u32 segv_device;
73670+ compat_ino_t segv_inode;
73671+ uid_t segv_uid;
73672+ __u16 num_sprole_pws;
73673+ __u16 mode;
73674+};
73675+
73676+struct gr_arg_wrapper_compat {
73677+ compat_uptr_t arg;
73678+ __u32 version;
73679+ __u32 size;
73680+};
73681+
73682+#endif
73683diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
73684new file mode 100644
73685index 0000000..323ecf2
73686--- /dev/null
73687+++ b/include/linux/gralloc.h
73688@@ -0,0 +1,9 @@
73689+#ifndef __GRALLOC_H
73690+#define __GRALLOC_H
73691+
73692+void acl_free_all(void);
73693+int acl_alloc_stack_init(unsigned long size);
73694+void *acl_alloc(unsigned long len);
73695+void *acl_alloc_num(unsigned long num, unsigned long len);
73696+
73697+#endif
73698diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
73699new file mode 100644
73700index 0000000..be66033
73701--- /dev/null
73702+++ b/include/linux/grdefs.h
73703@@ -0,0 +1,140 @@
73704+#ifndef GRDEFS_H
73705+#define GRDEFS_H
73706+
73707+/* Begin grsecurity status declarations */
73708+
73709+enum {
73710+ GR_READY = 0x01,
73711+ GR_STATUS_INIT = 0x00 // disabled state
73712+};
73713+
73714+/* Begin ACL declarations */
73715+
73716+/* Role flags */
73717+
73718+enum {
73719+ GR_ROLE_USER = 0x0001,
73720+ GR_ROLE_GROUP = 0x0002,
73721+ GR_ROLE_DEFAULT = 0x0004,
73722+ GR_ROLE_SPECIAL = 0x0008,
73723+ GR_ROLE_AUTH = 0x0010,
73724+ GR_ROLE_NOPW = 0x0020,
73725+ GR_ROLE_GOD = 0x0040,
73726+ GR_ROLE_LEARN = 0x0080,
73727+ GR_ROLE_TPE = 0x0100,
73728+ GR_ROLE_DOMAIN = 0x0200,
73729+ GR_ROLE_PAM = 0x0400,
73730+ GR_ROLE_PERSIST = 0x0800
73731+};
73732+
73733+/* ACL Subject and Object mode flags */
73734+enum {
73735+ GR_DELETED = 0x80000000
73736+};
73737+
73738+/* ACL Object-only mode flags */
73739+enum {
73740+ GR_READ = 0x00000001,
73741+ GR_APPEND = 0x00000002,
73742+ GR_WRITE = 0x00000004,
73743+ GR_EXEC = 0x00000008,
73744+ GR_FIND = 0x00000010,
73745+ GR_INHERIT = 0x00000020,
73746+ GR_SETID = 0x00000040,
73747+ GR_CREATE = 0x00000080,
73748+ GR_DELETE = 0x00000100,
73749+ GR_LINK = 0x00000200,
73750+ GR_AUDIT_READ = 0x00000400,
73751+ GR_AUDIT_APPEND = 0x00000800,
73752+ GR_AUDIT_WRITE = 0x00001000,
73753+ GR_AUDIT_EXEC = 0x00002000,
73754+ GR_AUDIT_FIND = 0x00004000,
73755+ GR_AUDIT_INHERIT= 0x00008000,
73756+ GR_AUDIT_SETID = 0x00010000,
73757+ GR_AUDIT_CREATE = 0x00020000,
73758+ GR_AUDIT_DELETE = 0x00040000,
73759+ GR_AUDIT_LINK = 0x00080000,
73760+ GR_PTRACERD = 0x00100000,
73761+ GR_NOPTRACE = 0x00200000,
73762+ GR_SUPPRESS = 0x00400000,
73763+ GR_NOLEARN = 0x00800000,
73764+ GR_INIT_TRANSFER= 0x01000000
73765+};
73766+
73767+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
73768+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
73769+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
73770+
73771+/* ACL subject-only mode flags */
73772+enum {
73773+ GR_KILL = 0x00000001,
73774+ GR_VIEW = 0x00000002,
73775+ GR_PROTECTED = 0x00000004,
73776+ GR_LEARN = 0x00000008,
73777+ GR_OVERRIDE = 0x00000010,
73778+ /* just a placeholder, this mode is only used in userspace */
73779+ GR_DUMMY = 0x00000020,
73780+ GR_PROTSHM = 0x00000040,
73781+ GR_KILLPROC = 0x00000080,
73782+ GR_KILLIPPROC = 0x00000100,
73783+ /* just a placeholder, this mode is only used in userspace */
73784+ GR_NOTROJAN = 0x00000200,
73785+ GR_PROTPROCFD = 0x00000400,
73786+ GR_PROCACCT = 0x00000800,
73787+ GR_RELAXPTRACE = 0x00001000,
73788+ //GR_NESTED = 0x00002000,
73789+ GR_INHERITLEARN = 0x00004000,
73790+ GR_PROCFIND = 0x00008000,
73791+ GR_POVERRIDE = 0x00010000,
73792+ GR_KERNELAUTH = 0x00020000,
73793+ GR_ATSECURE = 0x00040000,
73794+ GR_SHMEXEC = 0x00080000
73795+};
73796+
73797+enum {
73798+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
73799+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
73800+ GR_PAX_ENABLE_MPROTECT = 0x0004,
73801+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
73802+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
73803+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
73804+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
73805+ GR_PAX_DISABLE_MPROTECT = 0x0400,
73806+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
73807+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
73808+};
73809+
73810+enum {
73811+ GR_ID_USER = 0x01,
73812+ GR_ID_GROUP = 0x02,
73813+};
73814+
73815+enum {
73816+ GR_ID_ALLOW = 0x01,
73817+ GR_ID_DENY = 0x02,
73818+};
73819+
73820+#define GR_CRASH_RES 31
73821+#define GR_UIDTABLE_MAX 500
73822+
73823+/* begin resource learning section */
73824+enum {
73825+ GR_RLIM_CPU_BUMP = 60,
73826+ GR_RLIM_FSIZE_BUMP = 50000,
73827+ GR_RLIM_DATA_BUMP = 10000,
73828+ GR_RLIM_STACK_BUMP = 1000,
73829+ GR_RLIM_CORE_BUMP = 10000,
73830+ GR_RLIM_RSS_BUMP = 500000,
73831+ GR_RLIM_NPROC_BUMP = 1,
73832+ GR_RLIM_NOFILE_BUMP = 5,
73833+ GR_RLIM_MEMLOCK_BUMP = 50000,
73834+ GR_RLIM_AS_BUMP = 500000,
73835+ GR_RLIM_LOCKS_BUMP = 2,
73836+ GR_RLIM_SIGPENDING_BUMP = 5,
73837+ GR_RLIM_MSGQUEUE_BUMP = 10000,
73838+ GR_RLIM_NICE_BUMP = 1,
73839+ GR_RLIM_RTPRIO_BUMP = 1,
73840+ GR_RLIM_RTTIME_BUMP = 1000000
73841+};
73842+
73843+#endif
73844diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
73845new file mode 100644
73846index 0000000..e337683
73847--- /dev/null
73848+++ b/include/linux/grinternal.h
73849@@ -0,0 +1,229 @@
73850+#ifndef __GRINTERNAL_H
73851+#define __GRINTERNAL_H
73852+
73853+#ifdef CONFIG_GRKERNSEC
73854+
73855+#include <linux/fs.h>
73856+#include <linux/mnt_namespace.h>
73857+#include <linux/nsproxy.h>
73858+#include <linux/gracl.h>
73859+#include <linux/grdefs.h>
73860+#include <linux/grmsg.h>
73861+
73862+void gr_add_learn_entry(const char *fmt, ...)
73863+ __attribute__ ((format (printf, 1, 2)));
73864+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
73865+ const struct vfsmount *mnt);
73866+__u32 gr_check_create(const struct dentry *new_dentry,
73867+ const struct dentry *parent,
73868+ const struct vfsmount *mnt, const __u32 mode);
73869+int gr_check_protected_task(const struct task_struct *task);
73870+__u32 to_gr_audit(const __u32 reqmode);
73871+int gr_set_acls(const int type);
73872+int gr_apply_subject_to_task(struct task_struct *task);
73873+int gr_acl_is_enabled(void);
73874+char gr_roletype_to_char(void);
73875+
73876+void gr_handle_alertkill(struct task_struct *task);
73877+char *gr_to_filename(const struct dentry *dentry,
73878+ const struct vfsmount *mnt);
73879+char *gr_to_filename1(const struct dentry *dentry,
73880+ const struct vfsmount *mnt);
73881+char *gr_to_filename2(const struct dentry *dentry,
73882+ const struct vfsmount *mnt);
73883+char *gr_to_filename3(const struct dentry *dentry,
73884+ const struct vfsmount *mnt);
73885+
73886+extern int grsec_enable_ptrace_readexec;
73887+extern int grsec_enable_harden_ptrace;
73888+extern int grsec_enable_link;
73889+extern int grsec_enable_fifo;
73890+extern int grsec_enable_execve;
73891+extern int grsec_enable_shm;
73892+extern int grsec_enable_execlog;
73893+extern int grsec_enable_signal;
73894+extern int grsec_enable_audit_ptrace;
73895+extern int grsec_enable_forkfail;
73896+extern int grsec_enable_time;
73897+extern int grsec_enable_rofs;
73898+extern int grsec_deny_new_usb;
73899+extern int grsec_enable_chroot_shmat;
73900+extern int grsec_enable_chroot_mount;
73901+extern int grsec_enable_chroot_double;
73902+extern int grsec_enable_chroot_pivot;
73903+extern int grsec_enable_chroot_chdir;
73904+extern int grsec_enable_chroot_chmod;
73905+extern int grsec_enable_chroot_mknod;
73906+extern int grsec_enable_chroot_fchdir;
73907+extern int grsec_enable_chroot_nice;
73908+extern int grsec_enable_chroot_execlog;
73909+extern int grsec_enable_chroot_caps;
73910+extern int grsec_enable_chroot_sysctl;
73911+extern int grsec_enable_chroot_unix;
73912+extern int grsec_enable_symlinkown;
73913+extern kgid_t grsec_symlinkown_gid;
73914+extern int grsec_enable_tpe;
73915+extern kgid_t grsec_tpe_gid;
73916+extern int grsec_enable_tpe_all;
73917+extern int grsec_enable_tpe_invert;
73918+extern int grsec_enable_socket_all;
73919+extern kgid_t grsec_socket_all_gid;
73920+extern int grsec_enable_socket_client;
73921+extern kgid_t grsec_socket_client_gid;
73922+extern int grsec_enable_socket_server;
73923+extern kgid_t grsec_socket_server_gid;
73924+extern kgid_t grsec_audit_gid;
73925+extern int grsec_enable_group;
73926+extern int grsec_enable_log_rwxmaps;
73927+extern int grsec_enable_mount;
73928+extern int grsec_enable_chdir;
73929+extern int grsec_resource_logging;
73930+extern int grsec_enable_blackhole;
73931+extern int grsec_lastack_retries;
73932+extern int grsec_enable_brute;
73933+extern int grsec_lock;
73934+
73935+extern spinlock_t grsec_alert_lock;
73936+extern unsigned long grsec_alert_wtime;
73937+extern unsigned long grsec_alert_fyet;
73938+
73939+extern spinlock_t grsec_audit_lock;
73940+
73941+extern rwlock_t grsec_exec_file_lock;
73942+
73943+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
73944+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
73945+ (tsk)->exec_file->f_path.mnt) : "/")
73946+
73947+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
73948+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
73949+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
73950+
73951+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
73952+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
73953+ (tsk)->exec_file->f_path.mnt) : "/")
73954+
73955+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
73956+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
73957+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
73958+
73959+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
73960+
73961+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
73962+
73963+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
73964+{
73965+ if (file1 && file2) {
73966+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
73967+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
73968+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
73969+ return true;
73970+ }
73971+
73972+ return false;
73973+}
73974+
73975+#define GR_CHROOT_CAPS {{ \
73976+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
73977+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
73978+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
73979+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
73980+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
73981+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
73982+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
73983+
73984+#define security_learn(normal_msg,args...) \
73985+({ \
73986+ read_lock(&grsec_exec_file_lock); \
73987+ gr_add_learn_entry(normal_msg "\n", ## args); \
73988+ read_unlock(&grsec_exec_file_lock); \
73989+})
73990+
73991+enum {
73992+ GR_DO_AUDIT,
73993+ GR_DONT_AUDIT,
73994+ /* used for non-audit messages that we shouldn't kill the task on */
73995+ GR_DONT_AUDIT_GOOD
73996+};
73997+
73998+enum {
73999+ GR_TTYSNIFF,
74000+ GR_RBAC,
74001+ GR_RBAC_STR,
74002+ GR_STR_RBAC,
74003+ GR_RBAC_MODE2,
74004+ GR_RBAC_MODE3,
74005+ GR_FILENAME,
74006+ GR_SYSCTL_HIDDEN,
74007+ GR_NOARGS,
74008+ GR_ONE_INT,
74009+ GR_ONE_INT_TWO_STR,
74010+ GR_ONE_STR,
74011+ GR_STR_INT,
74012+ GR_TWO_STR_INT,
74013+ GR_TWO_INT,
74014+ GR_TWO_U64,
74015+ GR_THREE_INT,
74016+ GR_FIVE_INT_TWO_STR,
74017+ GR_TWO_STR,
74018+ GR_THREE_STR,
74019+ GR_FOUR_STR,
74020+ GR_STR_FILENAME,
74021+ GR_FILENAME_STR,
74022+ GR_FILENAME_TWO_INT,
74023+ GR_FILENAME_TWO_INT_STR,
74024+ GR_TEXTREL,
74025+ GR_PTRACE,
74026+ GR_RESOURCE,
74027+ GR_CAP,
74028+ GR_SIG,
74029+ GR_SIG2,
74030+ GR_CRASH1,
74031+ GR_CRASH2,
74032+ GR_PSACCT,
74033+ GR_RWXMAP,
74034+ GR_RWXMAPVMA
74035+};
74036+
74037+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
74038+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
74039+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
74040+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
74041+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
74042+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
74043+#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)
74044+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
74045+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
74046+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
74047+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
74048+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
74049+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
74050+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
74051+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
74052+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
74053+#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)
74054+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
74055+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
74056+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
74057+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
74058+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
74059+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
74060+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
74061+#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)
74062+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
74063+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
74064+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
74065+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
74066+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
74067+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
74068+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
74069+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
74070+#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)
74071+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
74072+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
74073+
74074+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
74075+
74076+#endif
74077+
74078+#endif
74079diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
74080new file mode 100644
74081index 0000000..a4396b5
74082--- /dev/null
74083+++ b/include/linux/grmsg.h
74084@@ -0,0 +1,113 @@
74085+#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"
74086+#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"
74087+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
74088+#define GR_STOPMOD_MSG "denied modification of module state by "
74089+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
74090+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
74091+#define GR_IOPERM_MSG "denied use of ioperm() by "
74092+#define GR_IOPL_MSG "denied use of iopl() by "
74093+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
74094+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
74095+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
74096+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
74097+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
74098+#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"
74099+#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"
74100+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
74101+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
74102+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
74103+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
74104+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
74105+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
74106+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
74107+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
74108+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
74109+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
74110+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
74111+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
74112+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
74113+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
74114+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
74115+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
74116+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
74117+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
74118+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
74119+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
74120+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
74121+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
74122+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
74123+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
74124+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
74125+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
74126+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
74127+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
74128+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
74129+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
74130+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
74131+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
74132+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
74133+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
74134+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
74135+#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"
74136+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
74137+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
74138+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
74139+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
74140+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
74141+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
74142+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
74143+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
74144+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
74145+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
74146+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
74147+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
74148+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
74149+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
74150+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
74151+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
74152+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
74153+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
74154+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
74155+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
74156+#define GR_FAILFORK_MSG "failed fork with errno %s by "
74157+#define GR_NICE_CHROOT_MSG "denied priority change by "
74158+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
74159+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
74160+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
74161+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
74162+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
74163+#define GR_TIME_MSG "time set by "
74164+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
74165+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
74166+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
74167+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
74168+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
74169+#define GR_BIND_MSG "denied bind() by "
74170+#define GR_CONNECT_MSG "denied connect() by "
74171+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
74172+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
74173+#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"
74174+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
74175+#define GR_CAP_ACL_MSG "use of %s denied for "
74176+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
74177+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
74178+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
74179+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
74180+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
74181+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
74182+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
74183+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
74184+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
74185+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
74186+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
74187+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
74188+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
74189+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
74190+#define GR_VM86_MSG "denied use of vm86 by "
74191+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
74192+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
74193+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
74194+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
74195+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
74196+#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 "
74197+#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 "
74198diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
74199new file mode 100644
74200index 0000000..d6f5a21
74201--- /dev/null
74202+++ b/include/linux/grsecurity.h
74203@@ -0,0 +1,244 @@
74204+#ifndef GR_SECURITY_H
74205+#define GR_SECURITY_H
74206+#include <linux/fs.h>
74207+#include <linux/fs_struct.h>
74208+#include <linux/binfmts.h>
74209+#include <linux/gracl.h>
74210+
74211+/* notify of brain-dead configs */
74212+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
74213+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
74214+#endif
74215+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
74216+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
74217+#endif
74218+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
74219+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
74220+#endif
74221+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
74222+#error "CONFIG_PAX enabled, but no PaX options are enabled."
74223+#endif
74224+
74225+int gr_handle_new_usb(void);
74226+
74227+void gr_handle_brute_attach(unsigned long mm_flags);
74228+void gr_handle_brute_check(void);
74229+void gr_handle_kernel_exploit(void);
74230+
74231+char gr_roletype_to_char(void);
74232+
74233+int gr_acl_enable_at_secure(void);
74234+
74235+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
74236+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
74237+
74238+void gr_del_task_from_ip_table(struct task_struct *p);
74239+
74240+int gr_pid_is_chrooted(struct task_struct *p);
74241+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
74242+int gr_handle_chroot_nice(void);
74243+int gr_handle_chroot_sysctl(const int op);
74244+int gr_handle_chroot_setpriority(struct task_struct *p,
74245+ const int niceval);
74246+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
74247+int gr_handle_chroot_chroot(const struct dentry *dentry,
74248+ const struct vfsmount *mnt);
74249+void gr_handle_chroot_chdir(const struct path *path);
74250+int gr_handle_chroot_chmod(const struct dentry *dentry,
74251+ const struct vfsmount *mnt, const int mode);
74252+int gr_handle_chroot_mknod(const struct dentry *dentry,
74253+ const struct vfsmount *mnt, const int mode);
74254+int gr_handle_chroot_mount(const struct dentry *dentry,
74255+ const struct vfsmount *mnt,
74256+ const char *dev_name);
74257+int gr_handle_chroot_pivot(void);
74258+int gr_handle_chroot_unix(const pid_t pid);
74259+
74260+int gr_handle_rawio(const struct inode *inode);
74261+
74262+void gr_handle_ioperm(void);
74263+void gr_handle_iopl(void);
74264+
74265+umode_t gr_acl_umask(void);
74266+
74267+int gr_tpe_allow(const struct file *file);
74268+
74269+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
74270+void gr_clear_chroot_entries(struct task_struct *task);
74271+
74272+void gr_log_forkfail(const int retval);
74273+void gr_log_timechange(void);
74274+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
74275+void gr_log_chdir(const struct dentry *dentry,
74276+ const struct vfsmount *mnt);
74277+void gr_log_chroot_exec(const struct dentry *dentry,
74278+ const struct vfsmount *mnt);
74279+void gr_log_remount(const char *devname, const int retval);
74280+void gr_log_unmount(const char *devname, const int retval);
74281+void gr_log_mount(const char *from, const char *to, const int retval);
74282+void gr_log_textrel(struct vm_area_struct *vma);
74283+void gr_log_ptgnustack(struct file *file);
74284+void gr_log_rwxmmap(struct file *file);
74285+void gr_log_rwxmprotect(struct vm_area_struct *vma);
74286+
74287+int gr_handle_follow_link(const struct inode *parent,
74288+ const struct inode *inode,
74289+ const struct dentry *dentry,
74290+ const struct vfsmount *mnt);
74291+int gr_handle_fifo(const struct dentry *dentry,
74292+ const struct vfsmount *mnt,
74293+ const struct dentry *dir, const int flag,
74294+ const int acc_mode);
74295+int gr_handle_hardlink(const struct dentry *dentry,
74296+ const struct vfsmount *mnt,
74297+ struct inode *inode,
74298+ const int mode, const struct filename *to);
74299+
74300+int gr_is_capable(const int cap);
74301+int gr_is_capable_nolog(const int cap);
74302+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74303+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
74304+
74305+void gr_copy_label(struct task_struct *tsk);
74306+void gr_handle_crash(struct task_struct *task, const int sig);
74307+int gr_handle_signal(const struct task_struct *p, const int sig);
74308+int gr_check_crash_uid(const kuid_t uid);
74309+int gr_check_protected_task(const struct task_struct *task);
74310+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
74311+int gr_acl_handle_mmap(const struct file *file,
74312+ const unsigned long prot);
74313+int gr_acl_handle_mprotect(const struct file *file,
74314+ const unsigned long prot);
74315+int gr_check_hidden_task(const struct task_struct *tsk);
74316+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
74317+ const struct vfsmount *mnt);
74318+__u32 gr_acl_handle_utime(const struct dentry *dentry,
74319+ const struct vfsmount *mnt);
74320+__u32 gr_acl_handle_access(const struct dentry *dentry,
74321+ const struct vfsmount *mnt, const int fmode);
74322+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
74323+ const struct vfsmount *mnt, umode_t *mode);
74324+__u32 gr_acl_handle_chown(const struct dentry *dentry,
74325+ const struct vfsmount *mnt);
74326+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
74327+ const struct vfsmount *mnt);
74328+int gr_handle_ptrace(struct task_struct *task, const long request);
74329+int gr_handle_proc_ptrace(struct task_struct *task);
74330+__u32 gr_acl_handle_execve(const struct dentry *dentry,
74331+ const struct vfsmount *mnt);
74332+int gr_check_crash_exec(const struct file *filp);
74333+int gr_acl_is_enabled(void);
74334+void gr_set_kernel_label(struct task_struct *task);
74335+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
74336+ const kgid_t gid);
74337+int gr_set_proc_label(const struct dentry *dentry,
74338+ const struct vfsmount *mnt,
74339+ const int unsafe_flags);
74340+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
74341+ const struct vfsmount *mnt);
74342+__u32 gr_acl_handle_open(const struct dentry *dentry,
74343+ const struct vfsmount *mnt, int acc_mode);
74344+__u32 gr_acl_handle_creat(const struct dentry *dentry,
74345+ const struct dentry *p_dentry,
74346+ const struct vfsmount *p_mnt,
74347+ int open_flags, int acc_mode, const int imode);
74348+void gr_handle_create(const struct dentry *dentry,
74349+ const struct vfsmount *mnt);
74350+void gr_handle_proc_create(const struct dentry *dentry,
74351+ const struct inode *inode);
74352+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
74353+ const struct dentry *parent_dentry,
74354+ const struct vfsmount *parent_mnt,
74355+ const int mode);
74356+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
74357+ const struct dentry *parent_dentry,
74358+ const struct vfsmount *parent_mnt);
74359+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
74360+ const struct vfsmount *mnt);
74361+void gr_handle_delete(const ino_t ino, const dev_t dev);
74362+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
74363+ const struct vfsmount *mnt);
74364+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
74365+ const struct dentry *parent_dentry,
74366+ const struct vfsmount *parent_mnt,
74367+ const struct filename *from);
74368+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
74369+ const struct dentry *parent_dentry,
74370+ const struct vfsmount *parent_mnt,
74371+ const struct dentry *old_dentry,
74372+ const struct vfsmount *old_mnt, const struct filename *to);
74373+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
74374+int gr_acl_handle_rename(struct dentry *new_dentry,
74375+ struct dentry *parent_dentry,
74376+ const struct vfsmount *parent_mnt,
74377+ struct dentry *old_dentry,
74378+ struct inode *old_parent_inode,
74379+ struct vfsmount *old_mnt, const struct filename *newname);
74380+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74381+ struct dentry *old_dentry,
74382+ struct dentry *new_dentry,
74383+ struct vfsmount *mnt, const __u8 replace);
74384+__u32 gr_check_link(const struct dentry *new_dentry,
74385+ const struct dentry *parent_dentry,
74386+ const struct vfsmount *parent_mnt,
74387+ const struct dentry *old_dentry,
74388+ const struct vfsmount *old_mnt);
74389+int gr_acl_handle_filldir(const struct file *file, const char *name,
74390+ const unsigned int namelen, const ino_t ino);
74391+
74392+__u32 gr_acl_handle_unix(const struct dentry *dentry,
74393+ const struct vfsmount *mnt);
74394+void gr_acl_handle_exit(void);
74395+void gr_acl_handle_psacct(struct task_struct *task, const long code);
74396+int gr_acl_handle_procpidmem(const struct task_struct *task);
74397+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
74398+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
74399+void gr_audit_ptrace(struct task_struct *task);
74400+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
74401+void gr_put_exec_file(struct task_struct *task);
74402+
74403+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
74404+
74405+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
74406+extern void gr_learn_resource(const struct task_struct *task, const int res,
74407+ const unsigned long wanted, const int gt);
74408+#else
74409+static inline void gr_learn_resource(const struct task_struct *task, const int res,
74410+ const unsigned long wanted, const int gt)
74411+{
74412+}
74413+#endif
74414+
74415+#ifdef CONFIG_GRKERNSEC_RESLOG
74416+extern void gr_log_resource(const struct task_struct *task, const int res,
74417+ const unsigned long wanted, const int gt);
74418+#else
74419+static inline void gr_log_resource(const struct task_struct *task, const int res,
74420+ const unsigned long wanted, const int gt)
74421+{
74422+}
74423+#endif
74424+
74425+#ifdef CONFIG_GRKERNSEC
74426+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
74427+void gr_handle_vm86(void);
74428+void gr_handle_mem_readwrite(u64 from, u64 to);
74429+
74430+void gr_log_badprocpid(const char *entry);
74431+
74432+extern int grsec_enable_dmesg;
74433+extern int grsec_disable_privio;
74434+
74435+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74436+extern kgid_t grsec_proc_gid;
74437+#endif
74438+
74439+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74440+extern int grsec_enable_chroot_findtask;
74441+#endif
74442+#ifdef CONFIG_GRKERNSEC_SETXID
74443+extern int grsec_enable_setxid;
74444+#endif
74445+#endif
74446+
74447+#endif
74448diff --git a/include/linux/grsock.h b/include/linux/grsock.h
74449new file mode 100644
74450index 0000000..e7ffaaf
74451--- /dev/null
74452+++ b/include/linux/grsock.h
74453@@ -0,0 +1,19 @@
74454+#ifndef __GRSOCK_H
74455+#define __GRSOCK_H
74456+
74457+extern void gr_attach_curr_ip(const struct sock *sk);
74458+extern int gr_handle_sock_all(const int family, const int type,
74459+ const int protocol);
74460+extern int gr_handle_sock_server(const struct sockaddr *sck);
74461+extern int gr_handle_sock_server_other(const struct sock *sck);
74462+extern int gr_handle_sock_client(const struct sockaddr *sck);
74463+extern int gr_search_connect(struct socket * sock,
74464+ struct sockaddr_in * addr);
74465+extern int gr_search_bind(struct socket * sock,
74466+ struct sockaddr_in * addr);
74467+extern int gr_search_listen(struct socket * sock);
74468+extern int gr_search_accept(struct socket * sock);
74469+extern int gr_search_socket(const int domain, const int type,
74470+ const int protocol);
74471+
74472+#endif
74473diff --git a/include/linux/hid.h b/include/linux/hid.h
74474index 0c48991..76e41d8 100644
74475--- a/include/linux/hid.h
74476+++ b/include/linux/hid.h
74477@@ -393,10 +393,12 @@ struct hid_report {
74478 struct hid_device *device; /* associated device */
74479 };
74480
74481+#define HID_MAX_IDS 256
74482+
74483 struct hid_report_enum {
74484 unsigned numbered;
74485 struct list_head report_list;
74486- struct hid_report *report_id_hash[256];
74487+ struct hid_report *report_id_hash[HID_MAX_IDS];
74488 };
74489
74490 #define HID_REPORT_TYPES 3
74491@@ -747,6 +749,10 @@ void hid_output_report(struct hid_report *report, __u8 *data);
74492 struct hid_device *hid_allocate_device(void);
74493 struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id);
74494 int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size);
74495+struct hid_report *hid_validate_report(struct hid_device *hid,
74496+ unsigned int type, unsigned int id,
74497+ unsigned int fields,
74498+ unsigned int report_counts);
74499 int hid_open_report(struct hid_device *device);
74500 int hid_check_keys_pressed(struct hid_device *hid);
74501 int hid_connect(struct hid_device *hid, unsigned int connect_mask);
74502diff --git a/include/linux/highmem.h b/include/linux/highmem.h
74503index 7fb31da..08b5114 100644
74504--- a/include/linux/highmem.h
74505+++ b/include/linux/highmem.h
74506@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
74507 kunmap_atomic(kaddr);
74508 }
74509
74510+static inline void sanitize_highpage(struct page *page)
74511+{
74512+ void *kaddr;
74513+ unsigned long flags;
74514+
74515+ local_irq_save(flags);
74516+ kaddr = kmap_atomic(page);
74517+ clear_page(kaddr);
74518+ kunmap_atomic(kaddr);
74519+ local_irq_restore(flags);
74520+}
74521+
74522 static inline void zero_user_segments(struct page *page,
74523 unsigned start1, unsigned end1,
74524 unsigned start2, unsigned end2)
74525diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
74526index 1c7b89a..7f52502 100644
74527--- a/include/linux/hwmon-sysfs.h
74528+++ b/include/linux/hwmon-sysfs.h
74529@@ -25,7 +25,8 @@
74530 struct sensor_device_attribute{
74531 struct device_attribute dev_attr;
74532 int index;
74533-};
74534+} __do_const;
74535+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
74536 #define to_sensor_dev_attr(_dev_attr) \
74537 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
74538
74539@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
74540 struct device_attribute dev_attr;
74541 u8 index;
74542 u8 nr;
74543-};
74544+} __do_const;
74545 #define to_sensor_dev_attr_2(_dev_attr) \
74546 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
74547
74548diff --git a/include/linux/i2c.h b/include/linux/i2c.h
74549index e988fa9..ff9f17e 100644
74550--- a/include/linux/i2c.h
74551+++ b/include/linux/i2c.h
74552@@ -366,6 +366,7 @@ struct i2c_algorithm {
74553 /* To determine what the adapter supports */
74554 u32 (*functionality) (struct i2c_adapter *);
74555 };
74556+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
74557
74558 /**
74559 * struct i2c_bus_recovery_info - I2C bus recovery information
74560diff --git a/include/linux/i2o.h b/include/linux/i2o.h
74561index d23c3c2..eb63c81 100644
74562--- a/include/linux/i2o.h
74563+++ b/include/linux/i2o.h
74564@@ -565,7 +565,7 @@ struct i2o_controller {
74565 struct i2o_device *exec; /* Executive */
74566 #if BITS_PER_LONG == 64
74567 spinlock_t context_list_lock; /* lock for context_list */
74568- atomic_t context_list_counter; /* needed for unique contexts */
74569+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
74570 struct list_head context_list; /* list of context id's
74571 and pointers */
74572 #endif
74573diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
74574index aff7ad8..3942bbd 100644
74575--- a/include/linux/if_pppox.h
74576+++ b/include/linux/if_pppox.h
74577@@ -76,7 +76,7 @@ struct pppox_proto {
74578 int (*ioctl)(struct socket *sock, unsigned int cmd,
74579 unsigned long arg);
74580 struct module *owner;
74581-};
74582+} __do_const;
74583
74584 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
74585 extern void unregister_pppox_proto(int proto_num);
74586diff --git a/include/linux/init.h b/include/linux/init.h
74587index e73f2b7..3a5082b 100644
74588--- a/include/linux/init.h
74589+++ b/include/linux/init.h
74590@@ -39,9 +39,22 @@
74591 * Also note, that this data cannot be "const".
74592 */
74593
74594+#ifdef MODULE
74595+#define add_init_latent_entropy
74596+#define add_meminit_latent_entropy
74597+#else
74598+#define add_init_latent_entropy __latent_entropy
74599+
74600+#ifdef CONFIG_MEMORY_HOTPLUG
74601+#define add_meminit_latent_entropy
74602+#else
74603+#define add_meminit_latent_entropy __latent_entropy
74604+#endif
74605+#endif
74606+
74607 /* These are for everybody (although not all archs will actually
74608 discard it in modules) */
74609-#define __init __section(.init.text) __cold notrace
74610+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
74611 #define __initdata __section(.init.data)
74612 #define __initconst __constsection(.init.rodata)
74613 #define __exitdata __section(.exit.data)
74614@@ -102,7 +115,7 @@
74615 #define __cpuexitconst
74616
74617 /* Used for MEMORY_HOTPLUG */
74618-#define __meminit __section(.meminit.text) __cold notrace
74619+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
74620 #define __meminitdata __section(.meminit.data)
74621 #define __meminitconst __constsection(.meminit.rodata)
74622 #define __memexit __section(.memexit.text) __exitused __cold notrace
74623diff --git a/include/linux/init_task.h b/include/linux/init_task.h
74624index 5cd0f09..c9f67cc 100644
74625--- a/include/linux/init_task.h
74626+++ b/include/linux/init_task.h
74627@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
74628
74629 #define INIT_TASK_COMM "swapper"
74630
74631+#ifdef CONFIG_X86
74632+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
74633+#else
74634+#define INIT_TASK_THREAD_INFO
74635+#endif
74636+
74637 /*
74638 * INIT_TASK is used to set up the first task table, touch at
74639 * your own risk!. Base=0, limit=0x1fffff (=2MB)
74640@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
74641 RCU_POINTER_INITIALIZER(cred, &init_cred), \
74642 .comm = INIT_TASK_COMM, \
74643 .thread = INIT_THREAD, \
74644+ INIT_TASK_THREAD_INFO \
74645 .fs = &init_fs, \
74646 .files = &init_files, \
74647 .signal = &init_signals, \
74648diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
74649index 5fa5afe..ac55b25 100644
74650--- a/include/linux/interrupt.h
74651+++ b/include/linux/interrupt.h
74652@@ -430,7 +430,7 @@ enum
74653 /* map softirq index to softirq name. update 'softirq_to_name' in
74654 * kernel/softirq.c when adding a new softirq.
74655 */
74656-extern char *softirq_to_name[NR_SOFTIRQS];
74657+extern const char * const softirq_to_name[NR_SOFTIRQS];
74658
74659 /* softirq mask and active fields moved to irq_cpustat_t in
74660 * asm/hardirq.h to get better cache usage. KAO
74661@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
74662
74663 struct softirq_action
74664 {
74665- void (*action)(struct softirq_action *);
74666-};
74667+ void (*action)(void);
74668+} __no_const;
74669
74670 asmlinkage void do_softirq(void);
74671 asmlinkage void __do_softirq(void);
74672-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
74673+extern void open_softirq(int nr, void (*action)(void));
74674 extern void softirq_init(void);
74675 extern void __raise_softirq_irqoff(unsigned int nr);
74676
74677diff --git a/include/linux/iommu.h b/include/linux/iommu.h
74678index 3aeb730..2177f39 100644
74679--- a/include/linux/iommu.h
74680+++ b/include/linux/iommu.h
74681@@ -113,7 +113,7 @@ struct iommu_ops {
74682 u32 (*domain_get_windows)(struct iommu_domain *domain);
74683
74684 unsigned long pgsize_bitmap;
74685-};
74686+} __do_const;
74687
74688 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
74689 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
74690diff --git a/include/linux/ioport.h b/include/linux/ioport.h
74691index 89b7c24..382af74 100644
74692--- a/include/linux/ioport.h
74693+++ b/include/linux/ioport.h
74694@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
74695 int adjust_resource(struct resource *res, resource_size_t start,
74696 resource_size_t size);
74697 resource_size_t resource_alignment(struct resource *res);
74698-static inline resource_size_t resource_size(const struct resource *res)
74699+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
74700 {
74701 return res->end - res->start + 1;
74702 }
74703diff --git a/include/linux/irq.h b/include/linux/irq.h
74704index f04d3ba..bcf2cfb 100644
74705--- a/include/linux/irq.h
74706+++ b/include/linux/irq.h
74707@@ -333,7 +333,8 @@ struct irq_chip {
74708 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
74709
74710 unsigned long flags;
74711-};
74712+} __do_const;
74713+typedef struct irq_chip __no_const irq_chip_no_const;
74714
74715 /*
74716 * irq_chip specific flags
74717diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
74718index 3e203eb..3fe68d0 100644
74719--- a/include/linux/irqchip/arm-gic.h
74720+++ b/include/linux/irqchip/arm-gic.h
74721@@ -59,9 +59,11 @@
74722
74723 #ifndef __ASSEMBLY__
74724
74725+#include <linux/irq.h>
74726+
74727 struct device_node;
74728
74729-extern struct irq_chip gic_arch_extn;
74730+extern irq_chip_no_const gic_arch_extn;
74731
74732 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
74733 u32 offset, struct device_node *);
74734diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
74735index 6883e19..e854fcb 100644
74736--- a/include/linux/kallsyms.h
74737+++ b/include/linux/kallsyms.h
74738@@ -15,7 +15,8 @@
74739
74740 struct module;
74741
74742-#ifdef CONFIG_KALLSYMS
74743+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
74744+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
74745 /* Lookup the address for a symbol. Returns 0 if not found. */
74746 unsigned long kallsyms_lookup_name(const char *name);
74747
74748@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
74749 /* Stupid that this does nothing, but I didn't create this mess. */
74750 #define __print_symbol(fmt, addr)
74751 #endif /*CONFIG_KALLSYMS*/
74752+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
74753+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
74754+extern unsigned long kallsyms_lookup_name(const char *name);
74755+extern void __print_symbol(const char *fmt, unsigned long address);
74756+extern int sprint_backtrace(char *buffer, unsigned long address);
74757+extern int sprint_symbol(char *buffer, unsigned long address);
74758+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
74759+const char *kallsyms_lookup(unsigned long addr,
74760+ unsigned long *symbolsize,
74761+ unsigned long *offset,
74762+ char **modname, char *namebuf);
74763+extern int kallsyms_lookup_size_offset(unsigned long addr,
74764+ unsigned long *symbolsize,
74765+ unsigned long *offset);
74766+#endif
74767
74768 /* This macro allows us to keep printk typechecking */
74769 static __printf(1, 2)
74770diff --git a/include/linux/key-type.h b/include/linux/key-type.h
74771index 518a53a..5e28358 100644
74772--- a/include/linux/key-type.h
74773+++ b/include/linux/key-type.h
74774@@ -125,7 +125,7 @@ struct key_type {
74775 /* internal fields */
74776 struct list_head link; /* link in types list */
74777 struct lock_class_key lock_class; /* key->sem lock class */
74778-};
74779+} __do_const;
74780
74781 extern struct key_type key_type_keyring;
74782
74783diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
74784index c6e091b..a940adf 100644
74785--- a/include/linux/kgdb.h
74786+++ b/include/linux/kgdb.h
74787@@ -52,7 +52,7 @@ extern int kgdb_connected;
74788 extern int kgdb_io_module_registered;
74789
74790 extern atomic_t kgdb_setting_breakpoint;
74791-extern atomic_t kgdb_cpu_doing_single_step;
74792+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
74793
74794 extern struct task_struct *kgdb_usethread;
74795 extern struct task_struct *kgdb_contthread;
74796@@ -254,7 +254,7 @@ struct kgdb_arch {
74797 void (*correct_hw_break)(void);
74798
74799 void (*enable_nmi)(bool on);
74800-};
74801+} __do_const;
74802
74803 /**
74804 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
74805@@ -279,7 +279,7 @@ struct kgdb_io {
74806 void (*pre_exception) (void);
74807 void (*post_exception) (void);
74808 int is_console;
74809-};
74810+} __do_const;
74811
74812 extern struct kgdb_arch arch_kgdb_ops;
74813
74814diff --git a/include/linux/kmod.h b/include/linux/kmod.h
74815index 0555cc6..b16a7a4 100644
74816--- a/include/linux/kmod.h
74817+++ b/include/linux/kmod.h
74818@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
74819 * usually useless though. */
74820 extern __printf(2, 3)
74821 int __request_module(bool wait, const char *name, ...);
74822+extern __printf(3, 4)
74823+int ___request_module(bool wait, char *param_name, const char *name, ...);
74824 #define request_module(mod...) __request_module(true, mod)
74825 #define request_module_nowait(mod...) __request_module(false, mod)
74826 #define try_then_request_module(x, mod...) \
74827diff --git a/include/linux/kobject.h b/include/linux/kobject.h
74828index 939b112..ed6ed51 100644
74829--- a/include/linux/kobject.h
74830+++ b/include/linux/kobject.h
74831@@ -111,7 +111,7 @@ struct kobj_type {
74832 struct attribute **default_attrs;
74833 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
74834 const void *(*namespace)(struct kobject *kobj);
74835-};
74836+} __do_const;
74837
74838 struct kobj_uevent_env {
74839 char *envp[UEVENT_NUM_ENVP];
74840@@ -134,6 +134,7 @@ struct kobj_attribute {
74841 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
74842 const char *buf, size_t count);
74843 };
74844+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
74845
74846 extern const struct sysfs_ops kobj_sysfs_ops;
74847
74848diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
74849index f66b065..c2c29b4 100644
74850--- a/include/linux/kobject_ns.h
74851+++ b/include/linux/kobject_ns.h
74852@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
74853 const void *(*netlink_ns)(struct sock *sk);
74854 const void *(*initial_ns)(void);
74855 void (*drop_ns)(void *);
74856-};
74857+} __do_const;
74858
74859 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
74860 int kobj_ns_type_registered(enum kobj_ns_type type);
74861diff --git a/include/linux/kref.h b/include/linux/kref.h
74862index 484604d..0f6c5b6 100644
74863--- a/include/linux/kref.h
74864+++ b/include/linux/kref.h
74865@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
74866 static inline int kref_sub(struct kref *kref, unsigned int count,
74867 void (*release)(struct kref *kref))
74868 {
74869- WARN_ON(release == NULL);
74870+ BUG_ON(release == NULL);
74871
74872 if (atomic_sub_and_test((int) count, &kref->refcount)) {
74873 release(kref);
74874diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
74875index a63d83e..77fd685 100644
74876--- a/include/linux/kvm_host.h
74877+++ b/include/linux/kvm_host.h
74878@@ -446,7 +446,7 @@ static inline void kvm_irqfd_exit(void)
74879 {
74880 }
74881 #endif
74882-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
74883+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
74884 struct module *module);
74885 void kvm_exit(void);
74886
74887@@ -618,7 +618,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
74888 struct kvm_guest_debug *dbg);
74889 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
74890
74891-int kvm_arch_init(void *opaque);
74892+int kvm_arch_init(const void *opaque);
74893 void kvm_arch_exit(void);
74894
74895 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
74896diff --git a/include/linux/libata.h b/include/linux/libata.h
74897index 4ea55bb..dcd2601 100644
74898--- a/include/linux/libata.h
74899+++ b/include/linux/libata.h
74900@@ -924,7 +924,7 @@ struct ata_port_operations {
74901 * fields must be pointers.
74902 */
74903 const struct ata_port_operations *inherits;
74904-};
74905+} __do_const;
74906
74907 struct ata_port_info {
74908 unsigned long flags;
74909diff --git a/include/linux/linkage.h b/include/linux/linkage.h
74910index d3e8ad2..a949f68 100644
74911--- a/include/linux/linkage.h
74912+++ b/include/linux/linkage.h
74913@@ -31,6 +31,7 @@
74914 #endif
74915
74916 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
74917+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
74918 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
74919
74920 /*
74921diff --git a/include/linux/list.h b/include/linux/list.h
74922index f4d8a2f..38e6e46 100644
74923--- a/include/linux/list.h
74924+++ b/include/linux/list.h
74925@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
74926 extern void list_del(struct list_head *entry);
74927 #endif
74928
74929+extern void __pax_list_add(struct list_head *new,
74930+ struct list_head *prev,
74931+ struct list_head *next);
74932+static inline void pax_list_add(struct list_head *new, struct list_head *head)
74933+{
74934+ __pax_list_add(new, head, head->next);
74935+}
74936+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
74937+{
74938+ __pax_list_add(new, head->prev, head);
74939+}
74940+extern void pax_list_del(struct list_head *entry);
74941+
74942 /**
74943 * list_replace - replace old entry by new one
74944 * @old : the element to be replaced
74945@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
74946 INIT_LIST_HEAD(entry);
74947 }
74948
74949+extern void pax_list_del_init(struct list_head *entry);
74950+
74951 /**
74952 * list_move - delete from one list and add as another's head
74953 * @list: the entry to move
74954diff --git a/include/linux/math64.h b/include/linux/math64.h
74955index 2913b86..8dcbb1e 100644
74956--- a/include/linux/math64.h
74957+++ b/include/linux/math64.h
74958@@ -15,7 +15,7 @@
74959 * This is commonly provided by 32bit archs to provide an optimized 64bit
74960 * divide.
74961 */
74962-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74963+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74964 {
74965 *remainder = dividend % divisor;
74966 return dividend / divisor;
74967@@ -33,7 +33,7 @@ static inline s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
74968 /**
74969 * div64_u64 - unsigned 64bit divide with 64bit divisor
74970 */
74971-static inline u64 div64_u64(u64 dividend, u64 divisor)
74972+static inline u64 __intentional_overflow(0) div64_u64(u64 dividend, u64 divisor)
74973 {
74974 return dividend / divisor;
74975 }
74976@@ -52,7 +52,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
74977 #define div64_ul(x, y) div_u64((x), (y))
74978
74979 #ifndef div_u64_rem
74980-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74981+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74982 {
74983 *remainder = do_div(dividend, divisor);
74984 return dividend;
74985@@ -81,7 +81,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
74986 * divide.
74987 */
74988 #ifndef div_u64
74989-static inline u64 div_u64(u64 dividend, u32 divisor)
74990+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
74991 {
74992 u32 remainder;
74993 return div_u64_rem(dividend, divisor, &remainder);
74994diff --git a/include/linux/mm.h b/include/linux/mm.h
74995index f022460..6ecf4f9 100644
74996--- a/include/linux/mm.h
74997+++ b/include/linux/mm.h
74998@@ -113,6 +113,11 @@ extern unsigned int kobjsize(const void *objp);
74999 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
75000 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
75001 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
75002+
75003+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75004+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
75005+#endif
75006+
75007 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
75008
75009 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
75010@@ -208,8 +213,8 @@ struct vm_operations_struct {
75011 /* called by access_process_vm when get_user_pages() fails, typically
75012 * for use by special VMAs that can switch between memory and hardware
75013 */
75014- int (*access)(struct vm_area_struct *vma, unsigned long addr,
75015- void *buf, int len, int write);
75016+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
75017+ void *buf, size_t len, int write);
75018 #ifdef CONFIG_NUMA
75019 /*
75020 * set_policy() op must add a reference to any non-NULL @new mempolicy
75021@@ -239,6 +244,7 @@ struct vm_operations_struct {
75022 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
75023 unsigned long size, pgoff_t pgoff);
75024 };
75025+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
75026
75027 struct mmu_gather;
75028 struct inode;
75029@@ -983,8 +989,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
75030 unsigned long *pfn);
75031 int follow_phys(struct vm_area_struct *vma, unsigned long address,
75032 unsigned int flags, unsigned long *prot, resource_size_t *phys);
75033-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
75034- void *buf, int len, int write);
75035+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
75036+ void *buf, size_t len, int write);
75037
75038 static inline void unmap_shared_mapping_range(struct address_space *mapping,
75039 loff_t const holebegin, loff_t const holelen)
75040@@ -1023,9 +1029,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
75041 }
75042 #endif
75043
75044-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
75045-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
75046- void *buf, int len, int write);
75047+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
75048+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
75049+ void *buf, size_t len, int write);
75050
75051 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75052 unsigned long start, unsigned long nr_pages,
75053@@ -1057,34 +1063,6 @@ int set_page_dirty(struct page *page);
75054 int set_page_dirty_lock(struct page *page);
75055 int clear_page_dirty_for_io(struct page *page);
75056
75057-/* Is the vma a continuation of the stack vma above it? */
75058-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
75059-{
75060- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
75061-}
75062-
75063-static inline int stack_guard_page_start(struct vm_area_struct *vma,
75064- unsigned long addr)
75065-{
75066- return (vma->vm_flags & VM_GROWSDOWN) &&
75067- (vma->vm_start == addr) &&
75068- !vma_growsdown(vma->vm_prev, addr);
75069-}
75070-
75071-/* Is the vma a continuation of the stack vma below it? */
75072-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
75073-{
75074- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
75075-}
75076-
75077-static inline int stack_guard_page_end(struct vm_area_struct *vma,
75078- unsigned long addr)
75079-{
75080- return (vma->vm_flags & VM_GROWSUP) &&
75081- (vma->vm_end == addr) &&
75082- !vma_growsup(vma->vm_next, addr);
75083-}
75084-
75085 extern pid_t
75086 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
75087
75088@@ -1184,6 +1162,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
75089 }
75090 #endif
75091
75092+#ifdef CONFIG_MMU
75093+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
75094+#else
75095+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
75096+{
75097+ return __pgprot(0);
75098+}
75099+#endif
75100+
75101 int vma_wants_writenotify(struct vm_area_struct *vma);
75102
75103 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
75104@@ -1202,8 +1189,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
75105 {
75106 return 0;
75107 }
75108+
75109+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
75110+ unsigned long address)
75111+{
75112+ return 0;
75113+}
75114 #else
75115 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
75116+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
75117 #endif
75118
75119 #ifdef __PAGETABLE_PMD_FOLDED
75120@@ -1212,8 +1206,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
75121 {
75122 return 0;
75123 }
75124+
75125+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
75126+ unsigned long address)
75127+{
75128+ return 0;
75129+}
75130 #else
75131 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
75132+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
75133 #endif
75134
75135 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
75136@@ -1231,11 +1232,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
75137 NULL: pud_offset(pgd, address);
75138 }
75139
75140+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
75141+{
75142+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
75143+ NULL: pud_offset(pgd, address);
75144+}
75145+
75146 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
75147 {
75148 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
75149 NULL: pmd_offset(pud, address);
75150 }
75151+
75152+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
75153+{
75154+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
75155+ NULL: pmd_offset(pud, address);
75156+}
75157 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
75158
75159 #if USE_SPLIT_PTLOCKS
75160@@ -1531,6 +1544,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75161 unsigned long len, unsigned long prot, unsigned long flags,
75162 unsigned long pgoff, unsigned long *populate);
75163 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
75164+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
75165
75166 #ifdef CONFIG_MMU
75167 extern int __mm_populate(unsigned long addr, unsigned long len,
75168@@ -1559,10 +1573,11 @@ struct vm_unmapped_area_info {
75169 unsigned long high_limit;
75170 unsigned long align_mask;
75171 unsigned long align_offset;
75172+ unsigned long threadstack_offset;
75173 };
75174
75175-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
75176-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
75177+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
75178+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
75179
75180 /*
75181 * Search for an unmapped address range.
75182@@ -1574,7 +1589,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
75183 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
75184 */
75185 static inline unsigned long
75186-vm_unmapped_area(struct vm_unmapped_area_info *info)
75187+vm_unmapped_area(const struct vm_unmapped_area_info *info)
75188 {
75189 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
75190 return unmapped_area(info);
75191@@ -1637,6 +1652,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
75192 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
75193 struct vm_area_struct **pprev);
75194
75195+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
75196+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
75197+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
75198+
75199 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
75200 NULL if none. Assume start_addr < end_addr. */
75201 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
75202@@ -1665,15 +1684,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
75203 return vma;
75204 }
75205
75206-#ifdef CONFIG_MMU
75207-pgprot_t vm_get_page_prot(unsigned long vm_flags);
75208-#else
75209-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
75210-{
75211- return __pgprot(0);
75212-}
75213-#endif
75214-
75215 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
75216 unsigned long change_prot_numa(struct vm_area_struct *vma,
75217 unsigned long start, unsigned long end);
75218@@ -1725,6 +1735,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
75219 static inline void vm_stat_account(struct mm_struct *mm,
75220 unsigned long flags, struct file *file, long pages)
75221 {
75222+
75223+#ifdef CONFIG_PAX_RANDMMAP
75224+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
75225+#endif
75226+
75227 mm->total_vm += pages;
75228 }
75229 #endif /* CONFIG_PROC_FS */
75230@@ -1805,7 +1820,7 @@ extern int unpoison_memory(unsigned long pfn);
75231 extern int sysctl_memory_failure_early_kill;
75232 extern int sysctl_memory_failure_recovery;
75233 extern void shake_page(struct page *p, int access);
75234-extern atomic_long_t num_poisoned_pages;
75235+extern atomic_long_unchecked_t num_poisoned_pages;
75236 extern int soft_offline_page(struct page *page, int flags);
75237
75238 extern void dump_page(struct page *page);
75239@@ -1842,5 +1857,11 @@ void __init setup_nr_node_ids(void);
75240 static inline void setup_nr_node_ids(void) {}
75241 #endif
75242
75243+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
75244+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
75245+#else
75246+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
75247+#endif
75248+
75249 #endif /* __KERNEL__ */
75250 #endif /* _LINUX_MM_H */
75251diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
75252index faf4b7c..1e70c6e 100644
75253--- a/include/linux/mm_types.h
75254+++ b/include/linux/mm_types.h
75255@@ -289,6 +289,8 @@ struct vm_area_struct {
75256 #ifdef CONFIG_NUMA
75257 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
75258 #endif
75259+
75260+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
75261 };
75262
75263 struct core_thread {
75264@@ -435,6 +437,24 @@ struct mm_struct {
75265 int first_nid;
75266 #endif
75267 struct uprobes_state uprobes_state;
75268+
75269+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
75270+ unsigned long pax_flags;
75271+#endif
75272+
75273+#ifdef CONFIG_PAX_DLRESOLVE
75274+ unsigned long call_dl_resolve;
75275+#endif
75276+
75277+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
75278+ unsigned long call_syscall;
75279+#endif
75280+
75281+#ifdef CONFIG_PAX_ASLR
75282+ unsigned long delta_mmap; /* randomized offset */
75283+ unsigned long delta_stack; /* randomized offset */
75284+#endif
75285+
75286 };
75287
75288 /* first nid will either be a valid NID or one of these values */
75289diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
75290index c5d5278..f0b68c8 100644
75291--- a/include/linux/mmiotrace.h
75292+++ b/include/linux/mmiotrace.h
75293@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
75294 /* Called from ioremap.c */
75295 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
75296 void __iomem *addr);
75297-extern void mmiotrace_iounmap(volatile void __iomem *addr);
75298+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
75299
75300 /* For anyone to insert markers. Remember trailing newline. */
75301 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
75302@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
75303 {
75304 }
75305
75306-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
75307+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
75308 {
75309 }
75310
75311diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
75312index af4a3b7..9ad8889 100644
75313--- a/include/linux/mmzone.h
75314+++ b/include/linux/mmzone.h
75315@@ -396,7 +396,7 @@ struct zone {
75316 unsigned long flags; /* zone flags, see below */
75317
75318 /* Zone statistics */
75319- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75320+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75321
75322 /*
75323 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
75324diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
75325index 45e9214..a7227d6 100644
75326--- a/include/linux/mod_devicetable.h
75327+++ b/include/linux/mod_devicetable.h
75328@@ -13,7 +13,7 @@
75329 typedef unsigned long kernel_ulong_t;
75330 #endif
75331
75332-#define PCI_ANY_ID (~0)
75333+#define PCI_ANY_ID ((__u16)~0)
75334
75335 struct pci_device_id {
75336 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
75337@@ -139,7 +139,7 @@ struct usb_device_id {
75338 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
75339 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
75340
75341-#define HID_ANY_ID (~0)
75342+#define HID_ANY_ID (~0U)
75343 #define HID_BUS_ANY 0xffff
75344 #define HID_GROUP_ANY 0x0000
75345
75346@@ -467,7 +467,7 @@ struct dmi_system_id {
75347 const char *ident;
75348 struct dmi_strmatch matches[4];
75349 void *driver_data;
75350-};
75351+} __do_const;
75352 /*
75353 * struct dmi_device_id appears during expansion of
75354 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
75355diff --git a/include/linux/module.h b/include/linux/module.h
75356index 46f1ea0..a34ca37 100644
75357--- a/include/linux/module.h
75358+++ b/include/linux/module.h
75359@@ -17,9 +17,11 @@
75360 #include <linux/moduleparam.h>
75361 #include <linux/tracepoint.h>
75362 #include <linux/export.h>
75363+#include <linux/fs.h>
75364
75365 #include <linux/percpu.h>
75366 #include <asm/module.h>
75367+#include <asm/pgtable.h>
75368
75369 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
75370 #define MODULE_SIG_STRING "~Module signature appended~\n"
75371@@ -54,12 +56,13 @@ struct module_attribute {
75372 int (*test)(struct module *);
75373 void (*free)(struct module *);
75374 };
75375+typedef struct module_attribute __no_const module_attribute_no_const;
75376
75377 struct module_version_attribute {
75378 struct module_attribute mattr;
75379 const char *module_name;
75380 const char *version;
75381-} __attribute__ ((__aligned__(sizeof(void *))));
75382+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
75383
75384 extern ssize_t __modver_version_show(struct module_attribute *,
75385 struct module_kobject *, char *);
75386@@ -232,7 +235,7 @@ struct module
75387
75388 /* Sysfs stuff. */
75389 struct module_kobject mkobj;
75390- struct module_attribute *modinfo_attrs;
75391+ module_attribute_no_const *modinfo_attrs;
75392 const char *version;
75393 const char *srcversion;
75394 struct kobject *holders_dir;
75395@@ -281,19 +284,16 @@ struct module
75396 int (*init)(void);
75397
75398 /* If this is non-NULL, vfree after init() returns */
75399- void *module_init;
75400+ void *module_init_rx, *module_init_rw;
75401
75402 /* Here is the actual code + data, vfree'd on unload. */
75403- void *module_core;
75404+ void *module_core_rx, *module_core_rw;
75405
75406 /* Here are the sizes of the init and core sections */
75407- unsigned int init_size, core_size;
75408+ unsigned int init_size_rw, core_size_rw;
75409
75410 /* The size of the executable code in each section. */
75411- unsigned int init_text_size, core_text_size;
75412-
75413- /* Size of RO sections of the module (text+rodata) */
75414- unsigned int init_ro_size, core_ro_size;
75415+ unsigned int init_size_rx, core_size_rx;
75416
75417 /* Arch-specific module values */
75418 struct mod_arch_specific arch;
75419@@ -349,6 +349,10 @@ struct module
75420 #ifdef CONFIG_EVENT_TRACING
75421 struct ftrace_event_call **trace_events;
75422 unsigned int num_trace_events;
75423+ struct file_operations trace_id;
75424+ struct file_operations trace_enable;
75425+ struct file_operations trace_format;
75426+ struct file_operations trace_filter;
75427 #endif
75428 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
75429 unsigned int num_ftrace_callsites;
75430@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
75431 bool is_module_percpu_address(unsigned long addr);
75432 bool is_module_text_address(unsigned long addr);
75433
75434+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
75435+{
75436+
75437+#ifdef CONFIG_PAX_KERNEXEC
75438+ if (ktla_ktva(addr) >= (unsigned long)start &&
75439+ ktla_ktva(addr) < (unsigned long)start + size)
75440+ return 1;
75441+#endif
75442+
75443+ return ((void *)addr >= start && (void *)addr < start + size);
75444+}
75445+
75446+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
75447+{
75448+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
75449+}
75450+
75451+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
75452+{
75453+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
75454+}
75455+
75456+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
75457+{
75458+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
75459+}
75460+
75461+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
75462+{
75463+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
75464+}
75465+
75466 static inline int within_module_core(unsigned long addr, const struct module *mod)
75467 {
75468- return (unsigned long)mod->module_core <= addr &&
75469- addr < (unsigned long)mod->module_core + mod->core_size;
75470+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
75471 }
75472
75473 static inline int within_module_init(unsigned long addr, const struct module *mod)
75474 {
75475- return (unsigned long)mod->module_init <= addr &&
75476- addr < (unsigned long)mod->module_init + mod->init_size;
75477+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
75478 }
75479
75480 /* Search for module by name: must hold module_mutex. */
75481diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
75482index 560ca53..ef621ef 100644
75483--- a/include/linux/moduleloader.h
75484+++ b/include/linux/moduleloader.h
75485@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
75486 sections. Returns NULL on failure. */
75487 void *module_alloc(unsigned long size);
75488
75489+#ifdef CONFIG_PAX_KERNEXEC
75490+void *module_alloc_exec(unsigned long size);
75491+#else
75492+#define module_alloc_exec(x) module_alloc(x)
75493+#endif
75494+
75495 /* Free memory returned from module_alloc. */
75496 void module_free(struct module *mod, void *module_region);
75497
75498+#ifdef CONFIG_PAX_KERNEXEC
75499+void module_free_exec(struct module *mod, void *module_region);
75500+#else
75501+#define module_free_exec(x, y) module_free((x), (y))
75502+#endif
75503+
75504 /*
75505 * Apply the given relocation to the (simplified) ELF. Return -error
75506 * or 0.
75507@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
75508 unsigned int relsec,
75509 struct module *me)
75510 {
75511+#ifdef CONFIG_MODULES
75512 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75513+#endif
75514 return -ENOEXEC;
75515 }
75516 #endif
75517@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
75518 unsigned int relsec,
75519 struct module *me)
75520 {
75521+#ifdef CONFIG_MODULES
75522 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75523+#endif
75524 return -ENOEXEC;
75525 }
75526 #endif
75527diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
75528index 27d9da3..5d94aa3 100644
75529--- a/include/linux/moduleparam.h
75530+++ b/include/linux/moduleparam.h
75531@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
75532 * @len is usually just sizeof(string).
75533 */
75534 #define module_param_string(name, string, len, perm) \
75535- static const struct kparam_string __param_string_##name \
75536+ static const struct kparam_string __param_string_##name __used \
75537 = { len, string }; \
75538 __module_param_call(MODULE_PARAM_PREFIX, name, \
75539 &param_ops_string, \
75540@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
75541 */
75542 #define module_param_array_named(name, array, type, nump, perm) \
75543 param_check_##type(name, &(array)[0]); \
75544- static const struct kparam_array __param_arr_##name \
75545+ static const struct kparam_array __param_arr_##name __used \
75546 = { .max = ARRAY_SIZE(array), .num = nump, \
75547 .ops = &param_ops_##type, \
75548 .elemsize = sizeof(array[0]), .elem = array }; \
75549diff --git a/include/linux/namei.h b/include/linux/namei.h
75550index 5a5ff57..5ae5070 100644
75551--- a/include/linux/namei.h
75552+++ b/include/linux/namei.h
75553@@ -19,7 +19,7 @@ struct nameidata {
75554 unsigned seq;
75555 int last_type;
75556 unsigned depth;
75557- char *saved_names[MAX_NESTED_LINKS + 1];
75558+ const char *saved_names[MAX_NESTED_LINKS + 1];
75559 };
75560
75561 /*
75562@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
75563
75564 extern void nd_jump_link(struct nameidata *nd, struct path *path);
75565
75566-static inline void nd_set_link(struct nameidata *nd, char *path)
75567+static inline void nd_set_link(struct nameidata *nd, const char *path)
75568 {
75569 nd->saved_names[nd->depth] = path;
75570 }
75571
75572-static inline char *nd_get_link(struct nameidata *nd)
75573+static inline const char *nd_get_link(const struct nameidata *nd)
75574 {
75575 return nd->saved_names[nd->depth];
75576 }
75577diff --git a/include/linux/net.h b/include/linux/net.h
75578index 4f27575..fc8a65f 100644
75579--- a/include/linux/net.h
75580+++ b/include/linux/net.h
75581@@ -183,7 +183,7 @@ struct net_proto_family {
75582 int (*create)(struct net *net, struct socket *sock,
75583 int protocol, int kern);
75584 struct module *owner;
75585-};
75586+} __do_const;
75587
75588 struct iovec;
75589 struct kvec;
75590diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
75591index 9a41568..203d903 100644
75592--- a/include/linux/netdevice.h
75593+++ b/include/linux/netdevice.h
75594@@ -1061,6 +1061,7 @@ struct net_device_ops {
75595 int (*ndo_change_carrier)(struct net_device *dev,
75596 bool new_carrier);
75597 };
75598+typedef struct net_device_ops __no_const net_device_ops_no_const;
75599
75600 /*
75601 * The DEVICE structure.
75602@@ -1131,7 +1132,7 @@ struct net_device {
75603 int iflink;
75604
75605 struct net_device_stats stats;
75606- atomic_long_t rx_dropped; /* dropped packets by core network
75607+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
75608 * Do not use this in drivers.
75609 */
75610
75611diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
75612index de70f7b..2675e91 100644
75613--- a/include/linux/netfilter.h
75614+++ b/include/linux/netfilter.h
75615@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
75616 #endif
75617 /* Use the module struct to lock set/get code in place */
75618 struct module *owner;
75619-};
75620+} __do_const;
75621
75622 /* Function to register/unregister hook points. */
75623 int nf_register_hook(struct nf_hook_ops *reg);
75624diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
75625index d80e275..c3510b8 100644
75626--- a/include/linux/netfilter/ipset/ip_set.h
75627+++ b/include/linux/netfilter/ipset/ip_set.h
75628@@ -124,7 +124,7 @@ struct ip_set_type_variant {
75629 /* Return true if "b" set is the same as "a"
75630 * according to the create set parameters */
75631 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
75632-};
75633+} __do_const;
75634
75635 /* The core set type structure */
75636 struct ip_set_type {
75637diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
75638index cadb740..d7c37c0 100644
75639--- a/include/linux/netfilter/nfnetlink.h
75640+++ b/include/linux/netfilter/nfnetlink.h
75641@@ -16,7 +16,7 @@ struct nfnl_callback {
75642 const struct nlattr * const cda[]);
75643 const struct nla_policy *policy; /* netlink attribute policy */
75644 const u_int16_t attr_count; /* number of nlattr's */
75645-};
75646+} __do_const;
75647
75648 struct nfnetlink_subsystem {
75649 const char *name;
75650diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
75651new file mode 100644
75652index 0000000..33f4af8
75653--- /dev/null
75654+++ b/include/linux/netfilter/xt_gradm.h
75655@@ -0,0 +1,9 @@
75656+#ifndef _LINUX_NETFILTER_XT_GRADM_H
75657+#define _LINUX_NETFILTER_XT_GRADM_H 1
75658+
75659+struct xt_gradm_mtinfo {
75660+ __u16 flags;
75661+ __u16 invflags;
75662+};
75663+
75664+#endif
75665diff --git a/include/linux/nls.h b/include/linux/nls.h
75666index 5dc635f..35f5e11 100644
75667--- a/include/linux/nls.h
75668+++ b/include/linux/nls.h
75669@@ -31,7 +31,7 @@ struct nls_table {
75670 const unsigned char *charset2upper;
75671 struct module *owner;
75672 struct nls_table *next;
75673-};
75674+} __do_const;
75675
75676 /* this value hold the maximum octet of charset */
75677 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
75678diff --git a/include/linux/notifier.h b/include/linux/notifier.h
75679index d14a4c3..a078786 100644
75680--- a/include/linux/notifier.h
75681+++ b/include/linux/notifier.h
75682@@ -54,7 +54,8 @@ struct notifier_block {
75683 notifier_fn_t notifier_call;
75684 struct notifier_block __rcu *next;
75685 int priority;
75686-};
75687+} __do_const;
75688+typedef struct notifier_block __no_const notifier_block_no_const;
75689
75690 struct atomic_notifier_head {
75691 spinlock_t lock;
75692diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
75693index a4c5624..79d6d88 100644
75694--- a/include/linux/oprofile.h
75695+++ b/include/linux/oprofile.h
75696@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
75697 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
75698 char const * name, ulong * val);
75699
75700-/** Create a file for read-only access to an atomic_t. */
75701+/** Create a file for read-only access to an atomic_unchecked_t. */
75702 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
75703- char const * name, atomic_t * val);
75704+ char const * name, atomic_unchecked_t * val);
75705
75706 /** create a directory */
75707 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
75708diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
75709index 8db71dc..a76bf2c 100644
75710--- a/include/linux/pci_hotplug.h
75711+++ b/include/linux/pci_hotplug.h
75712@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
75713 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
75714 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
75715 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
75716-};
75717+} __do_const;
75718+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
75719
75720 /**
75721 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
75722diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
75723index c43f6ea..2d4416f 100644
75724--- a/include/linux/perf_event.h
75725+++ b/include/linux/perf_event.h
75726@@ -328,8 +328,8 @@ struct perf_event {
75727
75728 enum perf_event_active_state state;
75729 unsigned int attach_state;
75730- local64_t count;
75731- atomic64_t child_count;
75732+ local64_t count; /* PaX: fix it one day */
75733+ atomic64_unchecked_t child_count;
75734
75735 /*
75736 * These are the total time in nanoseconds that the event
75737@@ -380,8 +380,8 @@ struct perf_event {
75738 * These accumulate total time (in nanoseconds) that children
75739 * events have been enabled and running, respectively.
75740 */
75741- atomic64_t child_total_time_enabled;
75742- atomic64_t child_total_time_running;
75743+ atomic64_unchecked_t child_total_time_enabled;
75744+ atomic64_unchecked_t child_total_time_running;
75745
75746 /*
75747 * Protect attach/detach and child_list:
75748@@ -703,7 +703,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
75749 entry->ip[entry->nr++] = ip;
75750 }
75751
75752-extern int sysctl_perf_event_paranoid;
75753+extern int sysctl_perf_event_legitimately_concerned;
75754 extern int sysctl_perf_event_mlock;
75755 extern int sysctl_perf_event_sample_rate;
75756 extern int sysctl_perf_cpu_time_max_percent;
75757@@ -718,19 +718,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
75758 loff_t *ppos);
75759
75760
75761+static inline bool perf_paranoid_any(void)
75762+{
75763+ return sysctl_perf_event_legitimately_concerned > 2;
75764+}
75765+
75766 static inline bool perf_paranoid_tracepoint_raw(void)
75767 {
75768- return sysctl_perf_event_paranoid > -1;
75769+ return sysctl_perf_event_legitimately_concerned > -1;
75770 }
75771
75772 static inline bool perf_paranoid_cpu(void)
75773 {
75774- return sysctl_perf_event_paranoid > 0;
75775+ return sysctl_perf_event_legitimately_concerned > 0;
75776 }
75777
75778 static inline bool perf_paranoid_kernel(void)
75779 {
75780- return sysctl_perf_event_paranoid > 1;
75781+ return sysctl_perf_event_legitimately_concerned > 1;
75782 }
75783
75784 extern void perf_event_init(void);
75785@@ -846,7 +851,7 @@ struct perf_pmu_events_attr {
75786 struct device_attribute attr;
75787 u64 id;
75788 const char *event_str;
75789-};
75790+} __do_const;
75791
75792 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
75793 static struct perf_pmu_events_attr _var = { \
75794diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
75795index b8809fe..ae4ccd0 100644
75796--- a/include/linux/pipe_fs_i.h
75797+++ b/include/linux/pipe_fs_i.h
75798@@ -47,10 +47,10 @@ struct pipe_inode_info {
75799 struct mutex mutex;
75800 wait_queue_head_t wait;
75801 unsigned int nrbufs, curbuf, buffers;
75802- unsigned int readers;
75803- unsigned int writers;
75804- unsigned int files;
75805- unsigned int waiting_writers;
75806+ atomic_t readers;
75807+ atomic_t writers;
75808+ atomic_t files;
75809+ atomic_t waiting_writers;
75810 unsigned int r_counter;
75811 unsigned int w_counter;
75812 struct page *tmp_page;
75813diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
75814index 5f28cae..3d23723 100644
75815--- a/include/linux/platform_data/usb-ehci-s5p.h
75816+++ b/include/linux/platform_data/usb-ehci-s5p.h
75817@@ -14,7 +14,7 @@
75818 struct s5p_ehci_platdata {
75819 int (*phy_init)(struct platform_device *pdev, int type);
75820 int (*phy_exit)(struct platform_device *pdev, int type);
75821-};
75822+} __no_const;
75823
75824 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
75825
75826diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
75827index c256c59..8ea94c7 100644
75828--- a/include/linux/platform_data/usb-ohci-exynos.h
75829+++ b/include/linux/platform_data/usb-ohci-exynos.h
75830@@ -14,7 +14,7 @@
75831 struct exynos4_ohci_platdata {
75832 int (*phy_init)(struct platform_device *pdev, int type);
75833 int (*phy_exit)(struct platform_device *pdev, int type);
75834-};
75835+} __no_const;
75836
75837 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
75838
75839diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
75840index 7c1d252..c5c773e 100644
75841--- a/include/linux/pm_domain.h
75842+++ b/include/linux/pm_domain.h
75843@@ -48,7 +48,7 @@ struct gpd_dev_ops {
75844
75845 struct gpd_cpu_data {
75846 unsigned int saved_exit_latency;
75847- struct cpuidle_state *idle_state;
75848+ cpuidle_state_no_const *idle_state;
75849 };
75850
75851 struct generic_pm_domain {
75852diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
75853index 6fa7cea..7bf6415 100644
75854--- a/include/linux/pm_runtime.h
75855+++ b/include/linux/pm_runtime.h
75856@@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
75857
75858 static inline void pm_runtime_mark_last_busy(struct device *dev)
75859 {
75860- ACCESS_ONCE(dev->power.last_busy) = jiffies;
75861+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
75862 }
75863
75864 #else /* !CONFIG_PM_RUNTIME */
75865diff --git a/include/linux/pnp.h b/include/linux/pnp.h
75866index 195aafc..49a7bc2 100644
75867--- a/include/linux/pnp.h
75868+++ b/include/linux/pnp.h
75869@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
75870 struct pnp_fixup {
75871 char id[7];
75872 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
75873-};
75874+} __do_const;
75875
75876 /* config parameters */
75877 #define PNP_CONFIG_NORMAL 0x0001
75878diff --git a/include/linux/poison.h b/include/linux/poison.h
75879index 2110a81..13a11bb 100644
75880--- a/include/linux/poison.h
75881+++ b/include/linux/poison.h
75882@@ -19,8 +19,8 @@
75883 * under normal circumstances, used to verify that nobody uses
75884 * non-initialized list entries.
75885 */
75886-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
75887-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
75888+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
75889+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
75890
75891 /********** include/linux/timer.h **********/
75892 /*
75893diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
75894index d8b187c3..9a9257a 100644
75895--- a/include/linux/power/smartreflex.h
75896+++ b/include/linux/power/smartreflex.h
75897@@ -238,7 +238,7 @@ struct omap_sr_class_data {
75898 int (*notify)(struct omap_sr *sr, u32 status);
75899 u8 notify_flags;
75900 u8 class_type;
75901-};
75902+} __do_const;
75903
75904 /**
75905 * struct omap_sr_nvalue_table - Smartreflex n-target value info
75906diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
75907index 4ea1d37..80f4b33 100644
75908--- a/include/linux/ppp-comp.h
75909+++ b/include/linux/ppp-comp.h
75910@@ -84,7 +84,7 @@ struct compressor {
75911 struct module *owner;
75912 /* Extra skb space needed by the compressor algorithm */
75913 unsigned int comp_extra;
75914-};
75915+} __do_const;
75916
75917 /*
75918 * The return value from decompress routine is the length of the
75919diff --git a/include/linux/preempt.h b/include/linux/preempt.h
75920index f5d4723..a6ea2fa 100644
75921--- a/include/linux/preempt.h
75922+++ b/include/linux/preempt.h
75923@@ -18,8 +18,13 @@
75924 # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
75925 #endif
75926
75927+#define raw_add_preempt_count(val) do { preempt_count() += (val); } while (0)
75928+#define raw_sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
75929+
75930 #define inc_preempt_count() add_preempt_count(1)
75931+#define raw_inc_preempt_count() raw_add_preempt_count(1)
75932 #define dec_preempt_count() sub_preempt_count(1)
75933+#define raw_dec_preempt_count() raw_sub_preempt_count(1)
75934
75935 #define preempt_count() (current_thread_info()->preempt_count)
75936
75937@@ -64,6 +69,12 @@ do { \
75938 barrier(); \
75939 } while (0)
75940
75941+#define raw_preempt_disable() \
75942+do { \
75943+ raw_inc_preempt_count(); \
75944+ barrier(); \
75945+} while (0)
75946+
75947 #define sched_preempt_enable_no_resched() \
75948 do { \
75949 barrier(); \
75950@@ -72,6 +83,12 @@ do { \
75951
75952 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
75953
75954+#define raw_preempt_enable_no_resched() \
75955+do { \
75956+ barrier(); \
75957+ raw_dec_preempt_count(); \
75958+} while (0)
75959+
75960 #define preempt_enable() \
75961 do { \
75962 preempt_enable_no_resched(); \
75963@@ -116,8 +133,10 @@ do { \
75964 * region.
75965 */
75966 #define preempt_disable() barrier()
75967+#define raw_preempt_disable() barrier()
75968 #define sched_preempt_enable_no_resched() barrier()
75969 #define preempt_enable_no_resched() barrier()
75970+#define raw_preempt_enable_no_resched() barrier()
75971 #define preempt_enable() barrier()
75972
75973 #define preempt_disable_notrace() barrier()
75974diff --git a/include/linux/printk.h b/include/linux/printk.h
75975index 22c7052..ad3fa0a 100644
75976--- a/include/linux/printk.h
75977+++ b/include/linux/printk.h
75978@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
75979 void early_printk(const char *s, ...) { }
75980 #endif
75981
75982+extern int kptr_restrict;
75983+
75984 #ifdef CONFIG_PRINTK
75985 asmlinkage __printf(5, 0)
75986 int vprintk_emit(int facility, int level,
75987@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
75988
75989 extern int printk_delay_msec;
75990 extern int dmesg_restrict;
75991-extern int kptr_restrict;
75992
75993 extern void wake_up_klogd(void);
75994
75995diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
75996index 608e60a..c26f864 100644
75997--- a/include/linux/proc_fs.h
75998+++ b/include/linux/proc_fs.h
75999@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
76000 return proc_create_data(name, mode, parent, proc_fops, NULL);
76001 }
76002
76003+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
76004+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
76005+{
76006+#ifdef CONFIG_GRKERNSEC_PROC_USER
76007+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
76008+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76009+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
76010+#else
76011+ return proc_create_data(name, mode, parent, proc_fops, NULL);
76012+#endif
76013+}
76014+
76015+
76016 extern void proc_set_size(struct proc_dir_entry *, loff_t);
76017 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
76018 extern void *PDE_DATA(const struct inode *);
76019diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
76020index 34a1e10..03a6d03 100644
76021--- a/include/linux/proc_ns.h
76022+++ b/include/linux/proc_ns.h
76023@@ -14,7 +14,7 @@ struct proc_ns_operations {
76024 void (*put)(void *ns);
76025 int (*install)(struct nsproxy *nsproxy, void *ns);
76026 unsigned int (*inum)(void *ns);
76027-};
76028+} __do_const;
76029
76030 struct proc_ns {
76031 void *ns;
76032diff --git a/include/linux/random.h b/include/linux/random.h
76033index 3b9377d..943ad4a 100644
76034--- a/include/linux/random.h
76035+++ b/include/linux/random.h
76036@@ -10,6 +10,16 @@
76037
76038
76039 extern void add_device_randomness(const void *, unsigned int);
76040+
76041+static inline void add_latent_entropy(void)
76042+{
76043+
76044+#ifdef LATENT_ENTROPY_PLUGIN
76045+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
76046+#endif
76047+
76048+}
76049+
76050 extern void add_input_randomness(unsigned int type, unsigned int code,
76051 unsigned int value);
76052 extern void add_interrupt_randomness(int irq, int irq_flags);
76053@@ -32,6 +42,11 @@ void prandom_seed(u32 seed);
76054 u32 prandom_u32_state(struct rnd_state *);
76055 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
76056
76057+static inline unsigned long pax_get_random_long(void)
76058+{
76059+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
76060+}
76061+
76062 /*
76063 * Handle minimum values for seeds
76064 */
76065diff --git a/include/linux/rculist.h b/include/linux/rculist.h
76066index f4b1001..8ddb2b6 100644
76067--- a/include/linux/rculist.h
76068+++ b/include/linux/rculist.h
76069@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
76070 struct list_head *prev, struct list_head *next);
76071 #endif
76072
76073+extern void __pax_list_add_rcu(struct list_head *new,
76074+ struct list_head *prev, struct list_head *next);
76075+
76076 /**
76077 * list_add_rcu - add a new entry to rcu-protected list
76078 * @new: new entry to be added
76079@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
76080 __list_add_rcu(new, head, head->next);
76081 }
76082
76083+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
76084+{
76085+ __pax_list_add_rcu(new, head, head->next);
76086+}
76087+
76088 /**
76089 * list_add_tail_rcu - add a new entry to rcu-protected list
76090 * @new: new entry to be added
76091@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
76092 __list_add_rcu(new, head->prev, head);
76093 }
76094
76095+static inline void pax_list_add_tail_rcu(struct list_head *new,
76096+ struct list_head *head)
76097+{
76098+ __pax_list_add_rcu(new, head->prev, head);
76099+}
76100+
76101 /**
76102 * list_del_rcu - deletes entry from list without re-initialization
76103 * @entry: the element to delete from the list.
76104@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
76105 entry->prev = LIST_POISON2;
76106 }
76107
76108+extern void pax_list_del_rcu(struct list_head *entry);
76109+
76110 /**
76111 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
76112 * @n: the element to delete from the hash list.
76113diff --git a/include/linux/reboot.h b/include/linux/reboot.h
76114index 8e00f9f..9449b55 100644
76115--- a/include/linux/reboot.h
76116+++ b/include/linux/reboot.h
76117@@ -43,9 +43,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
76118 * Architecture-specific implementations of sys_reboot commands.
76119 */
76120
76121-extern void machine_restart(char *cmd);
76122-extern void machine_halt(void);
76123-extern void machine_power_off(void);
76124+extern void machine_restart(char *cmd) __noreturn;
76125+extern void machine_halt(void) __noreturn;
76126+extern void machine_power_off(void) __noreturn;
76127
76128 extern void machine_shutdown(void);
76129 struct pt_regs;
76130@@ -56,9 +56,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
76131 */
76132
76133 extern void kernel_restart_prepare(char *cmd);
76134-extern void kernel_restart(char *cmd);
76135-extern void kernel_halt(void);
76136-extern void kernel_power_off(void);
76137+extern void kernel_restart(char *cmd) __noreturn;
76138+extern void kernel_halt(void) __noreturn;
76139+extern void kernel_power_off(void) __noreturn;
76140
76141 extern int C_A_D; /* for sysctl */
76142 void ctrl_alt_del(void);
76143@@ -72,7 +72,7 @@ extern int orderly_poweroff(bool force);
76144 * Emergency restart, callable from an interrupt handler.
76145 */
76146
76147-extern void emergency_restart(void);
76148+extern void emergency_restart(void) __noreturn;
76149 #include <asm/emergency-restart.h>
76150
76151 #endif /* _LINUX_REBOOT_H */
76152diff --git a/include/linux/regset.h b/include/linux/regset.h
76153index 8e0c9fe..ac4d221 100644
76154--- a/include/linux/regset.h
76155+++ b/include/linux/regset.h
76156@@ -161,7 +161,8 @@ struct user_regset {
76157 unsigned int align;
76158 unsigned int bias;
76159 unsigned int core_note_type;
76160-};
76161+} __do_const;
76162+typedef struct user_regset __no_const user_regset_no_const;
76163
76164 /**
76165 * struct user_regset_view - available regsets
76166diff --git a/include/linux/relay.h b/include/linux/relay.h
76167index d7c8359..818daf5 100644
76168--- a/include/linux/relay.h
76169+++ b/include/linux/relay.h
76170@@ -157,7 +157,7 @@ struct rchan_callbacks
76171 * The callback should return 0 if successful, negative if not.
76172 */
76173 int (*remove_buf_file)(struct dentry *dentry);
76174-};
76175+} __no_const;
76176
76177 /*
76178 * CONFIG_RELAY kernel API, kernel/relay.c
76179diff --git a/include/linux/rio.h b/include/linux/rio.h
76180index b71d573..2f940bd 100644
76181--- a/include/linux/rio.h
76182+++ b/include/linux/rio.h
76183@@ -355,7 +355,7 @@ struct rio_ops {
76184 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
76185 u64 rstart, u32 size, u32 flags);
76186 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
76187-};
76188+} __no_const;
76189
76190 #define RIO_RESOURCE_MEM 0x00000100
76191 #define RIO_RESOURCE_DOORBELL 0x00000200
76192diff --git a/include/linux/rmap.h b/include/linux/rmap.h
76193index 6dacb93..6174423 100644
76194--- a/include/linux/rmap.h
76195+++ b/include/linux/rmap.h
76196@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
76197 void anon_vma_init(void); /* create anon_vma_cachep */
76198 int anon_vma_prepare(struct vm_area_struct *);
76199 void unlink_anon_vmas(struct vm_area_struct *);
76200-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
76201-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
76202+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
76203+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
76204
76205 static inline void anon_vma_merge(struct vm_area_struct *vma,
76206 struct vm_area_struct *next)
76207diff --git a/include/linux/sched.h b/include/linux/sched.h
76208index 078066d..4090b3b 100644
76209--- a/include/linux/sched.h
76210+++ b/include/linux/sched.h
76211@@ -62,6 +62,7 @@ struct bio_list;
76212 struct fs_struct;
76213 struct perf_event_context;
76214 struct blk_plug;
76215+struct linux_binprm;
76216
76217 /*
76218 * List of flags we want to share for kernel threads,
76219@@ -303,7 +304,7 @@ extern char __sched_text_start[], __sched_text_end[];
76220 extern int in_sched_functions(unsigned long addr);
76221
76222 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
76223-extern signed long schedule_timeout(signed long timeout);
76224+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
76225 extern signed long schedule_timeout_interruptible(signed long timeout);
76226 extern signed long schedule_timeout_killable(signed long timeout);
76227 extern signed long schedule_timeout_uninterruptible(signed long timeout);
76228@@ -314,6 +315,19 @@ struct nsproxy;
76229 struct user_namespace;
76230
76231 #ifdef CONFIG_MMU
76232+
76233+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
76234+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
76235+#else
76236+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
76237+{
76238+ return 0;
76239+}
76240+#endif
76241+
76242+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
76243+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
76244+
76245 extern void arch_pick_mmap_layout(struct mm_struct *mm);
76246 extern unsigned long
76247 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
76248@@ -589,6 +603,17 @@ struct signal_struct {
76249 #ifdef CONFIG_TASKSTATS
76250 struct taskstats *stats;
76251 #endif
76252+
76253+#ifdef CONFIG_GRKERNSEC
76254+ u32 curr_ip;
76255+ u32 saved_ip;
76256+ u32 gr_saddr;
76257+ u32 gr_daddr;
76258+ u16 gr_sport;
76259+ u16 gr_dport;
76260+ u8 used_accept:1;
76261+#endif
76262+
76263 #ifdef CONFIG_AUDIT
76264 unsigned audit_tty;
76265 unsigned audit_tty_log_passwd;
76266@@ -669,6 +694,14 @@ struct user_struct {
76267 struct key *session_keyring; /* UID's default session keyring */
76268 #endif
76269
76270+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76271+ unsigned char kernel_banned;
76272+#endif
76273+#ifdef CONFIG_GRKERNSEC_BRUTE
76274+ unsigned char suid_banned;
76275+ unsigned long suid_ban_expires;
76276+#endif
76277+
76278 /* Hash table maintenance information */
76279 struct hlist_node uidhash_node;
76280 kuid_t uid;
76281@@ -1151,8 +1184,8 @@ struct task_struct {
76282 struct list_head thread_group;
76283
76284 struct completion *vfork_done; /* for vfork() */
76285- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
76286- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
76287+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
76288+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
76289
76290 cputime_t utime, stime, utimescaled, stimescaled;
76291 cputime_t gtime;
76292@@ -1177,11 +1210,6 @@ struct task_struct {
76293 struct task_cputime cputime_expires;
76294 struct list_head cpu_timers[3];
76295
76296-/* process credentials */
76297- const struct cred __rcu *real_cred; /* objective and real subjective task
76298- * credentials (COW) */
76299- const struct cred __rcu *cred; /* effective (overridable) subjective task
76300- * credentials (COW) */
76301 char comm[TASK_COMM_LEN]; /* executable name excluding path
76302 - access with [gs]et_task_comm (which lock
76303 it with task_lock())
76304@@ -1198,6 +1226,10 @@ struct task_struct {
76305 #endif
76306 /* CPU-specific state of this task */
76307 struct thread_struct thread;
76308+/* thread_info moved to task_struct */
76309+#ifdef CONFIG_X86
76310+ struct thread_info tinfo;
76311+#endif
76312 /* filesystem information */
76313 struct fs_struct *fs;
76314 /* open file information */
76315@@ -1271,6 +1303,10 @@ struct task_struct {
76316 gfp_t lockdep_reclaim_gfp;
76317 #endif
76318
76319+/* process credentials */
76320+ const struct cred __rcu *real_cred; /* objective and real subjective task
76321+ * credentials (COW) */
76322+
76323 /* journalling filesystem info */
76324 void *journal_info;
76325
76326@@ -1309,6 +1345,10 @@ struct task_struct {
76327 /* cg_list protected by css_set_lock and tsk->alloc_lock */
76328 struct list_head cg_list;
76329 #endif
76330+
76331+ const struct cred __rcu *cred; /* effective (overridable) subjective task
76332+ * credentials (COW) */
76333+
76334 #ifdef CONFIG_FUTEX
76335 struct robust_list_head __user *robust_list;
76336 #ifdef CONFIG_COMPAT
76337@@ -1406,8 +1446,76 @@ struct task_struct {
76338 unsigned int sequential_io;
76339 unsigned int sequential_io_avg;
76340 #endif
76341+
76342+#ifdef CONFIG_GRKERNSEC
76343+ /* grsecurity */
76344+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76345+ u64 exec_id;
76346+#endif
76347+#ifdef CONFIG_GRKERNSEC_SETXID
76348+ const struct cred *delayed_cred;
76349+#endif
76350+ struct dentry *gr_chroot_dentry;
76351+ struct acl_subject_label *acl;
76352+ struct acl_role_label *role;
76353+ struct file *exec_file;
76354+ unsigned long brute_expires;
76355+ u16 acl_role_id;
76356+ /* is this the task that authenticated to the special role */
76357+ u8 acl_sp_role;
76358+ u8 is_writable;
76359+ u8 brute;
76360+ u8 gr_is_chrooted;
76361+#endif
76362+
76363 };
76364
76365+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
76366+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
76367+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
76368+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
76369+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
76370+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
76371+
76372+#ifdef CONFIG_PAX_SOFTMODE
76373+extern int pax_softmode;
76374+#endif
76375+
76376+extern int pax_check_flags(unsigned long *);
76377+
76378+/* if tsk != current then task_lock must be held on it */
76379+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
76380+static inline unsigned long pax_get_flags(struct task_struct *tsk)
76381+{
76382+ if (likely(tsk->mm))
76383+ return tsk->mm->pax_flags;
76384+ else
76385+ return 0UL;
76386+}
76387+
76388+/* if tsk != current then task_lock must be held on it */
76389+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
76390+{
76391+ if (likely(tsk->mm)) {
76392+ tsk->mm->pax_flags = flags;
76393+ return 0;
76394+ }
76395+ return -EINVAL;
76396+}
76397+#endif
76398+
76399+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76400+extern void pax_set_initial_flags(struct linux_binprm *bprm);
76401+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
76402+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
76403+#endif
76404+
76405+struct path;
76406+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
76407+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
76408+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
76409+extern void pax_report_refcount_overflow(struct pt_regs *regs);
76410+
76411 /* Future-safe accessor for struct task_struct's cpus_allowed. */
76412 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
76413
76414@@ -1466,7 +1574,7 @@ struct pid_namespace;
76415 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
76416 struct pid_namespace *ns);
76417
76418-static inline pid_t task_pid_nr(struct task_struct *tsk)
76419+static inline pid_t task_pid_nr(const struct task_struct *tsk)
76420 {
76421 return tsk->pid;
76422 }
76423@@ -1916,7 +2024,9 @@ void yield(void);
76424 extern struct exec_domain default_exec_domain;
76425
76426 union thread_union {
76427+#ifndef CONFIG_X86
76428 struct thread_info thread_info;
76429+#endif
76430 unsigned long stack[THREAD_SIZE/sizeof(long)];
76431 };
76432
76433@@ -1949,6 +2059,7 @@ extern struct pid_namespace init_pid_ns;
76434 */
76435
76436 extern struct task_struct *find_task_by_vpid(pid_t nr);
76437+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
76438 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
76439 struct pid_namespace *ns);
76440
76441@@ -2113,7 +2224,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
76442 extern void exit_itimers(struct signal_struct *);
76443 extern void flush_itimer_signals(void);
76444
76445-extern void do_group_exit(int);
76446+extern __noreturn void do_group_exit(int);
76447
76448 extern int allow_signal(int);
76449 extern int disallow_signal(int);
76450@@ -2304,9 +2415,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
76451
76452 #endif
76453
76454-static inline int object_is_on_stack(void *obj)
76455+static inline int object_starts_on_stack(void *obj)
76456 {
76457- void *stack = task_stack_page(current);
76458+ const void *stack = task_stack_page(current);
76459
76460 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
76461 }
76462diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
76463index bf8086b..962b035 100644
76464--- a/include/linux/sched/sysctl.h
76465+++ b/include/linux/sched/sysctl.h
76466@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
76467 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
76468
76469 extern int sysctl_max_map_count;
76470+extern unsigned long sysctl_heap_stack_gap;
76471
76472 extern unsigned int sysctl_sched_latency;
76473 extern unsigned int sysctl_sched_min_granularity;
76474diff --git a/include/linux/security.h b/include/linux/security.h
76475index 7ce53ae..8ee24a5 100644
76476--- a/include/linux/security.h
76477+++ b/include/linux/security.h
76478@@ -27,6 +27,7 @@
76479 #include <linux/slab.h>
76480 #include <linux/err.h>
76481 #include <linux/string.h>
76482+#include <linux/grsecurity.h>
76483
76484 struct linux_binprm;
76485 struct cred;
76486@@ -116,8 +117,6 @@ struct seq_file;
76487
76488 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
76489
76490-void reset_security_ops(void);
76491-
76492 #ifdef CONFIG_MMU
76493 extern unsigned long mmap_min_addr;
76494 extern unsigned long dac_mmap_min_addr;
76495diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
76496index 4e32edc..f8f2d18 100644
76497--- a/include/linux/seq_file.h
76498+++ b/include/linux/seq_file.h
76499@@ -26,6 +26,9 @@ struct seq_file {
76500 struct mutex lock;
76501 const struct seq_operations *op;
76502 int poll_event;
76503+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76504+ u64 exec_id;
76505+#endif
76506 #ifdef CONFIG_USER_NS
76507 struct user_namespace *user_ns;
76508 #endif
76509@@ -38,6 +41,7 @@ struct seq_operations {
76510 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
76511 int (*show) (struct seq_file *m, void *v);
76512 };
76513+typedef struct seq_operations __no_const seq_operations_no_const;
76514
76515 #define SEQ_SKIP 1
76516
76517diff --git a/include/linux/shm.h b/include/linux/shm.h
76518index 429c199..4d42e38 100644
76519--- a/include/linux/shm.h
76520+++ b/include/linux/shm.h
76521@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
76522
76523 /* The task created the shm object. NULL if the task is dead. */
76524 struct task_struct *shm_creator;
76525+#ifdef CONFIG_GRKERNSEC
76526+ time_t shm_createtime;
76527+ pid_t shm_lapid;
76528+#endif
76529 };
76530
76531 /* shm_mode upper byte flags */
76532diff --git a/include/linux/signal.h b/include/linux/signal.h
76533index d897484..323ba98 100644
76534--- a/include/linux/signal.h
76535+++ b/include/linux/signal.h
76536@@ -433,6 +433,7 @@ void signals_init(void);
76537
76538 int restore_altstack(const stack_t __user *);
76539 int __save_altstack(stack_t __user *, unsigned long);
76540+void __save_altstack_ex(stack_t __user *, unsigned long);
76541
76542 #ifdef CONFIG_PROC_FS
76543 struct seq_file;
76544diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
76545index 3b71a4e..5c9f309 100644
76546--- a/include/linux/skbuff.h
76547+++ b/include/linux/skbuff.h
76548@@ -648,7 +648,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
76549 extern struct sk_buff *__alloc_skb(unsigned int size,
76550 gfp_t priority, int flags, int node);
76551 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
76552-static inline struct sk_buff *alloc_skb(unsigned int size,
76553+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
76554 gfp_t priority)
76555 {
76556 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
76557@@ -764,7 +764,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
76558 */
76559 static inline int skb_queue_empty(const struct sk_buff_head *list)
76560 {
76561- return list->next == (struct sk_buff *)list;
76562+ return list->next == (const struct sk_buff *)list;
76563 }
76564
76565 /**
76566@@ -777,7 +777,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
76567 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76568 const struct sk_buff *skb)
76569 {
76570- return skb->next == (struct sk_buff *)list;
76571+ return skb->next == (const struct sk_buff *)list;
76572 }
76573
76574 /**
76575@@ -790,7 +790,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76576 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
76577 const struct sk_buff *skb)
76578 {
76579- return skb->prev == (struct sk_buff *)list;
76580+ return skb->prev == (const struct sk_buff *)list;
76581 }
76582
76583 /**
76584@@ -1750,7 +1750,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
76585 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
76586 */
76587 #ifndef NET_SKB_PAD
76588-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
76589+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
76590 #endif
76591
76592 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
76593@@ -2345,7 +2345,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
76594 int noblock, int *err);
76595 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
76596 struct poll_table_struct *wait);
76597-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
76598+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
76599 int offset, struct iovec *to,
76600 int size);
76601 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
76602@@ -2636,6 +2636,9 @@ static inline void nf_reset(struct sk_buff *skb)
76603 nf_bridge_put(skb->nf_bridge);
76604 skb->nf_bridge = NULL;
76605 #endif
76606+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
76607+ skb->nf_trace = 0;
76608+#endif
76609 }
76610
76611 static inline void nf_reset_trace(struct sk_buff *skb)
76612diff --git a/include/linux/slab.h b/include/linux/slab.h
76613index 6c5cc0e..9ca0fd6 100644
76614--- a/include/linux/slab.h
76615+++ b/include/linux/slab.h
76616@@ -12,15 +12,29 @@
76617 #include <linux/gfp.h>
76618 #include <linux/types.h>
76619 #include <linux/workqueue.h>
76620-
76621+#include <linux/err.h>
76622
76623 /*
76624 * Flags to pass to kmem_cache_create().
76625 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
76626 */
76627 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
76628+
76629+#ifdef CONFIG_PAX_USERCOPY_SLABS
76630+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
76631+#else
76632+#define SLAB_USERCOPY 0x00000000UL
76633+#endif
76634+
76635 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
76636 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
76637+
76638+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76639+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
76640+#else
76641+#define SLAB_NO_SANITIZE 0x00000000UL
76642+#endif
76643+
76644 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
76645 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
76646 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
76647@@ -89,10 +103,13 @@
76648 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
76649 * Both make kfree a no-op.
76650 */
76651-#define ZERO_SIZE_PTR ((void *)16)
76652+#define ZERO_SIZE_PTR \
76653+({ \
76654+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
76655+ (void *)(-MAX_ERRNO-1L); \
76656+})
76657
76658-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
76659- (unsigned long)ZERO_SIZE_PTR)
76660+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
76661
76662
76663 struct mem_cgroup;
76664@@ -132,6 +149,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
76665 void kfree(const void *);
76666 void kzfree(const void *);
76667 size_t ksize(const void *);
76668+const char *check_heap_object(const void *ptr, unsigned long n);
76669+bool is_usercopy_object(const void *ptr);
76670
76671 /*
76672 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
76673@@ -164,7 +183,7 @@ struct kmem_cache {
76674 unsigned int align; /* Alignment as calculated */
76675 unsigned long flags; /* Active flags on the slab */
76676 const char *name; /* Slab name for sysfs */
76677- int refcount; /* Use counter */
76678+ atomic_t refcount; /* Use counter */
76679 void (*ctor)(void *); /* Called on object slot creation */
76680 struct list_head list; /* List of all slab caches on the system */
76681 };
76682@@ -238,6 +257,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
76683 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76684 #endif
76685
76686+#ifdef CONFIG_PAX_USERCOPY_SLABS
76687+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
76688+#endif
76689+
76690 /*
76691 * Figure out which kmalloc slab an allocation of a certain size
76692 * belongs to.
76693@@ -246,7 +269,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76694 * 2 = 120 .. 192 bytes
76695 * n = 2^(n-1) .. 2^n -1
76696 */
76697-static __always_inline int kmalloc_index(size_t size)
76698+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
76699 {
76700 if (!size)
76701 return 0;
76702@@ -492,7 +515,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
76703 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76704 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76705 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76706-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76707+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
76708 #define kmalloc_track_caller(size, flags) \
76709 __kmalloc_track_caller(size, flags, _RET_IP_)
76710 #else
76711@@ -512,7 +535,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76712 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76713 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76714 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76715-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
76716+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
76717 #define kmalloc_node_track_caller(size, flags, node) \
76718 __kmalloc_node_track_caller(size, flags, node, \
76719 _RET_IP_)
76720diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
76721index cd40158..4e2f7af 100644
76722--- a/include/linux/slab_def.h
76723+++ b/include/linux/slab_def.h
76724@@ -50,7 +50,7 @@ struct kmem_cache {
76725 /* 4) cache creation/removal */
76726 const char *name;
76727 struct list_head list;
76728- int refcount;
76729+ atomic_t refcount;
76730 int object_size;
76731 int align;
76732
76733@@ -66,10 +66,14 @@ struct kmem_cache {
76734 unsigned long node_allocs;
76735 unsigned long node_frees;
76736 unsigned long node_overflow;
76737- atomic_t allochit;
76738- atomic_t allocmiss;
76739- atomic_t freehit;
76740- atomic_t freemiss;
76741+ atomic_unchecked_t allochit;
76742+ atomic_unchecked_t allocmiss;
76743+ atomic_unchecked_t freehit;
76744+ atomic_unchecked_t freemiss;
76745+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76746+ atomic_unchecked_t sanitized;
76747+ atomic_unchecked_t not_sanitized;
76748+#endif
76749
76750 /*
76751 * If debugging is enabled, then the allocator can add additional
76752@@ -103,7 +107,7 @@ struct kmem_cache {
76753 };
76754
76755 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76756-void *__kmalloc(size_t size, gfp_t flags);
76757+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
76758
76759 #ifdef CONFIG_TRACING
76760 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
76761@@ -136,6 +140,13 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76762 cachep = kmalloc_dma_caches[i];
76763 else
76764 #endif
76765+
76766+#ifdef CONFIG_PAX_USERCOPY_SLABS
76767+ if (flags & GFP_USERCOPY)
76768+ cachep = kmalloc_usercopy_caches[i];
76769+ else
76770+#endif
76771+
76772 cachep = kmalloc_caches[i];
76773
76774 ret = kmem_cache_alloc_trace(cachep, flags, size);
76775@@ -146,7 +157,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76776 }
76777
76778 #ifdef CONFIG_NUMA
76779-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
76780+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76781 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76782
76783 #ifdef CONFIG_TRACING
76784@@ -185,6 +196,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76785 cachep = kmalloc_dma_caches[i];
76786 else
76787 #endif
76788+
76789+#ifdef CONFIG_PAX_USERCOPY_SLABS
76790+ if (flags & GFP_USERCOPY)
76791+ cachep = kmalloc_usercopy_caches[i];
76792+ else
76793+#endif
76794+
76795 cachep = kmalloc_caches[i];
76796
76797 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
76798diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
76799index 095a5a4..4b82027 100644
76800--- a/include/linux/slob_def.h
76801+++ b/include/linux/slob_def.h
76802@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
76803 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
76804 }
76805
76806-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76807+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76808
76809 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76810 {
76811@@ -23,7 +23,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76812 return __kmalloc_node(size, flags, NUMA_NO_NODE);
76813 }
76814
76815-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
76816+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
76817 {
76818 return kmalloc(size, flags);
76819 }
76820diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
76821index 027276f..092bfe8 100644
76822--- a/include/linux/slub_def.h
76823+++ b/include/linux/slub_def.h
76824@@ -80,7 +80,7 @@ struct kmem_cache {
76825 struct kmem_cache_order_objects max;
76826 struct kmem_cache_order_objects min;
76827 gfp_t allocflags; /* gfp flags to use on each alloc */
76828- int refcount; /* Refcount for slab cache destroy */
76829+ atomic_t refcount; /* Refcount for slab cache destroy */
76830 void (*ctor)(void *);
76831 int inuse; /* Offset to metadata */
76832 int align; /* Alignment */
76833@@ -105,7 +105,7 @@ struct kmem_cache {
76834 };
76835
76836 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76837-void *__kmalloc(size_t size, gfp_t flags);
76838+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
76839
76840 static __always_inline void *
76841 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
76842@@ -149,7 +149,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
76843 }
76844 #endif
76845
76846-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
76847+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
76848 {
76849 unsigned int order = get_order(size);
76850 return kmalloc_order_trace(size, flags, order);
76851@@ -175,7 +175,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76852 }
76853
76854 #ifdef CONFIG_NUMA
76855-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76856+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76857 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76858
76859 #ifdef CONFIG_TRACING
76860diff --git a/include/linux/smp.h b/include/linux/smp.h
76861index c181399..09d7b92 100644
76862--- a/include/linux/smp.h
76863+++ b/include/linux/smp.h
76864@@ -217,7 +217,9 @@ static inline void kick_all_cpus_sync(void) { }
76865 #endif
76866
76867 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
76868+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
76869 #define put_cpu() preempt_enable()
76870+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
76871
76872 /*
76873 * Callback to arch code if there's nosmp or maxcpus=0 on the
76874diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
76875index 54f91d3..be2c379 100644
76876--- a/include/linux/sock_diag.h
76877+++ b/include/linux/sock_diag.h
76878@@ -11,7 +11,7 @@ struct sock;
76879 struct sock_diag_handler {
76880 __u8 family;
76881 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
76882-};
76883+} __do_const;
76884
76885 int sock_diag_register(const struct sock_diag_handler *h);
76886 void sock_diag_unregister(const struct sock_diag_handler *h);
76887diff --git a/include/linux/sonet.h b/include/linux/sonet.h
76888index 680f9a3..f13aeb0 100644
76889--- a/include/linux/sonet.h
76890+++ b/include/linux/sonet.h
76891@@ -7,7 +7,7 @@
76892 #include <uapi/linux/sonet.h>
76893
76894 struct k_sonet_stats {
76895-#define __HANDLE_ITEM(i) atomic_t i
76896+#define __HANDLE_ITEM(i) atomic_unchecked_t i
76897 __SONET_ITEMS
76898 #undef __HANDLE_ITEM
76899 };
76900diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
76901index 07d8e53..dc934c9 100644
76902--- a/include/linux/sunrpc/addr.h
76903+++ b/include/linux/sunrpc/addr.h
76904@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
76905 {
76906 switch (sap->sa_family) {
76907 case AF_INET:
76908- return ntohs(((struct sockaddr_in *)sap)->sin_port);
76909+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
76910 case AF_INET6:
76911- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
76912+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
76913 }
76914 return 0;
76915 }
76916@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
76917 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
76918 const struct sockaddr *src)
76919 {
76920- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
76921+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
76922 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
76923
76924 dsin->sin_family = ssin->sin_family;
76925@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
76926 if (sa->sa_family != AF_INET6)
76927 return 0;
76928
76929- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
76930+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
76931 }
76932
76933 #endif /* _LINUX_SUNRPC_ADDR_H */
76934diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
76935index bfe11be..12bc8c4 100644
76936--- a/include/linux/sunrpc/clnt.h
76937+++ b/include/linux/sunrpc/clnt.h
76938@@ -96,7 +96,7 @@ struct rpc_procinfo {
76939 unsigned int p_timer; /* Which RTT timer to use */
76940 u32 p_statidx; /* Which procedure to account */
76941 const char * p_name; /* name of procedure */
76942-};
76943+} __do_const;
76944
76945 #ifdef __KERNEL__
76946
76947diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
76948index 1f0216b..6a4fa50 100644
76949--- a/include/linux/sunrpc/svc.h
76950+++ b/include/linux/sunrpc/svc.h
76951@@ -411,7 +411,7 @@ struct svc_procedure {
76952 unsigned int pc_count; /* call count */
76953 unsigned int pc_cachetype; /* cache info (NFS) */
76954 unsigned int pc_xdrressize; /* maximum size of XDR reply */
76955-};
76956+} __do_const;
76957
76958 /*
76959 * Function prototypes.
76960diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
76961index 0b8e3e6..33e0a01 100644
76962--- a/include/linux/sunrpc/svc_rdma.h
76963+++ b/include/linux/sunrpc/svc_rdma.h
76964@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
76965 extern unsigned int svcrdma_max_requests;
76966 extern unsigned int svcrdma_max_req_size;
76967
76968-extern atomic_t rdma_stat_recv;
76969-extern atomic_t rdma_stat_read;
76970-extern atomic_t rdma_stat_write;
76971-extern atomic_t rdma_stat_sq_starve;
76972-extern atomic_t rdma_stat_rq_starve;
76973-extern atomic_t rdma_stat_rq_poll;
76974-extern atomic_t rdma_stat_rq_prod;
76975-extern atomic_t rdma_stat_sq_poll;
76976-extern atomic_t rdma_stat_sq_prod;
76977+extern atomic_unchecked_t rdma_stat_recv;
76978+extern atomic_unchecked_t rdma_stat_read;
76979+extern atomic_unchecked_t rdma_stat_write;
76980+extern atomic_unchecked_t rdma_stat_sq_starve;
76981+extern atomic_unchecked_t rdma_stat_rq_starve;
76982+extern atomic_unchecked_t rdma_stat_rq_poll;
76983+extern atomic_unchecked_t rdma_stat_rq_prod;
76984+extern atomic_unchecked_t rdma_stat_sq_poll;
76985+extern atomic_unchecked_t rdma_stat_sq_prod;
76986
76987 #define RPCRDMA_VERSION 1
76988
76989diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
76990index 8d71d65..f79586e 100644
76991--- a/include/linux/sunrpc/svcauth.h
76992+++ b/include/linux/sunrpc/svcauth.h
76993@@ -120,7 +120,7 @@ struct auth_ops {
76994 int (*release)(struct svc_rqst *rq);
76995 void (*domain_release)(struct auth_domain *);
76996 int (*set_client)(struct svc_rqst *rq);
76997-};
76998+} __do_const;
76999
77000 #define SVC_GARBAGE 1
77001 #define SVC_SYSERR 2
77002diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
77003index a5ffd32..0935dea 100644
77004--- a/include/linux/swiotlb.h
77005+++ b/include/linux/swiotlb.h
77006@@ -60,7 +60,8 @@ extern void
77007
77008 extern void
77009 swiotlb_free_coherent(struct device *hwdev, size_t size,
77010- void *vaddr, dma_addr_t dma_handle);
77011+ void *vaddr, dma_addr_t dma_handle,
77012+ struct dma_attrs *attrs);
77013
77014 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
77015 unsigned long offset, size_t size,
77016diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
77017index 84662ec..5271947 100644
77018--- a/include/linux/syscalls.h
77019+++ b/include/linux/syscalls.h
77020@@ -97,8 +97,14 @@ struct sigaltstack;
77021 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
77022
77023 #define __SC_DECL(t, a) t a
77024+#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))
77025 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
77026-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
77027+#define __SC_LONG(t, a) __typeof( \
77028+ __builtin_choose_expr( \
77029+ sizeof(t) > sizeof(int), \
77030+ (t) 0, \
77031+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
77032+ )) a
77033 #define __SC_CAST(t, a) (t) a
77034 #define __SC_ARGS(t, a) a
77035 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
77036@@ -362,11 +368,11 @@ asmlinkage long sys_sync(void);
77037 asmlinkage long sys_fsync(unsigned int fd);
77038 asmlinkage long sys_fdatasync(unsigned int fd);
77039 asmlinkage long sys_bdflush(int func, long data);
77040-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
77041- char __user *type, unsigned long flags,
77042+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
77043+ const char __user *type, unsigned long flags,
77044 void __user *data);
77045-asmlinkage long sys_umount(char __user *name, int flags);
77046-asmlinkage long sys_oldumount(char __user *name);
77047+asmlinkage long sys_umount(const char __user *name, int flags);
77048+asmlinkage long sys_oldumount(const char __user *name);
77049 asmlinkage long sys_truncate(const char __user *path, long length);
77050 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
77051 asmlinkage long sys_stat(const char __user *filename,
77052@@ -578,7 +584,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
77053 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
77054 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
77055 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
77056- struct sockaddr __user *, int);
77057+ struct sockaddr __user *, int) __intentional_overflow(0);
77058 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
77059 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
77060 unsigned int vlen, unsigned flags);
77061diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
77062index 27b3b0b..e093dd9 100644
77063--- a/include/linux/syscore_ops.h
77064+++ b/include/linux/syscore_ops.h
77065@@ -16,7 +16,7 @@ struct syscore_ops {
77066 int (*suspend)(void);
77067 void (*resume)(void);
77068 void (*shutdown)(void);
77069-};
77070+} __do_const;
77071
77072 extern void register_syscore_ops(struct syscore_ops *ops);
77073 extern void unregister_syscore_ops(struct syscore_ops *ops);
77074diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
77075index 14a8ff2..af52bad 100644
77076--- a/include/linux/sysctl.h
77077+++ b/include/linux/sysctl.h
77078@@ -34,13 +34,13 @@ struct ctl_table_root;
77079 struct ctl_table_header;
77080 struct ctl_dir;
77081
77082-typedef struct ctl_table ctl_table;
77083-
77084 typedef int proc_handler (struct ctl_table *ctl, int write,
77085 void __user *buffer, size_t *lenp, loff_t *ppos);
77086
77087 extern int proc_dostring(struct ctl_table *, int,
77088 void __user *, size_t *, loff_t *);
77089+extern int proc_dostring_modpriv(struct ctl_table *, int,
77090+ void __user *, size_t *, loff_t *);
77091 extern int proc_dointvec(struct ctl_table *, int,
77092 void __user *, size_t *, loff_t *);
77093 extern int proc_dointvec_minmax(struct ctl_table *, int,
77094@@ -115,7 +115,9 @@ struct ctl_table
77095 struct ctl_table_poll *poll;
77096 void *extra1;
77097 void *extra2;
77098-};
77099+} __do_const;
77100+typedef struct ctl_table __no_const ctl_table_no_const;
77101+typedef struct ctl_table ctl_table;
77102
77103 struct ctl_node {
77104 struct rb_node node;
77105diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
77106index 9e8a9b5..753de68 100644
77107--- a/include/linux/sysfs.h
77108+++ b/include/linux/sysfs.h
77109@@ -33,7 +33,8 @@ struct attribute {
77110 struct lock_class_key *key;
77111 struct lock_class_key skey;
77112 #endif
77113-};
77114+} __do_const;
77115+typedef struct attribute __no_const attribute_no_const;
77116
77117 /**
77118 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
77119@@ -62,7 +63,8 @@ struct attribute_group {
77120 struct attribute *, int);
77121 struct attribute **attrs;
77122 struct bin_attribute **bin_attrs;
77123-};
77124+} __do_const;
77125+typedef struct attribute_group __no_const attribute_group_no_const;
77126
77127 /**
77128 * Use these macros to make defining attributes easier. See include/linux/device.h
77129@@ -123,7 +125,8 @@ struct bin_attribute {
77130 char *, loff_t, size_t);
77131 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
77132 struct vm_area_struct *vma);
77133-};
77134+} __do_const;
77135+typedef struct bin_attribute __no_const bin_attribute_no_const;
77136
77137 /**
77138 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
77139diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
77140index 7faf933..9b85a0c 100644
77141--- a/include/linux/sysrq.h
77142+++ b/include/linux/sysrq.h
77143@@ -16,6 +16,7 @@
77144
77145 #include <linux/errno.h>
77146 #include <linux/types.h>
77147+#include <linux/compiler.h>
77148
77149 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
77150 #define SYSRQ_DEFAULT_ENABLE 1
77151@@ -36,7 +37,7 @@ struct sysrq_key_op {
77152 char *help_msg;
77153 char *action_msg;
77154 int enable_mask;
77155-};
77156+} __do_const;
77157
77158 #ifdef CONFIG_MAGIC_SYSRQ
77159
77160diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
77161index e7e0473..7989295 100644
77162--- a/include/linux/thread_info.h
77163+++ b/include/linux/thread_info.h
77164@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
77165 #error "no set_restore_sigmask() provided and default one won't work"
77166 #endif
77167
77168+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
77169+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
77170+{
77171+#ifndef CONFIG_PAX_USERCOPY_DEBUG
77172+ if (!__builtin_constant_p(n))
77173+#endif
77174+ __check_object_size(ptr, n, to_user);
77175+}
77176+
77177 #endif /* __KERNEL__ */
77178
77179 #endif /* _LINUX_THREAD_INFO_H */
77180diff --git a/include/linux/tty.h b/include/linux/tty.h
77181index 01ac30e..bf18a71 100644
77182--- a/include/linux/tty.h
77183+++ b/include/linux/tty.h
77184@@ -194,7 +194,7 @@ struct tty_port {
77185 const struct tty_port_operations *ops; /* Port operations */
77186 spinlock_t lock; /* Lock protecting tty field */
77187 int blocked_open; /* Waiting to open */
77188- int count; /* Usage count */
77189+ atomic_t count; /* Usage count */
77190 wait_queue_head_t open_wait; /* Open waiters */
77191 wait_queue_head_t close_wait; /* Close waiters */
77192 wait_queue_head_t delta_msr_wait; /* Modem status change */
77193@@ -547,7 +547,7 @@ extern int tty_port_open(struct tty_port *port,
77194 struct tty_struct *tty, struct file *filp);
77195 static inline int tty_port_users(struct tty_port *port)
77196 {
77197- return port->count + port->blocked_open;
77198+ return atomic_read(&port->count) + port->blocked_open;
77199 }
77200
77201 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
77202diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
77203index 756a609..b302dd6 100644
77204--- a/include/linux/tty_driver.h
77205+++ b/include/linux/tty_driver.h
77206@@ -285,7 +285,7 @@ struct tty_operations {
77207 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
77208 #endif
77209 const struct file_operations *proc_fops;
77210-};
77211+} __do_const;
77212
77213 struct tty_driver {
77214 int magic; /* magic number for this structure */
77215diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
77216index a1b0489..f02e17c 100644
77217--- a/include/linux/tty_ldisc.h
77218+++ b/include/linux/tty_ldisc.h
77219@@ -198,7 +198,7 @@ struct tty_ldisc_ops {
77220
77221 struct module *owner;
77222
77223- int refcount;
77224+ atomic_t refcount;
77225 };
77226
77227 struct tty_ldisc {
77228diff --git a/include/linux/types.h b/include/linux/types.h
77229index 4d118ba..c3ee9bf 100644
77230--- a/include/linux/types.h
77231+++ b/include/linux/types.h
77232@@ -176,10 +176,26 @@ typedef struct {
77233 int counter;
77234 } atomic_t;
77235
77236+#ifdef CONFIG_PAX_REFCOUNT
77237+typedef struct {
77238+ int counter;
77239+} atomic_unchecked_t;
77240+#else
77241+typedef atomic_t atomic_unchecked_t;
77242+#endif
77243+
77244 #ifdef CONFIG_64BIT
77245 typedef struct {
77246 long counter;
77247 } atomic64_t;
77248+
77249+#ifdef CONFIG_PAX_REFCOUNT
77250+typedef struct {
77251+ long counter;
77252+} atomic64_unchecked_t;
77253+#else
77254+typedef atomic64_t atomic64_unchecked_t;
77255+#endif
77256 #endif
77257
77258 struct list_head {
77259diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
77260index 5ca0951..ab496a5 100644
77261--- a/include/linux/uaccess.h
77262+++ b/include/linux/uaccess.h
77263@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
77264 long ret; \
77265 mm_segment_t old_fs = get_fs(); \
77266 \
77267- set_fs(KERNEL_DS); \
77268 pagefault_disable(); \
77269- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
77270- pagefault_enable(); \
77271+ set_fs(KERNEL_DS); \
77272+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
77273 set_fs(old_fs); \
77274+ pagefault_enable(); \
77275 ret; \
77276 })
77277
77278diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
77279index 8e522cbc..aa8572d 100644
77280--- a/include/linux/uidgid.h
77281+++ b/include/linux/uidgid.h
77282@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
77283
77284 #endif /* CONFIG_USER_NS */
77285
77286+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
77287+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
77288+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
77289+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
77290+
77291 #endif /* _LINUX_UIDGID_H */
77292diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
77293index 99c1b4d..562e6f3 100644
77294--- a/include/linux/unaligned/access_ok.h
77295+++ b/include/linux/unaligned/access_ok.h
77296@@ -4,34 +4,34 @@
77297 #include <linux/kernel.h>
77298 #include <asm/byteorder.h>
77299
77300-static inline u16 get_unaligned_le16(const void *p)
77301+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
77302 {
77303- return le16_to_cpup((__le16 *)p);
77304+ return le16_to_cpup((const __le16 *)p);
77305 }
77306
77307-static inline u32 get_unaligned_le32(const void *p)
77308+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
77309 {
77310- return le32_to_cpup((__le32 *)p);
77311+ return le32_to_cpup((const __le32 *)p);
77312 }
77313
77314-static inline u64 get_unaligned_le64(const void *p)
77315+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
77316 {
77317- return le64_to_cpup((__le64 *)p);
77318+ return le64_to_cpup((const __le64 *)p);
77319 }
77320
77321-static inline u16 get_unaligned_be16(const void *p)
77322+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
77323 {
77324- return be16_to_cpup((__be16 *)p);
77325+ return be16_to_cpup((const __be16 *)p);
77326 }
77327
77328-static inline u32 get_unaligned_be32(const void *p)
77329+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
77330 {
77331- return be32_to_cpup((__be32 *)p);
77332+ return be32_to_cpup((const __be32 *)p);
77333 }
77334
77335-static inline u64 get_unaligned_be64(const void *p)
77336+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
77337 {
77338- return be64_to_cpup((__be64 *)p);
77339+ return be64_to_cpup((const __be64 *)p);
77340 }
77341
77342 static inline void put_unaligned_le16(u16 val, void *p)
77343diff --git a/include/linux/usb.h b/include/linux/usb.h
77344index 0eec268..4496526 100644
77345--- a/include/linux/usb.h
77346+++ b/include/linux/usb.h
77347@@ -560,7 +560,7 @@ struct usb_device {
77348 int maxchild;
77349
77350 u32 quirks;
77351- atomic_t urbnum;
77352+ atomic_unchecked_t urbnum;
77353
77354 unsigned long active_duration;
77355
77356@@ -1617,7 +1617,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
77357
77358 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
77359 __u8 request, __u8 requesttype, __u16 value, __u16 index,
77360- void *data, __u16 size, int timeout);
77361+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
77362 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
77363 void *data, int len, int *actual_length, int timeout);
77364 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
77365diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
77366index e452ba6..78f8e80 100644
77367--- a/include/linux/usb/renesas_usbhs.h
77368+++ b/include/linux/usb/renesas_usbhs.h
77369@@ -39,7 +39,7 @@ enum {
77370 */
77371 struct renesas_usbhs_driver_callback {
77372 int (*notify_hotplug)(struct platform_device *pdev);
77373-};
77374+} __no_const;
77375
77376 /*
77377 * callback functions for platform
77378diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
77379index 6f8fbcf..8259001 100644
77380--- a/include/linux/vermagic.h
77381+++ b/include/linux/vermagic.h
77382@@ -25,9 +25,35 @@
77383 #define MODULE_ARCH_VERMAGIC ""
77384 #endif
77385
77386+#ifdef CONFIG_PAX_REFCOUNT
77387+#define MODULE_PAX_REFCOUNT "REFCOUNT "
77388+#else
77389+#define MODULE_PAX_REFCOUNT ""
77390+#endif
77391+
77392+#ifdef CONSTIFY_PLUGIN
77393+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
77394+#else
77395+#define MODULE_CONSTIFY_PLUGIN ""
77396+#endif
77397+
77398+#ifdef STACKLEAK_PLUGIN
77399+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
77400+#else
77401+#define MODULE_STACKLEAK_PLUGIN ""
77402+#endif
77403+
77404+#ifdef CONFIG_GRKERNSEC
77405+#define MODULE_GRSEC "GRSEC "
77406+#else
77407+#define MODULE_GRSEC ""
77408+#endif
77409+
77410 #define VERMAGIC_STRING \
77411 UTS_RELEASE " " \
77412 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
77413 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
77414- MODULE_ARCH_VERMAGIC
77415+ MODULE_ARCH_VERMAGIC \
77416+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
77417+ MODULE_GRSEC
77418
77419diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
77420index 4b8a891..c20e936 100644
77421--- a/include/linux/vmalloc.h
77422+++ b/include/linux/vmalloc.h
77423@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
77424 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
77425 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
77426 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
77427+
77428+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
77429+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
77430+#endif
77431+
77432 /* bits [20..32] reserved for arch specific ioremap internals */
77433
77434 /*
77435@@ -75,7 +80,7 @@ extern void *vmalloc_32_user(unsigned long size);
77436 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
77437 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
77438 unsigned long start, unsigned long end, gfp_t gfp_mask,
77439- pgprot_t prot, int node, const void *caller);
77440+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
77441 extern void vfree(const void *addr);
77442
77443 extern void *vmap(struct page **pages, unsigned int count,
77444@@ -141,8 +146,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
77445 extern void free_vm_area(struct vm_struct *area);
77446
77447 /* for /dev/kmem */
77448-extern long vread(char *buf, char *addr, unsigned long count);
77449-extern long vwrite(char *buf, char *addr, unsigned long count);
77450+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
77451+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
77452
77453 /*
77454 * Internals. Dont't use..
77455diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
77456index c586679..f06b389 100644
77457--- a/include/linux/vmstat.h
77458+++ b/include/linux/vmstat.h
77459@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
77460 /*
77461 * Zone based page accounting with per cpu differentials.
77462 */
77463-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77464+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77465
77466 static inline void zone_page_state_add(long x, struct zone *zone,
77467 enum zone_stat_item item)
77468 {
77469- atomic_long_add(x, &zone->vm_stat[item]);
77470- atomic_long_add(x, &vm_stat[item]);
77471+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
77472+ atomic_long_add_unchecked(x, &vm_stat[item]);
77473 }
77474
77475 static inline unsigned long global_page_state(enum zone_stat_item item)
77476 {
77477- long x = atomic_long_read(&vm_stat[item]);
77478+ long x = atomic_long_read_unchecked(&vm_stat[item]);
77479 #ifdef CONFIG_SMP
77480 if (x < 0)
77481 x = 0;
77482@@ -112,7 +112,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
77483 static inline unsigned long zone_page_state(struct zone *zone,
77484 enum zone_stat_item item)
77485 {
77486- long x = atomic_long_read(&zone->vm_stat[item]);
77487+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77488 #ifdef CONFIG_SMP
77489 if (x < 0)
77490 x = 0;
77491@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
77492 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
77493 enum zone_stat_item item)
77494 {
77495- long x = atomic_long_read(&zone->vm_stat[item]);
77496+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77497
77498 #ifdef CONFIG_SMP
77499 int cpu;
77500@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
77501
77502 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
77503 {
77504- atomic_long_inc(&zone->vm_stat[item]);
77505- atomic_long_inc(&vm_stat[item]);
77506+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
77507+ atomic_long_inc_unchecked(&vm_stat[item]);
77508 }
77509
77510 static inline void __inc_zone_page_state(struct page *page,
77511@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
77512
77513 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
77514 {
77515- atomic_long_dec(&zone->vm_stat[item]);
77516- atomic_long_dec(&vm_stat[item]);
77517+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
77518+ atomic_long_dec_unchecked(&vm_stat[item]);
77519 }
77520
77521 static inline void __dec_zone_page_state(struct page *page,
77522diff --git a/include/linux/xattr.h b/include/linux/xattr.h
77523index fdbafc6..49dfe4f 100644
77524--- a/include/linux/xattr.h
77525+++ b/include/linux/xattr.h
77526@@ -28,7 +28,7 @@ struct xattr_handler {
77527 size_t size, int handler_flags);
77528 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
77529 size_t size, int flags, int handler_flags);
77530-};
77531+} __do_const;
77532
77533 struct xattr {
77534 char *name;
77535@@ -37,6 +37,9 @@ struct xattr {
77536 };
77537
77538 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
77539+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77540+ssize_t pax_getxattr(struct dentry *, void *, size_t);
77541+#endif
77542 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
77543 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
77544 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
77545diff --git a/include/linux/zlib.h b/include/linux/zlib.h
77546index 9c5a6b4..09c9438 100644
77547--- a/include/linux/zlib.h
77548+++ b/include/linux/zlib.h
77549@@ -31,6 +31,7 @@
77550 #define _ZLIB_H
77551
77552 #include <linux/zconf.h>
77553+#include <linux/compiler.h>
77554
77555 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
77556 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
77557@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
77558
77559 /* basic functions */
77560
77561-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
77562+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
77563 /*
77564 Returns the number of bytes that needs to be allocated for a per-
77565 stream workspace with the specified parameters. A pointer to this
77566diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
77567index c768c9f..bdcaa5a 100644
77568--- a/include/media/v4l2-dev.h
77569+++ b/include/media/v4l2-dev.h
77570@@ -76,7 +76,7 @@ struct v4l2_file_operations {
77571 int (*mmap) (struct file *, struct vm_area_struct *);
77572 int (*open) (struct file *);
77573 int (*release) (struct file *);
77574-};
77575+} __do_const;
77576
77577 /*
77578 * Newer version of video_device, handled by videodev2.c
77579diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
77580index c9b1593..a572459 100644
77581--- a/include/media/v4l2-device.h
77582+++ b/include/media/v4l2-device.h
77583@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
77584 this function returns 0. If the name ends with a digit (e.g. cx18),
77585 then the name will be set to cx18-0 since cx180 looks really odd. */
77586 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
77587- atomic_t *instance);
77588+ atomic_unchecked_t *instance);
77589
77590 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
77591 Since the parent disappears this ensures that v4l2_dev doesn't have an
77592diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
77593index d9fa68f..45c88d1 100644
77594--- a/include/net/9p/transport.h
77595+++ b/include/net/9p/transport.h
77596@@ -63,7 +63,7 @@ struct p9_trans_module {
77597 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
77598 int (*zc_request)(struct p9_client *, struct p9_req_t *,
77599 char *, char *, int , int, int, int);
77600-};
77601+} __do_const;
77602
77603 void v9fs_register_trans(struct p9_trans_module *m);
77604 void v9fs_unregister_trans(struct p9_trans_module *m);
77605diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
77606index 1a966af..2767cf6 100644
77607--- a/include/net/bluetooth/l2cap.h
77608+++ b/include/net/bluetooth/l2cap.h
77609@@ -551,7 +551,7 @@ struct l2cap_ops {
77610 void (*defer) (struct l2cap_chan *chan);
77611 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
77612 unsigned long len, int nb);
77613-};
77614+} __do_const;
77615
77616 struct l2cap_conn {
77617 struct hci_conn *hcon;
77618diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
77619index f2ae33d..c457cf0 100644
77620--- a/include/net/caif/cfctrl.h
77621+++ b/include/net/caif/cfctrl.h
77622@@ -52,7 +52,7 @@ struct cfctrl_rsp {
77623 void (*radioset_rsp)(void);
77624 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
77625 struct cflayer *client_layer);
77626-};
77627+} __no_const;
77628
77629 /* Link Setup Parameters for CAIF-Links. */
77630 struct cfctrl_link_param {
77631@@ -101,8 +101,8 @@ struct cfctrl_request_info {
77632 struct cfctrl {
77633 struct cfsrvl serv;
77634 struct cfctrl_rsp res;
77635- atomic_t req_seq_no;
77636- atomic_t rsp_seq_no;
77637+ atomic_unchecked_t req_seq_no;
77638+ atomic_unchecked_t rsp_seq_no;
77639 struct list_head list;
77640 /* Protects from simultaneous access to first_req list */
77641 spinlock_t info_list_lock;
77642diff --git a/include/net/flow.h b/include/net/flow.h
77643index 628e11b..4c475df 100644
77644--- a/include/net/flow.h
77645+++ b/include/net/flow.h
77646@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
77647
77648 extern void flow_cache_flush(void);
77649 extern void flow_cache_flush_deferred(void);
77650-extern atomic_t flow_cache_genid;
77651+extern atomic_unchecked_t flow_cache_genid;
77652
77653 #endif
77654diff --git a/include/net/genetlink.h b/include/net/genetlink.h
77655index 8e0b6c8..73cf605 100644
77656--- a/include/net/genetlink.h
77657+++ b/include/net/genetlink.h
77658@@ -120,7 +120,7 @@ struct genl_ops {
77659 struct netlink_callback *cb);
77660 int (*done)(struct netlink_callback *cb);
77661 struct list_head ops_list;
77662-};
77663+} __do_const;
77664
77665 extern int __genl_register_family(struct genl_family *family);
77666
77667diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
77668index 734d9b5..48a9a4b 100644
77669--- a/include/net/gro_cells.h
77670+++ b/include/net/gro_cells.h
77671@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
77672 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
77673
77674 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
77675- atomic_long_inc(&dev->rx_dropped);
77676+ atomic_long_inc_unchecked(&dev->rx_dropped);
77677 kfree_skb(skb);
77678 return;
77679 }
77680diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
77681index de2c785..0588a6b 100644
77682--- a/include/net/inet_connection_sock.h
77683+++ b/include/net/inet_connection_sock.h
77684@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
77685 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
77686 int (*bind_conflict)(const struct sock *sk,
77687 const struct inet_bind_bucket *tb, bool relax);
77688-};
77689+} __do_const;
77690
77691 /** inet_connection_sock - INET connection oriented sock
77692 *
77693diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
77694index 53f464d..0bd0b49 100644
77695--- a/include/net/inetpeer.h
77696+++ b/include/net/inetpeer.h
77697@@ -47,8 +47,8 @@ struct inet_peer {
77698 */
77699 union {
77700 struct {
77701- atomic_t rid; /* Frag reception counter */
77702- atomic_t ip_id_count; /* IP ID for the next packet */
77703+ atomic_unchecked_t rid; /* Frag reception counter */
77704+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
77705 };
77706 struct rcu_head rcu;
77707 struct inet_peer *gc_next;
77708@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
77709 /* can be called with or without local BH being disabled */
77710 static inline int inet_getid(struct inet_peer *p, int more)
77711 {
77712- int old, new;
77713+ int id;
77714 more++;
77715 inet_peer_refcheck(p);
77716- do {
77717- old = atomic_read(&p->ip_id_count);
77718- new = old + more;
77719- if (!new)
77720- new = 1;
77721- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
77722- return new;
77723+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
77724+ if (!id)
77725+ id = atomic_inc_return_unchecked(&p->ip_id_count);
77726+ return id;
77727 }
77728
77729 #endif /* _NET_INETPEER_H */
77730diff --git a/include/net/ip.h b/include/net/ip.h
77731index a68f838..74518ab 100644
77732--- a/include/net/ip.h
77733+++ b/include/net/ip.h
77734@@ -202,7 +202,7 @@ extern struct local_ports {
77735 } sysctl_local_ports;
77736 extern void inet_get_local_port_range(int *low, int *high);
77737
77738-extern unsigned long *sysctl_local_reserved_ports;
77739+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
77740 static inline int inet_is_reserved_local_port(int port)
77741 {
77742 return test_bit(port, sysctl_local_reserved_ports);
77743diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
77744index cbf2be3..3683f6d 100644
77745--- a/include/net/ip_fib.h
77746+++ b/include/net/ip_fib.h
77747@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
77748
77749 #define FIB_RES_SADDR(net, res) \
77750 ((FIB_RES_NH(res).nh_saddr_genid == \
77751- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
77752+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
77753 FIB_RES_NH(res).nh_saddr : \
77754 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
77755 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
77756diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
77757index f0d70f0..185f15b 100644
77758--- a/include/net/ip_vs.h
77759+++ b/include/net/ip_vs.h
77760@@ -588,7 +588,7 @@ struct ip_vs_conn {
77761 struct ip_vs_conn *control; /* Master control connection */
77762 atomic_t n_control; /* Number of controlled ones */
77763 struct ip_vs_dest *dest; /* real server */
77764- atomic_t in_pkts; /* incoming packet counter */
77765+ atomic_unchecked_t in_pkts; /* incoming packet counter */
77766
77767 /* packet transmitter for different forwarding methods. If it
77768 mangles the packet, it must return NF_DROP or better NF_STOLEN,
77769@@ -737,7 +737,7 @@ struct ip_vs_dest {
77770 __be16 port; /* port number of the server */
77771 union nf_inet_addr addr; /* IP address of the server */
77772 volatile unsigned int flags; /* dest status flags */
77773- atomic_t conn_flags; /* flags to copy to conn */
77774+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
77775 atomic_t weight; /* server weight */
77776
77777 atomic_t refcnt; /* reference counter */
77778@@ -993,11 +993,11 @@ struct netns_ipvs {
77779 /* ip_vs_lblc */
77780 int sysctl_lblc_expiration;
77781 struct ctl_table_header *lblc_ctl_header;
77782- struct ctl_table *lblc_ctl_table;
77783+ ctl_table_no_const *lblc_ctl_table;
77784 /* ip_vs_lblcr */
77785 int sysctl_lblcr_expiration;
77786 struct ctl_table_header *lblcr_ctl_header;
77787- struct ctl_table *lblcr_ctl_table;
77788+ ctl_table_no_const *lblcr_ctl_table;
77789 /* ip_vs_est */
77790 struct list_head est_list; /* estimator list */
77791 spinlock_t est_lock;
77792diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
77793index 80ffde3..968b0f4 100644
77794--- a/include/net/irda/ircomm_tty.h
77795+++ b/include/net/irda/ircomm_tty.h
77796@@ -35,6 +35,7 @@
77797 #include <linux/termios.h>
77798 #include <linux/timer.h>
77799 #include <linux/tty.h> /* struct tty_struct */
77800+#include <asm/local.h>
77801
77802 #include <net/irda/irias_object.h>
77803 #include <net/irda/ircomm_core.h>
77804diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
77805index 714cc9a..ea05f3e 100644
77806--- a/include/net/iucv/af_iucv.h
77807+++ b/include/net/iucv/af_iucv.h
77808@@ -149,7 +149,7 @@ struct iucv_skb_cb {
77809 struct iucv_sock_list {
77810 struct hlist_head head;
77811 rwlock_t lock;
77812- atomic_t autobind_name;
77813+ atomic_unchecked_t autobind_name;
77814 };
77815
77816 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
77817diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
77818index df83f69..9b640b8 100644
77819--- a/include/net/llc_c_ac.h
77820+++ b/include/net/llc_c_ac.h
77821@@ -87,7 +87,7 @@
77822 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
77823 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
77824
77825-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77826+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77827
77828 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
77829 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
77830diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
77831index 6ca3113..f8026dd 100644
77832--- a/include/net/llc_c_ev.h
77833+++ b/include/net/llc_c_ev.h
77834@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
77835 return (struct llc_conn_state_ev *)skb->cb;
77836 }
77837
77838-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77839-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77840+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77841+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77842
77843 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
77844 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
77845diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
77846index 0e79cfb..f46db31 100644
77847--- a/include/net/llc_c_st.h
77848+++ b/include/net/llc_c_st.h
77849@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
77850 u8 next_state;
77851 llc_conn_ev_qfyr_t *ev_qualifiers;
77852 llc_conn_action_t *ev_actions;
77853-};
77854+} __do_const;
77855
77856 struct llc_conn_state {
77857 u8 current_state;
77858diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
77859index 37a3bbd..55a4241 100644
77860--- a/include/net/llc_s_ac.h
77861+++ b/include/net/llc_s_ac.h
77862@@ -23,7 +23,7 @@
77863 #define SAP_ACT_TEST_IND 9
77864
77865 /* All action functions must look like this */
77866-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
77867+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
77868
77869 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
77870 struct sk_buff *skb);
77871diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
77872index 567c681..cd73ac0 100644
77873--- a/include/net/llc_s_st.h
77874+++ b/include/net/llc_s_st.h
77875@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
77876 llc_sap_ev_t ev;
77877 u8 next_state;
77878 llc_sap_action_t *ev_actions;
77879-};
77880+} __do_const;
77881
77882 struct llc_sap_state {
77883 u8 curr_state;
77884diff --git a/include/net/mac80211.h b/include/net/mac80211.h
77885index 551ba6a..11c99c1 100644
77886--- a/include/net/mac80211.h
77887+++ b/include/net/mac80211.h
77888@@ -4221,7 +4221,7 @@ struct rate_control_ops {
77889 void (*add_sta_debugfs)(void *priv, void *priv_sta,
77890 struct dentry *dir);
77891 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
77892-};
77893+} __do_const;
77894
77895 static inline int rate_supported(struct ieee80211_sta *sta,
77896 enum ieee80211_band band,
77897diff --git a/include/net/neighbour.h b/include/net/neighbour.h
77898index 7e748ad..5c6229b 100644
77899--- a/include/net/neighbour.h
77900+++ b/include/net/neighbour.h
77901@@ -123,7 +123,7 @@ struct neigh_ops {
77902 void (*error_report)(struct neighbour *, struct sk_buff *);
77903 int (*output)(struct neighbour *, struct sk_buff *);
77904 int (*connected_output)(struct neighbour *, struct sk_buff *);
77905-};
77906+} __do_const;
77907
77908 struct pneigh_entry {
77909 struct pneigh_entry *next;
77910diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
77911index 84e37b1..8eba19a 100644
77912--- a/include/net/net_namespace.h
77913+++ b/include/net/net_namespace.h
77914@@ -119,8 +119,8 @@ struct net {
77915 struct netns_ipvs *ipvs;
77916 #endif
77917 struct sock *diag_nlsk;
77918- atomic_t rt_genid;
77919- atomic_t fnhe_genid;
77920+ atomic_unchecked_t rt_genid;
77921+ atomic_unchecked_t fnhe_genid;
77922 };
77923
77924 /*
77925@@ -277,7 +277,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
77926 #define __net_init __init
77927 #define __net_exit __exit_refok
77928 #define __net_initdata __initdata
77929+#ifdef CONSTIFY_PLUGIN
77930 #define __net_initconst __initconst
77931+#else
77932+#define __net_initconst __initdata
77933+#endif
77934 #endif
77935
77936 struct pernet_operations {
77937@@ -287,7 +291,7 @@ struct pernet_operations {
77938 void (*exit_batch)(struct list_head *net_exit_list);
77939 int *id;
77940 size_t size;
77941-};
77942+} __do_const;
77943
77944 /*
77945 * Use these carefully. If you implement a network device and it
77946@@ -335,22 +339,22 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
77947
77948 static inline int rt_genid(struct net *net)
77949 {
77950- return atomic_read(&net->rt_genid);
77951+ return atomic_read_unchecked(&net->rt_genid);
77952 }
77953
77954 static inline void rt_genid_bump(struct net *net)
77955 {
77956- atomic_inc(&net->rt_genid);
77957+ atomic_inc_unchecked(&net->rt_genid);
77958 }
77959
77960 static inline int fnhe_genid(struct net *net)
77961 {
77962- return atomic_read(&net->fnhe_genid);
77963+ return atomic_read_unchecked(&net->fnhe_genid);
77964 }
77965
77966 static inline void fnhe_genid_bump(struct net *net)
77967 {
77968- atomic_inc(&net->fnhe_genid);
77969+ atomic_inc_unchecked(&net->fnhe_genid);
77970 }
77971
77972 #endif /* __NET_NET_NAMESPACE_H */
77973diff --git a/include/net/netdma.h b/include/net/netdma.h
77974index 8ba8ce2..99b7fff 100644
77975--- a/include/net/netdma.h
77976+++ b/include/net/netdma.h
77977@@ -24,7 +24,7 @@
77978 #include <linux/dmaengine.h>
77979 #include <linux/skbuff.h>
77980
77981-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
77982+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
77983 struct sk_buff *skb, int offset, struct iovec *to,
77984 size_t len, struct dma_pinned_list *pinned_list);
77985
77986diff --git a/include/net/netlink.h b/include/net/netlink.h
77987index 9690b0f..87aded7 100644
77988--- a/include/net/netlink.h
77989+++ b/include/net/netlink.h
77990@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
77991 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
77992 {
77993 if (mark)
77994- skb_trim(skb, (unsigned char *) mark - skb->data);
77995+ skb_trim(skb, (const unsigned char *) mark - skb->data);
77996 }
77997
77998 /**
77999diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
78000index c9c0c53..53f24c3 100644
78001--- a/include/net/netns/conntrack.h
78002+++ b/include/net/netns/conntrack.h
78003@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
78004 struct nf_proto_net {
78005 #ifdef CONFIG_SYSCTL
78006 struct ctl_table_header *ctl_table_header;
78007- struct ctl_table *ctl_table;
78008+ ctl_table_no_const *ctl_table;
78009 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
78010 struct ctl_table_header *ctl_compat_header;
78011- struct ctl_table *ctl_compat_table;
78012+ ctl_table_no_const *ctl_compat_table;
78013 #endif
78014 #endif
78015 unsigned int users;
78016@@ -58,7 +58,7 @@ struct nf_ip_net {
78017 struct nf_icmp_net icmpv6;
78018 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
78019 struct ctl_table_header *ctl_table_header;
78020- struct ctl_table *ctl_table;
78021+ ctl_table_no_const *ctl_table;
78022 #endif
78023 };
78024
78025diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
78026index 2ba9de8..47bd6c7 100644
78027--- a/include/net/netns/ipv4.h
78028+++ b/include/net/netns/ipv4.h
78029@@ -67,7 +67,7 @@ struct netns_ipv4 {
78030 kgid_t sysctl_ping_group_range[2];
78031 long sysctl_tcp_mem[3];
78032
78033- atomic_t dev_addr_genid;
78034+ atomic_unchecked_t dev_addr_genid;
78035
78036 #ifdef CONFIG_IP_MROUTE
78037 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
78038diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
78039index 005e2c2..023d340 100644
78040--- a/include/net/netns/ipv6.h
78041+++ b/include/net/netns/ipv6.h
78042@@ -71,7 +71,7 @@ struct netns_ipv6 {
78043 struct fib_rules_ops *mr6_rules_ops;
78044 #endif
78045 #endif
78046- atomic_t dev_addr_genid;
78047+ atomic_unchecked_t dev_addr_genid;
78048 };
78049
78050 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
78051diff --git a/include/net/ping.h b/include/net/ping.h
78052index 5db0224..0d65365 100644
78053--- a/include/net/ping.h
78054+++ b/include/net/ping.h
78055@@ -55,7 +55,7 @@ struct ping_iter_state {
78056 extern struct proto ping_prot;
78057 extern struct ping_table ping_table;
78058 #if IS_ENABLED(CONFIG_IPV6)
78059-extern struct pingv6_ops pingv6_ops;
78060+extern struct pingv6_ops *pingv6_ops;
78061 #endif
78062
78063 struct pingfakehdr {
78064diff --git a/include/net/protocol.h b/include/net/protocol.h
78065index 047c047..b9dad15 100644
78066--- a/include/net/protocol.h
78067+++ b/include/net/protocol.h
78068@@ -44,7 +44,7 @@ struct net_protocol {
78069 void (*err_handler)(struct sk_buff *skb, u32 info);
78070 unsigned int no_policy:1,
78071 netns_ok:1;
78072-};
78073+} __do_const;
78074
78075 #if IS_ENABLED(CONFIG_IPV6)
78076 struct inet6_protocol {
78077@@ -57,7 +57,7 @@ struct inet6_protocol {
78078 u8 type, u8 code, int offset,
78079 __be32 info);
78080 unsigned int flags; /* INET6_PROTO_xxx */
78081-};
78082+} __do_const;
78083
78084 #define INET6_PROTO_NOPOLICY 0x1
78085 #define INET6_PROTO_FINAL 0x2
78086diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
78087index 7026648..584cc8c 100644
78088--- a/include/net/rtnetlink.h
78089+++ b/include/net/rtnetlink.h
78090@@ -81,7 +81,7 @@ struct rtnl_link_ops {
78091 const struct net_device *dev);
78092 unsigned int (*get_num_tx_queues)(void);
78093 unsigned int (*get_num_rx_queues)(void);
78094-};
78095+} __do_const;
78096
78097 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
78098 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
78099diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
78100index 2a82d13..62a31c2 100644
78101--- a/include/net/sctp/sm.h
78102+++ b/include/net/sctp/sm.h
78103@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
78104 typedef struct {
78105 sctp_state_fn_t *fn;
78106 const char *name;
78107-} sctp_sm_table_entry_t;
78108+} __do_const sctp_sm_table_entry_t;
78109
78110 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
78111 * currently in use.
78112@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
78113 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
78114
78115 /* Extern declarations for major data structures. */
78116-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
78117+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
78118
78119
78120 /* Get the size of a DATA chunk payload. */
78121diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
78122index e745c92..3641448 100644
78123--- a/include/net/sctp/structs.h
78124+++ b/include/net/sctp/structs.h
78125@@ -516,7 +516,7 @@ struct sctp_pf {
78126 struct sctp_association *asoc);
78127 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
78128 struct sctp_af *af;
78129-};
78130+} __do_const;
78131
78132
78133 /* Structure to track chunk fragments that have been acked, but peer
78134diff --git a/include/net/sock.h b/include/net/sock.h
78135index 31d5cfb..9ee0602 100644
78136--- a/include/net/sock.h
78137+++ b/include/net/sock.h
78138@@ -331,7 +331,7 @@ struct sock {
78139 unsigned int sk_napi_id;
78140 unsigned int sk_ll_usec;
78141 #endif
78142- atomic_t sk_drops;
78143+ atomic_unchecked_t sk_drops;
78144 int sk_rcvbuf;
78145
78146 struct sk_filter __rcu *sk_filter;
78147@@ -1803,7 +1803,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
78148 }
78149
78150 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
78151- char __user *from, char *to,
78152+ char __user *from, unsigned char *to,
78153 int copy, int offset)
78154 {
78155 if (skb->ip_summed == CHECKSUM_NONE) {
78156@@ -2065,7 +2065,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
78157 }
78158 }
78159
78160-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
78161+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
78162
78163 /**
78164 * sk_page_frag - return an appropriate page_frag
78165diff --git a/include/net/tcp.h b/include/net/tcp.h
78166index d198005..c974a393 100644
78167--- a/include/net/tcp.h
78168+++ b/include/net/tcp.h
78169@@ -521,7 +521,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
78170 extern void tcp_xmit_retransmit_queue(struct sock *);
78171 extern void tcp_simple_retransmit(struct sock *);
78172 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
78173-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
78174+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
78175
78176 extern void tcp_send_probe0(struct sock *);
78177 extern void tcp_send_partial(struct sock *);
78178@@ -694,8 +694,8 @@ struct tcp_skb_cb {
78179 struct inet6_skb_parm h6;
78180 #endif
78181 } header; /* For incoming frames */
78182- __u32 seq; /* Starting sequence number */
78183- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
78184+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
78185+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
78186 __u32 when; /* used to compute rtt's */
78187 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
78188
78189@@ -709,7 +709,7 @@ struct tcp_skb_cb {
78190
78191 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
78192 /* 1 byte hole */
78193- __u32 ack_seq; /* Sequence number ACK'd */
78194+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
78195 };
78196
78197 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
78198diff --git a/include/net/xfrm.h b/include/net/xfrm.h
78199index e823786..55bf641 100644
78200--- a/include/net/xfrm.h
78201+++ b/include/net/xfrm.h
78202@@ -305,7 +305,7 @@ struct xfrm_policy_afinfo {
78203 struct net_device *dev,
78204 const struct flowi *fl);
78205 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
78206-};
78207+} __do_const;
78208
78209 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
78210 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
78211@@ -342,7 +342,7 @@ struct xfrm_state_afinfo {
78212 int (*transport_finish)(struct sk_buff *skb,
78213 int async);
78214 void (*local_error)(struct sk_buff *skb, u32 mtu);
78215-};
78216+} __do_const;
78217
78218 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
78219 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
78220@@ -427,7 +427,7 @@ struct xfrm_mode {
78221 struct module *owner;
78222 unsigned int encap;
78223 int flags;
78224-};
78225+} __do_const;
78226
78227 /* Flags for xfrm_mode. */
78228 enum {
78229@@ -524,7 +524,7 @@ struct xfrm_policy {
78230 struct timer_list timer;
78231
78232 struct flow_cache_object flo;
78233- atomic_t genid;
78234+ atomic_unchecked_t genid;
78235 u32 priority;
78236 u32 index;
78237 struct xfrm_mark mark;
78238diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
78239index 1a046b1..ee0bef0 100644
78240--- a/include/rdma/iw_cm.h
78241+++ b/include/rdma/iw_cm.h
78242@@ -122,7 +122,7 @@ struct iw_cm_verbs {
78243 int backlog);
78244
78245 int (*destroy_listen)(struct iw_cm_id *cm_id);
78246-};
78247+} __no_const;
78248
78249 /**
78250 * iw_create_cm_id - Create an IW CM identifier.
78251diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
78252index e1379b4..67eafbe 100644
78253--- a/include/scsi/libfc.h
78254+++ b/include/scsi/libfc.h
78255@@ -762,6 +762,7 @@ struct libfc_function_template {
78256 */
78257 void (*disc_stop_final) (struct fc_lport *);
78258 };
78259+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
78260
78261 /**
78262 * struct fc_disc - Discovery context
78263@@ -866,7 +867,7 @@ struct fc_lport {
78264 struct fc_vport *vport;
78265
78266 /* Operational Information */
78267- struct libfc_function_template tt;
78268+ libfc_function_template_no_const tt;
78269 u8 link_up;
78270 u8 qfull;
78271 enum fc_lport_state state;
78272diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
78273index a44954c..5da04b2 100644
78274--- a/include/scsi/scsi_device.h
78275+++ b/include/scsi/scsi_device.h
78276@@ -172,9 +172,9 @@ struct scsi_device {
78277 unsigned int max_device_blocked; /* what device_blocked counts down from */
78278 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
78279
78280- atomic_t iorequest_cnt;
78281- atomic_t iodone_cnt;
78282- atomic_t ioerr_cnt;
78283+ atomic_unchecked_t iorequest_cnt;
78284+ atomic_unchecked_t iodone_cnt;
78285+ atomic_unchecked_t ioerr_cnt;
78286
78287 struct device sdev_gendev,
78288 sdev_dev;
78289diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
78290index b797e8f..8e2c3aa 100644
78291--- a/include/scsi/scsi_transport_fc.h
78292+++ b/include/scsi/scsi_transport_fc.h
78293@@ -751,7 +751,8 @@ struct fc_function_template {
78294 unsigned long show_host_system_hostname:1;
78295
78296 unsigned long disable_target_scan:1;
78297-};
78298+} __do_const;
78299+typedef struct fc_function_template __no_const fc_function_template_no_const;
78300
78301
78302 /**
78303diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
78304index 9031a26..750d592 100644
78305--- a/include/sound/compress_driver.h
78306+++ b/include/sound/compress_driver.h
78307@@ -128,7 +128,7 @@ struct snd_compr_ops {
78308 struct snd_compr_caps *caps);
78309 int (*get_codec_caps) (struct snd_compr_stream *stream,
78310 struct snd_compr_codec_caps *codec);
78311-};
78312+} __no_const;
78313
78314 /**
78315 * struct snd_compr: Compressed device
78316diff --git a/include/sound/soc.h b/include/sound/soc.h
78317index 6eabee7..58afb50 100644
78318--- a/include/sound/soc.h
78319+++ b/include/sound/soc.h
78320@@ -783,7 +783,7 @@ struct snd_soc_codec_driver {
78321 /* probe ordering - for components with runtime dependencies */
78322 int probe_order;
78323 int remove_order;
78324-};
78325+} __do_const;
78326
78327 /* SoC platform interface */
78328 struct snd_soc_platform_driver {
78329@@ -829,7 +829,7 @@ struct snd_soc_platform_driver {
78330 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
78331 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
78332 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
78333-};
78334+} __do_const;
78335
78336 struct snd_soc_platform {
78337 const char *name;
78338diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
78339index e34fc90..ecefa2c 100644
78340--- a/include/target/target_core_base.h
78341+++ b/include/target/target_core_base.h
78342@@ -643,7 +643,7 @@ struct se_device {
78343 spinlock_t stats_lock;
78344 /* Active commands on this virtual SE device */
78345 atomic_t simple_cmds;
78346- atomic_t dev_ordered_id;
78347+ atomic_unchecked_t dev_ordered_id;
78348 atomic_t dev_ordered_sync;
78349 atomic_t dev_qf_count;
78350 int export_count;
78351diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
78352new file mode 100644
78353index 0000000..fb634b7
78354--- /dev/null
78355+++ b/include/trace/events/fs.h
78356@@ -0,0 +1,53 @@
78357+#undef TRACE_SYSTEM
78358+#define TRACE_SYSTEM fs
78359+
78360+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
78361+#define _TRACE_FS_H
78362+
78363+#include <linux/fs.h>
78364+#include <linux/tracepoint.h>
78365+
78366+TRACE_EVENT(do_sys_open,
78367+
78368+ TP_PROTO(const char *filename, int flags, int mode),
78369+
78370+ TP_ARGS(filename, flags, mode),
78371+
78372+ TP_STRUCT__entry(
78373+ __string( filename, filename )
78374+ __field( int, flags )
78375+ __field( int, mode )
78376+ ),
78377+
78378+ TP_fast_assign(
78379+ __assign_str(filename, filename);
78380+ __entry->flags = flags;
78381+ __entry->mode = mode;
78382+ ),
78383+
78384+ TP_printk("\"%s\" %x %o",
78385+ __get_str(filename), __entry->flags, __entry->mode)
78386+);
78387+
78388+TRACE_EVENT(open_exec,
78389+
78390+ TP_PROTO(const char *filename),
78391+
78392+ TP_ARGS(filename),
78393+
78394+ TP_STRUCT__entry(
78395+ __string( filename, filename )
78396+ ),
78397+
78398+ TP_fast_assign(
78399+ __assign_str(filename, filename);
78400+ ),
78401+
78402+ TP_printk("\"%s\"",
78403+ __get_str(filename))
78404+);
78405+
78406+#endif /* _TRACE_FS_H */
78407+
78408+/* This part must be outside protection */
78409+#include <trace/define_trace.h>
78410diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
78411index 1c09820..7f5ec79 100644
78412--- a/include/trace/events/irq.h
78413+++ b/include/trace/events/irq.h
78414@@ -36,7 +36,7 @@ struct softirq_action;
78415 */
78416 TRACE_EVENT(irq_handler_entry,
78417
78418- TP_PROTO(int irq, struct irqaction *action),
78419+ TP_PROTO(int irq, const struct irqaction *action),
78420
78421 TP_ARGS(irq, action),
78422
78423@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
78424 */
78425 TRACE_EVENT(irq_handler_exit,
78426
78427- TP_PROTO(int irq, struct irqaction *action, int ret),
78428+ TP_PROTO(int irq, const struct irqaction *action, int ret),
78429
78430 TP_ARGS(irq, action, ret),
78431
78432diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
78433index 7caf44c..23c6f27 100644
78434--- a/include/uapi/linux/a.out.h
78435+++ b/include/uapi/linux/a.out.h
78436@@ -39,6 +39,14 @@ enum machine_type {
78437 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
78438 };
78439
78440+/* Constants for the N_FLAGS field */
78441+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78442+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
78443+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
78444+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
78445+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78446+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78447+
78448 #if !defined (N_MAGIC)
78449 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
78450 #endif
78451diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
78452index d876736..ccce5c0 100644
78453--- a/include/uapi/linux/byteorder/little_endian.h
78454+++ b/include/uapi/linux/byteorder/little_endian.h
78455@@ -42,51 +42,51 @@
78456
78457 static inline __le64 __cpu_to_le64p(const __u64 *p)
78458 {
78459- return (__force __le64)*p;
78460+ return (__force const __le64)*p;
78461 }
78462-static inline __u64 __le64_to_cpup(const __le64 *p)
78463+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
78464 {
78465- return (__force __u64)*p;
78466+ return (__force const __u64)*p;
78467 }
78468 static inline __le32 __cpu_to_le32p(const __u32 *p)
78469 {
78470- return (__force __le32)*p;
78471+ return (__force const __le32)*p;
78472 }
78473 static inline __u32 __le32_to_cpup(const __le32 *p)
78474 {
78475- return (__force __u32)*p;
78476+ return (__force const __u32)*p;
78477 }
78478 static inline __le16 __cpu_to_le16p(const __u16 *p)
78479 {
78480- return (__force __le16)*p;
78481+ return (__force const __le16)*p;
78482 }
78483 static inline __u16 __le16_to_cpup(const __le16 *p)
78484 {
78485- return (__force __u16)*p;
78486+ return (__force const __u16)*p;
78487 }
78488 static inline __be64 __cpu_to_be64p(const __u64 *p)
78489 {
78490- return (__force __be64)__swab64p(p);
78491+ return (__force const __be64)__swab64p(p);
78492 }
78493 static inline __u64 __be64_to_cpup(const __be64 *p)
78494 {
78495- return __swab64p((__u64 *)p);
78496+ return __swab64p((const __u64 *)p);
78497 }
78498 static inline __be32 __cpu_to_be32p(const __u32 *p)
78499 {
78500- return (__force __be32)__swab32p(p);
78501+ return (__force const __be32)__swab32p(p);
78502 }
78503-static inline __u32 __be32_to_cpup(const __be32 *p)
78504+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
78505 {
78506- return __swab32p((__u32 *)p);
78507+ return __swab32p((const __u32 *)p);
78508 }
78509 static inline __be16 __cpu_to_be16p(const __u16 *p)
78510 {
78511- return (__force __be16)__swab16p(p);
78512+ return (__force const __be16)__swab16p(p);
78513 }
78514 static inline __u16 __be16_to_cpup(const __be16 *p)
78515 {
78516- return __swab16p((__u16 *)p);
78517+ return __swab16p((const __u16 *)p);
78518 }
78519 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
78520 #define __le64_to_cpus(x) do { (void)(x); } while (0)
78521diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
78522index ef6103b..d4e65dd 100644
78523--- a/include/uapi/linux/elf.h
78524+++ b/include/uapi/linux/elf.h
78525@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
78526 #define PT_GNU_EH_FRAME 0x6474e550
78527
78528 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
78529+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
78530+
78531+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
78532+
78533+/* Constants for the e_flags field */
78534+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78535+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
78536+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
78537+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
78538+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78539+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78540
78541 /*
78542 * Extended Numbering
78543@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
78544 #define DT_DEBUG 21
78545 #define DT_TEXTREL 22
78546 #define DT_JMPREL 23
78547+#define DT_FLAGS 30
78548+ #define DF_TEXTREL 0x00000004
78549 #define DT_ENCODING 32
78550 #define OLD_DT_LOOS 0x60000000
78551 #define DT_LOOS 0x6000000d
78552@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
78553 #define PF_W 0x2
78554 #define PF_X 0x1
78555
78556+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
78557+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
78558+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
78559+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
78560+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
78561+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
78562+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
78563+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
78564+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
78565+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
78566+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
78567+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
78568+
78569 typedef struct elf32_phdr{
78570 Elf32_Word p_type;
78571 Elf32_Off p_offset;
78572@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
78573 #define EI_OSABI 7
78574 #define EI_PAD 8
78575
78576+#define EI_PAX 14
78577+
78578 #define ELFMAG0 0x7f /* EI_MAG */
78579 #define ELFMAG1 'E'
78580 #define ELFMAG2 'L'
78581diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
78582index aa169c4..6a2771d 100644
78583--- a/include/uapi/linux/personality.h
78584+++ b/include/uapi/linux/personality.h
78585@@ -30,6 +30,7 @@ enum {
78586 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
78587 ADDR_NO_RANDOMIZE | \
78588 ADDR_COMPAT_LAYOUT | \
78589+ ADDR_LIMIT_3GB | \
78590 MMAP_PAGE_ZERO)
78591
78592 /*
78593diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
78594index 7530e74..e714828 100644
78595--- a/include/uapi/linux/screen_info.h
78596+++ b/include/uapi/linux/screen_info.h
78597@@ -43,7 +43,8 @@ struct screen_info {
78598 __u16 pages; /* 0x32 */
78599 __u16 vesa_attributes; /* 0x34 */
78600 __u32 capabilities; /* 0x36 */
78601- __u8 _reserved[6]; /* 0x3a */
78602+ __u16 vesapm_size; /* 0x3a */
78603+ __u8 _reserved[4]; /* 0x3c */
78604 } __attribute__((packed));
78605
78606 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
78607diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
78608index 0e011eb..82681b1 100644
78609--- a/include/uapi/linux/swab.h
78610+++ b/include/uapi/linux/swab.h
78611@@ -43,7 +43,7 @@
78612 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
78613 */
78614
78615-static inline __attribute_const__ __u16 __fswab16(__u16 val)
78616+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
78617 {
78618 #ifdef __HAVE_BUILTIN_BSWAP16__
78619 return __builtin_bswap16(val);
78620@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
78621 #endif
78622 }
78623
78624-static inline __attribute_const__ __u32 __fswab32(__u32 val)
78625+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
78626 {
78627 #ifdef __HAVE_BUILTIN_BSWAP32__
78628 return __builtin_bswap32(val);
78629@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
78630 #endif
78631 }
78632
78633-static inline __attribute_const__ __u64 __fswab64(__u64 val)
78634+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
78635 {
78636 #ifdef __HAVE_BUILTIN_BSWAP64__
78637 return __builtin_bswap64(val);
78638diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
78639index 6d67213..8dab561 100644
78640--- a/include/uapi/linux/sysctl.h
78641+++ b/include/uapi/linux/sysctl.h
78642@@ -155,7 +155,11 @@ enum
78643 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
78644 };
78645
78646-
78647+#ifdef CONFIG_PAX_SOFTMODE
78648+enum {
78649+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
78650+};
78651+#endif
78652
78653 /* CTL_VM names: */
78654 enum
78655diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
78656index e4629b9..6958086 100644
78657--- a/include/uapi/linux/xattr.h
78658+++ b/include/uapi/linux/xattr.h
78659@@ -63,5 +63,9 @@
78660 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
78661 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
78662
78663+/* User namespace */
78664+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
78665+#define XATTR_PAX_FLAGS_SUFFIX "flags"
78666+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
78667
78668 #endif /* _UAPI_LINUX_XATTR_H */
78669diff --git a/include/video/udlfb.h b/include/video/udlfb.h
78670index f9466fa..f4e2b81 100644
78671--- a/include/video/udlfb.h
78672+++ b/include/video/udlfb.h
78673@@ -53,10 +53,10 @@ struct dlfb_data {
78674 u32 pseudo_palette[256];
78675 int blank_mode; /*one of FB_BLANK_ */
78676 /* blit-only rendering path metrics, exposed through sysfs */
78677- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78678- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
78679- atomic_t bytes_sent; /* to usb, after compression including overhead */
78680- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
78681+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78682+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
78683+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
78684+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
78685 };
78686
78687 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
78688diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
78689index 30f5362..8ed8ac9 100644
78690--- a/include/video/uvesafb.h
78691+++ b/include/video/uvesafb.h
78692@@ -122,6 +122,7 @@ struct uvesafb_par {
78693 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
78694 u8 pmi_setpal; /* PMI for palette changes */
78695 u16 *pmi_base; /* protected mode interface location */
78696+ u8 *pmi_code; /* protected mode code location */
78697 void *pmi_start;
78698 void *pmi_pal;
78699 u8 *vbe_state_orig; /*
78700diff --git a/init/Kconfig b/init/Kconfig
78701index fed81b5..0d3b964 100644
78702--- a/init/Kconfig
78703+++ b/init/Kconfig
78704@@ -1069,6 +1069,7 @@ endif # CGROUPS
78705
78706 config CHECKPOINT_RESTORE
78707 bool "Checkpoint/restore support" if EXPERT
78708+ depends on !GRKERNSEC
78709 default n
78710 help
78711 Enables additional kernel features in a sake of checkpoint/restore.
78712@@ -1553,7 +1554,7 @@ config SLUB_DEBUG
78713
78714 config COMPAT_BRK
78715 bool "Disable heap randomization"
78716- default y
78717+ default n
78718 help
78719 Randomizing heap placement makes heap exploits harder, but it
78720 also breaks ancient binaries (including anything libc5 based).
78721@@ -1827,7 +1828,7 @@ config INIT_ALL_POSSIBLE
78722 config STOP_MACHINE
78723 bool
78724 default y
78725- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
78726+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
78727 help
78728 Need stop_machine() primitive.
78729
78730diff --git a/init/Makefile b/init/Makefile
78731index 7bc47ee..6da2dc7 100644
78732--- a/init/Makefile
78733+++ b/init/Makefile
78734@@ -2,6 +2,9 @@
78735 # Makefile for the linux kernel.
78736 #
78737
78738+ccflags-y := $(GCC_PLUGINS_CFLAGS)
78739+asflags-y := $(GCC_PLUGINS_AFLAGS)
78740+
78741 obj-y := main.o version.o mounts.o
78742 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
78743 obj-y += noinitramfs.o
78744diff --git a/init/do_mounts.c b/init/do_mounts.c
78745index 816014c..c2054db 100644
78746--- a/init/do_mounts.c
78747+++ b/init/do_mounts.c
78748@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
78749 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
78750 {
78751 struct super_block *s;
78752- int err = sys_mount(name, "/root", fs, flags, data);
78753+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
78754 if (err)
78755 return err;
78756
78757- sys_chdir("/root");
78758+ sys_chdir((const char __force_user *)"/root");
78759 s = current->fs->pwd.dentry->d_sb;
78760 ROOT_DEV = s->s_dev;
78761 printk(KERN_INFO
78762@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
78763 va_start(args, fmt);
78764 vsprintf(buf, fmt, args);
78765 va_end(args);
78766- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
78767+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
78768 if (fd >= 0) {
78769 sys_ioctl(fd, FDEJECT, 0);
78770 sys_close(fd);
78771 }
78772 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
78773- fd = sys_open("/dev/console", O_RDWR, 0);
78774+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
78775 if (fd >= 0) {
78776 sys_ioctl(fd, TCGETS, (long)&termios);
78777 termios.c_lflag &= ~ICANON;
78778 sys_ioctl(fd, TCSETSF, (long)&termios);
78779- sys_read(fd, &c, 1);
78780+ sys_read(fd, (char __user *)&c, 1);
78781 termios.c_lflag |= ICANON;
78782 sys_ioctl(fd, TCSETSF, (long)&termios);
78783 sys_close(fd);
78784@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
78785 mount_root();
78786 out:
78787 devtmpfs_mount("dev");
78788- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78789- sys_chroot(".");
78790+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78791+ sys_chroot((const char __force_user *)".");
78792 }
78793diff --git a/init/do_mounts.h b/init/do_mounts.h
78794index f5b978a..69dbfe8 100644
78795--- a/init/do_mounts.h
78796+++ b/init/do_mounts.h
78797@@ -15,15 +15,15 @@ extern int root_mountflags;
78798
78799 static inline int create_dev(char *name, dev_t dev)
78800 {
78801- sys_unlink(name);
78802- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
78803+ sys_unlink((char __force_user *)name);
78804+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
78805 }
78806
78807 #if BITS_PER_LONG == 32
78808 static inline u32 bstat(char *name)
78809 {
78810 struct stat64 stat;
78811- if (sys_stat64(name, &stat) != 0)
78812+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
78813 return 0;
78814 if (!S_ISBLK(stat.st_mode))
78815 return 0;
78816@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
78817 static inline u32 bstat(char *name)
78818 {
78819 struct stat stat;
78820- if (sys_newstat(name, &stat) != 0)
78821+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
78822 return 0;
78823 if (!S_ISBLK(stat.st_mode))
78824 return 0;
78825diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
78826index 3e0878e..8a9d7a0 100644
78827--- a/init/do_mounts_initrd.c
78828+++ b/init/do_mounts_initrd.c
78829@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
78830 {
78831 sys_unshare(CLONE_FS | CLONE_FILES);
78832 /* stdin/stdout/stderr for /linuxrc */
78833- sys_open("/dev/console", O_RDWR, 0);
78834+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
78835 sys_dup(0);
78836 sys_dup(0);
78837 /* move initrd over / and chdir/chroot in initrd root */
78838- sys_chdir("/root");
78839- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78840- sys_chroot(".");
78841+ sys_chdir((const char __force_user *)"/root");
78842+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78843+ sys_chroot((const char __force_user *)".");
78844 sys_setsid();
78845 return 0;
78846 }
78847@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
78848 create_dev("/dev/root.old", Root_RAM0);
78849 /* mount initrd on rootfs' /root */
78850 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
78851- sys_mkdir("/old", 0700);
78852- sys_chdir("/old");
78853+ sys_mkdir((const char __force_user *)"/old", 0700);
78854+ sys_chdir((const char __force_user *)"/old");
78855
78856 /* try loading default modules from initrd */
78857 load_default_modules();
78858@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
78859 current->flags &= ~PF_FREEZER_SKIP;
78860
78861 /* move initrd to rootfs' /old */
78862- sys_mount("..", ".", NULL, MS_MOVE, NULL);
78863+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
78864 /* switch root and cwd back to / of rootfs */
78865- sys_chroot("..");
78866+ sys_chroot((const char __force_user *)"..");
78867
78868 if (new_decode_dev(real_root_dev) == Root_RAM0) {
78869- sys_chdir("/old");
78870+ sys_chdir((const char __force_user *)"/old");
78871 return;
78872 }
78873
78874- sys_chdir("/");
78875+ sys_chdir((const char __force_user *)"/");
78876 ROOT_DEV = new_decode_dev(real_root_dev);
78877 mount_root();
78878
78879 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
78880- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
78881+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
78882 if (!error)
78883 printk("okay\n");
78884 else {
78885- int fd = sys_open("/dev/root.old", O_RDWR, 0);
78886+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
78887 if (error == -ENOENT)
78888 printk("/initrd does not exist. Ignored.\n");
78889 else
78890 printk("failed\n");
78891 printk(KERN_NOTICE "Unmounting old root\n");
78892- sys_umount("/old", MNT_DETACH);
78893+ sys_umount((char __force_user *)"/old", MNT_DETACH);
78894 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
78895 if (fd < 0) {
78896 error = fd;
78897@@ -127,11 +127,11 @@ int __init initrd_load(void)
78898 * mounted in the normal path.
78899 */
78900 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
78901- sys_unlink("/initrd.image");
78902+ sys_unlink((const char __force_user *)"/initrd.image");
78903 handle_initrd();
78904 return 1;
78905 }
78906 }
78907- sys_unlink("/initrd.image");
78908+ sys_unlink((const char __force_user *)"/initrd.image");
78909 return 0;
78910 }
78911diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
78912index 8cb6db5..d729f50 100644
78913--- a/init/do_mounts_md.c
78914+++ b/init/do_mounts_md.c
78915@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
78916 partitioned ? "_d" : "", minor,
78917 md_setup_args[ent].device_names);
78918
78919- fd = sys_open(name, 0, 0);
78920+ fd = sys_open((char __force_user *)name, 0, 0);
78921 if (fd < 0) {
78922 printk(KERN_ERR "md: open failed - cannot start "
78923 "array %s\n", name);
78924@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
78925 * array without it
78926 */
78927 sys_close(fd);
78928- fd = sys_open(name, 0, 0);
78929+ fd = sys_open((char __force_user *)name, 0, 0);
78930 sys_ioctl(fd, BLKRRPART, 0);
78931 }
78932 sys_close(fd);
78933@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
78934
78935 wait_for_device_probe();
78936
78937- fd = sys_open("/dev/md0", 0, 0);
78938+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
78939 if (fd >= 0) {
78940 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
78941 sys_close(fd);
78942diff --git a/init/init_task.c b/init/init_task.c
78943index ba0a7f36..2bcf1d5 100644
78944--- a/init/init_task.c
78945+++ b/init/init_task.c
78946@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
78947 * Initial thread structure. Alignment of this is handled by a special
78948 * linker map entry.
78949 */
78950+#ifdef CONFIG_X86
78951+union thread_union init_thread_union __init_task_data;
78952+#else
78953 union thread_union init_thread_union __init_task_data =
78954 { INIT_THREAD_INFO(init_task) };
78955+#endif
78956diff --git a/init/initramfs.c b/init/initramfs.c
78957index a67ef9d..2d17ed9 100644
78958--- a/init/initramfs.c
78959+++ b/init/initramfs.c
78960@@ -84,7 +84,7 @@ static void __init free_hash(void)
78961 }
78962 }
78963
78964-static long __init do_utime(char *filename, time_t mtime)
78965+static long __init do_utime(char __force_user *filename, time_t mtime)
78966 {
78967 struct timespec t[2];
78968
78969@@ -119,7 +119,7 @@ static void __init dir_utime(void)
78970 struct dir_entry *de, *tmp;
78971 list_for_each_entry_safe(de, tmp, &dir_list, list) {
78972 list_del(&de->list);
78973- do_utime(de->name, de->mtime);
78974+ do_utime((char __force_user *)de->name, de->mtime);
78975 kfree(de->name);
78976 kfree(de);
78977 }
78978@@ -281,7 +281,7 @@ static int __init maybe_link(void)
78979 if (nlink >= 2) {
78980 char *old = find_link(major, minor, ino, mode, collected);
78981 if (old)
78982- return (sys_link(old, collected) < 0) ? -1 : 1;
78983+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
78984 }
78985 return 0;
78986 }
78987@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
78988 {
78989 struct stat st;
78990
78991- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
78992+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
78993 if (S_ISDIR(st.st_mode))
78994- sys_rmdir(path);
78995+ sys_rmdir((char __force_user *)path);
78996 else
78997- sys_unlink(path);
78998+ sys_unlink((char __force_user *)path);
78999 }
79000 }
79001
79002@@ -315,7 +315,7 @@ static int __init do_name(void)
79003 int openflags = O_WRONLY|O_CREAT;
79004 if (ml != 1)
79005 openflags |= O_TRUNC;
79006- wfd = sys_open(collected, openflags, mode);
79007+ wfd = sys_open((char __force_user *)collected, openflags, mode);
79008
79009 if (wfd >= 0) {
79010 sys_fchown(wfd, uid, gid);
79011@@ -327,17 +327,17 @@ static int __init do_name(void)
79012 }
79013 }
79014 } else if (S_ISDIR(mode)) {
79015- sys_mkdir(collected, mode);
79016- sys_chown(collected, uid, gid);
79017- sys_chmod(collected, mode);
79018+ sys_mkdir((char __force_user *)collected, mode);
79019+ sys_chown((char __force_user *)collected, uid, gid);
79020+ sys_chmod((char __force_user *)collected, mode);
79021 dir_add(collected, mtime);
79022 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
79023 S_ISFIFO(mode) || S_ISSOCK(mode)) {
79024 if (maybe_link() == 0) {
79025- sys_mknod(collected, mode, rdev);
79026- sys_chown(collected, uid, gid);
79027- sys_chmod(collected, mode);
79028- do_utime(collected, mtime);
79029+ sys_mknod((char __force_user *)collected, mode, rdev);
79030+ sys_chown((char __force_user *)collected, uid, gid);
79031+ sys_chmod((char __force_user *)collected, mode);
79032+ do_utime((char __force_user *)collected, mtime);
79033 }
79034 }
79035 return 0;
79036@@ -346,15 +346,15 @@ static int __init do_name(void)
79037 static int __init do_copy(void)
79038 {
79039 if (count >= body_len) {
79040- sys_write(wfd, victim, body_len);
79041+ sys_write(wfd, (char __force_user *)victim, body_len);
79042 sys_close(wfd);
79043- do_utime(vcollected, mtime);
79044+ do_utime((char __force_user *)vcollected, mtime);
79045 kfree(vcollected);
79046 eat(body_len);
79047 state = SkipIt;
79048 return 0;
79049 } else {
79050- sys_write(wfd, victim, count);
79051+ sys_write(wfd, (char __force_user *)victim, count);
79052 body_len -= count;
79053 eat(count);
79054 return 1;
79055@@ -365,9 +365,9 @@ static int __init do_symlink(void)
79056 {
79057 collected[N_ALIGN(name_len) + body_len] = '\0';
79058 clean_path(collected, 0);
79059- sys_symlink(collected + N_ALIGN(name_len), collected);
79060- sys_lchown(collected, uid, gid);
79061- do_utime(collected, mtime);
79062+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
79063+ sys_lchown((char __force_user *)collected, uid, gid);
79064+ do_utime((char __force_user *)collected, mtime);
79065 state = SkipIt;
79066 next_state = Reset;
79067 return 0;
79068@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
79069 {
79070 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
79071 if (err)
79072- panic(err); /* Failed to decompress INTERNAL initramfs */
79073+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
79074 if (initrd_start) {
79075 #ifdef CONFIG_BLK_DEV_RAM
79076 int fd;
79077diff --git a/init/main.c b/init/main.c
79078index d03d2ec..665fac3 100644
79079--- a/init/main.c
79080+++ b/init/main.c
79081@@ -101,6 +101,8 @@ static inline void mark_rodata_ro(void) { }
79082 extern void tc_init(void);
79083 #endif
79084
79085+extern void grsecurity_init(void);
79086+
79087 /*
79088 * Debug helper: via this flag we know that we are in 'early bootup code'
79089 * where only the boot processor is running with IRQ disabled. This means
79090@@ -154,6 +156,74 @@ static int __init set_reset_devices(char *str)
79091
79092 __setup("reset_devices", set_reset_devices);
79093
79094+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79095+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
79096+static int __init setup_grsec_proc_gid(char *str)
79097+{
79098+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
79099+ return 1;
79100+}
79101+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
79102+#endif
79103+
79104+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
79105+unsigned long pax_user_shadow_base __read_only;
79106+EXPORT_SYMBOL(pax_user_shadow_base);
79107+extern char pax_enter_kernel_user[];
79108+extern char pax_exit_kernel_user[];
79109+#endif
79110+
79111+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
79112+static int __init setup_pax_nouderef(char *str)
79113+{
79114+#ifdef CONFIG_X86_32
79115+ unsigned int cpu;
79116+ struct desc_struct *gdt;
79117+
79118+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
79119+ gdt = get_cpu_gdt_table(cpu);
79120+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
79121+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
79122+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
79123+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
79124+ }
79125+ loadsegment(ds, __KERNEL_DS);
79126+ loadsegment(es, __KERNEL_DS);
79127+ loadsegment(ss, __KERNEL_DS);
79128+#else
79129+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
79130+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
79131+ clone_pgd_mask = ~(pgdval_t)0UL;
79132+ pax_user_shadow_base = 0UL;
79133+ setup_clear_cpu_cap(X86_FEATURE_PCID);
79134+#endif
79135+
79136+ return 0;
79137+}
79138+early_param("pax_nouderef", setup_pax_nouderef);
79139+
79140+#ifdef CONFIG_X86_64
79141+static int __init setup_pax_weakuderef(char *str)
79142+{
79143+ if (clone_pgd_mask != ~(pgdval_t)0UL)
79144+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
79145+ return 1;
79146+}
79147+__setup("pax_weakuderef", setup_pax_weakuderef);
79148+#endif
79149+#endif
79150+
79151+#ifdef CONFIG_PAX_SOFTMODE
79152+int pax_softmode;
79153+
79154+static int __init setup_pax_softmode(char *str)
79155+{
79156+ get_option(&str, &pax_softmode);
79157+ return 1;
79158+}
79159+__setup("pax_softmode=", setup_pax_softmode);
79160+#endif
79161+
79162 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
79163 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
79164 static const char *panic_later, *panic_param;
79165@@ -679,24 +749,22 @@ int __init_or_module do_one_initcall(initcall_t fn)
79166 {
79167 int count = preempt_count();
79168 int ret;
79169- char msgbuf[64];
79170+ const char *msg1 = "", *msg2 = "";
79171
79172 if (initcall_debug)
79173 ret = do_one_initcall_debug(fn);
79174 else
79175 ret = fn();
79176
79177- msgbuf[0] = 0;
79178-
79179 if (preempt_count() != count) {
79180- sprintf(msgbuf, "preemption imbalance ");
79181+ msg1 = " preemption imbalance";
79182 preempt_count() = count;
79183 }
79184 if (irqs_disabled()) {
79185- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
79186+ msg2 = " disabled interrupts";
79187 local_irq_enable();
79188 }
79189- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
79190+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
79191
79192 return ret;
79193 }
79194@@ -749,8 +817,10 @@ static void __init do_initcall_level(int level)
79195 level, level,
79196 &repair_env_string);
79197
79198- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
79199+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
79200 do_one_initcall(*fn);
79201+ add_latent_entropy();
79202+ }
79203 }
79204
79205 static void __init do_initcalls(void)
79206@@ -784,8 +854,10 @@ static void __init do_pre_smp_initcalls(void)
79207 {
79208 initcall_t *fn;
79209
79210- for (fn = __initcall_start; fn < __initcall0_start; fn++)
79211+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
79212 do_one_initcall(*fn);
79213+ add_latent_entropy();
79214+ }
79215 }
79216
79217 /*
79218@@ -803,8 +875,8 @@ static int run_init_process(const char *init_filename)
79219 {
79220 argv_init[0] = init_filename;
79221 return do_execve(init_filename,
79222- (const char __user *const __user *)argv_init,
79223- (const char __user *const __user *)envp_init);
79224+ (const char __user *const __force_user *)argv_init,
79225+ (const char __user *const __force_user *)envp_init);
79226 }
79227
79228 static noinline void __init kernel_init_freeable(void);
79229@@ -881,7 +953,7 @@ static noinline void __init kernel_init_freeable(void)
79230 do_basic_setup();
79231
79232 /* Open the /dev/console on the rootfs, this should never fail */
79233- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
79234+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
79235 pr_err("Warning: unable to open an initial console.\n");
79236
79237 (void) sys_dup(0);
79238@@ -894,11 +966,13 @@ static noinline void __init kernel_init_freeable(void)
79239 if (!ramdisk_execute_command)
79240 ramdisk_execute_command = "/init";
79241
79242- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
79243+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
79244 ramdisk_execute_command = NULL;
79245 prepare_namespace();
79246 }
79247
79248+ grsecurity_init();
79249+
79250 /*
79251 * Ok, we have completed the initial bootup, and
79252 * we're essentially up and running. Get rid of the
79253diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
79254index 130dfec..cc88451 100644
79255--- a/ipc/ipc_sysctl.c
79256+++ b/ipc/ipc_sysctl.c
79257@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
79258 static int proc_ipc_dointvec(ctl_table *table, int write,
79259 void __user *buffer, size_t *lenp, loff_t *ppos)
79260 {
79261- struct ctl_table ipc_table;
79262+ ctl_table_no_const ipc_table;
79263
79264 memcpy(&ipc_table, table, sizeof(ipc_table));
79265 ipc_table.data = get_ipc(table);
79266@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
79267 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
79268 void __user *buffer, size_t *lenp, loff_t *ppos)
79269 {
79270- struct ctl_table ipc_table;
79271+ ctl_table_no_const ipc_table;
79272
79273 memcpy(&ipc_table, table, sizeof(ipc_table));
79274 ipc_table.data = get_ipc(table);
79275@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
79276 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
79277 void __user *buffer, size_t *lenp, loff_t *ppos)
79278 {
79279- struct ctl_table ipc_table;
79280+ ctl_table_no_const ipc_table;
79281 size_t lenp_bef = *lenp;
79282 int rc;
79283
79284@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
79285 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
79286 void __user *buffer, size_t *lenp, loff_t *ppos)
79287 {
79288- struct ctl_table ipc_table;
79289+ ctl_table_no_const ipc_table;
79290 memcpy(&ipc_table, table, sizeof(ipc_table));
79291 ipc_table.data = get_ipc(table);
79292
79293@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
79294 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
79295 void __user *buffer, size_t *lenp, loff_t *ppos)
79296 {
79297- struct ctl_table ipc_table;
79298+ ctl_table_no_const ipc_table;
79299 size_t lenp_bef = *lenp;
79300 int oldval;
79301 int rc;
79302diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
79303index 383d638..943fdbb 100644
79304--- a/ipc/mq_sysctl.c
79305+++ b/ipc/mq_sysctl.c
79306@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
79307 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
79308 void __user *buffer, size_t *lenp, loff_t *ppos)
79309 {
79310- struct ctl_table mq_table;
79311+ ctl_table_no_const mq_table;
79312 memcpy(&mq_table, table, sizeof(mq_table));
79313 mq_table.data = get_mq(table);
79314
79315diff --git a/ipc/mqueue.c b/ipc/mqueue.c
79316index ae1996d..a35f2cc 100644
79317--- a/ipc/mqueue.c
79318+++ b/ipc/mqueue.c
79319@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
79320 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
79321 info->attr.mq_msgsize);
79322
79323+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
79324 spin_lock(&mq_lock);
79325 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
79326 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
79327diff --git a/ipc/msg.c b/ipc/msg.c
79328index 9f29d9e..8f284e0 100644
79329--- a/ipc/msg.c
79330+++ b/ipc/msg.c
79331@@ -291,18 +291,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
79332 return security_msg_queue_associate(msq, msgflg);
79333 }
79334
79335+static struct ipc_ops msg_ops = {
79336+ .getnew = newque,
79337+ .associate = msg_security,
79338+ .more_checks = NULL
79339+};
79340+
79341 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
79342 {
79343 struct ipc_namespace *ns;
79344- struct ipc_ops msg_ops;
79345 struct ipc_params msg_params;
79346
79347 ns = current->nsproxy->ipc_ns;
79348
79349- msg_ops.getnew = newque;
79350- msg_ops.associate = msg_security;
79351- msg_ops.more_checks = NULL;
79352-
79353 msg_params.key = key;
79354 msg_params.flg = msgflg;
79355
79356diff --git a/ipc/sem.c b/ipc/sem.c
79357index 4108889..511ada1 100644
79358--- a/ipc/sem.c
79359+++ b/ipc/sem.c
79360@@ -517,10 +517,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
79361 return 0;
79362 }
79363
79364+static struct ipc_ops sem_ops = {
79365+ .getnew = newary,
79366+ .associate = sem_security,
79367+ .more_checks = sem_more_checks
79368+};
79369+
79370 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
79371 {
79372 struct ipc_namespace *ns;
79373- struct ipc_ops sem_ops;
79374 struct ipc_params sem_params;
79375
79376 ns = current->nsproxy->ipc_ns;
79377@@ -528,10 +533,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
79378 if (nsems < 0 || nsems > ns->sc_semmsl)
79379 return -EINVAL;
79380
79381- sem_ops.getnew = newary;
79382- sem_ops.associate = sem_security;
79383- sem_ops.more_checks = sem_more_checks;
79384-
79385 sem_params.key = key;
79386 sem_params.flg = semflg;
79387 sem_params.u.nsems = nsems;
79388diff --git a/ipc/shm.c b/ipc/shm.c
79389index c6b4ad5..3ec3254 100644
79390--- a/ipc/shm.c
79391+++ b/ipc/shm.c
79392@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
79393 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
79394 #endif
79395
79396+#ifdef CONFIG_GRKERNSEC
79397+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79398+ const time_t shm_createtime, const kuid_t cuid,
79399+ const int shmid);
79400+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79401+ const time_t shm_createtime);
79402+#endif
79403+
79404 void shm_init_ns(struct ipc_namespace *ns)
79405 {
79406 ns->shm_ctlmax = SHMMAX;
79407@@ -531,6 +539,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
79408 shp->shm_lprid = 0;
79409 shp->shm_atim = shp->shm_dtim = 0;
79410 shp->shm_ctim = get_seconds();
79411+#ifdef CONFIG_GRKERNSEC
79412+ {
79413+ struct timespec timeval;
79414+ do_posix_clock_monotonic_gettime(&timeval);
79415+
79416+ shp->shm_createtime = timeval.tv_sec;
79417+ }
79418+#endif
79419 shp->shm_segsz = size;
79420 shp->shm_nattch = 0;
79421 shp->shm_file = file;
79422@@ -585,18 +601,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
79423 return 0;
79424 }
79425
79426+static struct ipc_ops shm_ops = {
79427+ .getnew = newseg,
79428+ .associate = shm_security,
79429+ .more_checks = shm_more_checks
79430+};
79431+
79432 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
79433 {
79434 struct ipc_namespace *ns;
79435- struct ipc_ops shm_ops;
79436 struct ipc_params shm_params;
79437
79438 ns = current->nsproxy->ipc_ns;
79439
79440- shm_ops.getnew = newseg;
79441- shm_ops.associate = shm_security;
79442- shm_ops.more_checks = shm_more_checks;
79443-
79444 shm_params.key = key;
79445 shm_params.flg = shmflg;
79446 shm_params.u.size = size;
79447@@ -1028,6 +1045,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79448 f_mode = FMODE_READ | FMODE_WRITE;
79449 }
79450 if (shmflg & SHM_EXEC) {
79451+
79452+#ifdef CONFIG_PAX_MPROTECT
79453+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
79454+ goto out;
79455+#endif
79456+
79457 prot |= PROT_EXEC;
79458 acc_mode |= S_IXUGO;
79459 }
79460@@ -1051,9 +1074,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79461 if (err)
79462 goto out_unlock;
79463
79464+#ifdef CONFIG_GRKERNSEC
79465+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
79466+ shp->shm_perm.cuid, shmid) ||
79467+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
79468+ err = -EACCES;
79469+ goto out_unlock;
79470+ }
79471+#endif
79472+
79473 path = shp->shm_file->f_path;
79474 path_get(&path);
79475 shp->shm_nattch++;
79476+#ifdef CONFIG_GRKERNSEC
79477+ shp->shm_lapid = current->pid;
79478+#endif
79479 size = i_size_read(path.dentry->d_inode);
79480 shm_unlock(shp);
79481
79482diff --git a/kernel/acct.c b/kernel/acct.c
79483index 8d6e145..33e0b1e 100644
79484--- a/kernel/acct.c
79485+++ b/kernel/acct.c
79486@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
79487 */
79488 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
79489 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
79490- file->f_op->write(file, (char *)&ac,
79491+ file->f_op->write(file, (char __force_user *)&ac,
79492 sizeof(acct_t), &file->f_pos);
79493 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
79494 set_fs(fs);
79495diff --git a/kernel/audit.c b/kernel/audit.c
79496index 91e53d0..d9e3ec4 100644
79497--- a/kernel/audit.c
79498+++ b/kernel/audit.c
79499@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
79500 3) suppressed due to audit_rate_limit
79501 4) suppressed due to audit_backlog_limit
79502 */
79503-static atomic_t audit_lost = ATOMIC_INIT(0);
79504+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
79505
79506 /* The netlink socket. */
79507 static struct sock *audit_sock;
79508@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
79509 unsigned long now;
79510 int print;
79511
79512- atomic_inc(&audit_lost);
79513+ atomic_inc_unchecked(&audit_lost);
79514
79515 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
79516
79517@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
79518 printk(KERN_WARNING
79519 "audit: audit_lost=%d audit_rate_limit=%d "
79520 "audit_backlog_limit=%d\n",
79521- atomic_read(&audit_lost),
79522+ atomic_read_unchecked(&audit_lost),
79523 audit_rate_limit,
79524 audit_backlog_limit);
79525 audit_panic(message);
79526@@ -664,7 +664,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
79527 status_set.pid = audit_pid;
79528 status_set.rate_limit = audit_rate_limit;
79529 status_set.backlog_limit = audit_backlog_limit;
79530- status_set.lost = atomic_read(&audit_lost);
79531+ status_set.lost = atomic_read_unchecked(&audit_lost);
79532 status_set.backlog = skb_queue_len(&audit_skb_queue);
79533 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
79534 &status_set, sizeof(status_set));
79535diff --git a/kernel/auditsc.c b/kernel/auditsc.c
79536index 9845cb3..3ec9369 100644
79537--- a/kernel/auditsc.c
79538+++ b/kernel/auditsc.c
79539@@ -1962,7 +1962,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
79540 }
79541
79542 /* global counter which is incremented every time something logs in */
79543-static atomic_t session_id = ATOMIC_INIT(0);
79544+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
79545
79546 /**
79547 * audit_set_loginuid - set current task's audit_context loginuid
79548@@ -1986,7 +1986,7 @@ int audit_set_loginuid(kuid_t loginuid)
79549 return -EPERM;
79550 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
79551
79552- sessionid = atomic_inc_return(&session_id);
79553+ sessionid = atomic_inc_return_unchecked(&session_id);
79554 if (context && context->in_syscall) {
79555 struct audit_buffer *ab;
79556
79557diff --git a/kernel/capability.c b/kernel/capability.c
79558index f6c2ce5..982c0f9 100644
79559--- a/kernel/capability.c
79560+++ b/kernel/capability.c
79561@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
79562 * before modification is attempted and the application
79563 * fails.
79564 */
79565+ if (tocopy > ARRAY_SIZE(kdata))
79566+ return -EFAULT;
79567+
79568 if (copy_to_user(dataptr, kdata, tocopy
79569 * sizeof(struct __user_cap_data_struct))) {
79570 return -EFAULT;
79571@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
79572 int ret;
79573
79574 rcu_read_lock();
79575- ret = security_capable(__task_cred(t), ns, cap);
79576+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
79577+ gr_task_is_capable(t, __task_cred(t), cap);
79578 rcu_read_unlock();
79579
79580- return (ret == 0);
79581+ return ret;
79582 }
79583
79584 /**
79585@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
79586 int ret;
79587
79588 rcu_read_lock();
79589- ret = security_capable_noaudit(__task_cred(t), ns, cap);
79590+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
79591 rcu_read_unlock();
79592
79593- return (ret == 0);
79594+ return ret;
79595 }
79596
79597 /**
79598@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
79599 BUG();
79600 }
79601
79602- if (security_capable(current_cred(), ns, cap) == 0) {
79603+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
79604 current->flags |= PF_SUPERPRIV;
79605 return true;
79606 }
79607@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
79608 }
79609 EXPORT_SYMBOL(ns_capable);
79610
79611+bool ns_capable_nolog(struct user_namespace *ns, int cap)
79612+{
79613+ if (unlikely(!cap_valid(cap))) {
79614+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
79615+ BUG();
79616+ }
79617+
79618+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
79619+ current->flags |= PF_SUPERPRIV;
79620+ return true;
79621+ }
79622+ return false;
79623+}
79624+EXPORT_SYMBOL(ns_capable_nolog);
79625+
79626 /**
79627 * file_ns_capable - Determine if the file's opener had a capability in effect
79628 * @file: The file we want to check
79629@@ -432,6 +451,12 @@ bool capable(int cap)
79630 }
79631 EXPORT_SYMBOL(capable);
79632
79633+bool capable_nolog(int cap)
79634+{
79635+ return ns_capable_nolog(&init_user_ns, cap);
79636+}
79637+EXPORT_SYMBOL(capable_nolog);
79638+
79639 /**
79640 * nsown_capable - Check superior capability to one's own user_ns
79641 * @cap: The capability in question
79642@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
79643
79644 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79645 }
79646+
79647+bool inode_capable_nolog(const struct inode *inode, int cap)
79648+{
79649+ struct user_namespace *ns = current_user_ns();
79650+
79651+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79652+}
79653diff --git a/kernel/cgroup.c b/kernel/cgroup.c
79654index e919633..f46b08f 100644
79655--- a/kernel/cgroup.c
79656+++ b/kernel/cgroup.c
79657@@ -5623,7 +5623,7 @@ static int cgroup_css_links_read(struct cgroup *cgrp,
79658 struct css_set *cset = link->cset;
79659 struct task_struct *task;
79660 int count = 0;
79661- seq_printf(seq, "css_set %p\n", cset);
79662+ seq_printf(seq, "css_set %pK\n", cset);
79663 list_for_each_entry(task, &cset->tasks, cg_list) {
79664 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
79665 seq_puts(seq, " ...\n");
79666diff --git a/kernel/compat.c b/kernel/compat.c
79667index 0a09e48..f44f3f0 100644
79668--- a/kernel/compat.c
79669+++ b/kernel/compat.c
79670@@ -13,6 +13,7 @@
79671
79672 #include <linux/linkage.h>
79673 #include <linux/compat.h>
79674+#include <linux/module.h>
79675 #include <linux/errno.h>
79676 #include <linux/time.h>
79677 #include <linux/signal.h>
79678@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
79679 mm_segment_t oldfs;
79680 long ret;
79681
79682- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
79683+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
79684 oldfs = get_fs();
79685 set_fs(KERNEL_DS);
79686 ret = hrtimer_nanosleep_restart(restart);
79687@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
79688 oldfs = get_fs();
79689 set_fs(KERNEL_DS);
79690 ret = hrtimer_nanosleep(&tu,
79691- rmtp ? (struct timespec __user *)&rmt : NULL,
79692+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
79693 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
79694 set_fs(oldfs);
79695
79696@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
79697 mm_segment_t old_fs = get_fs();
79698
79699 set_fs(KERNEL_DS);
79700- ret = sys_sigpending((old_sigset_t __user *) &s);
79701+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
79702 set_fs(old_fs);
79703 if (ret == 0)
79704 ret = put_user(s, set);
79705@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
79706 mm_segment_t old_fs = get_fs();
79707
79708 set_fs(KERNEL_DS);
79709- ret = sys_old_getrlimit(resource, &r);
79710+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
79711 set_fs(old_fs);
79712
79713 if (!ret) {
79714@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
79715 set_fs (KERNEL_DS);
79716 ret = sys_wait4(pid,
79717 (stat_addr ?
79718- (unsigned int __user *) &status : NULL),
79719- options, (struct rusage __user *) &r);
79720+ (unsigned int __force_user *) &status : NULL),
79721+ options, (struct rusage __force_user *) &r);
79722 set_fs (old_fs);
79723
79724 if (ret > 0) {
79725@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
79726 memset(&info, 0, sizeof(info));
79727
79728 set_fs(KERNEL_DS);
79729- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
79730- uru ? (struct rusage __user *)&ru : NULL);
79731+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
79732+ uru ? (struct rusage __force_user *)&ru : NULL);
79733 set_fs(old_fs);
79734
79735 if ((ret < 0) || (info.si_signo == 0))
79736@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
79737 oldfs = get_fs();
79738 set_fs(KERNEL_DS);
79739 err = sys_timer_settime(timer_id, flags,
79740- (struct itimerspec __user *) &newts,
79741- (struct itimerspec __user *) &oldts);
79742+ (struct itimerspec __force_user *) &newts,
79743+ (struct itimerspec __force_user *) &oldts);
79744 set_fs(oldfs);
79745 if (!err && old && put_compat_itimerspec(old, &oldts))
79746 return -EFAULT;
79747@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
79748 oldfs = get_fs();
79749 set_fs(KERNEL_DS);
79750 err = sys_timer_gettime(timer_id,
79751- (struct itimerspec __user *) &ts);
79752+ (struct itimerspec __force_user *) &ts);
79753 set_fs(oldfs);
79754 if (!err && put_compat_itimerspec(setting, &ts))
79755 return -EFAULT;
79756@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
79757 oldfs = get_fs();
79758 set_fs(KERNEL_DS);
79759 err = sys_clock_settime(which_clock,
79760- (struct timespec __user *) &ts);
79761+ (struct timespec __force_user *) &ts);
79762 set_fs(oldfs);
79763 return err;
79764 }
79765@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
79766 oldfs = get_fs();
79767 set_fs(KERNEL_DS);
79768 err = sys_clock_gettime(which_clock,
79769- (struct timespec __user *) &ts);
79770+ (struct timespec __force_user *) &ts);
79771 set_fs(oldfs);
79772 if (!err && put_compat_timespec(&ts, tp))
79773 return -EFAULT;
79774@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
79775
79776 oldfs = get_fs();
79777 set_fs(KERNEL_DS);
79778- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
79779+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
79780 set_fs(oldfs);
79781
79782 err = compat_put_timex(utp, &txc);
79783@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
79784 oldfs = get_fs();
79785 set_fs(KERNEL_DS);
79786 err = sys_clock_getres(which_clock,
79787- (struct timespec __user *) &ts);
79788+ (struct timespec __force_user *) &ts);
79789 set_fs(oldfs);
79790 if (!err && tp && put_compat_timespec(&ts, tp))
79791 return -EFAULT;
79792@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
79793 long err;
79794 mm_segment_t oldfs;
79795 struct timespec tu;
79796- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
79797+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
79798
79799- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
79800+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
79801 oldfs = get_fs();
79802 set_fs(KERNEL_DS);
79803 err = clock_nanosleep_restart(restart);
79804@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
79805 oldfs = get_fs();
79806 set_fs(KERNEL_DS);
79807 err = sys_clock_nanosleep(which_clock, flags,
79808- (struct timespec __user *) &in,
79809- (struct timespec __user *) &out);
79810+ (struct timespec __force_user *) &in,
79811+ (struct timespec __force_user *) &out);
79812 set_fs(oldfs);
79813
79814 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
79815diff --git a/kernel/configs.c b/kernel/configs.c
79816index c18b1f1..b9a0132 100644
79817--- a/kernel/configs.c
79818+++ b/kernel/configs.c
79819@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
79820 struct proc_dir_entry *entry;
79821
79822 /* create the current config file */
79823+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
79824+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
79825+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
79826+ &ikconfig_file_ops);
79827+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79828+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
79829+ &ikconfig_file_ops);
79830+#endif
79831+#else
79832 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
79833 &ikconfig_file_ops);
79834+#endif
79835+
79836 if (!entry)
79837 return -ENOMEM;
79838
79839diff --git a/kernel/cred.c b/kernel/cred.c
79840index e0573a4..3874e41 100644
79841--- a/kernel/cred.c
79842+++ b/kernel/cred.c
79843@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
79844 validate_creds(cred);
79845 alter_cred_subscribers(cred, -1);
79846 put_cred(cred);
79847+
79848+#ifdef CONFIG_GRKERNSEC_SETXID
79849+ cred = (struct cred *) tsk->delayed_cred;
79850+ if (cred != NULL) {
79851+ tsk->delayed_cred = NULL;
79852+ validate_creds(cred);
79853+ alter_cred_subscribers(cred, -1);
79854+ put_cred(cred);
79855+ }
79856+#endif
79857 }
79858
79859 /**
79860@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
79861 * Always returns 0 thus allowing this function to be tail-called at the end
79862 * of, say, sys_setgid().
79863 */
79864-int commit_creds(struct cred *new)
79865+static int __commit_creds(struct cred *new)
79866 {
79867 struct task_struct *task = current;
79868 const struct cred *old = task->real_cred;
79869@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
79870
79871 get_cred(new); /* we will require a ref for the subj creds too */
79872
79873+ gr_set_role_label(task, new->uid, new->gid);
79874+
79875 /* dumpability changes */
79876 if (!uid_eq(old->euid, new->euid) ||
79877 !gid_eq(old->egid, new->egid) ||
79878@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
79879 put_cred(old);
79880 return 0;
79881 }
79882+#ifdef CONFIG_GRKERNSEC_SETXID
79883+extern int set_user(struct cred *new);
79884+
79885+void gr_delayed_cred_worker(void)
79886+{
79887+ const struct cred *new = current->delayed_cred;
79888+ struct cred *ncred;
79889+
79890+ current->delayed_cred = NULL;
79891+
79892+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
79893+ // from doing get_cred on it when queueing this
79894+ put_cred(new);
79895+ return;
79896+ } else if (new == NULL)
79897+ return;
79898+
79899+ ncred = prepare_creds();
79900+ if (!ncred)
79901+ goto die;
79902+ // uids
79903+ ncred->uid = new->uid;
79904+ ncred->euid = new->euid;
79905+ ncred->suid = new->suid;
79906+ ncred->fsuid = new->fsuid;
79907+ // gids
79908+ ncred->gid = new->gid;
79909+ ncred->egid = new->egid;
79910+ ncred->sgid = new->sgid;
79911+ ncred->fsgid = new->fsgid;
79912+ // groups
79913+ if (set_groups(ncred, new->group_info) < 0) {
79914+ abort_creds(ncred);
79915+ goto die;
79916+ }
79917+ // caps
79918+ ncred->securebits = new->securebits;
79919+ ncred->cap_inheritable = new->cap_inheritable;
79920+ ncred->cap_permitted = new->cap_permitted;
79921+ ncred->cap_effective = new->cap_effective;
79922+ ncred->cap_bset = new->cap_bset;
79923+
79924+ if (set_user(ncred)) {
79925+ abort_creds(ncred);
79926+ goto die;
79927+ }
79928+
79929+ // from doing get_cred on it when queueing this
79930+ put_cred(new);
79931+
79932+ __commit_creds(ncred);
79933+ return;
79934+die:
79935+ // from doing get_cred on it when queueing this
79936+ put_cred(new);
79937+ do_group_exit(SIGKILL);
79938+}
79939+#endif
79940+
79941+int commit_creds(struct cred *new)
79942+{
79943+#ifdef CONFIG_GRKERNSEC_SETXID
79944+ int ret;
79945+ int schedule_it = 0;
79946+ struct task_struct *t;
79947+
79948+ /* we won't get called with tasklist_lock held for writing
79949+ and interrupts disabled as the cred struct in that case is
79950+ init_cred
79951+ */
79952+ if (grsec_enable_setxid && !current_is_single_threaded() &&
79953+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
79954+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
79955+ schedule_it = 1;
79956+ }
79957+ ret = __commit_creds(new);
79958+ if (schedule_it) {
79959+ rcu_read_lock();
79960+ read_lock(&tasklist_lock);
79961+ for (t = next_thread(current); t != current;
79962+ t = next_thread(t)) {
79963+ if (t->delayed_cred == NULL) {
79964+ t->delayed_cred = get_cred(new);
79965+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
79966+ set_tsk_need_resched(t);
79967+ }
79968+ }
79969+ read_unlock(&tasklist_lock);
79970+ rcu_read_unlock();
79971+ }
79972+ return ret;
79973+#else
79974+ return __commit_creds(new);
79975+#endif
79976+}
79977+
79978 EXPORT_SYMBOL(commit_creds);
79979
79980 /**
79981diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
79982index 0506d44..2c20034 100644
79983--- a/kernel/debug/debug_core.c
79984+++ b/kernel/debug/debug_core.c
79985@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
79986 */
79987 static atomic_t masters_in_kgdb;
79988 static atomic_t slaves_in_kgdb;
79989-static atomic_t kgdb_break_tasklet_var;
79990+static atomic_unchecked_t kgdb_break_tasklet_var;
79991 atomic_t kgdb_setting_breakpoint;
79992
79993 struct task_struct *kgdb_usethread;
79994@@ -133,7 +133,7 @@ int kgdb_single_step;
79995 static pid_t kgdb_sstep_pid;
79996
79997 /* to keep track of the CPU which is doing the single stepping*/
79998-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
79999+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
80000
80001 /*
80002 * If you are debugging a problem where roundup (the collection of
80003@@ -541,7 +541,7 @@ return_normal:
80004 * kernel will only try for the value of sstep_tries before
80005 * giving up and continuing on.
80006 */
80007- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
80008+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
80009 (kgdb_info[cpu].task &&
80010 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
80011 atomic_set(&kgdb_active, -1);
80012@@ -635,8 +635,8 @@ cpu_master_loop:
80013 }
80014
80015 kgdb_restore:
80016- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
80017- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
80018+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
80019+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
80020 if (kgdb_info[sstep_cpu].task)
80021 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
80022 else
80023@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
80024 static void kgdb_tasklet_bpt(unsigned long ing)
80025 {
80026 kgdb_breakpoint();
80027- atomic_set(&kgdb_break_tasklet_var, 0);
80028+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
80029 }
80030
80031 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
80032
80033 void kgdb_schedule_breakpoint(void)
80034 {
80035- if (atomic_read(&kgdb_break_tasklet_var) ||
80036+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
80037 atomic_read(&kgdb_active) != -1 ||
80038 atomic_read(&kgdb_setting_breakpoint))
80039 return;
80040- atomic_inc(&kgdb_break_tasklet_var);
80041+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
80042 tasklet_schedule(&kgdb_tasklet_breakpoint);
80043 }
80044 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
80045diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
80046index 00eb8f7..d7e3244 100644
80047--- a/kernel/debug/kdb/kdb_main.c
80048+++ b/kernel/debug/kdb/kdb_main.c
80049@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
80050 continue;
80051
80052 kdb_printf("%-20s%8u 0x%p ", mod->name,
80053- mod->core_size, (void *)mod);
80054+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
80055 #ifdef CONFIG_MODULE_UNLOAD
80056 kdb_printf("%4ld ", module_refcount(mod));
80057 #endif
80058@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
80059 kdb_printf(" (Loading)");
80060 else
80061 kdb_printf(" (Live)");
80062- kdb_printf(" 0x%p", mod->module_core);
80063+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
80064
80065 #ifdef CONFIG_MODULE_UNLOAD
80066 {
80067diff --git a/kernel/events/core.c b/kernel/events/core.c
80068index f86599e..b18b180 100644
80069--- a/kernel/events/core.c
80070+++ b/kernel/events/core.c
80071@@ -156,8 +156,15 @@ static struct srcu_struct pmus_srcu;
80072 * 0 - disallow raw tracepoint access for unpriv
80073 * 1 - disallow cpu events for unpriv
80074 * 2 - disallow kernel profiling for unpriv
80075+ * 3 - disallow all unpriv perf event use
80076 */
80077-int sysctl_perf_event_paranoid __read_mostly = 1;
80078+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
80079+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
80080+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
80081+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
80082+#else
80083+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
80084+#endif
80085
80086 /* Minimum for 512 kiB + 1 user control page */
80087 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
80088@@ -270,7 +277,7 @@ void perf_sample_event_took(u64 sample_len_ns)
80089 update_perf_cpu_limits();
80090 }
80091
80092-static atomic64_t perf_event_id;
80093+static atomic64_unchecked_t perf_event_id;
80094
80095 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
80096 enum event_type_t event_type);
80097@@ -2936,7 +2943,7 @@ static void __perf_event_read(void *info)
80098
80099 static inline u64 perf_event_count(struct perf_event *event)
80100 {
80101- return local64_read(&event->count) + atomic64_read(&event->child_count);
80102+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
80103 }
80104
80105 static u64 perf_event_read(struct perf_event *event)
80106@@ -3282,9 +3289,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
80107 mutex_lock(&event->child_mutex);
80108 total += perf_event_read(event);
80109 *enabled += event->total_time_enabled +
80110- atomic64_read(&event->child_total_time_enabled);
80111+ atomic64_read_unchecked(&event->child_total_time_enabled);
80112 *running += event->total_time_running +
80113- atomic64_read(&event->child_total_time_running);
80114+ atomic64_read_unchecked(&event->child_total_time_running);
80115
80116 list_for_each_entry(child, &event->child_list, child_list) {
80117 total += perf_event_read(child);
80118@@ -3670,10 +3677,10 @@ void perf_event_update_userpage(struct perf_event *event)
80119 userpg->offset -= local64_read(&event->hw.prev_count);
80120
80121 userpg->time_enabled = enabled +
80122- atomic64_read(&event->child_total_time_enabled);
80123+ atomic64_read_unchecked(&event->child_total_time_enabled);
80124
80125 userpg->time_running = running +
80126- atomic64_read(&event->child_total_time_running);
80127+ atomic64_read_unchecked(&event->child_total_time_running);
80128
80129 arch_perf_update_userpage(userpg, now);
80130
80131@@ -4223,7 +4230,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
80132
80133 /* Data. */
80134 sp = perf_user_stack_pointer(regs);
80135- rem = __output_copy_user(handle, (void *) sp, dump_size);
80136+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
80137 dyn_size = dump_size - rem;
80138
80139 perf_output_skip(handle, rem);
80140@@ -4311,11 +4318,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
80141 values[n++] = perf_event_count(event);
80142 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
80143 values[n++] = enabled +
80144- atomic64_read(&event->child_total_time_enabled);
80145+ atomic64_read_unchecked(&event->child_total_time_enabled);
80146 }
80147 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
80148 values[n++] = running +
80149- atomic64_read(&event->child_total_time_running);
80150+ atomic64_read_unchecked(&event->child_total_time_running);
80151 }
80152 if (read_format & PERF_FORMAT_ID)
80153 values[n++] = primary_event_id(event);
80154@@ -5024,12 +5031,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
80155 * need to add enough zero bytes after the string to handle
80156 * the 64bit alignment we do later.
80157 */
80158- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
80159+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
80160 if (!buf) {
80161 name = strncpy(tmp, "//enomem", sizeof(tmp));
80162 goto got_name;
80163 }
80164- name = d_path(&file->f_path, buf, PATH_MAX);
80165+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
80166 if (IS_ERR(name)) {
80167 name = strncpy(tmp, "//toolong", sizeof(tmp));
80168 goto got_name;
80169@@ -6498,7 +6505,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
80170 event->parent = parent_event;
80171
80172 event->ns = get_pid_ns(task_active_pid_ns(current));
80173- event->id = atomic64_inc_return(&perf_event_id);
80174+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
80175
80176 event->state = PERF_EVENT_STATE_INACTIVE;
80177
80178@@ -6807,6 +6814,11 @@ SYSCALL_DEFINE5(perf_event_open,
80179 if (flags & ~PERF_FLAG_ALL)
80180 return -EINVAL;
80181
80182+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
80183+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
80184+ return -EACCES;
80185+#endif
80186+
80187 err = perf_copy_attr(attr_uptr, &attr);
80188 if (err)
80189 return err;
80190@@ -7139,10 +7151,10 @@ static void sync_child_event(struct perf_event *child_event,
80191 /*
80192 * Add back the child's count to the parent's count:
80193 */
80194- atomic64_add(child_val, &parent_event->child_count);
80195- atomic64_add(child_event->total_time_enabled,
80196+ atomic64_add_unchecked(child_val, &parent_event->child_count);
80197+ atomic64_add_unchecked(child_event->total_time_enabled,
80198 &parent_event->child_total_time_enabled);
80199- atomic64_add(child_event->total_time_running,
80200+ atomic64_add_unchecked(child_event->total_time_running,
80201 &parent_event->child_total_time_running);
80202
80203 /*
80204diff --git a/kernel/events/internal.h b/kernel/events/internal.h
80205index ca65997..60df03d 100644
80206--- a/kernel/events/internal.h
80207+++ b/kernel/events/internal.h
80208@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
80209 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
80210 }
80211
80212-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
80213-static inline unsigned int \
80214+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
80215+static inline unsigned long \
80216 func_name(struct perf_output_handle *handle, \
80217- const void *buf, unsigned int len) \
80218+ const void user *buf, unsigned long len) \
80219 { \
80220 unsigned long size, written; \
80221 \
80222@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
80223 return n;
80224 }
80225
80226-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
80227+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
80228
80229 #define MEMCPY_SKIP(dst, src, n) (n)
80230
80231-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
80232+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
80233
80234 #ifndef arch_perf_out_copy_user
80235 #define arch_perf_out_copy_user __copy_from_user_inatomic
80236 #endif
80237
80238-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
80239+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
80240
80241 /* Callchain handling */
80242 extern struct perf_callchain_entry *
80243diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
80244index f356974..cb8c570 100644
80245--- a/kernel/events/uprobes.c
80246+++ b/kernel/events/uprobes.c
80247@@ -1556,7 +1556,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
80248 {
80249 struct page *page;
80250 uprobe_opcode_t opcode;
80251- int result;
80252+ long result;
80253
80254 pagefault_disable();
80255 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
80256diff --git a/kernel/exit.c b/kernel/exit.c
80257index a949819..a5f127d 100644
80258--- a/kernel/exit.c
80259+++ b/kernel/exit.c
80260@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
80261 struct task_struct *leader;
80262 int zap_leader;
80263 repeat:
80264+#ifdef CONFIG_NET
80265+ gr_del_task_from_ip_table(p);
80266+#endif
80267+
80268 /* don't need to get the RCU readlock here - the process is dead and
80269 * can't be modifying its own credentials. But shut RCU-lockdep up */
80270 rcu_read_lock();
80271@@ -329,7 +333,7 @@ int allow_signal(int sig)
80272 * know it'll be handled, so that they don't get converted to
80273 * SIGKILL or just silently dropped.
80274 */
80275- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
80276+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
80277 recalc_sigpending();
80278 spin_unlock_irq(&current->sighand->siglock);
80279 return 0;
80280@@ -698,6 +702,8 @@ void do_exit(long code)
80281 struct task_struct *tsk = current;
80282 int group_dead;
80283
80284+ set_fs(USER_DS);
80285+
80286 profile_task_exit(tsk);
80287
80288 WARN_ON(blk_needs_flush_plug(tsk));
80289@@ -714,7 +720,6 @@ void do_exit(long code)
80290 * mm_release()->clear_child_tid() from writing to a user-controlled
80291 * kernel address.
80292 */
80293- set_fs(USER_DS);
80294
80295 ptrace_event(PTRACE_EVENT_EXIT, code);
80296
80297@@ -773,6 +778,9 @@ void do_exit(long code)
80298 tsk->exit_code = code;
80299 taskstats_exit(tsk, group_dead);
80300
80301+ gr_acl_handle_psacct(tsk, code);
80302+ gr_acl_handle_exit();
80303+
80304 exit_mm(tsk);
80305
80306 if (group_dead)
80307@@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
80308 * Take down every thread in the group. This is called by fatal signals
80309 * as well as by sys_exit_group (below).
80310 */
80311-void
80312+__noreturn void
80313 do_group_exit(int exit_code)
80314 {
80315 struct signal_struct *sig = current->signal;
80316diff --git a/kernel/fork.c b/kernel/fork.c
80317index bf46287..2af185d 100644
80318--- a/kernel/fork.c
80319+++ b/kernel/fork.c
80320@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
80321 *stackend = STACK_END_MAGIC; /* for overflow detection */
80322
80323 #ifdef CONFIG_CC_STACKPROTECTOR
80324- tsk->stack_canary = get_random_int();
80325+ tsk->stack_canary = pax_get_random_long();
80326 #endif
80327
80328 /*
80329@@ -345,13 +345,81 @@ free_tsk:
80330 }
80331
80332 #ifdef CONFIG_MMU
80333-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80334+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
80335 {
80336- struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80337- struct rb_node **rb_link, *rb_parent;
80338- int retval;
80339+ struct vm_area_struct *tmp;
80340 unsigned long charge;
80341 struct mempolicy *pol;
80342+ struct file *file;
80343+
80344+ charge = 0;
80345+ if (mpnt->vm_flags & VM_ACCOUNT) {
80346+ unsigned long len = vma_pages(mpnt);
80347+
80348+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80349+ goto fail_nomem;
80350+ charge = len;
80351+ }
80352+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80353+ if (!tmp)
80354+ goto fail_nomem;
80355+ *tmp = *mpnt;
80356+ tmp->vm_mm = mm;
80357+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
80358+ pol = mpol_dup(vma_policy(mpnt));
80359+ if (IS_ERR(pol))
80360+ goto fail_nomem_policy;
80361+ vma_set_policy(tmp, pol);
80362+ if (anon_vma_fork(tmp, mpnt))
80363+ goto fail_nomem_anon_vma_fork;
80364+ tmp->vm_flags &= ~VM_LOCKED;
80365+ tmp->vm_next = tmp->vm_prev = NULL;
80366+ tmp->vm_mirror = NULL;
80367+ file = tmp->vm_file;
80368+ if (file) {
80369+ struct inode *inode = file_inode(file);
80370+ struct address_space *mapping = file->f_mapping;
80371+
80372+ get_file(file);
80373+ if (tmp->vm_flags & VM_DENYWRITE)
80374+ atomic_dec(&inode->i_writecount);
80375+ mutex_lock(&mapping->i_mmap_mutex);
80376+ if (tmp->vm_flags & VM_SHARED)
80377+ mapping->i_mmap_writable++;
80378+ flush_dcache_mmap_lock(mapping);
80379+ /* insert tmp into the share list, just after mpnt */
80380+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80381+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
80382+ else
80383+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
80384+ flush_dcache_mmap_unlock(mapping);
80385+ mutex_unlock(&mapping->i_mmap_mutex);
80386+ }
80387+
80388+ /*
80389+ * Clear hugetlb-related page reserves for children. This only
80390+ * affects MAP_PRIVATE mappings. Faults generated by the child
80391+ * are not guaranteed to succeed, even if read-only
80392+ */
80393+ if (is_vm_hugetlb_page(tmp))
80394+ reset_vma_resv_huge_pages(tmp);
80395+
80396+ return tmp;
80397+
80398+fail_nomem_anon_vma_fork:
80399+ mpol_put(pol);
80400+fail_nomem_policy:
80401+ kmem_cache_free(vm_area_cachep, tmp);
80402+fail_nomem:
80403+ vm_unacct_memory(charge);
80404+ return NULL;
80405+}
80406+
80407+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80408+{
80409+ struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80410+ struct rb_node **rb_link, *rb_parent;
80411+ int retval;
80412
80413 uprobe_start_dup_mmap();
80414 down_write(&oldmm->mmap_sem);
80415@@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80416
80417 prev = NULL;
80418 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
80419- struct file *file;
80420-
80421 if (mpnt->vm_flags & VM_DONTCOPY) {
80422 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
80423 -vma_pages(mpnt));
80424 continue;
80425 }
80426- charge = 0;
80427- if (mpnt->vm_flags & VM_ACCOUNT) {
80428- unsigned long len = vma_pages(mpnt);
80429-
80430- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80431- goto fail_nomem;
80432- charge = len;
80433- }
80434- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80435- if (!tmp)
80436- goto fail_nomem;
80437- *tmp = *mpnt;
80438- INIT_LIST_HEAD(&tmp->anon_vma_chain);
80439- pol = mpol_dup(vma_policy(mpnt));
80440- retval = PTR_ERR(pol);
80441- if (IS_ERR(pol))
80442- goto fail_nomem_policy;
80443- vma_set_policy(tmp, pol);
80444- tmp->vm_mm = mm;
80445- if (anon_vma_fork(tmp, mpnt))
80446- goto fail_nomem_anon_vma_fork;
80447- tmp->vm_flags &= ~VM_LOCKED;
80448- tmp->vm_next = tmp->vm_prev = NULL;
80449- file = tmp->vm_file;
80450- if (file) {
80451- struct inode *inode = file_inode(file);
80452- struct address_space *mapping = file->f_mapping;
80453-
80454- get_file(file);
80455- if (tmp->vm_flags & VM_DENYWRITE)
80456- atomic_dec(&inode->i_writecount);
80457- mutex_lock(&mapping->i_mmap_mutex);
80458- if (tmp->vm_flags & VM_SHARED)
80459- mapping->i_mmap_writable++;
80460- flush_dcache_mmap_lock(mapping);
80461- /* insert tmp into the share list, just after mpnt */
80462- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80463- vma_nonlinear_insert(tmp,
80464- &mapping->i_mmap_nonlinear);
80465- else
80466- vma_interval_tree_insert_after(tmp, mpnt,
80467- &mapping->i_mmap);
80468- flush_dcache_mmap_unlock(mapping);
80469- mutex_unlock(&mapping->i_mmap_mutex);
80470+ tmp = dup_vma(mm, oldmm, mpnt);
80471+ if (!tmp) {
80472+ retval = -ENOMEM;
80473+ goto out;
80474 }
80475
80476 /*
80477@@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80478 if (retval)
80479 goto out;
80480 }
80481+
80482+#ifdef CONFIG_PAX_SEGMEXEC
80483+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
80484+ struct vm_area_struct *mpnt_m;
80485+
80486+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
80487+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
80488+
80489+ if (!mpnt->vm_mirror)
80490+ continue;
80491+
80492+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
80493+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
80494+ mpnt->vm_mirror = mpnt_m;
80495+ } else {
80496+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
80497+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
80498+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
80499+ mpnt->vm_mirror->vm_mirror = mpnt;
80500+ }
80501+ }
80502+ BUG_ON(mpnt_m);
80503+ }
80504+#endif
80505+
80506 /* a new mm has just been created */
80507 arch_dup_mmap(oldmm, mm);
80508 retval = 0;
80509@@ -471,14 +522,6 @@ out:
80510 up_write(&oldmm->mmap_sem);
80511 uprobe_end_dup_mmap();
80512 return retval;
80513-fail_nomem_anon_vma_fork:
80514- mpol_put(pol);
80515-fail_nomem_policy:
80516- kmem_cache_free(vm_area_cachep, tmp);
80517-fail_nomem:
80518- retval = -ENOMEM;
80519- vm_unacct_memory(charge);
80520- goto out;
80521 }
80522
80523 static inline int mm_alloc_pgd(struct mm_struct *mm)
80524@@ -691,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
80525 return ERR_PTR(err);
80526
80527 mm = get_task_mm(task);
80528- if (mm && mm != current->mm &&
80529- !ptrace_may_access(task, mode)) {
80530+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
80531+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
80532 mmput(mm);
80533 mm = ERR_PTR(-EACCES);
80534 }
80535@@ -914,13 +957,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
80536 spin_unlock(&fs->lock);
80537 return -EAGAIN;
80538 }
80539- fs->users++;
80540+ atomic_inc(&fs->users);
80541 spin_unlock(&fs->lock);
80542 return 0;
80543 }
80544 tsk->fs = copy_fs_struct(fs);
80545 if (!tsk->fs)
80546 return -ENOMEM;
80547+ /* Carry through gr_chroot_dentry and is_chrooted instead
80548+ of recomputing it here. Already copied when the task struct
80549+ is duplicated. This allows pivot_root to not be treated as
80550+ a chroot
80551+ */
80552+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
80553+
80554 return 0;
80555 }
80556
80557@@ -1131,7 +1181,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
80558 * parts of the process environment (as per the clone
80559 * flags). The actual kick-off is left to the caller.
80560 */
80561-static struct task_struct *copy_process(unsigned long clone_flags,
80562+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
80563 unsigned long stack_start,
80564 unsigned long stack_size,
80565 int __user *child_tidptr,
80566@@ -1200,6 +1250,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80567 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
80568 #endif
80569 retval = -EAGAIN;
80570+
80571+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
80572+
80573 if (atomic_read(&p->real_cred->user->processes) >=
80574 task_rlimit(p, RLIMIT_NPROC)) {
80575 if (p->real_cred->user != INIT_USER &&
80576@@ -1449,6 +1502,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80577 goto bad_fork_free_pid;
80578 }
80579
80580+ /* synchronizes with gr_set_acls()
80581+ we need to call this past the point of no return for fork()
80582+ */
80583+ gr_copy_label(p);
80584+
80585 if (likely(p->pid)) {
80586 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
80587
80588@@ -1534,6 +1592,8 @@ bad_fork_cleanup_count:
80589 bad_fork_free:
80590 free_task(p);
80591 fork_out:
80592+ gr_log_forkfail(retval);
80593+
80594 return ERR_PTR(retval);
80595 }
80596
80597@@ -1604,6 +1664,7 @@ long do_fork(unsigned long clone_flags,
80598
80599 p = copy_process(clone_flags, stack_start, stack_size,
80600 child_tidptr, NULL, trace);
80601+ add_latent_entropy();
80602 /*
80603 * Do this prior waking up the new thread - the thread pointer
80604 * might get invalid after that point, if the thread exits quickly.
80605@@ -1618,6 +1679,8 @@ long do_fork(unsigned long clone_flags,
80606 if (clone_flags & CLONE_PARENT_SETTID)
80607 put_user(nr, parent_tidptr);
80608
80609+ gr_handle_brute_check();
80610+
80611 if (clone_flags & CLONE_VFORK) {
80612 p->vfork_done = &vfork;
80613 init_completion(&vfork);
80614@@ -1734,7 +1797,7 @@ void __init proc_caches_init(void)
80615 mm_cachep = kmem_cache_create("mm_struct",
80616 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
80617 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
80618- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
80619+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
80620 mmap_init();
80621 nsproxy_cache_init();
80622 }
80623@@ -1774,7 +1837,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
80624 return 0;
80625
80626 /* don't need lock here; in the worst case we'll do useless copy */
80627- if (fs->users == 1)
80628+ if (atomic_read(&fs->users) == 1)
80629 return 0;
80630
80631 *new_fsp = copy_fs_struct(fs);
80632@@ -1886,7 +1949,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
80633 fs = current->fs;
80634 spin_lock(&fs->lock);
80635 current->fs = new_fs;
80636- if (--fs->users)
80637+ gr_set_chroot_entries(current, &current->fs->root);
80638+ if (atomic_dec_return(&fs->users))
80639 new_fs = NULL;
80640 else
80641 new_fs = fs;
80642diff --git a/kernel/futex.c b/kernel/futex.c
80643index c3a1a55..e32b4a98 100644
80644--- a/kernel/futex.c
80645+++ b/kernel/futex.c
80646@@ -54,6 +54,7 @@
80647 #include <linux/mount.h>
80648 #include <linux/pagemap.h>
80649 #include <linux/syscalls.h>
80650+#include <linux/ptrace.h>
80651 #include <linux/signal.h>
80652 #include <linux/export.h>
80653 #include <linux/magic.h>
80654@@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
80655 struct page *page, *page_head;
80656 int err, ro = 0;
80657
80658+#ifdef CONFIG_PAX_SEGMEXEC
80659+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
80660+ return -EFAULT;
80661+#endif
80662+
80663 /*
80664 * The futex address must be "naturally" aligned.
80665 */
80666@@ -441,7 +447,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
80667
80668 static int get_futex_value_locked(u32 *dest, u32 __user *from)
80669 {
80670- int ret;
80671+ unsigned long ret;
80672
80673 pagefault_disable();
80674 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
80675@@ -2734,6 +2740,7 @@ static int __init futex_init(void)
80676 {
80677 u32 curval;
80678 int i;
80679+ mm_segment_t oldfs;
80680
80681 /*
80682 * This will fail and we want it. Some arch implementations do
80683@@ -2745,8 +2752,11 @@ static int __init futex_init(void)
80684 * implementation, the non-functional ones will return
80685 * -ENOSYS.
80686 */
80687+ oldfs = get_fs();
80688+ set_fs(USER_DS);
80689 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
80690 futex_cmpxchg_enabled = 1;
80691+ set_fs(oldfs);
80692
80693 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
80694 plist_head_init(&futex_queues[i].chain);
80695diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
80696index f9f44fd..29885e4 100644
80697--- a/kernel/futex_compat.c
80698+++ b/kernel/futex_compat.c
80699@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
80700 return 0;
80701 }
80702
80703-static void __user *futex_uaddr(struct robust_list __user *entry,
80704+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
80705 compat_long_t futex_offset)
80706 {
80707 compat_uptr_t base = ptr_to_compat(entry);
80708diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
80709index 9b22d03..6295b62 100644
80710--- a/kernel/gcov/base.c
80711+++ b/kernel/gcov/base.c
80712@@ -102,11 +102,6 @@ void gcov_enable_events(void)
80713 }
80714
80715 #ifdef CONFIG_MODULES
80716-static inline int within(void *addr, void *start, unsigned long size)
80717-{
80718- return ((addr >= start) && (addr < start + size));
80719-}
80720-
80721 /* Update list and generate events when modules are unloaded. */
80722 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80723 void *data)
80724@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80725 prev = NULL;
80726 /* Remove entries located in module from linked list. */
80727 for (info = gcov_info_head; info; info = info->next) {
80728- if (within(info, mod->module_core, mod->core_size)) {
80729+ if (within_module_core_rw((unsigned long)info, mod)) {
80730 if (prev)
80731 prev->next = info->next;
80732 else
80733diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
80734index 383319b..cd2b391 100644
80735--- a/kernel/hrtimer.c
80736+++ b/kernel/hrtimer.c
80737@@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
80738 local_irq_restore(flags);
80739 }
80740
80741-static void run_hrtimer_softirq(struct softirq_action *h)
80742+static void run_hrtimer_softirq(void)
80743 {
80744 hrtimer_peek_ahead_timers();
80745 }
80746diff --git a/kernel/irq_work.c b/kernel/irq_work.c
80747index 55fcce6..0e4cf34 100644
80748--- a/kernel/irq_work.c
80749+++ b/kernel/irq_work.c
80750@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
80751 return NOTIFY_OK;
80752 }
80753
80754-static struct notifier_block cpu_notify;
80755+static struct notifier_block cpu_notify = {
80756+ .notifier_call = irq_work_cpu_notify,
80757+ .priority = 0,
80758+};
80759
80760 static __init int irq_work_init_cpu_notifier(void)
80761 {
80762- cpu_notify.notifier_call = irq_work_cpu_notify;
80763- cpu_notify.priority = 0;
80764 register_cpu_notifier(&cpu_notify);
80765 return 0;
80766 }
80767diff --git a/kernel/jump_label.c b/kernel/jump_label.c
80768index 60f48fa..7f3a770 100644
80769--- a/kernel/jump_label.c
80770+++ b/kernel/jump_label.c
80771@@ -13,6 +13,7 @@
80772 #include <linux/sort.h>
80773 #include <linux/err.h>
80774 #include <linux/static_key.h>
80775+#include <linux/mm.h>
80776
80777 #ifdef HAVE_JUMP_LABEL
80778
80779@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
80780
80781 size = (((unsigned long)stop - (unsigned long)start)
80782 / sizeof(struct jump_entry));
80783+ pax_open_kernel();
80784 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
80785+ pax_close_kernel();
80786 }
80787
80788 static void jump_label_update(struct static_key *key, int enable);
80789@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
80790 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
80791 struct jump_entry *iter;
80792
80793+ pax_open_kernel();
80794 for (iter = iter_start; iter < iter_stop; iter++) {
80795 if (within_module_init(iter->code, mod))
80796 iter->code = 0;
80797 }
80798+ pax_close_kernel();
80799 }
80800
80801 static int
80802diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
80803index 3127ad5..159d880 100644
80804--- a/kernel/kallsyms.c
80805+++ b/kernel/kallsyms.c
80806@@ -11,6 +11,9 @@
80807 * Changed the compression method from stem compression to "table lookup"
80808 * compression (see scripts/kallsyms.c for a more complete description)
80809 */
80810+#ifdef CONFIG_GRKERNSEC_HIDESYM
80811+#define __INCLUDED_BY_HIDESYM 1
80812+#endif
80813 #include <linux/kallsyms.h>
80814 #include <linux/module.h>
80815 #include <linux/init.h>
80816@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
80817
80818 static inline int is_kernel_inittext(unsigned long addr)
80819 {
80820+ if (system_state != SYSTEM_BOOTING)
80821+ return 0;
80822+
80823 if (addr >= (unsigned long)_sinittext
80824 && addr <= (unsigned long)_einittext)
80825 return 1;
80826 return 0;
80827 }
80828
80829+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80830+#ifdef CONFIG_MODULES
80831+static inline int is_module_text(unsigned long addr)
80832+{
80833+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
80834+ return 1;
80835+
80836+ addr = ktla_ktva(addr);
80837+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
80838+}
80839+#else
80840+static inline int is_module_text(unsigned long addr)
80841+{
80842+ return 0;
80843+}
80844+#endif
80845+#endif
80846+
80847 static inline int is_kernel_text(unsigned long addr)
80848 {
80849 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
80850@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
80851
80852 static inline int is_kernel(unsigned long addr)
80853 {
80854+
80855+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80856+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
80857+ return 1;
80858+
80859+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
80860+#else
80861 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
80862+#endif
80863+
80864 return 1;
80865 return in_gate_area_no_mm(addr);
80866 }
80867
80868 static int is_ksym_addr(unsigned long addr)
80869 {
80870+
80871+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80872+ if (is_module_text(addr))
80873+ return 0;
80874+#endif
80875+
80876 if (all_var)
80877 return is_kernel(addr);
80878
80879@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
80880
80881 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
80882 {
80883- iter->name[0] = '\0';
80884 iter->nameoff = get_symbol_offset(new_pos);
80885 iter->pos = new_pos;
80886 }
80887@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
80888 {
80889 struct kallsym_iter *iter = m->private;
80890
80891+#ifdef CONFIG_GRKERNSEC_HIDESYM
80892+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
80893+ return 0;
80894+#endif
80895+
80896 /* Some debugging symbols have no name. Ignore them. */
80897 if (!iter->name[0])
80898 return 0;
80899@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
80900 */
80901 type = iter->exported ? toupper(iter->type) :
80902 tolower(iter->type);
80903+
80904 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
80905 type, iter->name, iter->module_name);
80906 } else
80907@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
80908 struct kallsym_iter *iter;
80909 int ret;
80910
80911- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
80912+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
80913 if (!iter)
80914 return -ENOMEM;
80915 reset_iter(iter, 0);
80916diff --git a/kernel/kcmp.c b/kernel/kcmp.c
80917index e30ac0f..3528cac 100644
80918--- a/kernel/kcmp.c
80919+++ b/kernel/kcmp.c
80920@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
80921 struct task_struct *task1, *task2;
80922 int ret;
80923
80924+#ifdef CONFIG_GRKERNSEC
80925+ return -ENOSYS;
80926+#endif
80927+
80928 rcu_read_lock();
80929
80930 /*
80931diff --git a/kernel/kexec.c b/kernel/kexec.c
80932index 59f7b55..4022f65 100644
80933--- a/kernel/kexec.c
80934+++ b/kernel/kexec.c
80935@@ -1041,7 +1041,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
80936 unsigned long flags)
80937 {
80938 struct compat_kexec_segment in;
80939- struct kexec_segment out, __user *ksegments;
80940+ struct kexec_segment out;
80941+ struct kexec_segment __user *ksegments;
80942 unsigned long i, result;
80943
80944 /* Don't allow clients that don't understand the native
80945diff --git a/kernel/kmod.c b/kernel/kmod.c
80946index fb32636..2fe8775 100644
80947--- a/kernel/kmod.c
80948+++ b/kernel/kmod.c
80949@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
80950 kfree(info->argv);
80951 }
80952
80953-static int call_modprobe(char *module_name, int wait)
80954+static int call_modprobe(char *module_name, char *module_param, int wait)
80955 {
80956 struct subprocess_info *info;
80957 static char *envp[] = {
80958@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
80959 NULL
80960 };
80961
80962- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
80963+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
80964 if (!argv)
80965 goto out;
80966
80967@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
80968 argv[1] = "-q";
80969 argv[2] = "--";
80970 argv[3] = module_name; /* check free_modprobe_argv() */
80971- argv[4] = NULL;
80972+ argv[4] = module_param;
80973+ argv[5] = NULL;
80974
80975 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
80976 NULL, free_modprobe_argv, NULL);
80977@@ -129,9 +130,8 @@ out:
80978 * If module auto-loading support is disabled then this function
80979 * becomes a no-operation.
80980 */
80981-int __request_module(bool wait, const char *fmt, ...)
80982+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
80983 {
80984- va_list args;
80985 char module_name[MODULE_NAME_LEN];
80986 unsigned int max_modprobes;
80987 int ret;
80988@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
80989 if (!modprobe_path[0])
80990 return 0;
80991
80992- va_start(args, fmt);
80993- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
80994- va_end(args);
80995+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
80996 if (ret >= MODULE_NAME_LEN)
80997 return -ENAMETOOLONG;
80998
80999@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
81000 if (ret)
81001 return ret;
81002
81003+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81004+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
81005+ /* hack to workaround consolekit/udisks stupidity */
81006+ read_lock(&tasklist_lock);
81007+ if (!strcmp(current->comm, "mount") &&
81008+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
81009+ read_unlock(&tasklist_lock);
81010+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
81011+ return -EPERM;
81012+ }
81013+ read_unlock(&tasklist_lock);
81014+ }
81015+#endif
81016+
81017 /* If modprobe needs a service that is in a module, we get a recursive
81018 * loop. Limit the number of running kmod threads to max_threads/2 or
81019 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
81020@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
81021
81022 trace_module_request(module_name, wait, _RET_IP_);
81023
81024- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
81025+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
81026
81027 atomic_dec(&kmod_concurrent);
81028 return ret;
81029 }
81030+
81031+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
81032+{
81033+ va_list args;
81034+ int ret;
81035+
81036+ va_start(args, fmt);
81037+ ret = ____request_module(wait, module_param, fmt, args);
81038+ va_end(args);
81039+
81040+ return ret;
81041+}
81042+
81043+int __request_module(bool wait, const char *fmt, ...)
81044+{
81045+ va_list args;
81046+ int ret;
81047+
81048+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81049+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
81050+ char module_param[MODULE_NAME_LEN];
81051+
81052+ memset(module_param, 0, sizeof(module_param));
81053+
81054+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
81055+
81056+ va_start(args, fmt);
81057+ ret = ____request_module(wait, module_param, fmt, args);
81058+ va_end(args);
81059+
81060+ return ret;
81061+ }
81062+#endif
81063+
81064+ va_start(args, fmt);
81065+ ret = ____request_module(wait, NULL, fmt, args);
81066+ va_end(args);
81067+
81068+ return ret;
81069+}
81070+
81071 EXPORT_SYMBOL(__request_module);
81072 #endif /* CONFIG_MODULES */
81073
81074@@ -303,7 +356,7 @@ static int wait_for_helper(void *data)
81075 *
81076 * Thus the __user pointer cast is valid here.
81077 */
81078- sys_wait4(pid, (int __user *)&ret, 0, NULL);
81079+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
81080
81081 /*
81082 * If ret is 0, either ____call_usermodehelper failed and the
81083@@ -646,7 +699,7 @@ EXPORT_SYMBOL(call_usermodehelper);
81084 static int proc_cap_handler(struct ctl_table *table, int write,
81085 void __user *buffer, size_t *lenp, loff_t *ppos)
81086 {
81087- struct ctl_table t;
81088+ ctl_table_no_const t;
81089 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
81090 kernel_cap_t new_cap;
81091 int err, i;
81092diff --git a/kernel/kprobes.c b/kernel/kprobes.c
81093index 6e33498..3133bd3 100644
81094--- a/kernel/kprobes.c
81095+++ b/kernel/kprobes.c
81096@@ -31,6 +31,9 @@
81097 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
81098 * <prasanna@in.ibm.com> added function-return probes.
81099 */
81100+#ifdef CONFIG_GRKERNSEC_HIDESYM
81101+#define __INCLUDED_BY_HIDESYM 1
81102+#endif
81103 #include <linux/kprobes.h>
81104 #include <linux/hash.h>
81105 #include <linux/init.h>
81106@@ -185,7 +188,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
81107 * kernel image and loaded module images reside. This is required
81108 * so x86_64 can correctly handle the %rip-relative fixups.
81109 */
81110- kip->insns = module_alloc(PAGE_SIZE);
81111+ kip->insns = module_alloc_exec(PAGE_SIZE);
81112 if (!kip->insns) {
81113 kfree(kip);
81114 return NULL;
81115@@ -225,7 +228,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
81116 */
81117 if (!list_is_singular(&kip->list)) {
81118 list_del(&kip->list);
81119- module_free(NULL, kip->insns);
81120+ module_free_exec(NULL, kip->insns);
81121 kfree(kip);
81122 }
81123 return 1;
81124@@ -2083,7 +2086,7 @@ static int __init init_kprobes(void)
81125 {
81126 int i, err = 0;
81127 unsigned long offset = 0, size = 0;
81128- char *modname, namebuf[128];
81129+ char *modname, namebuf[KSYM_NAME_LEN];
81130 const char *symbol_name;
81131 void *addr;
81132 struct kprobe_blackpoint *kb;
81133@@ -2168,11 +2171,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
81134 kprobe_type = "k";
81135
81136 if (sym)
81137- seq_printf(pi, "%p %s %s+0x%x %s ",
81138+ seq_printf(pi, "%pK %s %s+0x%x %s ",
81139 p->addr, kprobe_type, sym, offset,
81140 (modname ? modname : " "));
81141 else
81142- seq_printf(pi, "%p %s %p ",
81143+ seq_printf(pi, "%pK %s %pK ",
81144 p->addr, kprobe_type, p->addr);
81145
81146 if (!pp)
81147@@ -2209,7 +2212,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
81148 const char *sym = NULL;
81149 unsigned int i = *(loff_t *) v;
81150 unsigned long offset = 0;
81151- char *modname, namebuf[128];
81152+ char *modname, namebuf[KSYM_NAME_LEN];
81153
81154 head = &kprobe_table[i];
81155 preempt_disable();
81156diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
81157index 6ada93c..dce7d5d 100644
81158--- a/kernel/ksysfs.c
81159+++ b/kernel/ksysfs.c
81160@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
81161 {
81162 if (count+1 > UEVENT_HELPER_PATH_LEN)
81163 return -ENOENT;
81164+ if (!capable(CAP_SYS_ADMIN))
81165+ return -EPERM;
81166 memcpy(uevent_helper, buf, count);
81167 uevent_helper[count] = '\0';
81168 if (count && uevent_helper[count-1] == '\n')
81169@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
81170 return count;
81171 }
81172
81173-static struct bin_attribute notes_attr = {
81174+static bin_attribute_no_const notes_attr __read_only = {
81175 .attr = {
81176 .name = "notes",
81177 .mode = S_IRUGO,
81178diff --git a/kernel/lockdep.c b/kernel/lockdep.c
81179index e16c45b..6f49c48 100644
81180--- a/kernel/lockdep.c
81181+++ b/kernel/lockdep.c
81182@@ -596,6 +596,10 @@ static int static_obj(void *obj)
81183 end = (unsigned long) &_end,
81184 addr = (unsigned long) obj;
81185
81186+#ifdef CONFIG_PAX_KERNEXEC
81187+ start = ktla_ktva(start);
81188+#endif
81189+
81190 /*
81191 * static variable?
81192 */
81193@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
81194 if (!static_obj(lock->key)) {
81195 debug_locks_off();
81196 printk("INFO: trying to register non-static key.\n");
81197+ printk("lock:%pS key:%pS.\n", lock, lock->key);
81198 printk("the code is fine but needs lockdep annotation.\n");
81199 printk("turning off the locking correctness validator.\n");
81200 dump_stack();
81201@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
81202 if (!class)
81203 return 0;
81204 }
81205- atomic_inc((atomic_t *)&class->ops);
81206+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
81207 if (very_verbose(class)) {
81208 printk("\nacquire class [%p] %s", class->key, class->name);
81209 if (class->name_version > 1)
81210diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
81211index b2c71c5..7b88d63 100644
81212--- a/kernel/lockdep_proc.c
81213+++ b/kernel/lockdep_proc.c
81214@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
81215 return 0;
81216 }
81217
81218- seq_printf(m, "%p", class->key);
81219+ seq_printf(m, "%pK", class->key);
81220 #ifdef CONFIG_DEBUG_LOCKDEP
81221 seq_printf(m, " OPS:%8ld", class->ops);
81222 #endif
81223@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
81224
81225 list_for_each_entry(entry, &class->locks_after, entry) {
81226 if (entry->distance == 1) {
81227- seq_printf(m, " -> [%p] ", entry->class->key);
81228+ seq_printf(m, " -> [%pK] ", entry->class->key);
81229 print_name(m, entry->class);
81230 seq_puts(m, "\n");
81231 }
81232@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
81233 if (!class->key)
81234 continue;
81235
81236- seq_printf(m, "[%p] ", class->key);
81237+ seq_printf(m, "[%pK] ", class->key);
81238 print_name(m, class);
81239 seq_puts(m, "\n");
81240 }
81241@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
81242 if (!i)
81243 seq_line(m, '-', 40-namelen, namelen);
81244
81245- snprintf(ip, sizeof(ip), "[<%p>]",
81246+ snprintf(ip, sizeof(ip), "[<%pK>]",
81247 (void *)class->contention_point[i]);
81248 seq_printf(m, "%40s %14lu %29s %pS\n",
81249 name, stats->contention_point[i],
81250@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
81251 if (!i)
81252 seq_line(m, '-', 40-namelen, namelen);
81253
81254- snprintf(ip, sizeof(ip), "[<%p>]",
81255+ snprintf(ip, sizeof(ip), "[<%pK>]",
81256 (void *)class->contending_point[i]);
81257 seq_printf(m, "%40s %14lu %29s %pS\n",
81258 name, stats->contending_point[i],
81259diff --git a/kernel/module.c b/kernel/module.c
81260index 2069158..71101bb 100644
81261--- a/kernel/module.c
81262+++ b/kernel/module.c
81263@@ -61,6 +61,7 @@
81264 #include <linux/pfn.h>
81265 #include <linux/bsearch.h>
81266 #include <linux/fips.h>
81267+#include <linux/grsecurity.h>
81268 #include <uapi/linux/module.h>
81269 #include "module-internal.h"
81270
81271@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
81272
81273 /* Bounds of module allocation, for speeding __module_address.
81274 * Protected by module_mutex. */
81275-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
81276+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
81277+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
81278
81279 int register_module_notifier(struct notifier_block * nb)
81280 {
81281@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
81282 return true;
81283
81284 list_for_each_entry_rcu(mod, &modules, list) {
81285- struct symsearch arr[] = {
81286+ struct symsearch modarr[] = {
81287 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
81288 NOT_GPL_ONLY, false },
81289 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
81290@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
81291 if (mod->state == MODULE_STATE_UNFORMED)
81292 continue;
81293
81294- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
81295+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
81296 return true;
81297 }
81298 return false;
81299@@ -490,7 +492,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
81300 if (!pcpusec->sh_size)
81301 return 0;
81302
81303- if (align > PAGE_SIZE) {
81304+ if (align-1 >= PAGE_SIZE) {
81305 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
81306 mod->name, align, PAGE_SIZE);
81307 align = PAGE_SIZE;
81308@@ -1096,7 +1098,7 @@ struct module_attribute module_uevent =
81309 static ssize_t show_coresize(struct module_attribute *mattr,
81310 struct module_kobject *mk, char *buffer)
81311 {
81312- return sprintf(buffer, "%u\n", mk->mod->core_size);
81313+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
81314 }
81315
81316 static struct module_attribute modinfo_coresize =
81317@@ -1105,7 +1107,7 @@ static struct module_attribute modinfo_coresize =
81318 static ssize_t show_initsize(struct module_attribute *mattr,
81319 struct module_kobject *mk, char *buffer)
81320 {
81321- return sprintf(buffer, "%u\n", mk->mod->init_size);
81322+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
81323 }
81324
81325 static struct module_attribute modinfo_initsize =
81326@@ -1320,7 +1322,7 @@ resolve_symbol_wait(struct module *mod,
81327 */
81328 #ifdef CONFIG_SYSFS
81329
81330-#ifdef CONFIG_KALLSYMS
81331+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
81332 static inline bool sect_empty(const Elf_Shdr *sect)
81333 {
81334 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
81335@@ -1460,7 +1462,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
81336 {
81337 unsigned int notes, loaded, i;
81338 struct module_notes_attrs *notes_attrs;
81339- struct bin_attribute *nattr;
81340+ bin_attribute_no_const *nattr;
81341
81342 /* failed to create section attributes, so can't create notes */
81343 if (!mod->sect_attrs)
81344@@ -1572,7 +1574,7 @@ static void del_usage_links(struct module *mod)
81345 static int module_add_modinfo_attrs(struct module *mod)
81346 {
81347 struct module_attribute *attr;
81348- struct module_attribute *temp_attr;
81349+ module_attribute_no_const *temp_attr;
81350 int error = 0;
81351 int i;
81352
81353@@ -1786,21 +1788,21 @@ static void set_section_ro_nx(void *base,
81354
81355 static void unset_module_core_ro_nx(struct module *mod)
81356 {
81357- set_page_attributes(mod->module_core + mod->core_text_size,
81358- mod->module_core + mod->core_size,
81359+ set_page_attributes(mod->module_core_rw,
81360+ mod->module_core_rw + mod->core_size_rw,
81361 set_memory_x);
81362- set_page_attributes(mod->module_core,
81363- mod->module_core + mod->core_ro_size,
81364+ set_page_attributes(mod->module_core_rx,
81365+ mod->module_core_rx + mod->core_size_rx,
81366 set_memory_rw);
81367 }
81368
81369 static void unset_module_init_ro_nx(struct module *mod)
81370 {
81371- set_page_attributes(mod->module_init + mod->init_text_size,
81372- mod->module_init + mod->init_size,
81373+ set_page_attributes(mod->module_init_rw,
81374+ mod->module_init_rw + mod->init_size_rw,
81375 set_memory_x);
81376- set_page_attributes(mod->module_init,
81377- mod->module_init + mod->init_ro_size,
81378+ set_page_attributes(mod->module_init_rx,
81379+ mod->module_init_rx + mod->init_size_rx,
81380 set_memory_rw);
81381 }
81382
81383@@ -1813,14 +1815,14 @@ void set_all_modules_text_rw(void)
81384 list_for_each_entry_rcu(mod, &modules, list) {
81385 if (mod->state == MODULE_STATE_UNFORMED)
81386 continue;
81387- if ((mod->module_core) && (mod->core_text_size)) {
81388- set_page_attributes(mod->module_core,
81389- mod->module_core + mod->core_text_size,
81390+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81391+ set_page_attributes(mod->module_core_rx,
81392+ mod->module_core_rx + mod->core_size_rx,
81393 set_memory_rw);
81394 }
81395- if ((mod->module_init) && (mod->init_text_size)) {
81396- set_page_attributes(mod->module_init,
81397- mod->module_init + mod->init_text_size,
81398+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81399+ set_page_attributes(mod->module_init_rx,
81400+ mod->module_init_rx + mod->init_size_rx,
81401 set_memory_rw);
81402 }
81403 }
81404@@ -1836,14 +1838,14 @@ void set_all_modules_text_ro(void)
81405 list_for_each_entry_rcu(mod, &modules, list) {
81406 if (mod->state == MODULE_STATE_UNFORMED)
81407 continue;
81408- if ((mod->module_core) && (mod->core_text_size)) {
81409- set_page_attributes(mod->module_core,
81410- mod->module_core + mod->core_text_size,
81411+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81412+ set_page_attributes(mod->module_core_rx,
81413+ mod->module_core_rx + mod->core_size_rx,
81414 set_memory_ro);
81415 }
81416- if ((mod->module_init) && (mod->init_text_size)) {
81417- set_page_attributes(mod->module_init,
81418- mod->module_init + mod->init_text_size,
81419+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81420+ set_page_attributes(mod->module_init_rx,
81421+ mod->module_init_rx + mod->init_size_rx,
81422 set_memory_ro);
81423 }
81424 }
81425@@ -1894,16 +1896,19 @@ static void free_module(struct module *mod)
81426
81427 /* This may be NULL, but that's OK */
81428 unset_module_init_ro_nx(mod);
81429- module_free(mod, mod->module_init);
81430+ module_free(mod, mod->module_init_rw);
81431+ module_free_exec(mod, mod->module_init_rx);
81432 kfree(mod->args);
81433 percpu_modfree(mod);
81434
81435 /* Free lock-classes: */
81436- lockdep_free_key_range(mod->module_core, mod->core_size);
81437+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
81438+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
81439
81440 /* Finally, free the core (containing the module structure) */
81441 unset_module_core_ro_nx(mod);
81442- module_free(mod, mod->module_core);
81443+ module_free_exec(mod, mod->module_core_rx);
81444+ module_free(mod, mod->module_core_rw);
81445
81446 #ifdef CONFIG_MPU
81447 update_protections(current->mm);
81448@@ -1973,9 +1978,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81449 int ret = 0;
81450 const struct kernel_symbol *ksym;
81451
81452+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81453+ int is_fs_load = 0;
81454+ int register_filesystem_found = 0;
81455+ char *p;
81456+
81457+ p = strstr(mod->args, "grsec_modharden_fs");
81458+ if (p) {
81459+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
81460+ /* copy \0 as well */
81461+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
81462+ is_fs_load = 1;
81463+ }
81464+#endif
81465+
81466 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
81467 const char *name = info->strtab + sym[i].st_name;
81468
81469+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81470+ /* it's a real shame this will never get ripped and copied
81471+ upstream! ;(
81472+ */
81473+ if (is_fs_load && !strcmp(name, "register_filesystem"))
81474+ register_filesystem_found = 1;
81475+#endif
81476+
81477 switch (sym[i].st_shndx) {
81478 case SHN_COMMON:
81479 /* We compiled with -fno-common. These are not
81480@@ -1996,7 +2023,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81481 ksym = resolve_symbol_wait(mod, info, name);
81482 /* Ok if resolved. */
81483 if (ksym && !IS_ERR(ksym)) {
81484+ pax_open_kernel();
81485 sym[i].st_value = ksym->value;
81486+ pax_close_kernel();
81487 break;
81488 }
81489
81490@@ -2015,11 +2044,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81491 secbase = (unsigned long)mod_percpu(mod);
81492 else
81493 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
81494+ pax_open_kernel();
81495 sym[i].st_value += secbase;
81496+ pax_close_kernel();
81497 break;
81498 }
81499 }
81500
81501+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81502+ if (is_fs_load && !register_filesystem_found) {
81503+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
81504+ ret = -EPERM;
81505+ }
81506+#endif
81507+
81508 return ret;
81509 }
81510
81511@@ -2103,22 +2141,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
81512 || s->sh_entsize != ~0UL
81513 || strstarts(sname, ".init"))
81514 continue;
81515- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
81516+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81517+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
81518+ else
81519+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
81520 pr_debug("\t%s\n", sname);
81521 }
81522- switch (m) {
81523- case 0: /* executable */
81524- mod->core_size = debug_align(mod->core_size);
81525- mod->core_text_size = mod->core_size;
81526- break;
81527- case 1: /* RO: text and ro-data */
81528- mod->core_size = debug_align(mod->core_size);
81529- mod->core_ro_size = mod->core_size;
81530- break;
81531- case 3: /* whole core */
81532- mod->core_size = debug_align(mod->core_size);
81533- break;
81534- }
81535 }
81536
81537 pr_debug("Init section allocation order:\n");
81538@@ -2132,23 +2160,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
81539 || s->sh_entsize != ~0UL
81540 || !strstarts(sname, ".init"))
81541 continue;
81542- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
81543- | INIT_OFFSET_MASK);
81544+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81545+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
81546+ else
81547+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
81548+ s->sh_entsize |= INIT_OFFSET_MASK;
81549 pr_debug("\t%s\n", sname);
81550 }
81551- switch (m) {
81552- case 0: /* executable */
81553- mod->init_size = debug_align(mod->init_size);
81554- mod->init_text_size = mod->init_size;
81555- break;
81556- case 1: /* RO: text and ro-data */
81557- mod->init_size = debug_align(mod->init_size);
81558- mod->init_ro_size = mod->init_size;
81559- break;
81560- case 3: /* whole init */
81561- mod->init_size = debug_align(mod->init_size);
81562- break;
81563- }
81564 }
81565 }
81566
81567@@ -2321,7 +2339,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81568
81569 /* Put symbol section at end of init part of module. */
81570 symsect->sh_flags |= SHF_ALLOC;
81571- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
81572+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
81573 info->index.sym) | INIT_OFFSET_MASK;
81574 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
81575
81576@@ -2338,13 +2356,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81577 }
81578
81579 /* Append room for core symbols at end of core part. */
81580- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
81581- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
81582- mod->core_size += strtab_size;
81583+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
81584+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
81585+ mod->core_size_rx += strtab_size;
81586
81587 /* Put string table section at end of init part of module. */
81588 strsect->sh_flags |= SHF_ALLOC;
81589- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
81590+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
81591 info->index.str) | INIT_OFFSET_MASK;
81592 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
81593 }
81594@@ -2362,12 +2380,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81595 /* Make sure we get permanent strtab: don't use info->strtab. */
81596 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
81597
81598+ pax_open_kernel();
81599+
81600 /* Set types up while we still have access to sections. */
81601 for (i = 0; i < mod->num_symtab; i++)
81602 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
81603
81604- mod->core_symtab = dst = mod->module_core + info->symoffs;
81605- mod->core_strtab = s = mod->module_core + info->stroffs;
81606+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
81607+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
81608 src = mod->symtab;
81609 for (ndst = i = 0; i < mod->num_symtab; i++) {
81610 if (i == 0 ||
81611@@ -2379,6 +2399,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81612 }
81613 }
81614 mod->core_num_syms = ndst;
81615+
81616+ pax_close_kernel();
81617 }
81618 #else
81619 static inline void layout_symtab(struct module *mod, struct load_info *info)
81620@@ -2412,17 +2434,33 @@ void * __weak module_alloc(unsigned long size)
81621 return vmalloc_exec(size);
81622 }
81623
81624-static void *module_alloc_update_bounds(unsigned long size)
81625+static void *module_alloc_update_bounds_rw(unsigned long size)
81626 {
81627 void *ret = module_alloc(size);
81628
81629 if (ret) {
81630 mutex_lock(&module_mutex);
81631 /* Update module bounds. */
81632- if ((unsigned long)ret < module_addr_min)
81633- module_addr_min = (unsigned long)ret;
81634- if ((unsigned long)ret + size > module_addr_max)
81635- module_addr_max = (unsigned long)ret + size;
81636+ if ((unsigned long)ret < module_addr_min_rw)
81637+ module_addr_min_rw = (unsigned long)ret;
81638+ if ((unsigned long)ret + size > module_addr_max_rw)
81639+ module_addr_max_rw = (unsigned long)ret + size;
81640+ mutex_unlock(&module_mutex);
81641+ }
81642+ return ret;
81643+}
81644+
81645+static void *module_alloc_update_bounds_rx(unsigned long size)
81646+{
81647+ void *ret = module_alloc_exec(size);
81648+
81649+ if (ret) {
81650+ mutex_lock(&module_mutex);
81651+ /* Update module bounds. */
81652+ if ((unsigned long)ret < module_addr_min_rx)
81653+ module_addr_min_rx = (unsigned long)ret;
81654+ if ((unsigned long)ret + size > module_addr_max_rx)
81655+ module_addr_max_rx = (unsigned long)ret + size;
81656 mutex_unlock(&module_mutex);
81657 }
81658 return ret;
81659@@ -2698,8 +2736,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
81660 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81661 {
81662 const char *modmagic = get_modinfo(info, "vermagic");
81663+ const char *license = get_modinfo(info, "license");
81664 int err;
81665
81666+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
81667+ if (!license || !license_is_gpl_compatible(license))
81668+ return -ENOEXEC;
81669+#endif
81670+
81671 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
81672 modmagic = NULL;
81673
81674@@ -2725,7 +2769,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81675 }
81676
81677 /* Set up license info based on the info section */
81678- set_license(mod, get_modinfo(info, "license"));
81679+ set_license(mod, license);
81680
81681 return 0;
81682 }
81683@@ -2806,7 +2850,7 @@ static int move_module(struct module *mod, struct load_info *info)
81684 void *ptr;
81685
81686 /* Do the allocs. */
81687- ptr = module_alloc_update_bounds(mod->core_size);
81688+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
81689 /*
81690 * The pointer to this block is stored in the module structure
81691 * which is inside the block. Just mark it as not being a
81692@@ -2816,11 +2860,11 @@ static int move_module(struct module *mod, struct load_info *info)
81693 if (!ptr)
81694 return -ENOMEM;
81695
81696- memset(ptr, 0, mod->core_size);
81697- mod->module_core = ptr;
81698+ memset(ptr, 0, mod->core_size_rw);
81699+ mod->module_core_rw = ptr;
81700
81701- if (mod->init_size) {
81702- ptr = module_alloc_update_bounds(mod->init_size);
81703+ if (mod->init_size_rw) {
81704+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
81705 /*
81706 * The pointer to this block is stored in the module structure
81707 * which is inside the block. This block doesn't need to be
81708@@ -2829,13 +2873,45 @@ static int move_module(struct module *mod, struct load_info *info)
81709 */
81710 kmemleak_ignore(ptr);
81711 if (!ptr) {
81712- module_free(mod, mod->module_core);
81713+ module_free(mod, mod->module_core_rw);
81714 return -ENOMEM;
81715 }
81716- memset(ptr, 0, mod->init_size);
81717- mod->module_init = ptr;
81718+ memset(ptr, 0, mod->init_size_rw);
81719+ mod->module_init_rw = ptr;
81720 } else
81721- mod->module_init = NULL;
81722+ mod->module_init_rw = NULL;
81723+
81724+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
81725+ kmemleak_not_leak(ptr);
81726+ if (!ptr) {
81727+ if (mod->module_init_rw)
81728+ module_free(mod, mod->module_init_rw);
81729+ module_free(mod, mod->module_core_rw);
81730+ return -ENOMEM;
81731+ }
81732+
81733+ pax_open_kernel();
81734+ memset(ptr, 0, mod->core_size_rx);
81735+ pax_close_kernel();
81736+ mod->module_core_rx = ptr;
81737+
81738+ if (mod->init_size_rx) {
81739+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
81740+ kmemleak_ignore(ptr);
81741+ if (!ptr && mod->init_size_rx) {
81742+ module_free_exec(mod, mod->module_core_rx);
81743+ if (mod->module_init_rw)
81744+ module_free(mod, mod->module_init_rw);
81745+ module_free(mod, mod->module_core_rw);
81746+ return -ENOMEM;
81747+ }
81748+
81749+ pax_open_kernel();
81750+ memset(ptr, 0, mod->init_size_rx);
81751+ pax_close_kernel();
81752+ mod->module_init_rx = ptr;
81753+ } else
81754+ mod->module_init_rx = NULL;
81755
81756 /* Transfer each section which specifies SHF_ALLOC */
81757 pr_debug("final section addresses:\n");
81758@@ -2846,16 +2922,45 @@ static int move_module(struct module *mod, struct load_info *info)
81759 if (!(shdr->sh_flags & SHF_ALLOC))
81760 continue;
81761
81762- if (shdr->sh_entsize & INIT_OFFSET_MASK)
81763- dest = mod->module_init
81764- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81765- else
81766- dest = mod->module_core + shdr->sh_entsize;
81767+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
81768+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81769+ dest = mod->module_init_rw
81770+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81771+ else
81772+ dest = mod->module_init_rx
81773+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81774+ } else {
81775+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81776+ dest = mod->module_core_rw + shdr->sh_entsize;
81777+ else
81778+ dest = mod->module_core_rx + shdr->sh_entsize;
81779+ }
81780+
81781+ if (shdr->sh_type != SHT_NOBITS) {
81782+
81783+#ifdef CONFIG_PAX_KERNEXEC
81784+#ifdef CONFIG_X86_64
81785+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
81786+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
81787+#endif
81788+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
81789+ pax_open_kernel();
81790+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81791+ pax_close_kernel();
81792+ } else
81793+#endif
81794
81795- if (shdr->sh_type != SHT_NOBITS)
81796 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81797+ }
81798 /* Update sh_addr to point to copy in image. */
81799- shdr->sh_addr = (unsigned long)dest;
81800+
81801+#ifdef CONFIG_PAX_KERNEXEC
81802+ if (shdr->sh_flags & SHF_EXECINSTR)
81803+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
81804+ else
81805+#endif
81806+
81807+ shdr->sh_addr = (unsigned long)dest;
81808 pr_debug("\t0x%lx %s\n",
81809 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
81810 }
81811@@ -2912,12 +3017,12 @@ static void flush_module_icache(const struct module *mod)
81812 * Do it before processing of module parameters, so the module
81813 * can provide parameter accessor functions of its own.
81814 */
81815- if (mod->module_init)
81816- flush_icache_range((unsigned long)mod->module_init,
81817- (unsigned long)mod->module_init
81818- + mod->init_size);
81819- flush_icache_range((unsigned long)mod->module_core,
81820- (unsigned long)mod->module_core + mod->core_size);
81821+ if (mod->module_init_rx)
81822+ flush_icache_range((unsigned long)mod->module_init_rx,
81823+ (unsigned long)mod->module_init_rx
81824+ + mod->init_size_rx);
81825+ flush_icache_range((unsigned long)mod->module_core_rx,
81826+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
81827
81828 set_fs(old_fs);
81829 }
81830@@ -2974,8 +3079,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
81831 static void module_deallocate(struct module *mod, struct load_info *info)
81832 {
81833 percpu_modfree(mod);
81834- module_free(mod, mod->module_init);
81835- module_free(mod, mod->module_core);
81836+ module_free_exec(mod, mod->module_init_rx);
81837+ module_free_exec(mod, mod->module_core_rx);
81838+ module_free(mod, mod->module_init_rw);
81839+ module_free(mod, mod->module_core_rw);
81840 }
81841
81842 int __weak module_finalize(const Elf_Ehdr *hdr,
81843@@ -2988,7 +3095,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
81844 static int post_relocation(struct module *mod, const struct load_info *info)
81845 {
81846 /* Sort exception table now relocations are done. */
81847+ pax_open_kernel();
81848 sort_extable(mod->extable, mod->extable + mod->num_exentries);
81849+ pax_close_kernel();
81850
81851 /* Copy relocated percpu area over. */
81852 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
81853@@ -3042,16 +3151,16 @@ static int do_init_module(struct module *mod)
81854 MODULE_STATE_COMING, mod);
81855
81856 /* Set RO and NX regions for core */
81857- set_section_ro_nx(mod->module_core,
81858- mod->core_text_size,
81859- mod->core_ro_size,
81860- mod->core_size);
81861+ set_section_ro_nx(mod->module_core_rx,
81862+ mod->core_size_rx,
81863+ mod->core_size_rx,
81864+ mod->core_size_rx);
81865
81866 /* Set RO and NX regions for init */
81867- set_section_ro_nx(mod->module_init,
81868- mod->init_text_size,
81869- mod->init_ro_size,
81870- mod->init_size);
81871+ set_section_ro_nx(mod->module_init_rx,
81872+ mod->init_size_rx,
81873+ mod->init_size_rx,
81874+ mod->init_size_rx);
81875
81876 do_mod_ctors(mod);
81877 /* Start the module */
81878@@ -3113,11 +3222,12 @@ static int do_init_module(struct module *mod)
81879 mod->strtab = mod->core_strtab;
81880 #endif
81881 unset_module_init_ro_nx(mod);
81882- module_free(mod, mod->module_init);
81883- mod->module_init = NULL;
81884- mod->init_size = 0;
81885- mod->init_ro_size = 0;
81886- mod->init_text_size = 0;
81887+ module_free(mod, mod->module_init_rw);
81888+ module_free_exec(mod, mod->module_init_rx);
81889+ mod->module_init_rw = NULL;
81890+ mod->module_init_rx = NULL;
81891+ mod->init_size_rw = 0;
81892+ mod->init_size_rx = 0;
81893 mutex_unlock(&module_mutex);
81894 wake_up_all(&module_wq);
81895
81896@@ -3261,9 +3371,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
81897 if (err)
81898 goto free_unload;
81899
81900+ /* Now copy in args */
81901+ mod->args = strndup_user(uargs, ~0UL >> 1);
81902+ if (IS_ERR(mod->args)) {
81903+ err = PTR_ERR(mod->args);
81904+ goto free_unload;
81905+ }
81906+
81907 /* Set up MODINFO_ATTR fields */
81908 setup_modinfo(mod, info);
81909
81910+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81911+ {
81912+ char *p, *p2;
81913+
81914+ if (strstr(mod->args, "grsec_modharden_netdev")) {
81915+ 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);
81916+ err = -EPERM;
81917+ goto free_modinfo;
81918+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
81919+ p += sizeof("grsec_modharden_normal") - 1;
81920+ p2 = strstr(p, "_");
81921+ if (p2) {
81922+ *p2 = '\0';
81923+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
81924+ *p2 = '_';
81925+ }
81926+ err = -EPERM;
81927+ goto free_modinfo;
81928+ }
81929+ }
81930+#endif
81931+
81932 /* Fix up syms, so that st_value is a pointer to location. */
81933 err = simplify_symbols(mod, info);
81934 if (err < 0)
81935@@ -3279,13 +3418,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
81936
81937 flush_module_icache(mod);
81938
81939- /* Now copy in args */
81940- mod->args = strndup_user(uargs, ~0UL >> 1);
81941- if (IS_ERR(mod->args)) {
81942- err = PTR_ERR(mod->args);
81943- goto free_arch_cleanup;
81944- }
81945-
81946 dynamic_debug_setup(info->debug, info->num_debug);
81947
81948 /* Finally it's fully formed, ready to start executing. */
81949@@ -3320,11 +3452,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
81950 ddebug_cleanup:
81951 dynamic_debug_remove(info->debug);
81952 synchronize_sched();
81953- kfree(mod->args);
81954- free_arch_cleanup:
81955 module_arch_cleanup(mod);
81956 free_modinfo:
81957 free_modinfo(mod);
81958+ kfree(mod->args);
81959 free_unload:
81960 module_unload_free(mod);
81961 unlink_mod:
81962@@ -3407,10 +3538,16 @@ static const char *get_ksymbol(struct module *mod,
81963 unsigned long nextval;
81964
81965 /* At worse, next value is at end of module */
81966- if (within_module_init(addr, mod))
81967- nextval = (unsigned long)mod->module_init+mod->init_text_size;
81968+ if (within_module_init_rx(addr, mod))
81969+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
81970+ else if (within_module_init_rw(addr, mod))
81971+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
81972+ else if (within_module_core_rx(addr, mod))
81973+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
81974+ else if (within_module_core_rw(addr, mod))
81975+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
81976 else
81977- nextval = (unsigned long)mod->module_core+mod->core_text_size;
81978+ return NULL;
81979
81980 /* Scan for closest preceding symbol, and next symbol. (ELF
81981 starts real symbols at 1). */
81982@@ -3661,7 +3798,7 @@ static int m_show(struct seq_file *m, void *p)
81983 return 0;
81984
81985 seq_printf(m, "%s %u",
81986- mod->name, mod->init_size + mod->core_size);
81987+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
81988 print_unload_info(m, mod);
81989
81990 /* Informative for users. */
81991@@ -3670,7 +3807,7 @@ static int m_show(struct seq_file *m, void *p)
81992 mod->state == MODULE_STATE_COMING ? "Loading":
81993 "Live");
81994 /* Used by oprofile and other similar tools. */
81995- seq_printf(m, " 0x%pK", mod->module_core);
81996+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
81997
81998 /* Taints info */
81999 if (mod->taints)
82000@@ -3706,7 +3843,17 @@ static const struct file_operations proc_modules_operations = {
82001
82002 static int __init proc_modules_init(void)
82003 {
82004+#ifndef CONFIG_GRKERNSEC_HIDESYM
82005+#ifdef CONFIG_GRKERNSEC_PROC_USER
82006+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
82007+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82008+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
82009+#else
82010 proc_create("modules", 0, NULL, &proc_modules_operations);
82011+#endif
82012+#else
82013+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
82014+#endif
82015 return 0;
82016 }
82017 module_init(proc_modules_init);
82018@@ -3767,14 +3914,14 @@ struct module *__module_address(unsigned long addr)
82019 {
82020 struct module *mod;
82021
82022- if (addr < module_addr_min || addr > module_addr_max)
82023+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
82024+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
82025 return NULL;
82026
82027 list_for_each_entry_rcu(mod, &modules, list) {
82028 if (mod->state == MODULE_STATE_UNFORMED)
82029 continue;
82030- if (within_module_core(addr, mod)
82031- || within_module_init(addr, mod))
82032+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
82033 return mod;
82034 }
82035 return NULL;
82036@@ -3809,11 +3956,20 @@ bool is_module_text_address(unsigned long addr)
82037 */
82038 struct module *__module_text_address(unsigned long addr)
82039 {
82040- struct module *mod = __module_address(addr);
82041+ struct module *mod;
82042+
82043+#ifdef CONFIG_X86_32
82044+ addr = ktla_ktva(addr);
82045+#endif
82046+
82047+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
82048+ return NULL;
82049+
82050+ mod = __module_address(addr);
82051+
82052 if (mod) {
82053 /* Make sure it's within the text section. */
82054- if (!within(addr, mod->module_init, mod->init_text_size)
82055- && !within(addr, mod->module_core, mod->core_text_size))
82056+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
82057 mod = NULL;
82058 }
82059 return mod;
82060diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
82061index 7e3443f..b2a1e6b 100644
82062--- a/kernel/mutex-debug.c
82063+++ b/kernel/mutex-debug.c
82064@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
82065 }
82066
82067 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82068- struct thread_info *ti)
82069+ struct task_struct *task)
82070 {
82071 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
82072
82073 /* Mark the current thread as blocked on the lock: */
82074- ti->task->blocked_on = waiter;
82075+ task->blocked_on = waiter;
82076 }
82077
82078 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82079- struct thread_info *ti)
82080+ struct task_struct *task)
82081 {
82082 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
82083- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
82084- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
82085- ti->task->blocked_on = NULL;
82086+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
82087+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
82088+ task->blocked_on = NULL;
82089
82090 list_del_init(&waiter->list);
82091 waiter->task = NULL;
82092diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
82093index 0799fd3..d06ae3b 100644
82094--- a/kernel/mutex-debug.h
82095+++ b/kernel/mutex-debug.h
82096@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
82097 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
82098 extern void debug_mutex_add_waiter(struct mutex *lock,
82099 struct mutex_waiter *waiter,
82100- struct thread_info *ti);
82101+ struct task_struct *task);
82102 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82103- struct thread_info *ti);
82104+ struct task_struct *task);
82105 extern void debug_mutex_unlock(struct mutex *lock);
82106 extern void debug_mutex_init(struct mutex *lock, const char *name,
82107 struct lock_class_key *key);
82108diff --git a/kernel/mutex.c b/kernel/mutex.c
82109index a52ee7bb..f361f16 100644
82110--- a/kernel/mutex.c
82111+++ b/kernel/mutex.c
82112@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
82113 node->locked = 1;
82114 return;
82115 }
82116- ACCESS_ONCE(prev->next) = node;
82117+ ACCESS_ONCE_RW(prev->next) = node;
82118 smp_wmb();
82119 /* Wait until the lock holder passes the lock down */
82120 while (!ACCESS_ONCE(node->locked))
82121@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
82122 while (!(next = ACCESS_ONCE(node->next)))
82123 arch_mutex_cpu_relax();
82124 }
82125- ACCESS_ONCE(next->locked) = 1;
82126+ ACCESS_ONCE_RW(next->locked) = 1;
82127 smp_wmb();
82128 }
82129
82130@@ -514,7 +514,7 @@ slowpath:
82131 spin_lock_mutex(&lock->wait_lock, flags);
82132
82133 debug_mutex_lock_common(lock, &waiter);
82134- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
82135+ debug_mutex_add_waiter(lock, &waiter, task);
82136
82137 /* add waiting tasks to the end of the waitqueue (FIFO): */
82138 list_add_tail(&waiter.list, &lock->wait_list);
82139@@ -565,7 +565,7 @@ slowpath:
82140 done:
82141 lock_acquired(&lock->dep_map, ip);
82142 /* got the lock - rejoice! */
82143- mutex_remove_waiter(lock, &waiter, current_thread_info());
82144+ mutex_remove_waiter(lock, &waiter, task);
82145 mutex_set_owner(lock);
82146
82147 if (!__builtin_constant_p(ww_ctx == NULL)) {
82148@@ -604,7 +604,7 @@ done:
82149 return 0;
82150
82151 err:
82152- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
82153+ mutex_remove_waiter(lock, &waiter, task);
82154 spin_unlock_mutex(&lock->wait_lock, flags);
82155 debug_mutex_free_waiter(&waiter);
82156 mutex_release(&lock->dep_map, 1, ip);
82157diff --git a/kernel/notifier.c b/kernel/notifier.c
82158index 2d5cc4c..d9ea600 100644
82159--- a/kernel/notifier.c
82160+++ b/kernel/notifier.c
82161@@ -5,6 +5,7 @@
82162 #include <linux/rcupdate.h>
82163 #include <linux/vmalloc.h>
82164 #include <linux/reboot.h>
82165+#include <linux/mm.h>
82166
82167 /*
82168 * Notifier list for kernel code which wants to be called
82169@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
82170 while ((*nl) != NULL) {
82171 if (n->priority > (*nl)->priority)
82172 break;
82173- nl = &((*nl)->next);
82174+ nl = (struct notifier_block **)&((*nl)->next);
82175 }
82176- n->next = *nl;
82177+ pax_open_kernel();
82178+ *(const void **)&n->next = *nl;
82179 rcu_assign_pointer(*nl, n);
82180+ pax_close_kernel();
82181 return 0;
82182 }
82183
82184@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
82185 return 0;
82186 if (n->priority > (*nl)->priority)
82187 break;
82188- nl = &((*nl)->next);
82189+ nl = (struct notifier_block **)&((*nl)->next);
82190 }
82191- n->next = *nl;
82192+ pax_open_kernel();
82193+ *(const void **)&n->next = *nl;
82194 rcu_assign_pointer(*nl, n);
82195+ pax_close_kernel();
82196 return 0;
82197 }
82198
82199@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
82200 {
82201 while ((*nl) != NULL) {
82202 if ((*nl) == n) {
82203+ pax_open_kernel();
82204 rcu_assign_pointer(*nl, n->next);
82205+ pax_close_kernel();
82206 return 0;
82207 }
82208- nl = &((*nl)->next);
82209+ nl = (struct notifier_block **)&((*nl)->next);
82210 }
82211 return -ENOENT;
82212 }
82213diff --git a/kernel/panic.c b/kernel/panic.c
82214index 8018646..b6a5b4f 100644
82215--- a/kernel/panic.c
82216+++ b/kernel/panic.c
82217@@ -403,7 +403,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
82218 disable_trace_on_warning();
82219
82220 pr_warn("------------[ cut here ]------------\n");
82221- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
82222+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
82223 raw_smp_processor_id(), current->pid, file, line, caller);
82224
82225 if (args)
82226@@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
82227 */
82228 void __stack_chk_fail(void)
82229 {
82230- panic("stack-protector: Kernel stack is corrupted in: %p\n",
82231+ dump_stack();
82232+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
82233 __builtin_return_address(0));
82234 }
82235 EXPORT_SYMBOL(__stack_chk_fail);
82236diff --git a/kernel/pid.c b/kernel/pid.c
82237index 66505c1..87af12c 100644
82238--- a/kernel/pid.c
82239+++ b/kernel/pid.c
82240@@ -33,6 +33,7 @@
82241 #include <linux/rculist.h>
82242 #include <linux/bootmem.h>
82243 #include <linux/hash.h>
82244+#include <linux/security.h>
82245 #include <linux/pid_namespace.h>
82246 #include <linux/init_task.h>
82247 #include <linux/syscalls.h>
82248@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
82249
82250 int pid_max = PID_MAX_DEFAULT;
82251
82252-#define RESERVED_PIDS 300
82253+#define RESERVED_PIDS 500
82254
82255 int pid_max_min = RESERVED_PIDS + 1;
82256 int pid_max_max = PID_MAX_LIMIT;
82257@@ -439,10 +440,18 @@ EXPORT_SYMBOL(pid_task);
82258 */
82259 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
82260 {
82261+ struct task_struct *task;
82262+
82263 rcu_lockdep_assert(rcu_read_lock_held(),
82264 "find_task_by_pid_ns() needs rcu_read_lock()"
82265 " protection");
82266- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
82267+
82268+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
82269+
82270+ if (gr_pid_is_chrooted(task))
82271+ return NULL;
82272+
82273+ return task;
82274 }
82275
82276 struct task_struct *find_task_by_vpid(pid_t vnr)
82277@@ -450,6 +459,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
82278 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
82279 }
82280
82281+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
82282+{
82283+ rcu_lockdep_assert(rcu_read_lock_held(),
82284+ "find_task_by_pid_ns() needs rcu_read_lock()"
82285+ " protection");
82286+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
82287+}
82288+
82289 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
82290 {
82291 struct pid *pid;
82292diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
82293index 601bb36..f7e6f34 100644
82294--- a/kernel/pid_namespace.c
82295+++ b/kernel/pid_namespace.c
82296@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
82297 void __user *buffer, size_t *lenp, loff_t *ppos)
82298 {
82299 struct pid_namespace *pid_ns = task_active_pid_ns(current);
82300- struct ctl_table tmp = *table;
82301+ ctl_table_no_const tmp = *table;
82302
82303 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
82304 return -EPERM;
82305diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
82306index c7f31aa..2b44977 100644
82307--- a/kernel/posix-cpu-timers.c
82308+++ b/kernel/posix-cpu-timers.c
82309@@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
82310
82311 static __init int init_posix_cpu_timers(void)
82312 {
82313- struct k_clock process = {
82314+ static struct k_clock process = {
82315 .clock_getres = process_cpu_clock_getres,
82316 .clock_get = process_cpu_clock_get,
82317 .timer_create = process_cpu_timer_create,
82318 .nsleep = process_cpu_nsleep,
82319 .nsleep_restart = process_cpu_nsleep_restart,
82320 };
82321- struct k_clock thread = {
82322+ static struct k_clock thread = {
82323 .clock_getres = thread_cpu_clock_getres,
82324 .clock_get = thread_cpu_clock_get,
82325 .timer_create = thread_cpu_timer_create,
82326diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
82327index 424c2d4..679242f 100644
82328--- a/kernel/posix-timers.c
82329+++ b/kernel/posix-timers.c
82330@@ -43,6 +43,7 @@
82331 #include <linux/hash.h>
82332 #include <linux/posix-clock.h>
82333 #include <linux/posix-timers.h>
82334+#include <linux/grsecurity.h>
82335 #include <linux/syscalls.h>
82336 #include <linux/wait.h>
82337 #include <linux/workqueue.h>
82338@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
82339 * which we beg off on and pass to do_sys_settimeofday().
82340 */
82341
82342-static struct k_clock posix_clocks[MAX_CLOCKS];
82343+static struct k_clock *posix_clocks[MAX_CLOCKS];
82344
82345 /*
82346 * These ones are defined below.
82347@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
82348 */
82349 static __init int init_posix_timers(void)
82350 {
82351- struct k_clock clock_realtime = {
82352+ static struct k_clock clock_realtime = {
82353 .clock_getres = hrtimer_get_res,
82354 .clock_get = posix_clock_realtime_get,
82355 .clock_set = posix_clock_realtime_set,
82356@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
82357 .timer_get = common_timer_get,
82358 .timer_del = common_timer_del,
82359 };
82360- struct k_clock clock_monotonic = {
82361+ static struct k_clock clock_monotonic = {
82362 .clock_getres = hrtimer_get_res,
82363 .clock_get = posix_ktime_get_ts,
82364 .nsleep = common_nsleep,
82365@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
82366 .timer_get = common_timer_get,
82367 .timer_del = common_timer_del,
82368 };
82369- struct k_clock clock_monotonic_raw = {
82370+ static struct k_clock clock_monotonic_raw = {
82371 .clock_getres = hrtimer_get_res,
82372 .clock_get = posix_get_monotonic_raw,
82373 };
82374- struct k_clock clock_realtime_coarse = {
82375+ static struct k_clock clock_realtime_coarse = {
82376 .clock_getres = posix_get_coarse_res,
82377 .clock_get = posix_get_realtime_coarse,
82378 };
82379- struct k_clock clock_monotonic_coarse = {
82380+ static struct k_clock clock_monotonic_coarse = {
82381 .clock_getres = posix_get_coarse_res,
82382 .clock_get = posix_get_monotonic_coarse,
82383 };
82384- struct k_clock clock_tai = {
82385+ static struct k_clock clock_tai = {
82386 .clock_getres = hrtimer_get_res,
82387 .clock_get = posix_get_tai,
82388 .nsleep = common_nsleep,
82389@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
82390 .timer_get = common_timer_get,
82391 .timer_del = common_timer_del,
82392 };
82393- struct k_clock clock_boottime = {
82394+ static struct k_clock clock_boottime = {
82395 .clock_getres = hrtimer_get_res,
82396 .clock_get = posix_get_boottime,
82397 .nsleep = common_nsleep,
82398@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
82399 return;
82400 }
82401
82402- posix_clocks[clock_id] = *new_clock;
82403+ posix_clocks[clock_id] = new_clock;
82404 }
82405 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
82406
82407@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
82408 return (id & CLOCKFD_MASK) == CLOCKFD ?
82409 &clock_posix_dynamic : &clock_posix_cpu;
82410
82411- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
82412+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
82413 return NULL;
82414- return &posix_clocks[id];
82415+ return posix_clocks[id];
82416 }
82417
82418 static int common_timer_create(struct k_itimer *new_timer)
82419@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
82420 struct k_clock *kc = clockid_to_kclock(which_clock);
82421 struct k_itimer *new_timer;
82422 int error, new_timer_id;
82423- sigevent_t event;
82424+ sigevent_t event = { };
82425 int it_id_set = IT_ID_NOT_SET;
82426
82427 if (!kc)
82428@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
82429 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
82430 return -EFAULT;
82431
82432+ /* only the CLOCK_REALTIME clock can be set, all other clocks
82433+ have their clock_set fptr set to a nosettime dummy function
82434+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
82435+ call common_clock_set, which calls do_sys_settimeofday, which
82436+ we hook
82437+ */
82438+
82439 return kc->clock_set(which_clock, &new_tp);
82440 }
82441
82442diff --git a/kernel/power/process.c b/kernel/power/process.c
82443index 06ec886..9dba35e 100644
82444--- a/kernel/power/process.c
82445+++ b/kernel/power/process.c
82446@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
82447 unsigned int elapsed_msecs;
82448 bool wakeup = false;
82449 int sleep_usecs = USEC_PER_MSEC;
82450+ bool timedout = false;
82451
82452 do_gettimeofday(&start);
82453
82454@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
82455
82456 while (true) {
82457 todo = 0;
82458+ if (time_after(jiffies, end_time))
82459+ timedout = true;
82460 read_lock(&tasklist_lock);
82461 do_each_thread(g, p) {
82462 if (p == current || !freeze_task(p))
82463 continue;
82464
82465- if (!freezer_should_skip(p))
82466+ if (!freezer_should_skip(p)) {
82467 todo++;
82468+ if (timedout) {
82469+ printk(KERN_ERR "Task refusing to freeze:\n");
82470+ sched_show_task(p);
82471+ }
82472+ }
82473 } while_each_thread(g, p);
82474 read_unlock(&tasklist_lock);
82475
82476@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
82477 todo += wq_busy;
82478 }
82479
82480- if (!todo || time_after(jiffies, end_time))
82481+ if (!todo || timedout)
82482 break;
82483
82484 if (pm_wakeup_pending()) {
82485diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
82486index 5b5a708..ec7637e 100644
82487--- a/kernel/printk/printk.c
82488+++ b/kernel/printk/printk.c
82489@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
82490 if (from_file && type != SYSLOG_ACTION_OPEN)
82491 return 0;
82492
82493+#ifdef CONFIG_GRKERNSEC_DMESG
82494+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
82495+ return -EPERM;
82496+#endif
82497+
82498 if (syslog_action_restricted(type)) {
82499 if (capable(CAP_SYSLOG))
82500 return 0;
82501diff --git a/kernel/profile.c b/kernel/profile.c
82502index 6631e1e..310c266 100644
82503--- a/kernel/profile.c
82504+++ b/kernel/profile.c
82505@@ -37,7 +37,7 @@ struct profile_hit {
82506 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
82507 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
82508
82509-static atomic_t *prof_buffer;
82510+static atomic_unchecked_t *prof_buffer;
82511 static unsigned long prof_len, prof_shift;
82512
82513 int prof_on __read_mostly;
82514@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
82515 hits[i].pc = 0;
82516 continue;
82517 }
82518- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82519+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82520 hits[i].hits = hits[i].pc = 0;
82521 }
82522 }
82523@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82524 * Add the current hit(s) and flush the write-queue out
82525 * to the global buffer:
82526 */
82527- atomic_add(nr_hits, &prof_buffer[pc]);
82528+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
82529 for (i = 0; i < NR_PROFILE_HIT; ++i) {
82530- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82531+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82532 hits[i].pc = hits[i].hits = 0;
82533 }
82534 out:
82535@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82536 {
82537 unsigned long pc;
82538 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
82539- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82540+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82541 }
82542 #endif /* !CONFIG_SMP */
82543
82544@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
82545 return -EFAULT;
82546 buf++; p++; count--; read++;
82547 }
82548- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
82549+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
82550 if (copy_to_user(buf, (void *)pnt, count))
82551 return -EFAULT;
82552 read += count;
82553@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
82554 }
82555 #endif
82556 profile_discard_flip_buffers();
82557- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
82558+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
82559 return count;
82560 }
82561
82562diff --git a/kernel/ptrace.c b/kernel/ptrace.c
82563index a146ee3..ffed4c3 100644
82564--- a/kernel/ptrace.c
82565+++ b/kernel/ptrace.c
82566@@ -326,7 +326,7 @@ static int ptrace_attach(struct task_struct *task, long request,
82567 if (seize)
82568 flags |= PT_SEIZED;
82569 rcu_read_lock();
82570- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82571+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82572 flags |= PT_PTRACE_CAP;
82573 rcu_read_unlock();
82574 task->ptrace = flags;
82575@@ -537,7 +537,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
82576 break;
82577 return -EIO;
82578 }
82579- if (copy_to_user(dst, buf, retval))
82580+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
82581 return -EFAULT;
82582 copied += retval;
82583 src += retval;
82584@@ -805,7 +805,7 @@ int ptrace_request(struct task_struct *child, long request,
82585 bool seized = child->ptrace & PT_SEIZED;
82586 int ret = -EIO;
82587 siginfo_t siginfo, *si;
82588- void __user *datavp = (void __user *) data;
82589+ void __user *datavp = (__force void __user *) data;
82590 unsigned long __user *datalp = datavp;
82591 unsigned long flags;
82592
82593@@ -1051,14 +1051,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
82594 goto out;
82595 }
82596
82597+ if (gr_handle_ptrace(child, request)) {
82598+ ret = -EPERM;
82599+ goto out_put_task_struct;
82600+ }
82601+
82602 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82603 ret = ptrace_attach(child, request, addr, data);
82604 /*
82605 * Some architectures need to do book-keeping after
82606 * a ptrace attach.
82607 */
82608- if (!ret)
82609+ if (!ret) {
82610 arch_ptrace_attach(child);
82611+ gr_audit_ptrace(child);
82612+ }
82613 goto out_put_task_struct;
82614 }
82615
82616@@ -1086,7 +1093,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
82617 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
82618 if (copied != sizeof(tmp))
82619 return -EIO;
82620- return put_user(tmp, (unsigned long __user *)data);
82621+ return put_user(tmp, (__force unsigned long __user *)data);
82622 }
82623
82624 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
82625@@ -1180,7 +1187,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
82626 }
82627
82628 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82629- compat_long_t addr, compat_long_t data)
82630+ compat_ulong_t addr, compat_ulong_t data)
82631 {
82632 struct task_struct *child;
82633 long ret;
82634@@ -1196,14 +1203,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82635 goto out;
82636 }
82637
82638+ if (gr_handle_ptrace(child, request)) {
82639+ ret = -EPERM;
82640+ goto out_put_task_struct;
82641+ }
82642+
82643 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82644 ret = ptrace_attach(child, request, addr, data);
82645 /*
82646 * Some architectures need to do book-keeping after
82647 * a ptrace attach.
82648 */
82649- if (!ret)
82650+ if (!ret) {
82651 arch_ptrace_attach(child);
82652+ gr_audit_ptrace(child);
82653+ }
82654 goto out_put_task_struct;
82655 }
82656
82657diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
82658index cce6ba8..7c758b1f 100644
82659--- a/kernel/rcupdate.c
82660+++ b/kernel/rcupdate.c
82661@@ -412,10 +412,10 @@ int rcu_jiffies_till_stall_check(void)
82662 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
82663 */
82664 if (till_stall_check < 3) {
82665- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
82666+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
82667 till_stall_check = 3;
82668 } else if (till_stall_check > 300) {
82669- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
82670+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
82671 till_stall_check = 300;
82672 }
82673 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
82674diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
82675index aa34411..78e5ccb 100644
82676--- a/kernel/rcutiny.c
82677+++ b/kernel/rcutiny.c
82678@@ -45,7 +45,7 @@
82679 /* Forward declarations for rcutiny_plugin.h. */
82680 struct rcu_ctrlblk;
82681 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
82682-static void rcu_process_callbacks(struct softirq_action *unused);
82683+static void rcu_process_callbacks(void);
82684 static void __call_rcu(struct rcu_head *head,
82685 void (*func)(struct rcu_head *rcu),
82686 struct rcu_ctrlblk *rcp);
82687@@ -309,7 +309,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
82688 false));
82689 }
82690
82691-static void rcu_process_callbacks(struct softirq_action *unused)
82692+static void rcu_process_callbacks(void)
82693 {
82694 __rcu_process_callbacks(&rcu_sched_ctrlblk);
82695 __rcu_process_callbacks(&rcu_bh_ctrlblk);
82696diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
82697index f4871e5..8ef5741 100644
82698--- a/kernel/rcutorture.c
82699+++ b/kernel/rcutorture.c
82700@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
82701 { 0 };
82702 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
82703 { 0 };
82704-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82705-static atomic_t n_rcu_torture_alloc;
82706-static atomic_t n_rcu_torture_alloc_fail;
82707-static atomic_t n_rcu_torture_free;
82708-static atomic_t n_rcu_torture_mberror;
82709-static atomic_t n_rcu_torture_error;
82710+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82711+static atomic_unchecked_t n_rcu_torture_alloc;
82712+static atomic_unchecked_t n_rcu_torture_alloc_fail;
82713+static atomic_unchecked_t n_rcu_torture_free;
82714+static atomic_unchecked_t n_rcu_torture_mberror;
82715+static atomic_unchecked_t n_rcu_torture_error;
82716 static long n_rcu_torture_barrier_error;
82717 static long n_rcu_torture_boost_ktrerror;
82718 static long n_rcu_torture_boost_rterror;
82719@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
82720
82721 spin_lock_bh(&rcu_torture_lock);
82722 if (list_empty(&rcu_torture_freelist)) {
82723- atomic_inc(&n_rcu_torture_alloc_fail);
82724+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
82725 spin_unlock_bh(&rcu_torture_lock);
82726 return NULL;
82727 }
82728- atomic_inc(&n_rcu_torture_alloc);
82729+ atomic_inc_unchecked(&n_rcu_torture_alloc);
82730 p = rcu_torture_freelist.next;
82731 list_del_init(p);
82732 spin_unlock_bh(&rcu_torture_lock);
82733@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
82734 static void
82735 rcu_torture_free(struct rcu_torture *p)
82736 {
82737- atomic_inc(&n_rcu_torture_free);
82738+ atomic_inc_unchecked(&n_rcu_torture_free);
82739 spin_lock_bh(&rcu_torture_lock);
82740 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
82741 spin_unlock_bh(&rcu_torture_lock);
82742@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
82743 i = rp->rtort_pipe_count;
82744 if (i > RCU_TORTURE_PIPE_LEN)
82745 i = RCU_TORTURE_PIPE_LEN;
82746- atomic_inc(&rcu_torture_wcount[i]);
82747+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82748 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82749 rp->rtort_mbtest = 0;
82750 rcu_torture_free(rp);
82751@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
82752 i = rp->rtort_pipe_count;
82753 if (i > RCU_TORTURE_PIPE_LEN)
82754 i = RCU_TORTURE_PIPE_LEN;
82755- atomic_inc(&rcu_torture_wcount[i]);
82756+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82757 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82758 rp->rtort_mbtest = 0;
82759 list_del(&rp->rtort_free);
82760@@ -952,7 +952,7 @@ rcu_torture_writer(void *arg)
82761 i = old_rp->rtort_pipe_count;
82762 if (i > RCU_TORTURE_PIPE_LEN)
82763 i = RCU_TORTURE_PIPE_LEN;
82764- atomic_inc(&rcu_torture_wcount[i]);
82765+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82766 old_rp->rtort_pipe_count++;
82767 cur_ops->deferred_free(old_rp);
82768 }
82769@@ -1038,7 +1038,7 @@ static void rcu_torture_timer(unsigned long unused)
82770 return;
82771 }
82772 if (p->rtort_mbtest == 0)
82773- atomic_inc(&n_rcu_torture_mberror);
82774+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82775 spin_lock(&rand_lock);
82776 cur_ops->read_delay(&rand);
82777 n_rcu_torture_timers++;
82778@@ -1108,7 +1108,7 @@ rcu_torture_reader(void *arg)
82779 continue;
82780 }
82781 if (p->rtort_mbtest == 0)
82782- atomic_inc(&n_rcu_torture_mberror);
82783+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82784 cur_ops->read_delay(&rand);
82785 preempt_disable();
82786 pipe_count = p->rtort_pipe_count;
82787@@ -1171,11 +1171,11 @@ rcu_torture_printk(char *page)
82788 rcu_torture_current,
82789 rcu_torture_current_version,
82790 list_empty(&rcu_torture_freelist),
82791- atomic_read(&n_rcu_torture_alloc),
82792- atomic_read(&n_rcu_torture_alloc_fail),
82793- atomic_read(&n_rcu_torture_free));
82794+ atomic_read_unchecked(&n_rcu_torture_alloc),
82795+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
82796+ atomic_read_unchecked(&n_rcu_torture_free));
82797 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
82798- atomic_read(&n_rcu_torture_mberror),
82799+ atomic_read_unchecked(&n_rcu_torture_mberror),
82800 n_rcu_torture_boost_ktrerror,
82801 n_rcu_torture_boost_rterror);
82802 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
82803@@ -1194,14 +1194,14 @@ rcu_torture_printk(char *page)
82804 n_barrier_attempts,
82805 n_rcu_torture_barrier_error);
82806 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
82807- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
82808+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
82809 n_rcu_torture_barrier_error != 0 ||
82810 n_rcu_torture_boost_ktrerror != 0 ||
82811 n_rcu_torture_boost_rterror != 0 ||
82812 n_rcu_torture_boost_failure != 0 ||
82813 i > 1) {
82814 cnt += sprintf(&page[cnt], "!!! ");
82815- atomic_inc(&n_rcu_torture_error);
82816+ atomic_inc_unchecked(&n_rcu_torture_error);
82817 WARN_ON_ONCE(1);
82818 }
82819 cnt += sprintf(&page[cnt], "Reader Pipe: ");
82820@@ -1215,7 +1215,7 @@ rcu_torture_printk(char *page)
82821 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
82822 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82823 cnt += sprintf(&page[cnt], " %d",
82824- atomic_read(&rcu_torture_wcount[i]));
82825+ atomic_read_unchecked(&rcu_torture_wcount[i]));
82826 }
82827 cnt += sprintf(&page[cnt], "\n");
82828 if (cur_ops->stats)
82829@@ -1924,7 +1924,7 @@ rcu_torture_cleanup(void)
82830
82831 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
82832
82833- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82834+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82835 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
82836 else if (n_online_successes != n_online_attempts ||
82837 n_offline_successes != n_offline_attempts)
82838@@ -1992,18 +1992,18 @@ rcu_torture_init(void)
82839
82840 rcu_torture_current = NULL;
82841 rcu_torture_current_version = 0;
82842- atomic_set(&n_rcu_torture_alloc, 0);
82843- atomic_set(&n_rcu_torture_alloc_fail, 0);
82844- atomic_set(&n_rcu_torture_free, 0);
82845- atomic_set(&n_rcu_torture_mberror, 0);
82846- atomic_set(&n_rcu_torture_error, 0);
82847+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
82848+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
82849+ atomic_set_unchecked(&n_rcu_torture_free, 0);
82850+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
82851+ atomic_set_unchecked(&n_rcu_torture_error, 0);
82852 n_rcu_torture_barrier_error = 0;
82853 n_rcu_torture_boost_ktrerror = 0;
82854 n_rcu_torture_boost_rterror = 0;
82855 n_rcu_torture_boost_failure = 0;
82856 n_rcu_torture_boosts = 0;
82857 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
82858- atomic_set(&rcu_torture_wcount[i], 0);
82859+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
82860 for_each_possible_cpu(cpu) {
82861 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82862 per_cpu(rcu_torture_count, cpu)[i] = 0;
82863diff --git a/kernel/rcutree.c b/kernel/rcutree.c
82864index 068de3a..df7da65 100644
82865--- a/kernel/rcutree.c
82866+++ b/kernel/rcutree.c
82867@@ -358,9 +358,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
82868 rcu_prepare_for_idle(smp_processor_id());
82869 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
82870 smp_mb__before_atomic_inc(); /* See above. */
82871- atomic_inc(&rdtp->dynticks);
82872+ atomic_inc_unchecked(&rdtp->dynticks);
82873 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
82874- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
82875+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
82876
82877 /*
82878 * It is illegal to enter an extended quiescent state while
82879@@ -496,10 +496,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
82880 int user)
82881 {
82882 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
82883- atomic_inc(&rdtp->dynticks);
82884+ atomic_inc_unchecked(&rdtp->dynticks);
82885 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
82886 smp_mb__after_atomic_inc(); /* See above. */
82887- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
82888+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
82889 rcu_cleanup_after_idle(smp_processor_id());
82890 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
82891 if (!user && !is_idle_task(current)) {
82892@@ -638,14 +638,14 @@ void rcu_nmi_enter(void)
82893 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
82894
82895 if (rdtp->dynticks_nmi_nesting == 0 &&
82896- (atomic_read(&rdtp->dynticks) & 0x1))
82897+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
82898 return;
82899 rdtp->dynticks_nmi_nesting++;
82900 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
82901- atomic_inc(&rdtp->dynticks);
82902+ atomic_inc_unchecked(&rdtp->dynticks);
82903 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
82904 smp_mb__after_atomic_inc(); /* See above. */
82905- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
82906+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
82907 }
82908
82909 /**
82910@@ -664,9 +664,9 @@ void rcu_nmi_exit(void)
82911 return;
82912 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
82913 smp_mb__before_atomic_inc(); /* See above. */
82914- atomic_inc(&rdtp->dynticks);
82915+ atomic_inc_unchecked(&rdtp->dynticks);
82916 smp_mb__after_atomic_inc(); /* Force delay to next write. */
82917- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
82918+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
82919 }
82920
82921 /**
82922@@ -680,7 +680,7 @@ int rcu_is_cpu_idle(void)
82923 int ret;
82924
82925 preempt_disable();
82926- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
82927+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
82928 preempt_enable();
82929 return ret;
82930 }
82931@@ -748,7 +748,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
82932 */
82933 static int dyntick_save_progress_counter(struct rcu_data *rdp)
82934 {
82935- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
82936+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
82937 return (rdp->dynticks_snap & 0x1) == 0;
82938 }
82939
82940@@ -763,7 +763,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
82941 unsigned int curr;
82942 unsigned int snap;
82943
82944- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
82945+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
82946 snap = (unsigned int)rdp->dynticks_snap;
82947
82948 /*
82949@@ -1351,9 +1351,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
82950 rdp = this_cpu_ptr(rsp->rda);
82951 rcu_preempt_check_blocked_tasks(rnp);
82952 rnp->qsmask = rnp->qsmaskinit;
82953- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
82954+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
82955 WARN_ON_ONCE(rnp->completed != rsp->completed);
82956- ACCESS_ONCE(rnp->completed) = rsp->completed;
82957+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
82958 if (rnp == rdp->mynode)
82959 __note_gp_changes(rsp, rnp, rdp);
82960 rcu_preempt_boost_start_gp(rnp);
82961@@ -1435,7 +1435,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
82962 */
82963 rcu_for_each_node_breadth_first(rsp, rnp) {
82964 raw_spin_lock_irq(&rnp->lock);
82965- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
82966+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
82967 rdp = this_cpu_ptr(rsp->rda);
82968 if (rnp == rdp->mynode)
82969 __note_gp_changes(rsp, rnp, rdp);
82970@@ -1765,7 +1765,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
82971 rsp->qlen += rdp->qlen;
82972 rdp->n_cbs_orphaned += rdp->qlen;
82973 rdp->qlen_lazy = 0;
82974- ACCESS_ONCE(rdp->qlen) = 0;
82975+ ACCESS_ONCE_RW(rdp->qlen) = 0;
82976 }
82977
82978 /*
82979@@ -2011,7 +2011,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
82980 }
82981 smp_mb(); /* List handling before counting for rcu_barrier(). */
82982 rdp->qlen_lazy -= count_lazy;
82983- ACCESS_ONCE(rdp->qlen) -= count;
82984+ ACCESS_ONCE_RW(rdp->qlen) -= count;
82985 rdp->n_cbs_invoked += count;
82986
82987 /* Reinstate batch limit if we have worked down the excess. */
82988@@ -2202,7 +2202,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
82989 /*
82990 * Do RCU core processing for the current CPU.
82991 */
82992-static void rcu_process_callbacks(struct softirq_action *unused)
82993+static void rcu_process_callbacks(void)
82994 {
82995 struct rcu_state *rsp;
82996
82997@@ -2325,7 +2325,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
82998 local_irq_restore(flags);
82999 return;
83000 }
83001- ACCESS_ONCE(rdp->qlen)++;
83002+ ACCESS_ONCE_RW(rdp->qlen)++;
83003 if (lazy)
83004 rdp->qlen_lazy++;
83005 else
83006@@ -2534,11 +2534,11 @@ void synchronize_sched_expedited(void)
83007 * counter wrap on a 32-bit system. Quite a few more CPUs would of
83008 * course be required on a 64-bit system.
83009 */
83010- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
83011+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
83012 (ulong)atomic_long_read(&rsp->expedited_done) +
83013 ULONG_MAX / 8)) {
83014 synchronize_sched();
83015- atomic_long_inc(&rsp->expedited_wrap);
83016+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
83017 return;
83018 }
83019
83020@@ -2546,7 +2546,7 @@ void synchronize_sched_expedited(void)
83021 * Take a ticket. Note that atomic_inc_return() implies a
83022 * full memory barrier.
83023 */
83024- snap = atomic_long_inc_return(&rsp->expedited_start);
83025+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
83026 firstsnap = snap;
83027 get_online_cpus();
83028 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
83029@@ -2559,14 +2559,14 @@ void synchronize_sched_expedited(void)
83030 synchronize_sched_expedited_cpu_stop,
83031 NULL) == -EAGAIN) {
83032 put_online_cpus();
83033- atomic_long_inc(&rsp->expedited_tryfail);
83034+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
83035
83036 /* Check to see if someone else did our work for us. */
83037 s = atomic_long_read(&rsp->expedited_done);
83038 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
83039 /* ensure test happens before caller kfree */
83040 smp_mb__before_atomic_inc(); /* ^^^ */
83041- atomic_long_inc(&rsp->expedited_workdone1);
83042+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
83043 return;
83044 }
83045
83046@@ -2575,7 +2575,7 @@ void synchronize_sched_expedited(void)
83047 udelay(trycount * num_online_cpus());
83048 } else {
83049 wait_rcu_gp(call_rcu_sched);
83050- atomic_long_inc(&rsp->expedited_normal);
83051+ atomic_long_inc_unchecked(&rsp->expedited_normal);
83052 return;
83053 }
83054
83055@@ -2584,7 +2584,7 @@ void synchronize_sched_expedited(void)
83056 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
83057 /* ensure test happens before caller kfree */
83058 smp_mb__before_atomic_inc(); /* ^^^ */
83059- atomic_long_inc(&rsp->expedited_workdone2);
83060+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
83061 return;
83062 }
83063
83064@@ -2596,10 +2596,10 @@ void synchronize_sched_expedited(void)
83065 * period works for us.
83066 */
83067 get_online_cpus();
83068- snap = atomic_long_read(&rsp->expedited_start);
83069+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
83070 smp_mb(); /* ensure read is before try_stop_cpus(). */
83071 }
83072- atomic_long_inc(&rsp->expedited_stoppedcpus);
83073+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
83074
83075 /*
83076 * Everyone up to our most recent fetch is covered by our grace
83077@@ -2608,16 +2608,16 @@ void synchronize_sched_expedited(void)
83078 * than we did already did their update.
83079 */
83080 do {
83081- atomic_long_inc(&rsp->expedited_done_tries);
83082+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
83083 s = atomic_long_read(&rsp->expedited_done);
83084 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
83085 /* ensure test happens before caller kfree */
83086 smp_mb__before_atomic_inc(); /* ^^^ */
83087- atomic_long_inc(&rsp->expedited_done_lost);
83088+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
83089 break;
83090 }
83091 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
83092- atomic_long_inc(&rsp->expedited_done_exit);
83093+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
83094
83095 put_online_cpus();
83096 }
83097@@ -2799,7 +2799,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
83098 * ACCESS_ONCE() to prevent the compiler from speculating
83099 * the increment to precede the early-exit check.
83100 */
83101- ACCESS_ONCE(rsp->n_barrier_done)++;
83102+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
83103 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
83104 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
83105 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
83106@@ -2849,7 +2849,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
83107
83108 /* Increment ->n_barrier_done to prevent duplicate work. */
83109 smp_mb(); /* Keep increment after above mechanism. */
83110- ACCESS_ONCE(rsp->n_barrier_done)++;
83111+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
83112 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
83113 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
83114 smp_mb(); /* Keep increment before caller's subsequent code. */
83115@@ -2894,10 +2894,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
83116 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
83117 init_callback_list(rdp);
83118 rdp->qlen_lazy = 0;
83119- ACCESS_ONCE(rdp->qlen) = 0;
83120+ ACCESS_ONCE_RW(rdp->qlen) = 0;
83121 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
83122 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
83123- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
83124+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
83125 rdp->cpu = cpu;
83126 rdp->rsp = rsp;
83127 rcu_boot_init_nocb_percpu_data(rdp);
83128@@ -2930,8 +2930,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
83129 rdp->blimit = blimit;
83130 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
83131 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
83132- atomic_set(&rdp->dynticks->dynticks,
83133- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
83134+ atomic_set_unchecked(&rdp->dynticks->dynticks,
83135+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
83136 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
83137
83138 /* Add CPU to rcu_node bitmasks. */
83139diff --git a/kernel/rcutree.h b/kernel/rcutree.h
83140index b383258..2440c1e 100644
83141--- a/kernel/rcutree.h
83142+++ b/kernel/rcutree.h
83143@@ -87,7 +87,7 @@ struct rcu_dynticks {
83144 long long dynticks_nesting; /* Track irq/process nesting level. */
83145 /* Process level is worth LLONG_MAX/2. */
83146 int dynticks_nmi_nesting; /* Track NMI nesting level. */
83147- atomic_t dynticks; /* Even value for idle, else odd. */
83148+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
83149 #ifdef CONFIG_RCU_FAST_NO_HZ
83150 bool all_lazy; /* Are all CPU's CBs lazy? */
83151 unsigned long nonlazy_posted;
83152@@ -419,17 +419,17 @@ struct rcu_state {
83153 /* _rcu_barrier(). */
83154 /* End of fields guarded by barrier_mutex. */
83155
83156- atomic_long_t expedited_start; /* Starting ticket. */
83157- atomic_long_t expedited_done; /* Done ticket. */
83158- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
83159- atomic_long_t expedited_tryfail; /* # acquisition failures. */
83160- atomic_long_t expedited_workdone1; /* # done by others #1. */
83161- atomic_long_t expedited_workdone2; /* # done by others #2. */
83162- atomic_long_t expedited_normal; /* # fallbacks to normal. */
83163- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
83164- atomic_long_t expedited_done_tries; /* # tries to update _done. */
83165- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
83166- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
83167+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
83168+ atomic_long_t expedited_done; /* Done ticket. */
83169+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
83170+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
83171+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
83172+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
83173+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
83174+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
83175+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
83176+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
83177+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
83178
83179 unsigned long jiffies_force_qs; /* Time at which to invoke */
83180 /* force_quiescent_state(). */
83181diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
83182index 769e12e..7b2139b 100644
83183--- a/kernel/rcutree_plugin.h
83184+++ b/kernel/rcutree_plugin.h
83185@@ -902,7 +902,7 @@ void synchronize_rcu_expedited(void)
83186
83187 /* Clean up and exit. */
83188 smp_mb(); /* ensure expedited GP seen before counter increment. */
83189- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
83190+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
83191 unlock_mb_ret:
83192 mutex_unlock(&sync_rcu_preempt_exp_mutex);
83193 mb_ret:
83194@@ -1476,7 +1476,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
83195 free_cpumask_var(cm);
83196 }
83197
83198-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
83199+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
83200 .store = &rcu_cpu_kthread_task,
83201 .thread_should_run = rcu_cpu_kthread_should_run,
83202 .thread_fn = rcu_cpu_kthread,
83203@@ -1941,7 +1941,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
83204 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
83205 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
83206 cpu, ticks_value, ticks_title,
83207- atomic_read(&rdtp->dynticks) & 0xfff,
83208+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
83209 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
83210 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
83211 fast_no_hz);
83212@@ -2104,7 +2104,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
83213
83214 /* Enqueue the callback on the nocb list and update counts. */
83215 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
83216- ACCESS_ONCE(*old_rhpp) = rhp;
83217+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
83218 atomic_long_add(rhcount, &rdp->nocb_q_count);
83219 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
83220
83221@@ -2244,12 +2244,12 @@ static int rcu_nocb_kthread(void *arg)
83222 * Extract queued callbacks, update counts, and wait
83223 * for a grace period to elapse.
83224 */
83225- ACCESS_ONCE(rdp->nocb_head) = NULL;
83226+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
83227 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
83228 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
83229 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
83230- ACCESS_ONCE(rdp->nocb_p_count) += c;
83231- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
83232+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
83233+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
83234 rcu_nocb_wait_gp(rdp);
83235
83236 /* Each pass through the following loop invokes a callback. */
83237@@ -2271,8 +2271,8 @@ static int rcu_nocb_kthread(void *arg)
83238 list = next;
83239 }
83240 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
83241- ACCESS_ONCE(rdp->nocb_p_count) -= c;
83242- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
83243+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
83244+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
83245 rdp->n_nocbs_invoked += c;
83246 }
83247 return 0;
83248@@ -2299,7 +2299,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
83249 t = kthread_run(rcu_nocb_kthread, rdp,
83250 "rcuo%c/%d", rsp->abbr, cpu);
83251 BUG_ON(IS_ERR(t));
83252- ACCESS_ONCE(rdp->nocb_kthread) = t;
83253+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
83254 }
83255 }
83256
83257diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
83258index cf6c174..a8f4b50 100644
83259--- a/kernel/rcutree_trace.c
83260+++ b/kernel/rcutree_trace.c
83261@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
83262 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
83263 rdp->passed_quiesce, rdp->qs_pending);
83264 seq_printf(m, " dt=%d/%llx/%d df=%lu",
83265- atomic_read(&rdp->dynticks->dynticks),
83266+ atomic_read_unchecked(&rdp->dynticks->dynticks),
83267 rdp->dynticks->dynticks_nesting,
83268 rdp->dynticks->dynticks_nmi_nesting,
83269 rdp->dynticks_fqs);
83270@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
83271 struct rcu_state *rsp = (struct rcu_state *)m->private;
83272
83273 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",
83274- atomic_long_read(&rsp->expedited_start),
83275+ atomic_long_read_unchecked(&rsp->expedited_start),
83276 atomic_long_read(&rsp->expedited_done),
83277- atomic_long_read(&rsp->expedited_wrap),
83278- atomic_long_read(&rsp->expedited_tryfail),
83279- atomic_long_read(&rsp->expedited_workdone1),
83280- atomic_long_read(&rsp->expedited_workdone2),
83281- atomic_long_read(&rsp->expedited_normal),
83282- atomic_long_read(&rsp->expedited_stoppedcpus),
83283- atomic_long_read(&rsp->expedited_done_tries),
83284- atomic_long_read(&rsp->expedited_done_lost),
83285- atomic_long_read(&rsp->expedited_done_exit));
83286+ atomic_long_read_unchecked(&rsp->expedited_wrap),
83287+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
83288+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
83289+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
83290+ atomic_long_read_unchecked(&rsp->expedited_normal),
83291+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
83292+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
83293+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
83294+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
83295 return 0;
83296 }
83297
83298diff --git a/kernel/resource.c b/kernel/resource.c
83299index 3f285dc..5755f62 100644
83300--- a/kernel/resource.c
83301+++ b/kernel/resource.c
83302@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
83303
83304 static int __init ioresources_init(void)
83305 {
83306+#ifdef CONFIG_GRKERNSEC_PROC_ADD
83307+#ifdef CONFIG_GRKERNSEC_PROC_USER
83308+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
83309+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
83310+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83311+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
83312+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
83313+#endif
83314+#else
83315 proc_create("ioports", 0, NULL, &proc_ioports_operations);
83316 proc_create("iomem", 0, NULL, &proc_iomem_operations);
83317+#endif
83318 return 0;
83319 }
83320 __initcall(ioresources_init);
83321diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
83322index 1d96dd0..994ff19 100644
83323--- a/kernel/rtmutex-tester.c
83324+++ b/kernel/rtmutex-tester.c
83325@@ -22,7 +22,7 @@
83326 #define MAX_RT_TEST_MUTEXES 8
83327
83328 static spinlock_t rttest_lock;
83329-static atomic_t rttest_event;
83330+static atomic_unchecked_t rttest_event;
83331
83332 struct test_thread_data {
83333 int opcode;
83334@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83335
83336 case RTTEST_LOCKCONT:
83337 td->mutexes[td->opdata] = 1;
83338- td->event = atomic_add_return(1, &rttest_event);
83339+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83340 return 0;
83341
83342 case RTTEST_RESET:
83343@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83344 return 0;
83345
83346 case RTTEST_RESETEVENT:
83347- atomic_set(&rttest_event, 0);
83348+ atomic_set_unchecked(&rttest_event, 0);
83349 return 0;
83350
83351 default:
83352@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83353 return ret;
83354
83355 td->mutexes[id] = 1;
83356- td->event = atomic_add_return(1, &rttest_event);
83357+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83358 rt_mutex_lock(&mutexes[id]);
83359- td->event = atomic_add_return(1, &rttest_event);
83360+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83361 td->mutexes[id] = 4;
83362 return 0;
83363
83364@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83365 return ret;
83366
83367 td->mutexes[id] = 1;
83368- td->event = atomic_add_return(1, &rttest_event);
83369+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83370 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
83371- td->event = atomic_add_return(1, &rttest_event);
83372+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83373 td->mutexes[id] = ret ? 0 : 4;
83374 return ret ? -EINTR : 0;
83375
83376@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83377 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
83378 return ret;
83379
83380- td->event = atomic_add_return(1, &rttest_event);
83381+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83382 rt_mutex_unlock(&mutexes[id]);
83383- td->event = atomic_add_return(1, &rttest_event);
83384+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83385 td->mutexes[id] = 0;
83386 return 0;
83387
83388@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83389 break;
83390
83391 td->mutexes[dat] = 2;
83392- td->event = atomic_add_return(1, &rttest_event);
83393+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83394 break;
83395
83396 default:
83397@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83398 return;
83399
83400 td->mutexes[dat] = 3;
83401- td->event = atomic_add_return(1, &rttest_event);
83402+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83403 break;
83404
83405 case RTTEST_LOCKNOWAIT:
83406@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83407 return;
83408
83409 td->mutexes[dat] = 1;
83410- td->event = atomic_add_return(1, &rttest_event);
83411+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83412 return;
83413
83414 default:
83415diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
83416index 4a07353..66b5291 100644
83417--- a/kernel/sched/auto_group.c
83418+++ b/kernel/sched/auto_group.c
83419@@ -11,7 +11,7 @@
83420
83421 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
83422 static struct autogroup autogroup_default;
83423-static atomic_t autogroup_seq_nr;
83424+static atomic_unchecked_t autogroup_seq_nr;
83425
83426 void __init autogroup_init(struct task_struct *init_task)
83427 {
83428@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
83429
83430 kref_init(&ag->kref);
83431 init_rwsem(&ag->lock);
83432- ag->id = atomic_inc_return(&autogroup_seq_nr);
83433+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
83434 ag->tg = tg;
83435 #ifdef CONFIG_RT_GROUP_SCHED
83436 /*
83437diff --git a/kernel/sched/core.c b/kernel/sched/core.c
83438index 05c39f0..442e6fe 100644
83439--- a/kernel/sched/core.c
83440+++ b/kernel/sched/core.c
83441@@ -2885,7 +2885,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
83442 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83443 * or number of jiffies left till timeout) if completed.
83444 */
83445-long __sched
83446+long __sched __intentional_overflow(-1)
83447 wait_for_completion_interruptible_timeout(struct completion *x,
83448 unsigned long timeout)
83449 {
83450@@ -2902,7 +2902,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
83451 *
83452 * Return: -ERESTARTSYS if interrupted, 0 if completed.
83453 */
83454-int __sched wait_for_completion_killable(struct completion *x)
83455+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
83456 {
83457 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
83458 if (t == -ERESTARTSYS)
83459@@ -2923,7 +2923,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
83460 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83461 * or number of jiffies left till timeout) if completed.
83462 */
83463-long __sched
83464+long __sched __intentional_overflow(-1)
83465 wait_for_completion_killable_timeout(struct completion *x,
83466 unsigned long timeout)
83467 {
83468@@ -3149,6 +3149,8 @@ int can_nice(const struct task_struct *p, const int nice)
83469 /* convert nice value [19,-20] to rlimit style value [1,40] */
83470 int nice_rlim = 20 - nice;
83471
83472+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
83473+
83474 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
83475 capable(CAP_SYS_NICE));
83476 }
83477@@ -3182,7 +3184,8 @@ SYSCALL_DEFINE1(nice, int, increment)
83478 if (nice > 19)
83479 nice = 19;
83480
83481- if (increment < 0 && !can_nice(current, nice))
83482+ if (increment < 0 && (!can_nice(current, nice) ||
83483+ gr_handle_chroot_nice()))
83484 return -EPERM;
83485
83486 retval = security_task_setnice(current, nice);
83487@@ -3344,6 +3347,7 @@ recheck:
83488 unsigned long rlim_rtprio =
83489 task_rlimit(p, RLIMIT_RTPRIO);
83490
83491+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
83492 /* can't set/change the rt policy */
83493 if (policy != p->policy && !rlim_rtprio)
83494 return -EPERM;
83495@@ -4473,7 +4477,7 @@ static void migrate_tasks(unsigned int dead_cpu)
83496
83497 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
83498
83499-static struct ctl_table sd_ctl_dir[] = {
83500+static ctl_table_no_const sd_ctl_dir[] __read_only = {
83501 {
83502 .procname = "sched_domain",
83503 .mode = 0555,
83504@@ -4490,17 +4494,17 @@ static struct ctl_table sd_ctl_root[] = {
83505 {}
83506 };
83507
83508-static struct ctl_table *sd_alloc_ctl_entry(int n)
83509+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
83510 {
83511- struct ctl_table *entry =
83512+ ctl_table_no_const *entry =
83513 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
83514
83515 return entry;
83516 }
83517
83518-static void sd_free_ctl_entry(struct ctl_table **tablep)
83519+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
83520 {
83521- struct ctl_table *entry;
83522+ ctl_table_no_const *entry;
83523
83524 /*
83525 * In the intermediate directories, both the child directory and
83526@@ -4508,22 +4512,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
83527 * will always be set. In the lowest directory the names are
83528 * static strings and all have proc handlers.
83529 */
83530- for (entry = *tablep; entry->mode; entry++) {
83531- if (entry->child)
83532- sd_free_ctl_entry(&entry->child);
83533+ for (entry = tablep; entry->mode; entry++) {
83534+ if (entry->child) {
83535+ sd_free_ctl_entry(entry->child);
83536+ pax_open_kernel();
83537+ entry->child = NULL;
83538+ pax_close_kernel();
83539+ }
83540 if (entry->proc_handler == NULL)
83541 kfree(entry->procname);
83542 }
83543
83544- kfree(*tablep);
83545- *tablep = NULL;
83546+ kfree(tablep);
83547 }
83548
83549 static int min_load_idx = 0;
83550 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
83551
83552 static void
83553-set_table_entry(struct ctl_table *entry,
83554+set_table_entry(ctl_table_no_const *entry,
83555 const char *procname, void *data, int maxlen,
83556 umode_t mode, proc_handler *proc_handler,
83557 bool load_idx)
83558@@ -4543,7 +4550,7 @@ set_table_entry(struct ctl_table *entry,
83559 static struct ctl_table *
83560 sd_alloc_ctl_domain_table(struct sched_domain *sd)
83561 {
83562- struct ctl_table *table = sd_alloc_ctl_entry(13);
83563+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
83564
83565 if (table == NULL)
83566 return NULL;
83567@@ -4578,9 +4585,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
83568 return table;
83569 }
83570
83571-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
83572+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
83573 {
83574- struct ctl_table *entry, *table;
83575+ ctl_table_no_const *entry, *table;
83576 struct sched_domain *sd;
83577 int domain_num = 0, i;
83578 char buf[32];
83579@@ -4607,11 +4614,13 @@ static struct ctl_table_header *sd_sysctl_header;
83580 static void register_sched_domain_sysctl(void)
83581 {
83582 int i, cpu_num = num_possible_cpus();
83583- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
83584+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
83585 char buf[32];
83586
83587 WARN_ON(sd_ctl_dir[0].child);
83588+ pax_open_kernel();
83589 sd_ctl_dir[0].child = entry;
83590+ pax_close_kernel();
83591
83592 if (entry == NULL)
83593 return;
83594@@ -4634,8 +4643,12 @@ static void unregister_sched_domain_sysctl(void)
83595 if (sd_sysctl_header)
83596 unregister_sysctl_table(sd_sysctl_header);
83597 sd_sysctl_header = NULL;
83598- if (sd_ctl_dir[0].child)
83599- sd_free_ctl_entry(&sd_ctl_dir[0].child);
83600+ if (sd_ctl_dir[0].child) {
83601+ sd_free_ctl_entry(sd_ctl_dir[0].child);
83602+ pax_open_kernel();
83603+ sd_ctl_dir[0].child = NULL;
83604+ pax_close_kernel();
83605+ }
83606 }
83607 #else
83608 static void register_sched_domain_sysctl(void)
83609diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
83610index 68f1609..640ba13 100644
83611--- a/kernel/sched/fair.c
83612+++ b/kernel/sched/fair.c
83613@@ -869,7 +869,7 @@ void task_numa_fault(int node, int pages, bool migrated)
83614
83615 static void reset_ptenuma_scan(struct task_struct *p)
83616 {
83617- ACCESS_ONCE(p->mm->numa_scan_seq)++;
83618+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
83619 p->mm->numa_scan_offset = 0;
83620 }
83621
83622@@ -5727,7 +5727,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
83623 * run_rebalance_domains is triggered when needed from the scheduler tick.
83624 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
83625 */
83626-static void run_rebalance_domains(struct softirq_action *h)
83627+static void run_rebalance_domains(void)
83628 {
83629 int this_cpu = smp_processor_id();
83630 struct rq *this_rq = cpu_rq(this_cpu);
83631diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
83632index ef0a7b2..1b728c1 100644
83633--- a/kernel/sched/sched.h
83634+++ b/kernel/sched/sched.h
83635@@ -1004,7 +1004,7 @@ struct sched_class {
83636 #ifdef CONFIG_FAIR_GROUP_SCHED
83637 void (*task_move_group) (struct task_struct *p, int on_rq);
83638 #endif
83639-};
83640+} __do_const;
83641
83642 #define sched_class_highest (&stop_sched_class)
83643 #define for_each_class(class) \
83644diff --git a/kernel/signal.c b/kernel/signal.c
83645index 50e4107..08bcb94 100644
83646--- a/kernel/signal.c
83647+++ b/kernel/signal.c
83648@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
83649
83650 int print_fatal_signals __read_mostly;
83651
83652-static void __user *sig_handler(struct task_struct *t, int sig)
83653+static __sighandler_t sig_handler(struct task_struct *t, int sig)
83654 {
83655 return t->sighand->action[sig - 1].sa.sa_handler;
83656 }
83657
83658-static int sig_handler_ignored(void __user *handler, int sig)
83659+static int sig_handler_ignored(__sighandler_t handler, int sig)
83660 {
83661 /* Is it explicitly or implicitly ignored? */
83662 return handler == SIG_IGN ||
83663@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
83664
83665 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
83666 {
83667- void __user *handler;
83668+ __sighandler_t handler;
83669
83670 handler = sig_handler(t, sig);
83671
83672@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
83673 atomic_inc(&user->sigpending);
83674 rcu_read_unlock();
83675
83676+ if (!override_rlimit)
83677+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
83678+
83679 if (override_rlimit ||
83680 atomic_read(&user->sigpending) <=
83681 task_rlimit(t, RLIMIT_SIGPENDING)) {
83682@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
83683
83684 int unhandled_signal(struct task_struct *tsk, int sig)
83685 {
83686- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
83687+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
83688 if (is_global_init(tsk))
83689 return 1;
83690 if (handler != SIG_IGN && handler != SIG_DFL)
83691@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
83692 }
83693 }
83694
83695+ /* allow glibc communication via tgkill to other threads in our
83696+ thread group */
83697+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
83698+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
83699+ && gr_handle_signal(t, sig))
83700+ return -EPERM;
83701+
83702 return security_task_kill(t, info, sig, 0);
83703 }
83704
83705@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83706 return send_signal(sig, info, p, 1);
83707 }
83708
83709-static int
83710+int
83711 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83712 {
83713 return send_signal(sig, info, t, 0);
83714@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83715 unsigned long int flags;
83716 int ret, blocked, ignored;
83717 struct k_sigaction *action;
83718+ int is_unhandled = 0;
83719
83720 spin_lock_irqsave(&t->sighand->siglock, flags);
83721 action = &t->sighand->action[sig-1];
83722@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83723 }
83724 if (action->sa.sa_handler == SIG_DFL)
83725 t->signal->flags &= ~SIGNAL_UNKILLABLE;
83726+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
83727+ is_unhandled = 1;
83728 ret = specific_send_sig_info(sig, info, t);
83729 spin_unlock_irqrestore(&t->sighand->siglock, flags);
83730
83731+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
83732+ normal operation */
83733+ if (is_unhandled) {
83734+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
83735+ gr_handle_crash(t, sig);
83736+ }
83737+
83738 return ret;
83739 }
83740
83741@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83742 ret = check_kill_permission(sig, info, p);
83743 rcu_read_unlock();
83744
83745- if (!ret && sig)
83746+ if (!ret && sig) {
83747 ret = do_send_sig_info(sig, info, p, true);
83748+ if (!ret)
83749+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
83750+ }
83751
83752 return ret;
83753 }
83754@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
83755 int error = -ESRCH;
83756
83757 rcu_read_lock();
83758- p = find_task_by_vpid(pid);
83759+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
83760+ /* allow glibc communication via tgkill to other threads in our
83761+ thread group */
83762+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
83763+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
83764+ p = find_task_by_vpid_unrestricted(pid);
83765+ else
83766+#endif
83767+ p = find_task_by_vpid(pid);
83768 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
83769 error = check_kill_permission(sig, info, p);
83770 /*
83771@@ -3219,6 +3250,16 @@ int __save_altstack(stack_t __user *uss, unsigned long sp)
83772 __put_user(t->sas_ss_size, &uss->ss_size);
83773 }
83774
83775+#ifdef CONFIG_X86
83776+void __save_altstack_ex(stack_t __user *uss, unsigned long sp)
83777+{
83778+ struct task_struct *t = current;
83779+ put_user_ex((void __user *)t->sas_ss_sp, &uss->ss_sp);
83780+ put_user_ex(sas_ss_flags(sp), &uss->ss_flags);
83781+ put_user_ex(t->sas_ss_size, &uss->ss_size);
83782+}
83783+#endif
83784+
83785 #ifdef CONFIG_COMPAT
83786 COMPAT_SYSCALL_DEFINE2(sigaltstack,
83787 const compat_stack_t __user *, uss_ptr,
83788@@ -3240,8 +3281,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
83789 }
83790 seg = get_fs();
83791 set_fs(KERNEL_DS);
83792- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
83793- (stack_t __force __user *) &uoss,
83794+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
83795+ (stack_t __force_user *) &uoss,
83796 compat_user_stack_pointer());
83797 set_fs(seg);
83798 if (ret >= 0 && uoss_ptr) {
83799@@ -3268,6 +3309,16 @@ int __compat_save_altstack(compat_stack_t __user *uss, unsigned long sp)
83800 __put_user(sas_ss_flags(sp), &uss->ss_flags) |
83801 __put_user(t->sas_ss_size, &uss->ss_size);
83802 }
83803+
83804+#ifdef CONFIG_X86
83805+void __compat_save_altstack_ex(compat_stack_t __user *uss, unsigned long sp)
83806+{
83807+ struct task_struct *t = current;
83808+ put_user_ex(ptr_to_compat((void __user *)t->sas_ss_sp), &uss->ss_sp);
83809+ put_user_ex(sas_ss_flags(sp), &uss->ss_flags);
83810+ put_user_ex(t->sas_ss_size, &uss->ss_size);
83811+}
83812+#endif
83813 #endif
83814
83815 #ifdef __ARCH_WANT_SYS_SIGPENDING
83816diff --git a/kernel/smpboot.c b/kernel/smpboot.c
83817index eb89e18..a4e6792 100644
83818--- a/kernel/smpboot.c
83819+++ b/kernel/smpboot.c
83820@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
83821 }
83822 smpboot_unpark_thread(plug_thread, cpu);
83823 }
83824- list_add(&plug_thread->list, &hotplug_threads);
83825+ pax_list_add(&plug_thread->list, &hotplug_threads);
83826 out:
83827 mutex_unlock(&smpboot_threads_lock);
83828 return ret;
83829@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
83830 {
83831 get_online_cpus();
83832 mutex_lock(&smpboot_threads_lock);
83833- list_del(&plug_thread->list);
83834+ pax_list_del(&plug_thread->list);
83835 smpboot_destroy_threads(plug_thread);
83836 mutex_unlock(&smpboot_threads_lock);
83837 put_online_cpus();
83838diff --git a/kernel/softirq.c b/kernel/softirq.c
83839index be3d351..9e4d5f2 100644
83840--- a/kernel/softirq.c
83841+++ b/kernel/softirq.c
83842@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
83843 EXPORT_SYMBOL(irq_stat);
83844 #endif
83845
83846-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
83847+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
83848
83849 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
83850
83851-char *softirq_to_name[NR_SOFTIRQS] = {
83852+const char * const softirq_to_name[NR_SOFTIRQS] = {
83853 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
83854 "TASKLET", "SCHED", "HRTIMER", "RCU"
83855 };
83856@@ -248,7 +248,7 @@ restart:
83857 kstat_incr_softirqs_this_cpu(vec_nr);
83858
83859 trace_softirq_entry(vec_nr);
83860- h->action(h);
83861+ h->action();
83862 trace_softirq_exit(vec_nr);
83863 if (unlikely(prev_count != preempt_count())) {
83864 printk(KERN_ERR "huh, entered softirq %u %s %p"
83865@@ -403,7 +403,7 @@ void __raise_softirq_irqoff(unsigned int nr)
83866 or_softirq_pending(1UL << nr);
83867 }
83868
83869-void open_softirq(int nr, void (*action)(struct softirq_action *))
83870+void __init open_softirq(int nr, void (*action)(void))
83871 {
83872 softirq_vec[nr].action = action;
83873 }
83874@@ -459,7 +459,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
83875
83876 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
83877
83878-static void tasklet_action(struct softirq_action *a)
83879+static void tasklet_action(void)
83880 {
83881 struct tasklet_struct *list;
83882
83883@@ -494,7 +494,7 @@ static void tasklet_action(struct softirq_action *a)
83884 }
83885 }
83886
83887-static void tasklet_hi_action(struct softirq_action *a)
83888+static void tasklet_hi_action(void)
83889 {
83890 struct tasklet_struct *list;
83891
83892@@ -849,7 +849,7 @@ static struct notifier_block cpu_nfb = {
83893 .notifier_call = cpu_callback
83894 };
83895
83896-static struct smp_hotplug_thread softirq_threads = {
83897+static struct smp_hotplug_thread softirq_threads __read_only = {
83898 .store = &ksoftirqd,
83899 .thread_should_run = ksoftirqd_should_run,
83900 .thread_fn = run_ksoftirqd,
83901diff --git a/kernel/srcu.c b/kernel/srcu.c
83902index 01d5ccb..cdcbee6 100644
83903--- a/kernel/srcu.c
83904+++ b/kernel/srcu.c
83905@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
83906
83907 idx = ACCESS_ONCE(sp->completed) & 0x1;
83908 preempt_disable();
83909- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
83910+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
83911 smp_mb(); /* B */ /* Avoid leaking the critical section. */
83912- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
83913+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
83914 preempt_enable();
83915 return idx;
83916 }
83917diff --git a/kernel/sys.c b/kernel/sys.c
83918index 771129b..dc0c7e3 100644
83919--- a/kernel/sys.c
83920+++ b/kernel/sys.c
83921@@ -149,6 +149,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
83922 error = -EACCES;
83923 goto out;
83924 }
83925+
83926+ if (gr_handle_chroot_setpriority(p, niceval)) {
83927+ error = -EACCES;
83928+ goto out;
83929+ }
83930+
83931 no_nice = security_task_setnice(p, niceval);
83932 if (no_nice) {
83933 error = no_nice;
83934@@ -352,6 +358,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
83935 goto error;
83936 }
83937
83938+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
83939+ goto error;
83940+
83941 if (rgid != (gid_t) -1 ||
83942 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
83943 new->sgid = new->egid;
83944@@ -387,6 +396,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
83945 old = current_cred();
83946
83947 retval = -EPERM;
83948+
83949+ if (gr_check_group_change(kgid, kgid, kgid))
83950+ goto error;
83951+
83952 if (nsown_capable(CAP_SETGID))
83953 new->gid = new->egid = new->sgid = new->fsgid = kgid;
83954 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
83955@@ -404,7 +417,7 @@ error:
83956 /*
83957 * change the user struct in a credentials set to match the new UID
83958 */
83959-static int set_user(struct cred *new)
83960+int set_user(struct cred *new)
83961 {
83962 struct user_struct *new_user;
83963
83964@@ -484,6 +497,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
83965 goto error;
83966 }
83967
83968+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
83969+ goto error;
83970+
83971 if (!uid_eq(new->uid, old->uid)) {
83972 retval = set_user(new);
83973 if (retval < 0)
83974@@ -534,6 +550,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
83975 old = current_cred();
83976
83977 retval = -EPERM;
83978+
83979+ if (gr_check_crash_uid(kuid))
83980+ goto error;
83981+ if (gr_check_user_change(kuid, kuid, kuid))
83982+ goto error;
83983+
83984 if (nsown_capable(CAP_SETUID)) {
83985 new->suid = new->uid = kuid;
83986 if (!uid_eq(kuid, old->uid)) {
83987@@ -603,6 +625,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
83988 goto error;
83989 }
83990
83991+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
83992+ goto error;
83993+
83994 if (ruid != (uid_t) -1) {
83995 new->uid = kruid;
83996 if (!uid_eq(kruid, old->uid)) {
83997@@ -685,6 +710,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
83998 goto error;
83999 }
84000
84001+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
84002+ goto error;
84003+
84004 if (rgid != (gid_t) -1)
84005 new->gid = krgid;
84006 if (egid != (gid_t) -1)
84007@@ -746,12 +774,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
84008 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
84009 nsown_capable(CAP_SETUID)) {
84010 if (!uid_eq(kuid, old->fsuid)) {
84011+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
84012+ goto error;
84013+
84014 new->fsuid = kuid;
84015 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
84016 goto change_okay;
84017 }
84018 }
84019
84020+error:
84021 abort_creds(new);
84022 return old_fsuid;
84023
84024@@ -784,12 +816,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
84025 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
84026 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
84027 nsown_capable(CAP_SETGID)) {
84028+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
84029+ goto error;
84030+
84031 if (!gid_eq(kgid, old->fsgid)) {
84032 new->fsgid = kgid;
84033 goto change_okay;
84034 }
84035 }
84036
84037+error:
84038 abort_creds(new);
84039 return old_fsgid;
84040
84041@@ -1169,19 +1205,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
84042 return -EFAULT;
84043
84044 down_read(&uts_sem);
84045- error = __copy_to_user(&name->sysname, &utsname()->sysname,
84046+ error = __copy_to_user(name->sysname, &utsname()->sysname,
84047 __OLD_UTS_LEN);
84048 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
84049- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
84050+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
84051 __OLD_UTS_LEN);
84052 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
84053- error |= __copy_to_user(&name->release, &utsname()->release,
84054+ error |= __copy_to_user(name->release, &utsname()->release,
84055 __OLD_UTS_LEN);
84056 error |= __put_user(0, name->release + __OLD_UTS_LEN);
84057- error |= __copy_to_user(&name->version, &utsname()->version,
84058+ error |= __copy_to_user(name->version, &utsname()->version,
84059 __OLD_UTS_LEN);
84060 error |= __put_user(0, name->version + __OLD_UTS_LEN);
84061- error |= __copy_to_user(&name->machine, &utsname()->machine,
84062+ error |= __copy_to_user(name->machine, &utsname()->machine,
84063 __OLD_UTS_LEN);
84064 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
84065 up_read(&uts_sem);
84066@@ -1383,6 +1419,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
84067 */
84068 new_rlim->rlim_cur = 1;
84069 }
84070+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
84071+ is changed to a lower value. Since tasks can be created by the same
84072+ user in between this limit change and an execve by this task, force
84073+ a recheck only for this task by setting PF_NPROC_EXCEEDED
84074+ */
84075+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
84076+ tsk->flags |= PF_NPROC_EXCEEDED;
84077 }
84078 if (!retval) {
84079 if (old_rlim)
84080diff --git a/kernel/sysctl.c b/kernel/sysctl.c
84081index 07f6fc4..65fb3d4 100644
84082--- a/kernel/sysctl.c
84083+++ b/kernel/sysctl.c
84084@@ -93,7 +93,6 @@
84085
84086
84087 #if defined(CONFIG_SYSCTL)
84088-
84089 /* External variables not in a header file. */
84090 extern int sysctl_overcommit_memory;
84091 extern int sysctl_overcommit_ratio;
84092@@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
84093
84094 /* Constants used for minimum and maximum */
84095 #ifdef CONFIG_LOCKUP_DETECTOR
84096-static int sixty = 60;
84097+static int sixty __read_only = 60;
84098 #endif
84099
84100-static int zero;
84101-static int __maybe_unused one = 1;
84102-static int __maybe_unused two = 2;
84103-static int __maybe_unused three = 3;
84104-static unsigned long one_ul = 1;
84105-static int one_hundred = 100;
84106+static int neg_one __read_only = -1;
84107+static int zero __read_only = 0;
84108+static int __maybe_unused one __read_only = 1;
84109+static int __maybe_unused two __read_only = 2;
84110+static int __maybe_unused three __read_only = 3;
84111+static unsigned long one_ul __read_only = 1;
84112+static int one_hundred __read_only = 100;
84113 #ifdef CONFIG_PRINTK
84114-static int ten_thousand = 10000;
84115+static int ten_thousand __read_only = 10000;
84116 #endif
84117
84118 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
84119@@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
84120 void __user *buffer, size_t *lenp, loff_t *ppos);
84121 #endif
84122
84123-#ifdef CONFIG_PRINTK
84124 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84125 void __user *buffer, size_t *lenp, loff_t *ppos);
84126-#endif
84127
84128 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
84129 void __user *buffer, size_t *lenp, loff_t *ppos);
84130@@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
84131
84132 #endif
84133
84134+extern struct ctl_table grsecurity_table[];
84135+
84136 static struct ctl_table kern_table[];
84137 static struct ctl_table vm_table[];
84138 static struct ctl_table fs_table[];
84139@@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
84140 int sysctl_legacy_va_layout;
84141 #endif
84142
84143+#ifdef CONFIG_PAX_SOFTMODE
84144+static ctl_table pax_table[] = {
84145+ {
84146+ .procname = "softmode",
84147+ .data = &pax_softmode,
84148+ .maxlen = sizeof(unsigned int),
84149+ .mode = 0600,
84150+ .proc_handler = &proc_dointvec,
84151+ },
84152+
84153+ { }
84154+};
84155+#endif
84156+
84157 /* The default sysctl tables: */
84158
84159 static struct ctl_table sysctl_base_table[] = {
84160@@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
84161 #endif
84162
84163 static struct ctl_table kern_table[] = {
84164+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
84165+ {
84166+ .procname = "grsecurity",
84167+ .mode = 0500,
84168+ .child = grsecurity_table,
84169+ },
84170+#endif
84171+
84172+#ifdef CONFIG_PAX_SOFTMODE
84173+ {
84174+ .procname = "pax",
84175+ .mode = 0500,
84176+ .child = pax_table,
84177+ },
84178+#endif
84179+
84180 {
84181 .procname = "sched_child_runs_first",
84182 .data = &sysctl_sched_child_runs_first,
84183@@ -613,7 +643,7 @@ static struct ctl_table kern_table[] = {
84184 .data = &modprobe_path,
84185 .maxlen = KMOD_PATH_LEN,
84186 .mode = 0644,
84187- .proc_handler = proc_dostring,
84188+ .proc_handler = proc_dostring_modpriv,
84189 },
84190 {
84191 .procname = "modules_disabled",
84192@@ -780,16 +810,20 @@ static struct ctl_table kern_table[] = {
84193 .extra1 = &zero,
84194 .extra2 = &one,
84195 },
84196+#endif
84197 {
84198 .procname = "kptr_restrict",
84199 .data = &kptr_restrict,
84200 .maxlen = sizeof(int),
84201 .mode = 0644,
84202 .proc_handler = proc_dointvec_minmax_sysadmin,
84203+#ifdef CONFIG_GRKERNSEC_HIDESYM
84204+ .extra1 = &two,
84205+#else
84206 .extra1 = &zero,
84207+#endif
84208 .extra2 = &two,
84209 },
84210-#endif
84211 {
84212 .procname = "ngroups_max",
84213 .data = &ngroups_max,
84214@@ -1031,10 +1065,17 @@ static struct ctl_table kern_table[] = {
84215 */
84216 {
84217 .procname = "perf_event_paranoid",
84218- .data = &sysctl_perf_event_paranoid,
84219- .maxlen = sizeof(sysctl_perf_event_paranoid),
84220+ .data = &sysctl_perf_event_legitimately_concerned,
84221+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
84222 .mode = 0644,
84223- .proc_handler = proc_dointvec,
84224+ /* go ahead, be a hero */
84225+ .proc_handler = proc_dointvec_minmax_sysadmin,
84226+ .extra1 = &neg_one,
84227+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
84228+ .extra2 = &three,
84229+#else
84230+ .extra2 = &two,
84231+#endif
84232 },
84233 {
84234 .procname = "perf_event_mlock_kb",
84235@@ -1297,6 +1338,13 @@ static struct ctl_table vm_table[] = {
84236 .proc_handler = proc_dointvec_minmax,
84237 .extra1 = &zero,
84238 },
84239+ {
84240+ .procname = "heap_stack_gap",
84241+ .data = &sysctl_heap_stack_gap,
84242+ .maxlen = sizeof(sysctl_heap_stack_gap),
84243+ .mode = 0644,
84244+ .proc_handler = proc_doulongvec_minmax,
84245+ },
84246 #else
84247 {
84248 .procname = "nr_trim_pages",
84249@@ -1761,6 +1809,16 @@ int proc_dostring(struct ctl_table *table, int write,
84250 buffer, lenp, ppos);
84251 }
84252
84253+int proc_dostring_modpriv(struct ctl_table *table, int write,
84254+ void __user *buffer, size_t *lenp, loff_t *ppos)
84255+{
84256+ if (write && !capable(CAP_SYS_MODULE))
84257+ return -EPERM;
84258+
84259+ return _proc_do_string(table->data, table->maxlen, write,
84260+ buffer, lenp, ppos);
84261+}
84262+
84263 static size_t proc_skip_spaces(char **buf)
84264 {
84265 size_t ret;
84266@@ -1866,6 +1924,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
84267 len = strlen(tmp);
84268 if (len > *size)
84269 len = *size;
84270+ if (len > sizeof(tmp))
84271+ len = sizeof(tmp);
84272 if (copy_to_user(*buf, tmp, len))
84273 return -EFAULT;
84274 *size -= len;
84275@@ -2030,7 +2090,7 @@ int proc_dointvec(struct ctl_table *table, int write,
84276 static int proc_taint(struct ctl_table *table, int write,
84277 void __user *buffer, size_t *lenp, loff_t *ppos)
84278 {
84279- struct ctl_table t;
84280+ ctl_table_no_const t;
84281 unsigned long tmptaint = get_taint();
84282 int err;
84283
84284@@ -2058,7 +2118,6 @@ static int proc_taint(struct ctl_table *table, int write,
84285 return err;
84286 }
84287
84288-#ifdef CONFIG_PRINTK
84289 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84290 void __user *buffer, size_t *lenp, loff_t *ppos)
84291 {
84292@@ -2067,7 +2126,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84293
84294 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
84295 }
84296-#endif
84297
84298 struct do_proc_dointvec_minmax_conv_param {
84299 int *min;
84300@@ -2214,8 +2272,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
84301 *i = val;
84302 } else {
84303 val = convdiv * (*i) / convmul;
84304- if (!first)
84305+ if (!first) {
84306 err = proc_put_char(&buffer, &left, '\t');
84307+ if (err)
84308+ break;
84309+ }
84310 err = proc_put_long(&buffer, &left, val, false);
84311 if (err)
84312 break;
84313@@ -2611,6 +2672,12 @@ int proc_dostring(struct ctl_table *table, int write,
84314 return -ENOSYS;
84315 }
84316
84317+int proc_dostring_modpriv(struct ctl_table *table, int write,
84318+ void __user *buffer, size_t *lenp, loff_t *ppos)
84319+{
84320+ return -ENOSYS;
84321+}
84322+
84323 int proc_dointvec(struct ctl_table *table, int write,
84324 void __user *buffer, size_t *lenp, loff_t *ppos)
84325 {
84326@@ -2667,5 +2734,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
84327 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
84328 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
84329 EXPORT_SYMBOL(proc_dostring);
84330+EXPORT_SYMBOL(proc_dostring_modpriv);
84331 EXPORT_SYMBOL(proc_doulongvec_minmax);
84332 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
84333diff --git a/kernel/taskstats.c b/kernel/taskstats.c
84334index 145bb4d..b2aa969 100644
84335--- a/kernel/taskstats.c
84336+++ b/kernel/taskstats.c
84337@@ -28,9 +28,12 @@
84338 #include <linux/fs.h>
84339 #include <linux/file.h>
84340 #include <linux/pid_namespace.h>
84341+#include <linux/grsecurity.h>
84342 #include <net/genetlink.h>
84343 #include <linux/atomic.h>
84344
84345+extern int gr_is_taskstats_denied(int pid);
84346+
84347 /*
84348 * Maximum length of a cpumask that can be specified in
84349 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
84350@@ -570,6 +573,9 @@ err:
84351
84352 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
84353 {
84354+ if (gr_is_taskstats_denied(current->pid))
84355+ return -EACCES;
84356+
84357 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
84358 return cmd_attr_register_cpumask(info);
84359 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
84360diff --git a/kernel/time.c b/kernel/time.c
84361index 7c7964c..784a599 100644
84362--- a/kernel/time.c
84363+++ b/kernel/time.c
84364@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
84365 return error;
84366
84367 if (tz) {
84368+ /* we log in do_settimeofday called below, so don't log twice
84369+ */
84370+ if (!tv)
84371+ gr_log_timechange();
84372+
84373 sys_tz = *tz;
84374 update_vsyscall_tz();
84375 if (firsttime) {
84376@@ -502,7 +507,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
84377 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
84378 * value to a scaled second value.
84379 */
84380-unsigned long
84381+unsigned long __intentional_overflow(-1)
84382 timespec_to_jiffies(const struct timespec *value)
84383 {
84384 unsigned long sec = value->tv_sec;
84385diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
84386index eec50fc..65e5df6 100644
84387--- a/kernel/time/alarmtimer.c
84388+++ b/kernel/time/alarmtimer.c
84389@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
84390 struct platform_device *pdev;
84391 int error = 0;
84392 int i;
84393- struct k_clock alarm_clock = {
84394+ static struct k_clock alarm_clock = {
84395 .clock_getres = alarm_clock_getres,
84396 .clock_get = alarm_clock_get,
84397 .timer_create = alarm_timer_create,
84398diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
84399index 48b9fff..9e07e5f 100644
84400--- a/kernel/time/timekeeping.c
84401+++ b/kernel/time/timekeeping.c
84402@@ -15,6 +15,7 @@
84403 #include <linux/init.h>
84404 #include <linux/mm.h>
84405 #include <linux/sched.h>
84406+#include <linux/grsecurity.h>
84407 #include <linux/syscore_ops.h>
84408 #include <linux/clocksource.h>
84409 #include <linux/jiffies.h>
84410@@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
84411 if (!timespec_valid_strict(tv))
84412 return -EINVAL;
84413
84414+ gr_log_timechange();
84415+
84416 raw_spin_lock_irqsave(&timekeeper_lock, flags);
84417 write_seqcount_begin(&timekeeper_seq);
84418
84419diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
84420index 61ed862..3b52c65 100644
84421--- a/kernel/time/timer_list.c
84422+++ b/kernel/time/timer_list.c
84423@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
84424
84425 static void print_name_offset(struct seq_file *m, void *sym)
84426 {
84427+#ifdef CONFIG_GRKERNSEC_HIDESYM
84428+ SEQ_printf(m, "<%p>", NULL);
84429+#else
84430 char symname[KSYM_NAME_LEN];
84431
84432 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
84433 SEQ_printf(m, "<%pK>", sym);
84434 else
84435 SEQ_printf(m, "%s", symname);
84436+#endif
84437 }
84438
84439 static void
84440@@ -119,7 +123,11 @@ next_one:
84441 static void
84442 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
84443 {
84444+#ifdef CONFIG_GRKERNSEC_HIDESYM
84445+ SEQ_printf(m, " .base: %p\n", NULL);
84446+#else
84447 SEQ_printf(m, " .base: %pK\n", base);
84448+#endif
84449 SEQ_printf(m, " .index: %d\n",
84450 base->index);
84451 SEQ_printf(m, " .resolution: %Lu nsecs\n",
84452@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
84453 {
84454 struct proc_dir_entry *pe;
84455
84456+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84457+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
84458+#else
84459 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
84460+#endif
84461 if (!pe)
84462 return -ENOMEM;
84463 return 0;
84464diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
84465index 0b537f2..40d6c20 100644
84466--- a/kernel/time/timer_stats.c
84467+++ b/kernel/time/timer_stats.c
84468@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
84469 static unsigned long nr_entries;
84470 static struct entry entries[MAX_ENTRIES];
84471
84472-static atomic_t overflow_count;
84473+static atomic_unchecked_t overflow_count;
84474
84475 /*
84476 * The entries are in a hash-table, for fast lookup:
84477@@ -140,7 +140,7 @@ static void reset_entries(void)
84478 nr_entries = 0;
84479 memset(entries, 0, sizeof(entries));
84480 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
84481- atomic_set(&overflow_count, 0);
84482+ atomic_set_unchecked(&overflow_count, 0);
84483 }
84484
84485 static struct entry *alloc_entry(void)
84486@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84487 if (likely(entry))
84488 entry->count++;
84489 else
84490- atomic_inc(&overflow_count);
84491+ atomic_inc_unchecked(&overflow_count);
84492
84493 out_unlock:
84494 raw_spin_unlock_irqrestore(lock, flags);
84495@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84496
84497 static void print_name_offset(struct seq_file *m, unsigned long addr)
84498 {
84499+#ifdef CONFIG_GRKERNSEC_HIDESYM
84500+ seq_printf(m, "<%p>", NULL);
84501+#else
84502 char symname[KSYM_NAME_LEN];
84503
84504 if (lookup_symbol_name(addr, symname) < 0)
84505- seq_printf(m, "<%p>", (void *)addr);
84506+ seq_printf(m, "<%pK>", (void *)addr);
84507 else
84508 seq_printf(m, "%s", symname);
84509+#endif
84510 }
84511
84512 static int tstats_show(struct seq_file *m, void *v)
84513@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
84514
84515 seq_puts(m, "Timer Stats Version: v0.2\n");
84516 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
84517- if (atomic_read(&overflow_count))
84518+ if (atomic_read_unchecked(&overflow_count))
84519 seq_printf(m, "Overflow: %d entries\n",
84520- atomic_read(&overflow_count));
84521+ atomic_read_unchecked(&overflow_count));
84522
84523 for (i = 0; i < nr_entries; i++) {
84524 entry = entries + i;
84525@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
84526 {
84527 struct proc_dir_entry *pe;
84528
84529+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84530+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
84531+#else
84532 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
84533+#endif
84534 if (!pe)
84535 return -ENOMEM;
84536 return 0;
84537diff --git a/kernel/timer.c b/kernel/timer.c
84538index 4296d13..8998609 100644
84539--- a/kernel/timer.c
84540+++ b/kernel/timer.c
84541@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
84542 /*
84543 * This function runs timers and the timer-tq in bottom half context.
84544 */
84545-static void run_timer_softirq(struct softirq_action *h)
84546+static void run_timer_softirq(void)
84547 {
84548 struct tvec_base *base = __this_cpu_read(tvec_bases);
84549
84550@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
84551 *
84552 * In all cases the return value is guaranteed to be non-negative.
84553 */
84554-signed long __sched schedule_timeout(signed long timeout)
84555+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
84556 {
84557 struct timer_list timer;
84558 unsigned long expire;
84559diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
84560index b8b8560..75b1a09 100644
84561--- a/kernel/trace/blktrace.c
84562+++ b/kernel/trace/blktrace.c
84563@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
84564 struct blk_trace *bt = filp->private_data;
84565 char buf[16];
84566
84567- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
84568+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
84569
84570 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
84571 }
84572@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
84573 return 1;
84574
84575 bt = buf->chan->private_data;
84576- atomic_inc(&bt->dropped);
84577+ atomic_inc_unchecked(&bt->dropped);
84578 return 0;
84579 }
84580
84581@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
84582
84583 bt->dir = dir;
84584 bt->dev = dev;
84585- atomic_set(&bt->dropped, 0);
84586+ atomic_set_unchecked(&bt->dropped, 0);
84587
84588 ret = -EIO;
84589 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
84590diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
84591index a6d098c..bb8cf65 100644
84592--- a/kernel/trace/ftrace.c
84593+++ b/kernel/trace/ftrace.c
84594@@ -1950,12 +1950,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
84595 if (unlikely(ftrace_disabled))
84596 return 0;
84597
84598+ ret = ftrace_arch_code_modify_prepare();
84599+ FTRACE_WARN_ON(ret);
84600+ if (ret)
84601+ return 0;
84602+
84603 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
84604+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
84605 if (ret) {
84606 ftrace_bug(ret, ip);
84607- return 0;
84608 }
84609- return 1;
84610+ return ret ? 0 : 1;
84611 }
84612
84613 /*
84614@@ -4028,8 +4033,10 @@ static int ftrace_process_locs(struct module *mod,
84615 if (!count)
84616 return 0;
84617
84618+ pax_open_kernel();
84619 sort(start, count, sizeof(*start),
84620 ftrace_cmp_ips, ftrace_swap_ips);
84621+ pax_close_kernel();
84622
84623 start_pg = ftrace_allocate_pages(count);
84624 if (!start_pg)
84625@@ -4752,8 +4759,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
84626 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
84627
84628 static int ftrace_graph_active;
84629-static struct notifier_block ftrace_suspend_notifier;
84630-
84631 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
84632 {
84633 return 0;
84634@@ -4897,6 +4902,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
84635 return NOTIFY_DONE;
84636 }
84637
84638+static struct notifier_block ftrace_suspend_notifier = {
84639+ .notifier_call = ftrace_suspend_notifier_call
84640+};
84641+
84642 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84643 trace_func_graph_ent_t entryfunc)
84644 {
84645@@ -4910,7 +4919,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84646 goto out;
84647 }
84648
84649- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
84650 register_pm_notifier(&ftrace_suspend_notifier);
84651
84652 ftrace_graph_active++;
84653diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
84654index cc2f66f..05edd54 100644
84655--- a/kernel/trace/ring_buffer.c
84656+++ b/kernel/trace/ring_buffer.c
84657@@ -352,9 +352,9 @@ struct buffer_data_page {
84658 */
84659 struct buffer_page {
84660 struct list_head list; /* list of buffer pages */
84661- local_t write; /* index for next write */
84662+ local_unchecked_t write; /* index for next write */
84663 unsigned read; /* index for next read */
84664- local_t entries; /* entries on this page */
84665+ local_unchecked_t entries; /* entries on this page */
84666 unsigned long real_end; /* real end of data */
84667 struct buffer_data_page *page; /* Actual data page */
84668 };
84669@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
84670 unsigned long last_overrun;
84671 local_t entries_bytes;
84672 local_t entries;
84673- local_t overrun;
84674- local_t commit_overrun;
84675+ local_unchecked_t overrun;
84676+ local_unchecked_t commit_overrun;
84677 local_t dropped_events;
84678 local_t committing;
84679 local_t commits;
84680@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84681 *
84682 * We add a counter to the write field to denote this.
84683 */
84684- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
84685- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
84686+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
84687+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
84688
84689 /*
84690 * Just make sure we have seen our old_write and synchronize
84691@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84692 * cmpxchg to only update if an interrupt did not already
84693 * do it for us. If the cmpxchg fails, we don't care.
84694 */
84695- (void)local_cmpxchg(&next_page->write, old_write, val);
84696- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
84697+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
84698+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
84699
84700 /*
84701 * No need to worry about races with clearing out the commit.
84702@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
84703
84704 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
84705 {
84706- return local_read(&bpage->entries) & RB_WRITE_MASK;
84707+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
84708 }
84709
84710 static inline unsigned long rb_page_write(struct buffer_page *bpage)
84711 {
84712- return local_read(&bpage->write) & RB_WRITE_MASK;
84713+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
84714 }
84715
84716 static int
84717@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
84718 * bytes consumed in ring buffer from here.
84719 * Increment overrun to account for the lost events.
84720 */
84721- local_add(page_entries, &cpu_buffer->overrun);
84722+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
84723 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84724 }
84725
84726@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
84727 * it is our responsibility to update
84728 * the counters.
84729 */
84730- local_add(entries, &cpu_buffer->overrun);
84731+ local_add_unchecked(entries, &cpu_buffer->overrun);
84732 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84733
84734 /*
84735@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84736 if (tail == BUF_PAGE_SIZE)
84737 tail_page->real_end = 0;
84738
84739- local_sub(length, &tail_page->write);
84740+ local_sub_unchecked(length, &tail_page->write);
84741 return;
84742 }
84743
84744@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84745 rb_event_set_padding(event);
84746
84747 /* Set the write back to the previous setting */
84748- local_sub(length, &tail_page->write);
84749+ local_sub_unchecked(length, &tail_page->write);
84750 return;
84751 }
84752
84753@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84754
84755 /* Set write to end of buffer */
84756 length = (tail + length) - BUF_PAGE_SIZE;
84757- local_sub(length, &tail_page->write);
84758+ local_sub_unchecked(length, &tail_page->write);
84759 }
84760
84761 /*
84762@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84763 * about it.
84764 */
84765 if (unlikely(next_page == commit_page)) {
84766- local_inc(&cpu_buffer->commit_overrun);
84767+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84768 goto out_reset;
84769 }
84770
84771@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84772 cpu_buffer->tail_page) &&
84773 (cpu_buffer->commit_page ==
84774 cpu_buffer->reader_page))) {
84775- local_inc(&cpu_buffer->commit_overrun);
84776+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84777 goto out_reset;
84778 }
84779 }
84780@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84781 length += RB_LEN_TIME_EXTEND;
84782
84783 tail_page = cpu_buffer->tail_page;
84784- write = local_add_return(length, &tail_page->write);
84785+ write = local_add_return_unchecked(length, &tail_page->write);
84786
84787 /* set write to only the index of the write */
84788 write &= RB_WRITE_MASK;
84789@@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84790 kmemcheck_annotate_bitfield(event, bitfield);
84791 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
84792
84793- local_inc(&tail_page->entries);
84794+ local_inc_unchecked(&tail_page->entries);
84795
84796 /*
84797 * If this is the first commit on the page, then update
84798@@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84799
84800 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
84801 unsigned long write_mask =
84802- local_read(&bpage->write) & ~RB_WRITE_MASK;
84803+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
84804 unsigned long event_length = rb_event_length(event);
84805 /*
84806 * This is on the tail page. It is possible that
84807@@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84808 */
84809 old_index += write_mask;
84810 new_index += write_mask;
84811- index = local_cmpxchg(&bpage->write, old_index, new_index);
84812+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
84813 if (index == old_index) {
84814 /* update counters */
84815 local_sub(event_length, &cpu_buffer->entries_bytes);
84816@@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84817
84818 /* Do the likely case first */
84819 if (likely(bpage->page == (void *)addr)) {
84820- local_dec(&bpage->entries);
84821+ local_dec_unchecked(&bpage->entries);
84822 return;
84823 }
84824
84825@@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84826 start = bpage;
84827 do {
84828 if (bpage->page == (void *)addr) {
84829- local_dec(&bpage->entries);
84830+ local_dec_unchecked(&bpage->entries);
84831 return;
84832 }
84833 rb_inc_page(cpu_buffer, &bpage);
84834@@ -3139,7 +3139,7 @@ static inline unsigned long
84835 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
84836 {
84837 return local_read(&cpu_buffer->entries) -
84838- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
84839+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
84840 }
84841
84842 /**
84843@@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
84844 return 0;
84845
84846 cpu_buffer = buffer->buffers[cpu];
84847- ret = local_read(&cpu_buffer->overrun);
84848+ ret = local_read_unchecked(&cpu_buffer->overrun);
84849
84850 return ret;
84851 }
84852@@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
84853 return 0;
84854
84855 cpu_buffer = buffer->buffers[cpu];
84856- ret = local_read(&cpu_buffer->commit_overrun);
84857+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
84858
84859 return ret;
84860 }
84861@@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
84862 /* if you care about this being correct, lock the buffer */
84863 for_each_buffer_cpu(buffer, cpu) {
84864 cpu_buffer = buffer->buffers[cpu];
84865- overruns += local_read(&cpu_buffer->overrun);
84866+ overruns += local_read_unchecked(&cpu_buffer->overrun);
84867 }
84868
84869 return overruns;
84870@@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
84871 /*
84872 * Reset the reader page to size zero.
84873 */
84874- local_set(&cpu_buffer->reader_page->write, 0);
84875- local_set(&cpu_buffer->reader_page->entries, 0);
84876+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
84877+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
84878 local_set(&cpu_buffer->reader_page->page->commit, 0);
84879 cpu_buffer->reader_page->real_end = 0;
84880
84881@@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
84882 * want to compare with the last_overrun.
84883 */
84884 smp_mb();
84885- overwrite = local_read(&(cpu_buffer->overrun));
84886+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
84887
84888 /*
84889 * Here's the tricky part.
84890@@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
84891
84892 cpu_buffer->head_page
84893 = list_entry(cpu_buffer->pages, struct buffer_page, list);
84894- local_set(&cpu_buffer->head_page->write, 0);
84895- local_set(&cpu_buffer->head_page->entries, 0);
84896+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
84897+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
84898 local_set(&cpu_buffer->head_page->page->commit, 0);
84899
84900 cpu_buffer->head_page->read = 0;
84901@@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
84902
84903 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
84904 INIT_LIST_HEAD(&cpu_buffer->new_pages);
84905- local_set(&cpu_buffer->reader_page->write, 0);
84906- local_set(&cpu_buffer->reader_page->entries, 0);
84907+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
84908+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
84909 local_set(&cpu_buffer->reader_page->page->commit, 0);
84910 cpu_buffer->reader_page->read = 0;
84911
84912 local_set(&cpu_buffer->entries_bytes, 0);
84913- local_set(&cpu_buffer->overrun, 0);
84914- local_set(&cpu_buffer->commit_overrun, 0);
84915+ local_set_unchecked(&cpu_buffer->overrun, 0);
84916+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
84917 local_set(&cpu_buffer->dropped_events, 0);
84918 local_set(&cpu_buffer->entries, 0);
84919 local_set(&cpu_buffer->committing, 0);
84920@@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
84921 rb_init_page(bpage);
84922 bpage = reader->page;
84923 reader->page = *data_page;
84924- local_set(&reader->write, 0);
84925- local_set(&reader->entries, 0);
84926+ local_set_unchecked(&reader->write, 0);
84927+ local_set_unchecked(&reader->entries, 0);
84928 reader->read = 0;
84929 *data_page = bpage;
84930
84931diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
84932index 496f94d..754aeea 100644
84933--- a/kernel/trace/trace.c
84934+++ b/kernel/trace/trace.c
84935@@ -3335,7 +3335,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
84936 return 0;
84937 }
84938
84939-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
84940+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
84941 {
84942 /* do nothing if flag is already set */
84943 if (!!(trace_flags & mask) == !!enabled)
84944diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
84945index afaae41..64871f8 100644
84946--- a/kernel/trace/trace.h
84947+++ b/kernel/trace/trace.h
84948@@ -1025,7 +1025,7 @@ extern const char *__stop___trace_bprintk_fmt[];
84949 void trace_printk_init_buffers(void);
84950 void trace_printk_start_comm(void);
84951 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
84952-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
84953+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
84954
84955 /*
84956 * Normal trace_printk() and friends allocates special buffers
84957diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
84958index 26dc348..8708ca7 100644
84959--- a/kernel/trace/trace_clock.c
84960+++ b/kernel/trace/trace_clock.c
84961@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
84962 return now;
84963 }
84964
84965-static atomic64_t trace_counter;
84966+static atomic64_unchecked_t trace_counter;
84967
84968 /*
84969 * trace_clock_counter(): simply an atomic counter.
84970@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
84971 */
84972 u64 notrace trace_clock_counter(void)
84973 {
84974- return atomic64_add_return(1, &trace_counter);
84975+ return atomic64_inc_return_unchecked(&trace_counter);
84976 }
84977diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
84978index 29a7ebc..eb473cf 100644
84979--- a/kernel/trace/trace_events.c
84980+++ b/kernel/trace/trace_events.c
84981@@ -1778,10 +1778,6 @@ static LIST_HEAD(ftrace_module_file_list);
84982 struct ftrace_module_file_ops {
84983 struct list_head list;
84984 struct module *mod;
84985- struct file_operations id;
84986- struct file_operations enable;
84987- struct file_operations format;
84988- struct file_operations filter;
84989 };
84990
84991 static struct ftrace_module_file_ops *
84992@@ -1822,17 +1818,12 @@ trace_create_file_ops(struct module *mod)
84993
84994 file_ops->mod = mod;
84995
84996- file_ops->id = ftrace_event_id_fops;
84997- file_ops->id.owner = mod;
84998-
84999- file_ops->enable = ftrace_enable_fops;
85000- file_ops->enable.owner = mod;
85001-
85002- file_ops->filter = ftrace_event_filter_fops;
85003- file_ops->filter.owner = mod;
85004-
85005- file_ops->format = ftrace_event_format_fops;
85006- file_ops->format.owner = mod;
85007+ pax_open_kernel();
85008+ mod->trace_id.owner = mod;
85009+ mod->trace_enable.owner = mod;
85010+ mod->trace_filter.owner = mod;
85011+ mod->trace_format.owner = mod;
85012+ pax_close_kernel();
85013
85014 list_add(&file_ops->list, &ftrace_module_file_list);
85015
85016@@ -1925,8 +1916,8 @@ __trace_add_new_mod_event(struct ftrace_event_call *call,
85017 struct ftrace_module_file_ops *file_ops)
85018 {
85019 return __trace_add_new_event(call, tr,
85020- &file_ops->id, &file_ops->enable,
85021- &file_ops->filter, &file_ops->format);
85022+ &file_ops->mod->trace_id, &file_ops->mod->trace_enable,
85023+ &file_ops->mod->trace_filter, &file_ops->mod->trace_format);
85024 }
85025
85026 #else
85027diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
85028index b3dcfb2..ebee344 100644
85029--- a/kernel/trace/trace_mmiotrace.c
85030+++ b/kernel/trace/trace_mmiotrace.c
85031@@ -24,7 +24,7 @@ struct header_iter {
85032 static struct trace_array *mmio_trace_array;
85033 static bool overrun_detected;
85034 static unsigned long prev_overruns;
85035-static atomic_t dropped_count;
85036+static atomic_unchecked_t dropped_count;
85037
85038 static void mmio_reset_data(struct trace_array *tr)
85039 {
85040@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
85041
85042 static unsigned long count_overruns(struct trace_iterator *iter)
85043 {
85044- unsigned long cnt = atomic_xchg(&dropped_count, 0);
85045+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
85046 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
85047
85048 if (over > prev_overruns)
85049@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
85050 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
85051 sizeof(*entry), 0, pc);
85052 if (!event) {
85053- atomic_inc(&dropped_count);
85054+ atomic_inc_unchecked(&dropped_count);
85055 return;
85056 }
85057 entry = ring_buffer_event_data(event);
85058@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
85059 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
85060 sizeof(*entry), 0, pc);
85061 if (!event) {
85062- atomic_inc(&dropped_count);
85063+ atomic_inc_unchecked(&dropped_count);
85064 return;
85065 }
85066 entry = ring_buffer_event_data(event);
85067diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
85068index 34e7cba..6f9a729 100644
85069--- a/kernel/trace/trace_output.c
85070+++ b/kernel/trace/trace_output.c
85071@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
85072
85073 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
85074 if (!IS_ERR(p)) {
85075- p = mangle_path(s->buffer + s->len, p, "\n");
85076+ p = mangle_path(s->buffer + s->len, p, "\n\\");
85077 if (p) {
85078 s->len = p - s->buffer;
85079 return 1;
85080@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
85081 goto out;
85082 }
85083
85084+ pax_open_kernel();
85085 if (event->funcs->trace == NULL)
85086- event->funcs->trace = trace_nop_print;
85087+ *(void **)&event->funcs->trace = trace_nop_print;
85088 if (event->funcs->raw == NULL)
85089- event->funcs->raw = trace_nop_print;
85090+ *(void **)&event->funcs->raw = trace_nop_print;
85091 if (event->funcs->hex == NULL)
85092- event->funcs->hex = trace_nop_print;
85093+ *(void **)&event->funcs->hex = trace_nop_print;
85094 if (event->funcs->binary == NULL)
85095- event->funcs->binary = trace_nop_print;
85096+ *(void **)&event->funcs->binary = trace_nop_print;
85097+ pax_close_kernel();
85098
85099 key = event->type & (EVENT_HASHSIZE - 1);
85100
85101diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
85102index b20428c..4845a10 100644
85103--- a/kernel/trace/trace_stack.c
85104+++ b/kernel/trace/trace_stack.c
85105@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
85106 return;
85107
85108 /* we do not handle interrupt stacks yet */
85109- if (!object_is_on_stack(stack))
85110+ if (!object_starts_on_stack(stack))
85111 return;
85112
85113 local_irq_save(flags);
85114diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
85115index 9064b91..1f5d2f8 100644
85116--- a/kernel/user_namespace.c
85117+++ b/kernel/user_namespace.c
85118@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
85119 !kgid_has_mapping(parent_ns, group))
85120 return -EPERM;
85121
85122+#ifdef CONFIG_GRKERNSEC
85123+ /*
85124+ * This doesn't really inspire confidence:
85125+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
85126+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
85127+ * Increases kernel attack surface in areas developers
85128+ * previously cared little about ("low importance due
85129+ * to requiring "root" capability")
85130+ * To be removed when this code receives *proper* review
85131+ */
85132+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
85133+ !capable(CAP_SETGID))
85134+ return -EPERM;
85135+#endif
85136+
85137 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
85138 if (!ns)
85139 return -ENOMEM;
85140@@ -862,7 +877,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
85141 if (atomic_read(&current->mm->mm_users) > 1)
85142 return -EINVAL;
85143
85144- if (current->fs->users != 1)
85145+ if (atomic_read(&current->fs->users) != 1)
85146 return -EINVAL;
85147
85148 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
85149diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
85150index 4f69f9a..7c6f8f8 100644
85151--- a/kernel/utsname_sysctl.c
85152+++ b/kernel/utsname_sysctl.c
85153@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
85154 static int proc_do_uts_string(ctl_table *table, int write,
85155 void __user *buffer, size_t *lenp, loff_t *ppos)
85156 {
85157- struct ctl_table uts_table;
85158+ ctl_table_no_const uts_table;
85159 int r;
85160 memcpy(&uts_table, table, sizeof(uts_table));
85161 uts_table.data = get_uts(table, write);
85162diff --git a/kernel/watchdog.c b/kernel/watchdog.c
85163index 1241d8c..d5cfc28 100644
85164--- a/kernel/watchdog.c
85165+++ b/kernel/watchdog.c
85166@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
85167 static void watchdog_nmi_disable(unsigned int cpu) { return; }
85168 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
85169
85170-static struct smp_hotplug_thread watchdog_threads = {
85171+static struct smp_hotplug_thread watchdog_threads __read_only = {
85172 .store = &softlockup_watchdog,
85173 .thread_should_run = watchdog_should_run,
85174 .thread_fn = watchdog,
85175diff --git a/kernel/workqueue.c b/kernel/workqueue.c
85176index e93f7b9..989fcd7 100644
85177--- a/kernel/workqueue.c
85178+++ b/kernel/workqueue.c
85179@@ -4627,7 +4627,7 @@ static void rebind_workers(struct worker_pool *pool)
85180 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
85181 worker_flags |= WORKER_REBOUND;
85182 worker_flags &= ~WORKER_UNBOUND;
85183- ACCESS_ONCE(worker->flags) = worker_flags;
85184+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
85185 }
85186
85187 spin_unlock_irq(&pool->lock);
85188diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
85189index 1501aa5..e771896 100644
85190--- a/lib/Kconfig.debug
85191+++ b/lib/Kconfig.debug
85192@@ -836,7 +836,7 @@ config DEBUG_MUTEXES
85193
85194 config DEBUG_WW_MUTEX_SLOWPATH
85195 bool "Wait/wound mutex debugging: Slowpath testing"
85196- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85197+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85198 select DEBUG_LOCK_ALLOC
85199 select DEBUG_SPINLOCK
85200 select DEBUG_MUTEXES
85201@@ -849,7 +849,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
85202
85203 config DEBUG_LOCK_ALLOC
85204 bool "Lock debugging: detect incorrect freeing of live locks"
85205- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85206+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85207 select DEBUG_SPINLOCK
85208 select DEBUG_MUTEXES
85209 select LOCKDEP
85210@@ -863,7 +863,7 @@ config DEBUG_LOCK_ALLOC
85211
85212 config PROVE_LOCKING
85213 bool "Lock debugging: prove locking correctness"
85214- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85215+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85216 select LOCKDEP
85217 select DEBUG_SPINLOCK
85218 select DEBUG_MUTEXES
85219@@ -914,7 +914,7 @@ config LOCKDEP
85220
85221 config LOCK_STAT
85222 bool "Lock usage statistics"
85223- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85224+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85225 select LOCKDEP
85226 select DEBUG_SPINLOCK
85227 select DEBUG_MUTEXES
85228@@ -1357,6 +1357,7 @@ config LATENCYTOP
85229 depends on DEBUG_KERNEL
85230 depends on STACKTRACE_SUPPORT
85231 depends on PROC_FS
85232+ depends on !GRKERNSEC_HIDESYM
85233 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
85234 select KALLSYMS
85235 select KALLSYMS_ALL
85236@@ -1373,7 +1374,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
85237 config DEBUG_STRICT_USER_COPY_CHECKS
85238 bool "Strict user copy size checks"
85239 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
85240- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
85241+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
85242 help
85243 Enabling this option turns a certain set of sanity checks for user
85244 copy operations into compile time failures.
85245@@ -1483,7 +1484,7 @@ endmenu # runtime tests
85246
85247 config PROVIDE_OHCI1394_DMA_INIT
85248 bool "Remote debugging over FireWire early on boot"
85249- depends on PCI && X86
85250+ depends on PCI && X86 && !GRKERNSEC
85251 help
85252 If you want to debug problems which hang or crash the kernel early
85253 on boot and the crashing machine has a FireWire port, you can use
85254@@ -1512,7 +1513,7 @@ config PROVIDE_OHCI1394_DMA_INIT
85255
85256 config FIREWIRE_OHCI_REMOTE_DMA
85257 bool "Remote debugging over FireWire with firewire-ohci"
85258- depends on FIREWIRE_OHCI
85259+ depends on FIREWIRE_OHCI && !GRKERNSEC
85260 help
85261 This option lets you use the FireWire bus for remote debugging
85262 with help of the firewire-ohci driver. It enables unfiltered
85263diff --git a/lib/Makefile b/lib/Makefile
85264index 7baccfd..3ceb95f 100644
85265--- a/lib/Makefile
85266+++ b/lib/Makefile
85267@@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
85268
85269 obj-$(CONFIG_BTREE) += btree.o
85270 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
85271-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
85272+obj-y += list_debug.o
85273 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
85274
85275 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
85276diff --git a/lib/bitmap.c b/lib/bitmap.c
85277index 06f7e4f..f3cf2b0 100644
85278--- a/lib/bitmap.c
85279+++ b/lib/bitmap.c
85280@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
85281 {
85282 int c, old_c, totaldigits, ndigits, nchunks, nbits;
85283 u32 chunk;
85284- const char __user __force *ubuf = (const char __user __force *)buf;
85285+ const char __user *ubuf = (const char __force_user *)buf;
85286
85287 bitmap_zero(maskp, nmaskbits);
85288
85289@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
85290 {
85291 if (!access_ok(VERIFY_READ, ubuf, ulen))
85292 return -EFAULT;
85293- return __bitmap_parse((const char __force *)ubuf,
85294+ return __bitmap_parse((const char __force_kernel *)ubuf,
85295 ulen, 1, maskp, nmaskbits);
85296
85297 }
85298@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
85299 {
85300 unsigned a, b;
85301 int c, old_c, totaldigits;
85302- const char __user __force *ubuf = (const char __user __force *)buf;
85303+ const char __user *ubuf = (const char __force_user *)buf;
85304 int exp_digit, in_range;
85305
85306 totaldigits = c = 0;
85307@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
85308 {
85309 if (!access_ok(VERIFY_READ, ubuf, ulen))
85310 return -EFAULT;
85311- return __bitmap_parselist((const char __force *)ubuf,
85312+ return __bitmap_parselist((const char __force_kernel *)ubuf,
85313 ulen, 1, maskp, nmaskbits);
85314 }
85315 EXPORT_SYMBOL(bitmap_parselist_user);
85316diff --git a/lib/bug.c b/lib/bug.c
85317index 1686034..a9c00c8 100644
85318--- a/lib/bug.c
85319+++ b/lib/bug.c
85320@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
85321 return BUG_TRAP_TYPE_NONE;
85322
85323 bug = find_bug(bugaddr);
85324+ if (!bug)
85325+ return BUG_TRAP_TYPE_NONE;
85326
85327 file = NULL;
85328 line = 0;
85329diff --git a/lib/debugobjects.c b/lib/debugobjects.c
85330index 37061ed..da83f48 100644
85331--- a/lib/debugobjects.c
85332+++ b/lib/debugobjects.c
85333@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
85334 if (limit > 4)
85335 return;
85336
85337- is_on_stack = object_is_on_stack(addr);
85338+ is_on_stack = object_starts_on_stack(addr);
85339 if (is_on_stack == onstack)
85340 return;
85341
85342diff --git a/lib/devres.c b/lib/devres.c
85343index 8235331..5881053 100644
85344--- a/lib/devres.c
85345+++ b/lib/devres.c
85346@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
85347 void devm_iounmap(struct device *dev, void __iomem *addr)
85348 {
85349 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
85350- (void *)addr));
85351+ (void __force *)addr));
85352 iounmap(addr);
85353 }
85354 EXPORT_SYMBOL(devm_iounmap);
85355@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
85356 {
85357 ioport_unmap(addr);
85358 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
85359- devm_ioport_map_match, (void *)addr));
85360+ devm_ioport_map_match, (void __force *)addr));
85361 }
85362 EXPORT_SYMBOL(devm_ioport_unmap);
85363 #endif /* CONFIG_HAS_IOPORT */
85364diff --git a/lib/div64.c b/lib/div64.c
85365index a163b6c..9618fa5 100644
85366--- a/lib/div64.c
85367+++ b/lib/div64.c
85368@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
85369 EXPORT_SYMBOL(__div64_32);
85370
85371 #ifndef div_s64_rem
85372-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
85373+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
85374 {
85375 u64 quotient;
85376
85377@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
85378 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
85379 */
85380 #ifndef div64_u64
85381-u64 div64_u64(u64 dividend, u64 divisor)
85382+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
85383 {
85384 u32 high = divisor >> 32;
85385 u64 quot;
85386diff --git a/lib/dma-debug.c b/lib/dma-debug.c
85387index d87a17a..ac0d79a 100644
85388--- a/lib/dma-debug.c
85389+++ b/lib/dma-debug.c
85390@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
85391
85392 void dma_debug_add_bus(struct bus_type *bus)
85393 {
85394- struct notifier_block *nb;
85395+ notifier_block_no_const *nb;
85396
85397 if (global_disable)
85398 return;
85399@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
85400
85401 static void check_for_stack(struct device *dev, void *addr)
85402 {
85403- if (object_is_on_stack(addr))
85404+ if (object_starts_on_stack(addr))
85405 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
85406 "stack [addr=%p]\n", addr);
85407 }
85408diff --git a/lib/inflate.c b/lib/inflate.c
85409index 013a761..c28f3fc 100644
85410--- a/lib/inflate.c
85411+++ b/lib/inflate.c
85412@@ -269,7 +269,7 @@ static void free(void *where)
85413 malloc_ptr = free_mem_ptr;
85414 }
85415 #else
85416-#define malloc(a) kmalloc(a, GFP_KERNEL)
85417+#define malloc(a) kmalloc((a), GFP_KERNEL)
85418 #define free(a) kfree(a)
85419 #endif
85420
85421diff --git a/lib/ioremap.c b/lib/ioremap.c
85422index 0c9216c..863bd89 100644
85423--- a/lib/ioremap.c
85424+++ b/lib/ioremap.c
85425@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
85426 unsigned long next;
85427
85428 phys_addr -= addr;
85429- pmd = pmd_alloc(&init_mm, pud, addr);
85430+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
85431 if (!pmd)
85432 return -ENOMEM;
85433 do {
85434@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
85435 unsigned long next;
85436
85437 phys_addr -= addr;
85438- pud = pud_alloc(&init_mm, pgd, addr);
85439+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
85440 if (!pud)
85441 return -ENOMEM;
85442 do {
85443diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
85444index bd2bea9..6b3c95e 100644
85445--- a/lib/is_single_threaded.c
85446+++ b/lib/is_single_threaded.c
85447@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
85448 struct task_struct *p, *t;
85449 bool ret;
85450
85451+ if (!mm)
85452+ return true;
85453+
85454 if (atomic_read(&task->signal->live) != 1)
85455 return false;
85456
85457diff --git a/lib/kobject.c b/lib/kobject.c
85458index 4a1f33d..2f3ca75 100644
85459--- a/lib/kobject.c
85460+++ b/lib/kobject.c
85461@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
85462
85463
85464 static DEFINE_SPINLOCK(kobj_ns_type_lock);
85465-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
85466+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
85467
85468-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85469+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85470 {
85471 enum kobj_ns_type type = ops->type;
85472 int error;
85473diff --git a/lib/list_debug.c b/lib/list_debug.c
85474index c24c2f7..06e070b 100644
85475--- a/lib/list_debug.c
85476+++ b/lib/list_debug.c
85477@@ -11,7 +11,9 @@
85478 #include <linux/bug.h>
85479 #include <linux/kernel.h>
85480 #include <linux/rculist.h>
85481+#include <linux/mm.h>
85482
85483+#ifdef CONFIG_DEBUG_LIST
85484 /*
85485 * Insert a new entry between two known consecutive entries.
85486 *
85487@@ -19,21 +21,32 @@
85488 * the prev/next entries already!
85489 */
85490
85491-void __list_add(struct list_head *new,
85492- struct list_head *prev,
85493- struct list_head *next)
85494+static bool __list_add_debug(struct list_head *new,
85495+ struct list_head *prev,
85496+ struct list_head *next)
85497 {
85498- WARN(next->prev != prev,
85499+ if (WARN(next->prev != prev,
85500 "list_add corruption. next->prev should be "
85501 "prev (%p), but was %p. (next=%p).\n",
85502- prev, next->prev, next);
85503- WARN(prev->next != next,
85504+ prev, next->prev, next) ||
85505+ WARN(prev->next != next,
85506 "list_add corruption. prev->next should be "
85507 "next (%p), but was %p. (prev=%p).\n",
85508- next, prev->next, prev);
85509- WARN(new == prev || new == next,
85510- "list_add double add: new=%p, prev=%p, next=%p.\n",
85511- new, prev, next);
85512+ next, prev->next, prev) ||
85513+ WARN(new == prev || new == next,
85514+ "list_add double add: new=%p, prev=%p, next=%p.\n",
85515+ new, prev, next))
85516+ return false;
85517+ return true;
85518+}
85519+
85520+void __list_add(struct list_head *new,
85521+ struct list_head *prev,
85522+ struct list_head *next)
85523+{
85524+ if (!__list_add_debug(new, prev, next))
85525+ return;
85526+
85527 next->prev = new;
85528 new->next = next;
85529 new->prev = prev;
85530@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
85531 }
85532 EXPORT_SYMBOL(__list_add);
85533
85534-void __list_del_entry(struct list_head *entry)
85535+static bool __list_del_entry_debug(struct list_head *entry)
85536 {
85537 struct list_head *prev, *next;
85538
85539@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
85540 WARN(next->prev != entry,
85541 "list_del corruption. next->prev should be %p, "
85542 "but was %p\n", entry, next->prev))
85543+ return false;
85544+ return true;
85545+}
85546+
85547+void __list_del_entry(struct list_head *entry)
85548+{
85549+ if (!__list_del_entry_debug(entry))
85550 return;
85551
85552- __list_del(prev, next);
85553+ __list_del(entry->prev, entry->next);
85554 }
85555 EXPORT_SYMBOL(__list_del_entry);
85556
85557@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
85558 void __list_add_rcu(struct list_head *new,
85559 struct list_head *prev, struct list_head *next)
85560 {
85561- WARN(next->prev != prev,
85562- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
85563- prev, next->prev, next);
85564- WARN(prev->next != next,
85565- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
85566- next, prev->next, prev);
85567+ if (!__list_add_debug(new, prev, next))
85568+ return;
85569+
85570 new->next = next;
85571 new->prev = prev;
85572 rcu_assign_pointer(list_next_rcu(prev), new);
85573 next->prev = new;
85574 }
85575 EXPORT_SYMBOL(__list_add_rcu);
85576+#endif
85577+
85578+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
85579+{
85580+#ifdef CONFIG_DEBUG_LIST
85581+ if (!__list_add_debug(new, prev, next))
85582+ return;
85583+#endif
85584+
85585+ pax_open_kernel();
85586+ next->prev = new;
85587+ new->next = next;
85588+ new->prev = prev;
85589+ prev->next = new;
85590+ pax_close_kernel();
85591+}
85592+EXPORT_SYMBOL(__pax_list_add);
85593+
85594+void pax_list_del(struct list_head *entry)
85595+{
85596+#ifdef CONFIG_DEBUG_LIST
85597+ if (!__list_del_entry_debug(entry))
85598+ return;
85599+#endif
85600+
85601+ pax_open_kernel();
85602+ __list_del(entry->prev, entry->next);
85603+ entry->next = LIST_POISON1;
85604+ entry->prev = LIST_POISON2;
85605+ pax_close_kernel();
85606+}
85607+EXPORT_SYMBOL(pax_list_del);
85608+
85609+void pax_list_del_init(struct list_head *entry)
85610+{
85611+ pax_open_kernel();
85612+ __list_del(entry->prev, entry->next);
85613+ INIT_LIST_HEAD(entry);
85614+ pax_close_kernel();
85615+}
85616+EXPORT_SYMBOL(pax_list_del_init);
85617+
85618+void __pax_list_add_rcu(struct list_head *new,
85619+ struct list_head *prev, struct list_head *next)
85620+{
85621+#ifdef CONFIG_DEBUG_LIST
85622+ if (!__list_add_debug(new, prev, next))
85623+ return;
85624+#endif
85625+
85626+ pax_open_kernel();
85627+ new->next = next;
85628+ new->prev = prev;
85629+ rcu_assign_pointer(list_next_rcu(prev), new);
85630+ next->prev = new;
85631+ pax_close_kernel();
85632+}
85633+EXPORT_SYMBOL(__pax_list_add_rcu);
85634+
85635+void pax_list_del_rcu(struct list_head *entry)
85636+{
85637+#ifdef CONFIG_DEBUG_LIST
85638+ if (!__list_del_entry_debug(entry))
85639+ return;
85640+#endif
85641+
85642+ pax_open_kernel();
85643+ __list_del(entry->prev, entry->next);
85644+ entry->next = LIST_POISON1;
85645+ entry->prev = LIST_POISON2;
85646+ pax_close_kernel();
85647+}
85648+EXPORT_SYMBOL(pax_list_del_rcu);
85649diff --git a/lib/radix-tree.c b/lib/radix-tree.c
85650index e796429..6e38f9f 100644
85651--- a/lib/radix-tree.c
85652+++ b/lib/radix-tree.c
85653@@ -92,7 +92,7 @@ struct radix_tree_preload {
85654 int nr;
85655 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
85656 };
85657-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
85658+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
85659
85660 static inline void *ptr_to_indirect(void *ptr)
85661 {
85662diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
85663index bb2b201..46abaf9 100644
85664--- a/lib/strncpy_from_user.c
85665+++ b/lib/strncpy_from_user.c
85666@@ -21,7 +21,7 @@
85667 */
85668 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
85669 {
85670- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85671+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85672 long res = 0;
85673
85674 /*
85675diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
85676index a28df52..3d55877 100644
85677--- a/lib/strnlen_user.c
85678+++ b/lib/strnlen_user.c
85679@@ -26,7 +26,7 @@
85680 */
85681 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
85682 {
85683- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85684+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85685 long align, res = 0;
85686 unsigned long c;
85687
85688diff --git a/lib/swiotlb.c b/lib/swiotlb.c
85689index d23762e..e21eab2 100644
85690--- a/lib/swiotlb.c
85691+++ b/lib/swiotlb.c
85692@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
85693
85694 void
85695 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
85696- dma_addr_t dev_addr)
85697+ dma_addr_t dev_addr, struct dma_attrs *attrs)
85698 {
85699 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
85700
85701diff --git a/lib/usercopy.c b/lib/usercopy.c
85702index 4f5b1dd..7cab418 100644
85703--- a/lib/usercopy.c
85704+++ b/lib/usercopy.c
85705@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
85706 WARN(1, "Buffer overflow detected!\n");
85707 }
85708 EXPORT_SYMBOL(copy_from_user_overflow);
85709+
85710+void copy_to_user_overflow(void)
85711+{
85712+ WARN(1, "Buffer overflow detected!\n");
85713+}
85714+EXPORT_SYMBOL(copy_to_user_overflow);
85715diff --git a/lib/vsprintf.c b/lib/vsprintf.c
85716index 739a363..aa668d7 100644
85717--- a/lib/vsprintf.c
85718+++ b/lib/vsprintf.c
85719@@ -16,6 +16,9 @@
85720 * - scnprintf and vscnprintf
85721 */
85722
85723+#ifdef CONFIG_GRKERNSEC_HIDESYM
85724+#define __INCLUDED_BY_HIDESYM 1
85725+#endif
85726 #include <stdarg.h>
85727 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
85728 #include <linux/types.h>
85729@@ -1078,7 +1081,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
85730 return number(buf, end, *(const netdev_features_t *)addr, spec);
85731 }
85732
85733+#ifdef CONFIG_GRKERNSEC_HIDESYM
85734+int kptr_restrict __read_mostly = 2;
85735+#else
85736 int kptr_restrict __read_mostly;
85737+#endif
85738
85739 /*
85740 * Show a '%p' thing. A kernel extension is that the '%p' is followed
85741@@ -1091,6 +1098,7 @@ int kptr_restrict __read_mostly;
85742 * - 'f' For simple symbolic function names without offset
85743 * - 'S' For symbolic direct pointers with offset
85744 * - 's' For symbolic direct pointers without offset
85745+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
85746 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
85747 * - 'B' For backtraced symbolic direct pointers with offset
85748 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
85749@@ -1155,12 +1163,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85750
85751 if (!ptr && *fmt != 'K') {
85752 /*
85753- * Print (null) with the same width as a pointer so it makes
85754+ * Print (nil) with the same width as a pointer so it makes
85755 * tabular output look nice.
85756 */
85757 if (spec.field_width == -1)
85758 spec.field_width = default_width;
85759- return string(buf, end, "(null)", spec);
85760+ return string(buf, end, "(nil)", spec);
85761 }
85762
85763 switch (*fmt) {
85764@@ -1170,6 +1178,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85765 /* Fallthrough */
85766 case 'S':
85767 case 's':
85768+#ifdef CONFIG_GRKERNSEC_HIDESYM
85769+ break;
85770+#else
85771+ return symbol_string(buf, end, ptr, spec, fmt);
85772+#endif
85773+ case 'A':
85774 case 'B':
85775 return symbol_string(buf, end, ptr, spec, fmt);
85776 case 'R':
85777@@ -1225,6 +1239,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85778 va_end(va);
85779 return buf;
85780 }
85781+ case 'P':
85782+ break;
85783 case 'K':
85784 /*
85785 * %pK cannot be used in IRQ context because its test
85786@@ -1254,6 +1270,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85787 return number(buf, end,
85788 (unsigned long long) *((phys_addr_t *)ptr), spec);
85789 }
85790+
85791+#ifdef CONFIG_GRKERNSEC_HIDESYM
85792+ /* 'P' = approved pointers to copy to userland,
85793+ as in the /proc/kallsyms case, as we make it display nothing
85794+ for non-root users, and the real contents for root users
85795+ Also ignore 'K' pointers, since we force their NULLing for non-root users
85796+ above
85797+ */
85798+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
85799+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
85800+ dump_stack();
85801+ ptr = NULL;
85802+ }
85803+#endif
85804+
85805 spec.flags |= SMALL;
85806 if (spec.field_width == -1) {
85807 spec.field_width = default_width;
85808@@ -1977,11 +2008,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85809 typeof(type) value; \
85810 if (sizeof(type) == 8) { \
85811 args = PTR_ALIGN(args, sizeof(u32)); \
85812- *(u32 *)&value = *(u32 *)args; \
85813- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
85814+ *(u32 *)&value = *(const u32 *)args; \
85815+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
85816 } else { \
85817 args = PTR_ALIGN(args, sizeof(type)); \
85818- value = *(typeof(type) *)args; \
85819+ value = *(const typeof(type) *)args; \
85820 } \
85821 args += sizeof(type); \
85822 value; \
85823@@ -2044,7 +2075,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85824 case FORMAT_TYPE_STR: {
85825 const char *str_arg = args;
85826 args += strlen(str_arg) + 1;
85827- str = string(str, end, (char *)str_arg, spec);
85828+ str = string(str, end, str_arg, spec);
85829 break;
85830 }
85831
85832diff --git a/localversion-grsec b/localversion-grsec
85833new file mode 100644
85834index 0000000..7cd6065
85835--- /dev/null
85836+++ b/localversion-grsec
85837@@ -0,0 +1 @@
85838+-grsec
85839diff --git a/mm/Kconfig b/mm/Kconfig
85840index 8028dcc..9a2dbe7 100644
85841--- a/mm/Kconfig
85842+++ b/mm/Kconfig
85843@@ -317,10 +317,10 @@ config KSM
85844 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
85845
85846 config DEFAULT_MMAP_MIN_ADDR
85847- int "Low address space to protect from user allocation"
85848+ int "Low address space to protect from user allocation"
85849 depends on MMU
85850- default 4096
85851- help
85852+ default 65536
85853+ help
85854 This is the portion of low virtual memory which should be protected
85855 from userspace allocation. Keeping a user from writing to low pages
85856 can help reduce the impact of kernel NULL pointer bugs.
85857@@ -351,7 +351,7 @@ config MEMORY_FAILURE
85858
85859 config HWPOISON_INJECT
85860 tristate "HWPoison pages injector"
85861- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
85862+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
85863 select PROC_PAGE_MONITOR
85864
85865 config NOMMU_INITIAL_TRIM_EXCESS
85866diff --git a/mm/backing-dev.c b/mm/backing-dev.c
85867index e04454c..ca5be3e 100644
85868--- a/mm/backing-dev.c
85869+++ b/mm/backing-dev.c
85870@@ -12,7 +12,7 @@
85871 #include <linux/device.h>
85872 #include <trace/events/writeback.h>
85873
85874-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
85875+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
85876
85877 struct backing_dev_info default_backing_dev_info = {
85878 .name = "default",
85879@@ -522,7 +522,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
85880 return err;
85881
85882 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
85883- atomic_long_inc_return(&bdi_seq));
85884+ atomic_long_inc_return_unchecked(&bdi_seq));
85885 if (err) {
85886 bdi_destroy(bdi);
85887 return err;
85888diff --git a/mm/filemap.c b/mm/filemap.c
85889index 4b51ac1..5aa90ff 100644
85890--- a/mm/filemap.c
85891+++ b/mm/filemap.c
85892@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
85893 struct address_space *mapping = file->f_mapping;
85894
85895 if (!mapping->a_ops->readpage)
85896- return -ENOEXEC;
85897+ return -ENODEV;
85898 file_accessed(file);
85899 vma->vm_ops = &generic_file_vm_ops;
85900 return 0;
85901@@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
85902
85903 while (bytes) {
85904 char __user *buf = iov->iov_base + base;
85905- int copy = min(bytes, iov->iov_len - base);
85906+ size_t copy = min(bytes, iov->iov_len - base);
85907
85908 base = 0;
85909 left = __copy_from_user_inatomic(vaddr, buf, copy);
85910@@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
85911 BUG_ON(!in_atomic());
85912 kaddr = kmap_atomic(page);
85913 if (likely(i->nr_segs == 1)) {
85914- int left;
85915+ size_t left;
85916 char __user *buf = i->iov->iov_base + i->iov_offset;
85917 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
85918 copied = bytes - left;
85919@@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
85920
85921 kaddr = kmap(page);
85922 if (likely(i->nr_segs == 1)) {
85923- int left;
85924+ size_t left;
85925 char __user *buf = i->iov->iov_base + i->iov_offset;
85926 left = __copy_from_user(kaddr + offset, buf, bytes);
85927 copied = bytes - left;
85928@@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
85929 * zero-length segments (without overruning the iovec).
85930 */
85931 while (bytes || unlikely(i->count && !iov->iov_len)) {
85932- int copy;
85933+ size_t copy;
85934
85935 copy = min(bytes, iov->iov_len - base);
85936 BUG_ON(!i->count || i->count < copy);
85937@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
85938 *pos = i_size_read(inode);
85939
85940 if (limit != RLIM_INFINITY) {
85941+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
85942 if (*pos >= limit) {
85943 send_sig(SIGXFSZ, current, 0);
85944 return -EFBIG;
85945diff --git a/mm/fremap.c b/mm/fremap.c
85946index 5bff081..d8189a9 100644
85947--- a/mm/fremap.c
85948+++ b/mm/fremap.c
85949@@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
85950 retry:
85951 vma = find_vma(mm, start);
85952
85953+#ifdef CONFIG_PAX_SEGMEXEC
85954+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
85955+ goto out;
85956+#endif
85957+
85958 /*
85959 * Make sure the vma is shared, that it supports prefaulting,
85960 * and that the remapped range is valid and fully within
85961diff --git a/mm/highmem.c b/mm/highmem.c
85962index b32b70c..e512eb0 100644
85963--- a/mm/highmem.c
85964+++ b/mm/highmem.c
85965@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
85966 * So no dangers, even with speculative execution.
85967 */
85968 page = pte_page(pkmap_page_table[i]);
85969+ pax_open_kernel();
85970 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
85971-
85972+ pax_close_kernel();
85973 set_page_address(page, NULL);
85974 need_flush = 1;
85975 }
85976@@ -198,9 +199,11 @@ start:
85977 }
85978 }
85979 vaddr = PKMAP_ADDR(last_pkmap_nr);
85980+
85981+ pax_open_kernel();
85982 set_pte_at(&init_mm, vaddr,
85983 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
85984-
85985+ pax_close_kernel();
85986 pkmap_count[last_pkmap_nr] = 1;
85987 set_page_address(page, (void *)vaddr);
85988
85989diff --git a/mm/hugetlb.c b/mm/hugetlb.c
85990index b60f330..ee7de7e 100644
85991--- a/mm/hugetlb.c
85992+++ b/mm/hugetlb.c
85993@@ -2022,15 +2022,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
85994 struct hstate *h = &default_hstate;
85995 unsigned long tmp;
85996 int ret;
85997+ ctl_table_no_const hugetlb_table;
85998
85999 tmp = h->max_huge_pages;
86000
86001 if (write && h->order >= MAX_ORDER)
86002 return -EINVAL;
86003
86004- table->data = &tmp;
86005- table->maxlen = sizeof(unsigned long);
86006- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
86007+ hugetlb_table = *table;
86008+ hugetlb_table.data = &tmp;
86009+ hugetlb_table.maxlen = sizeof(unsigned long);
86010+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
86011 if (ret)
86012 goto out;
86013
86014@@ -2087,15 +2089,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
86015 struct hstate *h = &default_hstate;
86016 unsigned long tmp;
86017 int ret;
86018+ ctl_table_no_const hugetlb_table;
86019
86020 tmp = h->nr_overcommit_huge_pages;
86021
86022 if (write && h->order >= MAX_ORDER)
86023 return -EINVAL;
86024
86025- table->data = &tmp;
86026- table->maxlen = sizeof(unsigned long);
86027- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
86028+ hugetlb_table = *table;
86029+ hugetlb_table.data = &tmp;
86030+ hugetlb_table.maxlen = sizeof(unsigned long);
86031+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
86032 if (ret)
86033 goto out;
86034
86035@@ -2545,6 +2549,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
86036 return 1;
86037 }
86038
86039+#ifdef CONFIG_PAX_SEGMEXEC
86040+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
86041+{
86042+ struct mm_struct *mm = vma->vm_mm;
86043+ struct vm_area_struct *vma_m;
86044+ unsigned long address_m;
86045+ pte_t *ptep_m;
86046+
86047+ vma_m = pax_find_mirror_vma(vma);
86048+ if (!vma_m)
86049+ return;
86050+
86051+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86052+ address_m = address + SEGMEXEC_TASK_SIZE;
86053+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
86054+ get_page(page_m);
86055+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
86056+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
86057+}
86058+#endif
86059+
86060 /*
86061 * Hugetlb_cow() should be called with page lock of the original hugepage held.
86062 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
86063@@ -2663,6 +2688,11 @@ retry_avoidcopy:
86064 make_huge_pte(vma, new_page, 1));
86065 page_remove_rmap(old_page);
86066 hugepage_add_new_anon_rmap(new_page, vma, address);
86067+
86068+#ifdef CONFIG_PAX_SEGMEXEC
86069+ pax_mirror_huge_pte(vma, address, new_page);
86070+#endif
86071+
86072 /* Make the old page be freed below */
86073 new_page = old_page;
86074 }
86075@@ -2821,6 +2851,10 @@ retry:
86076 && (vma->vm_flags & VM_SHARED)));
86077 set_huge_pte_at(mm, address, ptep, new_pte);
86078
86079+#ifdef CONFIG_PAX_SEGMEXEC
86080+ pax_mirror_huge_pte(vma, address, page);
86081+#endif
86082+
86083 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
86084 /* Optimization, do the COW without a second fault */
86085 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
86086@@ -2850,6 +2884,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86087 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
86088 struct hstate *h = hstate_vma(vma);
86089
86090+#ifdef CONFIG_PAX_SEGMEXEC
86091+ struct vm_area_struct *vma_m;
86092+#endif
86093+
86094 address &= huge_page_mask(h);
86095
86096 ptep = huge_pte_offset(mm, address);
86097@@ -2863,6 +2901,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86098 VM_FAULT_SET_HINDEX(hstate_index(h));
86099 }
86100
86101+#ifdef CONFIG_PAX_SEGMEXEC
86102+ vma_m = pax_find_mirror_vma(vma);
86103+ if (vma_m) {
86104+ unsigned long address_m;
86105+
86106+ if (vma->vm_start > vma_m->vm_start) {
86107+ address_m = address;
86108+ address -= SEGMEXEC_TASK_SIZE;
86109+ vma = vma_m;
86110+ h = hstate_vma(vma);
86111+ } else
86112+ address_m = address + SEGMEXEC_TASK_SIZE;
86113+
86114+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
86115+ return VM_FAULT_OOM;
86116+ address_m &= HPAGE_MASK;
86117+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
86118+ }
86119+#endif
86120+
86121 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
86122 if (!ptep)
86123 return VM_FAULT_OOM;
86124diff --git a/mm/internal.h b/mm/internal.h
86125index 4390ac6..fc60373c 100644
86126--- a/mm/internal.h
86127+++ b/mm/internal.h
86128@@ -95,6 +95,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
86129 * in mm/page_alloc.c
86130 */
86131 extern void __free_pages_bootmem(struct page *page, unsigned int order);
86132+extern void free_compound_page(struct page *page);
86133 extern void prep_compound_page(struct page *page, unsigned long order);
86134 #ifdef CONFIG_MEMORY_FAILURE
86135 extern bool is_free_buddy_page(struct page *page);
86136@@ -350,7 +351,7 @@ extern u32 hwpoison_filter_enable;
86137
86138 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
86139 unsigned long, unsigned long,
86140- unsigned long, unsigned long);
86141+ unsigned long, unsigned long) __intentional_overflow(-1);
86142
86143 extern void set_pageblock_order(void);
86144 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
86145diff --git a/mm/kmemleak.c b/mm/kmemleak.c
86146index c8d7f31..2dbeffd 100644
86147--- a/mm/kmemleak.c
86148+++ b/mm/kmemleak.c
86149@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
86150
86151 for (i = 0; i < object->trace_len; i++) {
86152 void *ptr = (void *)object->trace[i];
86153- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
86154+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
86155 }
86156 }
86157
86158@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
86159 return -ENOMEM;
86160 }
86161
86162- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
86163+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
86164 &kmemleak_fops);
86165 if (!dentry)
86166 pr_warning("Failed to create the debugfs kmemleak file\n");
86167diff --git a/mm/maccess.c b/mm/maccess.c
86168index d53adf9..03a24bf 100644
86169--- a/mm/maccess.c
86170+++ b/mm/maccess.c
86171@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
86172 set_fs(KERNEL_DS);
86173 pagefault_disable();
86174 ret = __copy_from_user_inatomic(dst,
86175- (__force const void __user *)src, size);
86176+ (const void __force_user *)src, size);
86177 pagefault_enable();
86178 set_fs(old_fs);
86179
86180@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
86181
86182 set_fs(KERNEL_DS);
86183 pagefault_disable();
86184- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
86185+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
86186 pagefault_enable();
86187 set_fs(old_fs);
86188
86189diff --git a/mm/madvise.c b/mm/madvise.c
86190index 7055883..aafb1ed 100644
86191--- a/mm/madvise.c
86192+++ b/mm/madvise.c
86193@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
86194 pgoff_t pgoff;
86195 unsigned long new_flags = vma->vm_flags;
86196
86197+#ifdef CONFIG_PAX_SEGMEXEC
86198+ struct vm_area_struct *vma_m;
86199+#endif
86200+
86201 switch (behavior) {
86202 case MADV_NORMAL:
86203 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
86204@@ -126,6 +130,13 @@ success:
86205 /*
86206 * vm_flags is protected by the mmap_sem held in write mode.
86207 */
86208+
86209+#ifdef CONFIG_PAX_SEGMEXEC
86210+ vma_m = pax_find_mirror_vma(vma);
86211+ if (vma_m)
86212+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
86213+#endif
86214+
86215 vma->vm_flags = new_flags;
86216
86217 out:
86218@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
86219 struct vm_area_struct ** prev,
86220 unsigned long start, unsigned long end)
86221 {
86222+
86223+#ifdef CONFIG_PAX_SEGMEXEC
86224+ struct vm_area_struct *vma_m;
86225+#endif
86226+
86227 *prev = vma;
86228 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
86229 return -EINVAL;
86230@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
86231 zap_page_range(vma, start, end - start, &details);
86232 } else
86233 zap_page_range(vma, start, end - start, NULL);
86234+
86235+#ifdef CONFIG_PAX_SEGMEXEC
86236+ vma_m = pax_find_mirror_vma(vma);
86237+ if (vma_m) {
86238+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
86239+ struct zap_details details = {
86240+ .nonlinear_vma = vma_m,
86241+ .last_index = ULONG_MAX,
86242+ };
86243+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
86244+ } else
86245+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
86246+ }
86247+#endif
86248+
86249 return 0;
86250 }
86251
86252@@ -485,6 +516,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
86253 if (end < start)
86254 return error;
86255
86256+#ifdef CONFIG_PAX_SEGMEXEC
86257+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
86258+ if (end > SEGMEXEC_TASK_SIZE)
86259+ return error;
86260+ } else
86261+#endif
86262+
86263+ if (end > TASK_SIZE)
86264+ return error;
86265+
86266 error = 0;
86267 if (end == start)
86268 return error;
86269diff --git a/mm/memory-failure.c b/mm/memory-failure.c
86270index 2c13aa7..64cbc3f 100644
86271--- a/mm/memory-failure.c
86272+++ b/mm/memory-failure.c
86273@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
86274
86275 int sysctl_memory_failure_recovery __read_mostly = 1;
86276
86277-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
86278+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
86279
86280 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
86281
86282@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
86283 pfn, t->comm, t->pid);
86284 si.si_signo = SIGBUS;
86285 si.si_errno = 0;
86286- si.si_addr = (void *)addr;
86287+ si.si_addr = (void __user *)addr;
86288 #ifdef __ARCH_SI_TRAPNO
86289 si.si_trapno = trapno;
86290 #endif
86291@@ -760,7 +760,7 @@ static struct page_state {
86292 unsigned long res;
86293 char *msg;
86294 int (*action)(struct page *p, unsigned long pfn);
86295-} error_states[] = {
86296+} __do_const error_states[] = {
86297 { reserved, reserved, "reserved kernel", me_kernel },
86298 /*
86299 * free pages are specially detected outside this table:
86300@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86301 nr_pages = 1 << compound_order(hpage);
86302 else /* normal page or thp */
86303 nr_pages = 1;
86304- atomic_long_add(nr_pages, &num_poisoned_pages);
86305+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
86306
86307 /*
86308 * We need/can do nothing about count=0 pages.
86309@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86310 if (!PageHWPoison(hpage)
86311 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
86312 || (p != hpage && TestSetPageHWPoison(hpage))) {
86313- atomic_long_sub(nr_pages, &num_poisoned_pages);
86314+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86315 return 0;
86316 }
86317 set_page_hwpoison_huge_page(hpage);
86318@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86319 }
86320 if (hwpoison_filter(p)) {
86321 if (TestClearPageHWPoison(p))
86322- atomic_long_sub(nr_pages, &num_poisoned_pages);
86323+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86324 unlock_page(hpage);
86325 put_page(hpage);
86326 return 0;
86327@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
86328 return 0;
86329 }
86330 if (TestClearPageHWPoison(p))
86331- atomic_long_sub(nr_pages, &num_poisoned_pages);
86332+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86333 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
86334 return 0;
86335 }
86336@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
86337 */
86338 if (TestClearPageHWPoison(page)) {
86339 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
86340- atomic_long_sub(nr_pages, &num_poisoned_pages);
86341+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86342 freeit = 1;
86343 if (PageHuge(page))
86344 clear_page_hwpoison_huge_page(page);
86345@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
86346 } else {
86347 set_page_hwpoison_huge_page(hpage);
86348 dequeue_hwpoisoned_huge_page(hpage);
86349- atomic_long_add(1 << compound_trans_order(hpage),
86350+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
86351 &num_poisoned_pages);
86352 }
86353 return ret;
86354@@ -1551,11 +1551,11 @@ int soft_offline_page(struct page *page, int flags)
86355 if (PageHuge(page)) {
86356 set_page_hwpoison_huge_page(hpage);
86357 dequeue_hwpoisoned_huge_page(hpage);
86358- atomic_long_add(1 << compound_trans_order(hpage),
86359+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
86360 &num_poisoned_pages);
86361 } else {
86362 SetPageHWPoison(page);
86363- atomic_long_inc(&num_poisoned_pages);
86364+ atomic_long_inc_unchecked(&num_poisoned_pages);
86365 }
86366 }
86367 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
86368@@ -1595,7 +1595,7 @@ static int __soft_offline_page(struct page *page, int flags)
86369 put_page(page);
86370 pr_info("soft_offline: %#lx: invalidated\n", pfn);
86371 SetPageHWPoison(page);
86372- atomic_long_inc(&num_poisoned_pages);
86373+ atomic_long_inc_unchecked(&num_poisoned_pages);
86374 return 0;
86375 }
86376
86377@@ -1640,7 +1640,7 @@ static int __soft_offline_page(struct page *page, int flags)
86378 if (!is_free_buddy_page(page))
86379 pr_info("soft offline: %#lx: page leaked\n",
86380 pfn);
86381- atomic_long_inc(&num_poisoned_pages);
86382+ atomic_long_inc_unchecked(&num_poisoned_pages);
86383 }
86384 } else {
86385 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
86386diff --git a/mm/memory.c b/mm/memory.c
86387index af84bc0..2ed0816 100644
86388--- a/mm/memory.c
86389+++ b/mm/memory.c
86390@@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
86391 free_pte_range(tlb, pmd, addr);
86392 } while (pmd++, addr = next, addr != end);
86393
86394+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
86395 start &= PUD_MASK;
86396 if (start < floor)
86397 return;
86398@@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
86399 pmd = pmd_offset(pud, start);
86400 pud_clear(pud);
86401 pmd_free_tlb(tlb, pmd, start);
86402+#endif
86403+
86404 }
86405
86406 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86407@@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86408 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
86409 } while (pud++, addr = next, addr != end);
86410
86411+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
86412 start &= PGDIR_MASK;
86413 if (start < floor)
86414 return;
86415@@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86416 pud = pud_offset(pgd, start);
86417 pgd_clear(pgd);
86418 pud_free_tlb(tlb, pud, start);
86419+#endif
86420+
86421 }
86422
86423 /*
86424@@ -1645,12 +1651,6 @@ no_page_table:
86425 return page;
86426 }
86427
86428-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
86429-{
86430- return stack_guard_page_start(vma, addr) ||
86431- stack_guard_page_end(vma, addr+PAGE_SIZE);
86432-}
86433-
86434 /**
86435 * __get_user_pages() - pin user pages in memory
86436 * @tsk: task_struct of target task
86437@@ -1737,10 +1737,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86438
86439 i = 0;
86440
86441- do {
86442+ while (nr_pages) {
86443 struct vm_area_struct *vma;
86444
86445- vma = find_extend_vma(mm, start);
86446+ vma = find_vma(mm, start);
86447 if (!vma && in_gate_area(mm, start)) {
86448 unsigned long pg = start & PAGE_MASK;
86449 pgd_t *pgd;
86450@@ -1789,7 +1789,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86451 goto next_page;
86452 }
86453
86454- if (!vma ||
86455+ if (!vma || start < vma->vm_start ||
86456 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
86457 !(vm_flags & vma->vm_flags))
86458 return i ? : -EFAULT;
86459@@ -1818,11 +1818,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86460 int ret;
86461 unsigned int fault_flags = 0;
86462
86463- /* For mlock, just skip the stack guard page. */
86464- if (foll_flags & FOLL_MLOCK) {
86465- if (stack_guard_page(vma, start))
86466- goto next_page;
86467- }
86468 if (foll_flags & FOLL_WRITE)
86469 fault_flags |= FAULT_FLAG_WRITE;
86470 if (nonblocking)
86471@@ -1902,7 +1897,7 @@ next_page:
86472 start += page_increm * PAGE_SIZE;
86473 nr_pages -= page_increm;
86474 } while (nr_pages && start < vma->vm_end);
86475- } while (nr_pages);
86476+ }
86477 return i;
86478 }
86479 EXPORT_SYMBOL(__get_user_pages);
86480@@ -2109,6 +2104,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
86481 page_add_file_rmap(page);
86482 set_pte_at(mm, addr, pte, mk_pte(page, prot));
86483
86484+#ifdef CONFIG_PAX_SEGMEXEC
86485+ pax_mirror_file_pte(vma, addr, page, ptl);
86486+#endif
86487+
86488 retval = 0;
86489 pte_unmap_unlock(pte, ptl);
86490 return retval;
86491@@ -2153,9 +2152,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
86492 if (!page_count(page))
86493 return -EINVAL;
86494 if (!(vma->vm_flags & VM_MIXEDMAP)) {
86495+
86496+#ifdef CONFIG_PAX_SEGMEXEC
86497+ struct vm_area_struct *vma_m;
86498+#endif
86499+
86500 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
86501 BUG_ON(vma->vm_flags & VM_PFNMAP);
86502 vma->vm_flags |= VM_MIXEDMAP;
86503+
86504+#ifdef CONFIG_PAX_SEGMEXEC
86505+ vma_m = pax_find_mirror_vma(vma);
86506+ if (vma_m)
86507+ vma_m->vm_flags |= VM_MIXEDMAP;
86508+#endif
86509+
86510 }
86511 return insert_page(vma, addr, page, vma->vm_page_prot);
86512 }
86513@@ -2238,6 +2249,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
86514 unsigned long pfn)
86515 {
86516 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
86517+ BUG_ON(vma->vm_mirror);
86518
86519 if (addr < vma->vm_start || addr >= vma->vm_end)
86520 return -EFAULT;
86521@@ -2485,7 +2497,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
86522
86523 BUG_ON(pud_huge(*pud));
86524
86525- pmd = pmd_alloc(mm, pud, addr);
86526+ pmd = (mm == &init_mm) ?
86527+ pmd_alloc_kernel(mm, pud, addr) :
86528+ pmd_alloc(mm, pud, addr);
86529 if (!pmd)
86530 return -ENOMEM;
86531 do {
86532@@ -2505,7 +2519,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
86533 unsigned long next;
86534 int err;
86535
86536- pud = pud_alloc(mm, pgd, addr);
86537+ pud = (mm == &init_mm) ?
86538+ pud_alloc_kernel(mm, pgd, addr) :
86539+ pud_alloc(mm, pgd, addr);
86540 if (!pud)
86541 return -ENOMEM;
86542 do {
86543@@ -2593,6 +2609,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
86544 copy_user_highpage(dst, src, va, vma);
86545 }
86546
86547+#ifdef CONFIG_PAX_SEGMEXEC
86548+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
86549+{
86550+ struct mm_struct *mm = vma->vm_mm;
86551+ spinlock_t *ptl;
86552+ pte_t *pte, entry;
86553+
86554+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
86555+ entry = *pte;
86556+ if (!pte_present(entry)) {
86557+ if (!pte_none(entry)) {
86558+ BUG_ON(pte_file(entry));
86559+ free_swap_and_cache(pte_to_swp_entry(entry));
86560+ pte_clear_not_present_full(mm, address, pte, 0);
86561+ }
86562+ } else {
86563+ struct page *page;
86564+
86565+ flush_cache_page(vma, address, pte_pfn(entry));
86566+ entry = ptep_clear_flush(vma, address, pte);
86567+ BUG_ON(pte_dirty(entry));
86568+ page = vm_normal_page(vma, address, entry);
86569+ if (page) {
86570+ update_hiwater_rss(mm);
86571+ if (PageAnon(page))
86572+ dec_mm_counter_fast(mm, MM_ANONPAGES);
86573+ else
86574+ dec_mm_counter_fast(mm, MM_FILEPAGES);
86575+ page_remove_rmap(page);
86576+ page_cache_release(page);
86577+ }
86578+ }
86579+ pte_unmap_unlock(pte, ptl);
86580+}
86581+
86582+/* PaX: if vma is mirrored, synchronize the mirror's PTE
86583+ *
86584+ * the ptl of the lower mapped page is held on entry and is not released on exit
86585+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
86586+ */
86587+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86588+{
86589+ struct mm_struct *mm = vma->vm_mm;
86590+ unsigned long address_m;
86591+ spinlock_t *ptl_m;
86592+ struct vm_area_struct *vma_m;
86593+ pmd_t *pmd_m;
86594+ pte_t *pte_m, entry_m;
86595+
86596+ BUG_ON(!page_m || !PageAnon(page_m));
86597+
86598+ vma_m = pax_find_mirror_vma(vma);
86599+ if (!vma_m)
86600+ return;
86601+
86602+ BUG_ON(!PageLocked(page_m));
86603+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86604+ address_m = address + SEGMEXEC_TASK_SIZE;
86605+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86606+ pte_m = pte_offset_map(pmd_m, address_m);
86607+ ptl_m = pte_lockptr(mm, pmd_m);
86608+ if (ptl != ptl_m) {
86609+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86610+ if (!pte_none(*pte_m))
86611+ goto out;
86612+ }
86613+
86614+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86615+ page_cache_get(page_m);
86616+ page_add_anon_rmap(page_m, vma_m, address_m);
86617+ inc_mm_counter_fast(mm, MM_ANONPAGES);
86618+ set_pte_at(mm, address_m, pte_m, entry_m);
86619+ update_mmu_cache(vma_m, address_m, pte_m);
86620+out:
86621+ if (ptl != ptl_m)
86622+ spin_unlock(ptl_m);
86623+ pte_unmap(pte_m);
86624+ unlock_page(page_m);
86625+}
86626+
86627+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86628+{
86629+ struct mm_struct *mm = vma->vm_mm;
86630+ unsigned long address_m;
86631+ spinlock_t *ptl_m;
86632+ struct vm_area_struct *vma_m;
86633+ pmd_t *pmd_m;
86634+ pte_t *pte_m, entry_m;
86635+
86636+ BUG_ON(!page_m || PageAnon(page_m));
86637+
86638+ vma_m = pax_find_mirror_vma(vma);
86639+ if (!vma_m)
86640+ return;
86641+
86642+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86643+ address_m = address + SEGMEXEC_TASK_SIZE;
86644+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86645+ pte_m = pte_offset_map(pmd_m, address_m);
86646+ ptl_m = pte_lockptr(mm, pmd_m);
86647+ if (ptl != ptl_m) {
86648+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86649+ if (!pte_none(*pte_m))
86650+ goto out;
86651+ }
86652+
86653+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86654+ page_cache_get(page_m);
86655+ page_add_file_rmap(page_m);
86656+ inc_mm_counter_fast(mm, MM_FILEPAGES);
86657+ set_pte_at(mm, address_m, pte_m, entry_m);
86658+ update_mmu_cache(vma_m, address_m, pte_m);
86659+out:
86660+ if (ptl != ptl_m)
86661+ spin_unlock(ptl_m);
86662+ pte_unmap(pte_m);
86663+}
86664+
86665+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
86666+{
86667+ struct mm_struct *mm = vma->vm_mm;
86668+ unsigned long address_m;
86669+ spinlock_t *ptl_m;
86670+ struct vm_area_struct *vma_m;
86671+ pmd_t *pmd_m;
86672+ pte_t *pte_m, entry_m;
86673+
86674+ vma_m = pax_find_mirror_vma(vma);
86675+ if (!vma_m)
86676+ return;
86677+
86678+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86679+ address_m = address + SEGMEXEC_TASK_SIZE;
86680+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86681+ pte_m = pte_offset_map(pmd_m, address_m);
86682+ ptl_m = pte_lockptr(mm, pmd_m);
86683+ if (ptl != ptl_m) {
86684+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86685+ if (!pte_none(*pte_m))
86686+ goto out;
86687+ }
86688+
86689+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
86690+ set_pte_at(mm, address_m, pte_m, entry_m);
86691+out:
86692+ if (ptl != ptl_m)
86693+ spin_unlock(ptl_m);
86694+ pte_unmap(pte_m);
86695+}
86696+
86697+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
86698+{
86699+ struct page *page_m;
86700+ pte_t entry;
86701+
86702+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
86703+ goto out;
86704+
86705+ entry = *pte;
86706+ page_m = vm_normal_page(vma, address, entry);
86707+ if (!page_m)
86708+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
86709+ else if (PageAnon(page_m)) {
86710+ if (pax_find_mirror_vma(vma)) {
86711+ pte_unmap_unlock(pte, ptl);
86712+ lock_page(page_m);
86713+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
86714+ if (pte_same(entry, *pte))
86715+ pax_mirror_anon_pte(vma, address, page_m, ptl);
86716+ else
86717+ unlock_page(page_m);
86718+ }
86719+ } else
86720+ pax_mirror_file_pte(vma, address, page_m, ptl);
86721+
86722+out:
86723+ pte_unmap_unlock(pte, ptl);
86724+}
86725+#endif
86726+
86727 /*
86728 * This routine handles present pages, when users try to write
86729 * to a shared page. It is done by copying the page to a new address
86730@@ -2809,6 +3005,12 @@ gotten:
86731 */
86732 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86733 if (likely(pte_same(*page_table, orig_pte))) {
86734+
86735+#ifdef CONFIG_PAX_SEGMEXEC
86736+ if (pax_find_mirror_vma(vma))
86737+ BUG_ON(!trylock_page(new_page));
86738+#endif
86739+
86740 if (old_page) {
86741 if (!PageAnon(old_page)) {
86742 dec_mm_counter_fast(mm, MM_FILEPAGES);
86743@@ -2860,6 +3062,10 @@ gotten:
86744 page_remove_rmap(old_page);
86745 }
86746
86747+#ifdef CONFIG_PAX_SEGMEXEC
86748+ pax_mirror_anon_pte(vma, address, new_page, ptl);
86749+#endif
86750+
86751 /* Free the old page.. */
86752 new_page = old_page;
86753 ret |= VM_FAULT_WRITE;
86754@@ -3137,6 +3343,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86755 swap_free(entry);
86756 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
86757 try_to_free_swap(page);
86758+
86759+#ifdef CONFIG_PAX_SEGMEXEC
86760+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
86761+#endif
86762+
86763 unlock_page(page);
86764 if (page != swapcache) {
86765 /*
86766@@ -3160,6 +3371,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86767
86768 /* No need to invalidate - it was non-present before */
86769 update_mmu_cache(vma, address, page_table);
86770+
86771+#ifdef CONFIG_PAX_SEGMEXEC
86772+ pax_mirror_anon_pte(vma, address, page, ptl);
86773+#endif
86774+
86775 unlock:
86776 pte_unmap_unlock(page_table, ptl);
86777 out:
86778@@ -3179,40 +3395,6 @@ out_release:
86779 }
86780
86781 /*
86782- * This is like a special single-page "expand_{down|up}wards()",
86783- * except we must first make sure that 'address{-|+}PAGE_SIZE'
86784- * doesn't hit another vma.
86785- */
86786-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
86787-{
86788- address &= PAGE_MASK;
86789- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
86790- struct vm_area_struct *prev = vma->vm_prev;
86791-
86792- /*
86793- * Is there a mapping abutting this one below?
86794- *
86795- * That's only ok if it's the same stack mapping
86796- * that has gotten split..
86797- */
86798- if (prev && prev->vm_end == address)
86799- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
86800-
86801- expand_downwards(vma, address - PAGE_SIZE);
86802- }
86803- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
86804- struct vm_area_struct *next = vma->vm_next;
86805-
86806- /* As VM_GROWSDOWN but s/below/above/ */
86807- if (next && next->vm_start == address + PAGE_SIZE)
86808- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
86809-
86810- expand_upwards(vma, address + PAGE_SIZE);
86811- }
86812- return 0;
86813-}
86814-
86815-/*
86816 * We enter with non-exclusive mmap_sem (to exclude vma changes,
86817 * but allow concurrent faults), and pte mapped but not yet locked.
86818 * We return with mmap_sem still held, but pte unmapped and unlocked.
86819@@ -3221,27 +3403,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86820 unsigned long address, pte_t *page_table, pmd_t *pmd,
86821 unsigned int flags)
86822 {
86823- struct page *page;
86824+ struct page *page = NULL;
86825 spinlock_t *ptl;
86826 pte_t entry;
86827
86828- pte_unmap(page_table);
86829-
86830- /* Check if we need to add a guard page to the stack */
86831- if (check_stack_guard_page(vma, address) < 0)
86832- return VM_FAULT_SIGBUS;
86833-
86834- /* Use the zero-page for reads */
86835 if (!(flags & FAULT_FLAG_WRITE)) {
86836 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
86837 vma->vm_page_prot));
86838- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86839+ ptl = pte_lockptr(mm, pmd);
86840+ spin_lock(ptl);
86841 if (!pte_none(*page_table))
86842 goto unlock;
86843 goto setpte;
86844 }
86845
86846 /* Allocate our own private page. */
86847+ pte_unmap(page_table);
86848+
86849 if (unlikely(anon_vma_prepare(vma)))
86850 goto oom;
86851 page = alloc_zeroed_user_highpage_movable(vma, address);
86852@@ -3265,6 +3443,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86853 if (!pte_none(*page_table))
86854 goto release;
86855
86856+#ifdef CONFIG_PAX_SEGMEXEC
86857+ if (pax_find_mirror_vma(vma))
86858+ BUG_ON(!trylock_page(page));
86859+#endif
86860+
86861 inc_mm_counter_fast(mm, MM_ANONPAGES);
86862 page_add_new_anon_rmap(page, vma, address);
86863 setpte:
86864@@ -3272,6 +3455,12 @@ setpte:
86865
86866 /* No need to invalidate - it was non-present before */
86867 update_mmu_cache(vma, address, page_table);
86868+
86869+#ifdef CONFIG_PAX_SEGMEXEC
86870+ if (page)
86871+ pax_mirror_anon_pte(vma, address, page, ptl);
86872+#endif
86873+
86874 unlock:
86875 pte_unmap_unlock(page_table, ptl);
86876 return 0;
86877@@ -3415,6 +3604,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86878 */
86879 /* Only go through if we didn't race with anybody else... */
86880 if (likely(pte_same(*page_table, orig_pte))) {
86881+
86882+#ifdef CONFIG_PAX_SEGMEXEC
86883+ if (anon && pax_find_mirror_vma(vma))
86884+ BUG_ON(!trylock_page(page));
86885+#endif
86886+
86887 flush_icache_page(vma, page);
86888 entry = mk_pte(page, vma->vm_page_prot);
86889 if (flags & FAULT_FLAG_WRITE)
86890@@ -3436,6 +3631,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86891
86892 /* no need to invalidate: a not-present page won't be cached */
86893 update_mmu_cache(vma, address, page_table);
86894+
86895+#ifdef CONFIG_PAX_SEGMEXEC
86896+ if (anon)
86897+ pax_mirror_anon_pte(vma, address, page, ptl);
86898+ else
86899+ pax_mirror_file_pte(vma, address, page, ptl);
86900+#endif
86901+
86902 } else {
86903 if (cow_page)
86904 mem_cgroup_uncharge_page(cow_page);
86905@@ -3757,6 +3960,12 @@ int handle_pte_fault(struct mm_struct *mm,
86906 if (flags & FAULT_FLAG_WRITE)
86907 flush_tlb_fix_spurious_fault(vma, address);
86908 }
86909+
86910+#ifdef CONFIG_PAX_SEGMEXEC
86911+ pax_mirror_pte(vma, address, pte, pmd, ptl);
86912+ return 0;
86913+#endif
86914+
86915 unlock:
86916 pte_unmap_unlock(pte, ptl);
86917 return 0;
86918@@ -3773,6 +3982,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86919 pmd_t *pmd;
86920 pte_t *pte;
86921
86922+#ifdef CONFIG_PAX_SEGMEXEC
86923+ struct vm_area_struct *vma_m;
86924+#endif
86925+
86926 __set_current_state(TASK_RUNNING);
86927
86928 count_vm_event(PGFAULT);
86929@@ -3784,6 +3997,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86930 if (unlikely(is_vm_hugetlb_page(vma)))
86931 return hugetlb_fault(mm, vma, address, flags);
86932
86933+#ifdef CONFIG_PAX_SEGMEXEC
86934+ vma_m = pax_find_mirror_vma(vma);
86935+ if (vma_m) {
86936+ unsigned long address_m;
86937+ pgd_t *pgd_m;
86938+ pud_t *pud_m;
86939+ pmd_t *pmd_m;
86940+
86941+ if (vma->vm_start > vma_m->vm_start) {
86942+ address_m = address;
86943+ address -= SEGMEXEC_TASK_SIZE;
86944+ vma = vma_m;
86945+ } else
86946+ address_m = address + SEGMEXEC_TASK_SIZE;
86947+
86948+ pgd_m = pgd_offset(mm, address_m);
86949+ pud_m = pud_alloc(mm, pgd_m, address_m);
86950+ if (!pud_m)
86951+ return VM_FAULT_OOM;
86952+ pmd_m = pmd_alloc(mm, pud_m, address_m);
86953+ if (!pmd_m)
86954+ return VM_FAULT_OOM;
86955+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
86956+ return VM_FAULT_OOM;
86957+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
86958+ }
86959+#endif
86960+
86961 retry:
86962 pgd = pgd_offset(mm, address);
86963 pud = pud_alloc(mm, pgd, address);
86964@@ -3882,6 +4123,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
86965 spin_unlock(&mm->page_table_lock);
86966 return 0;
86967 }
86968+
86969+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
86970+{
86971+ pud_t *new = pud_alloc_one(mm, address);
86972+ if (!new)
86973+ return -ENOMEM;
86974+
86975+ smp_wmb(); /* See comment in __pte_alloc */
86976+
86977+ spin_lock(&mm->page_table_lock);
86978+ if (pgd_present(*pgd)) /* Another has populated it */
86979+ pud_free(mm, new);
86980+ else
86981+ pgd_populate_kernel(mm, pgd, new);
86982+ spin_unlock(&mm->page_table_lock);
86983+ return 0;
86984+}
86985 #endif /* __PAGETABLE_PUD_FOLDED */
86986
86987 #ifndef __PAGETABLE_PMD_FOLDED
86988@@ -3912,6 +4170,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
86989 spin_unlock(&mm->page_table_lock);
86990 return 0;
86991 }
86992+
86993+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
86994+{
86995+ pmd_t *new = pmd_alloc_one(mm, address);
86996+ if (!new)
86997+ return -ENOMEM;
86998+
86999+ smp_wmb(); /* See comment in __pte_alloc */
87000+
87001+ spin_lock(&mm->page_table_lock);
87002+#ifndef __ARCH_HAS_4LEVEL_HACK
87003+ if (pud_present(*pud)) /* Another has populated it */
87004+ pmd_free(mm, new);
87005+ else
87006+ pud_populate_kernel(mm, pud, new);
87007+#else
87008+ if (pgd_present(*pud)) /* Another has populated it */
87009+ pmd_free(mm, new);
87010+ else
87011+ pgd_populate_kernel(mm, pud, new);
87012+#endif /* __ARCH_HAS_4LEVEL_HACK */
87013+ spin_unlock(&mm->page_table_lock);
87014+ return 0;
87015+}
87016 #endif /* __PAGETABLE_PMD_FOLDED */
87017
87018 #if !defined(__HAVE_ARCH_GATE_AREA)
87019@@ -3925,7 +4207,7 @@ static int __init gate_vma_init(void)
87020 gate_vma.vm_start = FIXADDR_USER_START;
87021 gate_vma.vm_end = FIXADDR_USER_END;
87022 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
87023- gate_vma.vm_page_prot = __P101;
87024+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
87025
87026 return 0;
87027 }
87028@@ -4059,8 +4341,8 @@ out:
87029 return ret;
87030 }
87031
87032-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
87033- void *buf, int len, int write)
87034+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
87035+ void *buf, size_t len, int write)
87036 {
87037 resource_size_t phys_addr;
87038 unsigned long prot = 0;
87039@@ -4085,8 +4367,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
87040 * Access another process' address space as given in mm. If non-NULL, use the
87041 * given task for page fault accounting.
87042 */
87043-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87044- unsigned long addr, void *buf, int len, int write)
87045+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87046+ unsigned long addr, void *buf, size_t len, int write)
87047 {
87048 struct vm_area_struct *vma;
87049 void *old_buf = buf;
87050@@ -4094,7 +4376,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87051 down_read(&mm->mmap_sem);
87052 /* ignore errors, just check how much was successfully transferred */
87053 while (len) {
87054- int bytes, ret, offset;
87055+ ssize_t bytes, ret, offset;
87056 void *maddr;
87057 struct page *page = NULL;
87058
87059@@ -4153,8 +4435,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87060 *
87061 * The caller must hold a reference on @mm.
87062 */
87063-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
87064- void *buf, int len, int write)
87065+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
87066+ void *buf, size_t len, int write)
87067 {
87068 return __access_remote_vm(NULL, mm, addr, buf, len, write);
87069 }
87070@@ -4164,11 +4446,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
87071 * Source/target buffer must be kernel space,
87072 * Do not walk the page table directly, use get_user_pages
87073 */
87074-int access_process_vm(struct task_struct *tsk, unsigned long addr,
87075- void *buf, int len, int write)
87076+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
87077+ void *buf, size_t len, int write)
87078 {
87079 struct mm_struct *mm;
87080- int ret;
87081+ ssize_t ret;
87082
87083 mm = get_task_mm(tsk);
87084 if (!mm)
87085diff --git a/mm/mempolicy.c b/mm/mempolicy.c
87086index 4baf12e..5497066 100644
87087--- a/mm/mempolicy.c
87088+++ b/mm/mempolicy.c
87089@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
87090 unsigned long vmstart;
87091 unsigned long vmend;
87092
87093+#ifdef CONFIG_PAX_SEGMEXEC
87094+ struct vm_area_struct *vma_m;
87095+#endif
87096+
87097 vma = find_vma(mm, start);
87098 if (!vma || vma->vm_start > start)
87099 return -EFAULT;
87100@@ -751,6 +755,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
87101 err = vma_replace_policy(vma, new_pol);
87102 if (err)
87103 goto out;
87104+
87105+#ifdef CONFIG_PAX_SEGMEXEC
87106+ vma_m = pax_find_mirror_vma(vma);
87107+ if (vma_m) {
87108+ err = vma_replace_policy(vma_m, new_pol);
87109+ if (err)
87110+ goto out;
87111+ }
87112+#endif
87113+
87114 }
87115
87116 out:
87117@@ -1206,6 +1220,17 @@ static long do_mbind(unsigned long start, unsigned long len,
87118
87119 if (end < start)
87120 return -EINVAL;
87121+
87122+#ifdef CONFIG_PAX_SEGMEXEC
87123+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
87124+ if (end > SEGMEXEC_TASK_SIZE)
87125+ return -EINVAL;
87126+ } else
87127+#endif
87128+
87129+ if (end > TASK_SIZE)
87130+ return -EINVAL;
87131+
87132 if (end == start)
87133 return 0;
87134
87135@@ -1434,8 +1459,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
87136 */
87137 tcred = __task_cred(task);
87138 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
87139- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
87140- !capable(CAP_SYS_NICE)) {
87141+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
87142 rcu_read_unlock();
87143 err = -EPERM;
87144 goto out_put;
87145@@ -1466,6 +1490,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
87146 goto out;
87147 }
87148
87149+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
87150+ if (mm != current->mm &&
87151+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
87152+ mmput(mm);
87153+ err = -EPERM;
87154+ goto out;
87155+ }
87156+#endif
87157+
87158 err = do_migrate_pages(mm, old, new,
87159 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
87160
87161diff --git a/mm/migrate.c b/mm/migrate.c
87162index 6f0c244..6d1ae32 100644
87163--- a/mm/migrate.c
87164+++ b/mm/migrate.c
87165@@ -1399,8 +1399,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
87166 */
87167 tcred = __task_cred(task);
87168 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
87169- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
87170- !capable(CAP_SYS_NICE)) {
87171+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
87172 rcu_read_unlock();
87173 err = -EPERM;
87174 goto out;
87175diff --git a/mm/mlock.c b/mm/mlock.c
87176index 79b7cf7..9944291 100644
87177--- a/mm/mlock.c
87178+++ b/mm/mlock.c
87179@@ -13,6 +13,7 @@
87180 #include <linux/pagemap.h>
87181 #include <linux/mempolicy.h>
87182 #include <linux/syscalls.h>
87183+#include <linux/security.h>
87184 #include <linux/sched.h>
87185 #include <linux/export.h>
87186 #include <linux/rmap.h>
87187@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
87188 {
87189 unsigned long nstart, end, tmp;
87190 struct vm_area_struct * vma, * prev;
87191- int error;
87192+ int error = 0;
87193
87194 VM_BUG_ON(start & ~PAGE_MASK);
87195 VM_BUG_ON(len != PAGE_ALIGN(len));
87196@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
87197 return -EINVAL;
87198 if (end == start)
87199 return 0;
87200+ if (end > TASK_SIZE)
87201+ return -EINVAL;
87202+
87203 vma = find_vma(current->mm, start);
87204 if (!vma || vma->vm_start > start)
87205 return -ENOMEM;
87206@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
87207 for (nstart = start ; ; ) {
87208 vm_flags_t newflags;
87209
87210+#ifdef CONFIG_PAX_SEGMEXEC
87211+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
87212+ break;
87213+#endif
87214+
87215 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
87216
87217 newflags = vma->vm_flags & ~VM_LOCKED;
87218@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
87219 lock_limit >>= PAGE_SHIFT;
87220
87221 /* check against resource limits */
87222+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
87223 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
87224 error = do_mlock(start, len, 1);
87225 up_write(&current->mm->mmap_sem);
87226@@ -500,6 +510,11 @@ static int do_mlockall(int flags)
87227 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
87228 vm_flags_t newflags;
87229
87230+#ifdef CONFIG_PAX_SEGMEXEC
87231+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
87232+ break;
87233+#endif
87234+
87235 newflags = vma->vm_flags & ~VM_LOCKED;
87236 if (flags & MCL_CURRENT)
87237 newflags |= VM_LOCKED;
87238@@ -532,6 +547,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
87239 lock_limit >>= PAGE_SHIFT;
87240
87241 ret = -ENOMEM;
87242+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
87243 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
87244 capable(CAP_IPC_LOCK))
87245 ret = do_mlockall(flags);
87246diff --git a/mm/mmap.c b/mm/mmap.c
87247index f9c97d1..3468d3b 100644
87248--- a/mm/mmap.c
87249+++ b/mm/mmap.c
87250@@ -36,6 +36,7 @@
87251 #include <linux/sched/sysctl.h>
87252 #include <linux/notifier.h>
87253 #include <linux/memory.h>
87254+#include <linux/random.h>
87255
87256 #include <asm/uaccess.h>
87257 #include <asm/cacheflush.h>
87258@@ -52,6 +53,16 @@
87259 #define arch_rebalance_pgtables(addr, len) (addr)
87260 #endif
87261
87262+static inline void verify_mm_writelocked(struct mm_struct *mm)
87263+{
87264+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
87265+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
87266+ up_read(&mm->mmap_sem);
87267+ BUG();
87268+ }
87269+#endif
87270+}
87271+
87272 static void unmap_region(struct mm_struct *mm,
87273 struct vm_area_struct *vma, struct vm_area_struct *prev,
87274 unsigned long start, unsigned long end);
87275@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
87276 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
87277 *
87278 */
87279-pgprot_t protection_map[16] = {
87280+pgprot_t protection_map[16] __read_only = {
87281 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
87282 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
87283 };
87284
87285-pgprot_t vm_get_page_prot(unsigned long vm_flags)
87286+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
87287 {
87288- return __pgprot(pgprot_val(protection_map[vm_flags &
87289+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
87290 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
87291 pgprot_val(arch_vm_get_page_prot(vm_flags)));
87292+
87293+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87294+ if (!(__supported_pte_mask & _PAGE_NX) &&
87295+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
87296+ (vm_flags & (VM_READ | VM_WRITE)))
87297+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
87298+#endif
87299+
87300+ return prot;
87301 }
87302 EXPORT_SYMBOL(vm_get_page_prot);
87303
87304@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
87305 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
87306 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
87307 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
87308+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
87309 /*
87310 * Make sure vm_committed_as in one cacheline and not cacheline shared with
87311 * other variables. It can be updated by several CPUs frequently.
87312@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
87313 struct vm_area_struct *next = vma->vm_next;
87314
87315 might_sleep();
87316+ BUG_ON(vma->vm_mirror);
87317 if (vma->vm_ops && vma->vm_ops->close)
87318 vma->vm_ops->close(vma);
87319 if (vma->vm_file)
87320@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
87321 * not page aligned -Ram Gupta
87322 */
87323 rlim = rlimit(RLIMIT_DATA);
87324+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
87325 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
87326 (mm->end_data - mm->start_data) > rlim)
87327 goto out;
87328@@ -933,6 +956,12 @@ static int
87329 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
87330 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
87331 {
87332+
87333+#ifdef CONFIG_PAX_SEGMEXEC
87334+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
87335+ return 0;
87336+#endif
87337+
87338 if (is_mergeable_vma(vma, file, vm_flags) &&
87339 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
87340 if (vma->vm_pgoff == vm_pgoff)
87341@@ -952,6 +981,12 @@ static int
87342 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
87343 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
87344 {
87345+
87346+#ifdef CONFIG_PAX_SEGMEXEC
87347+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
87348+ return 0;
87349+#endif
87350+
87351 if (is_mergeable_vma(vma, file, vm_flags) &&
87352 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
87353 pgoff_t vm_pglen;
87354@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
87355 struct vm_area_struct *vma_merge(struct mm_struct *mm,
87356 struct vm_area_struct *prev, unsigned long addr,
87357 unsigned long end, unsigned long vm_flags,
87358- struct anon_vma *anon_vma, struct file *file,
87359+ struct anon_vma *anon_vma, struct file *file,
87360 pgoff_t pgoff, struct mempolicy *policy)
87361 {
87362 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
87363 struct vm_area_struct *area, *next;
87364 int err;
87365
87366+#ifdef CONFIG_PAX_SEGMEXEC
87367+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
87368+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
87369+
87370+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
87371+#endif
87372+
87373 /*
87374 * We later require that vma->vm_flags == vm_flags,
87375 * so this tests vma->vm_flags & VM_SPECIAL, too.
87376@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87377 if (next && next->vm_end == end) /* cases 6, 7, 8 */
87378 next = next->vm_next;
87379
87380+#ifdef CONFIG_PAX_SEGMEXEC
87381+ if (prev)
87382+ prev_m = pax_find_mirror_vma(prev);
87383+ if (area)
87384+ area_m = pax_find_mirror_vma(area);
87385+ if (next)
87386+ next_m = pax_find_mirror_vma(next);
87387+#endif
87388+
87389 /*
87390 * Can it merge with the predecessor?
87391 */
87392@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87393 /* cases 1, 6 */
87394 err = vma_adjust(prev, prev->vm_start,
87395 next->vm_end, prev->vm_pgoff, NULL);
87396- } else /* cases 2, 5, 7 */
87397+
87398+#ifdef CONFIG_PAX_SEGMEXEC
87399+ if (!err && prev_m)
87400+ err = vma_adjust(prev_m, prev_m->vm_start,
87401+ next_m->vm_end, prev_m->vm_pgoff, NULL);
87402+#endif
87403+
87404+ } else { /* cases 2, 5, 7 */
87405 err = vma_adjust(prev, prev->vm_start,
87406 end, prev->vm_pgoff, NULL);
87407+
87408+#ifdef CONFIG_PAX_SEGMEXEC
87409+ if (!err && prev_m)
87410+ err = vma_adjust(prev_m, prev_m->vm_start,
87411+ end_m, prev_m->vm_pgoff, NULL);
87412+#endif
87413+
87414+ }
87415 if (err)
87416 return NULL;
87417 khugepaged_enter_vma_merge(prev);
87418@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87419 mpol_equal(policy, vma_policy(next)) &&
87420 can_vma_merge_before(next, vm_flags,
87421 anon_vma, file, pgoff+pglen)) {
87422- if (prev && addr < prev->vm_end) /* case 4 */
87423+ if (prev && addr < prev->vm_end) { /* case 4 */
87424 err = vma_adjust(prev, prev->vm_start,
87425 addr, prev->vm_pgoff, NULL);
87426- else /* cases 3, 8 */
87427+
87428+#ifdef CONFIG_PAX_SEGMEXEC
87429+ if (!err && prev_m)
87430+ err = vma_adjust(prev_m, prev_m->vm_start,
87431+ addr_m, prev_m->vm_pgoff, NULL);
87432+#endif
87433+
87434+ } else { /* cases 3, 8 */
87435 err = vma_adjust(area, addr, next->vm_end,
87436 next->vm_pgoff - pglen, NULL);
87437+
87438+#ifdef CONFIG_PAX_SEGMEXEC
87439+ if (!err && area_m)
87440+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
87441+ next_m->vm_pgoff - pglen, NULL);
87442+#endif
87443+
87444+ }
87445 if (err)
87446 return NULL;
87447 khugepaged_enter_vma_merge(area);
87448@@ -1165,8 +1246,10 @@ none:
87449 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87450 struct file *file, long pages)
87451 {
87452- const unsigned long stack_flags
87453- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
87454+
87455+#ifdef CONFIG_PAX_RANDMMAP
87456+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87457+#endif
87458
87459 mm->total_vm += pages;
87460
87461@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87462 mm->shared_vm += pages;
87463 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
87464 mm->exec_vm += pages;
87465- } else if (flags & stack_flags)
87466+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
87467 mm->stack_vm += pages;
87468 }
87469 #endif /* CONFIG_PROC_FS */
87470@@ -1213,7 +1296,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87471 * (the exception is when the underlying filesystem is noexec
87472 * mounted, in which case we dont add PROT_EXEC.)
87473 */
87474- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
87475+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
87476 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
87477 prot |= PROT_EXEC;
87478
87479@@ -1239,7 +1322,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87480 /* Obtain the address to map to. we verify (or select) it and ensure
87481 * that it represents a valid section of the address space.
87482 */
87483- addr = get_unmapped_area(file, addr, len, pgoff, flags);
87484+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
87485 if (addr & ~PAGE_MASK)
87486 return addr;
87487
87488@@ -1250,6 +1333,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87489 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
87490 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
87491
87492+#ifdef CONFIG_PAX_MPROTECT
87493+ if (mm->pax_flags & MF_PAX_MPROTECT) {
87494+
87495+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
87496+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
87497+ mm->binfmt->handle_mmap)
87498+ mm->binfmt->handle_mmap(file);
87499+#endif
87500+
87501+#ifndef CONFIG_PAX_MPROTECT_COMPAT
87502+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
87503+ gr_log_rwxmmap(file);
87504+
87505+#ifdef CONFIG_PAX_EMUPLT
87506+ vm_flags &= ~VM_EXEC;
87507+#else
87508+ return -EPERM;
87509+#endif
87510+
87511+ }
87512+
87513+ if (!(vm_flags & VM_EXEC))
87514+ vm_flags &= ~VM_MAYEXEC;
87515+#else
87516+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
87517+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
87518+#endif
87519+ else
87520+ vm_flags &= ~VM_MAYWRITE;
87521+ }
87522+#endif
87523+
87524+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87525+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
87526+ vm_flags &= ~VM_PAGEEXEC;
87527+#endif
87528+
87529 if (flags & MAP_LOCKED)
87530 if (!can_do_mlock())
87531 return -EPERM;
87532@@ -1261,6 +1381,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87533 locked += mm->locked_vm;
87534 lock_limit = rlimit(RLIMIT_MEMLOCK);
87535 lock_limit >>= PAGE_SHIFT;
87536+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
87537 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
87538 return -EAGAIN;
87539 }
87540@@ -1341,6 +1462,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87541 vm_flags |= VM_NORESERVE;
87542 }
87543
87544+ if (!gr_acl_handle_mmap(file, prot))
87545+ return -EACCES;
87546+
87547 addr = mmap_region(file, addr, len, vm_flags, pgoff);
87548 if (!IS_ERR_VALUE(addr) &&
87549 ((vm_flags & VM_LOCKED) ||
87550@@ -1434,7 +1558,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
87551 vm_flags_t vm_flags = vma->vm_flags;
87552
87553 /* If it was private or non-writable, the write bit is already clear */
87554- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
87555+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
87556 return 0;
87557
87558 /* The backer wishes to know when pages are first written to? */
87559@@ -1482,7 +1606,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87560 unsigned long charged = 0;
87561 struct inode *inode = file ? file_inode(file) : NULL;
87562
87563+#ifdef CONFIG_PAX_SEGMEXEC
87564+ struct vm_area_struct *vma_m = NULL;
87565+#endif
87566+
87567+ /*
87568+ * mm->mmap_sem is required to protect against another thread
87569+ * changing the mappings in case we sleep.
87570+ */
87571+ verify_mm_writelocked(mm);
87572+
87573 /* Check against address space limit. */
87574+
87575+#ifdef CONFIG_PAX_RANDMMAP
87576+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87577+#endif
87578+
87579 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
87580 unsigned long nr_pages;
87581
87582@@ -1501,11 +1640,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87583
87584 /* Clear old maps */
87585 error = -ENOMEM;
87586-munmap_back:
87587 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
87588 if (do_munmap(mm, addr, len))
87589 return -ENOMEM;
87590- goto munmap_back;
87591+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
87592 }
87593
87594 /*
87595@@ -1536,6 +1674,16 @@ munmap_back:
87596 goto unacct_error;
87597 }
87598
87599+#ifdef CONFIG_PAX_SEGMEXEC
87600+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
87601+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
87602+ if (!vma_m) {
87603+ error = -ENOMEM;
87604+ goto free_vma;
87605+ }
87606+ }
87607+#endif
87608+
87609 vma->vm_mm = mm;
87610 vma->vm_start = addr;
87611 vma->vm_end = addr + len;
87612@@ -1560,6 +1708,13 @@ munmap_back:
87613 if (error)
87614 goto unmap_and_free_vma;
87615
87616+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87617+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
87618+ vma->vm_flags |= VM_PAGEEXEC;
87619+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
87620+ }
87621+#endif
87622+
87623 /* Can addr have changed??
87624 *
87625 * Answer: Yes, several device drivers can do it in their
87626@@ -1598,6 +1753,11 @@ munmap_back:
87627 vma_link(mm, vma, prev, rb_link, rb_parent);
87628 file = vma->vm_file;
87629
87630+#ifdef CONFIG_PAX_SEGMEXEC
87631+ if (vma_m)
87632+ BUG_ON(pax_mirror_vma(vma_m, vma));
87633+#endif
87634+
87635 /* Once vma denies write, undo our temporary denial count */
87636 if (correct_wcount)
87637 atomic_inc(&inode->i_writecount);
87638@@ -1605,6 +1765,7 @@ out:
87639 perf_event_mmap(vma);
87640
87641 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
87642+ track_exec_limit(mm, addr, addr + len, vm_flags);
87643 if (vm_flags & VM_LOCKED) {
87644 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
87645 vma == get_gate_vma(current->mm)))
87646@@ -1628,6 +1789,12 @@ unmap_and_free_vma:
87647 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
87648 charged = 0;
87649 free_vma:
87650+
87651+#ifdef CONFIG_PAX_SEGMEXEC
87652+ if (vma_m)
87653+ kmem_cache_free(vm_area_cachep, vma_m);
87654+#endif
87655+
87656 kmem_cache_free(vm_area_cachep, vma);
87657 unacct_error:
87658 if (charged)
87659@@ -1635,7 +1802,63 @@ unacct_error:
87660 return error;
87661 }
87662
87663-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87664+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
87665+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
87666+{
87667+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
87668+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
87669+
87670+ return 0;
87671+}
87672+#endif
87673+
87674+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
87675+{
87676+ if (!vma) {
87677+#ifdef CONFIG_STACK_GROWSUP
87678+ if (addr > sysctl_heap_stack_gap)
87679+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
87680+ else
87681+ vma = find_vma(current->mm, 0);
87682+ if (vma && (vma->vm_flags & VM_GROWSUP))
87683+ return false;
87684+#endif
87685+ return true;
87686+ }
87687+
87688+ if (addr + len > vma->vm_start)
87689+ return false;
87690+
87691+ if (vma->vm_flags & VM_GROWSDOWN)
87692+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
87693+#ifdef CONFIG_STACK_GROWSUP
87694+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
87695+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
87696+#endif
87697+ else if (offset)
87698+ return offset <= vma->vm_start - addr - len;
87699+
87700+ return true;
87701+}
87702+
87703+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
87704+{
87705+ if (vma->vm_start < len)
87706+ return -ENOMEM;
87707+
87708+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
87709+ if (offset <= vma->vm_start - len)
87710+ return vma->vm_start - len - offset;
87711+ else
87712+ return -ENOMEM;
87713+ }
87714+
87715+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
87716+ return vma->vm_start - len - sysctl_heap_stack_gap;
87717+ return -ENOMEM;
87718+}
87719+
87720+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
87721 {
87722 /*
87723 * We implement the search by looking for an rbtree node that
87724@@ -1683,11 +1906,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87725 }
87726 }
87727
87728- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
87729+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
87730 check_current:
87731 /* Check if current node has a suitable gap */
87732 if (gap_start > high_limit)
87733 return -ENOMEM;
87734+
87735+ if (gap_end - gap_start > info->threadstack_offset)
87736+ gap_start += info->threadstack_offset;
87737+ else
87738+ gap_start = gap_end;
87739+
87740+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87741+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87742+ gap_start += sysctl_heap_stack_gap;
87743+ else
87744+ gap_start = gap_end;
87745+ }
87746+ if (vma->vm_flags & VM_GROWSDOWN) {
87747+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87748+ gap_end -= sysctl_heap_stack_gap;
87749+ else
87750+ gap_end = gap_start;
87751+ }
87752 if (gap_end >= low_limit && gap_end - gap_start >= length)
87753 goto found;
87754
87755@@ -1737,7 +1978,7 @@ found:
87756 return gap_start;
87757 }
87758
87759-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
87760+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
87761 {
87762 struct mm_struct *mm = current->mm;
87763 struct vm_area_struct *vma;
87764@@ -1791,6 +2032,24 @@ check_current:
87765 gap_end = vma->vm_start;
87766 if (gap_end < low_limit)
87767 return -ENOMEM;
87768+
87769+ if (gap_end - gap_start > info->threadstack_offset)
87770+ gap_end -= info->threadstack_offset;
87771+ else
87772+ gap_end = gap_start;
87773+
87774+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87775+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87776+ gap_start += sysctl_heap_stack_gap;
87777+ else
87778+ gap_start = gap_end;
87779+ }
87780+ if (vma->vm_flags & VM_GROWSDOWN) {
87781+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87782+ gap_end -= sysctl_heap_stack_gap;
87783+ else
87784+ gap_end = gap_start;
87785+ }
87786 if (gap_start <= high_limit && gap_end - gap_start >= length)
87787 goto found;
87788
87789@@ -1854,6 +2113,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87790 struct mm_struct *mm = current->mm;
87791 struct vm_area_struct *vma;
87792 struct vm_unmapped_area_info info;
87793+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87794
87795 if (len > TASK_SIZE)
87796 return -ENOMEM;
87797@@ -1861,19 +2121,29 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87798 if (flags & MAP_FIXED)
87799 return addr;
87800
87801+#ifdef CONFIG_PAX_RANDMMAP
87802+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87803+#endif
87804+
87805 if (addr) {
87806 addr = PAGE_ALIGN(addr);
87807 vma = find_vma(mm, addr);
87808- if (TASK_SIZE - len >= addr &&
87809- (!vma || addr + len <= vma->vm_start))
87810+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87811 return addr;
87812 }
87813
87814 info.flags = 0;
87815 info.length = len;
87816 info.low_limit = TASK_UNMAPPED_BASE;
87817+
87818+#ifdef CONFIG_PAX_RANDMMAP
87819+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87820+ info.low_limit += mm->delta_mmap;
87821+#endif
87822+
87823 info.high_limit = TASK_SIZE;
87824 info.align_mask = 0;
87825+ info.threadstack_offset = offset;
87826 return vm_unmapped_area(&info);
87827 }
87828 #endif
87829@@ -1892,6 +2162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87830 struct mm_struct *mm = current->mm;
87831 unsigned long addr = addr0;
87832 struct vm_unmapped_area_info info;
87833+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87834
87835 /* requested length too big for entire address space */
87836 if (len > TASK_SIZE)
87837@@ -1900,12 +2171,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87838 if (flags & MAP_FIXED)
87839 return addr;
87840
87841+#ifdef CONFIG_PAX_RANDMMAP
87842+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87843+#endif
87844+
87845 /* requesting a specific address */
87846 if (addr) {
87847 addr = PAGE_ALIGN(addr);
87848 vma = find_vma(mm, addr);
87849- if (TASK_SIZE - len >= addr &&
87850- (!vma || addr + len <= vma->vm_start))
87851+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87852 return addr;
87853 }
87854
87855@@ -1914,6 +2188,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87856 info.low_limit = PAGE_SIZE;
87857 info.high_limit = mm->mmap_base;
87858 info.align_mask = 0;
87859+ info.threadstack_offset = offset;
87860 addr = vm_unmapped_area(&info);
87861
87862 /*
87863@@ -1926,6 +2201,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87864 VM_BUG_ON(addr != -ENOMEM);
87865 info.flags = 0;
87866 info.low_limit = TASK_UNMAPPED_BASE;
87867+
87868+#ifdef CONFIG_PAX_RANDMMAP
87869+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87870+ info.low_limit += mm->delta_mmap;
87871+#endif
87872+
87873 info.high_limit = TASK_SIZE;
87874 addr = vm_unmapped_area(&info);
87875 }
87876@@ -2027,6 +2308,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
87877 return vma;
87878 }
87879
87880+#ifdef CONFIG_PAX_SEGMEXEC
87881+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
87882+{
87883+ struct vm_area_struct *vma_m;
87884+
87885+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
87886+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
87887+ BUG_ON(vma->vm_mirror);
87888+ return NULL;
87889+ }
87890+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
87891+ vma_m = vma->vm_mirror;
87892+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
87893+ BUG_ON(vma->vm_file != vma_m->vm_file);
87894+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
87895+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
87896+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
87897+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
87898+ return vma_m;
87899+}
87900+#endif
87901+
87902 /*
87903 * Verify that the stack growth is acceptable and
87904 * update accounting. This is shared with both the
87905@@ -2043,6 +2346,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87906 return -ENOMEM;
87907
87908 /* Stack limit test */
87909+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
87910 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
87911 return -ENOMEM;
87912
87913@@ -2053,6 +2357,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87914 locked = mm->locked_vm + grow;
87915 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
87916 limit >>= PAGE_SHIFT;
87917+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
87918 if (locked > limit && !capable(CAP_IPC_LOCK))
87919 return -ENOMEM;
87920 }
87921@@ -2082,37 +2387,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87922 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
87923 * vma is the last one with address > vma->vm_end. Have to extend vma.
87924 */
87925+#ifndef CONFIG_IA64
87926+static
87927+#endif
87928 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
87929 {
87930 int error;
87931+ bool locknext;
87932
87933 if (!(vma->vm_flags & VM_GROWSUP))
87934 return -EFAULT;
87935
87936+ /* Also guard against wrapping around to address 0. */
87937+ if (address < PAGE_ALIGN(address+1))
87938+ address = PAGE_ALIGN(address+1);
87939+ else
87940+ return -ENOMEM;
87941+
87942 /*
87943 * We must make sure the anon_vma is allocated
87944 * so that the anon_vma locking is not a noop.
87945 */
87946 if (unlikely(anon_vma_prepare(vma)))
87947 return -ENOMEM;
87948+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
87949+ if (locknext && anon_vma_prepare(vma->vm_next))
87950+ return -ENOMEM;
87951 vma_lock_anon_vma(vma);
87952+ if (locknext)
87953+ vma_lock_anon_vma(vma->vm_next);
87954
87955 /*
87956 * vma->vm_start/vm_end cannot change under us because the caller
87957 * is required to hold the mmap_sem in read mode. We need the
87958- * anon_vma lock to serialize against concurrent expand_stacks.
87959- * Also guard against wrapping around to address 0.
87960+ * anon_vma locks to serialize against concurrent expand_stacks
87961+ * and expand_upwards.
87962 */
87963- if (address < PAGE_ALIGN(address+4))
87964- address = PAGE_ALIGN(address+4);
87965- else {
87966- vma_unlock_anon_vma(vma);
87967- return -ENOMEM;
87968- }
87969 error = 0;
87970
87971 /* Somebody else might have raced and expanded it already */
87972- if (address > vma->vm_end) {
87973+ 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)
87974+ error = -ENOMEM;
87975+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
87976 unsigned long size, grow;
87977
87978 size = address - vma->vm_start;
87979@@ -2147,6 +2463,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
87980 }
87981 }
87982 }
87983+ if (locknext)
87984+ vma_unlock_anon_vma(vma->vm_next);
87985 vma_unlock_anon_vma(vma);
87986 khugepaged_enter_vma_merge(vma);
87987 validate_mm(vma->vm_mm);
87988@@ -2161,6 +2479,8 @@ int expand_downwards(struct vm_area_struct *vma,
87989 unsigned long address)
87990 {
87991 int error;
87992+ bool lockprev = false;
87993+ struct vm_area_struct *prev;
87994
87995 /*
87996 * We must make sure the anon_vma is allocated
87997@@ -2174,6 +2494,15 @@ int expand_downwards(struct vm_area_struct *vma,
87998 if (error)
87999 return error;
88000
88001+ prev = vma->vm_prev;
88002+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
88003+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
88004+#endif
88005+ if (lockprev && anon_vma_prepare(prev))
88006+ return -ENOMEM;
88007+ if (lockprev)
88008+ vma_lock_anon_vma(prev);
88009+
88010 vma_lock_anon_vma(vma);
88011
88012 /*
88013@@ -2183,9 +2512,17 @@ int expand_downwards(struct vm_area_struct *vma,
88014 */
88015
88016 /* Somebody else might have raced and expanded it already */
88017- if (address < vma->vm_start) {
88018+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
88019+ error = -ENOMEM;
88020+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
88021 unsigned long size, grow;
88022
88023+#ifdef CONFIG_PAX_SEGMEXEC
88024+ struct vm_area_struct *vma_m;
88025+
88026+ vma_m = pax_find_mirror_vma(vma);
88027+#endif
88028+
88029 size = vma->vm_end - address;
88030 grow = (vma->vm_start - address) >> PAGE_SHIFT;
88031
88032@@ -2210,13 +2547,27 @@ int expand_downwards(struct vm_area_struct *vma,
88033 vma->vm_pgoff -= grow;
88034 anon_vma_interval_tree_post_update_vma(vma);
88035 vma_gap_update(vma);
88036+
88037+#ifdef CONFIG_PAX_SEGMEXEC
88038+ if (vma_m) {
88039+ anon_vma_interval_tree_pre_update_vma(vma_m);
88040+ vma_m->vm_start -= grow << PAGE_SHIFT;
88041+ vma_m->vm_pgoff -= grow;
88042+ anon_vma_interval_tree_post_update_vma(vma_m);
88043+ vma_gap_update(vma_m);
88044+ }
88045+#endif
88046+
88047 spin_unlock(&vma->vm_mm->page_table_lock);
88048
88049+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
88050 perf_event_mmap(vma);
88051 }
88052 }
88053 }
88054 vma_unlock_anon_vma(vma);
88055+ if (lockprev)
88056+ vma_unlock_anon_vma(prev);
88057 khugepaged_enter_vma_merge(vma);
88058 validate_mm(vma->vm_mm);
88059 return error;
88060@@ -2314,6 +2665,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
88061 do {
88062 long nrpages = vma_pages(vma);
88063
88064+#ifdef CONFIG_PAX_SEGMEXEC
88065+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
88066+ vma = remove_vma(vma);
88067+ continue;
88068+ }
88069+#endif
88070+
88071 if (vma->vm_flags & VM_ACCOUNT)
88072 nr_accounted += nrpages;
88073 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
88074@@ -2358,6 +2716,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
88075 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
88076 vma->vm_prev = NULL;
88077 do {
88078+
88079+#ifdef CONFIG_PAX_SEGMEXEC
88080+ if (vma->vm_mirror) {
88081+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
88082+ vma->vm_mirror->vm_mirror = NULL;
88083+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
88084+ vma->vm_mirror = NULL;
88085+ }
88086+#endif
88087+
88088 vma_rb_erase(vma, &mm->mm_rb);
88089 mm->map_count--;
88090 tail_vma = vma;
88091@@ -2384,14 +2752,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88092 struct vm_area_struct *new;
88093 int err = -ENOMEM;
88094
88095+#ifdef CONFIG_PAX_SEGMEXEC
88096+ struct vm_area_struct *vma_m, *new_m = NULL;
88097+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
88098+#endif
88099+
88100 if (is_vm_hugetlb_page(vma) && (addr &
88101 ~(huge_page_mask(hstate_vma(vma)))))
88102 return -EINVAL;
88103
88104+#ifdef CONFIG_PAX_SEGMEXEC
88105+ vma_m = pax_find_mirror_vma(vma);
88106+#endif
88107+
88108 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88109 if (!new)
88110 goto out_err;
88111
88112+#ifdef CONFIG_PAX_SEGMEXEC
88113+ if (vma_m) {
88114+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88115+ if (!new_m) {
88116+ kmem_cache_free(vm_area_cachep, new);
88117+ goto out_err;
88118+ }
88119+ }
88120+#endif
88121+
88122 /* most fields are the same, copy all, and then fixup */
88123 *new = *vma;
88124
88125@@ -2404,6 +2791,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88126 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
88127 }
88128
88129+#ifdef CONFIG_PAX_SEGMEXEC
88130+ if (vma_m) {
88131+ *new_m = *vma_m;
88132+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
88133+ new_m->vm_mirror = new;
88134+ new->vm_mirror = new_m;
88135+
88136+ if (new_below)
88137+ new_m->vm_end = addr_m;
88138+ else {
88139+ new_m->vm_start = addr_m;
88140+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
88141+ }
88142+ }
88143+#endif
88144+
88145 pol = mpol_dup(vma_policy(vma));
88146 if (IS_ERR(pol)) {
88147 err = PTR_ERR(pol);
88148@@ -2426,6 +2829,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88149 else
88150 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
88151
88152+#ifdef CONFIG_PAX_SEGMEXEC
88153+ if (!err && vma_m) {
88154+ if (anon_vma_clone(new_m, vma_m))
88155+ goto out_free_mpol;
88156+
88157+ mpol_get(pol);
88158+ vma_set_policy(new_m, pol);
88159+
88160+ if (new_m->vm_file)
88161+ get_file(new_m->vm_file);
88162+
88163+ if (new_m->vm_ops && new_m->vm_ops->open)
88164+ new_m->vm_ops->open(new_m);
88165+
88166+ if (new_below)
88167+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
88168+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
88169+ else
88170+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
88171+
88172+ if (err) {
88173+ if (new_m->vm_ops && new_m->vm_ops->close)
88174+ new_m->vm_ops->close(new_m);
88175+ if (new_m->vm_file)
88176+ fput(new_m->vm_file);
88177+ mpol_put(pol);
88178+ }
88179+ }
88180+#endif
88181+
88182 /* Success. */
88183 if (!err)
88184 return 0;
88185@@ -2435,10 +2868,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88186 new->vm_ops->close(new);
88187 if (new->vm_file)
88188 fput(new->vm_file);
88189- unlink_anon_vmas(new);
88190 out_free_mpol:
88191 mpol_put(pol);
88192 out_free_vma:
88193+
88194+#ifdef CONFIG_PAX_SEGMEXEC
88195+ if (new_m) {
88196+ unlink_anon_vmas(new_m);
88197+ kmem_cache_free(vm_area_cachep, new_m);
88198+ }
88199+#endif
88200+
88201+ unlink_anon_vmas(new);
88202 kmem_cache_free(vm_area_cachep, new);
88203 out_err:
88204 return err;
88205@@ -2451,6 +2892,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88206 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88207 unsigned long addr, int new_below)
88208 {
88209+
88210+#ifdef CONFIG_PAX_SEGMEXEC
88211+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
88212+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
88213+ if (mm->map_count >= sysctl_max_map_count-1)
88214+ return -ENOMEM;
88215+ } else
88216+#endif
88217+
88218 if (mm->map_count >= sysctl_max_map_count)
88219 return -ENOMEM;
88220
88221@@ -2462,11 +2912,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88222 * work. This now handles partial unmappings.
88223 * Jeremy Fitzhardinge <jeremy@goop.org>
88224 */
88225+#ifdef CONFIG_PAX_SEGMEXEC
88226 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88227 {
88228+ int ret = __do_munmap(mm, start, len);
88229+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
88230+ return ret;
88231+
88232+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
88233+}
88234+
88235+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88236+#else
88237+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88238+#endif
88239+{
88240 unsigned long end;
88241 struct vm_area_struct *vma, *prev, *last;
88242
88243+ /*
88244+ * mm->mmap_sem is required to protect against another thread
88245+ * changing the mappings in case we sleep.
88246+ */
88247+ verify_mm_writelocked(mm);
88248+
88249 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
88250 return -EINVAL;
88251
88252@@ -2541,6 +3010,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88253 /* Fix up all other VM information */
88254 remove_vma_list(mm, vma);
88255
88256+ track_exec_limit(mm, start, end, 0UL);
88257+
88258 return 0;
88259 }
88260
88261@@ -2549,6 +3020,13 @@ int vm_munmap(unsigned long start, size_t len)
88262 int ret;
88263 struct mm_struct *mm = current->mm;
88264
88265+
88266+#ifdef CONFIG_PAX_SEGMEXEC
88267+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
88268+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
88269+ return -EINVAL;
88270+#endif
88271+
88272 down_write(&mm->mmap_sem);
88273 ret = do_munmap(mm, start, len);
88274 up_write(&mm->mmap_sem);
88275@@ -2562,16 +3040,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
88276 return vm_munmap(addr, len);
88277 }
88278
88279-static inline void verify_mm_writelocked(struct mm_struct *mm)
88280-{
88281-#ifdef CONFIG_DEBUG_VM
88282- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
88283- WARN_ON(1);
88284- up_read(&mm->mmap_sem);
88285- }
88286-#endif
88287-}
88288-
88289 /*
88290 * this is really a simplified "do_mmap". it only handles
88291 * anonymous maps. eventually we may be able to do some
88292@@ -2585,6 +3053,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88293 struct rb_node ** rb_link, * rb_parent;
88294 pgoff_t pgoff = addr >> PAGE_SHIFT;
88295 int error;
88296+ unsigned long charged;
88297
88298 len = PAGE_ALIGN(len);
88299 if (!len)
88300@@ -2592,16 +3061,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88301
88302 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
88303
88304+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
88305+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
88306+ flags &= ~VM_EXEC;
88307+
88308+#ifdef CONFIG_PAX_MPROTECT
88309+ if (mm->pax_flags & MF_PAX_MPROTECT)
88310+ flags &= ~VM_MAYEXEC;
88311+#endif
88312+
88313+ }
88314+#endif
88315+
88316 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
88317 if (error & ~PAGE_MASK)
88318 return error;
88319
88320+ charged = len >> PAGE_SHIFT;
88321+
88322 /*
88323 * mlock MCL_FUTURE?
88324 */
88325 if (mm->def_flags & VM_LOCKED) {
88326 unsigned long locked, lock_limit;
88327- locked = len >> PAGE_SHIFT;
88328+ locked = charged;
88329 locked += mm->locked_vm;
88330 lock_limit = rlimit(RLIMIT_MEMLOCK);
88331 lock_limit >>= PAGE_SHIFT;
88332@@ -2618,21 +3101,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88333 /*
88334 * Clear old maps. this also does some error checking for us
88335 */
88336- munmap_back:
88337 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
88338 if (do_munmap(mm, addr, len))
88339 return -ENOMEM;
88340- goto munmap_back;
88341+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
88342 }
88343
88344 /* Check against address space limits *after* clearing old maps... */
88345- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
88346+ if (!may_expand_vm(mm, charged))
88347 return -ENOMEM;
88348
88349 if (mm->map_count > sysctl_max_map_count)
88350 return -ENOMEM;
88351
88352- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
88353+ if (security_vm_enough_memory_mm(mm, charged))
88354 return -ENOMEM;
88355
88356 /* Can we just expand an old private anonymous mapping? */
88357@@ -2646,7 +3128,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88358 */
88359 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88360 if (!vma) {
88361- vm_unacct_memory(len >> PAGE_SHIFT);
88362+ vm_unacct_memory(charged);
88363 return -ENOMEM;
88364 }
88365
88366@@ -2660,9 +3142,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88367 vma_link(mm, vma, prev, rb_link, rb_parent);
88368 out:
88369 perf_event_mmap(vma);
88370- mm->total_vm += len >> PAGE_SHIFT;
88371+ mm->total_vm += charged;
88372 if (flags & VM_LOCKED)
88373- mm->locked_vm += (len >> PAGE_SHIFT);
88374+ mm->locked_vm += charged;
88375+ track_exec_limit(mm, addr, addr + len, flags);
88376 return addr;
88377 }
88378
88379@@ -2724,6 +3207,7 @@ void exit_mmap(struct mm_struct *mm)
88380 while (vma) {
88381 if (vma->vm_flags & VM_ACCOUNT)
88382 nr_accounted += vma_pages(vma);
88383+ vma->vm_mirror = NULL;
88384 vma = remove_vma(vma);
88385 }
88386 vm_unacct_memory(nr_accounted);
88387@@ -2740,6 +3224,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
88388 struct vm_area_struct *prev;
88389 struct rb_node **rb_link, *rb_parent;
88390
88391+#ifdef CONFIG_PAX_SEGMEXEC
88392+ struct vm_area_struct *vma_m = NULL;
88393+#endif
88394+
88395+ if (security_mmap_addr(vma->vm_start))
88396+ return -EPERM;
88397+
88398 /*
88399 * The vm_pgoff of a purely anonymous vma should be irrelevant
88400 * until its first write fault, when page's anon_vma and index
88401@@ -2763,7 +3254,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
88402 security_vm_enough_memory_mm(mm, vma_pages(vma)))
88403 return -ENOMEM;
88404
88405+#ifdef CONFIG_PAX_SEGMEXEC
88406+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
88407+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88408+ if (!vma_m)
88409+ return -ENOMEM;
88410+ }
88411+#endif
88412+
88413 vma_link(mm, vma, prev, rb_link, rb_parent);
88414+
88415+#ifdef CONFIG_PAX_SEGMEXEC
88416+ if (vma_m)
88417+ BUG_ON(pax_mirror_vma(vma_m, vma));
88418+#endif
88419+
88420 return 0;
88421 }
88422
88423@@ -2783,6 +3288,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88424 struct mempolicy *pol;
88425 bool faulted_in_anon_vma = true;
88426
88427+ BUG_ON(vma->vm_mirror);
88428+
88429 /*
88430 * If anonymous vma has not yet been faulted, update new pgoff
88431 * to match new location, to increase its chance of merging.
88432@@ -2849,6 +3356,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88433 return NULL;
88434 }
88435
88436+#ifdef CONFIG_PAX_SEGMEXEC
88437+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
88438+{
88439+ struct vm_area_struct *prev_m;
88440+ struct rb_node **rb_link_m, *rb_parent_m;
88441+ struct mempolicy *pol_m;
88442+
88443+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
88444+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
88445+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
88446+ *vma_m = *vma;
88447+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
88448+ if (anon_vma_clone(vma_m, vma))
88449+ return -ENOMEM;
88450+ pol_m = vma_policy(vma_m);
88451+ mpol_get(pol_m);
88452+ vma_set_policy(vma_m, pol_m);
88453+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
88454+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
88455+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
88456+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
88457+ if (vma_m->vm_file)
88458+ get_file(vma_m->vm_file);
88459+ if (vma_m->vm_ops && vma_m->vm_ops->open)
88460+ vma_m->vm_ops->open(vma_m);
88461+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
88462+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
88463+ vma_m->vm_mirror = vma;
88464+ vma->vm_mirror = vma_m;
88465+ return 0;
88466+}
88467+#endif
88468+
88469 /*
88470 * Return true if the calling process may expand its vm space by the passed
88471 * number of pages
88472@@ -2860,6 +3400,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
88473
88474 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
88475
88476+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
88477 if (cur + npages > lim)
88478 return 0;
88479 return 1;
88480@@ -2930,6 +3471,22 @@ int install_special_mapping(struct mm_struct *mm,
88481 vma->vm_start = addr;
88482 vma->vm_end = addr + len;
88483
88484+#ifdef CONFIG_PAX_MPROTECT
88485+ if (mm->pax_flags & MF_PAX_MPROTECT) {
88486+#ifndef CONFIG_PAX_MPROTECT_COMPAT
88487+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
88488+ return -EPERM;
88489+ if (!(vm_flags & VM_EXEC))
88490+ vm_flags &= ~VM_MAYEXEC;
88491+#else
88492+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
88493+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
88494+#endif
88495+ else
88496+ vm_flags &= ~VM_MAYWRITE;
88497+ }
88498+#endif
88499+
88500 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
88501 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
88502
88503diff --git a/mm/mprotect.c b/mm/mprotect.c
88504index 94722a4..e661e29 100644
88505--- a/mm/mprotect.c
88506+++ b/mm/mprotect.c
88507@@ -23,10 +23,18 @@
88508 #include <linux/mmu_notifier.h>
88509 #include <linux/migrate.h>
88510 #include <linux/perf_event.h>
88511+#include <linux/sched/sysctl.h>
88512+
88513+#ifdef CONFIG_PAX_MPROTECT
88514+#include <linux/elf.h>
88515+#include <linux/binfmts.h>
88516+#endif
88517+
88518 #include <asm/uaccess.h>
88519 #include <asm/pgtable.h>
88520 #include <asm/cacheflush.h>
88521 #include <asm/tlbflush.h>
88522+#include <asm/mmu_context.h>
88523
88524 #ifndef pgprot_modify
88525 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
88526@@ -233,6 +241,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
88527 return pages;
88528 }
88529
88530+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88531+/* called while holding the mmap semaphor for writing except stack expansion */
88532+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
88533+{
88534+ unsigned long oldlimit, newlimit = 0UL;
88535+
88536+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
88537+ return;
88538+
88539+ spin_lock(&mm->page_table_lock);
88540+ oldlimit = mm->context.user_cs_limit;
88541+ if ((prot & VM_EXEC) && oldlimit < end)
88542+ /* USER_CS limit moved up */
88543+ newlimit = end;
88544+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
88545+ /* USER_CS limit moved down */
88546+ newlimit = start;
88547+
88548+ if (newlimit) {
88549+ mm->context.user_cs_limit = newlimit;
88550+
88551+#ifdef CONFIG_SMP
88552+ wmb();
88553+ cpus_clear(mm->context.cpu_user_cs_mask);
88554+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
88555+#endif
88556+
88557+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
88558+ }
88559+ spin_unlock(&mm->page_table_lock);
88560+ if (newlimit == end) {
88561+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
88562+
88563+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
88564+ if (is_vm_hugetlb_page(vma))
88565+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
88566+ else
88567+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
88568+ }
88569+}
88570+#endif
88571+
88572 int
88573 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88574 unsigned long start, unsigned long end, unsigned long newflags)
88575@@ -245,11 +295,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88576 int error;
88577 int dirty_accountable = 0;
88578
88579+#ifdef CONFIG_PAX_SEGMEXEC
88580+ struct vm_area_struct *vma_m = NULL;
88581+ unsigned long start_m, end_m;
88582+
88583+ start_m = start + SEGMEXEC_TASK_SIZE;
88584+ end_m = end + SEGMEXEC_TASK_SIZE;
88585+#endif
88586+
88587 if (newflags == oldflags) {
88588 *pprev = vma;
88589 return 0;
88590 }
88591
88592+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
88593+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
88594+
88595+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
88596+ return -ENOMEM;
88597+
88598+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
88599+ return -ENOMEM;
88600+ }
88601+
88602 /*
88603 * If we make a private mapping writable we increase our commit;
88604 * but (without finer accounting) cannot reduce our commit if we
88605@@ -266,6 +334,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88606 }
88607 }
88608
88609+#ifdef CONFIG_PAX_SEGMEXEC
88610+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
88611+ if (start != vma->vm_start) {
88612+ error = split_vma(mm, vma, start, 1);
88613+ if (error)
88614+ goto fail;
88615+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
88616+ *pprev = (*pprev)->vm_next;
88617+ }
88618+
88619+ if (end != vma->vm_end) {
88620+ error = split_vma(mm, vma, end, 0);
88621+ if (error)
88622+ goto fail;
88623+ }
88624+
88625+ if (pax_find_mirror_vma(vma)) {
88626+ error = __do_munmap(mm, start_m, end_m - start_m);
88627+ if (error)
88628+ goto fail;
88629+ } else {
88630+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88631+ if (!vma_m) {
88632+ error = -ENOMEM;
88633+ goto fail;
88634+ }
88635+ vma->vm_flags = newflags;
88636+ error = pax_mirror_vma(vma_m, vma);
88637+ if (error) {
88638+ vma->vm_flags = oldflags;
88639+ goto fail;
88640+ }
88641+ }
88642+ }
88643+#endif
88644+
88645 /*
88646 * First try to merge with previous and/or next vma.
88647 */
88648@@ -296,9 +400,21 @@ success:
88649 * vm_flags and vm_page_prot are protected by the mmap_sem
88650 * held in write mode.
88651 */
88652+
88653+#ifdef CONFIG_PAX_SEGMEXEC
88654+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
88655+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
88656+#endif
88657+
88658 vma->vm_flags = newflags;
88659+
88660+#ifdef CONFIG_PAX_MPROTECT
88661+ if (mm->binfmt && mm->binfmt->handle_mprotect)
88662+ mm->binfmt->handle_mprotect(vma, newflags);
88663+#endif
88664+
88665 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
88666- vm_get_page_prot(newflags));
88667+ vm_get_page_prot(vma->vm_flags));
88668
88669 if (vma_wants_writenotify(vma)) {
88670 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
88671@@ -337,6 +453,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88672 end = start + len;
88673 if (end <= start)
88674 return -ENOMEM;
88675+
88676+#ifdef CONFIG_PAX_SEGMEXEC
88677+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
88678+ if (end > SEGMEXEC_TASK_SIZE)
88679+ return -EINVAL;
88680+ } else
88681+#endif
88682+
88683+ if (end > TASK_SIZE)
88684+ return -EINVAL;
88685+
88686 if (!arch_validate_prot(prot))
88687 return -EINVAL;
88688
88689@@ -344,7 +471,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88690 /*
88691 * Does the application expect PROT_READ to imply PROT_EXEC:
88692 */
88693- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
88694+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
88695 prot |= PROT_EXEC;
88696
88697 vm_flags = calc_vm_prot_bits(prot);
88698@@ -376,6 +503,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88699 if (start > vma->vm_start)
88700 prev = vma;
88701
88702+#ifdef CONFIG_PAX_MPROTECT
88703+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
88704+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
88705+#endif
88706+
88707 for (nstart = start ; ; ) {
88708 unsigned long newflags;
88709
88710@@ -386,6 +518,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88711
88712 /* newflags >> 4 shift VM_MAY% in place of VM_% */
88713 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
88714+ if (prot & (PROT_WRITE | PROT_EXEC))
88715+ gr_log_rwxmprotect(vma);
88716+
88717+ error = -EACCES;
88718+ goto out;
88719+ }
88720+
88721+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
88722 error = -EACCES;
88723 goto out;
88724 }
88725@@ -400,6 +540,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88726 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
88727 if (error)
88728 goto out;
88729+
88730+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
88731+
88732 nstart = tmp;
88733
88734 if (nstart < prev->vm_end)
88735diff --git a/mm/mremap.c b/mm/mremap.c
88736index 0843feb..5607f47 100644
88737--- a/mm/mremap.c
88738+++ b/mm/mremap.c
88739@@ -25,6 +25,7 @@
88740 #include <asm/uaccess.h>
88741 #include <asm/cacheflush.h>
88742 #include <asm/tlbflush.h>
88743+#include <asm/pgalloc.h>
88744
88745 #include "internal.h"
88746
88747@@ -62,8 +63,10 @@ static pmd_t *alloc_new_pmd(struct mm_struct *mm, struct vm_area_struct *vma,
88748 return NULL;
88749
88750 pmd = pmd_alloc(mm, pud, addr);
88751- if (!pmd)
88752+ if (!pmd) {
88753+ pud_free(mm, pud);
88754 return NULL;
88755+ }
88756
88757 VM_BUG_ON(pmd_trans_huge(*pmd));
88758
88759@@ -144,6 +147,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
88760 continue;
88761 pte = ptep_get_and_clear(mm, old_addr, old_pte);
88762 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
88763+
88764+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88765+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
88766+ pte = pte_exprotect(pte);
88767+#endif
88768+
88769 pte = move_soft_dirty_pte(pte);
88770 set_pte_at(mm, new_addr, new_pte, pte);
88771 }
88772@@ -337,6 +346,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
88773 if (is_vm_hugetlb_page(vma))
88774 goto Einval;
88775
88776+#ifdef CONFIG_PAX_SEGMEXEC
88777+ if (pax_find_mirror_vma(vma))
88778+ goto Einval;
88779+#endif
88780+
88781 /* We can't remap across vm area boundaries */
88782 if (old_len > vma->vm_end - addr)
88783 goto Efault;
88784@@ -392,20 +406,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
88785 unsigned long ret = -EINVAL;
88786 unsigned long charged = 0;
88787 unsigned long map_flags;
88788+ unsigned long pax_task_size = TASK_SIZE;
88789
88790 if (new_addr & ~PAGE_MASK)
88791 goto out;
88792
88793- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
88794+#ifdef CONFIG_PAX_SEGMEXEC
88795+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88796+ pax_task_size = SEGMEXEC_TASK_SIZE;
88797+#endif
88798+
88799+ pax_task_size -= PAGE_SIZE;
88800+
88801+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
88802 goto out;
88803
88804 /* Check if the location we're moving into overlaps the
88805 * old location at all, and fail if it does.
88806 */
88807- if ((new_addr <= addr) && (new_addr+new_len) > addr)
88808- goto out;
88809-
88810- if ((addr <= new_addr) && (addr+old_len) > new_addr)
88811+ if (addr + old_len > new_addr && new_addr + new_len > addr)
88812 goto out;
88813
88814 ret = do_munmap(mm, new_addr, new_len);
88815@@ -474,6 +493,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88816 unsigned long ret = -EINVAL;
88817 unsigned long charged = 0;
88818 bool locked = false;
88819+ unsigned long pax_task_size = TASK_SIZE;
88820
88821 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
88822 return ret;
88823@@ -495,6 +515,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88824 if (!new_len)
88825 return ret;
88826
88827+#ifdef CONFIG_PAX_SEGMEXEC
88828+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88829+ pax_task_size = SEGMEXEC_TASK_SIZE;
88830+#endif
88831+
88832+ pax_task_size -= PAGE_SIZE;
88833+
88834+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
88835+ old_len > pax_task_size || addr > pax_task_size-old_len)
88836+ return ret;
88837+
88838 down_write(&current->mm->mmap_sem);
88839
88840 if (flags & MREMAP_FIXED) {
88841@@ -545,6 +576,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88842 new_addr = addr;
88843 }
88844 ret = addr;
88845+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
88846 goto out;
88847 }
88848 }
88849@@ -568,7 +600,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88850 goto out;
88851 }
88852
88853+ map_flags = vma->vm_flags;
88854 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
88855+ if (!(ret & ~PAGE_MASK)) {
88856+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
88857+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
88858+ }
88859 }
88860 out:
88861 if (ret & ~PAGE_MASK)
88862diff --git a/mm/nommu.c b/mm/nommu.c
88863index ecd1f15..77039bd 100644
88864--- a/mm/nommu.c
88865+++ b/mm/nommu.c
88866@@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
88867 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
88868 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
88869 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
88870-int heap_stack_gap = 0;
88871
88872 atomic_long_t mmap_pages_allocated;
88873
88874@@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
88875 EXPORT_SYMBOL(find_vma);
88876
88877 /*
88878- * find a VMA
88879- * - we don't extend stack VMAs under NOMMU conditions
88880- */
88881-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
88882-{
88883- return find_vma(mm, addr);
88884-}
88885-
88886-/*
88887 * expand a stack to a given address
88888 * - not supported under NOMMU conditions
88889 */
88890@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88891
88892 /* most fields are the same, copy all, and then fixup */
88893 *new = *vma;
88894+ INIT_LIST_HEAD(&new->anon_vma_chain);
88895 *region = *vma->vm_region;
88896 new->vm_region = region;
88897
88898@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
88899 }
88900 EXPORT_SYMBOL(generic_file_remap_pages);
88901
88902-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88903- unsigned long addr, void *buf, int len, int write)
88904+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88905+ unsigned long addr, void *buf, size_t len, int write)
88906 {
88907 struct vm_area_struct *vma;
88908
88909@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88910 *
88911 * The caller must hold a reference on @mm.
88912 */
88913-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88914- void *buf, int len, int write)
88915+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
88916+ void *buf, size_t len, int write)
88917 {
88918 return __access_remote_vm(NULL, mm, addr, buf, len, write);
88919 }
88920@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88921 * Access another process' address space.
88922 * - source/target buffer must be kernel space
88923 */
88924-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
88925+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
88926 {
88927 struct mm_struct *mm;
88928
88929diff --git a/mm/page-writeback.c b/mm/page-writeback.c
88930index 3f0c895..60cd104 100644
88931--- a/mm/page-writeback.c
88932+++ b/mm/page-writeback.c
88933@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
88934 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
88935 * - the bdi dirty thresh drops quickly due to change of JBOD workload
88936 */
88937-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
88938+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
88939 unsigned long thresh,
88940 unsigned long bg_thresh,
88941 unsigned long dirty,
88942diff --git a/mm/page_alloc.c b/mm/page_alloc.c
88943index b100255..a59b444 100644
88944--- a/mm/page_alloc.c
88945+++ b/mm/page_alloc.c
88946@@ -60,6 +60,7 @@
88947 #include <linux/page-debug-flags.h>
88948 #include <linux/hugetlb.h>
88949 #include <linux/sched/rt.h>
88950+#include <linux/random.h>
88951
88952 #include <asm/sections.h>
88953 #include <asm/tlbflush.h>
88954@@ -353,7 +354,7 @@ out:
88955 * This usage means that zero-order pages may not be compound.
88956 */
88957
88958-static void free_compound_page(struct page *page)
88959+void free_compound_page(struct page *page)
88960 {
88961 __free_pages_ok(page, compound_order(page));
88962 }
88963@@ -710,6 +711,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
88964 int i;
88965 int bad = 0;
88966
88967+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88968+ unsigned long index = 1UL << order;
88969+#endif
88970+
88971 trace_mm_page_free(page, order);
88972 kmemcheck_free_shadow(page, order);
88973
88974@@ -725,6 +730,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
88975 debug_check_no_obj_freed(page_address(page),
88976 PAGE_SIZE << order);
88977 }
88978+
88979+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88980+ for (; index; --index)
88981+ sanitize_highpage(page + index - 1);
88982+#endif
88983+
88984 arch_free_page(page, order);
88985 kernel_map_pages(page, 1 << order, 0);
88986
88987@@ -747,6 +758,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
88988 local_irq_restore(flags);
88989 }
88990
88991+#ifdef CONFIG_PAX_LATENT_ENTROPY
88992+bool __meminitdata extra_latent_entropy;
88993+
88994+static int __init setup_pax_extra_latent_entropy(char *str)
88995+{
88996+ extra_latent_entropy = true;
88997+ return 0;
88998+}
88999+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
89000+
89001+volatile u64 latent_entropy;
89002+#endif
89003+
89004 void __init __free_pages_bootmem(struct page *page, unsigned int order)
89005 {
89006 unsigned int nr_pages = 1 << order;
89007@@ -762,6 +786,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
89008 set_page_count(p, 0);
89009 }
89010
89011+#ifdef CONFIG_PAX_LATENT_ENTROPY
89012+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
89013+ u64 hash = 0;
89014+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
89015+ const u64 *data = lowmem_page_address(page);
89016+
89017+ for (index = 0; index < end; index++)
89018+ hash ^= hash + data[index];
89019+ latent_entropy ^= hash;
89020+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
89021+ }
89022+#endif
89023+
89024 page_zone(page)->managed_pages += 1 << order;
89025 set_page_refcounted(page);
89026 __free_pages(page, order);
89027@@ -867,8 +904,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
89028 arch_alloc_page(page, order);
89029 kernel_map_pages(page, 1 << order, 1);
89030
89031+#ifndef CONFIG_PAX_MEMORY_SANITIZE
89032 if (gfp_flags & __GFP_ZERO)
89033 prep_zero_page(page, order, gfp_flags);
89034+#endif
89035
89036 if (order && (gfp_flags & __GFP_COMP))
89037 prep_compound_page(page, order);
89038diff --git a/mm/page_io.c b/mm/page_io.c
89039index ba05b64..ef2f314 100644
89040--- a/mm/page_io.c
89041+++ b/mm/page_io.c
89042@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
89043 struct file *swap_file = sis->swap_file;
89044 struct address_space *mapping = swap_file->f_mapping;
89045 struct iovec iov = {
89046- .iov_base = kmap(page),
89047+ .iov_base = (void __force_user *)kmap(page),
89048 .iov_len = PAGE_SIZE,
89049 };
89050
89051diff --git a/mm/percpu.c b/mm/percpu.c
89052index 8c8e08f..73a5cda 100644
89053--- a/mm/percpu.c
89054+++ b/mm/percpu.c
89055@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
89056 static unsigned int pcpu_high_unit_cpu __read_mostly;
89057
89058 /* the address of the first chunk which starts with the kernel static area */
89059-void *pcpu_base_addr __read_mostly;
89060+void *pcpu_base_addr __read_only;
89061 EXPORT_SYMBOL_GPL(pcpu_base_addr);
89062
89063 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
89064diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
89065index fd26d04..0cea1b0 100644
89066--- a/mm/process_vm_access.c
89067+++ b/mm/process_vm_access.c
89068@@ -13,6 +13,7 @@
89069 #include <linux/uio.h>
89070 #include <linux/sched.h>
89071 #include <linux/highmem.h>
89072+#include <linux/security.h>
89073 #include <linux/ptrace.h>
89074 #include <linux/slab.h>
89075 #include <linux/syscalls.h>
89076@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
89077 size_t iov_l_curr_offset = 0;
89078 ssize_t iov_len;
89079
89080+ return -ENOSYS; // PaX: until properly audited
89081+
89082 /*
89083 * Work out how many pages of struct pages we're going to need
89084 * when eventually calling get_user_pages
89085 */
89086 for (i = 0; i < riovcnt; i++) {
89087 iov_len = rvec[i].iov_len;
89088- if (iov_len > 0) {
89089- nr_pages_iov = ((unsigned long)rvec[i].iov_base
89090- + iov_len)
89091- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
89092- / PAGE_SIZE + 1;
89093- nr_pages = max(nr_pages, nr_pages_iov);
89094- }
89095+ if (iov_len <= 0)
89096+ continue;
89097+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
89098+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
89099+ nr_pages = max(nr_pages, nr_pages_iov);
89100 }
89101
89102 if (nr_pages == 0)
89103@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
89104 goto free_proc_pages;
89105 }
89106
89107+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
89108+ rc = -EPERM;
89109+ goto put_task_struct;
89110+ }
89111+
89112 mm = mm_access(task, PTRACE_MODE_ATTACH);
89113 if (!mm || IS_ERR(mm)) {
89114 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
89115diff --git a/mm/rmap.c b/mm/rmap.c
89116index b2e29ac..4168491 100644
89117--- a/mm/rmap.c
89118+++ b/mm/rmap.c
89119@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89120 struct anon_vma *anon_vma = vma->anon_vma;
89121 struct anon_vma_chain *avc;
89122
89123+#ifdef CONFIG_PAX_SEGMEXEC
89124+ struct anon_vma_chain *avc_m = NULL;
89125+#endif
89126+
89127 might_sleep();
89128 if (unlikely(!anon_vma)) {
89129 struct mm_struct *mm = vma->vm_mm;
89130@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89131 if (!avc)
89132 goto out_enomem;
89133
89134+#ifdef CONFIG_PAX_SEGMEXEC
89135+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
89136+ if (!avc_m)
89137+ goto out_enomem_free_avc;
89138+#endif
89139+
89140 anon_vma = find_mergeable_anon_vma(vma);
89141 allocated = NULL;
89142 if (!anon_vma) {
89143@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89144 /* page_table_lock to protect against threads */
89145 spin_lock(&mm->page_table_lock);
89146 if (likely(!vma->anon_vma)) {
89147+
89148+#ifdef CONFIG_PAX_SEGMEXEC
89149+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
89150+
89151+ if (vma_m) {
89152+ BUG_ON(vma_m->anon_vma);
89153+ vma_m->anon_vma = anon_vma;
89154+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
89155+ avc_m = NULL;
89156+ }
89157+#endif
89158+
89159 vma->anon_vma = anon_vma;
89160 anon_vma_chain_link(vma, avc, anon_vma);
89161 allocated = NULL;
89162@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89163
89164 if (unlikely(allocated))
89165 put_anon_vma(allocated);
89166+
89167+#ifdef CONFIG_PAX_SEGMEXEC
89168+ if (unlikely(avc_m))
89169+ anon_vma_chain_free(avc_m);
89170+#endif
89171+
89172 if (unlikely(avc))
89173 anon_vma_chain_free(avc);
89174 }
89175 return 0;
89176
89177 out_enomem_free_avc:
89178+
89179+#ifdef CONFIG_PAX_SEGMEXEC
89180+ if (avc_m)
89181+ anon_vma_chain_free(avc_m);
89182+#endif
89183+
89184 anon_vma_chain_free(avc);
89185 out_enomem:
89186 return -ENOMEM;
89187@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
89188 * Attach the anon_vmas from src to dst.
89189 * Returns 0 on success, -ENOMEM on failure.
89190 */
89191-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
89192+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
89193 {
89194 struct anon_vma_chain *avc, *pavc;
89195 struct anon_vma *root = NULL;
89196@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
89197 * the corresponding VMA in the parent process is attached to.
89198 * Returns 0 on success, non-zero on failure.
89199 */
89200-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
89201+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
89202 {
89203 struct anon_vma_chain *avc;
89204 struct anon_vma *anon_vma;
89205@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
89206 void __init anon_vma_init(void)
89207 {
89208 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
89209- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
89210- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
89211+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
89212+ anon_vma_ctor);
89213+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
89214+ SLAB_PANIC|SLAB_NO_SANITIZE);
89215 }
89216
89217 /*
89218diff --git a/mm/shmem.c b/mm/shmem.c
89219index e43dc55..930e3a2 100644
89220--- a/mm/shmem.c
89221+++ b/mm/shmem.c
89222@@ -33,7 +33,7 @@
89223 #include <linux/swap.h>
89224 #include <linux/aio.h>
89225
89226-static struct vfsmount *shm_mnt;
89227+struct vfsmount *shm_mnt;
89228
89229 #ifdef CONFIG_SHMEM
89230 /*
89231@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
89232 #define BOGO_DIRENT_SIZE 20
89233
89234 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
89235-#define SHORT_SYMLINK_LEN 128
89236+#define SHORT_SYMLINK_LEN 64
89237
89238 /*
89239 * shmem_fallocate and shmem_writepage communicate via inode->i_private
89240@@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
89241 static int shmem_xattr_validate(const char *name)
89242 {
89243 struct { const char *prefix; size_t len; } arr[] = {
89244+
89245+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
89246+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
89247+#endif
89248+
89249 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
89250 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
89251 };
89252@@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
89253 if (err)
89254 return err;
89255
89256+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
89257+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
89258+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
89259+ return -EOPNOTSUPP;
89260+ if (size > 8)
89261+ return -EINVAL;
89262+ }
89263+#endif
89264+
89265 return simple_xattr_set(&info->xattrs, name, value, size, flags);
89266 }
89267
89268@@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
89269 int err = -ENOMEM;
89270
89271 /* Round up to L1_CACHE_BYTES to resist false sharing */
89272- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
89273- L1_CACHE_BYTES), GFP_KERNEL);
89274+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
89275 if (!sbinfo)
89276 return -ENOMEM;
89277
89278diff --git a/mm/slab.c b/mm/slab.c
89279index 2580db0..0523956 100644
89280--- a/mm/slab.c
89281+++ b/mm/slab.c
89282@@ -366,10 +366,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
89283 if ((x)->max_freeable < i) \
89284 (x)->max_freeable = i; \
89285 } while (0)
89286-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
89287-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
89288-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
89289-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
89290+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
89291+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
89292+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
89293+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
89294+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
89295+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
89296 #else
89297 #define STATS_INC_ACTIVE(x) do { } while (0)
89298 #define STATS_DEC_ACTIVE(x) do { } while (0)
89299@@ -386,6 +388,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
89300 #define STATS_INC_ALLOCMISS(x) do { } while (0)
89301 #define STATS_INC_FREEHIT(x) do { } while (0)
89302 #define STATS_INC_FREEMISS(x) do { } while (0)
89303+#define STATS_INC_SANITIZED(x) do { } while (0)
89304+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
89305 #endif
89306
89307 #if DEBUG
89308@@ -477,7 +481,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
89309 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
89310 */
89311 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
89312- const struct slab *slab, void *obj)
89313+ const struct slab *slab, const void *obj)
89314 {
89315 u32 offset = (obj - slab->s_mem);
89316 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
89317@@ -1571,12 +1575,12 @@ void __init kmem_cache_init(void)
89318 */
89319
89320 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
89321- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
89322+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
89323
89324 if (INDEX_AC != INDEX_NODE)
89325 kmalloc_caches[INDEX_NODE] =
89326 create_kmalloc_cache("kmalloc-node",
89327- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
89328+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
89329
89330 slab_early_init = 0;
89331
89332@@ -3577,6 +3581,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
89333 struct array_cache *ac = cpu_cache_get(cachep);
89334
89335 check_irq_off();
89336+
89337+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89338+ if (pax_sanitize_slab) {
89339+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
89340+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
89341+
89342+ if (cachep->ctor)
89343+ cachep->ctor(objp);
89344+
89345+ STATS_INC_SANITIZED(cachep);
89346+ } else
89347+ STATS_INC_NOT_SANITIZED(cachep);
89348+ }
89349+#endif
89350+
89351 kmemleak_free_recursive(objp, cachep->flags);
89352 objp = cache_free_debugcheck(cachep, objp, caller);
89353
89354@@ -3805,6 +3824,7 @@ void kfree(const void *objp)
89355
89356 if (unlikely(ZERO_OR_NULL_PTR(objp)))
89357 return;
89358+ VM_BUG_ON(!virt_addr_valid(objp));
89359 local_irq_save(flags);
89360 kfree_debugcheck(objp);
89361 c = virt_to_cache(objp);
89362@@ -4246,14 +4266,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
89363 }
89364 /* cpu stats */
89365 {
89366- unsigned long allochit = atomic_read(&cachep->allochit);
89367- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
89368- unsigned long freehit = atomic_read(&cachep->freehit);
89369- unsigned long freemiss = atomic_read(&cachep->freemiss);
89370+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
89371+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
89372+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
89373+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
89374
89375 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
89376 allochit, allocmiss, freehit, freemiss);
89377 }
89378+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89379+ {
89380+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
89381+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
89382+
89383+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
89384+ }
89385+#endif
89386 #endif
89387 }
89388
89389@@ -4471,13 +4499,71 @@ static const struct file_operations proc_slabstats_operations = {
89390 static int __init slab_proc_init(void)
89391 {
89392 #ifdef CONFIG_DEBUG_SLAB_LEAK
89393- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
89394+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
89395 #endif
89396 return 0;
89397 }
89398 module_init(slab_proc_init);
89399 #endif
89400
89401+bool is_usercopy_object(const void *ptr)
89402+{
89403+ struct page *page;
89404+ struct kmem_cache *cachep;
89405+
89406+ if (ZERO_OR_NULL_PTR(ptr))
89407+ return false;
89408+
89409+ if (!slab_is_available())
89410+ return false;
89411+
89412+ if (!virt_addr_valid(ptr))
89413+ return false;
89414+
89415+ page = virt_to_head_page(ptr);
89416+
89417+ if (!PageSlab(page))
89418+ return false;
89419+
89420+ cachep = page->slab_cache;
89421+ return cachep->flags & SLAB_USERCOPY;
89422+}
89423+
89424+#ifdef CONFIG_PAX_USERCOPY
89425+const char *check_heap_object(const void *ptr, unsigned long n)
89426+{
89427+ struct page *page;
89428+ struct kmem_cache *cachep;
89429+ struct slab *slabp;
89430+ unsigned int objnr;
89431+ unsigned long offset;
89432+
89433+ if (ZERO_OR_NULL_PTR(ptr))
89434+ return "<null>";
89435+
89436+ if (!virt_addr_valid(ptr))
89437+ return NULL;
89438+
89439+ page = virt_to_head_page(ptr);
89440+
89441+ if (!PageSlab(page))
89442+ return NULL;
89443+
89444+ cachep = page->slab_cache;
89445+ if (!(cachep->flags & SLAB_USERCOPY))
89446+ return cachep->name;
89447+
89448+ slabp = page->slab_page;
89449+ objnr = obj_to_index(cachep, slabp, ptr);
89450+ BUG_ON(objnr >= cachep->num);
89451+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
89452+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
89453+ return NULL;
89454+
89455+ return cachep->name;
89456+}
89457+#endif
89458+
89459 /**
89460 * ksize - get the actual amount of memory allocated for a given object
89461 * @objp: Pointer to the object
89462diff --git a/mm/slab.h b/mm/slab.h
89463index a535033..2f98fe5 100644
89464--- a/mm/slab.h
89465+++ b/mm/slab.h
89466@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
89467 /* The slab cache that manages slab cache information */
89468 extern struct kmem_cache *kmem_cache;
89469
89470+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89471+#ifdef CONFIG_X86_64
89472+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
89473+#else
89474+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
89475+#endif
89476+extern bool pax_sanitize_slab;
89477+#endif
89478+
89479 unsigned long calculate_alignment(unsigned long flags,
89480 unsigned long align, unsigned long size);
89481
89482@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
89483
89484 /* Legal flag mask for kmem_cache_create(), for various configurations */
89485 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
89486- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
89487+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
89488+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
89489
89490 #if defined(CONFIG_DEBUG_SLAB)
89491 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
89492@@ -231,6 +241,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
89493 return s;
89494
89495 page = virt_to_head_page(x);
89496+
89497+ BUG_ON(!PageSlab(page));
89498+
89499 cachep = page->slab_cache;
89500 if (slab_equal_or_root(cachep, s))
89501 return cachep;
89502diff --git a/mm/slab_common.c b/mm/slab_common.c
89503index 538bade..36fed99 100644
89504--- a/mm/slab_common.c
89505+++ b/mm/slab_common.c
89506@@ -22,11 +22,22 @@
89507
89508 #include "slab.h"
89509
89510-enum slab_state slab_state;
89511+enum slab_state slab_state __read_only;
89512 LIST_HEAD(slab_caches);
89513 DEFINE_MUTEX(slab_mutex);
89514 struct kmem_cache *kmem_cache;
89515
89516+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89517+bool pax_sanitize_slab __read_only = true;
89518+static int __init pax_sanitize_slab_setup(char *str)
89519+{
89520+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
89521+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
89522+ return 1;
89523+}
89524+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
89525+#endif
89526+
89527 #ifdef CONFIG_DEBUG_VM
89528 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
89529 size_t size)
89530@@ -209,7 +220,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
89531
89532 err = __kmem_cache_create(s, flags);
89533 if (!err) {
89534- s->refcount = 1;
89535+ atomic_set(&s->refcount, 1);
89536 list_add(&s->list, &slab_caches);
89537 memcg_cache_list_add(memcg, s);
89538 } else {
89539@@ -255,8 +266,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
89540
89541 get_online_cpus();
89542 mutex_lock(&slab_mutex);
89543- s->refcount--;
89544- if (!s->refcount) {
89545+ if (atomic_dec_and_test(&s->refcount)) {
89546 list_del(&s->list);
89547
89548 if (!__kmem_cache_shutdown(s)) {
89549@@ -302,7 +312,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
89550 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
89551 name, size, err);
89552
89553- s->refcount = -1; /* Exempt from merging for now */
89554+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
89555 }
89556
89557 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89558@@ -315,7 +325,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89559
89560 create_boot_cache(s, name, size, flags);
89561 list_add(&s->list, &slab_caches);
89562- s->refcount = 1;
89563+ atomic_set(&s->refcount, 1);
89564 return s;
89565 }
89566
89567@@ -327,6 +337,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
89568 EXPORT_SYMBOL(kmalloc_dma_caches);
89569 #endif
89570
89571+#ifdef CONFIG_PAX_USERCOPY_SLABS
89572+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
89573+EXPORT_SYMBOL(kmalloc_usercopy_caches);
89574+#endif
89575+
89576 /*
89577 * Conversion table for small slabs sizes / 8 to the index in the
89578 * kmalloc array. This is necessary for slabs < 192 since we have non power
89579@@ -391,6 +406,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
89580 return kmalloc_dma_caches[index];
89581
89582 #endif
89583+
89584+#ifdef CONFIG_PAX_USERCOPY_SLABS
89585+ if (unlikely((flags & GFP_USERCOPY)))
89586+ return kmalloc_usercopy_caches[index];
89587+
89588+#endif
89589+
89590 return kmalloc_caches[index];
89591 }
89592
89593@@ -447,7 +469,7 @@ void __init create_kmalloc_caches(unsigned long flags)
89594 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
89595 if (!kmalloc_caches[i]) {
89596 kmalloc_caches[i] = create_kmalloc_cache(NULL,
89597- 1 << i, flags);
89598+ 1 << i, SLAB_USERCOPY | flags);
89599 }
89600
89601 /*
89602@@ -456,10 +478,10 @@ void __init create_kmalloc_caches(unsigned long flags)
89603 * earlier power of two caches
89604 */
89605 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
89606- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
89607+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
89608
89609 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
89610- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
89611+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
89612 }
89613
89614 /* Kmalloc array is now usable */
89615@@ -492,6 +514,23 @@ void __init create_kmalloc_caches(unsigned long flags)
89616 }
89617 }
89618 #endif
89619+
89620+#ifdef CONFIG_PAX_USERCOPY_SLABS
89621+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
89622+ struct kmem_cache *s = kmalloc_caches[i];
89623+
89624+ if (s) {
89625+ int size = kmalloc_size(i);
89626+ char *n = kasprintf(GFP_NOWAIT,
89627+ "usercopy-kmalloc-%d", size);
89628+
89629+ BUG_ON(!n);
89630+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
89631+ size, SLAB_USERCOPY | flags);
89632+ }
89633+ }
89634+#endif
89635+
89636 }
89637 #endif /* !CONFIG_SLOB */
89638
89639@@ -523,6 +562,9 @@ void print_slabinfo_header(struct seq_file *m)
89640 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
89641 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
89642 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
89643+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89644+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
89645+#endif
89646 #endif
89647 seq_putc(m, '\n');
89648 }
89649diff --git a/mm/slob.c b/mm/slob.c
89650index 91bd3f2..e2f549e 100644
89651--- a/mm/slob.c
89652+++ b/mm/slob.c
89653@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
89654 /*
89655 * Return the size of a slob block.
89656 */
89657-static slobidx_t slob_units(slob_t *s)
89658+static slobidx_t slob_units(const slob_t *s)
89659 {
89660 if (s->units > 0)
89661 return s->units;
89662@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
89663 /*
89664 * Return the next free slob block pointer after this one.
89665 */
89666-static slob_t *slob_next(slob_t *s)
89667+static slob_t *slob_next(const slob_t *s)
89668 {
89669 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
89670 slobidx_t next;
89671@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
89672 /*
89673 * Returns true if s is the last free block in its page.
89674 */
89675-static int slob_last(slob_t *s)
89676+static int slob_last(const slob_t *s)
89677 {
89678 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
89679 }
89680
89681-static void *slob_new_pages(gfp_t gfp, int order, int node)
89682+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
89683 {
89684- void *page;
89685+ struct page *page;
89686
89687 #ifdef CONFIG_NUMA
89688 if (node != NUMA_NO_NODE)
89689@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
89690 if (!page)
89691 return NULL;
89692
89693- return page_address(page);
89694+ __SetPageSlab(page);
89695+ return page;
89696 }
89697
89698-static void slob_free_pages(void *b, int order)
89699+static void slob_free_pages(struct page *sp, int order)
89700 {
89701 if (current->reclaim_state)
89702 current->reclaim_state->reclaimed_slab += 1 << order;
89703- free_pages((unsigned long)b, order);
89704+ __ClearPageSlab(sp);
89705+ page_mapcount_reset(sp);
89706+ sp->private = 0;
89707+ __free_pages(sp, order);
89708 }
89709
89710 /*
89711@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
89712
89713 /* Not enough space: must allocate a new page */
89714 if (!b) {
89715- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89716- if (!b)
89717+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89718+ if (!sp)
89719 return NULL;
89720- sp = virt_to_page(b);
89721- __SetPageSlab(sp);
89722+ b = page_address(sp);
89723
89724 spin_lock_irqsave(&slob_lock, flags);
89725 sp->units = SLOB_UNITS(PAGE_SIZE);
89726 sp->freelist = b;
89727+ sp->private = 0;
89728 INIT_LIST_HEAD(&sp->list);
89729 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
89730 set_slob_page_free(sp, slob_list);
89731@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
89732 if (slob_page_free(sp))
89733 clear_slob_page_free(sp);
89734 spin_unlock_irqrestore(&slob_lock, flags);
89735- __ClearPageSlab(sp);
89736- page_mapcount_reset(sp);
89737- slob_free_pages(b, 0);
89738+ slob_free_pages(sp, 0);
89739 return;
89740 }
89741
89742+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89743+ if (pax_sanitize_slab)
89744+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
89745+#endif
89746+
89747 if (!slob_page_free(sp)) {
89748 /* This slob page is about to become partially free. Easy! */
89749 sp->units = units;
89750@@ -424,11 +431,10 @@ out:
89751 */
89752
89753 static __always_inline void *
89754-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89755+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
89756 {
89757- unsigned int *m;
89758- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89759- void *ret;
89760+ slob_t *m;
89761+ void *ret = NULL;
89762
89763 gfp &= gfp_allowed_mask;
89764
89765@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89766
89767 if (!m)
89768 return NULL;
89769- *m = size;
89770+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
89771+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
89772+ m[0].units = size;
89773+ m[1].units = align;
89774 ret = (void *)m + align;
89775
89776 trace_kmalloc_node(caller, ret,
89777 size, size + align, gfp, node);
89778 } else {
89779 unsigned int order = get_order(size);
89780+ struct page *page;
89781
89782 if (likely(order))
89783 gfp |= __GFP_COMP;
89784- ret = slob_new_pages(gfp, order, node);
89785+ page = slob_new_pages(gfp, order, node);
89786+ if (page) {
89787+ ret = page_address(page);
89788+ page->private = size;
89789+ }
89790
89791 trace_kmalloc_node(caller, ret,
89792 size, PAGE_SIZE << order, gfp, node);
89793 }
89794
89795- kmemleak_alloc(ret, size, 1, gfp);
89796+ return ret;
89797+}
89798+
89799+static __always_inline void *
89800+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89801+{
89802+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89803+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
89804+
89805+ if (!ZERO_OR_NULL_PTR(ret))
89806+ kmemleak_alloc(ret, size, 1, gfp);
89807 return ret;
89808 }
89809
89810@@ -493,34 +517,112 @@ void kfree(const void *block)
89811 return;
89812 kmemleak_free(block);
89813
89814+ VM_BUG_ON(!virt_addr_valid(block));
89815 sp = virt_to_page(block);
89816- if (PageSlab(sp)) {
89817+ VM_BUG_ON(!PageSlab(sp));
89818+ if (!sp->private) {
89819 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89820- unsigned int *m = (unsigned int *)(block - align);
89821- slob_free(m, *m + align);
89822- } else
89823+ slob_t *m = (slob_t *)(block - align);
89824+ slob_free(m, m[0].units + align);
89825+ } else {
89826+ __ClearPageSlab(sp);
89827+ page_mapcount_reset(sp);
89828+ sp->private = 0;
89829 __free_pages(sp, compound_order(sp));
89830+ }
89831 }
89832 EXPORT_SYMBOL(kfree);
89833
89834+bool is_usercopy_object(const void *ptr)
89835+{
89836+ if (!slab_is_available())
89837+ return false;
89838+
89839+ // PAX: TODO
89840+
89841+ return false;
89842+}
89843+
89844+#ifdef CONFIG_PAX_USERCOPY
89845+const char *check_heap_object(const void *ptr, unsigned long n)
89846+{
89847+ struct page *page;
89848+ const slob_t *free;
89849+ const void *base;
89850+ unsigned long flags;
89851+
89852+ if (ZERO_OR_NULL_PTR(ptr))
89853+ return "<null>";
89854+
89855+ if (!virt_addr_valid(ptr))
89856+ return NULL;
89857+
89858+ page = virt_to_head_page(ptr);
89859+ if (!PageSlab(page))
89860+ return NULL;
89861+
89862+ if (page->private) {
89863+ base = page;
89864+ if (base <= ptr && n <= page->private - (ptr - base))
89865+ return NULL;
89866+ return "<slob>";
89867+ }
89868+
89869+ /* some tricky double walking to find the chunk */
89870+ spin_lock_irqsave(&slob_lock, flags);
89871+ base = (void *)((unsigned long)ptr & PAGE_MASK);
89872+ free = page->freelist;
89873+
89874+ while (!slob_last(free) && (void *)free <= ptr) {
89875+ base = free + slob_units(free);
89876+ free = slob_next(free);
89877+ }
89878+
89879+ while (base < (void *)free) {
89880+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
89881+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
89882+ int offset;
89883+
89884+ if (ptr < base + align)
89885+ break;
89886+
89887+ offset = ptr - base - align;
89888+ if (offset >= m) {
89889+ base += size;
89890+ continue;
89891+ }
89892+
89893+ if (n > m - offset)
89894+ break;
89895+
89896+ spin_unlock_irqrestore(&slob_lock, flags);
89897+ return NULL;
89898+ }
89899+
89900+ spin_unlock_irqrestore(&slob_lock, flags);
89901+ return "<slob>";
89902+}
89903+#endif
89904+
89905 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
89906 size_t ksize(const void *block)
89907 {
89908 struct page *sp;
89909 int align;
89910- unsigned int *m;
89911+ slob_t *m;
89912
89913 BUG_ON(!block);
89914 if (unlikely(block == ZERO_SIZE_PTR))
89915 return 0;
89916
89917 sp = virt_to_page(block);
89918- if (unlikely(!PageSlab(sp)))
89919- return PAGE_SIZE << compound_order(sp);
89920+ VM_BUG_ON(!PageSlab(sp));
89921+ if (sp->private)
89922+ return sp->private;
89923
89924 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89925- m = (unsigned int *)(block - align);
89926- return SLOB_UNITS(*m) * SLOB_UNIT;
89927+ m = (slob_t *)(block - align);
89928+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
89929 }
89930 EXPORT_SYMBOL(ksize);
89931
89932@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
89933
89934 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
89935 {
89936- void *b;
89937+ void *b = NULL;
89938
89939 flags &= gfp_allowed_mask;
89940
89941 lockdep_trace_alloc(flags);
89942
89943+#ifdef CONFIG_PAX_USERCOPY_SLABS
89944+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
89945+#else
89946 if (c->size < PAGE_SIZE) {
89947 b = slob_alloc(c->size, flags, c->align, node);
89948 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
89949 SLOB_UNITS(c->size) * SLOB_UNIT,
89950 flags, node);
89951 } else {
89952- b = slob_new_pages(flags, get_order(c->size), node);
89953+ struct page *sp;
89954+
89955+ sp = slob_new_pages(flags, get_order(c->size), node);
89956+ if (sp) {
89957+ b = page_address(sp);
89958+ sp->private = c->size;
89959+ }
89960 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
89961 PAGE_SIZE << get_order(c->size),
89962 flags, node);
89963 }
89964+#endif
89965
89966 if (b && c->ctor)
89967 c->ctor(b);
89968@@ -564,10 +676,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
89969
89970 static void __kmem_cache_free(void *b, int size)
89971 {
89972- if (size < PAGE_SIZE)
89973+ struct page *sp;
89974+
89975+ sp = virt_to_page(b);
89976+ BUG_ON(!PageSlab(sp));
89977+ if (!sp->private)
89978 slob_free(b, size);
89979 else
89980- slob_free_pages(b, get_order(size));
89981+ slob_free_pages(sp, get_order(size));
89982 }
89983
89984 static void kmem_rcu_free(struct rcu_head *head)
89985@@ -580,17 +696,31 @@ static void kmem_rcu_free(struct rcu_head *head)
89986
89987 void kmem_cache_free(struct kmem_cache *c, void *b)
89988 {
89989+ int size = c->size;
89990+
89991+#ifdef CONFIG_PAX_USERCOPY_SLABS
89992+ if (size + c->align < PAGE_SIZE) {
89993+ size += c->align;
89994+ b -= c->align;
89995+ }
89996+#endif
89997+
89998 kmemleak_free_recursive(b, c->flags);
89999 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
90000 struct slob_rcu *slob_rcu;
90001- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
90002- slob_rcu->size = c->size;
90003+ slob_rcu = b + (size - sizeof(struct slob_rcu));
90004+ slob_rcu->size = size;
90005 call_rcu(&slob_rcu->head, kmem_rcu_free);
90006 } else {
90007- __kmem_cache_free(b, c->size);
90008+ __kmem_cache_free(b, size);
90009 }
90010
90011+#ifdef CONFIG_PAX_USERCOPY_SLABS
90012+ trace_kfree(_RET_IP_, b);
90013+#else
90014 trace_kmem_cache_free(_RET_IP_, b);
90015+#endif
90016+
90017 }
90018 EXPORT_SYMBOL(kmem_cache_free);
90019
90020diff --git a/mm/slub.c b/mm/slub.c
90021index e3ba1f2..bd45dac 100644
90022--- a/mm/slub.c
90023+++ b/mm/slub.c
90024@@ -207,7 +207,7 @@ struct track {
90025
90026 enum track_item { TRACK_ALLOC, TRACK_FREE };
90027
90028-#ifdef CONFIG_SYSFS
90029+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90030 static int sysfs_slab_add(struct kmem_cache *);
90031 static int sysfs_slab_alias(struct kmem_cache *, const char *);
90032 static void sysfs_slab_remove(struct kmem_cache *);
90033@@ -528,7 +528,7 @@ static void print_track(const char *s, struct track *t)
90034 if (!t->addr)
90035 return;
90036
90037- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
90038+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
90039 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
90040 #ifdef CONFIG_STACKTRACE
90041 {
90042@@ -2609,6 +2609,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
90043
90044 slab_free_hook(s, x);
90045
90046+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90047+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
90048+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
90049+ if (s->ctor)
90050+ s->ctor(x);
90051+ }
90052+#endif
90053+
90054 redo:
90055 /*
90056 * Determine the currently cpus per cpu slab.
90057@@ -2676,7 +2684,7 @@ static int slub_min_objects;
90058 * Merge control. If this is set then no merging of slab caches will occur.
90059 * (Could be removed. This was introduced to pacify the merge skeptics.)
90060 */
90061-static int slub_nomerge;
90062+static int slub_nomerge = 1;
90063
90064 /*
90065 * Calculate the order of allocation given an slab object size.
90066@@ -2953,6 +2961,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
90067 s->inuse = size;
90068
90069 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
90070+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90071+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
90072+#endif
90073 s->ctor)) {
90074 /*
90075 * Relocate free pointer after the object if it is not
90076@@ -3298,6 +3309,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
90077 EXPORT_SYMBOL(__kmalloc_node);
90078 #endif
90079
90080+bool is_usercopy_object(const void *ptr)
90081+{
90082+ struct page *page;
90083+ struct kmem_cache *s;
90084+
90085+ if (ZERO_OR_NULL_PTR(ptr))
90086+ return false;
90087+
90088+ if (!slab_is_available())
90089+ return false;
90090+
90091+ if (!virt_addr_valid(ptr))
90092+ return false;
90093+
90094+ page = virt_to_head_page(ptr);
90095+
90096+ if (!PageSlab(page))
90097+ return false;
90098+
90099+ s = page->slab_cache;
90100+ return s->flags & SLAB_USERCOPY;
90101+}
90102+
90103+#ifdef CONFIG_PAX_USERCOPY
90104+const char *check_heap_object(const void *ptr, unsigned long n)
90105+{
90106+ struct page *page;
90107+ struct kmem_cache *s;
90108+ unsigned long offset;
90109+
90110+ if (ZERO_OR_NULL_PTR(ptr))
90111+ return "<null>";
90112+
90113+ if (!virt_addr_valid(ptr))
90114+ return NULL;
90115+
90116+ page = virt_to_head_page(ptr);
90117+
90118+ if (!PageSlab(page))
90119+ return NULL;
90120+
90121+ s = page->slab_cache;
90122+ if (!(s->flags & SLAB_USERCOPY))
90123+ return s->name;
90124+
90125+ offset = (ptr - page_address(page)) % s->size;
90126+ if (offset <= s->object_size && n <= s->object_size - offset)
90127+ return NULL;
90128+
90129+ return s->name;
90130+}
90131+#endif
90132+
90133 size_t ksize(const void *object)
90134 {
90135 struct page *page;
90136@@ -3362,6 +3426,7 @@ void kfree(const void *x)
90137 if (unlikely(ZERO_OR_NULL_PTR(x)))
90138 return;
90139
90140+ VM_BUG_ON(!virt_addr_valid(x));
90141 page = virt_to_head_page(x);
90142 if (unlikely(!PageSlab(page))) {
90143 BUG_ON(!PageCompound(page));
90144@@ -3667,7 +3732,7 @@ static int slab_unmergeable(struct kmem_cache *s)
90145 /*
90146 * We may have set a slab to be unmergeable during bootstrap.
90147 */
90148- if (s->refcount < 0)
90149+ if (atomic_read(&s->refcount) < 0)
90150 return 1;
90151
90152 return 0;
90153@@ -3725,7 +3790,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90154
90155 s = find_mergeable(memcg, size, align, flags, name, ctor);
90156 if (s) {
90157- s->refcount++;
90158+ atomic_inc(&s->refcount);
90159 /*
90160 * Adjust the object sizes so that we clear
90161 * the complete object on kzalloc.
90162@@ -3734,7 +3799,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90163 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
90164
90165 if (sysfs_slab_alias(s, name)) {
90166- s->refcount--;
90167+ atomic_dec(&s->refcount);
90168 s = NULL;
90169 }
90170 }
90171@@ -3854,7 +3919,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
90172 }
90173 #endif
90174
90175-#ifdef CONFIG_SYSFS
90176+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90177 static int count_inuse(struct page *page)
90178 {
90179 return page->inuse;
90180@@ -4241,12 +4306,12 @@ static void resiliency_test(void)
90181 validate_slab_cache(kmalloc_caches[9]);
90182 }
90183 #else
90184-#ifdef CONFIG_SYSFS
90185+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90186 static void resiliency_test(void) {};
90187 #endif
90188 #endif
90189
90190-#ifdef CONFIG_SYSFS
90191+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90192 enum slab_stat_type {
90193 SL_ALL, /* All slabs */
90194 SL_PARTIAL, /* Only partially allocated slabs */
90195@@ -4490,7 +4555,7 @@ SLAB_ATTR_RO(ctor);
90196
90197 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
90198 {
90199- return sprintf(buf, "%d\n", s->refcount - 1);
90200+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
90201 }
90202 SLAB_ATTR_RO(aliases);
90203
90204@@ -4578,6 +4643,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
90205 SLAB_ATTR_RO(cache_dma);
90206 #endif
90207
90208+#ifdef CONFIG_PAX_USERCOPY_SLABS
90209+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
90210+{
90211+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
90212+}
90213+SLAB_ATTR_RO(usercopy);
90214+#endif
90215+
90216 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
90217 {
90218 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
90219@@ -4912,6 +4985,9 @@ static struct attribute *slab_attrs[] = {
90220 #ifdef CONFIG_ZONE_DMA
90221 &cache_dma_attr.attr,
90222 #endif
90223+#ifdef CONFIG_PAX_USERCOPY_SLABS
90224+ &usercopy_attr.attr,
90225+#endif
90226 #ifdef CONFIG_NUMA
90227 &remote_node_defrag_ratio_attr.attr,
90228 #endif
90229@@ -5143,6 +5219,7 @@ static char *create_unique_id(struct kmem_cache *s)
90230 return name;
90231 }
90232
90233+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90234 static int sysfs_slab_add(struct kmem_cache *s)
90235 {
90236 int err;
90237@@ -5166,7 +5243,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
90238 }
90239
90240 s->kobj.kset = slab_kset;
90241- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
90242+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
90243 if (err) {
90244 kobject_put(&s->kobj);
90245 return err;
90246@@ -5200,6 +5277,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
90247 kobject_del(&s->kobj);
90248 kobject_put(&s->kobj);
90249 }
90250+#endif
90251
90252 /*
90253 * Need to buffer aliases during bootup until sysfs becomes
90254@@ -5213,6 +5291,7 @@ struct saved_alias {
90255
90256 static struct saved_alias *alias_list;
90257
90258+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90259 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
90260 {
90261 struct saved_alias *al;
90262@@ -5235,6 +5314,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
90263 alias_list = al;
90264 return 0;
90265 }
90266+#endif
90267
90268 static int __init slab_sysfs_init(void)
90269 {
90270diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
90271index 27eeab3..7c3f7f2 100644
90272--- a/mm/sparse-vmemmap.c
90273+++ b/mm/sparse-vmemmap.c
90274@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
90275 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
90276 if (!p)
90277 return NULL;
90278- pud_populate(&init_mm, pud, p);
90279+ pud_populate_kernel(&init_mm, pud, p);
90280 }
90281 return pud;
90282 }
90283@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
90284 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
90285 if (!p)
90286 return NULL;
90287- pgd_populate(&init_mm, pgd, p);
90288+ pgd_populate_kernel(&init_mm, pgd, p);
90289 }
90290 return pgd;
90291 }
90292diff --git a/mm/sparse.c b/mm/sparse.c
90293index 308d503..3dbbd04 100644
90294--- a/mm/sparse.c
90295+++ b/mm/sparse.c
90296@@ -764,7 +764,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
90297
90298 for (i = 0; i < PAGES_PER_SECTION; i++) {
90299 if (PageHWPoison(&memmap[i])) {
90300- atomic_long_sub(1, &num_poisoned_pages);
90301+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
90302 ClearPageHWPoison(&memmap[i]);
90303 }
90304 }
90305diff --git a/mm/swap.c b/mm/swap.c
90306index 62b78a6..0bcf28f 100644
90307--- a/mm/swap.c
90308+++ b/mm/swap.c
90309@@ -31,6 +31,7 @@
90310 #include <linux/memcontrol.h>
90311 #include <linux/gfp.h>
90312 #include <linux/uio.h>
90313+#include <linux/hugetlb.h>
90314
90315 #include "internal.h"
90316
90317@@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
90318
90319 __page_cache_release(page);
90320 dtor = get_compound_page_dtor(page);
90321+ if (!PageHuge(page))
90322+ BUG_ON(dtor != free_compound_page);
90323 (*dtor)(page);
90324 }
90325
90326diff --git a/mm/swapfile.c b/mm/swapfile.c
90327index 6cf2e60..d204b3e 100644
90328--- a/mm/swapfile.c
90329+++ b/mm/swapfile.c
90330@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
90331
90332 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
90333 /* Activity counter to indicate that a swapon or swapoff has occurred */
90334-static atomic_t proc_poll_event = ATOMIC_INIT(0);
90335+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
90336
90337 static inline unsigned char swap_count(unsigned char ent)
90338 {
90339@@ -1699,7 +1699,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
90340 }
90341 filp_close(swap_file, NULL);
90342 err = 0;
90343- atomic_inc(&proc_poll_event);
90344+ atomic_inc_unchecked(&proc_poll_event);
90345 wake_up_interruptible(&proc_poll_wait);
90346
90347 out_dput:
90348@@ -1716,8 +1716,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
90349
90350 poll_wait(file, &proc_poll_wait, wait);
90351
90352- if (seq->poll_event != atomic_read(&proc_poll_event)) {
90353- seq->poll_event = atomic_read(&proc_poll_event);
90354+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
90355+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
90356 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
90357 }
90358
90359@@ -1815,7 +1815,7 @@ static int swaps_open(struct inode *inode, struct file *file)
90360 return ret;
90361
90362 seq = file->private_data;
90363- seq->poll_event = atomic_read(&proc_poll_event);
90364+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
90365 return 0;
90366 }
90367
90368@@ -2203,7 +2203,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
90369 (frontswap_map) ? "FS" : "");
90370
90371 mutex_unlock(&swapon_mutex);
90372- atomic_inc(&proc_poll_event);
90373+ atomic_inc_unchecked(&proc_poll_event);
90374 wake_up_interruptible(&proc_poll_wait);
90375
90376 if (S_ISREG(inode->i_mode))
90377diff --git a/mm/util.c b/mm/util.c
90378index 7441c41..c3de793 100644
90379--- a/mm/util.c
90380+++ b/mm/util.c
90381@@ -294,6 +294,12 @@ done:
90382 void arch_pick_mmap_layout(struct mm_struct *mm)
90383 {
90384 mm->mmap_base = TASK_UNMAPPED_BASE;
90385+
90386+#ifdef CONFIG_PAX_RANDMMAP
90387+ if (mm->pax_flags & MF_PAX_RANDMMAP)
90388+ mm->mmap_base += mm->delta_mmap;
90389+#endif
90390+
90391 mm->get_unmapped_area = arch_get_unmapped_area;
90392 }
90393 #endif
90394diff --git a/mm/vmalloc.c b/mm/vmalloc.c
90395index 13a5495..6707d97 100644
90396--- a/mm/vmalloc.c
90397+++ b/mm/vmalloc.c
90398@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
90399
90400 pte = pte_offset_kernel(pmd, addr);
90401 do {
90402- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
90403- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90404+
90405+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90406+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
90407+ BUG_ON(!pte_exec(*pte));
90408+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
90409+ continue;
90410+ }
90411+#endif
90412+
90413+ {
90414+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
90415+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90416+ }
90417 } while (pte++, addr += PAGE_SIZE, addr != end);
90418 }
90419
90420@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
90421 pte = pte_alloc_kernel(pmd, addr);
90422 if (!pte)
90423 return -ENOMEM;
90424+
90425+ pax_open_kernel();
90426 do {
90427 struct page *page = pages[*nr];
90428
90429- if (WARN_ON(!pte_none(*pte)))
90430+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90431+ if (pgprot_val(prot) & _PAGE_NX)
90432+#endif
90433+
90434+ if (!pte_none(*pte)) {
90435+ pax_close_kernel();
90436+ WARN_ON(1);
90437 return -EBUSY;
90438- if (WARN_ON(!page))
90439+ }
90440+ if (!page) {
90441+ pax_close_kernel();
90442+ WARN_ON(1);
90443 return -ENOMEM;
90444+ }
90445 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
90446 (*nr)++;
90447 } while (pte++, addr += PAGE_SIZE, addr != end);
90448+ pax_close_kernel();
90449 return 0;
90450 }
90451
90452@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
90453 pmd_t *pmd;
90454 unsigned long next;
90455
90456- pmd = pmd_alloc(&init_mm, pud, addr);
90457+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
90458 if (!pmd)
90459 return -ENOMEM;
90460 do {
90461@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
90462 pud_t *pud;
90463 unsigned long next;
90464
90465- pud = pud_alloc(&init_mm, pgd, addr);
90466+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
90467 if (!pud)
90468 return -ENOMEM;
90469 do {
90470@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
90471 if (addr >= MODULES_VADDR && addr < MODULES_END)
90472 return 1;
90473 #endif
90474+
90475+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90476+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
90477+ return 1;
90478+#endif
90479+
90480 return is_vmalloc_addr(x);
90481 }
90482
90483@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
90484
90485 if (!pgd_none(*pgd)) {
90486 pud_t *pud = pud_offset(pgd, addr);
90487+#ifdef CONFIG_X86
90488+ if (!pud_large(*pud))
90489+#endif
90490 if (!pud_none(*pud)) {
90491 pmd_t *pmd = pmd_offset(pud, addr);
90492+#ifdef CONFIG_X86
90493+ if (!pmd_large(*pmd))
90494+#endif
90495 if (!pmd_none(*pmd)) {
90496 pte_t *ptep, pte;
90497
90498@@ -339,7 +375,7 @@ static void purge_vmap_area_lazy(void);
90499 * Allocate a region of KVA of the specified size and alignment, within the
90500 * vstart and vend.
90501 */
90502-static struct vmap_area *alloc_vmap_area(unsigned long size,
90503+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
90504 unsigned long align,
90505 unsigned long vstart, unsigned long vend,
90506 int node, gfp_t gfp_mask)
90507@@ -1308,6 +1344,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
90508 struct vm_struct *area;
90509
90510 BUG_ON(in_interrupt());
90511+
90512+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90513+ if (flags & VM_KERNEXEC) {
90514+ if (start != VMALLOC_START || end != VMALLOC_END)
90515+ return NULL;
90516+ start = (unsigned long)MODULES_EXEC_VADDR;
90517+ end = (unsigned long)MODULES_EXEC_END;
90518+ }
90519+#endif
90520+
90521 if (flags & VM_IOREMAP)
90522 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
90523
90524@@ -1533,6 +1579,11 @@ void *vmap(struct page **pages, unsigned int count,
90525 if (count > totalram_pages)
90526 return NULL;
90527
90528+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90529+ if (!(pgprot_val(prot) & _PAGE_NX))
90530+ flags |= VM_KERNEXEC;
90531+#endif
90532+
90533 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
90534 __builtin_return_address(0));
90535 if (!area)
90536@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
90537 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
90538 goto fail;
90539
90540+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90541+ if (!(pgprot_val(prot) & _PAGE_NX))
90542+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
90543+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
90544+ else
90545+#endif
90546+
90547 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
90548 start, end, node, gfp_mask, caller);
90549 if (!area)
90550@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
90551 * For tight control over page level allocator and protection flags
90552 * use __vmalloc() instead.
90553 */
90554-
90555 void *vmalloc_exec(unsigned long size)
90556 {
90557- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
90558+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
90559 NUMA_NO_NODE, __builtin_return_address(0));
90560 }
90561
90562@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
90563 {
90564 struct vm_struct *area;
90565
90566+ BUG_ON(vma->vm_mirror);
90567+
90568 size = PAGE_ALIGN(size);
90569
90570 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
90571@@ -2605,7 +2664,11 @@ static int s_show(struct seq_file *m, void *p)
90572 v->addr, v->addr + v->size, v->size);
90573
90574 if (v->caller)
90575+#ifdef CONFIG_GRKERNSEC_HIDESYM
90576+ seq_printf(m, " %pK", v->caller);
90577+#else
90578 seq_printf(m, " %pS", v->caller);
90579+#endif
90580
90581 if (v->nr_pages)
90582 seq_printf(m, " pages=%d", v->nr_pages);
90583diff --git a/mm/vmstat.c b/mm/vmstat.c
90584index 20c2ef4..15e7ab7 100644
90585--- a/mm/vmstat.c
90586+++ b/mm/vmstat.c
90587@@ -76,7 +76,7 @@ void vm_events_fold_cpu(int cpu)
90588 *
90589 * vm_stat contains the global counters
90590 */
90591-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90592+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90593 EXPORT_SYMBOL(vm_stat);
90594
90595 #ifdef CONFIG_SMP
90596@@ -452,7 +452,7 @@ void refresh_cpu_vm_stats(int cpu)
90597 v = p->vm_stat_diff[i];
90598 p->vm_stat_diff[i] = 0;
90599 local_irq_restore(flags);
90600- atomic_long_add(v, &zone->vm_stat[i]);
90601+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90602 global_diff[i] += v;
90603 #ifdef CONFIG_NUMA
90604 /* 3 seconds idle till flush */
90605@@ -490,7 +490,7 @@ void refresh_cpu_vm_stats(int cpu)
90606
90607 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
90608 if (global_diff[i])
90609- atomic_long_add(global_diff[i], &vm_stat[i]);
90610+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
90611 }
90612
90613 /*
90614@@ -505,8 +505,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
90615 if (pset->vm_stat_diff[i]) {
90616 int v = pset->vm_stat_diff[i];
90617 pset->vm_stat_diff[i] = 0;
90618- atomic_long_add(v, &zone->vm_stat[i]);
90619- atomic_long_add(v, &vm_stat[i]);
90620+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90621+ atomic_long_add_unchecked(v, &vm_stat[i]);
90622 }
90623 }
90624 #endif
90625@@ -1241,10 +1241,20 @@ static int __init setup_vmstat(void)
90626 start_cpu_timer(cpu);
90627 #endif
90628 #ifdef CONFIG_PROC_FS
90629- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
90630- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
90631- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
90632- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
90633+ {
90634+ mode_t gr_mode = S_IRUGO;
90635+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90636+ gr_mode = S_IRUSR;
90637+#endif
90638+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
90639+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
90640+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
90641+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
90642+#else
90643+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
90644+#endif
90645+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
90646+ }
90647 #endif
90648 return 0;
90649 }
90650diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
90651index 2fb2d88..8c06e40 100644
90652--- a/net/8021q/vlan.c
90653+++ b/net/8021q/vlan.c
90654@@ -469,7 +469,7 @@ out:
90655 return NOTIFY_DONE;
90656 }
90657
90658-static struct notifier_block vlan_notifier_block __read_mostly = {
90659+static struct notifier_block vlan_notifier_block = {
90660 .notifier_call = vlan_device_event,
90661 };
90662
90663@@ -544,8 +544,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
90664 err = -EPERM;
90665 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
90666 break;
90667- if ((args.u.name_type >= 0) &&
90668- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
90669+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
90670 struct vlan_net *vn;
90671
90672 vn = net_generic(net, vlan_net_id);
90673diff --git a/net/9p/mod.c b/net/9p/mod.c
90674index 6ab36ae..6f1841b 100644
90675--- a/net/9p/mod.c
90676+++ b/net/9p/mod.c
90677@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
90678 void v9fs_register_trans(struct p9_trans_module *m)
90679 {
90680 spin_lock(&v9fs_trans_lock);
90681- list_add_tail(&m->list, &v9fs_trans_list);
90682+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
90683 spin_unlock(&v9fs_trans_lock);
90684 }
90685 EXPORT_SYMBOL(v9fs_register_trans);
90686@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
90687 void v9fs_unregister_trans(struct p9_trans_module *m)
90688 {
90689 spin_lock(&v9fs_trans_lock);
90690- list_del_init(&m->list);
90691+ pax_list_del_init((struct list_head *)&m->list);
90692 spin_unlock(&v9fs_trans_lock);
90693 }
90694 EXPORT_SYMBOL(v9fs_unregister_trans);
90695diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
90696index 3ffda1b..fceac96 100644
90697--- a/net/9p/trans_fd.c
90698+++ b/net/9p/trans_fd.c
90699@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
90700 oldfs = get_fs();
90701 set_fs(get_ds());
90702 /* The cast to a user pointer is valid due to the set_fs() */
90703- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
90704+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
90705 set_fs(oldfs);
90706
90707 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
90708diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
90709index 876fbe8..8bbea9f 100644
90710--- a/net/atm/atm_misc.c
90711+++ b/net/atm/atm_misc.c
90712@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
90713 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
90714 return 1;
90715 atm_return(vcc, truesize);
90716- atomic_inc(&vcc->stats->rx_drop);
90717+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90718 return 0;
90719 }
90720 EXPORT_SYMBOL(atm_charge);
90721@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
90722 }
90723 }
90724 atm_return(vcc, guess);
90725- atomic_inc(&vcc->stats->rx_drop);
90726+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90727 return NULL;
90728 }
90729 EXPORT_SYMBOL(atm_alloc_charge);
90730@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
90731
90732 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90733 {
90734-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90735+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90736 __SONET_ITEMS
90737 #undef __HANDLE_ITEM
90738 }
90739@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
90740
90741 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90742 {
90743-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90744+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
90745 __SONET_ITEMS
90746 #undef __HANDLE_ITEM
90747 }
90748diff --git a/net/atm/lec.h b/net/atm/lec.h
90749index 4149db1..f2ab682 100644
90750--- a/net/atm/lec.h
90751+++ b/net/atm/lec.h
90752@@ -48,7 +48,7 @@ struct lane2_ops {
90753 const u8 *tlvs, u32 sizeoftlvs);
90754 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
90755 const u8 *tlvs, u32 sizeoftlvs);
90756-};
90757+} __no_const;
90758
90759 /*
90760 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
90761diff --git a/net/atm/proc.c b/net/atm/proc.c
90762index bbb6461..cf04016 100644
90763--- a/net/atm/proc.c
90764+++ b/net/atm/proc.c
90765@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
90766 const struct k_atm_aal_stats *stats)
90767 {
90768 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
90769- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
90770- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
90771- atomic_read(&stats->rx_drop));
90772+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
90773+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
90774+ atomic_read_unchecked(&stats->rx_drop));
90775 }
90776
90777 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
90778diff --git a/net/atm/resources.c b/net/atm/resources.c
90779index 0447d5d..3cf4728 100644
90780--- a/net/atm/resources.c
90781+++ b/net/atm/resources.c
90782@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
90783 static void copy_aal_stats(struct k_atm_aal_stats *from,
90784 struct atm_aal_stats *to)
90785 {
90786-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90787+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90788 __AAL_STAT_ITEMS
90789 #undef __HANDLE_ITEM
90790 }
90791@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
90792 static void subtract_aal_stats(struct k_atm_aal_stats *from,
90793 struct atm_aal_stats *to)
90794 {
90795-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90796+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
90797 __AAL_STAT_ITEMS
90798 #undef __HANDLE_ITEM
90799 }
90800diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
90801index 919a5ce..cc6b444 100644
90802--- a/net/ax25/sysctl_net_ax25.c
90803+++ b/net/ax25/sysctl_net_ax25.c
90804@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
90805 {
90806 char path[sizeof("net/ax25/") + IFNAMSIZ];
90807 int k;
90808- struct ctl_table *table;
90809+ ctl_table_no_const *table;
90810
90811 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
90812 if (!table)
90813diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
90814index 62da527..aa27535 100644
90815--- a/net/batman-adv/bat_iv_ogm.c
90816+++ b/net/batman-adv/bat_iv_ogm.c
90817@@ -120,7 +120,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
90818
90819 /* randomize initial seqno to avoid collision */
90820 get_random_bytes(&random_seqno, sizeof(random_seqno));
90821- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90822+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90823
90824 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
90825 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
90826@@ -701,9 +701,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
90827 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
90828
90829 /* change sequence number to network order */
90830- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
90831+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
90832 batadv_ogm_packet->seqno = htonl(seqno);
90833- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
90834+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
90835
90836 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
90837 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
90838@@ -1109,7 +1109,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
90839 return;
90840
90841 /* could be changed by schedule_own_packet() */
90842- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
90843+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
90844
90845 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
90846 has_directlink_flag = 1;
90847diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
90848index c478e6b..469fd2f 100644
90849--- a/net/batman-adv/hard-interface.c
90850+++ b/net/batman-adv/hard-interface.c
90851@@ -453,7 +453,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
90852 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
90853 dev_add_pack(&hard_iface->batman_adv_ptype);
90854
90855- atomic_set(&hard_iface->frag_seqno, 1);
90856+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
90857 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
90858 hard_iface->net_dev->name);
90859
90860diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
90861index 0f04e1c..9c0ac11 100644
90862--- a/net/batman-adv/soft-interface.c
90863+++ b/net/batman-adv/soft-interface.c
90864@@ -260,7 +260,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
90865 primary_if->net_dev->dev_addr, ETH_ALEN);
90866
90867 /* set broadcast sequence number */
90868- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
90869+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
90870 bcast_packet->seqno = htonl(seqno);
90871
90872 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
90873@@ -479,7 +479,7 @@ static int batadv_softif_init_late(struct net_device *dev)
90874 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
90875
90876 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
90877- atomic_set(&bat_priv->bcast_seqno, 1);
90878+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
90879 atomic_set(&bat_priv->tt.vn, 0);
90880 atomic_set(&bat_priv->tt.local_changes, 0);
90881 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
90882diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
90883index b2c94e1..3d47e07 100644
90884--- a/net/batman-adv/types.h
90885+++ b/net/batman-adv/types.h
90886@@ -51,7 +51,7 @@
90887 struct batadv_hard_iface_bat_iv {
90888 unsigned char *ogm_buff;
90889 int ogm_buff_len;
90890- atomic_t ogm_seqno;
90891+ atomic_unchecked_t ogm_seqno;
90892 };
90893
90894 /**
90895@@ -76,7 +76,7 @@ struct batadv_hard_iface {
90896 int16_t if_num;
90897 char if_status;
90898 struct net_device *net_dev;
90899- atomic_t frag_seqno;
90900+ atomic_unchecked_t frag_seqno;
90901 uint8_t num_bcasts;
90902 struct kobject *hardif_obj;
90903 atomic_t refcount;
90904@@ -560,7 +560,7 @@ struct batadv_priv {
90905 #ifdef CONFIG_BATMAN_ADV_DEBUG
90906 atomic_t log_level;
90907 #endif
90908- atomic_t bcast_seqno;
90909+ atomic_unchecked_t bcast_seqno;
90910 atomic_t bcast_queue_left;
90911 atomic_t batman_queue_left;
90912 char num_ifaces;
90913diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
90914index 857e1b8..5ad07b2 100644
90915--- a/net/batman-adv/unicast.c
90916+++ b/net/batman-adv/unicast.c
90917@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
90918 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
90919 frag2->flags = large_tail;
90920
90921- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
90922+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
90923 frag1->seqno = htons(seqno - 1);
90924 frag2->seqno = htons(seqno);
90925
90926diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
90927index 9bd7d95..6c4884f 100644
90928--- a/net/bluetooth/hci_sock.c
90929+++ b/net/bluetooth/hci_sock.c
90930@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
90931 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
90932 }
90933
90934- len = min_t(unsigned int, len, sizeof(uf));
90935+ len = min((size_t)len, sizeof(uf));
90936 if (copy_from_user(&uf, optval, len)) {
90937 err = -EFAULT;
90938 break;
90939diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
90940index 8c3499b..2661c6a 100644
90941--- a/net/bluetooth/l2cap_core.c
90942+++ b/net/bluetooth/l2cap_core.c
90943@@ -3510,8 +3510,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
90944 break;
90945
90946 case L2CAP_CONF_RFC:
90947- if (olen == sizeof(rfc))
90948- memcpy(&rfc, (void *)val, olen);
90949+ if (olen != sizeof(rfc))
90950+ break;
90951+
90952+ memcpy(&rfc, (void *)val, olen);
90953
90954 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
90955 rfc.mode != chan->mode)
90956diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
90957index 0098af8..fb5a31f 100644
90958--- a/net/bluetooth/l2cap_sock.c
90959+++ b/net/bluetooth/l2cap_sock.c
90960@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
90961 struct sock *sk = sock->sk;
90962 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
90963 struct l2cap_options opts;
90964- int len, err = 0;
90965+ int err = 0;
90966+ size_t len = optlen;
90967 u32 opt;
90968
90969 BT_DBG("sk %p", sk);
90970@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
90971 opts.max_tx = chan->max_tx;
90972 opts.txwin_size = chan->tx_win;
90973
90974- len = min_t(unsigned int, sizeof(opts), optlen);
90975+ len = min(sizeof(opts), len);
90976 if (copy_from_user((char *) &opts, optval, len)) {
90977 err = -EFAULT;
90978 break;
90979@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90980 struct bt_security sec;
90981 struct bt_power pwr;
90982 struct l2cap_conn *conn;
90983- int len, err = 0;
90984+ int err = 0;
90985+ size_t len = optlen;
90986 u32 opt;
90987
90988 BT_DBG("sk %p", sk);
90989@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90990
90991 sec.level = BT_SECURITY_LOW;
90992
90993- len = min_t(unsigned int, sizeof(sec), optlen);
90994+ len = min(sizeof(sec), len);
90995 if (copy_from_user((char *) &sec, optval, len)) {
90996 err = -EFAULT;
90997 break;
90998@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90999
91000 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
91001
91002- len = min_t(unsigned int, sizeof(pwr), optlen);
91003+ len = min(sizeof(pwr), len);
91004 if (copy_from_user((char *) &pwr, optval, len)) {
91005 err = -EFAULT;
91006 break;
91007diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
91008index 30b3721..c1bd0a0 100644
91009--- a/net/bluetooth/rfcomm/sock.c
91010+++ b/net/bluetooth/rfcomm/sock.c
91011@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
91012 struct sock *sk = sock->sk;
91013 struct bt_security sec;
91014 int err = 0;
91015- size_t len;
91016+ size_t len = optlen;
91017 u32 opt;
91018
91019 BT_DBG("sk %p", sk);
91020@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
91021
91022 sec.level = BT_SECURITY_LOW;
91023
91024- len = min_t(unsigned int, sizeof(sec), optlen);
91025+ len = min(sizeof(sec), len);
91026 if (copy_from_user((char *) &sec, optval, len)) {
91027 err = -EFAULT;
91028 break;
91029diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
91030index b6e44ad..5b0d514 100644
91031--- a/net/bluetooth/rfcomm/tty.c
91032+++ b/net/bluetooth/rfcomm/tty.c
91033@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
91034 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
91035
91036 spin_lock_irqsave(&dev->port.lock, flags);
91037- if (dev->port.count > 0) {
91038+ if (atomic_read(&dev->port.count) > 0) {
91039 spin_unlock_irqrestore(&dev->port.lock, flags);
91040 return;
91041 }
91042@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
91043 return -ENODEV;
91044
91045 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
91046- dev->channel, dev->port.count);
91047+ dev->channel, atomic_read(&dev->port.count));
91048
91049 spin_lock_irqsave(&dev->port.lock, flags);
91050- if (++dev->port.count > 1) {
91051+ if (atomic_inc_return(&dev->port.count) > 1) {
91052 spin_unlock_irqrestore(&dev->port.lock, flags);
91053 return 0;
91054 }
91055@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
91056 return;
91057
91058 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
91059- dev->port.count);
91060+ atomic_read(&dev->port.count));
91061
91062 spin_lock_irqsave(&dev->port.lock, flags);
91063- if (!--dev->port.count) {
91064+ if (!atomic_dec_return(&dev->port.count)) {
91065 spin_unlock_irqrestore(&dev->port.lock, flags);
91066 if (dev->tty_dev->parent)
91067 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
91068diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
91069index ac78024..161a80c 100644
91070--- a/net/bridge/netfilter/ebtables.c
91071+++ b/net/bridge/netfilter/ebtables.c
91072@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
91073 tmp.valid_hooks = t->table->valid_hooks;
91074 }
91075 mutex_unlock(&ebt_mutex);
91076- if (copy_to_user(user, &tmp, *len) != 0){
91077+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
91078 BUGPRINT("c2u Didn't work\n");
91079 ret = -EFAULT;
91080 break;
91081@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
91082 goto out;
91083 tmp.valid_hooks = t->valid_hooks;
91084
91085- if (copy_to_user(user, &tmp, *len) != 0) {
91086+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
91087 ret = -EFAULT;
91088 break;
91089 }
91090@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
91091 tmp.entries_size = t->table->entries_size;
91092 tmp.valid_hooks = t->table->valid_hooks;
91093
91094- if (copy_to_user(user, &tmp, *len) != 0) {
91095+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
91096 ret = -EFAULT;
91097 break;
91098 }
91099diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
91100index 2bd4b58..0dc30a1 100644
91101--- a/net/caif/cfctrl.c
91102+++ b/net/caif/cfctrl.c
91103@@ -10,6 +10,7 @@
91104 #include <linux/spinlock.h>
91105 #include <linux/slab.h>
91106 #include <linux/pkt_sched.h>
91107+#include <linux/sched.h>
91108 #include <net/caif/caif_layer.h>
91109 #include <net/caif/cfpkt.h>
91110 #include <net/caif/cfctrl.h>
91111@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
91112 memset(&dev_info, 0, sizeof(dev_info));
91113 dev_info.id = 0xff;
91114 cfsrvl_init(&this->serv, 0, &dev_info, false);
91115- atomic_set(&this->req_seq_no, 1);
91116- atomic_set(&this->rsp_seq_no, 1);
91117+ atomic_set_unchecked(&this->req_seq_no, 1);
91118+ atomic_set_unchecked(&this->rsp_seq_no, 1);
91119 this->serv.layer.receive = cfctrl_recv;
91120 sprintf(this->serv.layer.name, "ctrl");
91121 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
91122@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
91123 struct cfctrl_request_info *req)
91124 {
91125 spin_lock_bh(&ctrl->info_list_lock);
91126- atomic_inc(&ctrl->req_seq_no);
91127- req->sequence_no = atomic_read(&ctrl->req_seq_no);
91128+ atomic_inc_unchecked(&ctrl->req_seq_no);
91129+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
91130 list_add_tail(&req->list, &ctrl->list);
91131 spin_unlock_bh(&ctrl->info_list_lock);
91132 }
91133@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
91134 if (p != first)
91135 pr_warn("Requests are not received in order\n");
91136
91137- atomic_set(&ctrl->rsp_seq_no,
91138+ atomic_set_unchecked(&ctrl->rsp_seq_no,
91139 p->sequence_no);
91140 list_del(&p->list);
91141 goto out;
91142diff --git a/net/can/af_can.c b/net/can/af_can.c
91143index 3ab8dd2..b9aef13 100644
91144--- a/net/can/af_can.c
91145+++ b/net/can/af_can.c
91146@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
91147 };
91148
91149 /* notifier block for netdevice event */
91150-static struct notifier_block can_netdev_notifier __read_mostly = {
91151+static struct notifier_block can_netdev_notifier = {
91152 .notifier_call = can_notifier,
91153 };
91154
91155diff --git a/net/can/gw.c b/net/can/gw.c
91156index 2f291f9..98c986a 100644
91157--- a/net/can/gw.c
91158+++ b/net/can/gw.c
91159@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
91160 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
91161
91162 static HLIST_HEAD(cgw_list);
91163-static struct notifier_block notifier;
91164
91165 static struct kmem_cache *cgw_cache __read_mostly;
91166
91167@@ -927,6 +926,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
91168 return err;
91169 }
91170
91171+static struct notifier_block notifier = {
91172+ .notifier_call = cgw_notifier
91173+};
91174+
91175 static __init int cgw_module_init(void)
91176 {
91177 /* sanitize given module parameter */
91178@@ -942,7 +945,6 @@ static __init int cgw_module_init(void)
91179 return -ENOMEM;
91180
91181 /* set notifier */
91182- notifier.notifier_call = cgw_notifier;
91183 register_netdevice_notifier(&notifier);
91184
91185 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
91186diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
91187index eb0a46a..5f3bae8 100644
91188--- a/net/ceph/messenger.c
91189+++ b/net/ceph/messenger.c
91190@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
91191 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
91192
91193 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
91194-static atomic_t addr_str_seq = ATOMIC_INIT(0);
91195+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
91196
91197 static struct page *zero_page; /* used in certain error cases */
91198
91199@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
91200 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
91201 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
91202
91203- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
91204+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
91205 s = addr_str[i];
91206
91207 switch (ss->ss_family) {
91208diff --git a/net/compat.c b/net/compat.c
91209index f0a1ba6..0541331 100644
91210--- a/net/compat.c
91211+++ b/net/compat.c
91212@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
91213 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
91214 __get_user(kmsg->msg_flags, &umsg->msg_flags))
91215 return -EFAULT;
91216- kmsg->msg_name = compat_ptr(tmp1);
91217- kmsg->msg_iov = compat_ptr(tmp2);
91218- kmsg->msg_control = compat_ptr(tmp3);
91219+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
91220+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
91221+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
91222 return 0;
91223 }
91224
91225@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91226
91227 if (kern_msg->msg_namelen) {
91228 if (mode == VERIFY_READ) {
91229- int err = move_addr_to_kernel(kern_msg->msg_name,
91230+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
91231 kern_msg->msg_namelen,
91232 kern_address);
91233 if (err < 0)
91234@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91235 kern_msg->msg_name = NULL;
91236
91237 tot_len = iov_from_user_compat_to_kern(kern_iov,
91238- (struct compat_iovec __user *)kern_msg->msg_iov,
91239+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
91240 kern_msg->msg_iovlen);
91241 if (tot_len >= 0)
91242 kern_msg->msg_iov = kern_iov;
91243@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91244
91245 #define CMSG_COMPAT_FIRSTHDR(msg) \
91246 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
91247- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
91248+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
91249 (struct compat_cmsghdr __user *)NULL)
91250
91251 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
91252 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
91253 (ucmlen) <= (unsigned long) \
91254 ((mhdr)->msg_controllen - \
91255- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
91256+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
91257
91258 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
91259 struct compat_cmsghdr __user *cmsg, int cmsg_len)
91260 {
91261 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
91262- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
91263+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
91264 msg->msg_controllen)
91265 return NULL;
91266 return (struct compat_cmsghdr __user *)ptr;
91267@@ -219,7 +219,7 @@ Efault:
91268
91269 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
91270 {
91271- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
91272+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
91273 struct compat_cmsghdr cmhdr;
91274 struct compat_timeval ctv;
91275 struct compat_timespec cts[3];
91276@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
91277
91278 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
91279 {
91280- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
91281+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
91282 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
91283 int fdnum = scm->fp->count;
91284 struct file **fp = scm->fp->fp;
91285@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
91286 return -EFAULT;
91287 old_fs = get_fs();
91288 set_fs(KERNEL_DS);
91289- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
91290+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
91291 set_fs(old_fs);
91292
91293 return err;
91294@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
91295 len = sizeof(ktime);
91296 old_fs = get_fs();
91297 set_fs(KERNEL_DS);
91298- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
91299+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
91300 set_fs(old_fs);
91301
91302 if (!err) {
91303@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91304 case MCAST_JOIN_GROUP:
91305 case MCAST_LEAVE_GROUP:
91306 {
91307- struct compat_group_req __user *gr32 = (void *)optval;
91308+ struct compat_group_req __user *gr32 = (void __user *)optval;
91309 struct group_req __user *kgr =
91310 compat_alloc_user_space(sizeof(struct group_req));
91311 u32 interface;
91312@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91313 case MCAST_BLOCK_SOURCE:
91314 case MCAST_UNBLOCK_SOURCE:
91315 {
91316- struct compat_group_source_req __user *gsr32 = (void *)optval;
91317+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
91318 struct group_source_req __user *kgsr = compat_alloc_user_space(
91319 sizeof(struct group_source_req));
91320 u32 interface;
91321@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91322 }
91323 case MCAST_MSFILTER:
91324 {
91325- struct compat_group_filter __user *gf32 = (void *)optval;
91326+ struct compat_group_filter __user *gf32 = (void __user *)optval;
91327 struct group_filter __user *kgf;
91328 u32 interface, fmode, numsrc;
91329
91330@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
91331 char __user *optval, int __user *optlen,
91332 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
91333 {
91334- struct compat_group_filter __user *gf32 = (void *)optval;
91335+ struct compat_group_filter __user *gf32 = (void __user *)optval;
91336 struct group_filter __user *kgf;
91337 int __user *koptlen;
91338 u32 interface, fmode, numsrc;
91339@@ -805,7 +805,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
91340
91341 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
91342 return -EINVAL;
91343- if (copy_from_user(a, args, nas[call]))
91344+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
91345 return -EFAULT;
91346 a0 = a[0];
91347 a1 = a[1];
91348diff --git a/net/core/datagram.c b/net/core/datagram.c
91349index 8ab48cd..57b1a80 100644
91350--- a/net/core/datagram.c
91351+++ b/net/core/datagram.c
91352@@ -300,7 +300,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
91353 }
91354
91355 kfree_skb(skb);
91356- atomic_inc(&sk->sk_drops);
91357+ atomic_inc_unchecked(&sk->sk_drops);
91358 sk_mem_reclaim_partial(sk);
91359
91360 return err;
91361diff --git a/net/core/dev.c b/net/core/dev.c
91362index 26755dd..5020ced 100644
91363--- a/net/core/dev.c
91364+++ b/net/core/dev.c
91365@@ -1680,14 +1680,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
91366 {
91367 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
91368 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
91369- atomic_long_inc(&dev->rx_dropped);
91370+ atomic_long_inc_unchecked(&dev->rx_dropped);
91371 kfree_skb(skb);
91372 return NET_RX_DROP;
91373 }
91374 }
91375
91376 if (unlikely(!is_skb_forwardable(dev, skb))) {
91377- atomic_long_inc(&dev->rx_dropped);
91378+ atomic_long_inc_unchecked(&dev->rx_dropped);
91379 kfree_skb(skb);
91380 return NET_RX_DROP;
91381 }
91382@@ -2431,7 +2431,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
91383
91384 struct dev_gso_cb {
91385 void (*destructor)(struct sk_buff *skb);
91386-};
91387+} __no_const;
91388
91389 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
91390
91391@@ -3206,7 +3206,7 @@ enqueue:
91392
91393 local_irq_restore(flags);
91394
91395- atomic_long_inc(&skb->dev->rx_dropped);
91396+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
91397 kfree_skb(skb);
91398 return NET_RX_DROP;
91399 }
91400@@ -3278,7 +3278,7 @@ int netif_rx_ni(struct sk_buff *skb)
91401 }
91402 EXPORT_SYMBOL(netif_rx_ni);
91403
91404-static void net_tx_action(struct softirq_action *h)
91405+static void net_tx_action(void)
91406 {
91407 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91408
91409@@ -3612,7 +3612,7 @@ ncls:
91410 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
91411 } else {
91412 drop:
91413- atomic_long_inc(&skb->dev->rx_dropped);
91414+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
91415 kfree_skb(skb);
91416 /* Jamal, now you will not able to escape explaining
91417 * me how you were going to use this. :-)
91418@@ -4272,7 +4272,7 @@ void netif_napi_del(struct napi_struct *napi)
91419 }
91420 EXPORT_SYMBOL(netif_napi_del);
91421
91422-static void net_rx_action(struct softirq_action *h)
91423+static void net_rx_action(void)
91424 {
91425 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91426 unsigned long time_limit = jiffies + 2;
91427@@ -5730,7 +5730,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
91428 } else {
91429 netdev_stats_to_stats64(storage, &dev->stats);
91430 }
91431- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
91432+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
91433 return storage;
91434 }
91435 EXPORT_SYMBOL(dev_get_stats);
91436diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
91437index 5b7d0e1..cb960fc 100644
91438--- a/net/core/dev_ioctl.c
91439+++ b/net/core/dev_ioctl.c
91440@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
91441 if (no_module && capable(CAP_NET_ADMIN))
91442 no_module = request_module("netdev-%s", name);
91443 if (no_module && capable(CAP_SYS_MODULE)) {
91444+#ifdef CONFIG_GRKERNSEC_MODHARDEN
91445+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
91446+#else
91447 if (!request_module("%s", name))
91448 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
91449 name);
91450+#endif
91451 }
91452 }
91453 EXPORT_SYMBOL(dev_load);
91454diff --git a/net/core/flow.c b/net/core/flow.c
91455index dfa602c..3103d88 100644
91456--- a/net/core/flow.c
91457+++ b/net/core/flow.c
91458@@ -61,7 +61,7 @@ struct flow_cache {
91459 struct timer_list rnd_timer;
91460 };
91461
91462-atomic_t flow_cache_genid = ATOMIC_INIT(0);
91463+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
91464 EXPORT_SYMBOL(flow_cache_genid);
91465 static struct flow_cache flow_cache_global;
91466 static struct kmem_cache *flow_cachep __read_mostly;
91467@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
91468
91469 static int flow_entry_valid(struct flow_cache_entry *fle)
91470 {
91471- if (atomic_read(&flow_cache_genid) != fle->genid)
91472+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
91473 return 0;
91474 if (fle->object && !fle->object->ops->check(fle->object))
91475 return 0;
91476@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
91477 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
91478 fcp->hash_count++;
91479 }
91480- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
91481+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
91482 flo = fle->object;
91483 if (!flo)
91484 goto ret_object;
91485@@ -279,7 +279,7 @@ nocache:
91486 }
91487 flo = resolver(net, key, family, dir, flo, ctx);
91488 if (fle) {
91489- fle->genid = atomic_read(&flow_cache_genid);
91490+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
91491 if (!IS_ERR(flo))
91492 fle->object = flo;
91493 else
91494diff --git a/net/core/iovec.c b/net/core/iovec.c
91495index de178e4..1dabd8b 100644
91496--- a/net/core/iovec.c
91497+++ b/net/core/iovec.c
91498@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91499 if (m->msg_namelen) {
91500 if (mode == VERIFY_READ) {
91501 void __user *namep;
91502- namep = (void __user __force *) m->msg_name;
91503+ namep = (void __force_user *) m->msg_name;
91504 err = move_addr_to_kernel(namep, m->msg_namelen,
91505 address);
91506 if (err < 0)
91507@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91508 }
91509
91510 size = m->msg_iovlen * sizeof(struct iovec);
91511- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
91512+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
91513 return -EFAULT;
91514
91515 m->msg_iov = iov;
91516diff --git a/net/core/neighbour.c b/net/core/neighbour.c
91517index 60533db..14842cc 100644
91518--- a/net/core/neighbour.c
91519+++ b/net/core/neighbour.c
91520@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
91521 void __user *buffer, size_t *lenp, loff_t *ppos)
91522 {
91523 int size, ret;
91524- struct ctl_table tmp = *ctl;
91525+ ctl_table_no_const tmp = *ctl;
91526
91527 tmp.extra1 = &zero;
91528 tmp.extra2 = &unres_qlen_max;
91529diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
91530index 2bf8329..7960607 100644
91531--- a/net/core/net-procfs.c
91532+++ b/net/core/net-procfs.c
91533@@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
91534 else
91535 seq_printf(seq, "%04x", ntohs(pt->type));
91536
91537+#ifdef CONFIG_GRKERNSEC_HIDESYM
91538+ seq_printf(seq, " %-8s %pf\n",
91539+ pt->dev ? pt->dev->name : "", NULL);
91540+#else
91541 seq_printf(seq, " %-8s %pf\n",
91542 pt->dev ? pt->dev->name : "", pt->func);
91543+#endif
91544 }
91545
91546 return 0;
91547diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
91548index 981fed3..536af34 100644
91549--- a/net/core/net-sysfs.c
91550+++ b/net/core/net-sysfs.c
91551@@ -1311,7 +1311,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
91552 }
91553 EXPORT_SYMBOL(netdev_class_remove_file);
91554
91555-int netdev_kobject_init(void)
91556+int __init netdev_kobject_init(void)
91557 {
91558 kobj_ns_type_register(&net_ns_type_operations);
91559 return class_register(&net_class);
91560diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
91561index f9765203..9feaef8 100644
91562--- a/net/core/net_namespace.c
91563+++ b/net/core/net_namespace.c
91564@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
91565 int error;
91566 LIST_HEAD(net_exit_list);
91567
91568- list_add_tail(&ops->list, list);
91569+ pax_list_add_tail((struct list_head *)&ops->list, list);
91570 if (ops->init || (ops->id && ops->size)) {
91571 for_each_net(net) {
91572 error = ops_init(ops, net);
91573@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
91574
91575 out_undo:
91576 /* If I have an error cleanup all namespaces I initialized */
91577- list_del(&ops->list);
91578+ pax_list_del((struct list_head *)&ops->list);
91579 ops_exit_list(ops, &net_exit_list);
91580 ops_free_list(ops, &net_exit_list);
91581 return error;
91582@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
91583 struct net *net;
91584 LIST_HEAD(net_exit_list);
91585
91586- list_del(&ops->list);
91587+ pax_list_del((struct list_head *)&ops->list);
91588 for_each_net(net)
91589 list_add_tail(&net->exit_list, &net_exit_list);
91590 ops_exit_list(ops, &net_exit_list);
91591@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
91592 mutex_lock(&net_mutex);
91593 error = register_pernet_operations(&pernet_list, ops);
91594 if (!error && (first_device == &pernet_list))
91595- first_device = &ops->list;
91596+ first_device = (struct list_head *)&ops->list;
91597 mutex_unlock(&net_mutex);
91598 return error;
91599 }
91600diff --git a/net/core/netpoll.c b/net/core/netpoll.c
91601index 2c637e9..68c9087 100644
91602--- a/net/core/netpoll.c
91603+++ b/net/core/netpoll.c
91604@@ -428,7 +428,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91605 struct udphdr *udph;
91606 struct iphdr *iph;
91607 struct ethhdr *eth;
91608- static atomic_t ip_ident;
91609+ static atomic_unchecked_t ip_ident;
91610 struct ipv6hdr *ip6h;
91611
91612 udp_len = len + sizeof(*udph);
91613@@ -499,7 +499,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91614 put_unaligned(0x45, (unsigned char *)iph);
91615 iph->tos = 0;
91616 put_unaligned(htons(ip_len), &(iph->tot_len));
91617- iph->id = htons(atomic_inc_return(&ip_ident));
91618+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
91619 iph->frag_off = 0;
91620 iph->ttl = 64;
91621 iph->protocol = IPPROTO_UDP;
91622diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
91623index ca198c1d1..125372f 100644
91624--- a/net/core/rtnetlink.c
91625+++ b/net/core/rtnetlink.c
91626@@ -58,7 +58,7 @@ struct rtnl_link {
91627 rtnl_doit_func doit;
91628 rtnl_dumpit_func dumpit;
91629 rtnl_calcit_func calcit;
91630-};
91631+} __no_const;
91632
91633 static DEFINE_MUTEX(rtnl_mutex);
91634
91635@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
91636 if (rtnl_link_ops_get(ops->kind))
91637 return -EEXIST;
91638
91639- if (!ops->dellink)
91640- ops->dellink = unregister_netdevice_queue;
91641+ if (!ops->dellink) {
91642+ pax_open_kernel();
91643+ *(void **)&ops->dellink = unregister_netdevice_queue;
91644+ pax_close_kernel();
91645+ }
91646
91647- list_add_tail(&ops->list, &link_ops);
91648+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
91649 return 0;
91650 }
91651 EXPORT_SYMBOL_GPL(__rtnl_link_register);
91652@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
91653 for_each_net(net) {
91654 __rtnl_kill_links(net, ops);
91655 }
91656- list_del(&ops->list);
91657+ pax_list_del((struct list_head *)&ops->list);
91658 }
91659 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
91660
91661diff --git a/net/core/scm.c b/net/core/scm.c
91662index b4da80b..98d6bdb 100644
91663--- a/net/core/scm.c
91664+++ b/net/core/scm.c
91665@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
91666 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91667 {
91668 struct cmsghdr __user *cm
91669- = (__force struct cmsghdr __user *)msg->msg_control;
91670+ = (struct cmsghdr __force_user *)msg->msg_control;
91671 struct cmsghdr cmhdr;
91672 int cmlen = CMSG_LEN(len);
91673 int err;
91674@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91675 err = -EFAULT;
91676 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
91677 goto out;
91678- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
91679+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
91680 goto out;
91681 cmlen = CMSG_SPACE(len);
91682 if (msg->msg_controllen < cmlen)
91683@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
91684 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91685 {
91686 struct cmsghdr __user *cm
91687- = (__force struct cmsghdr __user*)msg->msg_control;
91688+ = (struct cmsghdr __force_user *)msg->msg_control;
91689
91690 int fdmax = 0;
91691 int fdnum = scm->fp->count;
91692@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91693 if (fdnum < fdmax)
91694 fdmax = fdnum;
91695
91696- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
91697+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
91698 i++, cmfptr++)
91699 {
91700 struct socket *sock;
91701diff --git a/net/core/skbuff.c b/net/core/skbuff.c
91702index 2c3d0f5..f5a326f 100644
91703--- a/net/core/skbuff.c
91704+++ b/net/core/skbuff.c
91705@@ -3082,13 +3082,15 @@ void __init skb_init(void)
91706 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
91707 sizeof(struct sk_buff),
91708 0,
91709- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91710+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91711+ SLAB_NO_SANITIZE,
91712 NULL);
91713 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
91714 (2*sizeof(struct sk_buff)) +
91715 sizeof(atomic_t),
91716 0,
91717- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91718+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91719+ SLAB_NO_SANITIZE,
91720 NULL);
91721 }
91722
91723diff --git a/net/core/sock.c b/net/core/sock.c
91724index 2c097c5..bf72858 100644
91725--- a/net/core/sock.c
91726+++ b/net/core/sock.c
91727@@ -392,7 +392,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91728 struct sk_buff_head *list = &sk->sk_receive_queue;
91729
91730 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
91731- atomic_inc(&sk->sk_drops);
91732+ atomic_inc_unchecked(&sk->sk_drops);
91733 trace_sock_rcvqueue_full(sk, skb);
91734 return -ENOMEM;
91735 }
91736@@ -402,7 +402,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91737 return err;
91738
91739 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
91740- atomic_inc(&sk->sk_drops);
91741+ atomic_inc_unchecked(&sk->sk_drops);
91742 return -ENOBUFS;
91743 }
91744
91745@@ -422,7 +422,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91746 skb_dst_force(skb);
91747
91748 spin_lock_irqsave(&list->lock, flags);
91749- skb->dropcount = atomic_read(&sk->sk_drops);
91750+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
91751 __skb_queue_tail(list, skb);
91752 spin_unlock_irqrestore(&list->lock, flags);
91753
91754@@ -442,7 +442,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91755 skb->dev = NULL;
91756
91757 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
91758- atomic_inc(&sk->sk_drops);
91759+ atomic_inc_unchecked(&sk->sk_drops);
91760 goto discard_and_relse;
91761 }
91762 if (nested)
91763@@ -460,7 +460,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91764 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
91765 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
91766 bh_unlock_sock(sk);
91767- atomic_inc(&sk->sk_drops);
91768+ atomic_inc_unchecked(&sk->sk_drops);
91769 goto discard_and_relse;
91770 }
91771
91772@@ -948,12 +948,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91773 struct timeval tm;
91774 } v;
91775
91776- int lv = sizeof(int);
91777- int len;
91778+ unsigned int lv = sizeof(int);
91779+ unsigned int len;
91780
91781 if (get_user(len, optlen))
91782 return -EFAULT;
91783- if (len < 0)
91784+ if (len > INT_MAX)
91785 return -EINVAL;
91786
91787 memset(&v, 0, sizeof(v));
91788@@ -1105,11 +1105,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91789
91790 case SO_PEERNAME:
91791 {
91792- char address[128];
91793+ char address[_K_SS_MAXSIZE];
91794
91795 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
91796 return -ENOTCONN;
91797- if (lv < len)
91798+ if (lv < len || sizeof address < len)
91799 return -EINVAL;
91800 if (copy_to_user(optval, address, len))
91801 return -EFAULT;
91802@@ -1182,7 +1182,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91803
91804 if (len > lv)
91805 len = lv;
91806- if (copy_to_user(optval, &v, len))
91807+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
91808 return -EFAULT;
91809 lenout:
91810 if (put_user(len, optlen))
91811@@ -2303,7 +2303,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
91812 */
91813 smp_wmb();
91814 atomic_set(&sk->sk_refcnt, 1);
91815- atomic_set(&sk->sk_drops, 0);
91816+ atomic_set_unchecked(&sk->sk_drops, 0);
91817 }
91818 EXPORT_SYMBOL(sock_init_data);
91819
91820diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
91821index a0e9cf6..ef7f9ed 100644
91822--- a/net/core/sock_diag.c
91823+++ b/net/core/sock_diag.c
91824@@ -9,26 +9,33 @@
91825 #include <linux/inet_diag.h>
91826 #include <linux/sock_diag.h>
91827
91828-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
91829+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
91830 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
91831 static DEFINE_MUTEX(sock_diag_table_mutex);
91832
91833 int sock_diag_check_cookie(void *sk, __u32 *cookie)
91834 {
91835+#ifndef CONFIG_GRKERNSEC_HIDESYM
91836 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
91837 cookie[1] != INET_DIAG_NOCOOKIE) &&
91838 ((u32)(unsigned long)sk != cookie[0] ||
91839 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
91840 return -ESTALE;
91841 else
91842+#endif
91843 return 0;
91844 }
91845 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
91846
91847 void sock_diag_save_cookie(void *sk, __u32 *cookie)
91848 {
91849+#ifdef CONFIG_GRKERNSEC_HIDESYM
91850+ cookie[0] = 0;
91851+ cookie[1] = 0;
91852+#else
91853 cookie[0] = (u32)(unsigned long)sk;
91854 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
91855+#endif
91856 }
91857 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
91858
91859@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
91860 mutex_lock(&sock_diag_table_mutex);
91861 if (sock_diag_handlers[hndl->family])
91862 err = -EBUSY;
91863- else
91864+ else {
91865+ pax_open_kernel();
91866 sock_diag_handlers[hndl->family] = hndl;
91867+ pax_close_kernel();
91868+ }
91869 mutex_unlock(&sock_diag_table_mutex);
91870
91871 return err;
91872@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
91873
91874 mutex_lock(&sock_diag_table_mutex);
91875 BUG_ON(sock_diag_handlers[family] != hnld);
91876+ pax_open_kernel();
91877 sock_diag_handlers[family] = NULL;
91878+ pax_close_kernel();
91879 mutex_unlock(&sock_diag_table_mutex);
91880 }
91881 EXPORT_SYMBOL_GPL(sock_diag_unregister);
91882diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
91883index 31107ab..ae03d5a 100644
91884--- a/net/core/sysctl_net_core.c
91885+++ b/net/core/sysctl_net_core.c
91886@@ -31,7 +31,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
91887 {
91888 unsigned int orig_size, size;
91889 int ret, i;
91890- struct ctl_table tmp = {
91891+ ctl_table_no_const tmp = {
91892 .data = &size,
91893 .maxlen = sizeof(size),
91894 .mode = table->mode
91895@@ -350,13 +350,12 @@ static struct ctl_table netns_core_table[] = {
91896
91897 static __net_init int sysctl_core_net_init(struct net *net)
91898 {
91899- struct ctl_table *tbl;
91900+ ctl_table_no_const *tbl = NULL;
91901
91902 net->core.sysctl_somaxconn = SOMAXCONN;
91903
91904- tbl = netns_core_table;
91905 if (!net_eq(net, &init_net)) {
91906- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
91907+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
91908 if (tbl == NULL)
91909 goto err_dup;
91910
91911@@ -366,17 +365,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
91912 if (net->user_ns != &init_user_ns) {
91913 tbl[0].procname = NULL;
91914 }
91915- }
91916-
91917- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
91918+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
91919+ } else
91920+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
91921 if (net->core.sysctl_hdr == NULL)
91922 goto err_reg;
91923
91924 return 0;
91925
91926 err_reg:
91927- if (tbl != netns_core_table)
91928- kfree(tbl);
91929+ kfree(tbl);
91930 err_dup:
91931 return -ENOMEM;
91932 }
91933@@ -391,7 +389,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
91934 kfree(tbl);
91935 }
91936
91937-static __net_initdata struct pernet_operations sysctl_core_ops = {
91938+static __net_initconst struct pernet_operations sysctl_core_ops = {
91939 .init = sysctl_core_net_init,
91940 .exit = sysctl_core_net_exit,
91941 };
91942diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
91943index dd4d506..fb2fb87 100644
91944--- a/net/decnet/af_decnet.c
91945+++ b/net/decnet/af_decnet.c
91946@@ -465,6 +465,7 @@ static struct proto dn_proto = {
91947 .sysctl_rmem = sysctl_decnet_rmem,
91948 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
91949 .obj_size = sizeof(struct dn_sock),
91950+ .slab_flags = SLAB_USERCOPY,
91951 };
91952
91953 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
91954diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
91955index 5325b54..a0d4d69 100644
91956--- a/net/decnet/sysctl_net_decnet.c
91957+++ b/net/decnet/sysctl_net_decnet.c
91958@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
91959
91960 if (len > *lenp) len = *lenp;
91961
91962- if (copy_to_user(buffer, addr, len))
91963+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
91964 return -EFAULT;
91965
91966 *lenp = len;
91967@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
91968
91969 if (len > *lenp) len = *lenp;
91970
91971- if (copy_to_user(buffer, devname, len))
91972+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
91973 return -EFAULT;
91974
91975 *lenp = len;
91976diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
91977index 3b9d5f2..d7015c6 100644
91978--- a/net/ieee802154/6lowpan.c
91979+++ b/net/ieee802154/6lowpan.c
91980@@ -459,7 +459,7 @@ static int lowpan_header_create(struct sk_buff *skb,
91981 hc06_ptr += 3;
91982 } else {
91983 /* compress nothing */
91984- memcpy(hc06_ptr, &hdr, 4);
91985+ memcpy(hc06_ptr, hdr, 4);
91986 /* replace the top byte with new ECN | DSCP format */
91987 *hc06_ptr = tmp;
91988 hc06_ptr += 4;
91989diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
91990index b4d0be2..443d0f0 100644
91991--- a/net/ipv4/af_inet.c
91992+++ b/net/ipv4/af_inet.c
91993@@ -1689,13 +1689,9 @@ static int __init inet_init(void)
91994
91995 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
91996
91997- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
91998- if (!sysctl_local_reserved_ports)
91999- goto out;
92000-
92001 rc = proto_register(&tcp_prot, 1);
92002 if (rc)
92003- goto out_free_reserved_ports;
92004+ goto out;
92005
92006 rc = proto_register(&udp_prot, 1);
92007 if (rc)
92008@@ -1804,8 +1800,6 @@ out_unregister_udp_proto:
92009 proto_unregister(&udp_prot);
92010 out_unregister_tcp_proto:
92011 proto_unregister(&tcp_prot);
92012-out_free_reserved_ports:
92013- kfree(sysctl_local_reserved_ports);
92014 goto out;
92015 }
92016
92017diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
92018index 34ca6d5..b6421e8 100644
92019--- a/net/ipv4/devinet.c
92020+++ b/net/ipv4/devinet.c
92021@@ -1532,7 +1532,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
92022 idx = 0;
92023 head = &net->dev_index_head[h];
92024 rcu_read_lock();
92025- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
92026+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
92027 net->dev_base_seq;
92028 hlist_for_each_entry_rcu(dev, head, index_hlist) {
92029 if (idx < s_idx)
92030@@ -1843,7 +1843,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
92031 idx = 0;
92032 head = &net->dev_index_head[h];
92033 rcu_read_lock();
92034- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
92035+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
92036 net->dev_base_seq;
92037 hlist_for_each_entry_rcu(dev, head, index_hlist) {
92038 if (idx < s_idx)
92039@@ -2068,7 +2068,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
92040 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
92041 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
92042
92043-static struct devinet_sysctl_table {
92044+static const struct devinet_sysctl_table {
92045 struct ctl_table_header *sysctl_header;
92046 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
92047 } devinet_sysctl = {
92048@@ -2186,7 +2186,7 @@ static __net_init int devinet_init_net(struct net *net)
92049 int err;
92050 struct ipv4_devconf *all, *dflt;
92051 #ifdef CONFIG_SYSCTL
92052- struct ctl_table *tbl = ctl_forward_entry;
92053+ ctl_table_no_const *tbl = NULL;
92054 struct ctl_table_header *forw_hdr;
92055 #endif
92056
92057@@ -2204,7 +2204,7 @@ static __net_init int devinet_init_net(struct net *net)
92058 goto err_alloc_dflt;
92059
92060 #ifdef CONFIG_SYSCTL
92061- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
92062+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
92063 if (tbl == NULL)
92064 goto err_alloc_ctl;
92065
92066@@ -2224,7 +2224,10 @@ static __net_init int devinet_init_net(struct net *net)
92067 goto err_reg_dflt;
92068
92069 err = -ENOMEM;
92070- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
92071+ if (!net_eq(net, &init_net))
92072+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
92073+ else
92074+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
92075 if (forw_hdr == NULL)
92076 goto err_reg_ctl;
92077 net->ipv4.forw_hdr = forw_hdr;
92078@@ -2240,8 +2243,7 @@ err_reg_ctl:
92079 err_reg_dflt:
92080 __devinet_sysctl_unregister(all);
92081 err_reg_all:
92082- if (tbl != ctl_forward_entry)
92083- kfree(tbl);
92084+ kfree(tbl);
92085 err_alloc_ctl:
92086 #endif
92087 if (dflt != &ipv4_devconf_dflt)
92088diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
92089index b3f627a..b0f3e99 100644
92090--- a/net/ipv4/fib_frontend.c
92091+++ b/net/ipv4/fib_frontend.c
92092@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
92093 #ifdef CONFIG_IP_ROUTE_MULTIPATH
92094 fib_sync_up(dev);
92095 #endif
92096- atomic_inc(&net->ipv4.dev_addr_genid);
92097+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92098 rt_cache_flush(dev_net(dev));
92099 break;
92100 case NETDEV_DOWN:
92101 fib_del_ifaddr(ifa, NULL);
92102- atomic_inc(&net->ipv4.dev_addr_genid);
92103+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92104 if (ifa->ifa_dev->ifa_list == NULL) {
92105 /* Last address was deleted from this interface.
92106 * Disable IP.
92107@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
92108 #ifdef CONFIG_IP_ROUTE_MULTIPATH
92109 fib_sync_up(dev);
92110 #endif
92111- atomic_inc(&net->ipv4.dev_addr_genid);
92112+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92113 rt_cache_flush(net);
92114 break;
92115 case NETDEV_DOWN:
92116diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
92117index d5dbca5..6251d5f 100644
92118--- a/net/ipv4/fib_semantics.c
92119+++ b/net/ipv4/fib_semantics.c
92120@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
92121 nh->nh_saddr = inet_select_addr(nh->nh_dev,
92122 nh->nh_gw,
92123 nh->nh_parent->fib_scope);
92124- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
92125+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
92126
92127 return nh->nh_saddr;
92128 }
92129diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
92130index 6acb541..9ea617d 100644
92131--- a/net/ipv4/inet_connection_sock.c
92132+++ b/net/ipv4/inet_connection_sock.c
92133@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
92134 .range = { 32768, 61000 },
92135 };
92136
92137-unsigned long *sysctl_local_reserved_ports;
92138+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
92139 EXPORT_SYMBOL(sysctl_local_reserved_ports);
92140
92141 void inet_get_local_port_range(int *low, int *high)
92142diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
92143index 7bd8983..3abdcf6 100644
92144--- a/net/ipv4/inet_hashtables.c
92145+++ b/net/ipv4/inet_hashtables.c
92146@@ -18,12 +18,15 @@
92147 #include <linux/sched.h>
92148 #include <linux/slab.h>
92149 #include <linux/wait.h>
92150+#include <linux/security.h>
92151
92152 #include <net/inet_connection_sock.h>
92153 #include <net/inet_hashtables.h>
92154 #include <net/secure_seq.h>
92155 #include <net/ip.h>
92156
92157+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
92158+
92159 /*
92160 * Allocate and initialize a new local port bind bucket.
92161 * The bindhash mutex for snum's hash chain must be held here.
92162@@ -554,6 +557,8 @@ ok:
92163 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
92164 spin_unlock(&head->lock);
92165
92166+ gr_update_task_in_ip_table(current, inet_sk(sk));
92167+
92168 if (tw) {
92169 inet_twsk_deschedule(tw, death_row);
92170 while (twrefcnt) {
92171diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
92172index 000e3d2..5472da3 100644
92173--- a/net/ipv4/inetpeer.c
92174+++ b/net/ipv4/inetpeer.c
92175@@ -503,8 +503,8 @@ relookup:
92176 if (p) {
92177 p->daddr = *daddr;
92178 atomic_set(&p->refcnt, 1);
92179- atomic_set(&p->rid, 0);
92180- atomic_set(&p->ip_id_count,
92181+ atomic_set_unchecked(&p->rid, 0);
92182+ atomic_set_unchecked(&p->ip_id_count,
92183 (daddr->family == AF_INET) ?
92184 secure_ip_id(daddr->addr.a4) :
92185 secure_ipv6_id(daddr->addr.a6));
92186diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
92187index b66910a..cfe416e 100644
92188--- a/net/ipv4/ip_fragment.c
92189+++ b/net/ipv4/ip_fragment.c
92190@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
92191 return 0;
92192
92193 start = qp->rid;
92194- end = atomic_inc_return(&peer->rid);
92195+ end = atomic_inc_return_unchecked(&peer->rid);
92196 qp->rid = end;
92197
92198 rc = qp->q.fragments && (end - start) > max;
92199@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
92200
92201 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92202 {
92203- struct ctl_table *table;
92204+ ctl_table_no_const *table = NULL;
92205 struct ctl_table_header *hdr;
92206
92207- table = ip4_frags_ns_ctl_table;
92208 if (!net_eq(net, &init_net)) {
92209- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
92210+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
92211 if (table == NULL)
92212 goto err_alloc;
92213
92214@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92215 /* Don't export sysctls to unprivileged users */
92216 if (net->user_ns != &init_user_ns)
92217 table[0].procname = NULL;
92218- }
92219+ hdr = register_net_sysctl(net, "net/ipv4", table);
92220+ } else
92221+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
92222
92223- hdr = register_net_sysctl(net, "net/ipv4", table);
92224 if (hdr == NULL)
92225 goto err_reg;
92226
92227@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92228 return 0;
92229
92230 err_reg:
92231- if (!net_eq(net, &init_net))
92232- kfree(table);
92233+ kfree(table);
92234 err_alloc:
92235 return -ENOMEM;
92236 }
92237diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
92238index 8d6939e..19d0a95 100644
92239--- a/net/ipv4/ip_gre.c
92240+++ b/net/ipv4/ip_gre.c
92241@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
92242 module_param(log_ecn_error, bool, 0644);
92243 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
92244
92245-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
92246+static struct rtnl_link_ops ipgre_link_ops;
92247 static int ipgre_tunnel_init(struct net_device *dev);
92248
92249 static int ipgre_net_id __read_mostly;
92250@@ -731,7 +731,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
92251 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
92252 };
92253
92254-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
92255+static struct rtnl_link_ops ipgre_link_ops = {
92256 .kind = "gre",
92257 .maxtype = IFLA_GRE_MAX,
92258 .policy = ipgre_policy,
92259@@ -745,7 +745,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
92260 .fill_info = ipgre_fill_info,
92261 };
92262
92263-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
92264+static struct rtnl_link_ops ipgre_tap_ops = {
92265 .kind = "gretap",
92266 .maxtype = IFLA_GRE_MAX,
92267 .policy = ipgre_policy,
92268diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
92269index d9c4f11..02b82dbc 100644
92270--- a/net/ipv4/ip_sockglue.c
92271+++ b/net/ipv4/ip_sockglue.c
92272@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
92273 len = min_t(unsigned int, len, opt->optlen);
92274 if (put_user(len, optlen))
92275 return -EFAULT;
92276- if (copy_to_user(optval, opt->__data, len))
92277+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
92278+ copy_to_user(optval, opt->__data, len))
92279 return -EFAULT;
92280 return 0;
92281 }
92282@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
92283 if (sk->sk_type != SOCK_STREAM)
92284 return -ENOPROTOOPT;
92285
92286- msg.msg_control = optval;
92287+ msg.msg_control = (void __force_kernel *)optval;
92288 msg.msg_controllen = len;
92289 msg.msg_flags = flags;
92290
92291diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
92292index 17cc0ff..63856c4 100644
92293--- a/net/ipv4/ip_vti.c
92294+++ b/net/ipv4/ip_vti.c
92295@@ -47,7 +47,7 @@
92296 #define HASH_SIZE 16
92297 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
92298
92299-static struct rtnl_link_ops vti_link_ops __read_mostly;
92300+static struct rtnl_link_ops vti_link_ops;
92301
92302 static int vti_net_id __read_mostly;
92303 struct vti_net {
92304@@ -840,7 +840,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
92305 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
92306 };
92307
92308-static struct rtnl_link_ops vti_link_ops __read_mostly = {
92309+static struct rtnl_link_ops vti_link_ops = {
92310 .kind = "vti",
92311 .maxtype = IFLA_VTI_MAX,
92312 .policy = vti_policy,
92313diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
92314index efa1138..20dbba0 100644
92315--- a/net/ipv4/ipconfig.c
92316+++ b/net/ipv4/ipconfig.c
92317@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
92318
92319 mm_segment_t oldfs = get_fs();
92320 set_fs(get_ds());
92321- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
92322+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
92323 set_fs(oldfs);
92324 return res;
92325 }
92326@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
92327
92328 mm_segment_t oldfs = get_fs();
92329 set_fs(get_ds());
92330- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
92331+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
92332 set_fs(oldfs);
92333 return res;
92334 }
92335@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
92336
92337 mm_segment_t oldfs = get_fs();
92338 set_fs(get_ds());
92339- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
92340+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
92341 set_fs(oldfs);
92342 return res;
92343 }
92344diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
92345index b3ac3c3..ec6bd95 100644
92346--- a/net/ipv4/ipip.c
92347+++ b/net/ipv4/ipip.c
92348@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
92349 static int ipip_net_id __read_mostly;
92350
92351 static int ipip_tunnel_init(struct net_device *dev);
92352-static struct rtnl_link_ops ipip_link_ops __read_mostly;
92353+static struct rtnl_link_ops ipip_link_ops;
92354
92355 static int ipip_err(struct sk_buff *skb, u32 info)
92356 {
92357@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
92358 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
92359 };
92360
92361-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
92362+static struct rtnl_link_ops ipip_link_ops = {
92363 .kind = "ipip",
92364 .maxtype = IFLA_IPTUN_MAX,
92365 .policy = ipip_policy,
92366diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
92367index 85a4f21..1beb1f5 100644
92368--- a/net/ipv4/netfilter/arp_tables.c
92369+++ b/net/ipv4/netfilter/arp_tables.c
92370@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
92371 #endif
92372
92373 static int get_info(struct net *net, void __user *user,
92374- const int *len, int compat)
92375+ int len, int compat)
92376 {
92377 char name[XT_TABLE_MAXNAMELEN];
92378 struct xt_table *t;
92379 int ret;
92380
92381- if (*len != sizeof(struct arpt_getinfo)) {
92382- duprintf("length %u != %Zu\n", *len,
92383+ if (len != sizeof(struct arpt_getinfo)) {
92384+ duprintf("length %u != %Zu\n", len,
92385 sizeof(struct arpt_getinfo));
92386 return -EINVAL;
92387 }
92388@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
92389 info.size = private->size;
92390 strcpy(info.name, name);
92391
92392- if (copy_to_user(user, &info, *len) != 0)
92393+ if (copy_to_user(user, &info, len) != 0)
92394 ret = -EFAULT;
92395 else
92396 ret = 0;
92397@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
92398
92399 switch (cmd) {
92400 case ARPT_SO_GET_INFO:
92401- ret = get_info(sock_net(sk), user, len, 1);
92402+ ret = get_info(sock_net(sk), user, *len, 1);
92403 break;
92404 case ARPT_SO_GET_ENTRIES:
92405 ret = compat_get_entries(sock_net(sk), user, len);
92406@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
92407
92408 switch (cmd) {
92409 case ARPT_SO_GET_INFO:
92410- ret = get_info(sock_net(sk), user, len, 0);
92411+ ret = get_info(sock_net(sk), user, *len, 0);
92412 break;
92413
92414 case ARPT_SO_GET_ENTRIES:
92415diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
92416index d23118d..6ad7277 100644
92417--- a/net/ipv4/netfilter/ip_tables.c
92418+++ b/net/ipv4/netfilter/ip_tables.c
92419@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
92420 #endif
92421
92422 static int get_info(struct net *net, void __user *user,
92423- const int *len, int compat)
92424+ int len, int compat)
92425 {
92426 char name[XT_TABLE_MAXNAMELEN];
92427 struct xt_table *t;
92428 int ret;
92429
92430- if (*len != sizeof(struct ipt_getinfo)) {
92431- duprintf("length %u != %zu\n", *len,
92432+ if (len != sizeof(struct ipt_getinfo)) {
92433+ duprintf("length %u != %zu\n", len,
92434 sizeof(struct ipt_getinfo));
92435 return -EINVAL;
92436 }
92437@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
92438 info.size = private->size;
92439 strcpy(info.name, name);
92440
92441- if (copy_to_user(user, &info, *len) != 0)
92442+ if (copy_to_user(user, &info, len) != 0)
92443 ret = -EFAULT;
92444 else
92445 ret = 0;
92446@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92447
92448 switch (cmd) {
92449 case IPT_SO_GET_INFO:
92450- ret = get_info(sock_net(sk), user, len, 1);
92451+ ret = get_info(sock_net(sk), user, *len, 1);
92452 break;
92453 case IPT_SO_GET_ENTRIES:
92454 ret = compat_get_entries(sock_net(sk), user, len);
92455@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92456
92457 switch (cmd) {
92458 case IPT_SO_GET_INFO:
92459- ret = get_info(sock_net(sk), user, len, 0);
92460+ ret = get_info(sock_net(sk), user, *len, 0);
92461 break;
92462
92463 case IPT_SO_GET_ENTRIES:
92464diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
92465index 746427c..80eab72 100644
92466--- a/net/ipv4/ping.c
92467+++ b/net/ipv4/ping.c
92468@@ -55,7 +55,7 @@
92469
92470
92471 struct ping_table ping_table;
92472-struct pingv6_ops pingv6_ops;
92473+struct pingv6_ops *pingv6_ops;
92474 EXPORT_SYMBOL_GPL(pingv6_ops);
92475
92476 static u16 ping_port_rover;
92477@@ -335,7 +335,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
92478 return -ENODEV;
92479 }
92480 }
92481- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
92482+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
92483 scoped);
92484 rcu_read_unlock();
92485
92486@@ -541,7 +541,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92487 }
92488 #if IS_ENABLED(CONFIG_IPV6)
92489 } else if (skb->protocol == htons(ETH_P_IPV6)) {
92490- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
92491+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
92492 #endif
92493 }
92494
92495@@ -559,7 +559,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92496 info, (u8 *)icmph);
92497 #if IS_ENABLED(CONFIG_IPV6)
92498 } else if (family == AF_INET6) {
92499- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
92500+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
92501 info, (u8 *)icmph);
92502 #endif
92503 }
92504@@ -850,7 +850,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92505 return ip_recv_error(sk, msg, len);
92506 #if IS_ENABLED(CONFIG_IPV6)
92507 } else if (family == AF_INET6) {
92508- return pingv6_ops.ipv6_recv_error(sk, msg, len);
92509+ return pingv6_ops->ipv6_recv_error(sk, msg, len);
92510 #endif
92511 }
92512 }
92513@@ -900,7 +900,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92514 IP6CB(skb)->iif);
92515
92516 if (inet6_sk(sk)->rxopt.all)
92517- pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
92518+ pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
92519 #endif
92520 } else {
92521 BUG();
92522@@ -1090,7 +1090,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
92523 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
92524 0, sock_i_ino(sp),
92525 atomic_read(&sp->sk_refcnt), sp,
92526- atomic_read(&sp->sk_drops), len);
92527+ atomic_read_unchecked(&sp->sk_drops), len);
92528 }
92529
92530 static int ping_v4_seq_show(struct seq_file *seq, void *v)
92531diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
92532index 61e60d6..d6996cd 100644
92533--- a/net/ipv4/raw.c
92534+++ b/net/ipv4/raw.c
92535@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
92536 int raw_rcv(struct sock *sk, struct sk_buff *skb)
92537 {
92538 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
92539- atomic_inc(&sk->sk_drops);
92540+ atomic_inc_unchecked(&sk->sk_drops);
92541 kfree_skb(skb);
92542 return NET_RX_DROP;
92543 }
92544@@ -746,16 +746,20 @@ static int raw_init(struct sock *sk)
92545
92546 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
92547 {
92548+ struct icmp_filter filter;
92549+
92550 if (optlen > sizeof(struct icmp_filter))
92551 optlen = sizeof(struct icmp_filter);
92552- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
92553+ if (copy_from_user(&filter, optval, optlen))
92554 return -EFAULT;
92555+ raw_sk(sk)->filter = filter;
92556 return 0;
92557 }
92558
92559 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
92560 {
92561 int len, ret = -EFAULT;
92562+ struct icmp_filter filter;
92563
92564 if (get_user(len, optlen))
92565 goto out;
92566@@ -765,8 +769,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
92567 if (len > sizeof(struct icmp_filter))
92568 len = sizeof(struct icmp_filter);
92569 ret = -EFAULT;
92570- if (put_user(len, optlen) ||
92571- copy_to_user(optval, &raw_sk(sk)->filter, len))
92572+ filter = raw_sk(sk)->filter;
92573+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
92574 goto out;
92575 ret = 0;
92576 out: return ret;
92577@@ -995,7 +999,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
92578 0, 0L, 0,
92579 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
92580 0, sock_i_ino(sp),
92581- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
92582+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
92583 }
92584
92585 static int raw_seq_show(struct seq_file *seq, void *v)
92586diff --git a/net/ipv4/route.c b/net/ipv4/route.c
92587index a9a54a2..647316e 100644
92588--- a/net/ipv4/route.c
92589+++ b/net/ipv4/route.c
92590@@ -2615,34 +2615,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
92591 .maxlen = sizeof(int),
92592 .mode = 0200,
92593 .proc_handler = ipv4_sysctl_rtcache_flush,
92594+ .extra1 = &init_net,
92595 },
92596 { },
92597 };
92598
92599 static __net_init int sysctl_route_net_init(struct net *net)
92600 {
92601- struct ctl_table *tbl;
92602+ ctl_table_no_const *tbl = NULL;
92603
92604- tbl = ipv4_route_flush_table;
92605 if (!net_eq(net, &init_net)) {
92606- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92607+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92608 if (tbl == NULL)
92609 goto err_dup;
92610
92611 /* Don't export sysctls to unprivileged users */
92612 if (net->user_ns != &init_user_ns)
92613 tbl[0].procname = NULL;
92614- }
92615- tbl[0].extra1 = net;
92616+ tbl[0].extra1 = net;
92617+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92618+ } else
92619+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
92620
92621- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92622 if (net->ipv4.route_hdr == NULL)
92623 goto err_reg;
92624 return 0;
92625
92626 err_reg:
92627- if (tbl != ipv4_route_flush_table)
92628- kfree(tbl);
92629+ kfree(tbl);
92630 err_dup:
92631 return -ENOMEM;
92632 }
92633@@ -2665,8 +2665,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
92634
92635 static __net_init int rt_genid_init(struct net *net)
92636 {
92637- atomic_set(&net->rt_genid, 0);
92638- atomic_set(&net->fnhe_genid, 0);
92639+ atomic_set_unchecked(&net->rt_genid, 0);
92640+ atomic_set_unchecked(&net->fnhe_genid, 0);
92641 get_random_bytes(&net->ipv4.dev_addr_genid,
92642 sizeof(net->ipv4.dev_addr_genid));
92643 return 0;
92644diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
92645index 610e324..fd42e75 100644
92646--- a/net/ipv4/sysctl_net_ipv4.c
92647+++ b/net/ipv4/sysctl_net_ipv4.c
92648@@ -57,7 +57,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
92649 {
92650 int ret;
92651 int range[2];
92652- struct ctl_table tmp = {
92653+ ctl_table_no_const tmp = {
92654 .data = &range,
92655 .maxlen = sizeof(range),
92656 .mode = table->mode,
92657@@ -110,7 +110,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
92658 int ret;
92659 gid_t urange[2];
92660 kgid_t low, high;
92661- struct ctl_table tmp = {
92662+ ctl_table_no_const tmp = {
92663 .data = &urange,
92664 .maxlen = sizeof(urange),
92665 .mode = table->mode,
92666@@ -141,7 +141,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
92667 void __user *buffer, size_t *lenp, loff_t *ppos)
92668 {
92669 char val[TCP_CA_NAME_MAX];
92670- struct ctl_table tbl = {
92671+ ctl_table_no_const tbl = {
92672 .data = val,
92673 .maxlen = TCP_CA_NAME_MAX,
92674 };
92675@@ -160,7 +160,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
92676 void __user *buffer, size_t *lenp,
92677 loff_t *ppos)
92678 {
92679- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
92680+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
92681 int ret;
92682
92683 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92684@@ -177,7 +177,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
92685 void __user *buffer, size_t *lenp,
92686 loff_t *ppos)
92687 {
92688- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
92689+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
92690 int ret;
92691
92692 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92693@@ -203,15 +203,17 @@ static int ipv4_tcp_mem(struct ctl_table *ctl, int write,
92694 struct mem_cgroup *memcg;
92695 #endif
92696
92697- struct ctl_table tmp = {
92698+ ctl_table_no_const tmp = {
92699 .data = &vec,
92700 .maxlen = sizeof(vec),
92701 .mode = ctl->mode,
92702 };
92703
92704 if (!write) {
92705- ctl->data = &net->ipv4.sysctl_tcp_mem;
92706- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
92707+ ctl_table_no_const tcp_mem = *ctl;
92708+
92709+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
92710+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
92711 }
92712
92713 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
92714@@ -239,7 +241,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
92715 void __user *buffer, size_t *lenp,
92716 loff_t *ppos)
92717 {
92718- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92719+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92720 struct tcp_fastopen_context *ctxt;
92721 int ret;
92722 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
92723@@ -482,7 +484,7 @@ static struct ctl_table ipv4_table[] = {
92724 },
92725 {
92726 .procname = "ip_local_reserved_ports",
92727- .data = NULL, /* initialized in sysctl_ipv4_init */
92728+ .data = sysctl_local_reserved_ports,
92729 .maxlen = 65536,
92730 .mode = 0644,
92731 .proc_handler = proc_do_large_bitmap,
92732@@ -847,11 +849,10 @@ static struct ctl_table ipv4_net_table[] = {
92733
92734 static __net_init int ipv4_sysctl_init_net(struct net *net)
92735 {
92736- struct ctl_table *table;
92737+ ctl_table_no_const *table = NULL;
92738
92739- table = ipv4_net_table;
92740 if (!net_eq(net, &init_net)) {
92741- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
92742+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
92743 if (table == NULL)
92744 goto err_alloc;
92745
92746@@ -886,15 +887,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
92747
92748 tcp_init_mem(net);
92749
92750- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92751+ if (!net_eq(net, &init_net))
92752+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92753+ else
92754+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
92755 if (net->ipv4.ipv4_hdr == NULL)
92756 goto err_reg;
92757
92758 return 0;
92759
92760 err_reg:
92761- if (!net_eq(net, &init_net))
92762- kfree(table);
92763+ kfree(table);
92764 err_alloc:
92765 return -ENOMEM;
92766 }
92767@@ -916,16 +919,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
92768 static __init int sysctl_ipv4_init(void)
92769 {
92770 struct ctl_table_header *hdr;
92771- struct ctl_table *i;
92772-
92773- for (i = ipv4_table; i->procname; i++) {
92774- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
92775- i->data = sysctl_local_reserved_ports;
92776- break;
92777- }
92778- }
92779- if (!i->procname)
92780- return -EINVAL;
92781
92782 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
92783 if (hdr == NULL)
92784diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
92785index 3ca2139..c4cc060 100644
92786--- a/net/ipv4/tcp_input.c
92787+++ b/net/ipv4/tcp_input.c
92788@@ -4379,7 +4379,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
92789 * simplifies code)
92790 */
92791 static void
92792-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92793+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92794 struct sk_buff *head, struct sk_buff *tail,
92795 u32 start, u32 end)
92796 {
92797@@ -5465,6 +5465,7 @@ discard:
92798 tcp_paws_reject(&tp->rx_opt, 0))
92799 goto discard_and_undo;
92800
92801+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
92802 if (th->syn) {
92803 /* We see SYN without ACK. It is attempt of
92804 * simultaneous connect with crossed SYNs.
92805@@ -5515,6 +5516,7 @@ discard:
92806 goto discard;
92807 #endif
92808 }
92809+#endif
92810 /* "fifth, if neither of the SYN or RST bits is set then
92811 * drop the segment and return."
92812 */
92813@@ -5560,7 +5562,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
92814 goto discard;
92815
92816 if (th->syn) {
92817- if (th->fin)
92818+ if (th->fin || th->urg || th->psh)
92819 goto discard;
92820 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
92821 return 1;
92822diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
92823index b299da5..097db06 100644
92824--- a/net/ipv4/tcp_ipv4.c
92825+++ b/net/ipv4/tcp_ipv4.c
92826@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
92827 EXPORT_SYMBOL(sysctl_tcp_low_latency);
92828
92829
92830+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92831+extern int grsec_enable_blackhole;
92832+#endif
92833+
92834 #ifdef CONFIG_TCP_MD5SIG
92835 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
92836 __be32 daddr, __be32 saddr, const struct tcphdr *th);
92837@@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
92838 return 0;
92839
92840 reset:
92841+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92842+ if (!grsec_enable_blackhole)
92843+#endif
92844 tcp_v4_send_reset(rsk, skb);
92845 discard:
92846 kfree_skb(skb);
92847@@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
92848 TCP_SKB_CB(skb)->sacked = 0;
92849
92850 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
92851- if (!sk)
92852+ if (!sk) {
92853+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92854+ ret = 1;
92855+#endif
92856 goto no_tcp_socket;
92857-
92858+ }
92859 process:
92860- if (sk->sk_state == TCP_TIME_WAIT)
92861+ if (sk->sk_state == TCP_TIME_WAIT) {
92862+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92863+ ret = 2;
92864+#endif
92865 goto do_time_wait;
92866+ }
92867
92868 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
92869 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
92870@@ -2034,6 +2048,10 @@ csum_error:
92871 bad_packet:
92872 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
92873 } else {
92874+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92875+ if (!grsec_enable_blackhole || (ret == 1 &&
92876+ (skb->dev->flags & IFF_LOOPBACK)))
92877+#endif
92878 tcp_v4_send_reset(NULL, skb);
92879 }
92880
92881diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
92882index ab1c086..2a8d76b 100644
92883--- a/net/ipv4/tcp_minisocks.c
92884+++ b/net/ipv4/tcp_minisocks.c
92885@@ -27,6 +27,10 @@
92886 #include <net/inet_common.h>
92887 #include <net/xfrm.h>
92888
92889+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92890+extern int grsec_enable_blackhole;
92891+#endif
92892+
92893 int sysctl_tcp_syncookies __read_mostly = 1;
92894 EXPORT_SYMBOL(sysctl_tcp_syncookies);
92895
92896@@ -715,7 +719,10 @@ embryonic_reset:
92897 * avoid becoming vulnerable to outside attack aiming at
92898 * resetting legit local connections.
92899 */
92900- req->rsk_ops->send_reset(sk, skb);
92901+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92902+ if (!grsec_enable_blackhole)
92903+#endif
92904+ req->rsk_ops->send_reset(sk, skb);
92905 } else if (fastopen) { /* received a valid RST pkt */
92906 reqsk_fastopen_remove(sk, req, true);
92907 tcp_reset(sk);
92908diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
92909index d4943f6..e7a74a5 100644
92910--- a/net/ipv4/tcp_probe.c
92911+++ b/net/ipv4/tcp_probe.c
92912@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
92913 if (cnt + width >= len)
92914 break;
92915
92916- if (copy_to_user(buf + cnt, tbuf, width))
92917+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
92918 return -EFAULT;
92919 cnt += width;
92920 }
92921diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
92922index 4b85e6f..22f9ac9 100644
92923--- a/net/ipv4/tcp_timer.c
92924+++ b/net/ipv4/tcp_timer.c
92925@@ -22,6 +22,10 @@
92926 #include <linux/gfp.h>
92927 #include <net/tcp.h>
92928
92929+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92930+extern int grsec_lastack_retries;
92931+#endif
92932+
92933 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
92934 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
92935 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
92936@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
92937 }
92938 }
92939
92940+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92941+ if ((sk->sk_state == TCP_LAST_ACK) &&
92942+ (grsec_lastack_retries > 0) &&
92943+ (grsec_lastack_retries < retry_until))
92944+ retry_until = grsec_lastack_retries;
92945+#endif
92946+
92947 if (retransmits_timed_out(sk, retry_until,
92948 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
92949 /* Has it gone just too far? */
92950diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
92951index 766e6ba..aff2f8d 100644
92952--- a/net/ipv4/udp.c
92953+++ b/net/ipv4/udp.c
92954@@ -87,6 +87,7 @@
92955 #include <linux/types.h>
92956 #include <linux/fcntl.h>
92957 #include <linux/module.h>
92958+#include <linux/security.h>
92959 #include <linux/socket.h>
92960 #include <linux/sockios.h>
92961 #include <linux/igmp.h>
92962@@ -112,6 +113,10 @@
92963 #include <net/busy_poll.h>
92964 #include "udp_impl.h"
92965
92966+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92967+extern int grsec_enable_blackhole;
92968+#endif
92969+
92970 struct udp_table udp_table __read_mostly;
92971 EXPORT_SYMBOL(udp_table);
92972
92973@@ -595,6 +600,9 @@ found:
92974 return s;
92975 }
92976
92977+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
92978+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
92979+
92980 /*
92981 * This routine is called by the ICMP module when it gets some
92982 * sort of error condition. If err < 0 then the socket should
92983@@ -891,9 +899,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92984 dport = usin->sin_port;
92985 if (dport == 0)
92986 return -EINVAL;
92987+
92988+ err = gr_search_udp_sendmsg(sk, usin);
92989+ if (err)
92990+ return err;
92991 } else {
92992 if (sk->sk_state != TCP_ESTABLISHED)
92993 return -EDESTADDRREQ;
92994+
92995+ err = gr_search_udp_sendmsg(sk, NULL);
92996+ if (err)
92997+ return err;
92998+
92999 daddr = inet->inet_daddr;
93000 dport = inet->inet_dport;
93001 /* Open fast path for connected socket.
93002@@ -1137,7 +1154,7 @@ static unsigned int first_packet_length(struct sock *sk)
93003 IS_UDPLITE(sk));
93004 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93005 IS_UDPLITE(sk));
93006- atomic_inc(&sk->sk_drops);
93007+ atomic_inc_unchecked(&sk->sk_drops);
93008 __skb_unlink(skb, rcvq);
93009 __skb_queue_tail(&list_kill, skb);
93010 }
93011@@ -1223,6 +1240,10 @@ try_again:
93012 if (!skb)
93013 goto out;
93014
93015+ err = gr_search_udp_recvmsg(sk, skb);
93016+ if (err)
93017+ goto out_free;
93018+
93019 ulen = skb->len - sizeof(struct udphdr);
93020 copied = len;
93021 if (copied > ulen)
93022@@ -1256,7 +1277,7 @@ try_again:
93023 if (unlikely(err)) {
93024 trace_kfree_skb(skb, udp_recvmsg);
93025 if (!peeked) {
93026- atomic_inc(&sk->sk_drops);
93027+ atomic_inc_unchecked(&sk->sk_drops);
93028 UDP_INC_STATS_USER(sock_net(sk),
93029 UDP_MIB_INERRORS, is_udplite);
93030 }
93031@@ -1543,7 +1564,7 @@ csum_error:
93032 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
93033 drop:
93034 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
93035- atomic_inc(&sk->sk_drops);
93036+ atomic_inc_unchecked(&sk->sk_drops);
93037 kfree_skb(skb);
93038 return -1;
93039 }
93040@@ -1562,7 +1583,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
93041 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
93042
93043 if (!skb1) {
93044- atomic_inc(&sk->sk_drops);
93045+ atomic_inc_unchecked(&sk->sk_drops);
93046 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
93047 IS_UDPLITE(sk));
93048 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93049@@ -1734,6 +1755,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
93050 goto csum_error;
93051
93052 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
93053+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93054+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
93055+#endif
93056 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
93057
93058 /*
93059@@ -2166,7 +2190,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
93060 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
93061 0, sock_i_ino(sp),
93062 atomic_read(&sp->sk_refcnt), sp,
93063- atomic_read(&sp->sk_drops), len);
93064+ atomic_read_unchecked(&sp->sk_drops), len);
93065 }
93066
93067 int udp4_seq_show(struct seq_file *seq, void *v)
93068diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
93069index 9a459be..086b866 100644
93070--- a/net/ipv4/xfrm4_policy.c
93071+++ b/net/ipv4/xfrm4_policy.c
93072@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
93073
93074 static int __net_init xfrm4_net_init(struct net *net)
93075 {
93076- struct ctl_table *table;
93077+ ctl_table_no_const *table = NULL;
93078 struct ctl_table_header *hdr;
93079
93080- table = xfrm4_policy_table;
93081 if (!net_eq(net, &init_net)) {
93082- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
93083+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
93084 if (!table)
93085 goto err_alloc;
93086
93087 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
93088- }
93089-
93090- hdr = register_net_sysctl(net, "net/ipv4", table);
93091+ hdr = register_net_sysctl(net, "net/ipv4", table);
93092+ } else
93093+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
93094 if (!hdr)
93095 goto err_reg;
93096
93097@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
93098 return 0;
93099
93100 err_reg:
93101- if (!net_eq(net, &init_net))
93102- kfree(table);
93103+ kfree(table);
93104 err_alloc:
93105 return -ENOMEM;
93106 }
93107diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
93108index 498ea99..42501bc 100644
93109--- a/net/ipv6/addrconf.c
93110+++ b/net/ipv6/addrconf.c
93111@@ -618,7 +618,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
93112 idx = 0;
93113 head = &net->dev_index_head[h];
93114 rcu_read_lock();
93115- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
93116+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
93117 net->dev_base_seq;
93118 hlist_for_each_entry_rcu(dev, head, index_hlist) {
93119 if (idx < s_idx)
93120@@ -2381,7 +2381,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
93121 p.iph.ihl = 5;
93122 p.iph.protocol = IPPROTO_IPV6;
93123 p.iph.ttl = 64;
93124- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
93125+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
93126
93127 if (ops->ndo_do_ioctl) {
93128 mm_segment_t oldfs = get_fs();
93129@@ -4030,7 +4030,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
93130 s_ip_idx = ip_idx = cb->args[2];
93131
93132 rcu_read_lock();
93133- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
93134+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
93135 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
93136 idx = 0;
93137 head = &net->dev_index_head[h];
93138@@ -4651,7 +4651,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
93139 dst_free(&ifp->rt->dst);
93140 break;
93141 }
93142- atomic_inc(&net->ipv6.dev_addr_genid);
93143+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
93144 }
93145
93146 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
93147@@ -4671,7 +4671,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
93148 int *valp = ctl->data;
93149 int val = *valp;
93150 loff_t pos = *ppos;
93151- struct ctl_table lctl;
93152+ ctl_table_no_const lctl;
93153 int ret;
93154
93155 /*
93156@@ -4756,7 +4756,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
93157 int *valp = ctl->data;
93158 int val = *valp;
93159 loff_t pos = *ppos;
93160- struct ctl_table lctl;
93161+ ctl_table_no_const lctl;
93162 int ret;
93163
93164 /*
93165diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
93166index 197e6f4..16d8396 100644
93167--- a/net/ipv6/datagram.c
93168+++ b/net/ipv6/datagram.c
93169@@ -904,5 +904,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
93170 0,
93171 sock_i_ino(sp),
93172 atomic_read(&sp->sk_refcnt), sp,
93173- atomic_read(&sp->sk_drops));
93174+ atomic_read_unchecked(&sp->sk_drops));
93175 }
93176diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
93177index 7cfc8d2..c5394b6 100644
93178--- a/net/ipv6/icmp.c
93179+++ b/net/ipv6/icmp.c
93180@@ -989,7 +989,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
93181
93182 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
93183 {
93184- struct ctl_table *table;
93185+ ctl_table_no_const *table;
93186
93187 table = kmemdup(ipv6_icmp_table_template,
93188 sizeof(ipv6_icmp_table_template),
93189diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
93190index 90747f1..505320d 100644
93191--- a/net/ipv6/ip6_gre.c
93192+++ b/net/ipv6/ip6_gre.c
93193@@ -74,7 +74,7 @@ struct ip6gre_net {
93194 struct net_device *fb_tunnel_dev;
93195 };
93196
93197-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
93198+static struct rtnl_link_ops ip6gre_link_ops;
93199 static int ip6gre_tunnel_init(struct net_device *dev);
93200 static void ip6gre_tunnel_setup(struct net_device *dev);
93201 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
93202@@ -1288,7 +1288,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
93203 }
93204
93205
93206-static struct inet6_protocol ip6gre_protocol __read_mostly = {
93207+static struct inet6_protocol ip6gre_protocol = {
93208 .handler = ip6gre_rcv,
93209 .err_handler = ip6gre_err,
93210 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
93211@@ -1622,7 +1622,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
93212 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
93213 };
93214
93215-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
93216+static struct rtnl_link_ops ip6gre_link_ops = {
93217 .kind = "ip6gre",
93218 .maxtype = IFLA_GRE_MAX,
93219 .policy = ip6gre_policy,
93220@@ -1635,7 +1635,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
93221 .fill_info = ip6gre_fill_info,
93222 };
93223
93224-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
93225+static struct rtnl_link_ops ip6gre_tap_ops = {
93226 .kind = "ip6gretap",
93227 .maxtype = IFLA_GRE_MAX,
93228 .policy = ip6gre_policy,
93229diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
93230index 46ba243..576f50e 100644
93231--- a/net/ipv6/ip6_tunnel.c
93232+++ b/net/ipv6/ip6_tunnel.c
93233@@ -88,7 +88,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
93234
93235 static int ip6_tnl_dev_init(struct net_device *dev);
93236 static void ip6_tnl_dev_setup(struct net_device *dev);
93237-static struct rtnl_link_ops ip6_link_ops __read_mostly;
93238+static struct rtnl_link_ops ip6_link_ops;
93239
93240 static int ip6_tnl_net_id __read_mostly;
93241 struct ip6_tnl_net {
93242@@ -1678,7 +1678,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
93243 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
93244 };
93245
93246-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
93247+static struct rtnl_link_ops ip6_link_ops = {
93248 .kind = "ip6tnl",
93249 .maxtype = IFLA_IPTUN_MAX,
93250 .policy = ip6_tnl_policy,
93251diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
93252index d1e2e8e..51c19ae 100644
93253--- a/net/ipv6/ipv6_sockglue.c
93254+++ b/net/ipv6/ipv6_sockglue.c
93255@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
93256 if (sk->sk_type != SOCK_STREAM)
93257 return -ENOPROTOOPT;
93258
93259- msg.msg_control = optval;
93260+ msg.msg_control = (void __force_kernel *)optval;
93261 msg.msg_controllen = len;
93262 msg.msg_flags = flags;
93263
93264diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
93265index 44400c2..8e11f52 100644
93266--- a/net/ipv6/netfilter/ip6_tables.c
93267+++ b/net/ipv6/netfilter/ip6_tables.c
93268@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
93269 #endif
93270
93271 static int get_info(struct net *net, void __user *user,
93272- const int *len, int compat)
93273+ int len, int compat)
93274 {
93275 char name[XT_TABLE_MAXNAMELEN];
93276 struct xt_table *t;
93277 int ret;
93278
93279- if (*len != sizeof(struct ip6t_getinfo)) {
93280- duprintf("length %u != %zu\n", *len,
93281+ if (len != sizeof(struct ip6t_getinfo)) {
93282+ duprintf("length %u != %zu\n", len,
93283 sizeof(struct ip6t_getinfo));
93284 return -EINVAL;
93285 }
93286@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
93287 info.size = private->size;
93288 strcpy(info.name, name);
93289
93290- if (copy_to_user(user, &info, *len) != 0)
93291+ if (copy_to_user(user, &info, len) != 0)
93292 ret = -EFAULT;
93293 else
93294 ret = 0;
93295@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93296
93297 switch (cmd) {
93298 case IP6T_SO_GET_INFO:
93299- ret = get_info(sock_net(sk), user, len, 1);
93300+ ret = get_info(sock_net(sk), user, *len, 1);
93301 break;
93302 case IP6T_SO_GET_ENTRIES:
93303 ret = compat_get_entries(sock_net(sk), user, len);
93304@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93305
93306 switch (cmd) {
93307 case IP6T_SO_GET_INFO:
93308- ret = get_info(sock_net(sk), user, len, 0);
93309+ ret = get_info(sock_net(sk), user, *len, 0);
93310 break;
93311
93312 case IP6T_SO_GET_ENTRIES:
93313diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
93314index dffdc1a..ccc6678 100644
93315--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
93316+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
93317@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
93318
93319 static int nf_ct_frag6_sysctl_register(struct net *net)
93320 {
93321- struct ctl_table *table;
93322+ ctl_table_no_const *table = NULL;
93323 struct ctl_table_header *hdr;
93324
93325- table = nf_ct_frag6_sysctl_table;
93326 if (!net_eq(net, &init_net)) {
93327- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
93328+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
93329 GFP_KERNEL);
93330 if (table == NULL)
93331 goto err_alloc;
93332@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93333 table[0].data = &net->nf_frag.frags.timeout;
93334 table[1].data = &net->nf_frag.frags.low_thresh;
93335 table[2].data = &net->nf_frag.frags.high_thresh;
93336- }
93337-
93338- hdr = register_net_sysctl(net, "net/netfilter", table);
93339+ hdr = register_net_sysctl(net, "net/netfilter", table);
93340+ } else
93341+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
93342 if (hdr == NULL)
93343 goto err_reg;
93344
93345@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93346 return 0;
93347
93348 err_reg:
93349- if (!net_eq(net, &init_net))
93350- kfree(table);
93351+ kfree(table);
93352 err_alloc:
93353 return -ENOMEM;
93354 }
93355diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
93356index ab92a36..bb4a528 100644
93357--- a/net/ipv6/output_core.c
93358+++ b/net/ipv6/output_core.c
93359@@ -8,8 +8,8 @@
93360
93361 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93362 {
93363- static atomic_t ipv6_fragmentation_id;
93364- int old, new;
93365+ static atomic_unchecked_t ipv6_fragmentation_id;
93366+ int id;
93367
93368 #if IS_ENABLED(CONFIG_IPV6)
93369 if (rt && !(rt->dst.flags & DST_NOPEER)) {
93370@@ -25,13 +25,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93371 }
93372 }
93373 #endif
93374- do {
93375- old = atomic_read(&ipv6_fragmentation_id);
93376- new = old + 1;
93377- if (!new)
93378- new = 1;
93379- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
93380- fhdr->identification = htonl(new);
93381+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93382+ if (!id)
93383+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93384+ fhdr->identification = htonl(id);
93385 }
93386 EXPORT_SYMBOL(ipv6_select_ident);
93387
93388diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
93389index 18f19df..b46ada1 100644
93390--- a/net/ipv6/ping.c
93391+++ b/net/ipv6/ping.c
93392@@ -245,6 +245,22 @@ static struct pernet_operations ping_v6_net_ops = {
93393 };
93394 #endif
93395
93396+static struct pingv6_ops real_pingv6_ops = {
93397+ .ipv6_recv_error = ipv6_recv_error,
93398+ .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
93399+ .icmpv6_err_convert = icmpv6_err_convert,
93400+ .ipv6_icmp_error = ipv6_icmp_error,
93401+ .ipv6_chk_addr = ipv6_chk_addr,
93402+};
93403+
93404+static struct pingv6_ops dummy_pingv6_ops = {
93405+ .ipv6_recv_error = dummy_ipv6_recv_error,
93406+ .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
93407+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
93408+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
93409+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
93410+};
93411+
93412 int __init pingv6_init(void)
93413 {
93414 #ifdef CONFIG_PROC_FS
93415@@ -252,11 +268,7 @@ int __init pingv6_init(void)
93416 if (ret)
93417 return ret;
93418 #endif
93419- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
93420- pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
93421- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
93422- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
93423- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
93424+ pingv6_ops = &real_pingv6_ops;
93425 return inet6_register_protosw(&pingv6_protosw);
93426 }
93427
93428@@ -265,11 +277,7 @@ int __init pingv6_init(void)
93429 */
93430 void pingv6_exit(void)
93431 {
93432- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
93433- pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
93434- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
93435- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
93436- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
93437+ pingv6_ops = &dummy_pingv6_ops;
93438 #ifdef CONFIG_PROC_FS
93439 unregister_pernet_subsys(&ping_v6_net_ops);
93440 #endif
93441diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
93442index cdaed47..515edde9 100644
93443--- a/net/ipv6/raw.c
93444+++ b/net/ipv6/raw.c
93445@@ -108,7 +108,7 @@ found:
93446 */
93447 static int icmpv6_filter(const struct sock *sk, const struct sk_buff *skb)
93448 {
93449- struct icmp6hdr *_hdr;
93450+ struct icmp6hdr _hdr;
93451 const struct icmp6hdr *hdr;
93452
93453 hdr = skb_header_pointer(skb, skb_transport_offset(skb),
93454@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
93455 {
93456 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
93457 skb_checksum_complete(skb)) {
93458- atomic_inc(&sk->sk_drops);
93459+ atomic_inc_unchecked(&sk->sk_drops);
93460 kfree_skb(skb);
93461 return NET_RX_DROP;
93462 }
93463@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93464 struct raw6_sock *rp = raw6_sk(sk);
93465
93466 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
93467- atomic_inc(&sk->sk_drops);
93468+ atomic_inc_unchecked(&sk->sk_drops);
93469 kfree_skb(skb);
93470 return NET_RX_DROP;
93471 }
93472@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93473
93474 if (inet->hdrincl) {
93475 if (skb_checksum_complete(skb)) {
93476- atomic_inc(&sk->sk_drops);
93477+ atomic_inc_unchecked(&sk->sk_drops);
93478 kfree_skb(skb);
93479 return NET_RX_DROP;
93480 }
93481@@ -602,7 +602,7 @@ out:
93482 return err;
93483 }
93484
93485-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
93486+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
93487 struct flowi6 *fl6, struct dst_entry **dstp,
93488 unsigned int flags)
93489 {
93490@@ -915,12 +915,15 @@ do_confirm:
93491 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
93492 char __user *optval, int optlen)
93493 {
93494+ struct icmp6_filter filter;
93495+
93496 switch (optname) {
93497 case ICMPV6_FILTER:
93498 if (optlen > sizeof(struct icmp6_filter))
93499 optlen = sizeof(struct icmp6_filter);
93500- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
93501+ if (copy_from_user(&filter, optval, optlen))
93502 return -EFAULT;
93503+ raw6_sk(sk)->filter = filter;
93504 return 0;
93505 default:
93506 return -ENOPROTOOPT;
93507@@ -933,6 +936,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93508 char __user *optval, int __user *optlen)
93509 {
93510 int len;
93511+ struct icmp6_filter filter;
93512
93513 switch (optname) {
93514 case ICMPV6_FILTER:
93515@@ -944,7 +948,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93516 len = sizeof(struct icmp6_filter);
93517 if (put_user(len, optlen))
93518 return -EFAULT;
93519- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
93520+ filter = raw6_sk(sk)->filter;
93521+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
93522 return -EFAULT;
93523 return 0;
93524 default:
93525diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
93526index 1aeb473..bea761c 100644
93527--- a/net/ipv6/reassembly.c
93528+++ b/net/ipv6/reassembly.c
93529@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
93530
93531 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93532 {
93533- struct ctl_table *table;
93534+ ctl_table_no_const *table = NULL;
93535 struct ctl_table_header *hdr;
93536
93537- table = ip6_frags_ns_ctl_table;
93538 if (!net_eq(net, &init_net)) {
93539- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93540+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93541 if (table == NULL)
93542 goto err_alloc;
93543
93544@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93545 /* Don't export sysctls to unprivileged users */
93546 if (net->user_ns != &init_user_ns)
93547 table[0].procname = NULL;
93548- }
93549+ hdr = register_net_sysctl(net, "net/ipv6", table);
93550+ } else
93551+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
93552
93553- hdr = register_net_sysctl(net, "net/ipv6", table);
93554 if (hdr == NULL)
93555 goto err_reg;
93556
93557@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93558 return 0;
93559
93560 err_reg:
93561- if (!net_eq(net, &init_net))
93562- kfree(table);
93563+ kfree(table);
93564 err_alloc:
93565 return -ENOMEM;
93566 }
93567diff --git a/net/ipv6/route.c b/net/ipv6/route.c
93568index 8d9a93ed..cd89616 100644
93569--- a/net/ipv6/route.c
93570+++ b/net/ipv6/route.c
93571@@ -2926,7 +2926,7 @@ struct ctl_table ipv6_route_table_template[] = {
93572
93573 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
93574 {
93575- struct ctl_table *table;
93576+ ctl_table_no_const *table;
93577
93578 table = kmemdup(ipv6_route_table_template,
93579 sizeof(ipv6_route_table_template),
93580diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
93581index 21b25dd..9a43e37 100644
93582--- a/net/ipv6/sit.c
93583+++ b/net/ipv6/sit.c
93584@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
93585 static void ipip6_dev_free(struct net_device *dev);
93586 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
93587 __be32 *v4dst);
93588-static struct rtnl_link_ops sit_link_ops __read_mostly;
93589+static struct rtnl_link_ops sit_link_ops;
93590
93591 static int sit_net_id __read_mostly;
93592 struct sit_net {
93593@@ -1547,7 +1547,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
93594 #endif
93595 };
93596
93597-static struct rtnl_link_ops sit_link_ops __read_mostly = {
93598+static struct rtnl_link_ops sit_link_ops = {
93599 .kind = "sit",
93600 .maxtype = IFLA_IPTUN_MAX,
93601 .policy = ipip6_policy,
93602diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
93603index 107b2f1..72741a9 100644
93604--- a/net/ipv6/sysctl_net_ipv6.c
93605+++ b/net/ipv6/sysctl_net_ipv6.c
93606@@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
93607
93608 static int __net_init ipv6_sysctl_net_init(struct net *net)
93609 {
93610- struct ctl_table *ipv6_table;
93611+ ctl_table_no_const *ipv6_table;
93612 struct ctl_table *ipv6_route_table;
93613 struct ctl_table *ipv6_icmp_table;
93614 int err;
93615diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
93616index 6e1649d..75ddb4c 100644
93617--- a/net/ipv6/tcp_ipv6.c
93618+++ b/net/ipv6/tcp_ipv6.c
93619@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
93620 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
93621 }
93622
93623+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93624+extern int grsec_enable_blackhole;
93625+#endif
93626+
93627 static void tcp_v6_hash(struct sock *sk)
93628 {
93629 if (sk->sk_state != TCP_CLOSE) {
93630@@ -1399,6 +1403,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
93631 return 0;
93632
93633 reset:
93634+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93635+ if (!grsec_enable_blackhole)
93636+#endif
93637 tcp_v6_send_reset(sk, skb);
93638 discard:
93639 if (opt_skb)
93640@@ -1427,7 +1434,7 @@ ipv6_pktoptions:
93641 if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim)
93642 np->mcast_hops = ipv6_hdr(opt_skb)->hop_limit;
93643 if (np->rxopt.bits.rxtclass)
93644- np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));
93645+ np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(opt_skb));
93646 if (ipv6_opt_accepted(sk, opt_skb)) {
93647 skb_set_owner_r(opt_skb, sk);
93648 opt_skb = xchg(&np->pktoptions, opt_skb);
93649@@ -1481,12 +1488,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
93650 TCP_SKB_CB(skb)->sacked = 0;
93651
93652 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
93653- if (!sk)
93654+ if (!sk) {
93655+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93656+ ret = 1;
93657+#endif
93658 goto no_tcp_socket;
93659+ }
93660
93661 process:
93662- if (sk->sk_state == TCP_TIME_WAIT)
93663+ if (sk->sk_state == TCP_TIME_WAIT) {
93664+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93665+ ret = 2;
93666+#endif
93667 goto do_time_wait;
93668+ }
93669
93670 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
93671 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
93672@@ -1538,6 +1553,10 @@ csum_error:
93673 bad_packet:
93674 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
93675 } else {
93676+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93677+ if (!grsec_enable_blackhole || (ret == 1 &&
93678+ (skb->dev->flags & IFF_LOOPBACK)))
93679+#endif
93680 tcp_v6_send_reset(NULL, skb);
93681 }
93682
93683diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
93684index f405815..45a68a6 100644
93685--- a/net/ipv6/udp.c
93686+++ b/net/ipv6/udp.c
93687@@ -53,6 +53,10 @@
93688 #include <trace/events/skb.h>
93689 #include "udp_impl.h"
93690
93691+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93692+extern int grsec_enable_blackhole;
93693+#endif
93694+
93695 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
93696 {
93697 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
93698@@ -420,7 +424,7 @@ try_again:
93699 if (unlikely(err)) {
93700 trace_kfree_skb(skb, udpv6_recvmsg);
93701 if (!peeked) {
93702- atomic_inc(&sk->sk_drops);
93703+ atomic_inc_unchecked(&sk->sk_drops);
93704 if (is_udp4)
93705 UDP_INC_STATS_USER(sock_net(sk),
93706 UDP_MIB_INERRORS,
93707@@ -666,7 +670,7 @@ csum_error:
93708 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
93709 drop:
93710 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
93711- atomic_inc(&sk->sk_drops);
93712+ atomic_inc_unchecked(&sk->sk_drops);
93713 kfree_skb(skb);
93714 return -1;
93715 }
93716@@ -724,7 +728,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
93717 if (likely(skb1 == NULL))
93718 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
93719 if (!skb1) {
93720- atomic_inc(&sk->sk_drops);
93721+ atomic_inc_unchecked(&sk->sk_drops);
93722 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
93723 IS_UDPLITE(sk));
93724 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93725@@ -864,6 +868,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
93726 goto csum_error;
93727
93728 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
93729+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93730+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
93731+#endif
93732 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
93733
93734 kfree_skb(skb);
93735diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
93736index 23ed03d..465a71d 100644
93737--- a/net/ipv6/xfrm6_policy.c
93738+++ b/net/ipv6/xfrm6_policy.c
93739@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
93740
93741 static int __net_init xfrm6_net_init(struct net *net)
93742 {
93743- struct ctl_table *table;
93744+ ctl_table_no_const *table = NULL;
93745 struct ctl_table_header *hdr;
93746
93747- table = xfrm6_policy_table;
93748 if (!net_eq(net, &init_net)) {
93749- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93750+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93751 if (!table)
93752 goto err_alloc;
93753
93754 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
93755- }
93756+ hdr = register_net_sysctl(net, "net/ipv6", table);
93757+ } else
93758+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
93759
93760- hdr = register_net_sysctl(net, "net/ipv6", table);
93761 if (!hdr)
93762 goto err_reg;
93763
93764@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
93765 return 0;
93766
93767 err_reg:
93768- if (!net_eq(net, &init_net))
93769- kfree(table);
93770+ kfree(table);
93771 err_alloc:
93772 return -ENOMEM;
93773 }
93774diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
93775index 41ac7938..75e3bb1 100644
93776--- a/net/irda/ircomm/ircomm_tty.c
93777+++ b/net/irda/ircomm/ircomm_tty.c
93778@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93779 add_wait_queue(&port->open_wait, &wait);
93780
93781 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
93782- __FILE__, __LINE__, tty->driver->name, port->count);
93783+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93784
93785 spin_lock_irqsave(&port->lock, flags);
93786 if (!tty_hung_up_p(filp))
93787- port->count--;
93788+ atomic_dec(&port->count);
93789 port->blocked_open++;
93790 spin_unlock_irqrestore(&port->lock, flags);
93791
93792@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93793 }
93794
93795 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
93796- __FILE__, __LINE__, tty->driver->name, port->count);
93797+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93798
93799 schedule();
93800 }
93801@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93802
93803 spin_lock_irqsave(&port->lock, flags);
93804 if (!tty_hung_up_p(filp))
93805- port->count++;
93806+ atomic_inc(&port->count);
93807 port->blocked_open--;
93808 spin_unlock_irqrestore(&port->lock, flags);
93809
93810 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
93811- __FILE__, __LINE__, tty->driver->name, port->count);
93812+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93813
93814 if (!retval)
93815 port->flags |= ASYNC_NORMAL_ACTIVE;
93816@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
93817
93818 /* ++ is not atomic, so this should be protected - Jean II */
93819 spin_lock_irqsave(&self->port.lock, flags);
93820- self->port.count++;
93821+ atomic_inc(&self->port.count);
93822 spin_unlock_irqrestore(&self->port.lock, flags);
93823 tty_port_tty_set(&self->port, tty);
93824
93825 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
93826- self->line, self->port.count);
93827+ self->line, atomic_read(&self->port.count));
93828
93829 /* Not really used by us, but lets do it anyway */
93830 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
93831@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
93832 tty_kref_put(port->tty);
93833 }
93834 port->tty = NULL;
93835- port->count = 0;
93836+ atomic_set(&port->count, 0);
93837 spin_unlock_irqrestore(&port->lock, flags);
93838
93839 wake_up_interruptible(&port->open_wait);
93840@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
93841 seq_putc(m, '\n');
93842
93843 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
93844- seq_printf(m, "Open count: %d\n", self->port.count);
93845+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
93846 seq_printf(m, "Max data size: %d\n", self->max_data_size);
93847 seq_printf(m, "Max header size: %d\n", self->max_header_size);
93848
93849diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
93850index 168aff5..9d43132 100644
93851--- a/net/iucv/af_iucv.c
93852+++ b/net/iucv/af_iucv.c
93853@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
93854
93855 write_lock_bh(&iucv_sk_list.lock);
93856
93857- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
93858+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
93859 while (__iucv_get_sock_by_name(name)) {
93860 sprintf(name, "%08x",
93861- atomic_inc_return(&iucv_sk_list.autobind_name));
93862+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
93863 }
93864
93865 write_unlock_bh(&iucv_sk_list.lock);
93866diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
93867index cd5b8ec..f205e6b 100644
93868--- a/net/iucv/iucv.c
93869+++ b/net/iucv/iucv.c
93870@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
93871 return NOTIFY_OK;
93872 }
93873
93874-static struct notifier_block __refdata iucv_cpu_notifier = {
93875+static struct notifier_block iucv_cpu_notifier = {
93876 .notifier_call = iucv_cpu_notify,
93877 };
93878
93879diff --git a/net/key/af_key.c b/net/key/af_key.c
93880index ab8bd2c..cd2d641 100644
93881--- a/net/key/af_key.c
93882+++ b/net/key/af_key.c
93883@@ -3048,10 +3048,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
93884 static u32 get_acqseq(void)
93885 {
93886 u32 res;
93887- static atomic_t acqseq;
93888+ static atomic_unchecked_t acqseq;
93889
93890 do {
93891- res = atomic_inc_return(&acqseq);
93892+ res = atomic_inc_return_unchecked(&acqseq);
93893 } while (!res);
93894 return res;
93895 }
93896diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
93897index 43dd752..63a23bc 100644
93898--- a/net/mac80211/cfg.c
93899+++ b/net/mac80211/cfg.c
93900@@ -820,7 +820,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
93901 ret = ieee80211_vif_use_channel(sdata, chandef,
93902 IEEE80211_CHANCTX_EXCLUSIVE);
93903 }
93904- } else if (local->open_count == local->monitors) {
93905+ } else if (local_read(&local->open_count) == local->monitors) {
93906 local->_oper_chandef = *chandef;
93907 ieee80211_hw_config(local, 0);
93908 }
93909@@ -2941,7 +2941,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
93910 else
93911 local->probe_req_reg--;
93912
93913- if (!local->open_count)
93914+ if (!local_read(&local->open_count))
93915 break;
93916
93917 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
93918@@ -3404,8 +3404,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
93919 if (chanctx_conf) {
93920 *chandef = chanctx_conf->def;
93921 ret = 0;
93922- } else if (local->open_count > 0 &&
93923- local->open_count == local->monitors &&
93924+ } else if (local_read(&local->open_count) > 0 &&
93925+ local_read(&local->open_count) == local->monitors &&
93926 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
93927 if (local->use_chanctx)
93928 *chandef = local->monitor_chandef;
93929diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
93930index 8412a30..6e00181 100644
93931--- a/net/mac80211/ieee80211_i.h
93932+++ b/net/mac80211/ieee80211_i.h
93933@@ -28,6 +28,7 @@
93934 #include <net/ieee80211_radiotap.h>
93935 #include <net/cfg80211.h>
93936 #include <net/mac80211.h>
93937+#include <asm/local.h>
93938 #include "key.h"
93939 #include "sta_info.h"
93940 #include "debug.h"
93941@@ -907,7 +908,7 @@ struct ieee80211_local {
93942 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
93943 spinlock_t queue_stop_reason_lock;
93944
93945- int open_count;
93946+ local_t open_count;
93947 int monitors, cooked_mntrs;
93948 /* number of interfaces with corresponding FIF_ flags */
93949 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
93950diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
93951index cc11759..11d5541 100644
93952--- a/net/mac80211/iface.c
93953+++ b/net/mac80211/iface.c
93954@@ -511,7 +511,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
93955 break;
93956 }
93957
93958- if (local->open_count == 0) {
93959+ if (local_read(&local->open_count) == 0) {
93960 res = drv_start(local);
93961 if (res)
93962 goto err_del_bss;
93963@@ -558,7 +558,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
93964 res = drv_add_interface(local, sdata);
93965 if (res)
93966 goto err_stop;
93967- } else if (local->monitors == 0 && local->open_count == 0) {
93968+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
93969 res = ieee80211_add_virtual_monitor(local);
93970 if (res)
93971 goto err_stop;
93972@@ -666,7 +666,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
93973 atomic_inc(&local->iff_promiscs);
93974
93975 if (coming_up)
93976- local->open_count++;
93977+ local_inc(&local->open_count);
93978
93979 if (hw_reconf_flags)
93980 ieee80211_hw_config(local, hw_reconf_flags);
93981@@ -704,7 +704,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
93982 err_del_interface:
93983 drv_remove_interface(local, sdata);
93984 err_stop:
93985- if (!local->open_count)
93986+ if (!local_read(&local->open_count))
93987 drv_stop(local);
93988 err_del_bss:
93989 sdata->bss = NULL;
93990@@ -841,7 +841,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
93991 }
93992
93993 if (going_down)
93994- local->open_count--;
93995+ local_dec(&local->open_count);
93996
93997 switch (sdata->vif.type) {
93998 case NL80211_IFTYPE_AP_VLAN:
93999@@ -908,7 +908,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94000 }
94001 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
94002
94003- if (local->open_count == 0)
94004+ if (local_read(&local->open_count) == 0)
94005 ieee80211_clear_tx_pending(local);
94006
94007 /*
94008@@ -948,7 +948,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94009
94010 ieee80211_recalc_ps(local, -1);
94011
94012- if (local->open_count == 0) {
94013+ if (local_read(&local->open_count) == 0) {
94014 ieee80211_stop_device(local);
94015
94016 /* no reconfiguring after stop! */
94017@@ -959,7 +959,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94018 ieee80211_configure_filter(local);
94019 ieee80211_hw_config(local, hw_reconf_flags);
94020
94021- if (local->monitors == local->open_count)
94022+ if (local->monitors == local_read(&local->open_count))
94023 ieee80211_add_virtual_monitor(local);
94024 }
94025
94026diff --git a/net/mac80211/main.c b/net/mac80211/main.c
94027index 091088a..daf43c7 100644
94028--- a/net/mac80211/main.c
94029+++ b/net/mac80211/main.c
94030@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
94031 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
94032 IEEE80211_CONF_CHANGE_POWER);
94033
94034- if (changed && local->open_count) {
94035+ if (changed && local_read(&local->open_count)) {
94036 ret = drv_config(local, changed);
94037 /*
94038 * Goal:
94039diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
94040index 3401262..d5cd68d 100644
94041--- a/net/mac80211/pm.c
94042+++ b/net/mac80211/pm.c
94043@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94044 struct ieee80211_sub_if_data *sdata;
94045 struct sta_info *sta;
94046
94047- if (!local->open_count)
94048+ if (!local_read(&local->open_count))
94049 goto suspend;
94050
94051 ieee80211_scan_cancel(local);
94052@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94053 cancel_work_sync(&local->dynamic_ps_enable_work);
94054 del_timer_sync(&local->dynamic_ps_timer);
94055
94056- local->wowlan = wowlan && local->open_count;
94057+ local->wowlan = wowlan && local_read(&local->open_count);
94058 if (local->wowlan) {
94059 int err = drv_suspend(local, wowlan);
94060 if (err < 0) {
94061@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94062 WARN_ON(!list_empty(&local->chanctx_list));
94063
94064 /* stop hardware - this must stop RX */
94065- if (local->open_count)
94066+ if (local_read(&local->open_count))
94067 ieee80211_stop_device(local);
94068
94069 suspend:
94070diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
94071index 30d58d2..449ac8e 100644
94072--- a/net/mac80211/rate.c
94073+++ b/net/mac80211/rate.c
94074@@ -718,7 +718,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
94075
94076 ASSERT_RTNL();
94077
94078- if (local->open_count)
94079+ if (local_read(&local->open_count))
94080 return -EBUSY;
94081
94082 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
94083diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
94084index c97a065..ff61928 100644
94085--- a/net/mac80211/rc80211_pid_debugfs.c
94086+++ b/net/mac80211/rc80211_pid_debugfs.c
94087@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
94088
94089 spin_unlock_irqrestore(&events->lock, status);
94090
94091- if (copy_to_user(buf, pb, p))
94092+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
94093 return -EFAULT;
94094
94095 return p;
94096diff --git a/net/mac80211/util.c b/net/mac80211/util.c
94097index 2265445..ba14971 100644
94098--- a/net/mac80211/util.c
94099+++ b/net/mac80211/util.c
94100@@ -1452,7 +1452,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
94101 }
94102 #endif
94103 /* everything else happens only if HW was up & running */
94104- if (!local->open_count)
94105+ if (!local_read(&local->open_count))
94106 goto wake_up;
94107
94108 /*
94109@@ -1677,7 +1677,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
94110 local->in_reconfig = false;
94111 barrier();
94112
94113- if (local->monitors == local->open_count && local->monitors > 0)
94114+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
94115 ieee80211_add_virtual_monitor(local);
94116
94117 /*
94118diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
94119index 56d22ca..87c778f 100644
94120--- a/net/netfilter/Kconfig
94121+++ b/net/netfilter/Kconfig
94122@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
94123
94124 To compile it as a module, choose M here. If unsure, say N.
94125
94126+config NETFILTER_XT_MATCH_GRADM
94127+ tristate '"gradm" match support'
94128+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
94129+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
94130+ ---help---
94131+ The gradm match allows to match on grsecurity RBAC being enabled.
94132+ It is useful when iptables rules are applied early on bootup to
94133+ prevent connections to the machine (except from a trusted host)
94134+ while the RBAC system is disabled.
94135+
94136 config NETFILTER_XT_MATCH_HASHLIMIT
94137 tristate '"hashlimit" match support'
94138 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
94139diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
94140index a1abf87..dbcb7ee 100644
94141--- a/net/netfilter/Makefile
94142+++ b/net/netfilter/Makefile
94143@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
94144 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
94145 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
94146 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
94147+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
94148 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
94149 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
94150 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
94151diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
94152index f771390..145b765 100644
94153--- a/net/netfilter/ipset/ip_set_core.c
94154+++ b/net/netfilter/ipset/ip_set_core.c
94155@@ -1820,7 +1820,7 @@ done:
94156 return ret;
94157 }
94158
94159-static struct nf_sockopt_ops so_set __read_mostly = {
94160+static struct nf_sockopt_ops so_set = {
94161 .pf = PF_INET,
94162 .get_optmin = SO_IP_SET,
94163 .get_optmax = SO_IP_SET + 1,
94164diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
94165index 4c8e5c0..5a79b4d 100644
94166--- a/net/netfilter/ipvs/ip_vs_conn.c
94167+++ b/net/netfilter/ipvs/ip_vs_conn.c
94168@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
94169 /* Increase the refcnt counter of the dest */
94170 ip_vs_dest_hold(dest);
94171
94172- conn_flags = atomic_read(&dest->conn_flags);
94173+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
94174 if (cp->protocol != IPPROTO_UDP)
94175 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
94176 flags = cp->flags;
94177@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
94178
94179 cp->control = NULL;
94180 atomic_set(&cp->n_control, 0);
94181- atomic_set(&cp->in_pkts, 0);
94182+ atomic_set_unchecked(&cp->in_pkts, 0);
94183
94184 cp->packet_xmit = NULL;
94185 cp->app = NULL;
94186@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
94187
94188 /* Don't drop the entry if its number of incoming packets is not
94189 located in [0, 8] */
94190- i = atomic_read(&cp->in_pkts);
94191+ i = atomic_read_unchecked(&cp->in_pkts);
94192 if (i > 8 || i < 0) return 0;
94193
94194 if (!todrop_rate[i]) return 0;
94195diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
94196index 4f69e83..da2d8bf 100644
94197--- a/net/netfilter/ipvs/ip_vs_core.c
94198+++ b/net/netfilter/ipvs/ip_vs_core.c
94199@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
94200 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
94201 /* do not touch skb anymore */
94202
94203- atomic_inc(&cp->in_pkts);
94204+ atomic_inc_unchecked(&cp->in_pkts);
94205 ip_vs_conn_put(cp);
94206 return ret;
94207 }
94208@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
94209 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
94210 pkts = sysctl_sync_threshold(ipvs);
94211 else
94212- pkts = atomic_add_return(1, &cp->in_pkts);
94213+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94214
94215 if (ipvs->sync_state & IP_VS_STATE_MASTER)
94216 ip_vs_sync_conn(net, cp, pkts);
94217diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
94218index c8148e4..eff604f 100644
94219--- a/net/netfilter/ipvs/ip_vs_ctl.c
94220+++ b/net/netfilter/ipvs/ip_vs_ctl.c
94221@@ -789,7 +789,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
94222 */
94223 ip_vs_rs_hash(ipvs, dest);
94224 }
94225- atomic_set(&dest->conn_flags, conn_flags);
94226+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
94227
94228 /* bind the service */
94229 if (!dest->svc) {
94230@@ -1657,7 +1657,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
94231 * align with netns init in ip_vs_control_net_init()
94232 */
94233
94234-static struct ctl_table vs_vars[] = {
94235+static ctl_table_no_const vs_vars[] __read_only = {
94236 {
94237 .procname = "amemthresh",
94238 .maxlen = sizeof(int),
94239@@ -2078,7 +2078,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
94240 " %-7s %-6d %-10d %-10d\n",
94241 &dest->addr.in6,
94242 ntohs(dest->port),
94243- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
94244+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
94245 atomic_read(&dest->weight),
94246 atomic_read(&dest->activeconns),
94247 atomic_read(&dest->inactconns));
94248@@ -2089,7 +2089,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
94249 "%-7s %-6d %-10d %-10d\n",
94250 ntohl(dest->addr.ip),
94251 ntohs(dest->port),
94252- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
94253+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
94254 atomic_read(&dest->weight),
94255 atomic_read(&dest->activeconns),
94256 atomic_read(&dest->inactconns));
94257@@ -2567,7 +2567,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
94258
94259 entry.addr = dest->addr.ip;
94260 entry.port = dest->port;
94261- entry.conn_flags = atomic_read(&dest->conn_flags);
94262+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
94263 entry.weight = atomic_read(&dest->weight);
94264 entry.u_threshold = dest->u_threshold;
94265 entry.l_threshold = dest->l_threshold;
94266@@ -3110,7 +3110,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
94267 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
94268 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
94269 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
94270- (atomic_read(&dest->conn_flags) &
94271+ (atomic_read_unchecked(&dest->conn_flags) &
94272 IP_VS_CONN_F_FWD_MASK)) ||
94273 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
94274 atomic_read(&dest->weight)) ||
94275@@ -3700,7 +3700,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
94276 {
94277 int idx;
94278 struct netns_ipvs *ipvs = net_ipvs(net);
94279- struct ctl_table *tbl;
94280+ ctl_table_no_const *tbl;
94281
94282 atomic_set(&ipvs->dropentry, 0);
94283 spin_lock_init(&ipvs->dropentry_lock);
94284diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
94285index 1383b0e..91f68ae 100644
94286--- a/net/netfilter/ipvs/ip_vs_lblc.c
94287+++ b/net/netfilter/ipvs/ip_vs_lblc.c
94288@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
94289 * IPVS LBLC sysctl table
94290 */
94291 #ifdef CONFIG_SYSCTL
94292-static struct ctl_table vs_vars_table[] = {
94293+static struct ctl_table vs_vars_table[] __read_only = {
94294 {
94295 .procname = "lblc_expiration",
94296 .data = NULL,
94297diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
94298index 3cd85b2..b45b17e 100644
94299--- a/net/netfilter/ipvs/ip_vs_lblcr.c
94300+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
94301@@ -299,7 +299,7 @@ struct ip_vs_lblcr_table {
94302 * IPVS LBLCR sysctl table
94303 */
94304
94305-static struct ctl_table vs_vars_table[] = {
94306+static struct ctl_table vs_vars_table[] __read_only = {
94307 {
94308 .procname = "lblcr_expiration",
94309 .data = NULL,
94310diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
94311index f448471..995f131 100644
94312--- a/net/netfilter/ipvs/ip_vs_sync.c
94313+++ b/net/netfilter/ipvs/ip_vs_sync.c
94314@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
94315 cp = cp->control;
94316 if (cp) {
94317 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94318- pkts = atomic_add_return(1, &cp->in_pkts);
94319+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94320 else
94321 pkts = sysctl_sync_threshold(ipvs);
94322 ip_vs_sync_conn(net, cp->control, pkts);
94323@@ -771,7 +771,7 @@ control:
94324 if (!cp)
94325 return;
94326 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94327- pkts = atomic_add_return(1, &cp->in_pkts);
94328+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94329 else
94330 pkts = sysctl_sync_threshold(ipvs);
94331 goto sloop;
94332@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
94333
94334 if (opt)
94335 memcpy(&cp->in_seq, opt, sizeof(*opt));
94336- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94337+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94338 cp->state = state;
94339 cp->old_state = cp->state;
94340 /*
94341diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
94342index b75ff64..0c51bbe 100644
94343--- a/net/netfilter/ipvs/ip_vs_xmit.c
94344+++ b/net/netfilter/ipvs/ip_vs_xmit.c
94345@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
94346 else
94347 rc = NF_ACCEPT;
94348 /* do not touch skb anymore */
94349- atomic_inc(&cp->in_pkts);
94350+ atomic_inc_unchecked(&cp->in_pkts);
94351 goto out;
94352 }
94353
94354@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
94355 else
94356 rc = NF_ACCEPT;
94357 /* do not touch skb anymore */
94358- atomic_inc(&cp->in_pkts);
94359+ atomic_inc_unchecked(&cp->in_pkts);
94360 goto out;
94361 }
94362
94363diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
94364index 2d3030a..7ba1c0a 100644
94365--- a/net/netfilter/nf_conntrack_acct.c
94366+++ b/net/netfilter/nf_conntrack_acct.c
94367@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
94368 #ifdef CONFIG_SYSCTL
94369 static int nf_conntrack_acct_init_sysctl(struct net *net)
94370 {
94371- struct ctl_table *table;
94372+ ctl_table_no_const *table;
94373
94374 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
94375 GFP_KERNEL);
94376diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
94377index 0283bae..5febcb0 100644
94378--- a/net/netfilter/nf_conntrack_core.c
94379+++ b/net/netfilter/nf_conntrack_core.c
94380@@ -1614,6 +1614,10 @@ void nf_conntrack_init_end(void)
94381 #define DYING_NULLS_VAL ((1<<30)+1)
94382 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
94383
94384+#ifdef CONFIG_GRKERNSEC_HIDESYM
94385+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
94386+#endif
94387+
94388 int nf_conntrack_init_net(struct net *net)
94389 {
94390 int ret;
94391@@ -1628,7 +1632,11 @@ int nf_conntrack_init_net(struct net *net)
94392 goto err_stat;
94393 }
94394
94395+#ifdef CONFIG_GRKERNSEC_HIDESYM
94396+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
94397+#else
94398 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
94399+#endif
94400 if (!net->ct.slabname) {
94401 ret = -ENOMEM;
94402 goto err_slabname;
94403diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
94404index 1df1761..ce8b88a 100644
94405--- a/net/netfilter/nf_conntrack_ecache.c
94406+++ b/net/netfilter/nf_conntrack_ecache.c
94407@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
94408 #ifdef CONFIG_SYSCTL
94409 static int nf_conntrack_event_init_sysctl(struct net *net)
94410 {
94411- struct ctl_table *table;
94412+ ctl_table_no_const *table;
94413
94414 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
94415 GFP_KERNEL);
94416diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
94417index 974a2a4..52cc6ff 100644
94418--- a/net/netfilter/nf_conntrack_helper.c
94419+++ b/net/netfilter/nf_conntrack_helper.c
94420@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
94421
94422 static int nf_conntrack_helper_init_sysctl(struct net *net)
94423 {
94424- struct ctl_table *table;
94425+ ctl_table_no_const *table;
94426
94427 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
94428 GFP_KERNEL);
94429diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
94430index 0ab9636..cea3c6a 100644
94431--- a/net/netfilter/nf_conntrack_proto.c
94432+++ b/net/netfilter/nf_conntrack_proto.c
94433@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
94434
94435 static void
94436 nf_ct_unregister_sysctl(struct ctl_table_header **header,
94437- struct ctl_table **table,
94438+ ctl_table_no_const **table,
94439 unsigned int users)
94440 {
94441 if (users > 0)
94442diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
94443index a99b6c3..cb372f9 100644
94444--- a/net/netfilter/nf_conntrack_proto_dccp.c
94445+++ b/net/netfilter/nf_conntrack_proto_dccp.c
94446@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94447 const char *msg;
94448 u_int8_t state;
94449
94450- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94451+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94452 BUG_ON(dh == NULL);
94453
94454 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
94455@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94456 out_invalid:
94457 if (LOG_INVALID(net, IPPROTO_DCCP))
94458 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
94459- NULL, msg);
94460+ NULL, "%s", msg);
94461 return false;
94462 }
94463
94464@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
94465 u_int8_t type, old_state, new_state;
94466 enum ct_dccp_roles role;
94467
94468- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94469+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94470 BUG_ON(dh == NULL);
94471 type = dh->dccph_type;
94472
94473@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94474 unsigned int cscov;
94475 const char *msg;
94476
94477- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94478+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94479 if (dh == NULL) {
94480 msg = "nf_ct_dccp: short packet ";
94481 goto out_invalid;
94482@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94483
94484 out_invalid:
94485 if (LOG_INVALID(net, IPPROTO_DCCP))
94486- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
94487+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
94488 return -NF_ACCEPT;
94489 }
94490
94491diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
94492index f641751..d3c5b51 100644
94493--- a/net/netfilter/nf_conntrack_standalone.c
94494+++ b/net/netfilter/nf_conntrack_standalone.c
94495@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
94496
94497 static int nf_conntrack_standalone_init_sysctl(struct net *net)
94498 {
94499- struct ctl_table *table;
94500+ ctl_table_no_const *table;
94501
94502 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
94503 GFP_KERNEL);
94504diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
94505index 902fb0a..87f7fdb 100644
94506--- a/net/netfilter/nf_conntrack_timestamp.c
94507+++ b/net/netfilter/nf_conntrack_timestamp.c
94508@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
94509 #ifdef CONFIG_SYSCTL
94510 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
94511 {
94512- struct ctl_table *table;
94513+ ctl_table_no_const *table;
94514
94515 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
94516 GFP_KERNEL);
94517diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
94518index 85296d4..8becdec 100644
94519--- a/net/netfilter/nf_log.c
94520+++ b/net/netfilter/nf_log.c
94521@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
94522
94523 #ifdef CONFIG_SYSCTL
94524 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
94525-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
94526+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
94527
94528 static int nf_log_proc_dostring(struct ctl_table *table, int write,
94529 void __user *buffer, size_t *lenp, loff_t *ppos)
94530@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
94531 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
94532 mutex_unlock(&nf_log_mutex);
94533 } else {
94534+ ctl_table_no_const nf_log_table = *table;
94535+
94536 mutex_lock(&nf_log_mutex);
94537 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
94538 lockdep_is_held(&nf_log_mutex));
94539 if (!logger)
94540- table->data = "NONE";
94541+ nf_log_table.data = "NONE";
94542 else
94543- table->data = logger->name;
94544- r = proc_dostring(table, write, buffer, lenp, ppos);
94545+ nf_log_table.data = logger->name;
94546+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
94547 mutex_unlock(&nf_log_mutex);
94548 }
94549
94550diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
94551index f042ae5..30ea486 100644
94552--- a/net/netfilter/nf_sockopt.c
94553+++ b/net/netfilter/nf_sockopt.c
94554@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
94555 }
94556 }
94557
94558- list_add(&reg->list, &nf_sockopts);
94559+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
94560 out:
94561 mutex_unlock(&nf_sockopt_mutex);
94562 return ret;
94563@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
94564 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
94565 {
94566 mutex_lock(&nf_sockopt_mutex);
94567- list_del(&reg->list);
94568+ pax_list_del((struct list_head *)&reg->list);
94569 mutex_unlock(&nf_sockopt_mutex);
94570 }
94571 EXPORT_SYMBOL(nf_unregister_sockopt);
94572diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
94573index d92cc31..e46f350 100644
94574--- a/net/netfilter/nfnetlink_log.c
94575+++ b/net/netfilter/nfnetlink_log.c
94576@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
94577 struct nfnl_log_net {
94578 spinlock_t instances_lock;
94579 struct hlist_head instance_table[INSTANCE_BUCKETS];
94580- atomic_t global_seq;
94581+ atomic_unchecked_t global_seq;
94582 };
94583
94584 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
94585@@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
94586 /* global sequence number */
94587 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
94588 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
94589- htonl(atomic_inc_return(&log->global_seq))))
94590+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
94591 goto nla_put_failure;
94592
94593 if (data_len) {
94594diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
94595new file mode 100644
94596index 0000000..c566332
94597--- /dev/null
94598+++ b/net/netfilter/xt_gradm.c
94599@@ -0,0 +1,51 @@
94600+/*
94601+ * gradm match for netfilter
94602