]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.11.1-201309142343.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.11.1-201309142343.patch
CommitLineData
3bcd5444
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..4c73c9e 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+ unsigned long 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+ unsigned long 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_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
19933index a45d8d4..8abd32c 100644
19934--- a/arch/x86/kernel/cpu/perf_event_intel.c
19935+++ b/arch/x86/kernel/cpu/perf_event_intel.c
19936@@ -2099,10 +2099,10 @@ __init int intel_pmu_init(void)
19937 * v2 and above have a perf capabilities MSR
19938 */
19939 if (version > 1) {
19940- u64 capabilities;
19941+ u64 capabilities = x86_pmu.intel_cap.capabilities;
19942
19943- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
19944- x86_pmu.intel_cap.capabilities = capabilities;
19945+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
19946+ x86_pmu.intel_cap.capabilities = capabilities;
19947 }
19948
19949 intel_ds_init();
19950diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
19951index 1fb6c72..f5fa2a3 100644
19952--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
19953+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
19954@@ -3095,7 +3095,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
19955 static int __init uncore_type_init(struct intel_uncore_type *type)
19956 {
19957 struct intel_uncore_pmu *pmus;
19958- struct attribute_group *attr_group;
19959+ attribute_group_no_const *attr_group;
19960 struct attribute **attrs;
19961 int i, j;
19962
19963diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
19964index 47b3d00c..2cf1751 100644
19965--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
19966+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
19967@@ -488,7 +488,7 @@ struct intel_uncore_box {
19968 struct uncore_event_desc {
19969 struct kobj_attribute attr;
19970 const char *config;
19971-};
19972+} __do_const;
19973
19974 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
19975 { \
19976diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
19977index 7d9481c..99c7e4b 100644
19978--- a/arch/x86/kernel/cpuid.c
19979+++ b/arch/x86/kernel/cpuid.c
19980@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
19981 return notifier_from_errno(err);
19982 }
19983
19984-static struct notifier_block __refdata cpuid_class_cpu_notifier =
19985+static struct notifier_block cpuid_class_cpu_notifier =
19986 {
19987 .notifier_call = cpuid_class_cpu_callback,
19988 };
19989diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
19990index 74467fe..18793d5 100644
19991--- a/arch/x86/kernel/crash.c
19992+++ b/arch/x86/kernel/crash.c
19993@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
19994 {
19995 #ifdef CONFIG_X86_32
19996 struct pt_regs fixed_regs;
19997-#endif
19998
19999-#ifdef CONFIG_X86_32
20000- if (!user_mode_vm(regs)) {
20001+ if (!user_mode(regs)) {
20002 crash_fixup_ss_esp(&fixed_regs, regs);
20003 regs = &fixed_regs;
20004 }
20005diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
20006index afa64ad..dce67dd 100644
20007--- a/arch/x86/kernel/crash_dump_64.c
20008+++ b/arch/x86/kernel/crash_dump_64.c
20009@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
20010 return -ENOMEM;
20011
20012 if (userbuf) {
20013- if (copy_to_user(buf, vaddr + offset, csize)) {
20014+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
20015 iounmap(vaddr);
20016 return -EFAULT;
20017 }
20018diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
20019index 5d3fe8d..02e1429 100644
20020--- a/arch/x86/kernel/doublefault.c
20021+++ b/arch/x86/kernel/doublefault.c
20022@@ -13,7 +13,7 @@
20023
20024 #define DOUBLEFAULT_STACKSIZE (1024)
20025 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
20026-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
20027+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
20028
20029 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
20030
20031@@ -23,7 +23,7 @@ static void doublefault_fn(void)
20032 unsigned long gdt, tss;
20033
20034 native_store_gdt(&gdt_desc);
20035- gdt = gdt_desc.address;
20036+ gdt = (unsigned long)gdt_desc.address;
20037
20038 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
20039
20040@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
20041 /* 0x2 bit is always set */
20042 .flags = X86_EFLAGS_SF | 0x2,
20043 .sp = STACK_START,
20044- .es = __USER_DS,
20045+ .es = __KERNEL_DS,
20046 .cs = __KERNEL_CS,
20047 .ss = __KERNEL_DS,
20048- .ds = __USER_DS,
20049+ .ds = __KERNEL_DS,
20050 .fs = __KERNEL_PERCPU,
20051
20052 .__cr3 = __pa_nodebug(swapper_pg_dir),
20053diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
20054index deb6421..76bbc12 100644
20055--- a/arch/x86/kernel/dumpstack.c
20056+++ b/arch/x86/kernel/dumpstack.c
20057@@ -2,6 +2,9 @@
20058 * Copyright (C) 1991, 1992 Linus Torvalds
20059 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
20060 */
20061+#ifdef CONFIG_GRKERNSEC_HIDESYM
20062+#define __INCLUDED_BY_HIDESYM 1
20063+#endif
20064 #include <linux/kallsyms.h>
20065 #include <linux/kprobes.h>
20066 #include <linux/uaccess.h>
20067@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
20068 static void
20069 print_ftrace_graph_addr(unsigned long addr, void *data,
20070 const struct stacktrace_ops *ops,
20071- struct thread_info *tinfo, int *graph)
20072+ struct task_struct *task, int *graph)
20073 {
20074- struct task_struct *task;
20075 unsigned long ret_addr;
20076 int index;
20077
20078 if (addr != (unsigned long)return_to_handler)
20079 return;
20080
20081- task = tinfo->task;
20082 index = task->curr_ret_stack;
20083
20084 if (!task->ret_stack || index < *graph)
20085@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20086 static inline void
20087 print_ftrace_graph_addr(unsigned long addr, void *data,
20088 const struct stacktrace_ops *ops,
20089- struct thread_info *tinfo, int *graph)
20090+ struct task_struct *task, int *graph)
20091 { }
20092 #endif
20093
20094@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20095 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
20096 */
20097
20098-static inline int valid_stack_ptr(struct thread_info *tinfo,
20099- void *p, unsigned int size, void *end)
20100+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
20101 {
20102- void *t = tinfo;
20103 if (end) {
20104 if (p < end && p >= (end-THREAD_SIZE))
20105 return 1;
20106@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
20107 }
20108
20109 unsigned long
20110-print_context_stack(struct thread_info *tinfo,
20111+print_context_stack(struct task_struct *task, void *stack_start,
20112 unsigned long *stack, unsigned long bp,
20113 const struct stacktrace_ops *ops, void *data,
20114 unsigned long *end, int *graph)
20115 {
20116 struct stack_frame *frame = (struct stack_frame *)bp;
20117
20118- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
20119+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
20120 unsigned long addr;
20121
20122 addr = *stack;
20123@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
20124 } else {
20125 ops->address(data, addr, 0);
20126 }
20127- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20128+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20129 }
20130 stack++;
20131 }
20132@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
20133 EXPORT_SYMBOL_GPL(print_context_stack);
20134
20135 unsigned long
20136-print_context_stack_bp(struct thread_info *tinfo,
20137+print_context_stack_bp(struct task_struct *task, void *stack_start,
20138 unsigned long *stack, unsigned long bp,
20139 const struct stacktrace_ops *ops, void *data,
20140 unsigned long *end, int *graph)
20141@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20142 struct stack_frame *frame = (struct stack_frame *)bp;
20143 unsigned long *ret_addr = &frame->return_address;
20144
20145- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
20146+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
20147 unsigned long addr = *ret_addr;
20148
20149 if (!__kernel_text_address(addr))
20150@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20151 ops->address(data, addr, 1);
20152 frame = frame->next_frame;
20153 ret_addr = &frame->return_address;
20154- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20155+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20156 }
20157
20158 return (unsigned long)frame;
20159@@ -150,7 +149,7 @@ static int print_trace_stack(void *data, char *name)
20160 static void print_trace_address(void *data, unsigned long addr, int reliable)
20161 {
20162 touch_nmi_watchdog();
20163- printk(data);
20164+ printk("%s", (char *)data);
20165 printk_address(addr, reliable);
20166 }
20167
20168@@ -219,6 +218,8 @@ unsigned __kprobes long oops_begin(void)
20169 }
20170 EXPORT_SYMBOL_GPL(oops_begin);
20171
20172+extern void gr_handle_kernel_exploit(void);
20173+
20174 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20175 {
20176 if (regs && kexec_should_crash(current))
20177@@ -240,7 +241,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20178 panic("Fatal exception in interrupt");
20179 if (panic_on_oops)
20180 panic("Fatal exception");
20181- do_exit(signr);
20182+
20183+ gr_handle_kernel_exploit();
20184+
20185+ do_group_exit(signr);
20186 }
20187
20188 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20189@@ -268,7 +272,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20190 print_modules();
20191 show_regs(regs);
20192 #ifdef CONFIG_X86_32
20193- if (user_mode_vm(regs)) {
20194+ if (user_mode(regs)) {
20195 sp = regs->sp;
20196 ss = regs->ss & 0xffff;
20197 } else {
20198@@ -296,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
20199 unsigned long flags = oops_begin();
20200 int sig = SIGSEGV;
20201
20202- if (!user_mode_vm(regs))
20203+ if (!user_mode(regs))
20204 report_bug(regs->ip, regs);
20205
20206 if (__die(str, regs, err))
20207diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
20208index f2a1770..540657f 100644
20209--- a/arch/x86/kernel/dumpstack_32.c
20210+++ b/arch/x86/kernel/dumpstack_32.c
20211@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20212 bp = stack_frame(task, regs);
20213
20214 for (;;) {
20215- struct thread_info *context;
20216+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20217
20218- context = (struct thread_info *)
20219- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
20220- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
20221+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20222
20223- stack = (unsigned long *)context->previous_esp;
20224- if (!stack)
20225+ if (stack_start == task_stack_page(task))
20226 break;
20227+ stack = *(unsigned long **)stack_start;
20228 if (ops->stack(data, "IRQ") < 0)
20229 break;
20230 touch_nmi_watchdog();
20231@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
20232 int i;
20233
20234 show_regs_print_info(KERN_EMERG);
20235- __show_regs(regs, !user_mode_vm(regs));
20236+ __show_regs(regs, !user_mode(regs));
20237
20238 /*
20239 * When in-kernel, we also print out the stack and code at the
20240 * time of the fault..
20241 */
20242- if (!user_mode_vm(regs)) {
20243+ if (!user_mode(regs)) {
20244 unsigned int code_prologue = code_bytes * 43 / 64;
20245 unsigned int code_len = code_bytes;
20246 unsigned char c;
20247 u8 *ip;
20248+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
20249
20250 pr_emerg("Stack:\n");
20251 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
20252
20253 pr_emerg("Code:");
20254
20255- ip = (u8 *)regs->ip - code_prologue;
20256+ ip = (u8 *)regs->ip - code_prologue + cs_base;
20257 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
20258 /* try starting at IP */
20259- ip = (u8 *)regs->ip;
20260+ ip = (u8 *)regs->ip + cs_base;
20261 code_len = code_len - code_prologue + 1;
20262 }
20263 for (i = 0; i < code_len; i++, ip++) {
20264@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
20265 pr_cont(" Bad EIP value.");
20266 break;
20267 }
20268- if (ip == (u8 *)regs->ip)
20269+ if (ip == (u8 *)regs->ip + cs_base)
20270 pr_cont(" <%02x>", c);
20271 else
20272 pr_cont(" %02x", c);
20273@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
20274 {
20275 unsigned short ud2;
20276
20277+ ip = ktla_ktva(ip);
20278 if (ip < PAGE_OFFSET)
20279 return 0;
20280 if (probe_kernel_address((unsigned short *)ip, ud2))
20281@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
20282
20283 return ud2 == 0x0b0f;
20284 }
20285+
20286+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20287+void pax_check_alloca(unsigned long size)
20288+{
20289+ unsigned long sp = (unsigned long)&sp, stack_left;
20290+
20291+ /* all kernel stacks are of the same size */
20292+ stack_left = sp & (THREAD_SIZE - 1);
20293+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20294+}
20295+EXPORT_SYMBOL(pax_check_alloca);
20296+#endif
20297diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
20298index addb207..99635fa 100644
20299--- a/arch/x86/kernel/dumpstack_64.c
20300+++ b/arch/x86/kernel/dumpstack_64.c
20301@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20302 unsigned long *irq_stack_end =
20303 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
20304 unsigned used = 0;
20305- struct thread_info *tinfo;
20306 int graph = 0;
20307 unsigned long dummy;
20308+ void *stack_start;
20309
20310 if (!task)
20311 task = current;
20312@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20313 * current stack address. If the stacks consist of nested
20314 * exceptions
20315 */
20316- tinfo = task_thread_info(task);
20317 for (;;) {
20318 char *id;
20319 unsigned long *estack_end;
20320+
20321 estack_end = in_exception_stack(cpu, (unsigned long)stack,
20322 &used, &id);
20323
20324@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20325 if (ops->stack(data, id) < 0)
20326 break;
20327
20328- bp = ops->walk_stack(tinfo, stack, bp, ops,
20329+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
20330 data, estack_end, &graph);
20331 ops->stack(data, "<EOE>");
20332 /*
20333@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20334 * second-to-last pointer (index -2 to end) in the
20335 * exception stack:
20336 */
20337+ if ((u16)estack_end[-1] != __KERNEL_DS)
20338+ goto out;
20339 stack = (unsigned long *) estack_end[-2];
20340 continue;
20341 }
20342@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20343 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
20344 if (ops->stack(data, "IRQ") < 0)
20345 break;
20346- bp = ops->walk_stack(tinfo, stack, bp,
20347+ bp = ops->walk_stack(task, irq_stack, stack, bp,
20348 ops, data, irq_stack_end, &graph);
20349 /*
20350 * We link to the next stack (which would be
20351@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20352 /*
20353 * This handles the process stack:
20354 */
20355- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
20356+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20357+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20358+out:
20359 put_cpu();
20360 }
20361 EXPORT_SYMBOL(dump_trace);
20362@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
20363
20364 return ud2 == 0x0b0f;
20365 }
20366+
20367+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20368+void pax_check_alloca(unsigned long size)
20369+{
20370+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
20371+ unsigned cpu, used;
20372+ char *id;
20373+
20374+ /* check the process stack first */
20375+ stack_start = (unsigned long)task_stack_page(current);
20376+ stack_end = stack_start + THREAD_SIZE;
20377+ if (likely(stack_start <= sp && sp < stack_end)) {
20378+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
20379+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20380+ return;
20381+ }
20382+
20383+ cpu = get_cpu();
20384+
20385+ /* check the irq stacks */
20386+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
20387+ stack_start = stack_end - IRQ_STACK_SIZE;
20388+ if (stack_start <= sp && sp < stack_end) {
20389+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
20390+ put_cpu();
20391+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20392+ return;
20393+ }
20394+
20395+ /* check the exception stacks */
20396+ used = 0;
20397+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
20398+ stack_start = stack_end - EXCEPTION_STKSZ;
20399+ if (stack_end && stack_start <= sp && sp < stack_end) {
20400+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
20401+ put_cpu();
20402+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20403+ return;
20404+ }
20405+
20406+ put_cpu();
20407+
20408+ /* unknown stack */
20409+ BUG();
20410+}
20411+EXPORT_SYMBOL(pax_check_alloca);
20412+#endif
20413diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
20414index d32abea..74daf4f 100644
20415--- a/arch/x86/kernel/e820.c
20416+++ b/arch/x86/kernel/e820.c
20417@@ -800,8 +800,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
20418
20419 static void early_panic(char *msg)
20420 {
20421- early_printk(msg);
20422- panic(msg);
20423+ early_printk("%s", msg);
20424+ panic("%s", msg);
20425 }
20426
20427 static int userdef __initdata;
20428diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
20429index d15f575..d692043 100644
20430--- a/arch/x86/kernel/early_printk.c
20431+++ b/arch/x86/kernel/early_printk.c
20432@@ -7,6 +7,7 @@
20433 #include <linux/pci_regs.h>
20434 #include <linux/pci_ids.h>
20435 #include <linux/errno.h>
20436+#include <linux/sched.h>
20437 #include <asm/io.h>
20438 #include <asm/processor.h>
20439 #include <asm/fcntl.h>
20440diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
20441index 2cfbc3a..b756682 100644
20442--- a/arch/x86/kernel/entry_32.S
20443+++ b/arch/x86/kernel/entry_32.S
20444@@ -177,13 +177,153 @@
20445 /*CFI_REL_OFFSET gs, PT_GS*/
20446 .endm
20447 .macro SET_KERNEL_GS reg
20448+
20449+#ifdef CONFIG_CC_STACKPROTECTOR
20450 movl $(__KERNEL_STACK_CANARY), \reg
20451+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20452+ movl $(__USER_DS), \reg
20453+#else
20454+ xorl \reg, \reg
20455+#endif
20456+
20457 movl \reg, %gs
20458 .endm
20459
20460 #endif /* CONFIG_X86_32_LAZY_GS */
20461
20462-.macro SAVE_ALL
20463+.macro pax_enter_kernel
20464+#ifdef CONFIG_PAX_KERNEXEC
20465+ call pax_enter_kernel
20466+#endif
20467+.endm
20468+
20469+.macro pax_exit_kernel
20470+#ifdef CONFIG_PAX_KERNEXEC
20471+ call pax_exit_kernel
20472+#endif
20473+.endm
20474+
20475+#ifdef CONFIG_PAX_KERNEXEC
20476+ENTRY(pax_enter_kernel)
20477+#ifdef CONFIG_PARAVIRT
20478+ pushl %eax
20479+ pushl %ecx
20480+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
20481+ mov %eax, %esi
20482+#else
20483+ mov %cr0, %esi
20484+#endif
20485+ bts $16, %esi
20486+ jnc 1f
20487+ mov %cs, %esi
20488+ cmp $__KERNEL_CS, %esi
20489+ jz 3f
20490+ ljmp $__KERNEL_CS, $3f
20491+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
20492+2:
20493+#ifdef CONFIG_PARAVIRT
20494+ mov %esi, %eax
20495+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
20496+#else
20497+ mov %esi, %cr0
20498+#endif
20499+3:
20500+#ifdef CONFIG_PARAVIRT
20501+ popl %ecx
20502+ popl %eax
20503+#endif
20504+ ret
20505+ENDPROC(pax_enter_kernel)
20506+
20507+ENTRY(pax_exit_kernel)
20508+#ifdef CONFIG_PARAVIRT
20509+ pushl %eax
20510+ pushl %ecx
20511+#endif
20512+ mov %cs, %esi
20513+ cmp $__KERNEXEC_KERNEL_CS, %esi
20514+ jnz 2f
20515+#ifdef CONFIG_PARAVIRT
20516+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
20517+ mov %eax, %esi
20518+#else
20519+ mov %cr0, %esi
20520+#endif
20521+ btr $16, %esi
20522+ ljmp $__KERNEL_CS, $1f
20523+1:
20524+#ifdef CONFIG_PARAVIRT
20525+ mov %esi, %eax
20526+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
20527+#else
20528+ mov %esi, %cr0
20529+#endif
20530+2:
20531+#ifdef CONFIG_PARAVIRT
20532+ popl %ecx
20533+ popl %eax
20534+#endif
20535+ ret
20536+ENDPROC(pax_exit_kernel)
20537+#endif
20538+
20539+ .macro pax_erase_kstack
20540+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20541+ call pax_erase_kstack
20542+#endif
20543+ .endm
20544+
20545+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20546+/*
20547+ * ebp: thread_info
20548+ */
20549+ENTRY(pax_erase_kstack)
20550+ pushl %edi
20551+ pushl %ecx
20552+ pushl %eax
20553+
20554+ mov TI_lowest_stack(%ebp), %edi
20555+ mov $-0xBEEF, %eax
20556+ std
20557+
20558+1: mov %edi, %ecx
20559+ and $THREAD_SIZE_asm - 1, %ecx
20560+ shr $2, %ecx
20561+ repne scasl
20562+ jecxz 2f
20563+
20564+ cmp $2*16, %ecx
20565+ jc 2f
20566+
20567+ mov $2*16, %ecx
20568+ repe scasl
20569+ jecxz 2f
20570+ jne 1b
20571+
20572+2: cld
20573+ mov %esp, %ecx
20574+ sub %edi, %ecx
20575+
20576+ cmp $THREAD_SIZE_asm, %ecx
20577+ jb 3f
20578+ ud2
20579+3:
20580+
20581+ shr $2, %ecx
20582+ rep stosl
20583+
20584+ mov TI_task_thread_sp0(%ebp), %edi
20585+ sub $128, %edi
20586+ mov %edi, TI_lowest_stack(%ebp)
20587+
20588+ popl %eax
20589+ popl %ecx
20590+ popl %edi
20591+ ret
20592+ENDPROC(pax_erase_kstack)
20593+#endif
20594+
20595+.macro __SAVE_ALL _DS
20596 cld
20597 PUSH_GS
20598 pushl_cfi %fs
20599@@ -206,7 +346,7 @@
20600 CFI_REL_OFFSET ecx, 0
20601 pushl_cfi %ebx
20602 CFI_REL_OFFSET ebx, 0
20603- movl $(__USER_DS), %edx
20604+ movl $\_DS, %edx
20605 movl %edx, %ds
20606 movl %edx, %es
20607 movl $(__KERNEL_PERCPU), %edx
20608@@ -214,6 +354,15 @@
20609 SET_KERNEL_GS %edx
20610 .endm
20611
20612+.macro SAVE_ALL
20613+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20614+ __SAVE_ALL __KERNEL_DS
20615+ pax_enter_kernel
20616+#else
20617+ __SAVE_ALL __USER_DS
20618+#endif
20619+.endm
20620+
20621 .macro RESTORE_INT_REGS
20622 popl_cfi %ebx
20623 CFI_RESTORE ebx
20624@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
20625 popfl_cfi
20626 jmp syscall_exit
20627 CFI_ENDPROC
20628-END(ret_from_fork)
20629+ENDPROC(ret_from_fork)
20630
20631 ENTRY(ret_from_kernel_thread)
20632 CFI_STARTPROC
20633@@ -344,7 +493,15 @@ ret_from_intr:
20634 andl $SEGMENT_RPL_MASK, %eax
20635 #endif
20636 cmpl $USER_RPL, %eax
20637+
20638+#ifdef CONFIG_PAX_KERNEXEC
20639+ jae resume_userspace
20640+
20641+ pax_exit_kernel
20642+ jmp resume_kernel
20643+#else
20644 jb resume_kernel # not returning to v8086 or userspace
20645+#endif
20646
20647 ENTRY(resume_userspace)
20648 LOCKDEP_SYS_EXIT
20649@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
20650 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
20651 # int/exception return?
20652 jne work_pending
20653- jmp restore_all
20654-END(ret_from_exception)
20655+ jmp restore_all_pax
20656+ENDPROC(ret_from_exception)
20657
20658 #ifdef CONFIG_PREEMPT
20659 ENTRY(resume_kernel)
20660@@ -372,7 +529,7 @@ need_resched:
20661 jz restore_all
20662 call preempt_schedule_irq
20663 jmp need_resched
20664-END(resume_kernel)
20665+ENDPROC(resume_kernel)
20666 #endif
20667 CFI_ENDPROC
20668 /*
20669@@ -406,30 +563,45 @@ sysenter_past_esp:
20670 /*CFI_REL_OFFSET cs, 0*/
20671 /*
20672 * Push current_thread_info()->sysenter_return to the stack.
20673- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
20674- * pushed above; +8 corresponds to copy_thread's esp0 setting.
20675 */
20676- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
20677+ pushl_cfi $0
20678 CFI_REL_OFFSET eip, 0
20679
20680 pushl_cfi %eax
20681 SAVE_ALL
20682+ GET_THREAD_INFO(%ebp)
20683+ movl TI_sysenter_return(%ebp),%ebp
20684+ movl %ebp,PT_EIP(%esp)
20685 ENABLE_INTERRUPTS(CLBR_NONE)
20686
20687 /*
20688 * Load the potential sixth argument from user stack.
20689 * Careful about security.
20690 */
20691+ movl PT_OLDESP(%esp),%ebp
20692+
20693+#ifdef CONFIG_PAX_MEMORY_UDEREF
20694+ mov PT_OLDSS(%esp),%ds
20695+1: movl %ds:(%ebp),%ebp
20696+ push %ss
20697+ pop %ds
20698+#else
20699 cmpl $__PAGE_OFFSET-3,%ebp
20700 jae syscall_fault
20701 ASM_STAC
20702 1: movl (%ebp),%ebp
20703 ASM_CLAC
20704+#endif
20705+
20706 movl %ebp,PT_EBP(%esp)
20707 _ASM_EXTABLE(1b,syscall_fault)
20708
20709 GET_THREAD_INFO(%ebp)
20710
20711+#ifdef CONFIG_PAX_RANDKSTACK
20712+ pax_erase_kstack
20713+#endif
20714+
20715 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20716 jnz sysenter_audit
20717 sysenter_do_call:
20718@@ -444,12 +616,24 @@ sysenter_do_call:
20719 testl $_TIF_ALLWORK_MASK, %ecx
20720 jne sysexit_audit
20721 sysenter_exit:
20722+
20723+#ifdef CONFIG_PAX_RANDKSTACK
20724+ pushl_cfi %eax
20725+ movl %esp, %eax
20726+ call pax_randomize_kstack
20727+ popl_cfi %eax
20728+#endif
20729+
20730+ pax_erase_kstack
20731+
20732 /* if something modifies registers it must also disable sysexit */
20733 movl PT_EIP(%esp), %edx
20734 movl PT_OLDESP(%esp), %ecx
20735 xorl %ebp,%ebp
20736 TRACE_IRQS_ON
20737 1: mov PT_FS(%esp), %fs
20738+2: mov PT_DS(%esp), %ds
20739+3: mov PT_ES(%esp), %es
20740 PTGS_TO_GS
20741 ENABLE_INTERRUPTS_SYSEXIT
20742
20743@@ -466,6 +650,9 @@ sysenter_audit:
20744 movl %eax,%edx /* 2nd arg: syscall number */
20745 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
20746 call __audit_syscall_entry
20747+
20748+ pax_erase_kstack
20749+
20750 pushl_cfi %ebx
20751 movl PT_EAX(%esp),%eax /* reload syscall number */
20752 jmp sysenter_do_call
20753@@ -491,10 +678,16 @@ sysexit_audit:
20754
20755 CFI_ENDPROC
20756 .pushsection .fixup,"ax"
20757-2: movl $0,PT_FS(%esp)
20758+4: movl $0,PT_FS(%esp)
20759+ jmp 1b
20760+5: movl $0,PT_DS(%esp)
20761+ jmp 1b
20762+6: movl $0,PT_ES(%esp)
20763 jmp 1b
20764 .popsection
20765- _ASM_EXTABLE(1b,2b)
20766+ _ASM_EXTABLE(1b,4b)
20767+ _ASM_EXTABLE(2b,5b)
20768+ _ASM_EXTABLE(3b,6b)
20769 PTGS_TO_GS_EX
20770 ENDPROC(ia32_sysenter_target)
20771
20772@@ -509,6 +702,11 @@ ENTRY(system_call)
20773 pushl_cfi %eax # save orig_eax
20774 SAVE_ALL
20775 GET_THREAD_INFO(%ebp)
20776+
20777+#ifdef CONFIG_PAX_RANDKSTACK
20778+ pax_erase_kstack
20779+#endif
20780+
20781 # system call tracing in operation / emulation
20782 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20783 jnz syscall_trace_entry
20784@@ -527,6 +725,15 @@ syscall_exit:
20785 testl $_TIF_ALLWORK_MASK, %ecx # current->work
20786 jne syscall_exit_work
20787
20788+restore_all_pax:
20789+
20790+#ifdef CONFIG_PAX_RANDKSTACK
20791+ movl %esp, %eax
20792+ call pax_randomize_kstack
20793+#endif
20794+
20795+ pax_erase_kstack
20796+
20797 restore_all:
20798 TRACE_IRQS_IRET
20799 restore_all_notrace:
20800@@ -583,14 +790,34 @@ ldt_ss:
20801 * compensating for the offset by changing to the ESPFIX segment with
20802 * a base address that matches for the difference.
20803 */
20804-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
20805+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
20806 mov %esp, %edx /* load kernel esp */
20807 mov PT_OLDESP(%esp), %eax /* load userspace esp */
20808 mov %dx, %ax /* eax: new kernel esp */
20809 sub %eax, %edx /* offset (low word is 0) */
20810+#ifdef CONFIG_SMP
20811+ movl PER_CPU_VAR(cpu_number), %ebx
20812+ shll $PAGE_SHIFT_asm, %ebx
20813+ addl $cpu_gdt_table, %ebx
20814+#else
20815+ movl $cpu_gdt_table, %ebx
20816+#endif
20817 shr $16, %edx
20818- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
20819- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
20820+
20821+#ifdef CONFIG_PAX_KERNEXEC
20822+ mov %cr0, %esi
20823+ btr $16, %esi
20824+ mov %esi, %cr0
20825+#endif
20826+
20827+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
20828+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
20829+
20830+#ifdef CONFIG_PAX_KERNEXEC
20831+ bts $16, %esi
20832+ mov %esi, %cr0
20833+#endif
20834+
20835 pushl_cfi $__ESPFIX_SS
20836 pushl_cfi %eax /* new kernel esp */
20837 /* Disable interrupts, but do not irqtrace this section: we
20838@@ -619,20 +846,18 @@ work_resched:
20839 movl TI_flags(%ebp), %ecx
20840 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
20841 # than syscall tracing?
20842- jz restore_all
20843+ jz restore_all_pax
20844 testb $_TIF_NEED_RESCHED, %cl
20845 jnz work_resched
20846
20847 work_notifysig: # deal with pending signals and
20848 # notify-resume requests
20849+ movl %esp, %eax
20850 #ifdef CONFIG_VM86
20851 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
20852- movl %esp, %eax
20853 jne work_notifysig_v86 # returning to kernel-space or
20854 # vm86-space
20855 1:
20856-#else
20857- movl %esp, %eax
20858 #endif
20859 TRACE_IRQS_ON
20860 ENABLE_INTERRUPTS(CLBR_NONE)
20861@@ -653,7 +878,7 @@ work_notifysig_v86:
20862 movl %eax, %esp
20863 jmp 1b
20864 #endif
20865-END(work_pending)
20866+ENDPROC(work_pending)
20867
20868 # perform syscall exit tracing
20869 ALIGN
20870@@ -661,11 +886,14 @@ syscall_trace_entry:
20871 movl $-ENOSYS,PT_EAX(%esp)
20872 movl %esp, %eax
20873 call syscall_trace_enter
20874+
20875+ pax_erase_kstack
20876+
20877 /* What it returned is what we'll actually use. */
20878 cmpl $(NR_syscalls), %eax
20879 jnae syscall_call
20880 jmp syscall_exit
20881-END(syscall_trace_entry)
20882+ENDPROC(syscall_trace_entry)
20883
20884 # perform syscall exit tracing
20885 ALIGN
20886@@ -678,21 +906,25 @@ syscall_exit_work:
20887 movl %esp, %eax
20888 call syscall_trace_leave
20889 jmp resume_userspace
20890-END(syscall_exit_work)
20891+ENDPROC(syscall_exit_work)
20892 CFI_ENDPROC
20893
20894 RING0_INT_FRAME # can't unwind into user space anyway
20895 syscall_fault:
20896+#ifdef CONFIG_PAX_MEMORY_UDEREF
20897+ push %ss
20898+ pop %ds
20899+#endif
20900 ASM_CLAC
20901 GET_THREAD_INFO(%ebp)
20902 movl $-EFAULT,PT_EAX(%esp)
20903 jmp resume_userspace
20904-END(syscall_fault)
20905+ENDPROC(syscall_fault)
20906
20907 syscall_badsys:
20908 movl $-ENOSYS,PT_EAX(%esp)
20909 jmp resume_userspace
20910-END(syscall_badsys)
20911+ENDPROC(syscall_badsys)
20912 CFI_ENDPROC
20913 /*
20914 * End of kprobes section
20915@@ -708,8 +940,15 @@ END(syscall_badsys)
20916 * normal stack and adjusts ESP with the matching offset.
20917 */
20918 /* fixup the stack */
20919- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
20920- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
20921+#ifdef CONFIG_SMP
20922+ movl PER_CPU_VAR(cpu_number), %ebx
20923+ shll $PAGE_SHIFT_asm, %ebx
20924+ addl $cpu_gdt_table, %ebx
20925+#else
20926+ movl $cpu_gdt_table, %ebx
20927+#endif
20928+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
20929+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
20930 shl $16, %eax
20931 addl %esp, %eax /* the adjusted stack pointer */
20932 pushl_cfi $__KERNEL_DS
20933@@ -762,7 +1001,7 @@ vector=vector+1
20934 .endr
20935 2: jmp common_interrupt
20936 .endr
20937-END(irq_entries_start)
20938+ENDPROC(irq_entries_start)
20939
20940 .previous
20941 END(interrupt)
20942@@ -823,7 +1062,7 @@ ENTRY(coprocessor_error)
20943 pushl_cfi $do_coprocessor_error
20944 jmp error_code
20945 CFI_ENDPROC
20946-END(coprocessor_error)
20947+ENDPROC(coprocessor_error)
20948
20949 ENTRY(simd_coprocessor_error)
20950 RING0_INT_FRAME
20951@@ -836,7 +1075,7 @@ ENTRY(simd_coprocessor_error)
20952 .section .altinstructions,"a"
20953 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
20954 .previous
20955-.section .altinstr_replacement,"ax"
20956+.section .altinstr_replacement,"a"
20957 663: pushl $do_simd_coprocessor_error
20958 664:
20959 .previous
20960@@ -845,7 +1084,7 @@ ENTRY(simd_coprocessor_error)
20961 #endif
20962 jmp error_code
20963 CFI_ENDPROC
20964-END(simd_coprocessor_error)
20965+ENDPROC(simd_coprocessor_error)
20966
20967 ENTRY(device_not_available)
20968 RING0_INT_FRAME
20969@@ -854,18 +1093,18 @@ ENTRY(device_not_available)
20970 pushl_cfi $do_device_not_available
20971 jmp error_code
20972 CFI_ENDPROC
20973-END(device_not_available)
20974+ENDPROC(device_not_available)
20975
20976 #ifdef CONFIG_PARAVIRT
20977 ENTRY(native_iret)
20978 iret
20979 _ASM_EXTABLE(native_iret, iret_exc)
20980-END(native_iret)
20981+ENDPROC(native_iret)
20982
20983 ENTRY(native_irq_enable_sysexit)
20984 sti
20985 sysexit
20986-END(native_irq_enable_sysexit)
20987+ENDPROC(native_irq_enable_sysexit)
20988 #endif
20989
20990 ENTRY(overflow)
20991@@ -875,7 +1114,7 @@ ENTRY(overflow)
20992 pushl_cfi $do_overflow
20993 jmp error_code
20994 CFI_ENDPROC
20995-END(overflow)
20996+ENDPROC(overflow)
20997
20998 ENTRY(bounds)
20999 RING0_INT_FRAME
21000@@ -884,7 +1123,7 @@ ENTRY(bounds)
21001 pushl_cfi $do_bounds
21002 jmp error_code
21003 CFI_ENDPROC
21004-END(bounds)
21005+ENDPROC(bounds)
21006
21007 ENTRY(invalid_op)
21008 RING0_INT_FRAME
21009@@ -893,7 +1132,7 @@ ENTRY(invalid_op)
21010 pushl_cfi $do_invalid_op
21011 jmp error_code
21012 CFI_ENDPROC
21013-END(invalid_op)
21014+ENDPROC(invalid_op)
21015
21016 ENTRY(coprocessor_segment_overrun)
21017 RING0_INT_FRAME
21018@@ -902,7 +1141,7 @@ ENTRY(coprocessor_segment_overrun)
21019 pushl_cfi $do_coprocessor_segment_overrun
21020 jmp error_code
21021 CFI_ENDPROC
21022-END(coprocessor_segment_overrun)
21023+ENDPROC(coprocessor_segment_overrun)
21024
21025 ENTRY(invalid_TSS)
21026 RING0_EC_FRAME
21027@@ -910,7 +1149,7 @@ ENTRY(invalid_TSS)
21028 pushl_cfi $do_invalid_TSS
21029 jmp error_code
21030 CFI_ENDPROC
21031-END(invalid_TSS)
21032+ENDPROC(invalid_TSS)
21033
21034 ENTRY(segment_not_present)
21035 RING0_EC_FRAME
21036@@ -918,7 +1157,7 @@ ENTRY(segment_not_present)
21037 pushl_cfi $do_segment_not_present
21038 jmp error_code
21039 CFI_ENDPROC
21040-END(segment_not_present)
21041+ENDPROC(segment_not_present)
21042
21043 ENTRY(stack_segment)
21044 RING0_EC_FRAME
21045@@ -926,7 +1165,7 @@ ENTRY(stack_segment)
21046 pushl_cfi $do_stack_segment
21047 jmp error_code
21048 CFI_ENDPROC
21049-END(stack_segment)
21050+ENDPROC(stack_segment)
21051
21052 ENTRY(alignment_check)
21053 RING0_EC_FRAME
21054@@ -934,7 +1173,7 @@ ENTRY(alignment_check)
21055 pushl_cfi $do_alignment_check
21056 jmp error_code
21057 CFI_ENDPROC
21058-END(alignment_check)
21059+ENDPROC(alignment_check)
21060
21061 ENTRY(divide_error)
21062 RING0_INT_FRAME
21063@@ -943,7 +1182,7 @@ ENTRY(divide_error)
21064 pushl_cfi $do_divide_error
21065 jmp error_code
21066 CFI_ENDPROC
21067-END(divide_error)
21068+ENDPROC(divide_error)
21069
21070 #ifdef CONFIG_X86_MCE
21071 ENTRY(machine_check)
21072@@ -953,7 +1192,7 @@ ENTRY(machine_check)
21073 pushl_cfi machine_check_vector
21074 jmp error_code
21075 CFI_ENDPROC
21076-END(machine_check)
21077+ENDPROC(machine_check)
21078 #endif
21079
21080 ENTRY(spurious_interrupt_bug)
21081@@ -963,7 +1202,7 @@ ENTRY(spurious_interrupt_bug)
21082 pushl_cfi $do_spurious_interrupt_bug
21083 jmp error_code
21084 CFI_ENDPROC
21085-END(spurious_interrupt_bug)
21086+ENDPROC(spurious_interrupt_bug)
21087 /*
21088 * End of kprobes section
21089 */
21090@@ -1073,7 +1312,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
21091
21092 ENTRY(mcount)
21093 ret
21094-END(mcount)
21095+ENDPROC(mcount)
21096
21097 ENTRY(ftrace_caller)
21098 cmpl $0, function_trace_stop
21099@@ -1106,7 +1345,7 @@ ftrace_graph_call:
21100 .globl ftrace_stub
21101 ftrace_stub:
21102 ret
21103-END(ftrace_caller)
21104+ENDPROC(ftrace_caller)
21105
21106 ENTRY(ftrace_regs_caller)
21107 pushf /* push flags before compare (in cs location) */
21108@@ -1207,7 +1446,7 @@ trace:
21109 popl %ecx
21110 popl %eax
21111 jmp ftrace_stub
21112-END(mcount)
21113+ENDPROC(mcount)
21114 #endif /* CONFIG_DYNAMIC_FTRACE */
21115 #endif /* CONFIG_FUNCTION_TRACER */
21116
21117@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
21118 popl %ecx
21119 popl %eax
21120 ret
21121-END(ftrace_graph_caller)
21122+ENDPROC(ftrace_graph_caller)
21123
21124 .globl return_to_handler
21125 return_to_handler:
21126@@ -1281,15 +1520,18 @@ error_code:
21127 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
21128 REG_TO_PTGS %ecx
21129 SET_KERNEL_GS %ecx
21130- movl $(__USER_DS), %ecx
21131+ movl $(__KERNEL_DS), %ecx
21132 movl %ecx, %ds
21133 movl %ecx, %es
21134+
21135+ pax_enter_kernel
21136+
21137 TRACE_IRQS_OFF
21138 movl %esp,%eax # pt_regs pointer
21139 call *%edi
21140 jmp ret_from_exception
21141 CFI_ENDPROC
21142-END(page_fault)
21143+ENDPROC(page_fault)
21144
21145 /*
21146 * Debug traps and NMI can happen at the one SYSENTER instruction
21147@@ -1332,7 +1574,7 @@ debug_stack_correct:
21148 call do_debug
21149 jmp ret_from_exception
21150 CFI_ENDPROC
21151-END(debug)
21152+ENDPROC(debug)
21153
21154 /*
21155 * NMI is doubly nasty. It can happen _while_ we're handling
21156@@ -1370,6 +1612,9 @@ nmi_stack_correct:
21157 xorl %edx,%edx # zero error code
21158 movl %esp,%eax # pt_regs pointer
21159 call do_nmi
21160+
21161+ pax_exit_kernel
21162+
21163 jmp restore_all_notrace
21164 CFI_ENDPROC
21165
21166@@ -1406,12 +1651,15 @@ nmi_espfix_stack:
21167 FIXUP_ESPFIX_STACK # %eax == %esp
21168 xorl %edx,%edx # zero error code
21169 call do_nmi
21170+
21171+ pax_exit_kernel
21172+
21173 RESTORE_REGS
21174 lss 12+4(%esp), %esp # back to espfix stack
21175 CFI_ADJUST_CFA_OFFSET -24
21176 jmp irq_return
21177 CFI_ENDPROC
21178-END(nmi)
21179+ENDPROC(nmi)
21180
21181 ENTRY(int3)
21182 RING0_INT_FRAME
21183@@ -1424,14 +1672,14 @@ ENTRY(int3)
21184 call do_int3
21185 jmp ret_from_exception
21186 CFI_ENDPROC
21187-END(int3)
21188+ENDPROC(int3)
21189
21190 ENTRY(general_protection)
21191 RING0_EC_FRAME
21192 pushl_cfi $do_general_protection
21193 jmp error_code
21194 CFI_ENDPROC
21195-END(general_protection)
21196+ENDPROC(general_protection)
21197
21198 #ifdef CONFIG_KVM_GUEST
21199 ENTRY(async_page_fault)
21200@@ -1440,7 +1688,7 @@ ENTRY(async_page_fault)
21201 pushl_cfi $do_async_page_fault
21202 jmp error_code
21203 CFI_ENDPROC
21204-END(async_page_fault)
21205+ENDPROC(async_page_fault)
21206 #endif
21207
21208 /*
21209diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
21210index 1b69951..8430a6d 100644
21211--- a/arch/x86/kernel/entry_64.S
21212+++ b/arch/x86/kernel/entry_64.S
21213@@ -59,6 +59,8 @@
21214 #include <asm/context_tracking.h>
21215 #include <asm/smap.h>
21216 #include <linux/err.h>
21217+#include <asm/pgtable.h>
21218+#include <asm/alternative-asm.h>
21219
21220 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
21221 #include <linux/elf-em.h>
21222@@ -80,8 +82,9 @@
21223 #ifdef CONFIG_DYNAMIC_FTRACE
21224
21225 ENTRY(function_hook)
21226+ pax_force_retaddr
21227 retq
21228-END(function_hook)
21229+ENDPROC(function_hook)
21230
21231 /* skip is set if stack has been adjusted */
21232 .macro ftrace_caller_setup skip=0
21233@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
21234 #endif
21235
21236 GLOBAL(ftrace_stub)
21237+ pax_force_retaddr
21238 retq
21239-END(ftrace_caller)
21240+ENDPROC(ftrace_caller)
21241
21242 ENTRY(ftrace_regs_caller)
21243 /* Save the current flags before compare (in SS location)*/
21244@@ -191,7 +195,7 @@ ftrace_restore_flags:
21245 popfq
21246 jmp ftrace_stub
21247
21248-END(ftrace_regs_caller)
21249+ENDPROC(ftrace_regs_caller)
21250
21251
21252 #else /* ! CONFIG_DYNAMIC_FTRACE */
21253@@ -212,6 +216,7 @@ ENTRY(function_hook)
21254 #endif
21255
21256 GLOBAL(ftrace_stub)
21257+ pax_force_retaddr
21258 retq
21259
21260 trace:
21261@@ -225,12 +230,13 @@ trace:
21262 #endif
21263 subq $MCOUNT_INSN_SIZE, %rdi
21264
21265+ pax_force_fptr ftrace_trace_function
21266 call *ftrace_trace_function
21267
21268 MCOUNT_RESTORE_FRAME
21269
21270 jmp ftrace_stub
21271-END(function_hook)
21272+ENDPROC(function_hook)
21273 #endif /* CONFIG_DYNAMIC_FTRACE */
21274 #endif /* CONFIG_FUNCTION_TRACER */
21275
21276@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
21277
21278 MCOUNT_RESTORE_FRAME
21279
21280+ pax_force_retaddr
21281 retq
21282-END(ftrace_graph_caller)
21283+ENDPROC(ftrace_graph_caller)
21284
21285 GLOBAL(return_to_handler)
21286 subq $24, %rsp
21287@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
21288 movq 8(%rsp), %rdx
21289 movq (%rsp), %rax
21290 addq $24, %rsp
21291+ pax_force_fptr %rdi
21292 jmp *%rdi
21293+ENDPROC(return_to_handler)
21294 #endif
21295
21296
21297@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
21298 ENDPROC(native_usergs_sysret64)
21299 #endif /* CONFIG_PARAVIRT */
21300
21301+ .macro ljmpq sel, off
21302+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
21303+ .byte 0x48; ljmp *1234f(%rip)
21304+ .pushsection .rodata
21305+ .align 16
21306+ 1234: .quad \off; .word \sel
21307+ .popsection
21308+#else
21309+ pushq $\sel
21310+ pushq $\off
21311+ lretq
21312+#endif
21313+ .endm
21314+
21315+ .macro pax_enter_kernel
21316+ pax_set_fptr_mask
21317+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21318+ call pax_enter_kernel
21319+#endif
21320+ .endm
21321+
21322+ .macro pax_exit_kernel
21323+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21324+ call pax_exit_kernel
21325+#endif
21326+
21327+ .endm
21328+
21329+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21330+ENTRY(pax_enter_kernel)
21331+ pushq %rdi
21332+
21333+#ifdef CONFIG_PARAVIRT
21334+ PV_SAVE_REGS(CLBR_RDI)
21335+#endif
21336+
21337+#ifdef CONFIG_PAX_KERNEXEC
21338+ GET_CR0_INTO_RDI
21339+ bts $16,%rdi
21340+ jnc 3f
21341+ mov %cs,%edi
21342+ cmp $__KERNEL_CS,%edi
21343+ jnz 2f
21344+1:
21345+#endif
21346+
21347+#ifdef CONFIG_PAX_MEMORY_UDEREF
21348+ 661: jmp 111f
21349+ .pushsection .altinstr_replacement, "a"
21350+ 662: ASM_NOP2
21351+ .popsection
21352+ .pushsection .altinstructions, "a"
21353+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21354+ .popsection
21355+ GET_CR3_INTO_RDI
21356+ cmp $0,%dil
21357+ jnz 112f
21358+ mov $__KERNEL_DS,%edi
21359+ mov %edi,%ss
21360+ jmp 111f
21361+112: cmp $1,%dil
21362+ jz 113f
21363+ ud2
21364+113: sub $4097,%rdi
21365+ bts $63,%rdi
21366+ SET_RDI_INTO_CR3
21367+ mov $__UDEREF_KERNEL_DS,%edi
21368+ mov %edi,%ss
21369+111:
21370+#endif
21371+
21372+#ifdef CONFIG_PARAVIRT
21373+ PV_RESTORE_REGS(CLBR_RDI)
21374+#endif
21375+
21376+ popq %rdi
21377+ pax_force_retaddr
21378+ retq
21379+
21380+#ifdef CONFIG_PAX_KERNEXEC
21381+2: ljmpq __KERNEL_CS,1b
21382+3: ljmpq __KERNEXEC_KERNEL_CS,4f
21383+4: SET_RDI_INTO_CR0
21384+ jmp 1b
21385+#endif
21386+ENDPROC(pax_enter_kernel)
21387+
21388+ENTRY(pax_exit_kernel)
21389+ pushq %rdi
21390+
21391+#ifdef CONFIG_PARAVIRT
21392+ PV_SAVE_REGS(CLBR_RDI)
21393+#endif
21394+
21395+#ifdef CONFIG_PAX_KERNEXEC
21396+ mov %cs,%rdi
21397+ cmp $__KERNEXEC_KERNEL_CS,%edi
21398+ jz 2f
21399+ GET_CR0_INTO_RDI
21400+ bts $16,%rdi
21401+ jnc 4f
21402+1:
21403+#endif
21404+
21405+#ifdef CONFIG_PAX_MEMORY_UDEREF
21406+ 661: jmp 111f
21407+ .pushsection .altinstr_replacement, "a"
21408+ 662: ASM_NOP2
21409+ .popsection
21410+ .pushsection .altinstructions, "a"
21411+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21412+ .popsection
21413+ mov %ss,%edi
21414+ cmp $__UDEREF_KERNEL_DS,%edi
21415+ jnz 111f
21416+ GET_CR3_INTO_RDI
21417+ cmp $0,%dil
21418+ jz 112f
21419+ ud2
21420+112: add $4097,%rdi
21421+ bts $63,%rdi
21422+ SET_RDI_INTO_CR3
21423+ mov $__KERNEL_DS,%edi
21424+ mov %edi,%ss
21425+111:
21426+#endif
21427+
21428+#ifdef CONFIG_PARAVIRT
21429+ PV_RESTORE_REGS(CLBR_RDI);
21430+#endif
21431+
21432+ popq %rdi
21433+ pax_force_retaddr
21434+ retq
21435+
21436+#ifdef CONFIG_PAX_KERNEXEC
21437+2: GET_CR0_INTO_RDI
21438+ btr $16,%rdi
21439+ jnc 4f
21440+ ljmpq __KERNEL_CS,3f
21441+3: SET_RDI_INTO_CR0
21442+ jmp 1b
21443+4: ud2
21444+ jmp 4b
21445+#endif
21446+ENDPROC(pax_exit_kernel)
21447+#endif
21448+
21449+ .macro pax_enter_kernel_user
21450+ pax_set_fptr_mask
21451+#ifdef CONFIG_PAX_MEMORY_UDEREF
21452+ call pax_enter_kernel_user
21453+#endif
21454+ .endm
21455+
21456+ .macro pax_exit_kernel_user
21457+#ifdef CONFIG_PAX_MEMORY_UDEREF
21458+ call pax_exit_kernel_user
21459+#endif
21460+#ifdef CONFIG_PAX_RANDKSTACK
21461+ pushq %rax
21462+ pushq %r11
21463+ call pax_randomize_kstack
21464+ popq %r11
21465+ popq %rax
21466+#endif
21467+ .endm
21468+
21469+#ifdef CONFIG_PAX_MEMORY_UDEREF
21470+ENTRY(pax_enter_kernel_user)
21471+ pushq %rdi
21472+ pushq %rbx
21473+
21474+#ifdef CONFIG_PARAVIRT
21475+ PV_SAVE_REGS(CLBR_RDI)
21476+#endif
21477+
21478+ 661: jmp 111f
21479+ .pushsection .altinstr_replacement, "a"
21480+ 662: ASM_NOP2
21481+ .popsection
21482+ .pushsection .altinstructions, "a"
21483+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21484+ .popsection
21485+ GET_CR3_INTO_RDI
21486+ cmp $1,%dil
21487+ jnz 4f
21488+ sub $4097,%rdi
21489+ bts $63,%rdi
21490+ SET_RDI_INTO_CR3
21491+ jmp 3f
21492+111:
21493+
21494+ GET_CR3_INTO_RDI
21495+ mov %rdi,%rbx
21496+ add $__START_KERNEL_map,%rbx
21497+ sub phys_base(%rip),%rbx
21498+
21499+#ifdef CONFIG_PARAVIRT
21500+ cmpl $0, pv_info+PARAVIRT_enabled
21501+ jz 1f
21502+ pushq %rdi
21503+ i = 0
21504+ .rept USER_PGD_PTRS
21505+ mov i*8(%rbx),%rsi
21506+ mov $0,%sil
21507+ lea i*8(%rbx),%rdi
21508+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21509+ i = i + 1
21510+ .endr
21511+ popq %rdi
21512+ jmp 2f
21513+1:
21514+#endif
21515+
21516+ i = 0
21517+ .rept USER_PGD_PTRS
21518+ movb $0,i*8(%rbx)
21519+ i = i + 1
21520+ .endr
21521+
21522+2: SET_RDI_INTO_CR3
21523+
21524+#ifdef CONFIG_PAX_KERNEXEC
21525+ GET_CR0_INTO_RDI
21526+ bts $16,%rdi
21527+ SET_RDI_INTO_CR0
21528+#endif
21529+
21530+3:
21531+
21532+#ifdef CONFIG_PARAVIRT
21533+ PV_RESTORE_REGS(CLBR_RDI)
21534+#endif
21535+
21536+ popq %rbx
21537+ popq %rdi
21538+ pax_force_retaddr
21539+ retq
21540+4: ud2
21541+ENDPROC(pax_enter_kernel_user)
21542+
21543+ENTRY(pax_exit_kernel_user)
21544+ pushq %rdi
21545+ pushq %rbx
21546+
21547+#ifdef CONFIG_PARAVIRT
21548+ PV_SAVE_REGS(CLBR_RDI)
21549+#endif
21550+
21551+ GET_CR3_INTO_RDI
21552+ 661: jmp 1f
21553+ .pushsection .altinstr_replacement, "a"
21554+ 662: ASM_NOP2
21555+ .popsection
21556+ .pushsection .altinstructions, "a"
21557+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21558+ .popsection
21559+ cmp $0,%dil
21560+ jnz 3f
21561+ add $4097,%rdi
21562+ bts $63,%rdi
21563+ SET_RDI_INTO_CR3
21564+ jmp 2f
21565+1:
21566+
21567+ mov %rdi,%rbx
21568+
21569+#ifdef CONFIG_PAX_KERNEXEC
21570+ GET_CR0_INTO_RDI
21571+ btr $16,%rdi
21572+ jnc 3f
21573+ SET_RDI_INTO_CR0
21574+#endif
21575+
21576+ add $__START_KERNEL_map,%rbx
21577+ sub phys_base(%rip),%rbx
21578+
21579+#ifdef CONFIG_PARAVIRT
21580+ cmpl $0, pv_info+PARAVIRT_enabled
21581+ jz 1f
21582+ i = 0
21583+ .rept USER_PGD_PTRS
21584+ mov i*8(%rbx),%rsi
21585+ mov $0x67,%sil
21586+ lea i*8(%rbx),%rdi
21587+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21588+ i = i + 1
21589+ .endr
21590+ jmp 2f
21591+1:
21592+#endif
21593+
21594+ i = 0
21595+ .rept USER_PGD_PTRS
21596+ movb $0x67,i*8(%rbx)
21597+ i = i + 1
21598+ .endr
21599+2:
21600+
21601+#ifdef CONFIG_PARAVIRT
21602+ PV_RESTORE_REGS(CLBR_RDI)
21603+#endif
21604+
21605+ popq %rbx
21606+ popq %rdi
21607+ pax_force_retaddr
21608+ retq
21609+3: ud2
21610+ENDPROC(pax_exit_kernel_user)
21611+#endif
21612+
21613+ .macro pax_enter_kernel_nmi
21614+ pax_set_fptr_mask
21615+
21616+#ifdef CONFIG_PAX_KERNEXEC
21617+ GET_CR0_INTO_RDI
21618+ bts $16,%rdi
21619+ jc 110f
21620+ SET_RDI_INTO_CR0
21621+ or $2,%ebx
21622+110:
21623+#endif
21624+
21625+#ifdef CONFIG_PAX_MEMORY_UDEREF
21626+ 661: jmp 111f
21627+ .pushsection .altinstr_replacement, "a"
21628+ 662: ASM_NOP2
21629+ .popsection
21630+ .pushsection .altinstructions, "a"
21631+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21632+ .popsection
21633+ GET_CR3_INTO_RDI
21634+ cmp $0,%dil
21635+ jz 111f
21636+ sub $4097,%rdi
21637+ or $4,%ebx
21638+ bts $63,%rdi
21639+ SET_RDI_INTO_CR3
21640+ mov $__UDEREF_KERNEL_DS,%edi
21641+ mov %edi,%ss
21642+111:
21643+#endif
21644+ .endm
21645+
21646+ .macro pax_exit_kernel_nmi
21647+#ifdef CONFIG_PAX_KERNEXEC
21648+ btr $1,%ebx
21649+ jnc 110f
21650+ GET_CR0_INTO_RDI
21651+ btr $16,%rdi
21652+ SET_RDI_INTO_CR0
21653+110:
21654+#endif
21655+
21656+#ifdef CONFIG_PAX_MEMORY_UDEREF
21657+ btr $2,%ebx
21658+ jnc 111f
21659+ GET_CR3_INTO_RDI
21660+ add $4097,%rdi
21661+ bts $63,%rdi
21662+ SET_RDI_INTO_CR3
21663+ mov $__KERNEL_DS,%edi
21664+ mov %edi,%ss
21665+111:
21666+#endif
21667+ .endm
21668+
21669+ .macro pax_erase_kstack
21670+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21671+ call pax_erase_kstack
21672+#endif
21673+ .endm
21674+
21675+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21676+ENTRY(pax_erase_kstack)
21677+ pushq %rdi
21678+ pushq %rcx
21679+ pushq %rax
21680+ pushq %r11
21681+
21682+ GET_THREAD_INFO(%r11)
21683+ mov TI_lowest_stack(%r11), %rdi
21684+ mov $-0xBEEF, %rax
21685+ std
21686+
21687+1: mov %edi, %ecx
21688+ and $THREAD_SIZE_asm - 1, %ecx
21689+ shr $3, %ecx
21690+ repne scasq
21691+ jecxz 2f
21692+
21693+ cmp $2*8, %ecx
21694+ jc 2f
21695+
21696+ mov $2*8, %ecx
21697+ repe scasq
21698+ jecxz 2f
21699+ jne 1b
21700+
21701+2: cld
21702+ mov %esp, %ecx
21703+ sub %edi, %ecx
21704+
21705+ cmp $THREAD_SIZE_asm, %rcx
21706+ jb 3f
21707+ ud2
21708+3:
21709+
21710+ shr $3, %ecx
21711+ rep stosq
21712+
21713+ mov TI_task_thread_sp0(%r11), %rdi
21714+ sub $256, %rdi
21715+ mov %rdi, TI_lowest_stack(%r11)
21716+
21717+ popq %r11
21718+ popq %rax
21719+ popq %rcx
21720+ popq %rdi
21721+ pax_force_retaddr
21722+ ret
21723+ENDPROC(pax_erase_kstack)
21724+#endif
21725
21726 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
21727 #ifdef CONFIG_TRACE_IRQFLAGS
21728@@ -375,8 +808,8 @@ ENDPROC(native_usergs_sysret64)
21729 .endm
21730
21731 .macro UNFAKE_STACK_FRAME
21732- addq $8*6, %rsp
21733- CFI_ADJUST_CFA_OFFSET -(6*8)
21734+ addq $8*6 + ARG_SKIP, %rsp
21735+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
21736 .endm
21737
21738 /*
21739@@ -463,7 +896,7 @@ ENDPROC(native_usergs_sysret64)
21740 movq %rsp, %rsi
21741
21742 leaq -RBP(%rsp),%rdi /* arg1 for handler */
21743- testl $3, CS-RBP(%rsi)
21744+ testb $3, CS-RBP(%rsi)
21745 je 1f
21746 SWAPGS
21747 /*
21748@@ -498,9 +931,10 @@ ENTRY(save_rest)
21749 movq_cfi r15, R15+16
21750 movq %r11, 8(%rsp) /* return address */
21751 FIXUP_TOP_OF_STACK %r11, 16
21752+ pax_force_retaddr
21753 ret
21754 CFI_ENDPROC
21755-END(save_rest)
21756+ENDPROC(save_rest)
21757
21758 /* save complete stack frame */
21759 .pushsection .kprobes.text, "ax"
21760@@ -529,9 +963,10 @@ ENTRY(save_paranoid)
21761 js 1f /* negative -> in kernel */
21762 SWAPGS
21763 xorl %ebx,%ebx
21764-1: ret
21765+1: pax_force_retaddr_bts
21766+ ret
21767 CFI_ENDPROC
21768-END(save_paranoid)
21769+ENDPROC(save_paranoid)
21770 .popsection
21771
21772 /*
21773@@ -553,7 +988,7 @@ ENTRY(ret_from_fork)
21774
21775 RESTORE_REST
21776
21777- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21778+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21779 jz 1f
21780
21781 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
21782@@ -571,7 +1006,7 @@ ENTRY(ret_from_fork)
21783 RESTORE_REST
21784 jmp int_ret_from_sys_call
21785 CFI_ENDPROC
21786-END(ret_from_fork)
21787+ENDPROC(ret_from_fork)
21788
21789 /*
21790 * System call entry. Up to 6 arguments in registers are supported.
21791@@ -608,7 +1043,7 @@ END(ret_from_fork)
21792 ENTRY(system_call)
21793 CFI_STARTPROC simple
21794 CFI_SIGNAL_FRAME
21795- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
21796+ CFI_DEF_CFA rsp,0
21797 CFI_REGISTER rip,rcx
21798 /*CFI_REGISTER rflags,r11*/
21799 SWAPGS_UNSAFE_STACK
21800@@ -621,16 +1056,23 @@ GLOBAL(system_call_after_swapgs)
21801
21802 movq %rsp,PER_CPU_VAR(old_rsp)
21803 movq PER_CPU_VAR(kernel_stack),%rsp
21804+ SAVE_ARGS 8*6,0
21805+ pax_enter_kernel_user
21806+
21807+#ifdef CONFIG_PAX_RANDKSTACK
21808+ pax_erase_kstack
21809+#endif
21810+
21811 /*
21812 * No need to follow this irqs off/on section - it's straight
21813 * and short:
21814 */
21815 ENABLE_INTERRUPTS(CLBR_NONE)
21816- SAVE_ARGS 8,0
21817 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
21818 movq %rcx,RIP-ARGOFFSET(%rsp)
21819 CFI_REL_OFFSET rip,RIP-ARGOFFSET
21820- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21821+ GET_THREAD_INFO(%rcx)
21822+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
21823 jnz tracesys
21824 system_call_fastpath:
21825 #if __SYSCALL_MASK == ~0
21826@@ -640,7 +1082,7 @@ system_call_fastpath:
21827 cmpl $__NR_syscall_max,%eax
21828 #endif
21829 ja badsys
21830- movq %r10,%rcx
21831+ movq R10-ARGOFFSET(%rsp),%rcx
21832 call *sys_call_table(,%rax,8) # XXX: rip relative
21833 movq %rax,RAX-ARGOFFSET(%rsp)
21834 /*
21835@@ -654,10 +1096,13 @@ sysret_check:
21836 LOCKDEP_SYS_EXIT
21837 DISABLE_INTERRUPTS(CLBR_NONE)
21838 TRACE_IRQS_OFF
21839- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
21840+ GET_THREAD_INFO(%rcx)
21841+ movl TI_flags(%rcx),%edx
21842 andl %edi,%edx
21843 jnz sysret_careful
21844 CFI_REMEMBER_STATE
21845+ pax_exit_kernel_user
21846+ pax_erase_kstack
21847 /*
21848 * sysretq will re-enable interrupts:
21849 */
21850@@ -709,14 +1154,18 @@ badsys:
21851 * jump back to the normal fast path.
21852 */
21853 auditsys:
21854- movq %r10,%r9 /* 6th arg: 4th syscall arg */
21855+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
21856 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
21857 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
21858 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
21859 movq %rax,%rsi /* 2nd arg: syscall number */
21860 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
21861 call __audit_syscall_entry
21862+
21863+ pax_erase_kstack
21864+
21865 LOAD_ARGS 0 /* reload call-clobbered registers */
21866+ pax_set_fptr_mask
21867 jmp system_call_fastpath
21868
21869 /*
21870@@ -737,7 +1186,7 @@ sysret_audit:
21871 /* Do syscall tracing */
21872 tracesys:
21873 #ifdef CONFIG_AUDITSYSCALL
21874- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21875+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
21876 jz auditsys
21877 #endif
21878 SAVE_REST
21879@@ -745,12 +1194,16 @@ tracesys:
21880 FIXUP_TOP_OF_STACK %rdi
21881 movq %rsp,%rdi
21882 call syscall_trace_enter
21883+
21884+ pax_erase_kstack
21885+
21886 /*
21887 * Reload arg registers from stack in case ptrace changed them.
21888 * We don't reload %rax because syscall_trace_enter() returned
21889 * the value it wants us to use in the table lookup.
21890 */
21891 LOAD_ARGS ARGOFFSET, 1
21892+ pax_set_fptr_mask
21893 RESTORE_REST
21894 #if __SYSCALL_MASK == ~0
21895 cmpq $__NR_syscall_max,%rax
21896@@ -759,7 +1212,7 @@ tracesys:
21897 cmpl $__NR_syscall_max,%eax
21898 #endif
21899 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
21900- movq %r10,%rcx /* fixup for C */
21901+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
21902 call *sys_call_table(,%rax,8)
21903 movq %rax,RAX-ARGOFFSET(%rsp)
21904 /* Use IRET because user could have changed frame */
21905@@ -780,7 +1233,9 @@ GLOBAL(int_with_check)
21906 andl %edi,%edx
21907 jnz int_careful
21908 andl $~TS_COMPAT,TI_status(%rcx)
21909- jmp retint_swapgs
21910+ pax_exit_kernel_user
21911+ pax_erase_kstack
21912+ jmp retint_swapgs_pax
21913
21914 /* Either reschedule or signal or syscall exit tracking needed. */
21915 /* First do a reschedule test. */
21916@@ -826,7 +1281,7 @@ int_restore_rest:
21917 TRACE_IRQS_OFF
21918 jmp int_with_check
21919 CFI_ENDPROC
21920-END(system_call)
21921+ENDPROC(system_call)
21922
21923 .macro FORK_LIKE func
21924 ENTRY(stub_\func)
21925@@ -839,9 +1294,10 @@ ENTRY(stub_\func)
21926 DEFAULT_FRAME 0 8 /* offset 8: return address */
21927 call sys_\func
21928 RESTORE_TOP_OF_STACK %r11, 8
21929+ pax_force_retaddr
21930 ret $REST_SKIP /* pop extended registers */
21931 CFI_ENDPROC
21932-END(stub_\func)
21933+ENDPROC(stub_\func)
21934 .endm
21935
21936 .macro FIXED_FRAME label,func
21937@@ -851,9 +1307,10 @@ ENTRY(\label)
21938 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
21939 call \func
21940 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
21941+ pax_force_retaddr
21942 ret
21943 CFI_ENDPROC
21944-END(\label)
21945+ENDPROC(\label)
21946 .endm
21947
21948 FORK_LIKE clone
21949@@ -870,9 +1327,10 @@ ENTRY(ptregscall_common)
21950 movq_cfi_restore R12+8, r12
21951 movq_cfi_restore RBP+8, rbp
21952 movq_cfi_restore RBX+8, rbx
21953+ pax_force_retaddr
21954 ret $REST_SKIP /* pop extended registers */
21955 CFI_ENDPROC
21956-END(ptregscall_common)
21957+ENDPROC(ptregscall_common)
21958
21959 ENTRY(stub_execve)
21960 CFI_STARTPROC
21961@@ -885,7 +1343,7 @@ ENTRY(stub_execve)
21962 RESTORE_REST
21963 jmp int_ret_from_sys_call
21964 CFI_ENDPROC
21965-END(stub_execve)
21966+ENDPROC(stub_execve)
21967
21968 /*
21969 * sigreturn is special because it needs to restore all registers on return.
21970@@ -902,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
21971 RESTORE_REST
21972 jmp int_ret_from_sys_call
21973 CFI_ENDPROC
21974-END(stub_rt_sigreturn)
21975+ENDPROC(stub_rt_sigreturn)
21976
21977 #ifdef CONFIG_X86_X32_ABI
21978 ENTRY(stub_x32_rt_sigreturn)
21979@@ -916,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
21980 RESTORE_REST
21981 jmp int_ret_from_sys_call
21982 CFI_ENDPROC
21983-END(stub_x32_rt_sigreturn)
21984+ENDPROC(stub_x32_rt_sigreturn)
21985
21986 ENTRY(stub_x32_execve)
21987 CFI_STARTPROC
21988@@ -930,7 +1388,7 @@ ENTRY(stub_x32_execve)
21989 RESTORE_REST
21990 jmp int_ret_from_sys_call
21991 CFI_ENDPROC
21992-END(stub_x32_execve)
21993+ENDPROC(stub_x32_execve)
21994
21995 #endif
21996
21997@@ -967,7 +1425,7 @@ vector=vector+1
21998 2: jmp common_interrupt
21999 .endr
22000 CFI_ENDPROC
22001-END(irq_entries_start)
22002+ENDPROC(irq_entries_start)
22003
22004 .previous
22005 END(interrupt)
22006@@ -987,6 +1445,16 @@ END(interrupt)
22007 subq $ORIG_RAX-RBP, %rsp
22008 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
22009 SAVE_ARGS_IRQ
22010+#ifdef CONFIG_PAX_MEMORY_UDEREF
22011+ testb $3, CS(%rdi)
22012+ jnz 1f
22013+ pax_enter_kernel
22014+ jmp 2f
22015+1: pax_enter_kernel_user
22016+2:
22017+#else
22018+ pax_enter_kernel
22019+#endif
22020 call \func
22021 .endm
22022
22023@@ -1019,7 +1487,7 @@ ret_from_intr:
22024
22025 exit_intr:
22026 GET_THREAD_INFO(%rcx)
22027- testl $3,CS-ARGOFFSET(%rsp)
22028+ testb $3,CS-ARGOFFSET(%rsp)
22029 je retint_kernel
22030
22031 /* Interrupt came from user space */
22032@@ -1041,12 +1509,16 @@ retint_swapgs: /* return to user-space */
22033 * The iretq could re-enable interrupts:
22034 */
22035 DISABLE_INTERRUPTS(CLBR_ANY)
22036+ pax_exit_kernel_user
22037+retint_swapgs_pax:
22038 TRACE_IRQS_IRETQ
22039 SWAPGS
22040 jmp restore_args
22041
22042 retint_restore_args: /* return to kernel space */
22043 DISABLE_INTERRUPTS(CLBR_ANY)
22044+ pax_exit_kernel
22045+ pax_force_retaddr (RIP-ARGOFFSET)
22046 /*
22047 * The iretq could re-enable interrupts:
22048 */
22049@@ -1129,7 +1601,7 @@ ENTRY(retint_kernel)
22050 #endif
22051
22052 CFI_ENDPROC
22053-END(common_interrupt)
22054+ENDPROC(common_interrupt)
22055 /*
22056 * End of kprobes section
22057 */
22058@@ -1147,7 +1619,7 @@ ENTRY(\sym)
22059 interrupt \do_sym
22060 jmp ret_from_intr
22061 CFI_ENDPROC
22062-END(\sym)
22063+ENDPROC(\sym)
22064 .endm
22065
22066 #ifdef CONFIG_TRACING
22067@@ -1230,12 +1702,22 @@ ENTRY(\sym)
22068 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22069 call error_entry
22070 DEFAULT_FRAME 0
22071+#ifdef CONFIG_PAX_MEMORY_UDEREF
22072+ testb $3, CS(%rsp)
22073+ jnz 1f
22074+ pax_enter_kernel
22075+ jmp 2f
22076+1: pax_enter_kernel_user
22077+2:
22078+#else
22079+ pax_enter_kernel
22080+#endif
22081 movq %rsp,%rdi /* pt_regs pointer */
22082 xorl %esi,%esi /* no error code */
22083 call \do_sym
22084 jmp error_exit /* %ebx: no swapgs flag */
22085 CFI_ENDPROC
22086-END(\sym)
22087+ENDPROC(\sym)
22088 .endm
22089
22090 .macro paranoidzeroentry sym do_sym
22091@@ -1248,15 +1730,25 @@ ENTRY(\sym)
22092 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22093 call save_paranoid
22094 TRACE_IRQS_OFF
22095+#ifdef CONFIG_PAX_MEMORY_UDEREF
22096+ testb $3, CS(%rsp)
22097+ jnz 1f
22098+ pax_enter_kernel
22099+ jmp 2f
22100+1: pax_enter_kernel_user
22101+2:
22102+#else
22103+ pax_enter_kernel
22104+#endif
22105 movq %rsp,%rdi /* pt_regs pointer */
22106 xorl %esi,%esi /* no error code */
22107 call \do_sym
22108 jmp paranoid_exit /* %ebx: no swapgs flag */
22109 CFI_ENDPROC
22110-END(\sym)
22111+ENDPROC(\sym)
22112 .endm
22113
22114-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
22115+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
22116 .macro paranoidzeroentry_ist sym do_sym ist
22117 ENTRY(\sym)
22118 INTR_FRAME
22119@@ -1267,14 +1759,30 @@ ENTRY(\sym)
22120 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22121 call save_paranoid
22122 TRACE_IRQS_OFF_DEBUG
22123+#ifdef CONFIG_PAX_MEMORY_UDEREF
22124+ testb $3, CS(%rsp)
22125+ jnz 1f
22126+ pax_enter_kernel
22127+ jmp 2f
22128+1: pax_enter_kernel_user
22129+2:
22130+#else
22131+ pax_enter_kernel
22132+#endif
22133 movq %rsp,%rdi /* pt_regs pointer */
22134 xorl %esi,%esi /* no error code */
22135+#ifdef CONFIG_SMP
22136+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
22137+ lea init_tss(%r12), %r12
22138+#else
22139+ lea init_tss(%rip), %r12
22140+#endif
22141 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22142 call \do_sym
22143 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22144 jmp paranoid_exit /* %ebx: no swapgs flag */
22145 CFI_ENDPROC
22146-END(\sym)
22147+ENDPROC(\sym)
22148 .endm
22149
22150 .macro errorentry sym do_sym
22151@@ -1286,13 +1794,23 @@ ENTRY(\sym)
22152 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22153 call error_entry
22154 DEFAULT_FRAME 0
22155+#ifdef CONFIG_PAX_MEMORY_UDEREF
22156+ testb $3, CS(%rsp)
22157+ jnz 1f
22158+ pax_enter_kernel
22159+ jmp 2f
22160+1: pax_enter_kernel_user
22161+2:
22162+#else
22163+ pax_enter_kernel
22164+#endif
22165 movq %rsp,%rdi /* pt_regs pointer */
22166 movq ORIG_RAX(%rsp),%rsi /* get error code */
22167 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22168 call \do_sym
22169 jmp error_exit /* %ebx: no swapgs flag */
22170 CFI_ENDPROC
22171-END(\sym)
22172+ENDPROC(\sym)
22173 .endm
22174
22175 /* error code is on the stack already */
22176@@ -1306,13 +1824,23 @@ ENTRY(\sym)
22177 call save_paranoid
22178 DEFAULT_FRAME 0
22179 TRACE_IRQS_OFF
22180+#ifdef CONFIG_PAX_MEMORY_UDEREF
22181+ testb $3, CS(%rsp)
22182+ jnz 1f
22183+ pax_enter_kernel
22184+ jmp 2f
22185+1: pax_enter_kernel_user
22186+2:
22187+#else
22188+ pax_enter_kernel
22189+#endif
22190 movq %rsp,%rdi /* pt_regs pointer */
22191 movq ORIG_RAX(%rsp),%rsi /* get error code */
22192 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22193 call \do_sym
22194 jmp paranoid_exit /* %ebx: no swapgs flag */
22195 CFI_ENDPROC
22196-END(\sym)
22197+ENDPROC(\sym)
22198 .endm
22199
22200 zeroentry divide_error do_divide_error
22201@@ -1342,9 +1870,10 @@ gs_change:
22202 2: mfence /* workaround */
22203 SWAPGS
22204 popfq_cfi
22205+ pax_force_retaddr
22206 ret
22207 CFI_ENDPROC
22208-END(native_load_gs_index)
22209+ENDPROC(native_load_gs_index)
22210
22211 _ASM_EXTABLE(gs_change,bad_gs)
22212 .section .fixup,"ax"
22213@@ -1372,9 +1901,10 @@ ENTRY(call_softirq)
22214 CFI_DEF_CFA_REGISTER rsp
22215 CFI_ADJUST_CFA_OFFSET -8
22216 decl PER_CPU_VAR(irq_count)
22217+ pax_force_retaddr
22218 ret
22219 CFI_ENDPROC
22220-END(call_softirq)
22221+ENDPROC(call_softirq)
22222
22223 #ifdef CONFIG_XEN
22224 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
22225@@ -1412,7 +1942,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
22226 decl PER_CPU_VAR(irq_count)
22227 jmp error_exit
22228 CFI_ENDPROC
22229-END(xen_do_hypervisor_callback)
22230+ENDPROC(xen_do_hypervisor_callback)
22231
22232 /*
22233 * Hypervisor uses this for application faults while it executes.
22234@@ -1471,7 +2001,7 @@ ENTRY(xen_failsafe_callback)
22235 SAVE_ALL
22236 jmp error_exit
22237 CFI_ENDPROC
22238-END(xen_failsafe_callback)
22239+ENDPROC(xen_failsafe_callback)
22240
22241 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
22242 xen_hvm_callback_vector xen_evtchn_do_upcall
22243@@ -1523,18 +2053,33 @@ ENTRY(paranoid_exit)
22244 DEFAULT_FRAME
22245 DISABLE_INTERRUPTS(CLBR_NONE)
22246 TRACE_IRQS_OFF_DEBUG
22247- testl %ebx,%ebx /* swapgs needed? */
22248+ testl $1,%ebx /* swapgs needed? */
22249 jnz paranoid_restore
22250- testl $3,CS(%rsp)
22251+ testb $3,CS(%rsp)
22252 jnz paranoid_userspace
22253+#ifdef CONFIG_PAX_MEMORY_UDEREF
22254+ pax_exit_kernel
22255+ TRACE_IRQS_IRETQ 0
22256+ SWAPGS_UNSAFE_STACK
22257+ RESTORE_ALL 8
22258+ pax_force_retaddr_bts
22259+ jmp irq_return
22260+#endif
22261 paranoid_swapgs:
22262+#ifdef CONFIG_PAX_MEMORY_UDEREF
22263+ pax_exit_kernel_user
22264+#else
22265+ pax_exit_kernel
22266+#endif
22267 TRACE_IRQS_IRETQ 0
22268 SWAPGS_UNSAFE_STACK
22269 RESTORE_ALL 8
22270 jmp irq_return
22271 paranoid_restore:
22272+ pax_exit_kernel
22273 TRACE_IRQS_IRETQ_DEBUG 0
22274 RESTORE_ALL 8
22275+ pax_force_retaddr_bts
22276 jmp irq_return
22277 paranoid_userspace:
22278 GET_THREAD_INFO(%rcx)
22279@@ -1563,7 +2108,7 @@ paranoid_schedule:
22280 TRACE_IRQS_OFF
22281 jmp paranoid_userspace
22282 CFI_ENDPROC
22283-END(paranoid_exit)
22284+ENDPROC(paranoid_exit)
22285
22286 /*
22287 * Exception entry point. This expects an error code/orig_rax on the stack.
22288@@ -1590,12 +2135,13 @@ ENTRY(error_entry)
22289 movq_cfi r14, R14+8
22290 movq_cfi r15, R15+8
22291 xorl %ebx,%ebx
22292- testl $3,CS+8(%rsp)
22293+ testb $3,CS+8(%rsp)
22294 je error_kernelspace
22295 error_swapgs:
22296 SWAPGS
22297 error_sti:
22298 TRACE_IRQS_OFF
22299+ pax_force_retaddr_bts
22300 ret
22301
22302 /*
22303@@ -1622,7 +2168,7 @@ bstep_iret:
22304 movq %rcx,RIP+8(%rsp)
22305 jmp error_swapgs
22306 CFI_ENDPROC
22307-END(error_entry)
22308+ENDPROC(error_entry)
22309
22310
22311 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
22312@@ -1633,7 +2179,7 @@ ENTRY(error_exit)
22313 DISABLE_INTERRUPTS(CLBR_NONE)
22314 TRACE_IRQS_OFF
22315 GET_THREAD_INFO(%rcx)
22316- testl %eax,%eax
22317+ testl $1,%eax
22318 jne retint_kernel
22319 LOCKDEP_SYS_EXIT_IRQ
22320 movl TI_flags(%rcx),%edx
22321@@ -1642,7 +2188,7 @@ ENTRY(error_exit)
22322 jnz retint_careful
22323 jmp retint_swapgs
22324 CFI_ENDPROC
22325-END(error_exit)
22326+ENDPROC(error_exit)
22327
22328 /*
22329 * Test if a given stack is an NMI stack or not.
22330@@ -1700,9 +2246,11 @@ ENTRY(nmi)
22331 * If %cs was not the kernel segment, then the NMI triggered in user
22332 * space, which means it is definitely not nested.
22333 */
22334+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
22335+ je 1f
22336 cmpl $__KERNEL_CS, 16(%rsp)
22337 jne first_nmi
22338-
22339+1:
22340 /*
22341 * Check the special variable on the stack to see if NMIs are
22342 * executing.
22343@@ -1736,8 +2284,7 @@ nested_nmi:
22344
22345 1:
22346 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
22347- leaq -1*8(%rsp), %rdx
22348- movq %rdx, %rsp
22349+ subq $8, %rsp
22350 CFI_ADJUST_CFA_OFFSET 1*8
22351 leaq -10*8(%rsp), %rdx
22352 pushq_cfi $__KERNEL_DS
22353@@ -1755,6 +2302,7 @@ nested_nmi_out:
22354 CFI_RESTORE rdx
22355
22356 /* No need to check faults here */
22357+# pax_force_retaddr_bts
22358 INTERRUPT_RETURN
22359
22360 CFI_RESTORE_STATE
22361@@ -1871,6 +2419,8 @@ end_repeat_nmi:
22362 */
22363 movq %cr2, %r12
22364
22365+ pax_enter_kernel_nmi
22366+
22367 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
22368 movq %rsp,%rdi
22369 movq $-1,%rsi
22370@@ -1883,26 +2433,31 @@ end_repeat_nmi:
22371 movq %r12, %cr2
22372 1:
22373
22374- testl %ebx,%ebx /* swapgs needed? */
22375+ testl $1,%ebx /* swapgs needed? */
22376 jnz nmi_restore
22377 nmi_swapgs:
22378 SWAPGS_UNSAFE_STACK
22379 nmi_restore:
22380+ pax_exit_kernel_nmi
22381 /* Pop the extra iret frame at once */
22382 RESTORE_ALL 6*8
22383+ testb $3, 8(%rsp)
22384+ jnz 1f
22385+ pax_force_retaddr_bts
22386+1:
22387
22388 /* Clear the NMI executing stack variable */
22389 movq $0, 5*8(%rsp)
22390 jmp irq_return
22391 CFI_ENDPROC
22392-END(nmi)
22393+ENDPROC(nmi)
22394
22395 ENTRY(ignore_sysret)
22396 CFI_STARTPROC
22397 mov $-ENOSYS,%eax
22398 sysret
22399 CFI_ENDPROC
22400-END(ignore_sysret)
22401+ENDPROC(ignore_sysret)
22402
22403 /*
22404 * End of kprobes section
22405diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
22406index 42a392a..fbbd930 100644
22407--- a/arch/x86/kernel/ftrace.c
22408+++ b/arch/x86/kernel/ftrace.c
22409@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
22410 {
22411 unsigned char replaced[MCOUNT_INSN_SIZE];
22412
22413+ ip = ktla_ktva(ip);
22414+
22415 /*
22416 * Note: Due to modules and __init, code can
22417 * disappear and change, we need to protect against faulting
22418@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22419 unsigned char old[MCOUNT_INSN_SIZE], *new;
22420 int ret;
22421
22422- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
22423+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
22424 new = ftrace_call_replace(ip, (unsigned long)func);
22425
22426 /* See comment above by declaration of modifying_ftrace_code */
22427@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22428 /* Also update the regs callback function */
22429 if (!ret) {
22430 ip = (unsigned long)(&ftrace_regs_call);
22431- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
22432+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
22433 new = ftrace_call_replace(ip, (unsigned long)func);
22434 ret = ftrace_modify_code(ip, old, new);
22435 }
22436@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
22437 * kernel identity mapping to modify code.
22438 */
22439 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
22440- ip = (unsigned long)__va(__pa_symbol(ip));
22441+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
22442
22443 return probe_kernel_write((void *)ip, val, size);
22444 }
22445@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
22446 unsigned char replaced[MCOUNT_INSN_SIZE];
22447 unsigned char brk = BREAKPOINT_INSTRUCTION;
22448
22449- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
22450+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
22451 return -EFAULT;
22452
22453 /* Make sure it is what we expect it to be */
22454@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
22455 return ret;
22456
22457 fail_update:
22458- probe_kernel_write((void *)ip, &old_code[0], 1);
22459+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
22460 goto out;
22461 }
22462
22463@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
22464 {
22465 unsigned char code[MCOUNT_INSN_SIZE];
22466
22467+ ip = ktla_ktva(ip);
22468+
22469 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
22470 return -EFAULT;
22471
22472diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
22473index 55b6761..a6456fc 100644
22474--- a/arch/x86/kernel/head64.c
22475+++ b/arch/x86/kernel/head64.c
22476@@ -67,12 +67,12 @@ again:
22477 pgd = *pgd_p;
22478
22479 /*
22480- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
22481- * critical -- __PAGE_OFFSET would point us back into the dynamic
22482+ * The use of __early_va rather than __va here is critical:
22483+ * __va would point us back into the dynamic
22484 * range and we might end up looping forever...
22485 */
22486 if (pgd)
22487- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22488+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
22489 else {
22490 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22491 reset_early_page_tables();
22492@@ -82,13 +82,13 @@ again:
22493 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
22494 for (i = 0; i < PTRS_PER_PUD; i++)
22495 pud_p[i] = 0;
22496- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22497+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
22498 }
22499 pud_p += pud_index(address);
22500 pud = *pud_p;
22501
22502 if (pud)
22503- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22504+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
22505 else {
22506 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22507 reset_early_page_tables();
22508@@ -98,7 +98,7 @@ again:
22509 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
22510 for (i = 0; i < PTRS_PER_PMD; i++)
22511 pmd_p[i] = 0;
22512- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22513+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
22514 }
22515 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
22516 pmd_p[pmd_index(address)] = pmd;
22517@@ -175,7 +175,6 @@ void __init x86_64_start_kernel(char * real_mode_data)
22518 if (console_loglevel == 10)
22519 early_printk("Kernel alive\n");
22520
22521- clear_page(init_level4_pgt);
22522 /* set init_level4_pgt kernel high mapping*/
22523 init_level4_pgt[511] = early_level4_pgt[511];
22524
22525diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
22526index 5dd87a8..d68b3f4 100644
22527--- a/arch/x86/kernel/head_32.S
22528+++ b/arch/x86/kernel/head_32.S
22529@@ -26,6 +26,12 @@
22530 /* Physical address */
22531 #define pa(X) ((X) - __PAGE_OFFSET)
22532
22533+#ifdef CONFIG_PAX_KERNEXEC
22534+#define ta(X) (X)
22535+#else
22536+#define ta(X) ((X) - __PAGE_OFFSET)
22537+#endif
22538+
22539 /*
22540 * References to members of the new_cpu_data structure.
22541 */
22542@@ -55,11 +61,7 @@
22543 * and small than max_low_pfn, otherwise will waste some page table entries
22544 */
22545
22546-#if PTRS_PER_PMD > 1
22547-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
22548-#else
22549-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
22550-#endif
22551+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
22552
22553 /* Number of possible pages in the lowmem region */
22554 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
22555@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
22556 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22557
22558 /*
22559+ * Real beginning of normal "text" segment
22560+ */
22561+ENTRY(stext)
22562+ENTRY(_stext)
22563+
22564+/*
22565 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
22566 * %esi points to the real-mode code as a 32-bit pointer.
22567 * CS and DS must be 4 GB flat segments, but we don't depend on
22568@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22569 * can.
22570 */
22571 __HEAD
22572+
22573+#ifdef CONFIG_PAX_KERNEXEC
22574+ jmp startup_32
22575+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
22576+.fill PAGE_SIZE-5,1,0xcc
22577+#endif
22578+
22579 ENTRY(startup_32)
22580 movl pa(stack_start),%ecx
22581
22582@@ -106,6 +121,59 @@ ENTRY(startup_32)
22583 2:
22584 leal -__PAGE_OFFSET(%ecx),%esp
22585
22586+#ifdef CONFIG_SMP
22587+ movl $pa(cpu_gdt_table),%edi
22588+ movl $__per_cpu_load,%eax
22589+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
22590+ rorl $16,%eax
22591+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
22592+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
22593+ movl $__per_cpu_end - 1,%eax
22594+ subl $__per_cpu_start,%eax
22595+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
22596+#endif
22597+
22598+#ifdef CONFIG_PAX_MEMORY_UDEREF
22599+ movl $NR_CPUS,%ecx
22600+ movl $pa(cpu_gdt_table),%edi
22601+1:
22602+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
22603+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
22604+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
22605+ addl $PAGE_SIZE_asm,%edi
22606+ loop 1b
22607+#endif
22608+
22609+#ifdef CONFIG_PAX_KERNEXEC
22610+ movl $pa(boot_gdt),%edi
22611+ movl $__LOAD_PHYSICAL_ADDR,%eax
22612+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
22613+ rorl $16,%eax
22614+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
22615+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
22616+ rorl $16,%eax
22617+
22618+ ljmp $(__BOOT_CS),$1f
22619+1:
22620+
22621+ movl $NR_CPUS,%ecx
22622+ movl $pa(cpu_gdt_table),%edi
22623+ addl $__PAGE_OFFSET,%eax
22624+1:
22625+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
22626+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
22627+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
22628+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
22629+ rorl $16,%eax
22630+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
22631+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
22632+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
22633+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
22634+ rorl $16,%eax
22635+ addl $PAGE_SIZE_asm,%edi
22636+ loop 1b
22637+#endif
22638+
22639 /*
22640 * Clear BSS first so that there are no surprises...
22641 */
22642@@ -201,8 +269,11 @@ ENTRY(startup_32)
22643 movl %eax, pa(max_pfn_mapped)
22644
22645 /* Do early initialization of the fixmap area */
22646- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22647- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
22648+#ifdef CONFIG_COMPAT_VDSO
22649+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
22650+#else
22651+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
22652+#endif
22653 #else /* Not PAE */
22654
22655 page_pde_offset = (__PAGE_OFFSET >> 20);
22656@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22657 movl %eax, pa(max_pfn_mapped)
22658
22659 /* Do early initialization of the fixmap area */
22660- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22661- movl %eax,pa(initial_page_table+0xffc)
22662+#ifdef CONFIG_COMPAT_VDSO
22663+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
22664+#else
22665+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
22666+#endif
22667 #endif
22668
22669 #ifdef CONFIG_PARAVIRT
22670@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22671 cmpl $num_subarch_entries, %eax
22672 jae bad_subarch
22673
22674- movl pa(subarch_entries)(,%eax,4), %eax
22675- subl $__PAGE_OFFSET, %eax
22676- jmp *%eax
22677+ jmp *pa(subarch_entries)(,%eax,4)
22678
22679 bad_subarch:
22680 WEAK(lguest_entry)
22681@@ -261,10 +333,10 @@ WEAK(xen_entry)
22682 __INITDATA
22683
22684 subarch_entries:
22685- .long default_entry /* normal x86/PC */
22686- .long lguest_entry /* lguest hypervisor */
22687- .long xen_entry /* Xen hypervisor */
22688- .long default_entry /* Moorestown MID */
22689+ .long ta(default_entry) /* normal x86/PC */
22690+ .long ta(lguest_entry) /* lguest hypervisor */
22691+ .long ta(xen_entry) /* Xen hypervisor */
22692+ .long ta(default_entry) /* Moorestown MID */
22693 num_subarch_entries = (. - subarch_entries) / 4
22694 .previous
22695 #else
22696@@ -354,6 +426,7 @@ default_entry:
22697 movl pa(mmu_cr4_features),%eax
22698 movl %eax,%cr4
22699
22700+#ifdef CONFIG_X86_PAE
22701 testb $X86_CR4_PAE, %al # check if PAE is enabled
22702 jz enable_paging
22703
22704@@ -382,6 +455,9 @@ default_entry:
22705 /* Make changes effective */
22706 wrmsr
22707
22708+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
22709+#endif
22710+
22711 enable_paging:
22712
22713 /*
22714@@ -449,14 +525,20 @@ is486:
22715 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
22716 movl %eax,%ss # after changing gdt.
22717
22718- movl $(__USER_DS),%eax # DS/ES contains default USER segment
22719+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
22720 movl %eax,%ds
22721 movl %eax,%es
22722
22723 movl $(__KERNEL_PERCPU), %eax
22724 movl %eax,%fs # set this cpu's percpu
22725
22726+#ifdef CONFIG_CC_STACKPROTECTOR
22727 movl $(__KERNEL_STACK_CANARY),%eax
22728+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22729+ movl $(__USER_DS),%eax
22730+#else
22731+ xorl %eax,%eax
22732+#endif
22733 movl %eax,%gs
22734
22735 xorl %eax,%eax # Clear LDT
22736@@ -512,8 +594,11 @@ setup_once:
22737 * relocation. Manually set base address in stack canary
22738 * segment descriptor.
22739 */
22740- movl $gdt_page,%eax
22741+ movl $cpu_gdt_table,%eax
22742 movl $stack_canary,%ecx
22743+#ifdef CONFIG_SMP
22744+ addl $__per_cpu_load,%ecx
22745+#endif
22746 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
22747 shrl $16, %ecx
22748 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
22749@@ -544,7 +629,7 @@ ENDPROC(early_idt_handlers)
22750 /* This is global to keep gas from relaxing the jumps */
22751 ENTRY(early_idt_handler)
22752 cld
22753- cmpl $2,%ss:early_recursion_flag
22754+ cmpl $1,%ss:early_recursion_flag
22755 je hlt_loop
22756 incl %ss:early_recursion_flag
22757
22758@@ -582,8 +667,8 @@ ENTRY(early_idt_handler)
22759 pushl (20+6*4)(%esp) /* trapno */
22760 pushl $fault_msg
22761 call printk
22762-#endif
22763 call dump_stack
22764+#endif
22765 hlt_loop:
22766 hlt
22767 jmp hlt_loop
22768@@ -602,8 +687,11 @@ ENDPROC(early_idt_handler)
22769 /* This is the default interrupt "handler" :-) */
22770 ALIGN
22771 ignore_int:
22772- cld
22773 #ifdef CONFIG_PRINTK
22774+ cmpl $2,%ss:early_recursion_flag
22775+ je hlt_loop
22776+ incl %ss:early_recursion_flag
22777+ cld
22778 pushl %eax
22779 pushl %ecx
22780 pushl %edx
22781@@ -612,9 +700,6 @@ ignore_int:
22782 movl $(__KERNEL_DS),%eax
22783 movl %eax,%ds
22784 movl %eax,%es
22785- cmpl $2,early_recursion_flag
22786- je hlt_loop
22787- incl early_recursion_flag
22788 pushl 16(%esp)
22789 pushl 24(%esp)
22790 pushl 32(%esp)
22791@@ -648,29 +733,34 @@ ENTRY(setup_once_ref)
22792 /*
22793 * BSS section
22794 */
22795-__PAGE_ALIGNED_BSS
22796- .align PAGE_SIZE
22797 #ifdef CONFIG_X86_PAE
22798+.section .initial_pg_pmd,"a",@progbits
22799 initial_pg_pmd:
22800 .fill 1024*KPMDS,4,0
22801 #else
22802+.section .initial_page_table,"a",@progbits
22803 ENTRY(initial_page_table)
22804 .fill 1024,4,0
22805 #endif
22806+.section .initial_pg_fixmap,"a",@progbits
22807 initial_pg_fixmap:
22808 .fill 1024,4,0
22809+.section .empty_zero_page,"a",@progbits
22810 ENTRY(empty_zero_page)
22811 .fill 4096,1,0
22812+.section .swapper_pg_dir,"a",@progbits
22813 ENTRY(swapper_pg_dir)
22814+#ifdef CONFIG_X86_PAE
22815+ .fill 4,8,0
22816+#else
22817 .fill 1024,4,0
22818+#endif
22819
22820 /*
22821 * This starts the data section.
22822 */
22823 #ifdef CONFIG_X86_PAE
22824-__PAGE_ALIGNED_DATA
22825- /* Page-aligned for the benefit of paravirt? */
22826- .align PAGE_SIZE
22827+.section .initial_page_table,"a",@progbits
22828 ENTRY(initial_page_table)
22829 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
22830 # if KPMDS == 3
22831@@ -689,12 +779,20 @@ ENTRY(initial_page_table)
22832 # error "Kernel PMDs should be 1, 2 or 3"
22833 # endif
22834 .align PAGE_SIZE /* needs to be page-sized too */
22835+
22836+#ifdef CONFIG_PAX_PER_CPU_PGD
22837+ENTRY(cpu_pgd)
22838+ .rept 2*NR_CPUS
22839+ .fill 4,8,0
22840+ .endr
22841+#endif
22842+
22843 #endif
22844
22845 .data
22846 .balign 4
22847 ENTRY(stack_start)
22848- .long init_thread_union+THREAD_SIZE
22849+ .long init_thread_union+THREAD_SIZE-8
22850
22851 __INITRODATA
22852 int_msg:
22853@@ -722,7 +820,7 @@ fault_msg:
22854 * segment size, and 32-bit linear address value:
22855 */
22856
22857- .data
22858+.section .rodata,"a",@progbits
22859 .globl boot_gdt_descr
22860 .globl idt_descr
22861
22862@@ -731,7 +829,7 @@ fault_msg:
22863 .word 0 # 32 bit align gdt_desc.address
22864 boot_gdt_descr:
22865 .word __BOOT_DS+7
22866- .long boot_gdt - __PAGE_OFFSET
22867+ .long pa(boot_gdt)
22868
22869 .word 0 # 32-bit align idt_desc.address
22870 idt_descr:
22871@@ -742,7 +840,7 @@ idt_descr:
22872 .word 0 # 32 bit align gdt_desc.address
22873 ENTRY(early_gdt_descr)
22874 .word GDT_ENTRIES*8-1
22875- .long gdt_page /* Overwritten for secondary CPUs */
22876+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
22877
22878 /*
22879 * The boot_gdt must mirror the equivalent in setup.S and is
22880@@ -751,5 +849,65 @@ ENTRY(early_gdt_descr)
22881 .align L1_CACHE_BYTES
22882 ENTRY(boot_gdt)
22883 .fill GDT_ENTRY_BOOT_CS,8,0
22884- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
22885- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
22886+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
22887+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
22888+
22889+ .align PAGE_SIZE_asm
22890+ENTRY(cpu_gdt_table)
22891+ .rept NR_CPUS
22892+ .quad 0x0000000000000000 /* NULL descriptor */
22893+ .quad 0x0000000000000000 /* 0x0b reserved */
22894+ .quad 0x0000000000000000 /* 0x13 reserved */
22895+ .quad 0x0000000000000000 /* 0x1b reserved */
22896+
22897+#ifdef CONFIG_PAX_KERNEXEC
22898+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
22899+#else
22900+ .quad 0x0000000000000000 /* 0x20 unused */
22901+#endif
22902+
22903+ .quad 0x0000000000000000 /* 0x28 unused */
22904+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
22905+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
22906+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
22907+ .quad 0x0000000000000000 /* 0x4b reserved */
22908+ .quad 0x0000000000000000 /* 0x53 reserved */
22909+ .quad 0x0000000000000000 /* 0x5b reserved */
22910+
22911+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
22912+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
22913+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
22914+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
22915+
22916+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
22917+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
22918+
22919+ /*
22920+ * Segments used for calling PnP BIOS have byte granularity.
22921+ * The code segments and data segments have fixed 64k limits,
22922+ * the transfer segment sizes are set at run time.
22923+ */
22924+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
22925+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
22926+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
22927+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
22928+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
22929+
22930+ /*
22931+ * The APM segments have byte granularity and their bases
22932+ * are set at run time. All have 64k limits.
22933+ */
22934+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
22935+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
22936+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
22937+
22938+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
22939+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
22940+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
22941+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
22942+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
22943+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
22944+
22945+ /* Be sure this is zeroed to avoid false validations in Xen */
22946+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
22947+ .endr
22948diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
22949index e1aabdb..73dcad8 100644
22950--- a/arch/x86/kernel/head_64.S
22951+++ b/arch/x86/kernel/head_64.S
22952@@ -20,6 +20,8 @@
22953 #include <asm/processor-flags.h>
22954 #include <asm/percpu.h>
22955 #include <asm/nops.h>
22956+#include <asm/cpufeature.h>
22957+#include <asm/alternative-asm.h>
22958
22959 #ifdef CONFIG_PARAVIRT
22960 #include <asm/asm-offsets.h>
22961@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
22962 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
22963 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
22964 L3_START_KERNEL = pud_index(__START_KERNEL_map)
22965+L4_VMALLOC_START = pgd_index(VMALLOC_START)
22966+L3_VMALLOC_START = pud_index(VMALLOC_START)
22967+L4_VMALLOC_END = pgd_index(VMALLOC_END)
22968+L3_VMALLOC_END = pud_index(VMALLOC_END)
22969+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
22970+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
22971
22972 .text
22973 __HEAD
22974@@ -89,11 +97,23 @@ startup_64:
22975 * Fixup the physical addresses in the page table
22976 */
22977 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
22978+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
22979+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
22980+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
22981+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
22982+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
22983
22984- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
22985- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
22986+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
22987+#ifndef CONFIG_XEN
22988+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
22989+#endif
22990
22991- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
22992+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
22993+
22994+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
22995+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
22996+
22997+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
22998
22999 /*
23000 * Set up the identity mapping for the switchover. These
23001@@ -177,8 +197,8 @@ ENTRY(secondary_startup_64)
23002 movq $(init_level4_pgt - __START_KERNEL_map), %rax
23003 1:
23004
23005- /* Enable PAE mode and PGE */
23006- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
23007+ /* Enable PAE mode and PSE/PGE */
23008+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
23009 movq %rcx, %cr4
23010
23011 /* Setup early boot stage 4 level pagetables. */
23012@@ -199,10 +219,18 @@ ENTRY(secondary_startup_64)
23013 movl $MSR_EFER, %ecx
23014 rdmsr
23015 btsl $_EFER_SCE, %eax /* Enable System Call */
23016- btl $20,%edi /* No Execute supported? */
23017+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
23018 jnc 1f
23019 btsl $_EFER_NX, %eax
23020 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
23021+ leaq init_level4_pgt(%rip), %rdi
23022+#ifndef CONFIG_EFI
23023+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
23024+#endif
23025+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
23026+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
23027+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
23028+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
23029 1: wrmsr /* Make changes effective */
23030
23031 /* Setup cr0 */
23032@@ -282,6 +310,7 @@ ENTRY(secondary_startup_64)
23033 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
23034 * address given in m16:64.
23035 */
23036+ pax_set_fptr_mask
23037 movq initial_code(%rip),%rax
23038 pushq $0 # fake return address to stop unwinder
23039 pushq $__KERNEL_CS # set correct cs
23040@@ -388,7 +417,7 @@ ENTRY(early_idt_handler)
23041 call dump_stack
23042 #ifdef CONFIG_KALLSYMS
23043 leaq early_idt_ripmsg(%rip),%rdi
23044- movq 40(%rsp),%rsi # %rip again
23045+ movq 88(%rsp),%rsi # %rip again
23046 call __print_symbol
23047 #endif
23048 #endif /* EARLY_PRINTK */
23049@@ -416,6 +445,7 @@ ENDPROC(early_idt_handler)
23050 early_recursion_flag:
23051 .long 0
23052
23053+ .section .rodata,"a",@progbits
23054 #ifdef CONFIG_EARLY_PRINTK
23055 early_idt_msg:
23056 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
23057@@ -443,29 +473,52 @@ NEXT_PAGE(early_level4_pgt)
23058 NEXT_PAGE(early_dynamic_pgts)
23059 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
23060
23061- .data
23062+ .section .rodata,"a",@progbits
23063
23064-#ifndef CONFIG_XEN
23065 NEXT_PAGE(init_level4_pgt)
23066- .fill 512,8,0
23067-#else
23068-NEXT_PAGE(init_level4_pgt)
23069- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23070 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
23071 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23072+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
23073+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
23074+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
23075+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
23076+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
23077+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23078 .org init_level4_pgt + L4_START_KERNEL*8, 0
23079 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
23080 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
23081
23082+#ifdef CONFIG_PAX_PER_CPU_PGD
23083+NEXT_PAGE(cpu_pgd)
23084+ .rept 2*NR_CPUS
23085+ .fill 512,8,0
23086+ .endr
23087+#endif
23088+
23089 NEXT_PAGE(level3_ident_pgt)
23090 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23091+#ifdef CONFIG_XEN
23092 .fill 511, 8, 0
23093+#else
23094+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
23095+ .fill 510,8,0
23096+#endif
23097+
23098+NEXT_PAGE(level3_vmalloc_start_pgt)
23099+ .fill 512,8,0
23100+
23101+NEXT_PAGE(level3_vmalloc_end_pgt)
23102+ .fill 512,8,0
23103+
23104+NEXT_PAGE(level3_vmemmap_pgt)
23105+ .fill L3_VMEMMAP_START,8,0
23106+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23107+
23108 NEXT_PAGE(level2_ident_pgt)
23109- /* Since I easily can, map the first 1G.
23110+ /* Since I easily can, map the first 2G.
23111 * Don't set NX because code runs from these pages.
23112 */
23113- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
23114-#endif
23115+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
23116
23117 NEXT_PAGE(level3_kernel_pgt)
23118 .fill L3_START_KERNEL,8,0
23119@@ -473,6 +526,9 @@ NEXT_PAGE(level3_kernel_pgt)
23120 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
23121 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23122
23123+NEXT_PAGE(level2_vmemmap_pgt)
23124+ .fill 512,8,0
23125+
23126 NEXT_PAGE(level2_kernel_pgt)
23127 /*
23128 * 512 MB kernel mapping. We spend a full page on this pagetable
23129@@ -488,30 +544,62 @@ NEXT_PAGE(level2_kernel_pgt)
23130 KERNEL_IMAGE_SIZE/PMD_SIZE)
23131
23132 NEXT_PAGE(level2_fixmap_pgt)
23133- .fill 506,8,0
23134- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23135- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
23136- .fill 5,8,0
23137+ .fill 507,8,0
23138+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
23139+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
23140+ .fill 4,8,0
23141
23142-NEXT_PAGE(level1_fixmap_pgt)
23143+NEXT_PAGE(level1_vsyscall_pgt)
23144 .fill 512,8,0
23145
23146 #undef PMDS
23147
23148- .data
23149+ .align PAGE_SIZE
23150+ENTRY(cpu_gdt_table)
23151+ .rept NR_CPUS
23152+ .quad 0x0000000000000000 /* NULL descriptor */
23153+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
23154+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
23155+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
23156+ .quad 0x00cffb000000ffff /* __USER32_CS */
23157+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
23158+ .quad 0x00affb000000ffff /* __USER_CS */
23159+
23160+#ifdef CONFIG_PAX_KERNEXEC
23161+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
23162+#else
23163+ .quad 0x0 /* unused */
23164+#endif
23165+
23166+ .quad 0,0 /* TSS */
23167+ .quad 0,0 /* LDT */
23168+ .quad 0,0,0 /* three TLS descriptors */
23169+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
23170+ /* asm/segment.h:GDT_ENTRIES must match this */
23171+
23172+#ifdef CONFIG_PAX_MEMORY_UDEREF
23173+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
23174+#else
23175+ .quad 0x0 /* unused */
23176+#endif
23177+
23178+ /* zero the remaining page */
23179+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
23180+ .endr
23181+
23182 .align 16
23183 .globl early_gdt_descr
23184 early_gdt_descr:
23185 .word GDT_ENTRIES*8-1
23186 early_gdt_descr_base:
23187- .quad INIT_PER_CPU_VAR(gdt_page)
23188+ .quad cpu_gdt_table
23189
23190 ENTRY(phys_base)
23191 /* This must match the first entry in level2_kernel_pgt */
23192 .quad 0x0000000000000000
23193
23194 #include "../../x86/xen/xen-head.S"
23195-
23196- __PAGE_ALIGNED_BSS
23197+
23198+ .section .rodata,"a",@progbits
23199 NEXT_PAGE(empty_zero_page)
23200 .skip PAGE_SIZE
23201diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
23202index 0fa6912..b37438b 100644
23203--- a/arch/x86/kernel/i386_ksyms_32.c
23204+++ b/arch/x86/kernel/i386_ksyms_32.c
23205@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
23206 EXPORT_SYMBOL(cmpxchg8b_emu);
23207 #endif
23208
23209+EXPORT_SYMBOL_GPL(cpu_gdt_table);
23210+
23211 /* Networking helper routines. */
23212 EXPORT_SYMBOL(csum_partial_copy_generic);
23213+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
23214+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
23215
23216 EXPORT_SYMBOL(__get_user_1);
23217 EXPORT_SYMBOL(__get_user_2);
23218@@ -37,3 +41,11 @@ EXPORT_SYMBOL(strstr);
23219
23220 EXPORT_SYMBOL(csum_partial);
23221 EXPORT_SYMBOL(empty_zero_page);
23222+
23223+#ifdef CONFIG_PAX_KERNEXEC
23224+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
23225+#endif
23226+
23227+#ifdef CONFIG_PAX_PER_CPU_PGD
23228+EXPORT_SYMBOL(cpu_pgd);
23229+#endif
23230diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
23231index 5d576ab..1403a03 100644
23232--- a/arch/x86/kernel/i387.c
23233+++ b/arch/x86/kernel/i387.c
23234@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
23235 static inline bool interrupted_user_mode(void)
23236 {
23237 struct pt_regs *regs = get_irq_regs();
23238- return regs && user_mode_vm(regs);
23239+ return regs && user_mode(regs);
23240 }
23241
23242 /*
23243diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
23244index 9a5c460..84868423 100644
23245--- a/arch/x86/kernel/i8259.c
23246+++ b/arch/x86/kernel/i8259.c
23247@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
23248 static void make_8259A_irq(unsigned int irq)
23249 {
23250 disable_irq_nosync(irq);
23251- io_apic_irqs &= ~(1<<irq);
23252+ io_apic_irqs &= ~(1UL<<irq);
23253 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
23254 i8259A_chip.name);
23255 enable_irq(irq);
23256@@ -209,7 +209,7 @@ spurious_8259A_irq:
23257 "spurious 8259A interrupt: IRQ%d.\n", irq);
23258 spurious_irq_mask |= irqmask;
23259 }
23260- atomic_inc(&irq_err_count);
23261+ atomic_inc_unchecked(&irq_err_count);
23262 /*
23263 * Theoretically we do not have to handle this IRQ,
23264 * but in Linux this does not cause problems and is
23265@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
23266 /* (slave's support for AEOI in flat mode is to be investigated) */
23267 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
23268
23269+ pax_open_kernel();
23270 if (auto_eoi)
23271 /*
23272 * In AEOI mode we just have to mask the interrupt
23273 * when acking.
23274 */
23275- i8259A_chip.irq_mask_ack = disable_8259A_irq;
23276+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
23277 else
23278- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23279+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23280+ pax_close_kernel();
23281
23282 udelay(100); /* wait for 8259A to initialize */
23283
23284diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
23285index a979b5b..1d6db75 100644
23286--- a/arch/x86/kernel/io_delay.c
23287+++ b/arch/x86/kernel/io_delay.c
23288@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
23289 * Quirk table for systems that misbehave (lock up, etc.) if port
23290 * 0x80 is used:
23291 */
23292-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
23293+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
23294 {
23295 .callback = dmi_io_delay_0xed_port,
23296 .ident = "Compaq Presario V6000",
23297diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
23298index 4ddaf66..6292f4e 100644
23299--- a/arch/x86/kernel/ioport.c
23300+++ b/arch/x86/kernel/ioport.c
23301@@ -6,6 +6,7 @@
23302 #include <linux/sched.h>
23303 #include <linux/kernel.h>
23304 #include <linux/capability.h>
23305+#include <linux/security.h>
23306 #include <linux/errno.h>
23307 #include <linux/types.h>
23308 #include <linux/ioport.h>
23309@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23310
23311 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
23312 return -EINVAL;
23313+#ifdef CONFIG_GRKERNSEC_IO
23314+ if (turn_on && grsec_disable_privio) {
23315+ gr_handle_ioperm();
23316+ return -EPERM;
23317+ }
23318+#endif
23319 if (turn_on && !capable(CAP_SYS_RAWIO))
23320 return -EPERM;
23321
23322@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23323 * because the ->io_bitmap_max value must match the bitmap
23324 * contents:
23325 */
23326- tss = &per_cpu(init_tss, get_cpu());
23327+ tss = init_tss + get_cpu();
23328
23329 if (turn_on)
23330 bitmap_clear(t->io_bitmap_ptr, from, num);
23331@@ -103,6 +110,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
23332 return -EINVAL;
23333 /* Trying to gain more privileges? */
23334 if (level > old) {
23335+#ifdef CONFIG_GRKERNSEC_IO
23336+ if (grsec_disable_privio) {
23337+ gr_handle_iopl();
23338+ return -EPERM;
23339+ }
23340+#endif
23341 if (!capable(CAP_SYS_RAWIO))
23342 return -EPERM;
23343 }
23344diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
23345index 3a8185c..3c042ee 100644
23346--- a/arch/x86/kernel/irq.c
23347+++ b/arch/x86/kernel/irq.c
23348@@ -21,7 +21,7 @@
23349 #define CREATE_TRACE_POINTS
23350 #include <asm/trace/irq_vectors.h>
23351
23352-atomic_t irq_err_count;
23353+atomic_unchecked_t irq_err_count;
23354
23355 /* Function pointer for generic interrupt vector handling */
23356 void (*x86_platform_ipi_callback)(void) = NULL;
23357@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
23358 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
23359 seq_printf(p, " Machine check polls\n");
23360 #endif
23361- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
23362+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
23363 #if defined(CONFIG_X86_IO_APIC)
23364- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
23365+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
23366 #endif
23367 return 0;
23368 }
23369@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
23370
23371 u64 arch_irq_stat(void)
23372 {
23373- u64 sum = atomic_read(&irq_err_count);
23374+ u64 sum = atomic_read_unchecked(&irq_err_count);
23375 return sum;
23376 }
23377
23378diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
23379index 4186755..784efa0 100644
23380--- a/arch/x86/kernel/irq_32.c
23381+++ b/arch/x86/kernel/irq_32.c
23382@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
23383 __asm__ __volatile__("andl %%esp,%0" :
23384 "=r" (sp) : "0" (THREAD_SIZE - 1));
23385
23386- return sp < (sizeof(struct thread_info) + STACK_WARN);
23387+ return sp < STACK_WARN;
23388 }
23389
23390 static void print_stack_overflow(void)
23391@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
23392 * per-CPU IRQ handling contexts (thread information and stack)
23393 */
23394 union irq_ctx {
23395- struct thread_info tinfo;
23396- u32 stack[THREAD_SIZE/sizeof(u32)];
23397+ unsigned long previous_esp;
23398+ u32 stack[THREAD_SIZE/sizeof(u32)];
23399 } __attribute__((aligned(THREAD_SIZE)));
23400
23401 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
23402@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
23403 static inline int
23404 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23405 {
23406- union irq_ctx *curctx, *irqctx;
23407+ union irq_ctx *irqctx;
23408 u32 *isp, arg1, arg2;
23409
23410- curctx = (union irq_ctx *) current_thread_info();
23411 irqctx = __this_cpu_read(hardirq_ctx);
23412
23413 /*
23414@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23415 * handler) we can't do that and just have to keep using the
23416 * current stack (which is the irq stack already after all)
23417 */
23418- if (unlikely(curctx == irqctx))
23419+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
23420 return 0;
23421
23422 /* build the stack frame on the IRQ stack */
23423- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23424- irqctx->tinfo.task = curctx->tinfo.task;
23425- irqctx->tinfo.previous_esp = current_stack_pointer;
23426+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23427+ irqctx->previous_esp = current_stack_pointer;
23428
23429- /* Copy the preempt_count so that the [soft]irq checks work. */
23430- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
23431+#ifdef CONFIG_PAX_MEMORY_UDEREF
23432+ __set_fs(MAKE_MM_SEG(0));
23433+#endif
23434
23435 if (unlikely(overflow))
23436 call_on_stack(print_stack_overflow, isp);
23437@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23438 : "0" (irq), "1" (desc), "2" (isp),
23439 "D" (desc->handle_irq)
23440 : "memory", "cc", "ecx");
23441+
23442+#ifdef CONFIG_PAX_MEMORY_UDEREF
23443+ __set_fs(current_thread_info()->addr_limit);
23444+#endif
23445+
23446 return 1;
23447 }
23448
23449@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23450 */
23451 void irq_ctx_init(int cpu)
23452 {
23453- union irq_ctx *irqctx;
23454-
23455 if (per_cpu(hardirq_ctx, cpu))
23456 return;
23457
23458- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23459- THREADINFO_GFP,
23460- THREAD_SIZE_ORDER));
23461- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23462- irqctx->tinfo.cpu = cpu;
23463- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
23464- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23465+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23466+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23467
23468- per_cpu(hardirq_ctx, cpu) = irqctx;
23469-
23470- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23471- THREADINFO_GFP,
23472- THREAD_SIZE_ORDER));
23473- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23474- irqctx->tinfo.cpu = cpu;
23475- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23476-
23477- per_cpu(softirq_ctx, cpu) = irqctx;
23478+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23479+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23480
23481 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23482 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23483@@ -152,7 +141,6 @@ void irq_ctx_init(int cpu)
23484 asmlinkage void do_softirq(void)
23485 {
23486 unsigned long flags;
23487- struct thread_info *curctx;
23488 union irq_ctx *irqctx;
23489 u32 *isp;
23490
23491@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
23492 local_irq_save(flags);
23493
23494 if (local_softirq_pending()) {
23495- curctx = current_thread_info();
23496 irqctx = __this_cpu_read(softirq_ctx);
23497- irqctx->tinfo.task = curctx->task;
23498- irqctx->tinfo.previous_esp = current_stack_pointer;
23499+ irqctx->previous_esp = current_stack_pointer;
23500
23501 /* build the stack frame on the softirq stack */
23502- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23503+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23504+
23505+#ifdef CONFIG_PAX_MEMORY_UDEREF
23506+ __set_fs(MAKE_MM_SEG(0));
23507+#endif
23508
23509 call_on_stack(__do_softirq, isp);
23510+
23511+#ifdef CONFIG_PAX_MEMORY_UDEREF
23512+ __set_fs(current_thread_info()->addr_limit);
23513+#endif
23514+
23515 /*
23516 * Shouldn't happen, we returned above if in_interrupt():
23517 */
23518@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
23519 if (unlikely(!desc))
23520 return false;
23521
23522- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23523+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23524 if (unlikely(overflow))
23525 print_stack_overflow();
23526 desc->handle_irq(irq, desc);
23527diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
23528index d04d3ec..ea4b374 100644
23529--- a/arch/x86/kernel/irq_64.c
23530+++ b/arch/x86/kernel/irq_64.c
23531@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
23532 u64 estack_top, estack_bottom;
23533 u64 curbase = (u64)task_stack_page(current);
23534
23535- if (user_mode_vm(regs))
23536+ if (user_mode(regs))
23537 return;
23538
23539 if (regs->sp >= curbase + sizeof(struct thread_info) +
23540diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
23541index dc1404b..bbc43e7 100644
23542--- a/arch/x86/kernel/kdebugfs.c
23543+++ b/arch/x86/kernel/kdebugfs.c
23544@@ -27,7 +27,7 @@ struct setup_data_node {
23545 u32 len;
23546 };
23547
23548-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
23549+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
23550 size_t count, loff_t *ppos)
23551 {
23552 struct setup_data_node *node = file->private_data;
23553diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
23554index 836f832..a8bda67 100644
23555--- a/arch/x86/kernel/kgdb.c
23556+++ b/arch/x86/kernel/kgdb.c
23557@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
23558 #ifdef CONFIG_X86_32
23559 switch (regno) {
23560 case GDB_SS:
23561- if (!user_mode_vm(regs))
23562+ if (!user_mode(regs))
23563 *(unsigned long *)mem = __KERNEL_DS;
23564 break;
23565 case GDB_SP:
23566- if (!user_mode_vm(regs))
23567+ if (!user_mode(regs))
23568 *(unsigned long *)mem = kernel_stack_pointer(regs);
23569 break;
23570 case GDB_GS:
23571@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
23572 bp->attr.bp_addr = breakinfo[breakno].addr;
23573 bp->attr.bp_len = breakinfo[breakno].len;
23574 bp->attr.bp_type = breakinfo[breakno].type;
23575- info->address = breakinfo[breakno].addr;
23576+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
23577+ info->address = ktla_ktva(breakinfo[breakno].addr);
23578+ else
23579+ info->address = breakinfo[breakno].addr;
23580 info->len = breakinfo[breakno].len;
23581 info->type = breakinfo[breakno].type;
23582 val = arch_install_hw_breakpoint(bp);
23583@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
23584 case 'k':
23585 /* clear the trace bit */
23586 linux_regs->flags &= ~X86_EFLAGS_TF;
23587- atomic_set(&kgdb_cpu_doing_single_step, -1);
23588+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
23589
23590 /* set the trace bit if we're stepping */
23591 if (remcomInBuffer[0] == 's') {
23592 linux_regs->flags |= X86_EFLAGS_TF;
23593- atomic_set(&kgdb_cpu_doing_single_step,
23594+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
23595 raw_smp_processor_id());
23596 }
23597
23598@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
23599
23600 switch (cmd) {
23601 case DIE_DEBUG:
23602- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
23603+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
23604 if (user_mode(regs))
23605 return single_step_cont(regs, args);
23606 break;
23607@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23608 #endif /* CONFIG_DEBUG_RODATA */
23609
23610 bpt->type = BP_BREAKPOINT;
23611- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
23612+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
23613 BREAK_INSTR_SIZE);
23614 if (err)
23615 return err;
23616- err = probe_kernel_write((char *)bpt->bpt_addr,
23617+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23618 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
23619 #ifdef CONFIG_DEBUG_RODATA
23620 if (!err)
23621@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23622 return -EBUSY;
23623 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
23624 BREAK_INSTR_SIZE);
23625- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23626+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23627 if (err)
23628 return err;
23629 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
23630@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
23631 if (mutex_is_locked(&text_mutex))
23632 goto knl_write;
23633 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
23634- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23635+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23636 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
23637 goto knl_write;
23638 return err;
23639 knl_write:
23640 #endif /* CONFIG_DEBUG_RODATA */
23641- return probe_kernel_write((char *)bpt->bpt_addr,
23642+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23643 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
23644 }
23645
23646diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
23647index 211bce4..6e2580a 100644
23648--- a/arch/x86/kernel/kprobes/core.c
23649+++ b/arch/x86/kernel/kprobes/core.c
23650@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
23651 s32 raddr;
23652 } __packed *insn;
23653
23654- insn = (struct __arch_relative_insn *)from;
23655+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
23656+
23657+ pax_open_kernel();
23658 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
23659 insn->op = op;
23660+ pax_close_kernel();
23661 }
23662
23663 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
23664@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
23665 kprobe_opcode_t opcode;
23666 kprobe_opcode_t *orig_opcodes = opcodes;
23667
23668- if (search_exception_tables((unsigned long)opcodes))
23669+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
23670 return 0; /* Page fault may occur on this address. */
23671
23672 retry:
23673@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
23674 * for the first byte, we can recover the original instruction
23675 * from it and kp->opcode.
23676 */
23677- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23678+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23679 buf[0] = kp->opcode;
23680- return (unsigned long)buf;
23681+ return ktva_ktla((unsigned long)buf);
23682 }
23683
23684 /*
23685@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23686 /* Another subsystem puts a breakpoint, failed to recover */
23687 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
23688 return 0;
23689+ pax_open_kernel();
23690 memcpy(dest, insn.kaddr, insn.length);
23691+ pax_close_kernel();
23692
23693 #ifdef CONFIG_X86_64
23694 if (insn_rip_relative(&insn)) {
23695@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23696 return 0;
23697 }
23698 disp = (u8 *) dest + insn_offset_displacement(&insn);
23699+ pax_open_kernel();
23700 *(s32 *) disp = (s32) newdisp;
23701+ pax_close_kernel();
23702 }
23703 #endif
23704 return insn.length;
23705@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23706 * nor set current_kprobe, because it doesn't use single
23707 * stepping.
23708 */
23709- regs->ip = (unsigned long)p->ainsn.insn;
23710+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23711 preempt_enable_no_resched();
23712 return;
23713 }
23714@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23715 regs->flags &= ~X86_EFLAGS_IF;
23716 /* single step inline if the instruction is an int3 */
23717 if (p->opcode == BREAKPOINT_INSTRUCTION)
23718- regs->ip = (unsigned long)p->addr;
23719+ regs->ip = ktla_ktva((unsigned long)p->addr);
23720 else
23721- regs->ip = (unsigned long)p->ainsn.insn;
23722+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23723 }
23724
23725 /*
23726@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
23727 setup_singlestep(p, regs, kcb, 0);
23728 return 1;
23729 }
23730- } else if (*addr != BREAKPOINT_INSTRUCTION) {
23731+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
23732 /*
23733 * The breakpoint instruction was removed right
23734 * after we hit it. Another cpu has removed
23735@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
23736 " movq %rax, 152(%rsp)\n"
23737 RESTORE_REGS_STRING
23738 " popfq\n"
23739+#ifdef KERNEXEC_PLUGIN
23740+ " btsq $63,(%rsp)\n"
23741+#endif
23742 #else
23743 " pushf\n"
23744 SAVE_REGS_STRING
23745@@ -779,7 +789,7 @@ static void __kprobes
23746 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
23747 {
23748 unsigned long *tos = stack_addr(regs);
23749- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
23750+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
23751 unsigned long orig_ip = (unsigned long)p->addr;
23752 kprobe_opcode_t *insn = p->ainsn.insn;
23753
23754@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
23755 struct die_args *args = data;
23756 int ret = NOTIFY_DONE;
23757
23758- if (args->regs && user_mode_vm(args->regs))
23759+ if (args->regs && user_mode(args->regs))
23760 return ret;
23761
23762 switch (val) {
23763diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
23764index 76dc6f0..66bdfc3 100644
23765--- a/arch/x86/kernel/kprobes/opt.c
23766+++ b/arch/x86/kernel/kprobes/opt.c
23767@@ -79,6 +79,7 @@ found:
23768 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
23769 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
23770 {
23771+ pax_open_kernel();
23772 #ifdef CONFIG_X86_64
23773 *addr++ = 0x48;
23774 *addr++ = 0xbf;
23775@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
23776 *addr++ = 0xb8;
23777 #endif
23778 *(unsigned long *)addr = val;
23779+ pax_close_kernel();
23780 }
23781
23782 static void __used __kprobes kprobes_optinsn_template_holder(void)
23783@@ -338,7 +340,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23784 * Verify if the address gap is in 2GB range, because this uses
23785 * a relative jump.
23786 */
23787- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
23788+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
23789 if (abs(rel) > 0x7fffffff)
23790 return -ERANGE;
23791
23792@@ -353,16 +355,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23793 op->optinsn.size = ret;
23794
23795 /* Copy arch-dep-instance from template */
23796- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
23797+ pax_open_kernel();
23798+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
23799+ pax_close_kernel();
23800
23801 /* Set probe information */
23802 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
23803
23804 /* Set probe function call */
23805- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
23806+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
23807
23808 /* Set returning jmp instruction at the tail of out-of-line buffer */
23809- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
23810+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
23811 (u8 *)op->kp.addr + op->optinsn.size);
23812
23813 flush_icache_range((unsigned long) buf,
23814@@ -385,7 +389,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
23815 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
23816
23817 /* Backup instructions which will be replaced by jump address */
23818- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
23819+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
23820 RELATIVE_ADDR_SIZE);
23821
23822 insn_buf[0] = RELATIVEJUMP_OPCODE;
23823@@ -483,7 +487,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
23824 /* This kprobe is really able to run optimized path. */
23825 op = container_of(p, struct optimized_kprobe, kp);
23826 /* Detour through copied instructions */
23827- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
23828+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
23829 if (!reenter)
23830 reset_current_kprobe();
23831 preempt_enable_no_resched();
23832diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
23833index ebc9873..1b9724b 100644
23834--- a/arch/x86/kernel/ldt.c
23835+++ b/arch/x86/kernel/ldt.c
23836@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
23837 if (reload) {
23838 #ifdef CONFIG_SMP
23839 preempt_disable();
23840- load_LDT(pc);
23841+ load_LDT_nolock(pc);
23842 if (!cpumask_equal(mm_cpumask(current->mm),
23843 cpumask_of(smp_processor_id())))
23844 smp_call_function(flush_ldt, current->mm, 1);
23845 preempt_enable();
23846 #else
23847- load_LDT(pc);
23848+ load_LDT_nolock(pc);
23849 #endif
23850 }
23851 if (oldsize) {
23852@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
23853 return err;
23854
23855 for (i = 0; i < old->size; i++)
23856- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
23857+ write_ldt_entry(new->ldt, i, old->ldt + i);
23858 return 0;
23859 }
23860
23861@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
23862 retval = copy_ldt(&mm->context, &old_mm->context);
23863 mutex_unlock(&old_mm->context.lock);
23864 }
23865+
23866+ if (tsk == current) {
23867+ mm->context.vdso = 0;
23868+
23869+#ifdef CONFIG_X86_32
23870+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23871+ mm->context.user_cs_base = 0UL;
23872+ mm->context.user_cs_limit = ~0UL;
23873+
23874+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
23875+ cpus_clear(mm->context.cpu_user_cs_mask);
23876+#endif
23877+
23878+#endif
23879+#endif
23880+
23881+ }
23882+
23883 return retval;
23884 }
23885
23886@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
23887 }
23888 }
23889
23890+#ifdef CONFIG_PAX_SEGMEXEC
23891+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
23892+ error = -EINVAL;
23893+ goto out_unlock;
23894+ }
23895+#endif
23896+
23897 fill_ldt(&ldt, &ldt_info);
23898 if (oldmode)
23899 ldt.avl = 0;
23900diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
23901index 5b19e4d..6476a76 100644
23902--- a/arch/x86/kernel/machine_kexec_32.c
23903+++ b/arch/x86/kernel/machine_kexec_32.c
23904@@ -26,7 +26,7 @@
23905 #include <asm/cacheflush.h>
23906 #include <asm/debugreg.h>
23907
23908-static void set_idt(void *newidt, __u16 limit)
23909+static void set_idt(struct desc_struct *newidt, __u16 limit)
23910 {
23911 struct desc_ptr curidt;
23912
23913@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
23914 }
23915
23916
23917-static void set_gdt(void *newgdt, __u16 limit)
23918+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
23919 {
23920 struct desc_ptr curgdt;
23921
23922@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
23923 }
23924
23925 control_page = page_address(image->control_code_page);
23926- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
23927+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
23928
23929 relocate_kernel_ptr = control_page;
23930 page_list[PA_CONTROL_PAGE] = __pa(control_page);
23931diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
23932index 15c9876..0a43909 100644
23933--- a/arch/x86/kernel/microcode_core.c
23934+++ b/arch/x86/kernel/microcode_core.c
23935@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
23936 return NOTIFY_OK;
23937 }
23938
23939-static struct notifier_block __refdata mc_cpu_notifier = {
23940+static struct notifier_block mc_cpu_notifier = {
23941 .notifier_call = mc_cpu_callback,
23942 };
23943
23944diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
23945index 5fb2ceb..3ae90bb 100644
23946--- a/arch/x86/kernel/microcode_intel.c
23947+++ b/arch/x86/kernel/microcode_intel.c
23948@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
23949
23950 static int get_ucode_user(void *to, const void *from, size_t n)
23951 {
23952- return copy_from_user(to, from, n);
23953+ return copy_from_user(to, (const void __force_user *)from, n);
23954 }
23955
23956 static enum ucode_state
23957 request_microcode_user(int cpu, const void __user *buf, size_t size)
23958 {
23959- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
23960+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
23961 }
23962
23963 static void microcode_fini_cpu(int cpu)
23964diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
23965index 216a4d7..228255a 100644
23966--- a/arch/x86/kernel/module.c
23967+++ b/arch/x86/kernel/module.c
23968@@ -43,15 +43,60 @@ do { \
23969 } while (0)
23970 #endif
23971
23972-void *module_alloc(unsigned long size)
23973+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
23974 {
23975- if (PAGE_ALIGN(size) > MODULES_LEN)
23976+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
23977 return NULL;
23978 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
23979- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
23980+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
23981 -1, __builtin_return_address(0));
23982 }
23983
23984+void *module_alloc(unsigned long size)
23985+{
23986+
23987+#ifdef CONFIG_PAX_KERNEXEC
23988+ return __module_alloc(size, PAGE_KERNEL);
23989+#else
23990+ return __module_alloc(size, PAGE_KERNEL_EXEC);
23991+#endif
23992+
23993+}
23994+
23995+#ifdef CONFIG_PAX_KERNEXEC
23996+#ifdef CONFIG_X86_32
23997+void *module_alloc_exec(unsigned long size)
23998+{
23999+ struct vm_struct *area;
24000+
24001+ if (size == 0)
24002+ return NULL;
24003+
24004+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
24005+ return area ? area->addr : NULL;
24006+}
24007+EXPORT_SYMBOL(module_alloc_exec);
24008+
24009+void module_free_exec(struct module *mod, void *module_region)
24010+{
24011+ vunmap(module_region);
24012+}
24013+EXPORT_SYMBOL(module_free_exec);
24014+#else
24015+void module_free_exec(struct module *mod, void *module_region)
24016+{
24017+ module_free(mod, module_region);
24018+}
24019+EXPORT_SYMBOL(module_free_exec);
24020+
24021+void *module_alloc_exec(unsigned long size)
24022+{
24023+ return __module_alloc(size, PAGE_KERNEL_RX);
24024+}
24025+EXPORT_SYMBOL(module_alloc_exec);
24026+#endif
24027+#endif
24028+
24029 #ifdef CONFIG_X86_32
24030 int apply_relocate(Elf32_Shdr *sechdrs,
24031 const char *strtab,
24032@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24033 unsigned int i;
24034 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
24035 Elf32_Sym *sym;
24036- uint32_t *location;
24037+ uint32_t *plocation, location;
24038
24039 DEBUGP("Applying relocate section %u to %u\n",
24040 relsec, sechdrs[relsec].sh_info);
24041 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
24042 /* This is where to make the change */
24043- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
24044- + rel[i].r_offset;
24045+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
24046+ location = (uint32_t)plocation;
24047+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
24048+ plocation = ktla_ktva((void *)plocation);
24049 /* This is the symbol it is referring to. Note that all
24050 undefined symbols have been resolved. */
24051 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
24052@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24053 switch (ELF32_R_TYPE(rel[i].r_info)) {
24054 case R_386_32:
24055 /* We add the value into the location given */
24056- *location += sym->st_value;
24057+ pax_open_kernel();
24058+ *plocation += sym->st_value;
24059+ pax_close_kernel();
24060 break;
24061 case R_386_PC32:
24062 /* Add the value, subtract its position */
24063- *location += sym->st_value - (uint32_t)location;
24064+ pax_open_kernel();
24065+ *plocation += sym->st_value - location;
24066+ pax_close_kernel();
24067 break;
24068 default:
24069 pr_err("%s: Unknown relocation: %u\n",
24070@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
24071 case R_X86_64_NONE:
24072 break;
24073 case R_X86_64_64:
24074+ pax_open_kernel();
24075 *(u64 *)loc = val;
24076+ pax_close_kernel();
24077 break;
24078 case R_X86_64_32:
24079+ pax_open_kernel();
24080 *(u32 *)loc = val;
24081+ pax_close_kernel();
24082 if (val != *(u32 *)loc)
24083 goto overflow;
24084 break;
24085 case R_X86_64_32S:
24086+ pax_open_kernel();
24087 *(s32 *)loc = val;
24088+ pax_close_kernel();
24089 if ((s64)val != *(s32 *)loc)
24090 goto overflow;
24091 break;
24092 case R_X86_64_PC32:
24093 val -= (u64)loc;
24094+ pax_open_kernel();
24095 *(u32 *)loc = val;
24096+ pax_close_kernel();
24097+
24098 #if 0
24099 if ((s64)val != *(s32 *)loc)
24100 goto overflow;
24101diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
24102index 88458fa..349f7a4 100644
24103--- a/arch/x86/kernel/msr.c
24104+++ b/arch/x86/kernel/msr.c
24105@@ -233,7 +233,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
24106 return notifier_from_errno(err);
24107 }
24108
24109-static struct notifier_block __refdata msr_class_cpu_notifier = {
24110+static struct notifier_block msr_class_cpu_notifier = {
24111 .notifier_call = msr_class_cpu_callback,
24112 };
24113
24114diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
24115index ba77ebc..65da999 100644
24116--- a/arch/x86/kernel/nmi.c
24117+++ b/arch/x86/kernel/nmi.c
24118@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
24119 return handled;
24120 }
24121
24122-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24123+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
24124 {
24125 struct nmi_desc *desc = nmi_to_desc(type);
24126 unsigned long flags;
24127@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24128 * event confuses some handlers (kdump uses this flag)
24129 */
24130 if (action->flags & NMI_FLAG_FIRST)
24131- list_add_rcu(&action->list, &desc->head);
24132+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
24133 else
24134- list_add_tail_rcu(&action->list, &desc->head);
24135+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
24136
24137 spin_unlock_irqrestore(&desc->lock, flags);
24138 return 0;
24139@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
24140 if (!strcmp(n->name, name)) {
24141 WARN(in_nmi(),
24142 "Trying to free NMI (%s) from NMI context!\n", n->name);
24143- list_del_rcu(&n->list);
24144+ pax_list_del_rcu((struct list_head *)&n->list);
24145 break;
24146 }
24147 }
24148@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
24149 dotraplinkage notrace __kprobes void
24150 do_nmi(struct pt_regs *regs, long error_code)
24151 {
24152+
24153+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24154+ if (!user_mode(regs)) {
24155+ unsigned long cs = regs->cs & 0xFFFF;
24156+ unsigned long ip = ktva_ktla(regs->ip);
24157+
24158+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
24159+ regs->ip = ip;
24160+ }
24161+#endif
24162+
24163 nmi_nesting_preprocess(regs);
24164
24165 nmi_enter();
24166diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
24167index 6d9582e..f746287 100644
24168--- a/arch/x86/kernel/nmi_selftest.c
24169+++ b/arch/x86/kernel/nmi_selftest.c
24170@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
24171 {
24172 /* trap all the unknown NMIs we may generate */
24173 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
24174- __initdata);
24175+ __initconst);
24176 }
24177
24178 static void __init cleanup_nmi_testsuite(void)
24179@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
24180 unsigned long timeout;
24181
24182 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
24183- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
24184+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
24185 nmi_fail = FAILURE;
24186 return;
24187 }
24188diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
24189index 676b8c7..870ba04 100644
24190--- a/arch/x86/kernel/paravirt-spinlocks.c
24191+++ b/arch/x86/kernel/paravirt-spinlocks.c
24192@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
24193 arch_spin_lock(lock);
24194 }
24195
24196-struct pv_lock_ops pv_lock_ops = {
24197+struct pv_lock_ops pv_lock_ops __read_only = {
24198 #ifdef CONFIG_SMP
24199 .spin_is_locked = __ticket_spin_is_locked,
24200 .spin_is_contended = __ticket_spin_is_contended,
24201diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
24202index cd6de64..27c6af0 100644
24203--- a/arch/x86/kernel/paravirt.c
24204+++ b/arch/x86/kernel/paravirt.c
24205@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
24206 {
24207 return x;
24208 }
24209+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24210+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
24211+#endif
24212
24213 void __init default_banner(void)
24214 {
24215@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
24216 if (opfunc == NULL)
24217 /* If there's no function, patch it with a ud2a (BUG) */
24218 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
24219- else if (opfunc == _paravirt_nop)
24220+ else if (opfunc == (void *)_paravirt_nop)
24221 /* If the operation is a nop, then nop the callsite */
24222 ret = paravirt_patch_nop();
24223
24224 /* identity functions just return their single argument */
24225- else if (opfunc == _paravirt_ident_32)
24226+ else if (opfunc == (void *)_paravirt_ident_32)
24227 ret = paravirt_patch_ident_32(insnbuf, len);
24228- else if (opfunc == _paravirt_ident_64)
24229+ else if (opfunc == (void *)_paravirt_ident_64)
24230 ret = paravirt_patch_ident_64(insnbuf, len);
24231+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24232+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
24233+ ret = paravirt_patch_ident_64(insnbuf, len);
24234+#endif
24235
24236 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
24237 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
24238@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
24239 if (insn_len > len || start == NULL)
24240 insn_len = len;
24241 else
24242- memcpy(insnbuf, start, insn_len);
24243+ memcpy(insnbuf, ktla_ktva(start), insn_len);
24244
24245 return insn_len;
24246 }
24247@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
24248 return this_cpu_read(paravirt_lazy_mode);
24249 }
24250
24251-struct pv_info pv_info = {
24252+struct pv_info pv_info __read_only = {
24253 .name = "bare hardware",
24254 .paravirt_enabled = 0,
24255 .kernel_rpl = 0,
24256@@ -315,16 +322,16 @@ struct pv_info pv_info = {
24257 #endif
24258 };
24259
24260-struct pv_init_ops pv_init_ops = {
24261+struct pv_init_ops pv_init_ops __read_only = {
24262 .patch = native_patch,
24263 };
24264
24265-struct pv_time_ops pv_time_ops = {
24266+struct pv_time_ops pv_time_ops __read_only = {
24267 .sched_clock = native_sched_clock,
24268 .steal_clock = native_steal_clock,
24269 };
24270
24271-struct pv_irq_ops pv_irq_ops = {
24272+struct pv_irq_ops pv_irq_ops __read_only = {
24273 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
24274 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
24275 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
24276@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
24277 #endif
24278 };
24279
24280-struct pv_cpu_ops pv_cpu_ops = {
24281+struct pv_cpu_ops pv_cpu_ops __read_only = {
24282 .cpuid = native_cpuid,
24283 .get_debugreg = native_get_debugreg,
24284 .set_debugreg = native_set_debugreg,
24285@@ -394,21 +401,26 @@ struct pv_cpu_ops pv_cpu_ops = {
24286 .end_context_switch = paravirt_nop,
24287 };
24288
24289-struct pv_apic_ops pv_apic_ops = {
24290+struct pv_apic_ops pv_apic_ops __read_only= {
24291 #ifdef CONFIG_X86_LOCAL_APIC
24292 .startup_ipi_hook = paravirt_nop,
24293 #endif
24294 };
24295
24296-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
24297+#ifdef CONFIG_X86_32
24298+#ifdef CONFIG_X86_PAE
24299+/* 64-bit pagetable entries */
24300+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
24301+#else
24302 /* 32-bit pagetable entries */
24303 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
24304+#endif
24305 #else
24306 /* 64-bit pagetable entries */
24307 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
24308 #endif
24309
24310-struct pv_mmu_ops pv_mmu_ops = {
24311+struct pv_mmu_ops pv_mmu_ops __read_only = {
24312
24313 .read_cr2 = native_read_cr2,
24314 .write_cr2 = native_write_cr2,
24315@@ -458,6 +470,7 @@ struct pv_mmu_ops pv_mmu_ops = {
24316 .make_pud = PTE_IDENT,
24317
24318 .set_pgd = native_set_pgd,
24319+ .set_pgd_batched = native_set_pgd_batched,
24320 #endif
24321 #endif /* PAGETABLE_LEVELS >= 3 */
24322
24323@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
24324 },
24325
24326 .set_fixmap = native_set_fixmap,
24327+
24328+#ifdef CONFIG_PAX_KERNEXEC
24329+ .pax_open_kernel = native_pax_open_kernel,
24330+ .pax_close_kernel = native_pax_close_kernel,
24331+#endif
24332+
24333 };
24334
24335 EXPORT_SYMBOL_GPL(pv_time_ops);
24336diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
24337index 299d493..2ccb0ee 100644
24338--- a/arch/x86/kernel/pci-calgary_64.c
24339+++ b/arch/x86/kernel/pci-calgary_64.c
24340@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
24341 tce_space = be64_to_cpu(readq(target));
24342 tce_space = tce_space & TAR_SW_BITS;
24343
24344- tce_space = tce_space & (~specified_table_size);
24345+ tce_space = tce_space & (~(unsigned long)specified_table_size);
24346 info->tce_space = (u64 *)__va(tce_space);
24347 }
24348 }
24349diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
24350index 35ccf75..7a15747 100644
24351--- a/arch/x86/kernel/pci-iommu_table.c
24352+++ b/arch/x86/kernel/pci-iommu_table.c
24353@@ -2,7 +2,7 @@
24354 #include <asm/iommu_table.h>
24355 #include <linux/string.h>
24356 #include <linux/kallsyms.h>
24357-
24358+#include <linux/sched.h>
24359
24360 #define DEBUG 1
24361
24362diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
24363index 6c483ba..d10ce2f 100644
24364--- a/arch/x86/kernel/pci-swiotlb.c
24365+++ b/arch/x86/kernel/pci-swiotlb.c
24366@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
24367 void *vaddr, dma_addr_t dma_addr,
24368 struct dma_attrs *attrs)
24369 {
24370- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
24371+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
24372 }
24373
24374 static struct dma_map_ops swiotlb_dma_ops = {
24375diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
24376index 83369e5..52b93f0 100644
24377--- a/arch/x86/kernel/process.c
24378+++ b/arch/x86/kernel/process.c
24379@@ -36,7 +36,8 @@
24380 * section. Since TSS's are completely CPU-local, we want them
24381 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
24382 */
24383-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
24384+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
24385+EXPORT_SYMBOL(init_tss);
24386
24387 #ifdef CONFIG_X86_64
24388 static DEFINE_PER_CPU(unsigned char, is_idle);
24389@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
24390 task_xstate_cachep =
24391 kmem_cache_create("task_xstate", xstate_size,
24392 __alignof__(union thread_xstate),
24393- SLAB_PANIC | SLAB_NOTRACK, NULL);
24394+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
24395 }
24396
24397 /*
24398@@ -105,7 +106,7 @@ void exit_thread(void)
24399 unsigned long *bp = t->io_bitmap_ptr;
24400
24401 if (bp) {
24402- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
24403+ struct tss_struct *tss = init_tss + get_cpu();
24404
24405 t->io_bitmap_ptr = NULL;
24406 clear_thread_flag(TIF_IO_BITMAP);
24407@@ -125,6 +126,9 @@ void flush_thread(void)
24408 {
24409 struct task_struct *tsk = current;
24410
24411+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
24412+ loadsegment(gs, 0);
24413+#endif
24414 flush_ptrace_hw_breakpoint(tsk);
24415 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
24416 drop_init_fpu(tsk);
24417@@ -271,7 +275,7 @@ static void __exit_idle(void)
24418 void exit_idle(void)
24419 {
24420 /* idle loop has pid 0 */
24421- if (current->pid)
24422+ if (task_pid_nr(current))
24423 return;
24424 __exit_idle();
24425 }
24426@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
24427 return ret;
24428 }
24429 #endif
24430-void stop_this_cpu(void *dummy)
24431+__noreturn void stop_this_cpu(void *dummy)
24432 {
24433 local_irq_disable();
24434 /*
24435@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
24436 }
24437 early_param("idle", idle_setup);
24438
24439-unsigned long arch_align_stack(unsigned long sp)
24440+#ifdef CONFIG_PAX_RANDKSTACK
24441+void pax_randomize_kstack(struct pt_regs *regs)
24442 {
24443- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
24444- sp -= get_random_int() % 8192;
24445- return sp & ~0xf;
24446-}
24447+ struct thread_struct *thread = &current->thread;
24448+ unsigned long time;
24449
24450-unsigned long arch_randomize_brk(struct mm_struct *mm)
24451-{
24452- unsigned long range_end = mm->brk + 0x02000000;
24453- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
24454-}
24455+ if (!randomize_va_space)
24456+ return;
24457+
24458+ if (v8086_mode(regs))
24459+ return;
24460
24461+ rdtscl(time);
24462+
24463+ /* P4 seems to return a 0 LSB, ignore it */
24464+#ifdef CONFIG_MPENTIUM4
24465+ time &= 0x3EUL;
24466+ time <<= 2;
24467+#elif defined(CONFIG_X86_64)
24468+ time &= 0xFUL;
24469+ time <<= 4;
24470+#else
24471+ time &= 0x1FUL;
24472+ time <<= 3;
24473+#endif
24474+
24475+ thread->sp0 ^= time;
24476+ load_sp0(init_tss + smp_processor_id(), thread);
24477+
24478+#ifdef CONFIG_X86_64
24479+ this_cpu_write(kernel_stack, thread->sp0);
24480+#endif
24481+}
24482+#endif
24483diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
24484index f8adefc..4bce3d6 100644
24485--- a/arch/x86/kernel/process_32.c
24486+++ b/arch/x86/kernel/process_32.c
24487@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
24488 unsigned long thread_saved_pc(struct task_struct *tsk)
24489 {
24490 return ((unsigned long *)tsk->thread.sp)[3];
24491+//XXX return tsk->thread.eip;
24492 }
24493
24494 void __show_regs(struct pt_regs *regs, int all)
24495@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
24496 unsigned long sp;
24497 unsigned short ss, gs;
24498
24499- if (user_mode_vm(regs)) {
24500+ if (user_mode(regs)) {
24501 sp = regs->sp;
24502 ss = regs->ss & 0xffff;
24503- gs = get_user_gs(regs);
24504 } else {
24505 sp = kernel_stack_pointer(regs);
24506 savesegment(ss, ss);
24507- savesegment(gs, gs);
24508 }
24509+ gs = get_user_gs(regs);
24510
24511 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
24512 (u16)regs->cs, regs->ip, regs->flags,
24513- smp_processor_id());
24514+ raw_smp_processor_id());
24515 print_symbol("EIP is at %s\n", regs->ip);
24516
24517 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
24518@@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
24519 int copy_thread(unsigned long clone_flags, unsigned long sp,
24520 unsigned long arg, struct task_struct *p)
24521 {
24522- struct pt_regs *childregs = task_pt_regs(p);
24523+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
24524 struct task_struct *tsk;
24525 int err;
24526
24527 p->thread.sp = (unsigned long) childregs;
24528 p->thread.sp0 = (unsigned long) (childregs+1);
24529+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24530
24531 if (unlikely(p->flags & PF_KTHREAD)) {
24532 /* kernel thread */
24533 memset(childregs, 0, sizeof(struct pt_regs));
24534 p->thread.ip = (unsigned long) ret_from_kernel_thread;
24535- task_user_gs(p) = __KERNEL_STACK_CANARY;
24536- childregs->ds = __USER_DS;
24537- childregs->es = __USER_DS;
24538+ savesegment(gs, childregs->gs);
24539+ childregs->ds = __KERNEL_DS;
24540+ childregs->es = __KERNEL_DS;
24541 childregs->fs = __KERNEL_PERCPU;
24542 childregs->bx = sp; /* function */
24543 childregs->bp = arg;
24544@@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24545 struct thread_struct *prev = &prev_p->thread,
24546 *next = &next_p->thread;
24547 int cpu = smp_processor_id();
24548- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24549+ struct tss_struct *tss = init_tss + cpu;
24550 fpu_switch_t fpu;
24551
24552 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
24553@@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24554 */
24555 lazy_save_gs(prev->gs);
24556
24557+#ifdef CONFIG_PAX_MEMORY_UDEREF
24558+ __set_fs(task_thread_info(next_p)->addr_limit);
24559+#endif
24560+
24561 /*
24562 * Load the per-thread Thread-Local Storage descriptor.
24563 */
24564@@ -307,6 +312,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24565 */
24566 arch_end_context_switch(next_p);
24567
24568+ this_cpu_write(current_task, next_p);
24569+ this_cpu_write(current_tinfo, &next_p->tinfo);
24570+
24571 /*
24572 * Restore %gs if needed (which is common)
24573 */
24574@@ -315,8 +323,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24575
24576 switch_fpu_finish(next_p, fpu);
24577
24578- this_cpu_write(current_task, next_p);
24579-
24580 return prev_p;
24581 }
24582
24583@@ -346,4 +352,3 @@ unsigned long get_wchan(struct task_struct *p)
24584 } while (count++ < 16);
24585 return 0;
24586 }
24587-
24588diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
24589index 05646ba..0c2906d 100644
24590--- a/arch/x86/kernel/process_64.c
24591+++ b/arch/x86/kernel/process_64.c
24592@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24593 struct pt_regs *childregs;
24594 struct task_struct *me = current;
24595
24596- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
24597+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
24598 childregs = task_pt_regs(p);
24599 p->thread.sp = (unsigned long) childregs;
24600 p->thread.usersp = me->thread.usersp;
24601+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24602 set_tsk_thread_flag(p, TIF_FORK);
24603 p->fpu_counter = 0;
24604 p->thread.io_bitmap_ptr = NULL;
24605@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24606 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
24607 savesegment(es, p->thread.es);
24608 savesegment(ds, p->thread.ds);
24609+ savesegment(ss, p->thread.ss);
24610+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
24611 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
24612
24613 if (unlikely(p->flags & PF_KTHREAD)) {
24614@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24615 struct thread_struct *prev = &prev_p->thread;
24616 struct thread_struct *next = &next_p->thread;
24617 int cpu = smp_processor_id();
24618- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24619+ struct tss_struct *tss = init_tss + cpu;
24620 unsigned fsindex, gsindex;
24621 fpu_switch_t fpu;
24622
24623@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24624 if (unlikely(next->ds | prev->ds))
24625 loadsegment(ds, next->ds);
24626
24627+ savesegment(ss, prev->ss);
24628+ if (unlikely(next->ss != prev->ss))
24629+ loadsegment(ss, next->ss);
24630
24631 /* We must save %fs and %gs before load_TLS() because
24632 * %fs and %gs may be cleared by load_TLS().
24633@@ -362,10 +368,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24634 prev->usersp = this_cpu_read(old_rsp);
24635 this_cpu_write(old_rsp, next->usersp);
24636 this_cpu_write(current_task, next_p);
24637+ this_cpu_write(current_tinfo, &next_p->tinfo);
24638
24639- this_cpu_write(kernel_stack,
24640- (unsigned long)task_stack_page(next_p) +
24641- THREAD_SIZE - KERNEL_STACK_OFFSET);
24642+ this_cpu_write(kernel_stack, next->sp0);
24643
24644 /*
24645 * Now maybe reload the debug registers and handle I/O bitmaps
24646@@ -434,12 +439,11 @@ unsigned long get_wchan(struct task_struct *p)
24647 if (!p || p == current || p->state == TASK_RUNNING)
24648 return 0;
24649 stack = (unsigned long)task_stack_page(p);
24650- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
24651+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
24652 return 0;
24653 fp = *(u64 *)(p->thread.sp);
24654 do {
24655- if (fp < (unsigned long)stack ||
24656- fp >= (unsigned long)stack+THREAD_SIZE)
24657+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
24658 return 0;
24659 ip = *(u64 *)(fp+8);
24660 if (!in_sched_functions(ip))
24661diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
24662index 7461f50..1334029 100644
24663--- a/arch/x86/kernel/ptrace.c
24664+++ b/arch/x86/kernel/ptrace.c
24665@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
24666 {
24667 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
24668 unsigned long sp = (unsigned long)&regs->sp;
24669- struct thread_info *tinfo;
24670
24671- if (context == (sp & ~(THREAD_SIZE - 1)))
24672+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
24673 return sp;
24674
24675- tinfo = (struct thread_info *)context;
24676- if (tinfo->previous_esp)
24677- return tinfo->previous_esp;
24678+ sp = *(unsigned long *)context;
24679+ if (sp)
24680+ return sp;
24681
24682 return (unsigned long)regs;
24683 }
24684@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
24685 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
24686 {
24687 int i;
24688- int dr7 = 0;
24689+ unsigned long dr7 = 0;
24690 struct arch_hw_breakpoint *info;
24691
24692 for (i = 0; i < HBP_NUM; i++) {
24693@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
24694 unsigned long addr, unsigned long data)
24695 {
24696 int ret;
24697- unsigned long __user *datap = (unsigned long __user *)data;
24698+ unsigned long __user *datap = (__force unsigned long __user *)data;
24699
24700 switch (request) {
24701 /* read the word at location addr in the USER area. */
24702@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
24703 if ((int) addr < 0)
24704 return -EIO;
24705 ret = do_get_thread_area(child, addr,
24706- (struct user_desc __user *)data);
24707+ (__force struct user_desc __user *) data);
24708 break;
24709
24710 case PTRACE_SET_THREAD_AREA:
24711 if ((int) addr < 0)
24712 return -EIO;
24713 ret = do_set_thread_area(child, addr,
24714- (struct user_desc __user *)data, 0);
24715+ (__force struct user_desc __user *) data, 0);
24716 break;
24717 #endif
24718
24719@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
24720
24721 #ifdef CONFIG_X86_64
24722
24723-static struct user_regset x86_64_regsets[] __read_mostly = {
24724+static user_regset_no_const x86_64_regsets[] __read_only = {
24725 [REGSET_GENERAL] = {
24726 .core_note_type = NT_PRSTATUS,
24727 .n = sizeof(struct user_regs_struct) / sizeof(long),
24728@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
24729 #endif /* CONFIG_X86_64 */
24730
24731 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
24732-static struct user_regset x86_32_regsets[] __read_mostly = {
24733+static user_regset_no_const x86_32_regsets[] __read_only = {
24734 [REGSET_GENERAL] = {
24735 .core_note_type = NT_PRSTATUS,
24736 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
24737@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
24738 */
24739 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
24740
24741-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24742+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24743 {
24744 #ifdef CONFIG_X86_64
24745 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
24746@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
24747 memset(info, 0, sizeof(*info));
24748 info->si_signo = SIGTRAP;
24749 info->si_code = si_code;
24750- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
24751+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
24752 }
24753
24754 void user_single_step_siginfo(struct task_struct *tsk,
24755@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
24756 # define IS_IA32 0
24757 #endif
24758
24759+#ifdef CONFIG_GRKERNSEC_SETXID
24760+extern void gr_delayed_cred_worker(void);
24761+#endif
24762+
24763 /*
24764 * We must return the syscall number to actually look up in the table.
24765 * This can be -1L to skip running any syscall at all.
24766@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
24767
24768 user_exit();
24769
24770+#ifdef CONFIG_GRKERNSEC_SETXID
24771+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24772+ gr_delayed_cred_worker();
24773+#endif
24774+
24775 /*
24776 * If we stepped into a sysenter/syscall insn, it trapped in
24777 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
24778@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
24779 */
24780 user_exit();
24781
24782+#ifdef CONFIG_GRKERNSEC_SETXID
24783+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24784+ gr_delayed_cred_worker();
24785+#endif
24786+
24787 audit_syscall_exit(regs);
24788
24789 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
24790diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
24791index 2cb9470..ff1fd80 100644
24792--- a/arch/x86/kernel/pvclock.c
24793+++ b/arch/x86/kernel/pvclock.c
24794@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
24795 return pv_tsc_khz;
24796 }
24797
24798-static atomic64_t last_value = ATOMIC64_INIT(0);
24799+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
24800
24801 void pvclock_resume(void)
24802 {
24803- atomic64_set(&last_value, 0);
24804+ atomic64_set_unchecked(&last_value, 0);
24805 }
24806
24807 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
24808@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
24809 * updating at the same time, and one of them could be slightly behind,
24810 * making the assumption that last_value always go forward fail to hold.
24811 */
24812- last = atomic64_read(&last_value);
24813+ last = atomic64_read_unchecked(&last_value);
24814 do {
24815 if (ret < last)
24816 return last;
24817- last = atomic64_cmpxchg(&last_value, last, ret);
24818+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
24819 } while (unlikely(last != ret));
24820
24821 return ret;
24822diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
24823index 563ed91..b9c3313 100644
24824--- a/arch/x86/kernel/reboot.c
24825+++ b/arch/x86/kernel/reboot.c
24826@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
24827
24828 void __noreturn machine_real_restart(unsigned int type)
24829 {
24830+
24831+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
24832+ struct desc_struct *gdt;
24833+#endif
24834+
24835 local_irq_disable();
24836
24837 /*
24838@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
24839
24840 /* Jump to the identity-mapped low memory code */
24841 #ifdef CONFIG_X86_32
24842- asm volatile("jmpl *%0" : :
24843+
24844+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
24845+ gdt = get_cpu_gdt_table(smp_processor_id());
24846+ pax_open_kernel();
24847+#ifdef CONFIG_PAX_MEMORY_UDEREF
24848+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
24849+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
24850+ loadsegment(ds, __KERNEL_DS);
24851+ loadsegment(es, __KERNEL_DS);
24852+ loadsegment(ss, __KERNEL_DS);
24853+#endif
24854+#ifdef CONFIG_PAX_KERNEXEC
24855+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
24856+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
24857+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
24858+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
24859+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
24860+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
24861+#endif
24862+ pax_close_kernel();
24863+#endif
24864+
24865+ asm volatile("ljmpl *%0" : :
24866 "rm" (real_mode_header->machine_real_restart_asm),
24867 "a" (type));
24868 #else
24869@@ -442,7 +469,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
24870 * try to force a triple fault and then cycle between hitting the keyboard
24871 * controller and doing that
24872 */
24873-static void native_machine_emergency_restart(void)
24874+static void __noreturn native_machine_emergency_restart(void)
24875 {
24876 int i;
24877 int attempt = 0;
24878@@ -551,13 +578,13 @@ void native_machine_shutdown(void)
24879 #endif
24880 }
24881
24882-static void __machine_emergency_restart(int emergency)
24883+static void __noreturn __machine_emergency_restart(int emergency)
24884 {
24885 reboot_emergency = emergency;
24886 machine_ops.emergency_restart();
24887 }
24888
24889-static void native_machine_restart(char *__unused)
24890+static void __noreturn native_machine_restart(char *__unused)
24891 {
24892 pr_notice("machine restart\n");
24893
24894@@ -566,7 +593,7 @@ static void native_machine_restart(char *__unused)
24895 __machine_emergency_restart(0);
24896 }
24897
24898-static void native_machine_halt(void)
24899+static void __noreturn native_machine_halt(void)
24900 {
24901 /* Stop other cpus and apics */
24902 machine_shutdown();
24903@@ -576,7 +603,7 @@ static void native_machine_halt(void)
24904 stop_this_cpu(NULL);
24905 }
24906
24907-static void native_machine_power_off(void)
24908+static void __noreturn native_machine_power_off(void)
24909 {
24910 if (pm_power_off) {
24911 if (!reboot_force)
24912@@ -585,9 +612,10 @@ static void native_machine_power_off(void)
24913 }
24914 /* A fallback in case there is no PM info available */
24915 tboot_shutdown(TB_SHUTDOWN_HALT);
24916+ unreachable();
24917 }
24918
24919-struct machine_ops machine_ops = {
24920+struct machine_ops machine_ops __read_only = {
24921 .power_off = native_machine_power_off,
24922 .shutdown = native_machine_shutdown,
24923 .emergency_restart = native_machine_emergency_restart,
24924diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
24925index c8e41e9..64049ef 100644
24926--- a/arch/x86/kernel/reboot_fixups_32.c
24927+++ b/arch/x86/kernel/reboot_fixups_32.c
24928@@ -57,7 +57,7 @@ struct device_fixup {
24929 unsigned int vendor;
24930 unsigned int device;
24931 void (*reboot_fixup)(struct pci_dev *);
24932-};
24933+} __do_const;
24934
24935 /*
24936 * PCI ids solely used for fixups_table go here
24937diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
24938index 3fd2c69..16ef367 100644
24939--- a/arch/x86/kernel/relocate_kernel_64.S
24940+++ b/arch/x86/kernel/relocate_kernel_64.S
24941@@ -11,6 +11,7 @@
24942 #include <asm/kexec.h>
24943 #include <asm/processor-flags.h>
24944 #include <asm/pgtable_types.h>
24945+#include <asm/alternative-asm.h>
24946
24947 /*
24948 * Must be relocatable PIC code callable as a C function
24949@@ -96,8 +97,7 @@ relocate_kernel:
24950
24951 /* jump to identity mapped page */
24952 addq $(identity_mapped - relocate_kernel), %r8
24953- pushq %r8
24954- ret
24955+ jmp *%r8
24956
24957 identity_mapped:
24958 /* set return address to 0 if not preserving context */
24959@@ -167,6 +167,7 @@ identity_mapped:
24960 xorl %r14d, %r14d
24961 xorl %r15d, %r15d
24962
24963+ pax_force_retaddr 0, 1
24964 ret
24965
24966 1:
24967diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
24968index f8ec578..0cc110a 100644
24969--- a/arch/x86/kernel/setup.c
24970+++ b/arch/x86/kernel/setup.c
24971@@ -110,6 +110,7 @@
24972 #include <asm/mce.h>
24973 #include <asm/alternative.h>
24974 #include <asm/prom.h>
24975+#include <asm/boot.h>
24976
24977 /*
24978 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
24979@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
24980 #endif
24981
24982
24983-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
24984-unsigned long mmu_cr4_features;
24985+#ifdef CONFIG_X86_64
24986+unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
24987+#elif defined(CONFIG_X86_PAE)
24988+unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
24989 #else
24990-unsigned long mmu_cr4_features = X86_CR4_PAE;
24991+unsigned long mmu_cr4_features __read_only;
24992 #endif
24993
24994+void set_in_cr4(unsigned long mask)
24995+{
24996+ unsigned long cr4 = read_cr4();
24997+
24998+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
24999+ return;
25000+
25001+ pax_open_kernel();
25002+ mmu_cr4_features |= mask;
25003+ pax_close_kernel();
25004+
25005+ if (trampoline_cr4_features)
25006+ *trampoline_cr4_features = mmu_cr4_features;
25007+ cr4 |= mask;
25008+ write_cr4(cr4);
25009+}
25010+EXPORT_SYMBOL(set_in_cr4);
25011+
25012+void clear_in_cr4(unsigned long mask)
25013+{
25014+ unsigned long cr4 = read_cr4();
25015+
25016+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
25017+ return;
25018+
25019+ pax_open_kernel();
25020+ mmu_cr4_features &= ~mask;
25021+ pax_close_kernel();
25022+
25023+ if (trampoline_cr4_features)
25024+ *trampoline_cr4_features = mmu_cr4_features;
25025+ cr4 &= ~mask;
25026+ write_cr4(cr4);
25027+}
25028+EXPORT_SYMBOL(clear_in_cr4);
25029+
25030 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
25031 int bootloader_type, bootloader_version;
25032
25033@@ -444,7 +483,7 @@ static void __init parse_setup_data(void)
25034
25035 switch (data->type) {
25036 case SETUP_E820_EXT:
25037- parse_e820_ext(data);
25038+ parse_e820_ext((struct setup_data __force_kernel *)data);
25039 break;
25040 case SETUP_DTB:
25041 add_dtb(pa_data);
25042@@ -771,7 +810,7 @@ static void __init trim_bios_range(void)
25043 * area (640->1Mb) as ram even though it is not.
25044 * take them out.
25045 */
25046- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
25047+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
25048
25049 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
25050 }
25051@@ -779,7 +818,7 @@ static void __init trim_bios_range(void)
25052 /* called before trim_bios_range() to spare extra sanitize */
25053 static void __init e820_add_kernel_range(void)
25054 {
25055- u64 start = __pa_symbol(_text);
25056+ u64 start = __pa_symbol(ktla_ktva(_text));
25057 u64 size = __pa_symbol(_end) - start;
25058
25059 /*
25060@@ -841,8 +880,12 @@ static void __init trim_low_memory_range(void)
25061
25062 void __init setup_arch(char **cmdline_p)
25063 {
25064+#ifdef CONFIG_X86_32
25065+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
25066+#else
25067 memblock_reserve(__pa_symbol(_text),
25068 (unsigned long)__bss_stop - (unsigned long)_text);
25069+#endif
25070
25071 early_reserve_initrd();
25072
25073@@ -934,14 +977,14 @@ void __init setup_arch(char **cmdline_p)
25074
25075 if (!boot_params.hdr.root_flags)
25076 root_mountflags &= ~MS_RDONLY;
25077- init_mm.start_code = (unsigned long) _text;
25078- init_mm.end_code = (unsigned long) _etext;
25079+ init_mm.start_code = ktla_ktva((unsigned long) _text);
25080+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
25081 init_mm.end_data = (unsigned long) _edata;
25082 init_mm.brk = _brk_end;
25083
25084- code_resource.start = __pa_symbol(_text);
25085- code_resource.end = __pa_symbol(_etext)-1;
25086- data_resource.start = __pa_symbol(_etext);
25087+ code_resource.start = __pa_symbol(ktla_ktva(_text));
25088+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
25089+ data_resource.start = __pa_symbol(_sdata);
25090 data_resource.end = __pa_symbol(_edata)-1;
25091 bss_resource.start = __pa_symbol(__bss_start);
25092 bss_resource.end = __pa_symbol(__bss_stop)-1;
25093diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
25094index 5cdff03..80fa283 100644
25095--- a/arch/x86/kernel/setup_percpu.c
25096+++ b/arch/x86/kernel/setup_percpu.c
25097@@ -21,19 +21,17 @@
25098 #include <asm/cpu.h>
25099 #include <asm/stackprotector.h>
25100
25101-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
25102+#ifdef CONFIG_SMP
25103+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
25104 EXPORT_PER_CPU_SYMBOL(cpu_number);
25105+#endif
25106
25107-#ifdef CONFIG_X86_64
25108 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
25109-#else
25110-#define BOOT_PERCPU_OFFSET 0
25111-#endif
25112
25113 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
25114 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
25115
25116-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
25117+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
25118 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
25119 };
25120 EXPORT_SYMBOL(__per_cpu_offset);
25121@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
25122 {
25123 #ifdef CONFIG_NEED_MULTIPLE_NODES
25124 pg_data_t *last = NULL;
25125- unsigned int cpu;
25126+ int cpu;
25127
25128 for_each_possible_cpu(cpu) {
25129 int node = early_cpu_to_node(cpu);
25130@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
25131 {
25132 #ifdef CONFIG_X86_32
25133 struct desc_struct gdt;
25134+ unsigned long base = per_cpu_offset(cpu);
25135
25136- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
25137- 0x2 | DESCTYPE_S, 0x8);
25138- gdt.s = 1;
25139+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
25140+ 0x83 | DESCTYPE_S, 0xC);
25141 write_gdt_entry(get_cpu_gdt_table(cpu),
25142 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
25143 #endif
25144@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
25145 /* alrighty, percpu areas up and running */
25146 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
25147 for_each_possible_cpu(cpu) {
25148+#ifdef CONFIG_CC_STACKPROTECTOR
25149+#ifdef CONFIG_X86_32
25150+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
25151+#endif
25152+#endif
25153 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
25154 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
25155 per_cpu(cpu_number, cpu) = cpu;
25156@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
25157 */
25158 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
25159 #endif
25160+#ifdef CONFIG_CC_STACKPROTECTOR
25161+#ifdef CONFIG_X86_32
25162+ if (!cpu)
25163+ per_cpu(stack_canary.canary, cpu) = canary;
25164+#endif
25165+#endif
25166 /*
25167 * Up to this point, the boot CPU has been using .init.data
25168 * area. Reload any changed state for the boot CPU.
25169diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
25170index cf91358..a7081ea 100644
25171--- a/arch/x86/kernel/signal.c
25172+++ b/arch/x86/kernel/signal.c
25173@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
25174 * Align the stack pointer according to the i386 ABI,
25175 * i.e. so that on function entry ((sp + 4) & 15) == 0.
25176 */
25177- sp = ((sp + 4) & -16ul) - 4;
25178+ sp = ((sp - 12) & -16ul) - 4;
25179 #else /* !CONFIG_X86_32 */
25180 sp = round_down(sp, 16) - 8;
25181 #endif
25182@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25183 }
25184
25185 if (current->mm->context.vdso)
25186- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25187+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25188 else
25189- restorer = &frame->retcode;
25190+ restorer = (void __user *)&frame->retcode;
25191 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25192 restorer = ksig->ka.sa.sa_restorer;
25193
25194@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25195 * reasons and because gdb uses it as a signature to notice
25196 * signal handler stack frames.
25197 */
25198- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
25199+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
25200
25201 if (err)
25202 return -EFAULT;
25203@@ -358,10 +358,13 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25204 else
25205 put_user_ex(0, &frame->uc.uc_flags);
25206 put_user_ex(0, &frame->uc.uc_link);
25207- err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
25208+ __save_altstack_ex(&frame->uc.uc_stack, regs->sp);
25209
25210 /* Set up to return from userspace. */
25211- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25212+ if (current->mm->context.vdso)
25213+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25214+ else
25215+ restorer = (void __user *)&frame->retcode;
25216 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25217 restorer = ksig->ka.sa.sa_restorer;
25218 put_user_ex(restorer, &frame->pretcode);
25219@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25220 * reasons and because gdb uses it as a signature to notice
25221 * signal handler stack frames.
25222 */
25223- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
25224+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
25225 } put_user_catch(err);
25226
25227 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
25228@@ -423,7 +426,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25229 else
25230 put_user_ex(0, &frame->uc.uc_flags);
25231 put_user_ex(0, &frame->uc.uc_link);
25232- err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
25233+ __save_altstack_ex(&frame->uc.uc_stack, regs->sp);
25234
25235 /* Set up to return from userspace. If provided, use a stub
25236 already in userspace. */
25237@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25238 {
25239 int usig = signr_convert(ksig->sig);
25240 sigset_t *set = sigmask_to_save();
25241- compat_sigset_t *cset = (compat_sigset_t *) set;
25242+ sigset_t sigcopy;
25243+ compat_sigset_t *cset;
25244+
25245+ sigcopy = *set;
25246+
25247+ cset = (compat_sigset_t *) &sigcopy;
25248
25249 /* Set up the stack frame */
25250 if (is_ia32_frame()) {
25251@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25252 } else if (is_x32_frame()) {
25253 return x32_setup_rt_frame(ksig, cset, regs);
25254 } else {
25255- return __setup_rt_frame(ksig->sig, ksig, set, regs);
25256+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
25257 }
25258 }
25259
25260diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
25261index cdaa347..f5af55d 100644
25262--- a/arch/x86/kernel/smp.c
25263+++ b/arch/x86/kernel/smp.c
25264@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
25265
25266 __setup("nonmi_ipi", nonmi_ipi_setup);
25267
25268-struct smp_ops smp_ops = {
25269+struct smp_ops smp_ops __read_only = {
25270 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
25271 .smp_prepare_cpus = native_smp_prepare_cpus,
25272 .smp_cpus_done = native_smp_cpus_done,
25273diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
25274index aecc98a..0244a53 100644
25275--- a/arch/x86/kernel/smpboot.c
25276+++ b/arch/x86/kernel/smpboot.c
25277@@ -251,14 +251,18 @@ static void notrace start_secondary(void *unused)
25278
25279 enable_start_cpu0 = 0;
25280
25281-#ifdef CONFIG_X86_32
25282- /* switch away from the initial page table */
25283- load_cr3(swapper_pg_dir);
25284- __flush_tlb_all();
25285-#endif
25286-
25287 /* otherwise gcc will move up smp_processor_id before the cpu_init */
25288 barrier();
25289+
25290+ /* switch away from the initial page table */
25291+#ifdef CONFIG_PAX_PER_CPU_PGD
25292+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
25293+ __flush_tlb_all();
25294+#elif defined(CONFIG_X86_32)
25295+ load_cr3(swapper_pg_dir);
25296+ __flush_tlb_all();
25297+#endif
25298+
25299 /*
25300 * Check TSC synchronization with the BP:
25301 */
25302@@ -748,6 +752,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25303 idle->thread.sp = (unsigned long) (((struct pt_regs *)
25304 (THREAD_SIZE + task_stack_page(idle))) - 1);
25305 per_cpu(current_task, cpu) = idle;
25306+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
25307
25308 #ifdef CONFIG_X86_32
25309 /* Stack for startup_32 can be just as for start_secondary onwards */
25310@@ -755,11 +760,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25311 #else
25312 clear_tsk_thread_flag(idle, TIF_FORK);
25313 initial_gs = per_cpu_offset(cpu);
25314- per_cpu(kernel_stack, cpu) =
25315- (unsigned long)task_stack_page(idle) -
25316- KERNEL_STACK_OFFSET + THREAD_SIZE;
25317+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
25318 #endif
25319+
25320+ pax_open_kernel();
25321 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
25322+ pax_close_kernel();
25323+
25324 initial_code = (unsigned long)start_secondary;
25325 stack_start = idle->thread.sp;
25326
25327@@ -908,6 +915,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
25328 /* the FPU context is blank, nobody can own it */
25329 __cpu_disable_lazy_restore(cpu);
25330
25331+#ifdef CONFIG_PAX_PER_CPU_PGD
25332+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
25333+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25334+ KERNEL_PGD_PTRS);
25335+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
25336+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25337+ KERNEL_PGD_PTRS);
25338+#endif
25339+
25340 err = do_boot_cpu(apicid, cpu, tidle);
25341 if (err) {
25342 pr_debug("do_boot_cpu failed %d\n", err);
25343diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
25344index 9b4d51d..5d28b58 100644
25345--- a/arch/x86/kernel/step.c
25346+++ b/arch/x86/kernel/step.c
25347@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25348 struct desc_struct *desc;
25349 unsigned long base;
25350
25351- seg &= ~7UL;
25352+ seg >>= 3;
25353
25354 mutex_lock(&child->mm->context.lock);
25355- if (unlikely((seg >> 3) >= child->mm->context.size))
25356+ if (unlikely(seg >= child->mm->context.size))
25357 addr = -1L; /* bogus selector, access would fault */
25358 else {
25359 desc = child->mm->context.ldt + seg;
25360@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25361 addr += base;
25362 }
25363 mutex_unlock(&child->mm->context.lock);
25364- }
25365+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
25366+ addr = ktla_ktva(addr);
25367
25368 return addr;
25369 }
25370@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
25371 unsigned char opcode[15];
25372 unsigned long addr = convert_ip_to_linear(child, regs);
25373
25374+ if (addr == -EINVAL)
25375+ return 0;
25376+
25377 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
25378 for (i = 0; i < copied; i++) {
25379 switch (opcode[i]) {
25380diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
25381new file mode 100644
25382index 0000000..5877189
25383--- /dev/null
25384+++ b/arch/x86/kernel/sys_i386_32.c
25385@@ -0,0 +1,189 @@
25386+/*
25387+ * This file contains various random system calls that
25388+ * have a non-standard calling sequence on the Linux/i386
25389+ * platform.
25390+ */
25391+
25392+#include <linux/errno.h>
25393+#include <linux/sched.h>
25394+#include <linux/mm.h>
25395+#include <linux/fs.h>
25396+#include <linux/smp.h>
25397+#include <linux/sem.h>
25398+#include <linux/msg.h>
25399+#include <linux/shm.h>
25400+#include <linux/stat.h>
25401+#include <linux/syscalls.h>
25402+#include <linux/mman.h>
25403+#include <linux/file.h>
25404+#include <linux/utsname.h>
25405+#include <linux/ipc.h>
25406+#include <linux/elf.h>
25407+
25408+#include <linux/uaccess.h>
25409+#include <linux/unistd.h>
25410+
25411+#include <asm/syscalls.h>
25412+
25413+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
25414+{
25415+ unsigned long pax_task_size = TASK_SIZE;
25416+
25417+#ifdef CONFIG_PAX_SEGMEXEC
25418+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
25419+ pax_task_size = SEGMEXEC_TASK_SIZE;
25420+#endif
25421+
25422+ if (flags & MAP_FIXED)
25423+ if (len > pax_task_size || addr > pax_task_size - len)
25424+ return -EINVAL;
25425+
25426+ return 0;
25427+}
25428+
25429+/*
25430+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
25431+ */
25432+static unsigned long get_align_mask(void)
25433+{
25434+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
25435+ return 0;
25436+
25437+ if (!(current->flags & PF_RANDOMIZE))
25438+ return 0;
25439+
25440+ return va_align.mask;
25441+}
25442+
25443+unsigned long
25444+arch_get_unmapped_area(struct file *filp, unsigned long addr,
25445+ unsigned long len, unsigned long pgoff, unsigned long flags)
25446+{
25447+ struct mm_struct *mm = current->mm;
25448+ struct vm_area_struct *vma;
25449+ unsigned long pax_task_size = TASK_SIZE;
25450+ struct vm_unmapped_area_info info;
25451+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25452+
25453+#ifdef CONFIG_PAX_SEGMEXEC
25454+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25455+ pax_task_size = SEGMEXEC_TASK_SIZE;
25456+#endif
25457+
25458+ pax_task_size -= PAGE_SIZE;
25459+
25460+ if (len > pax_task_size)
25461+ return -ENOMEM;
25462+
25463+ if (flags & MAP_FIXED)
25464+ return addr;
25465+
25466+#ifdef CONFIG_PAX_RANDMMAP
25467+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25468+#endif
25469+
25470+ if (addr) {
25471+ addr = PAGE_ALIGN(addr);
25472+ if (pax_task_size - len >= addr) {
25473+ vma = find_vma(mm, addr);
25474+ if (check_heap_stack_gap(vma, addr, len, offset))
25475+ return addr;
25476+ }
25477+ }
25478+
25479+ info.flags = 0;
25480+ info.length = len;
25481+ info.align_mask = filp ? get_align_mask() : 0;
25482+ info.align_offset = pgoff << PAGE_SHIFT;
25483+ info.threadstack_offset = offset;
25484+
25485+#ifdef CONFIG_PAX_PAGEEXEC
25486+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
25487+ info.low_limit = 0x00110000UL;
25488+ info.high_limit = mm->start_code;
25489+
25490+#ifdef CONFIG_PAX_RANDMMAP
25491+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25492+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
25493+#endif
25494+
25495+ if (info.low_limit < info.high_limit) {
25496+ addr = vm_unmapped_area(&info);
25497+ if (!IS_ERR_VALUE(addr))
25498+ return addr;
25499+ }
25500+ } else
25501+#endif
25502+
25503+ info.low_limit = mm->mmap_base;
25504+ info.high_limit = pax_task_size;
25505+
25506+ return vm_unmapped_area(&info);
25507+}
25508+
25509+unsigned long
25510+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25511+ const unsigned long len, const unsigned long pgoff,
25512+ const unsigned long flags)
25513+{
25514+ struct vm_area_struct *vma;
25515+ struct mm_struct *mm = current->mm;
25516+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
25517+ struct vm_unmapped_area_info info;
25518+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25519+
25520+#ifdef CONFIG_PAX_SEGMEXEC
25521+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25522+ pax_task_size = SEGMEXEC_TASK_SIZE;
25523+#endif
25524+
25525+ pax_task_size -= PAGE_SIZE;
25526+
25527+ /* requested length too big for entire address space */
25528+ if (len > pax_task_size)
25529+ return -ENOMEM;
25530+
25531+ if (flags & MAP_FIXED)
25532+ return addr;
25533+
25534+#ifdef CONFIG_PAX_PAGEEXEC
25535+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
25536+ goto bottomup;
25537+#endif
25538+
25539+#ifdef CONFIG_PAX_RANDMMAP
25540+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25541+#endif
25542+
25543+ /* requesting a specific address */
25544+ if (addr) {
25545+ addr = PAGE_ALIGN(addr);
25546+ if (pax_task_size - len >= addr) {
25547+ vma = find_vma(mm, addr);
25548+ if (check_heap_stack_gap(vma, addr, len, offset))
25549+ return addr;
25550+ }
25551+ }
25552+
25553+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
25554+ info.length = len;
25555+ info.low_limit = PAGE_SIZE;
25556+ info.high_limit = mm->mmap_base;
25557+ info.align_mask = filp ? get_align_mask() : 0;
25558+ info.align_offset = pgoff << PAGE_SHIFT;
25559+ info.threadstack_offset = offset;
25560+
25561+ addr = vm_unmapped_area(&info);
25562+ if (!(addr & ~PAGE_MASK))
25563+ return addr;
25564+ VM_BUG_ON(addr != -ENOMEM);
25565+
25566+bottomup:
25567+ /*
25568+ * A failed mmap() very likely causes application failure,
25569+ * so fall back to the bottom-up function here. This scenario
25570+ * can happen with large stack limits and large mmap()
25571+ * allocations.
25572+ */
25573+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
25574+}
25575diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
25576index 30277e2..5664a29 100644
25577--- a/arch/x86/kernel/sys_x86_64.c
25578+++ b/arch/x86/kernel/sys_x86_64.c
25579@@ -81,8 +81,8 @@ out:
25580 return error;
25581 }
25582
25583-static void find_start_end(unsigned long flags, unsigned long *begin,
25584- unsigned long *end)
25585+static void find_start_end(struct mm_struct *mm, unsigned long flags,
25586+ unsigned long *begin, unsigned long *end)
25587 {
25588 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
25589 unsigned long new_begin;
25590@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
25591 *begin = new_begin;
25592 }
25593 } else {
25594- *begin = current->mm->mmap_legacy_base;
25595+ *begin = mm->mmap_legacy_base;
25596 *end = TASK_SIZE;
25597 }
25598 }
25599@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25600 struct vm_area_struct *vma;
25601 struct vm_unmapped_area_info info;
25602 unsigned long begin, end;
25603+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25604
25605 if (flags & MAP_FIXED)
25606 return addr;
25607
25608- find_start_end(flags, &begin, &end);
25609+ find_start_end(mm, flags, &begin, &end);
25610
25611 if (len > end)
25612 return -ENOMEM;
25613
25614+#ifdef CONFIG_PAX_RANDMMAP
25615+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25616+#endif
25617+
25618 if (addr) {
25619 addr = PAGE_ALIGN(addr);
25620 vma = find_vma(mm, addr);
25621- if (end - len >= addr &&
25622- (!vma || addr + len <= vma->vm_start))
25623+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25624 return addr;
25625 }
25626
25627@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25628 info.high_limit = end;
25629 info.align_mask = filp ? get_align_mask() : 0;
25630 info.align_offset = pgoff << PAGE_SHIFT;
25631+ info.threadstack_offset = offset;
25632 return vm_unmapped_area(&info);
25633 }
25634
25635@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25636 struct mm_struct *mm = current->mm;
25637 unsigned long addr = addr0;
25638 struct vm_unmapped_area_info info;
25639+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25640
25641 /* requested length too big for entire address space */
25642 if (len > TASK_SIZE)
25643@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25644 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
25645 goto bottomup;
25646
25647+#ifdef CONFIG_PAX_RANDMMAP
25648+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25649+#endif
25650+
25651 /* requesting a specific address */
25652 if (addr) {
25653 addr = PAGE_ALIGN(addr);
25654 vma = find_vma(mm, addr);
25655- if (TASK_SIZE - len >= addr &&
25656- (!vma || addr + len <= vma->vm_start))
25657+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25658 return addr;
25659 }
25660
25661@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25662 info.high_limit = mm->mmap_base;
25663 info.align_mask = filp ? get_align_mask() : 0;
25664 info.align_offset = pgoff << PAGE_SHIFT;
25665+ info.threadstack_offset = offset;
25666 addr = vm_unmapped_area(&info);
25667 if (!(addr & ~PAGE_MASK))
25668 return addr;
25669diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
25670index addf7b5..f960685 100644
25671--- a/arch/x86/kernel/tboot.c
25672+++ b/arch/x86/kernel/tboot.c
25673@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
25674
25675 void tboot_shutdown(u32 shutdown_type)
25676 {
25677- void (*shutdown)(void);
25678+ void (* __noreturn shutdown)(void);
25679
25680 if (!tboot_enabled())
25681 return;
25682@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
25683
25684 switch_to_tboot_pt();
25685
25686- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
25687+ shutdown = (void *)tboot->shutdown_entry;
25688 shutdown();
25689
25690 /* should not reach here */
25691@@ -301,7 +301,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
25692 return 0;
25693 }
25694
25695-static atomic_t ap_wfs_count;
25696+static atomic_unchecked_t ap_wfs_count;
25697
25698 static int tboot_wait_for_aps(int num_aps)
25699 {
25700@@ -325,9 +325,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
25701 {
25702 switch (action) {
25703 case CPU_DYING:
25704- atomic_inc(&ap_wfs_count);
25705+ atomic_inc_unchecked(&ap_wfs_count);
25706 if (num_online_cpus() == 1)
25707- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
25708+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
25709 return NOTIFY_BAD;
25710 break;
25711 }
25712@@ -413,7 +413,7 @@ static __init int tboot_late_init(void)
25713
25714 tboot_create_trampoline();
25715
25716- atomic_set(&ap_wfs_count, 0);
25717+ atomic_set_unchecked(&ap_wfs_count, 0);
25718 register_hotcpu_notifier(&tboot_cpu_notifier);
25719
25720 #ifdef CONFIG_DEBUG_FS
25721diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
25722index 24d3c91..d06b473 100644
25723--- a/arch/x86/kernel/time.c
25724+++ b/arch/x86/kernel/time.c
25725@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
25726 {
25727 unsigned long pc = instruction_pointer(regs);
25728
25729- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
25730+ if (!user_mode(regs) && in_lock_functions(pc)) {
25731 #ifdef CONFIG_FRAME_POINTER
25732- return *(unsigned long *)(regs->bp + sizeof(long));
25733+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
25734 #else
25735 unsigned long *sp =
25736 (unsigned long *)kernel_stack_pointer(regs);
25737@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
25738 * or above a saved flags. Eflags has bits 22-31 zero,
25739 * kernel addresses don't.
25740 */
25741+
25742+#ifdef CONFIG_PAX_KERNEXEC
25743+ return ktla_ktva(sp[0]);
25744+#else
25745 if (sp[0] >> 22)
25746 return sp[0];
25747 if (sp[1] >> 22)
25748 return sp[1];
25749 #endif
25750+
25751+#endif
25752 }
25753 return pc;
25754 }
25755diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
25756index f7fec09..9991981 100644
25757--- a/arch/x86/kernel/tls.c
25758+++ b/arch/x86/kernel/tls.c
25759@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
25760 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
25761 return -EINVAL;
25762
25763+#ifdef CONFIG_PAX_SEGMEXEC
25764+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
25765+ return -EINVAL;
25766+#endif
25767+
25768 set_tls_desc(p, idx, &info, 1);
25769
25770 return 0;
25771@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
25772
25773 if (kbuf)
25774 info = kbuf;
25775- else if (__copy_from_user(infobuf, ubuf, count))
25776+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
25777 return -EFAULT;
25778 else
25779 info = infobuf;
25780diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
25781index 1c113db..287b42e 100644
25782--- a/arch/x86/kernel/tracepoint.c
25783+++ b/arch/x86/kernel/tracepoint.c
25784@@ -9,11 +9,11 @@
25785 #include <linux/atomic.h>
25786
25787 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
25788-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25789+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25790 (unsigned long) trace_idt_table };
25791
25792 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25793-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
25794+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
25795
25796 static int trace_irq_vector_refcount;
25797 static DEFINE_MUTEX(irq_vector_mutex);
25798diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
25799index 1b23a1c..910de0d 100644
25800--- a/arch/x86/kernel/traps.c
25801+++ b/arch/x86/kernel/traps.c
25802@@ -65,7 +65,7 @@
25803 #include <asm/proto.h>
25804
25805 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25806-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
25807+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
25808 #else
25809 #include <asm/processor-flags.h>
25810 #include <asm/setup.h>
25811@@ -74,7 +74,7 @@ asmlinkage int system_call(void);
25812 #endif
25813
25814 /* Must be page-aligned because the real IDT is used in a fixmap. */
25815-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
25816+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
25817
25818 DECLARE_BITMAP(used_vectors, NR_VECTORS);
25819 EXPORT_SYMBOL_GPL(used_vectors);
25820@@ -106,11 +106,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
25821 }
25822
25823 static int __kprobes
25824-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25825+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
25826 struct pt_regs *regs, long error_code)
25827 {
25828 #ifdef CONFIG_X86_32
25829- if (regs->flags & X86_VM_MASK) {
25830+ if (v8086_mode(regs)) {
25831 /*
25832 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
25833 * On nmi (interrupt 2), do_trap should not be called.
25834@@ -123,12 +123,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25835 return -1;
25836 }
25837 #endif
25838- if (!user_mode(regs)) {
25839+ if (!user_mode_novm(regs)) {
25840 if (!fixup_exception(regs)) {
25841 tsk->thread.error_code = error_code;
25842 tsk->thread.trap_nr = trapnr;
25843+
25844+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25845+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
25846+ str = "PAX: suspicious stack segment fault";
25847+#endif
25848+
25849 die(str, regs, error_code);
25850 }
25851+
25852+#ifdef CONFIG_PAX_REFCOUNT
25853+ if (trapnr == 4)
25854+ pax_report_refcount_overflow(regs);
25855+#endif
25856+
25857 return 0;
25858 }
25859
25860@@ -136,7 +148,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25861 }
25862
25863 static void __kprobes
25864-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25865+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
25866 long error_code, siginfo_t *info)
25867 {
25868 struct task_struct *tsk = current;
25869@@ -160,7 +172,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25870 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
25871 printk_ratelimit()) {
25872 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
25873- tsk->comm, tsk->pid, str,
25874+ tsk->comm, task_pid_nr(tsk), str,
25875 regs->ip, regs->sp, error_code);
25876 print_vma_addr(" in ", regs->ip);
25877 pr_cont("\n");
25878@@ -276,7 +288,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
25879 conditional_sti(regs);
25880
25881 #ifdef CONFIG_X86_32
25882- if (regs->flags & X86_VM_MASK) {
25883+ if (v8086_mode(regs)) {
25884 local_irq_enable();
25885 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
25886 goto exit;
25887@@ -284,18 +296,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
25888 #endif
25889
25890 tsk = current;
25891- if (!user_mode(regs)) {
25892+ if (!user_mode_novm(regs)) {
25893 if (fixup_exception(regs))
25894 goto exit;
25895
25896 tsk->thread.error_code = error_code;
25897 tsk->thread.trap_nr = X86_TRAP_GP;
25898 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
25899- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
25900+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
25901+
25902+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25903+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
25904+ die("PAX: suspicious general protection fault", regs, error_code);
25905+ else
25906+#endif
25907+
25908 die("general protection fault", regs, error_code);
25909+ }
25910 goto exit;
25911 }
25912
25913+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25914+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
25915+ struct mm_struct *mm = tsk->mm;
25916+ unsigned long limit;
25917+
25918+ down_write(&mm->mmap_sem);
25919+ limit = mm->context.user_cs_limit;
25920+ if (limit < TASK_SIZE) {
25921+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
25922+ up_write(&mm->mmap_sem);
25923+ return;
25924+ }
25925+ up_write(&mm->mmap_sem);
25926+ }
25927+#endif
25928+
25929 tsk->thread.error_code = error_code;
25930 tsk->thread.trap_nr = X86_TRAP_GP;
25931
25932@@ -453,7 +489,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
25933 /* It's safe to allow irq's after DR6 has been saved */
25934 preempt_conditional_sti(regs);
25935
25936- if (regs->flags & X86_VM_MASK) {
25937+ if (v8086_mode(regs)) {
25938 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
25939 X86_TRAP_DB);
25940 preempt_conditional_cli(regs);
25941@@ -468,7 +504,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
25942 * We already checked v86 mode above, so we can check for kernel mode
25943 * by just checking the CPL of CS.
25944 */
25945- if ((dr6 & DR_STEP) && !user_mode(regs)) {
25946+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
25947 tsk->thread.debugreg6 &= ~DR_STEP;
25948 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
25949 regs->flags &= ~X86_EFLAGS_TF;
25950@@ -500,7 +536,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
25951 return;
25952 conditional_sti(regs);
25953
25954- if (!user_mode_vm(regs))
25955+ if (!user_mode(regs))
25956 {
25957 if (!fixup_exception(regs)) {
25958 task->thread.error_code = error_code;
25959diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
25960index 2ed8459..7cf329f 100644
25961--- a/arch/x86/kernel/uprobes.c
25962+++ b/arch/x86/kernel/uprobes.c
25963@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
25964 int ret = NOTIFY_DONE;
25965
25966 /* We are only interested in userspace traps */
25967- if (regs && !user_mode_vm(regs))
25968+ if (regs && !user_mode(regs))
25969 return NOTIFY_DONE;
25970
25971 switch (val) {
25972@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
25973
25974 if (ncopied != rasize) {
25975 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
25976- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
25977+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
25978
25979 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
25980 }
25981diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
25982index b9242ba..50c5edd 100644
25983--- a/arch/x86/kernel/verify_cpu.S
25984+++ b/arch/x86/kernel/verify_cpu.S
25985@@ -20,6 +20,7 @@
25986 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
25987 * arch/x86/kernel/trampoline_64.S: secondary processor verification
25988 * arch/x86/kernel/head_32.S: processor startup
25989+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
25990 *
25991 * verify_cpu, returns the status of longmode and SSE in register %eax.
25992 * 0: Success 1: Failure
25993diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
25994index e8edcf5..27f9344 100644
25995--- a/arch/x86/kernel/vm86_32.c
25996+++ b/arch/x86/kernel/vm86_32.c
25997@@ -44,6 +44,7 @@
25998 #include <linux/ptrace.h>
25999 #include <linux/audit.h>
26000 #include <linux/stddef.h>
26001+#include <linux/grsecurity.h>
26002
26003 #include <asm/uaccess.h>
26004 #include <asm/io.h>
26005@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
26006 do_exit(SIGSEGV);
26007 }
26008
26009- tss = &per_cpu(init_tss, get_cpu());
26010+ tss = init_tss + get_cpu();
26011 current->thread.sp0 = current->thread.saved_sp0;
26012 current->thread.sysenter_cs = __KERNEL_CS;
26013 load_sp0(tss, &current->thread);
26014@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
26015
26016 if (tsk->thread.saved_sp0)
26017 return -EPERM;
26018+
26019+#ifdef CONFIG_GRKERNSEC_VM86
26020+ if (!capable(CAP_SYS_RAWIO)) {
26021+ gr_handle_vm86();
26022+ return -EPERM;
26023+ }
26024+#endif
26025+
26026 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
26027 offsetof(struct kernel_vm86_struct, vm86plus) -
26028 sizeof(info.regs));
26029@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
26030 int tmp;
26031 struct vm86plus_struct __user *v86;
26032
26033+#ifdef CONFIG_GRKERNSEC_VM86
26034+ if (!capable(CAP_SYS_RAWIO)) {
26035+ gr_handle_vm86();
26036+ return -EPERM;
26037+ }
26038+#endif
26039+
26040 tsk = current;
26041 switch (cmd) {
26042 case VM86_REQUEST_IRQ:
26043@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
26044 tsk->thread.saved_fs = info->regs32->fs;
26045 tsk->thread.saved_gs = get_user_gs(info->regs32);
26046
26047- tss = &per_cpu(init_tss, get_cpu());
26048+ tss = init_tss + get_cpu();
26049 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
26050 if (cpu_has_sep)
26051 tsk->thread.sysenter_cs = 0;
26052@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
26053 goto cannot_handle;
26054 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
26055 goto cannot_handle;
26056- intr_ptr = (unsigned long __user *) (i << 2);
26057+ intr_ptr = (__force unsigned long __user *) (i << 2);
26058 if (get_user(segoffs, intr_ptr))
26059 goto cannot_handle;
26060 if ((segoffs >> 16) == BIOSSEG)
26061diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
26062index 10c4f30..65408b9 100644
26063--- a/arch/x86/kernel/vmlinux.lds.S
26064+++ b/arch/x86/kernel/vmlinux.lds.S
26065@@ -26,6 +26,13 @@
26066 #include <asm/page_types.h>
26067 #include <asm/cache.h>
26068 #include <asm/boot.h>
26069+#include <asm/segment.h>
26070+
26071+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26072+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
26073+#else
26074+#define __KERNEL_TEXT_OFFSET 0
26075+#endif
26076
26077 #undef i386 /* in case the preprocessor is a 32bit one */
26078
26079@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
26080
26081 PHDRS {
26082 text PT_LOAD FLAGS(5); /* R_E */
26083+#ifdef CONFIG_X86_32
26084+ module PT_LOAD FLAGS(5); /* R_E */
26085+#endif
26086+#ifdef CONFIG_XEN
26087+ rodata PT_LOAD FLAGS(5); /* R_E */
26088+#else
26089+ rodata PT_LOAD FLAGS(4); /* R__ */
26090+#endif
26091 data PT_LOAD FLAGS(6); /* RW_ */
26092-#ifdef CONFIG_X86_64
26093+ init.begin PT_LOAD FLAGS(6); /* RW_ */
26094 #ifdef CONFIG_SMP
26095 percpu PT_LOAD FLAGS(6); /* RW_ */
26096 #endif
26097+ text.init PT_LOAD FLAGS(5); /* R_E */
26098+ text.exit PT_LOAD FLAGS(5); /* R_E */
26099 init PT_LOAD FLAGS(7); /* RWE */
26100-#endif
26101 note PT_NOTE FLAGS(0); /* ___ */
26102 }
26103
26104 SECTIONS
26105 {
26106 #ifdef CONFIG_X86_32
26107- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
26108- phys_startup_32 = startup_32 - LOAD_OFFSET;
26109+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
26110 #else
26111- . = __START_KERNEL;
26112- phys_startup_64 = startup_64 - LOAD_OFFSET;
26113+ . = __START_KERNEL;
26114 #endif
26115
26116 /* Text and read-only data */
26117- .text : AT(ADDR(.text) - LOAD_OFFSET) {
26118- _text = .;
26119+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26120 /* bootstrapping code */
26121+#ifdef CONFIG_X86_32
26122+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26123+#else
26124+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26125+#endif
26126+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26127+ _text = .;
26128 HEAD_TEXT
26129 . = ALIGN(8);
26130 _stext = .;
26131@@ -104,13 +124,47 @@ SECTIONS
26132 IRQENTRY_TEXT
26133 *(.fixup)
26134 *(.gnu.warning)
26135- /* End of text section */
26136- _etext = .;
26137 } :text = 0x9090
26138
26139- NOTES :text :note
26140+ . += __KERNEL_TEXT_OFFSET;
26141
26142- EXCEPTION_TABLE(16) :text = 0x9090
26143+#ifdef CONFIG_X86_32
26144+ . = ALIGN(PAGE_SIZE);
26145+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
26146+
26147+#ifdef CONFIG_PAX_KERNEXEC
26148+ MODULES_EXEC_VADDR = .;
26149+ BYTE(0)
26150+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
26151+ . = ALIGN(HPAGE_SIZE) - 1;
26152+ MODULES_EXEC_END = .;
26153+#endif
26154+
26155+ } :module
26156+#endif
26157+
26158+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
26159+ /* End of text section */
26160+ BYTE(0)
26161+ _etext = . - __KERNEL_TEXT_OFFSET;
26162+ }
26163+
26164+#ifdef CONFIG_X86_32
26165+ . = ALIGN(PAGE_SIZE);
26166+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
26167+ . = ALIGN(PAGE_SIZE);
26168+ *(.empty_zero_page)
26169+ *(.initial_pg_fixmap)
26170+ *(.initial_pg_pmd)
26171+ *(.initial_page_table)
26172+ *(.swapper_pg_dir)
26173+ } :rodata
26174+#endif
26175+
26176+ . = ALIGN(PAGE_SIZE);
26177+ NOTES :rodata :note
26178+
26179+ EXCEPTION_TABLE(16) :rodata
26180
26181 #if defined(CONFIG_DEBUG_RODATA)
26182 /* .text should occupy whole number of pages */
26183@@ -122,16 +176,20 @@ SECTIONS
26184
26185 /* Data */
26186 .data : AT(ADDR(.data) - LOAD_OFFSET) {
26187+
26188+#ifdef CONFIG_PAX_KERNEXEC
26189+ . = ALIGN(HPAGE_SIZE);
26190+#else
26191+ . = ALIGN(PAGE_SIZE);
26192+#endif
26193+
26194 /* Start of data section */
26195 _sdata = .;
26196
26197 /* init_task */
26198 INIT_TASK_DATA(THREAD_SIZE)
26199
26200-#ifdef CONFIG_X86_32
26201- /* 32 bit has nosave before _edata */
26202 NOSAVE_DATA
26203-#endif
26204
26205 PAGE_ALIGNED_DATA(PAGE_SIZE)
26206
26207@@ -172,12 +230,19 @@ SECTIONS
26208 #endif /* CONFIG_X86_64 */
26209
26210 /* Init code and data - will be freed after init */
26211- . = ALIGN(PAGE_SIZE);
26212 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
26213+ BYTE(0)
26214+
26215+#ifdef CONFIG_PAX_KERNEXEC
26216+ . = ALIGN(HPAGE_SIZE);
26217+#else
26218+ . = ALIGN(PAGE_SIZE);
26219+#endif
26220+
26221 __init_begin = .; /* paired with __init_end */
26222- }
26223+ } :init.begin
26224
26225-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
26226+#ifdef CONFIG_SMP
26227 /*
26228 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
26229 * output PHDR, so the next output section - .init.text - should
26230@@ -186,12 +251,27 @@ SECTIONS
26231 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
26232 #endif
26233
26234- INIT_TEXT_SECTION(PAGE_SIZE)
26235-#ifdef CONFIG_X86_64
26236- :init
26237-#endif
26238+ . = ALIGN(PAGE_SIZE);
26239+ init_begin = .;
26240+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
26241+ VMLINUX_SYMBOL(_sinittext) = .;
26242+ INIT_TEXT
26243+ VMLINUX_SYMBOL(_einittext) = .;
26244+ . = ALIGN(PAGE_SIZE);
26245+ } :text.init
26246
26247- INIT_DATA_SECTION(16)
26248+ /*
26249+ * .exit.text is discard at runtime, not link time, to deal with
26250+ * references from .altinstructions and .eh_frame
26251+ */
26252+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26253+ EXIT_TEXT
26254+ . = ALIGN(16);
26255+ } :text.exit
26256+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
26257+
26258+ . = ALIGN(PAGE_SIZE);
26259+ INIT_DATA_SECTION(16) :init
26260
26261 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
26262 __x86_cpu_dev_start = .;
26263@@ -253,19 +333,12 @@ SECTIONS
26264 }
26265
26266 . = ALIGN(8);
26267- /*
26268- * .exit.text is discard at runtime, not link time, to deal with
26269- * references from .altinstructions and .eh_frame
26270- */
26271- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
26272- EXIT_TEXT
26273- }
26274
26275 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
26276 EXIT_DATA
26277 }
26278
26279-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
26280+#ifndef CONFIG_SMP
26281 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
26282 #endif
26283
26284@@ -284,16 +357,10 @@ SECTIONS
26285 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
26286 __smp_locks = .;
26287 *(.smp_locks)
26288- . = ALIGN(PAGE_SIZE);
26289 __smp_locks_end = .;
26290+ . = ALIGN(PAGE_SIZE);
26291 }
26292
26293-#ifdef CONFIG_X86_64
26294- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
26295- NOSAVE_DATA
26296- }
26297-#endif
26298-
26299 /* BSS */
26300 . = ALIGN(PAGE_SIZE);
26301 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
26302@@ -309,6 +376,7 @@ SECTIONS
26303 __brk_base = .;
26304 . += 64 * 1024; /* 64k alignment slop space */
26305 *(.brk_reservation) /* areas brk users have reserved */
26306+ . = ALIGN(HPAGE_SIZE);
26307 __brk_limit = .;
26308 }
26309
26310@@ -335,13 +403,12 @@ SECTIONS
26311 * for the boot processor.
26312 */
26313 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
26314-INIT_PER_CPU(gdt_page);
26315 INIT_PER_CPU(irq_stack_union);
26316
26317 /*
26318 * Build-time check on the image size:
26319 */
26320-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
26321+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
26322 "kernel image bigger than KERNEL_IMAGE_SIZE");
26323
26324 #ifdef CONFIG_SMP
26325diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
26326index 1f96f93..d5c8f7a 100644
26327--- a/arch/x86/kernel/vsyscall_64.c
26328+++ b/arch/x86/kernel/vsyscall_64.c
26329@@ -56,15 +56,13 @@
26330 DEFINE_VVAR(int, vgetcpu_mode);
26331 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
26332
26333-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
26334+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
26335
26336 static int __init vsyscall_setup(char *str)
26337 {
26338 if (str) {
26339 if (!strcmp("emulate", str))
26340 vsyscall_mode = EMULATE;
26341- else if (!strcmp("native", str))
26342- vsyscall_mode = NATIVE;
26343 else if (!strcmp("none", str))
26344 vsyscall_mode = NONE;
26345 else
26346@@ -323,8 +321,7 @@ do_ret:
26347 return true;
26348
26349 sigsegv:
26350- force_sig(SIGSEGV, current);
26351- return true;
26352+ do_group_exit(SIGKILL);
26353 }
26354
26355 /*
26356@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
26357 extern char __vvar_page;
26358 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
26359
26360- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
26361- vsyscall_mode == NATIVE
26362- ? PAGE_KERNEL_VSYSCALL
26363- : PAGE_KERNEL_VVAR);
26364+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
26365 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
26366 (unsigned long)VSYSCALL_START);
26367
26368diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
26369index b014d94..e775258 100644
26370--- a/arch/x86/kernel/x8664_ksyms_64.c
26371+++ b/arch/x86/kernel/x8664_ksyms_64.c
26372@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
26373 EXPORT_SYMBOL(copy_user_generic_unrolled);
26374 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
26375 EXPORT_SYMBOL(__copy_user_nocache);
26376-EXPORT_SYMBOL(_copy_from_user);
26377-EXPORT_SYMBOL(_copy_to_user);
26378
26379 EXPORT_SYMBOL(copy_page);
26380 EXPORT_SYMBOL(clear_page);
26381@@ -66,3 +64,7 @@ EXPORT_SYMBOL(empty_zero_page);
26382 #ifndef CONFIG_PARAVIRT
26383 EXPORT_SYMBOL(native_load_gs_index);
26384 #endif
26385+
26386+#ifdef CONFIG_PAX_PER_CPU_PGD
26387+EXPORT_SYMBOL(cpu_pgd);
26388+#endif
26389diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
26390index 5f24c71..1dadf09 100644
26391--- a/arch/x86/kernel/x86_init.c
26392+++ b/arch/x86/kernel/x86_init.c
26393@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
26394 static void default_nmi_init(void) { };
26395 static int default_i8042_detect(void) { return 1; };
26396
26397-struct x86_platform_ops x86_platform = {
26398+struct x86_platform_ops x86_platform __read_only = {
26399 .calibrate_tsc = native_calibrate_tsc,
26400 .get_wallclock = mach_get_cmos_time,
26401 .set_wallclock = mach_set_rtc_mmss,
26402@@ -107,7 +107,7 @@ struct x86_platform_ops x86_platform = {
26403 };
26404
26405 EXPORT_SYMBOL_GPL(x86_platform);
26406-struct x86_msi_ops x86_msi = {
26407+struct x86_msi_ops x86_msi __read_only = {
26408 .setup_msi_irqs = native_setup_msi_irqs,
26409 .compose_msi_msg = native_compose_msi_msg,
26410 .teardown_msi_irq = native_teardown_msi_irq,
26411@@ -116,7 +116,7 @@ struct x86_msi_ops x86_msi = {
26412 .setup_hpet_msi = default_setup_hpet_msi,
26413 };
26414
26415-struct x86_io_apic_ops x86_io_apic_ops = {
26416+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
26417 .init = native_io_apic_init_mappings,
26418 .read = native_io_apic_read,
26419 .write = native_io_apic_write,
26420diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
26421index 422fd82..c3687ca 100644
26422--- a/arch/x86/kernel/xsave.c
26423+++ b/arch/x86/kernel/xsave.c
26424@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
26425 {
26426 int err;
26427
26428+ buf = (struct xsave_struct __user *)____m(buf);
26429 if (use_xsave())
26430 err = xsave_user(buf);
26431 else if (use_fxsr())
26432@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
26433 */
26434 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
26435 {
26436+ buf = (void __user *)____m(buf);
26437 if (use_xsave()) {
26438 if ((unsigned long)buf % 64 || fx_only) {
26439 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
26440diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
26441index a20ecb5..d0e2194 100644
26442--- a/arch/x86/kvm/cpuid.c
26443+++ b/arch/x86/kvm/cpuid.c
26444@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
26445 struct kvm_cpuid2 *cpuid,
26446 struct kvm_cpuid_entry2 __user *entries)
26447 {
26448- int r;
26449+ int r, i;
26450
26451 r = -E2BIG;
26452 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
26453 goto out;
26454 r = -EFAULT;
26455- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
26456- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26457+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26458 goto out;
26459+ for (i = 0; i < cpuid->nent; ++i) {
26460+ struct kvm_cpuid_entry2 cpuid_entry;
26461+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
26462+ goto out;
26463+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
26464+ }
26465 vcpu->arch.cpuid_nent = cpuid->nent;
26466 kvm_apic_set_version(vcpu);
26467 kvm_x86_ops->cpuid_update(vcpu);
26468@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
26469 struct kvm_cpuid2 *cpuid,
26470 struct kvm_cpuid_entry2 __user *entries)
26471 {
26472- int r;
26473+ int r, i;
26474
26475 r = -E2BIG;
26476 if (cpuid->nent < vcpu->arch.cpuid_nent)
26477 goto out;
26478 r = -EFAULT;
26479- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
26480- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26481+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26482 goto out;
26483+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
26484+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
26485+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
26486+ goto out;
26487+ }
26488 return 0;
26489
26490 out:
26491diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
26492index afc1124..3e431f2 100644
26493--- a/arch/x86/kvm/lapic.c
26494+++ b/arch/x86/kvm/lapic.c
26495@@ -55,7 +55,7 @@
26496 #define APIC_BUS_CYCLE_NS 1
26497
26498 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
26499-#define apic_debug(fmt, arg...)
26500+#define apic_debug(fmt, arg...) do {} while (0)
26501
26502 #define APIC_LVT_NUM 6
26503 /* 14 is the version for Xeon and Pentium 8.4.8*/
26504diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
26505index 7769699..c8aca4a7f 100644
26506--- a/arch/x86/kvm/paging_tmpl.h
26507+++ b/arch/x86/kvm/paging_tmpl.h
26508@@ -208,7 +208,7 @@ retry_walk:
26509 if (unlikely(kvm_is_error_hva(host_addr)))
26510 goto error;
26511
26512- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
26513+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
26514 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
26515 goto error;
26516 walker->ptep_user[walker->level - 1] = ptep_user;
26517diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
26518index c0bc803..6837a50 100644
26519--- a/arch/x86/kvm/svm.c
26520+++ b/arch/x86/kvm/svm.c
26521@@ -3501,7 +3501,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
26522 int cpu = raw_smp_processor_id();
26523
26524 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
26525+
26526+ pax_open_kernel();
26527 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
26528+ pax_close_kernel();
26529+
26530 load_TR_desc();
26531 }
26532
26533@@ -3902,6 +3906,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
26534 #endif
26535 #endif
26536
26537+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26538+ __set_fs(current_thread_info()->addr_limit);
26539+#endif
26540+
26541 reload_tss(vcpu);
26542
26543 local_irq_disable();
26544diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
26545index 064d0be..f5f758e 100644
26546--- a/arch/x86/kvm/vmx.c
26547+++ b/arch/x86/kvm/vmx.c
26548@@ -1311,12 +1311,12 @@ static void vmcs_write64(unsigned long field, u64 value)
26549 #endif
26550 }
26551
26552-static void vmcs_clear_bits(unsigned long field, u32 mask)
26553+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
26554 {
26555 vmcs_writel(field, vmcs_readl(field) & ~mask);
26556 }
26557
26558-static void vmcs_set_bits(unsigned long field, u32 mask)
26559+static void vmcs_set_bits(unsigned long field, unsigned long mask)
26560 {
26561 vmcs_writel(field, vmcs_readl(field) | mask);
26562 }
26563@@ -1517,7 +1517,11 @@ static void reload_tss(void)
26564 struct desc_struct *descs;
26565
26566 descs = (void *)gdt->address;
26567+
26568+ pax_open_kernel();
26569 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
26570+ pax_close_kernel();
26571+
26572 load_TR_desc();
26573 }
26574
26575@@ -1741,6 +1745,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
26576 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
26577 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
26578
26579+#ifdef CONFIG_PAX_PER_CPU_PGD
26580+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26581+#endif
26582+
26583 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
26584 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
26585 vmx->loaded_vmcs->cpu = cpu;
26586@@ -2940,8 +2948,11 @@ static __init int hardware_setup(void)
26587 if (!cpu_has_vmx_flexpriority())
26588 flexpriority_enabled = 0;
26589
26590- if (!cpu_has_vmx_tpr_shadow())
26591- kvm_x86_ops->update_cr8_intercept = NULL;
26592+ if (!cpu_has_vmx_tpr_shadow()) {
26593+ pax_open_kernel();
26594+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26595+ pax_close_kernel();
26596+ }
26597
26598 if (enable_ept && !cpu_has_vmx_ept_2m_page())
26599 kvm_disable_largepages();
26600@@ -2952,13 +2963,15 @@ static __init int hardware_setup(void)
26601 if (!cpu_has_vmx_apicv())
26602 enable_apicv = 0;
26603
26604+ pax_open_kernel();
26605 if (enable_apicv)
26606- kvm_x86_ops->update_cr8_intercept = NULL;
26607+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26608 else {
26609- kvm_x86_ops->hwapic_irr_update = NULL;
26610- kvm_x86_ops->deliver_posted_interrupt = NULL;
26611- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26612+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
26613+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
26614+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26615 }
26616+ pax_close_kernel();
26617
26618 if (nested)
26619 nested_vmx_setup_ctls_msrs();
26620@@ -4081,7 +4094,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26621
26622 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
26623 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
26624+
26625+#ifndef CONFIG_PAX_PER_CPU_PGD
26626 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26627+#endif
26628
26629 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
26630 #ifdef CONFIG_X86_64
26631@@ -4103,7 +4119,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26632 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
26633 vmx->host_idt_base = dt.address;
26634
26635- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
26636+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
26637
26638 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
26639 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
26640@@ -7039,6 +7055,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26641 "jmp 2f \n\t"
26642 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
26643 "2: "
26644+
26645+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26646+ "ljmp %[cs],$3f\n\t"
26647+ "3: "
26648+#endif
26649+
26650 /* Save guest registers, load host registers, keep flags */
26651 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
26652 "pop %0 \n\t"
26653@@ -7091,6 +7113,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26654 #endif
26655 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
26656 [wordsize]"i"(sizeof(ulong))
26657+
26658+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26659+ ,[cs]"i"(__KERNEL_CS)
26660+#endif
26661+
26662 : "cc", "memory"
26663 #ifdef CONFIG_X86_64
26664 , "rax", "rbx", "rdi", "rsi"
26665@@ -7104,7 +7131,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26666 if (debugctlmsr)
26667 update_debugctlmsr(debugctlmsr);
26668
26669-#ifndef CONFIG_X86_64
26670+#ifdef CONFIG_X86_32
26671 /*
26672 * The sysexit path does not restore ds/es, so we must set them to
26673 * a reasonable value ourselves.
26674@@ -7113,8 +7140,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26675 * may be executed in interrupt context, which saves and restore segments
26676 * around it, nullifying its effect.
26677 */
26678- loadsegment(ds, __USER_DS);
26679- loadsegment(es, __USER_DS);
26680+ loadsegment(ds, __KERNEL_DS);
26681+ loadsegment(es, __KERNEL_DS);
26682+ loadsegment(ss, __KERNEL_DS);
26683+
26684+#ifdef CONFIG_PAX_KERNEXEC
26685+ loadsegment(fs, __KERNEL_PERCPU);
26686+#endif
26687+
26688+#ifdef CONFIG_PAX_MEMORY_UDEREF
26689+ __set_fs(current_thread_info()->addr_limit);
26690+#endif
26691+
26692 #endif
26693
26694 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
26695diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
26696index d21bce5..fdae9f1 100644
26697--- a/arch/x86/kvm/x86.c
26698+++ b/arch/x86/kvm/x86.c
26699@@ -1766,8 +1766,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
26700 {
26701 struct kvm *kvm = vcpu->kvm;
26702 int lm = is_long_mode(vcpu);
26703- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26704- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26705+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26706+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26707 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
26708 : kvm->arch.xen_hvm_config.blob_size_32;
26709 u32 page_num = data & ~PAGE_MASK;
26710@@ -2650,6 +2650,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
26711 if (n < msr_list.nmsrs)
26712 goto out;
26713 r = -EFAULT;
26714+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
26715+ goto out;
26716 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
26717 num_msrs_to_save * sizeof(u32)))
26718 goto out;
26719@@ -5344,7 +5346,7 @@ static struct notifier_block pvclock_gtod_notifier = {
26720 };
26721 #endif
26722
26723-int kvm_arch_init(void *opaque)
26724+int kvm_arch_init(const void *opaque)
26725 {
26726 int r;
26727 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
26728diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
26729index 6a22c19..1763f04 100644
26730--- a/arch/x86/lguest/boot.c
26731+++ b/arch/x86/lguest/boot.c
26732@@ -1201,9 +1201,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
26733 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
26734 * Launcher to reboot us.
26735 */
26736-static void lguest_restart(char *reason)
26737+static __noreturn void lguest_restart(char *reason)
26738 {
26739 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
26740+ BUG();
26741 }
26742
26743 /*G:050
26744diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
26745index 00933d5..3a64af9 100644
26746--- a/arch/x86/lib/atomic64_386_32.S
26747+++ b/arch/x86/lib/atomic64_386_32.S
26748@@ -48,6 +48,10 @@ BEGIN(read)
26749 movl (v), %eax
26750 movl 4(v), %edx
26751 RET_ENDP
26752+BEGIN(read_unchecked)
26753+ movl (v), %eax
26754+ movl 4(v), %edx
26755+RET_ENDP
26756 #undef v
26757
26758 #define v %esi
26759@@ -55,6 +59,10 @@ BEGIN(set)
26760 movl %ebx, (v)
26761 movl %ecx, 4(v)
26762 RET_ENDP
26763+BEGIN(set_unchecked)
26764+ movl %ebx, (v)
26765+ movl %ecx, 4(v)
26766+RET_ENDP
26767 #undef v
26768
26769 #define v %esi
26770@@ -70,6 +78,20 @@ RET_ENDP
26771 BEGIN(add)
26772 addl %eax, (v)
26773 adcl %edx, 4(v)
26774+
26775+#ifdef CONFIG_PAX_REFCOUNT
26776+ jno 0f
26777+ subl %eax, (v)
26778+ sbbl %edx, 4(v)
26779+ int $4
26780+0:
26781+ _ASM_EXTABLE(0b, 0b)
26782+#endif
26783+
26784+RET_ENDP
26785+BEGIN(add_unchecked)
26786+ addl %eax, (v)
26787+ adcl %edx, 4(v)
26788 RET_ENDP
26789 #undef v
26790
26791@@ -77,6 +99,24 @@ RET_ENDP
26792 BEGIN(add_return)
26793 addl (v), %eax
26794 adcl 4(v), %edx
26795+
26796+#ifdef CONFIG_PAX_REFCOUNT
26797+ into
26798+1234:
26799+ _ASM_EXTABLE(1234b, 2f)
26800+#endif
26801+
26802+ movl %eax, (v)
26803+ movl %edx, 4(v)
26804+
26805+#ifdef CONFIG_PAX_REFCOUNT
26806+2:
26807+#endif
26808+
26809+RET_ENDP
26810+BEGIN(add_return_unchecked)
26811+ addl (v), %eax
26812+ adcl 4(v), %edx
26813 movl %eax, (v)
26814 movl %edx, 4(v)
26815 RET_ENDP
26816@@ -86,6 +126,20 @@ RET_ENDP
26817 BEGIN(sub)
26818 subl %eax, (v)
26819 sbbl %edx, 4(v)
26820+
26821+#ifdef CONFIG_PAX_REFCOUNT
26822+ jno 0f
26823+ addl %eax, (v)
26824+ adcl %edx, 4(v)
26825+ int $4
26826+0:
26827+ _ASM_EXTABLE(0b, 0b)
26828+#endif
26829+
26830+RET_ENDP
26831+BEGIN(sub_unchecked)
26832+ subl %eax, (v)
26833+ sbbl %edx, 4(v)
26834 RET_ENDP
26835 #undef v
26836
26837@@ -96,6 +150,27 @@ BEGIN(sub_return)
26838 sbbl $0, %edx
26839 addl (v), %eax
26840 adcl 4(v), %edx
26841+
26842+#ifdef CONFIG_PAX_REFCOUNT
26843+ into
26844+1234:
26845+ _ASM_EXTABLE(1234b, 2f)
26846+#endif
26847+
26848+ movl %eax, (v)
26849+ movl %edx, 4(v)
26850+
26851+#ifdef CONFIG_PAX_REFCOUNT
26852+2:
26853+#endif
26854+
26855+RET_ENDP
26856+BEGIN(sub_return_unchecked)
26857+ negl %edx
26858+ negl %eax
26859+ sbbl $0, %edx
26860+ addl (v), %eax
26861+ adcl 4(v), %edx
26862 movl %eax, (v)
26863 movl %edx, 4(v)
26864 RET_ENDP
26865@@ -105,6 +180,20 @@ RET_ENDP
26866 BEGIN(inc)
26867 addl $1, (v)
26868 adcl $0, 4(v)
26869+
26870+#ifdef CONFIG_PAX_REFCOUNT
26871+ jno 0f
26872+ subl $1, (v)
26873+ sbbl $0, 4(v)
26874+ int $4
26875+0:
26876+ _ASM_EXTABLE(0b, 0b)
26877+#endif
26878+
26879+RET_ENDP
26880+BEGIN(inc_unchecked)
26881+ addl $1, (v)
26882+ adcl $0, 4(v)
26883 RET_ENDP
26884 #undef v
26885
26886@@ -114,6 +203,26 @@ BEGIN(inc_return)
26887 movl 4(v), %edx
26888 addl $1, %eax
26889 adcl $0, %edx
26890+
26891+#ifdef CONFIG_PAX_REFCOUNT
26892+ into
26893+1234:
26894+ _ASM_EXTABLE(1234b, 2f)
26895+#endif
26896+
26897+ movl %eax, (v)
26898+ movl %edx, 4(v)
26899+
26900+#ifdef CONFIG_PAX_REFCOUNT
26901+2:
26902+#endif
26903+
26904+RET_ENDP
26905+BEGIN(inc_return_unchecked)
26906+ movl (v), %eax
26907+ movl 4(v), %edx
26908+ addl $1, %eax
26909+ adcl $0, %edx
26910 movl %eax, (v)
26911 movl %edx, 4(v)
26912 RET_ENDP
26913@@ -123,6 +232,20 @@ RET_ENDP
26914 BEGIN(dec)
26915 subl $1, (v)
26916 sbbl $0, 4(v)
26917+
26918+#ifdef CONFIG_PAX_REFCOUNT
26919+ jno 0f
26920+ addl $1, (v)
26921+ adcl $0, 4(v)
26922+ int $4
26923+0:
26924+ _ASM_EXTABLE(0b, 0b)
26925+#endif
26926+
26927+RET_ENDP
26928+BEGIN(dec_unchecked)
26929+ subl $1, (v)
26930+ sbbl $0, 4(v)
26931 RET_ENDP
26932 #undef v
26933
26934@@ -132,6 +255,26 @@ BEGIN(dec_return)
26935 movl 4(v), %edx
26936 subl $1, %eax
26937 sbbl $0, %edx
26938+
26939+#ifdef CONFIG_PAX_REFCOUNT
26940+ into
26941+1234:
26942+ _ASM_EXTABLE(1234b, 2f)
26943+#endif
26944+
26945+ movl %eax, (v)
26946+ movl %edx, 4(v)
26947+
26948+#ifdef CONFIG_PAX_REFCOUNT
26949+2:
26950+#endif
26951+
26952+RET_ENDP
26953+BEGIN(dec_return_unchecked)
26954+ movl (v), %eax
26955+ movl 4(v), %edx
26956+ subl $1, %eax
26957+ sbbl $0, %edx
26958 movl %eax, (v)
26959 movl %edx, 4(v)
26960 RET_ENDP
26961@@ -143,6 +286,13 @@ BEGIN(add_unless)
26962 adcl %edx, %edi
26963 addl (v), %eax
26964 adcl 4(v), %edx
26965+
26966+#ifdef CONFIG_PAX_REFCOUNT
26967+ into
26968+1234:
26969+ _ASM_EXTABLE(1234b, 2f)
26970+#endif
26971+
26972 cmpl %eax, %ecx
26973 je 3f
26974 1:
26975@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
26976 1:
26977 addl $1, %eax
26978 adcl $0, %edx
26979+
26980+#ifdef CONFIG_PAX_REFCOUNT
26981+ into
26982+1234:
26983+ _ASM_EXTABLE(1234b, 2f)
26984+#endif
26985+
26986 movl %eax, (v)
26987 movl %edx, 4(v)
26988 movl $1, %eax
26989@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
26990 movl 4(v), %edx
26991 subl $1, %eax
26992 sbbl $0, %edx
26993+
26994+#ifdef CONFIG_PAX_REFCOUNT
26995+ into
26996+1234:
26997+ _ASM_EXTABLE(1234b, 1f)
26998+#endif
26999+
27000 js 1f
27001 movl %eax, (v)
27002 movl %edx, 4(v)
27003diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
27004index f5cc9eb..51fa319 100644
27005--- a/arch/x86/lib/atomic64_cx8_32.S
27006+++ b/arch/x86/lib/atomic64_cx8_32.S
27007@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
27008 CFI_STARTPROC
27009
27010 read64 %ecx
27011+ pax_force_retaddr
27012 ret
27013 CFI_ENDPROC
27014 ENDPROC(atomic64_read_cx8)
27015
27016+ENTRY(atomic64_read_unchecked_cx8)
27017+ CFI_STARTPROC
27018+
27019+ read64 %ecx
27020+ pax_force_retaddr
27021+ ret
27022+ CFI_ENDPROC
27023+ENDPROC(atomic64_read_unchecked_cx8)
27024+
27025 ENTRY(atomic64_set_cx8)
27026 CFI_STARTPROC
27027
27028@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
27029 cmpxchg8b (%esi)
27030 jne 1b
27031
27032+ pax_force_retaddr
27033 ret
27034 CFI_ENDPROC
27035 ENDPROC(atomic64_set_cx8)
27036
27037+ENTRY(atomic64_set_unchecked_cx8)
27038+ CFI_STARTPROC
27039+
27040+1:
27041+/* we don't need LOCK_PREFIX since aligned 64-bit writes
27042+ * are atomic on 586 and newer */
27043+ cmpxchg8b (%esi)
27044+ jne 1b
27045+
27046+ pax_force_retaddr
27047+ ret
27048+ CFI_ENDPROC
27049+ENDPROC(atomic64_set_unchecked_cx8)
27050+
27051 ENTRY(atomic64_xchg_cx8)
27052 CFI_STARTPROC
27053
27054@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
27055 cmpxchg8b (%esi)
27056 jne 1b
27057
27058+ pax_force_retaddr
27059 ret
27060 CFI_ENDPROC
27061 ENDPROC(atomic64_xchg_cx8)
27062
27063-.macro addsub_return func ins insc
27064-ENTRY(atomic64_\func\()_return_cx8)
27065+.macro addsub_return func ins insc unchecked=""
27066+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27067 CFI_STARTPROC
27068 SAVE ebp
27069 SAVE ebx
27070@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
27071 movl %edx, %ecx
27072 \ins\()l %esi, %ebx
27073 \insc\()l %edi, %ecx
27074+
27075+.ifb \unchecked
27076+#ifdef CONFIG_PAX_REFCOUNT
27077+ into
27078+2:
27079+ _ASM_EXTABLE(2b, 3f)
27080+#endif
27081+.endif
27082+
27083 LOCK_PREFIX
27084 cmpxchg8b (%ebp)
27085 jne 1b
27086-
27087-10:
27088 movl %ebx, %eax
27089 movl %ecx, %edx
27090+
27091+.ifb \unchecked
27092+#ifdef CONFIG_PAX_REFCOUNT
27093+3:
27094+#endif
27095+.endif
27096+
27097 RESTORE edi
27098 RESTORE esi
27099 RESTORE ebx
27100 RESTORE ebp
27101+ pax_force_retaddr
27102 ret
27103 CFI_ENDPROC
27104-ENDPROC(atomic64_\func\()_return_cx8)
27105+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27106 .endm
27107
27108 addsub_return add add adc
27109 addsub_return sub sub sbb
27110+addsub_return add add adc _unchecked
27111+addsub_return sub sub sbb _unchecked
27112
27113-.macro incdec_return func ins insc
27114-ENTRY(atomic64_\func\()_return_cx8)
27115+.macro incdec_return func ins insc unchecked=""
27116+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27117 CFI_STARTPROC
27118 SAVE ebx
27119
27120@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
27121 movl %edx, %ecx
27122 \ins\()l $1, %ebx
27123 \insc\()l $0, %ecx
27124+
27125+.ifb \unchecked
27126+#ifdef CONFIG_PAX_REFCOUNT
27127+ into
27128+2:
27129+ _ASM_EXTABLE(2b, 3f)
27130+#endif
27131+.endif
27132+
27133 LOCK_PREFIX
27134 cmpxchg8b (%esi)
27135 jne 1b
27136
27137-10:
27138 movl %ebx, %eax
27139 movl %ecx, %edx
27140+
27141+.ifb \unchecked
27142+#ifdef CONFIG_PAX_REFCOUNT
27143+3:
27144+#endif
27145+.endif
27146+
27147 RESTORE ebx
27148+ pax_force_retaddr
27149 ret
27150 CFI_ENDPROC
27151-ENDPROC(atomic64_\func\()_return_cx8)
27152+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27153 .endm
27154
27155 incdec_return inc add adc
27156 incdec_return dec sub sbb
27157+incdec_return inc add adc _unchecked
27158+incdec_return dec sub sbb _unchecked
27159
27160 ENTRY(atomic64_dec_if_positive_cx8)
27161 CFI_STARTPROC
27162@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
27163 movl %edx, %ecx
27164 subl $1, %ebx
27165 sbb $0, %ecx
27166+
27167+#ifdef CONFIG_PAX_REFCOUNT
27168+ into
27169+1234:
27170+ _ASM_EXTABLE(1234b, 2f)
27171+#endif
27172+
27173 js 2f
27174 LOCK_PREFIX
27175 cmpxchg8b (%esi)
27176@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
27177 movl %ebx, %eax
27178 movl %ecx, %edx
27179 RESTORE ebx
27180+ pax_force_retaddr
27181 ret
27182 CFI_ENDPROC
27183 ENDPROC(atomic64_dec_if_positive_cx8)
27184@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
27185 movl %edx, %ecx
27186 addl %ebp, %ebx
27187 adcl %edi, %ecx
27188+
27189+#ifdef CONFIG_PAX_REFCOUNT
27190+ into
27191+1234:
27192+ _ASM_EXTABLE(1234b, 3f)
27193+#endif
27194+
27195 LOCK_PREFIX
27196 cmpxchg8b (%esi)
27197 jne 1b
27198@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
27199 CFI_ADJUST_CFA_OFFSET -8
27200 RESTORE ebx
27201 RESTORE ebp
27202+ pax_force_retaddr
27203 ret
27204 4:
27205 cmpl %edx, 4(%esp)
27206@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
27207 xorl %ecx, %ecx
27208 addl $1, %ebx
27209 adcl %edx, %ecx
27210+
27211+#ifdef CONFIG_PAX_REFCOUNT
27212+ into
27213+1234:
27214+ _ASM_EXTABLE(1234b, 3f)
27215+#endif
27216+
27217 LOCK_PREFIX
27218 cmpxchg8b (%esi)
27219 jne 1b
27220@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
27221 movl $1, %eax
27222 3:
27223 RESTORE ebx
27224+ pax_force_retaddr
27225 ret
27226 CFI_ENDPROC
27227 ENDPROC(atomic64_inc_not_zero_cx8)
27228diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
27229index e78b8ee..7e173a8 100644
27230--- a/arch/x86/lib/checksum_32.S
27231+++ b/arch/x86/lib/checksum_32.S
27232@@ -29,7 +29,8 @@
27233 #include <asm/dwarf2.h>
27234 #include <asm/errno.h>
27235 #include <asm/asm.h>
27236-
27237+#include <asm/segment.h>
27238+
27239 /*
27240 * computes a partial checksum, e.g. for TCP/UDP fragments
27241 */
27242@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
27243
27244 #define ARGBASE 16
27245 #define FP 12
27246-
27247-ENTRY(csum_partial_copy_generic)
27248+
27249+ENTRY(csum_partial_copy_generic_to_user)
27250 CFI_STARTPROC
27251+
27252+#ifdef CONFIG_PAX_MEMORY_UDEREF
27253+ pushl_cfi %gs
27254+ popl_cfi %es
27255+ jmp csum_partial_copy_generic
27256+#endif
27257+
27258+ENTRY(csum_partial_copy_generic_from_user)
27259+
27260+#ifdef CONFIG_PAX_MEMORY_UDEREF
27261+ pushl_cfi %gs
27262+ popl_cfi %ds
27263+#endif
27264+
27265+ENTRY(csum_partial_copy_generic)
27266 subl $4,%esp
27267 CFI_ADJUST_CFA_OFFSET 4
27268 pushl_cfi %edi
27269@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
27270 jmp 4f
27271 SRC(1: movw (%esi), %bx )
27272 addl $2, %esi
27273-DST( movw %bx, (%edi) )
27274+DST( movw %bx, %es:(%edi) )
27275 addl $2, %edi
27276 addw %bx, %ax
27277 adcl $0, %eax
27278@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
27279 SRC(1: movl (%esi), %ebx )
27280 SRC( movl 4(%esi), %edx )
27281 adcl %ebx, %eax
27282-DST( movl %ebx, (%edi) )
27283+DST( movl %ebx, %es:(%edi) )
27284 adcl %edx, %eax
27285-DST( movl %edx, 4(%edi) )
27286+DST( movl %edx, %es:4(%edi) )
27287
27288 SRC( movl 8(%esi), %ebx )
27289 SRC( movl 12(%esi), %edx )
27290 adcl %ebx, %eax
27291-DST( movl %ebx, 8(%edi) )
27292+DST( movl %ebx, %es:8(%edi) )
27293 adcl %edx, %eax
27294-DST( movl %edx, 12(%edi) )
27295+DST( movl %edx, %es:12(%edi) )
27296
27297 SRC( movl 16(%esi), %ebx )
27298 SRC( movl 20(%esi), %edx )
27299 adcl %ebx, %eax
27300-DST( movl %ebx, 16(%edi) )
27301+DST( movl %ebx, %es:16(%edi) )
27302 adcl %edx, %eax
27303-DST( movl %edx, 20(%edi) )
27304+DST( movl %edx, %es:20(%edi) )
27305
27306 SRC( movl 24(%esi), %ebx )
27307 SRC( movl 28(%esi), %edx )
27308 adcl %ebx, %eax
27309-DST( movl %ebx, 24(%edi) )
27310+DST( movl %ebx, %es:24(%edi) )
27311 adcl %edx, %eax
27312-DST( movl %edx, 28(%edi) )
27313+DST( movl %edx, %es:28(%edi) )
27314
27315 lea 32(%esi), %esi
27316 lea 32(%edi), %edi
27317@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
27318 shrl $2, %edx # This clears CF
27319 SRC(3: movl (%esi), %ebx )
27320 adcl %ebx, %eax
27321-DST( movl %ebx, (%edi) )
27322+DST( movl %ebx, %es:(%edi) )
27323 lea 4(%esi), %esi
27324 lea 4(%edi), %edi
27325 dec %edx
27326@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
27327 jb 5f
27328 SRC( movw (%esi), %cx )
27329 leal 2(%esi), %esi
27330-DST( movw %cx, (%edi) )
27331+DST( movw %cx, %es:(%edi) )
27332 leal 2(%edi), %edi
27333 je 6f
27334 shll $16,%ecx
27335 SRC(5: movb (%esi), %cl )
27336-DST( movb %cl, (%edi) )
27337+DST( movb %cl, %es:(%edi) )
27338 6: addl %ecx, %eax
27339 adcl $0, %eax
27340 7:
27341@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
27342
27343 6001:
27344 movl ARGBASE+20(%esp), %ebx # src_err_ptr
27345- movl $-EFAULT, (%ebx)
27346+ movl $-EFAULT, %ss:(%ebx)
27347
27348 # zero the complete destination - computing the rest
27349 # is too much work
27350@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
27351
27352 6002:
27353 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27354- movl $-EFAULT,(%ebx)
27355+ movl $-EFAULT,%ss:(%ebx)
27356 jmp 5000b
27357
27358 .previous
27359
27360+ pushl_cfi %ss
27361+ popl_cfi %ds
27362+ pushl_cfi %ss
27363+ popl_cfi %es
27364 popl_cfi %ebx
27365 CFI_RESTORE ebx
27366 popl_cfi %esi
27367@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
27368 popl_cfi %ecx # equivalent to addl $4,%esp
27369 ret
27370 CFI_ENDPROC
27371-ENDPROC(csum_partial_copy_generic)
27372+ENDPROC(csum_partial_copy_generic_to_user)
27373
27374 #else
27375
27376 /* Version for PentiumII/PPro */
27377
27378 #define ROUND1(x) \
27379+ nop; nop; nop; \
27380 SRC(movl x(%esi), %ebx ) ; \
27381 addl %ebx, %eax ; \
27382- DST(movl %ebx, x(%edi) ) ;
27383+ DST(movl %ebx, %es:x(%edi)) ;
27384
27385 #define ROUND(x) \
27386+ nop; nop; nop; \
27387 SRC(movl x(%esi), %ebx ) ; \
27388 adcl %ebx, %eax ; \
27389- DST(movl %ebx, x(%edi) ) ;
27390+ DST(movl %ebx, %es:x(%edi)) ;
27391
27392 #define ARGBASE 12
27393-
27394-ENTRY(csum_partial_copy_generic)
27395+
27396+ENTRY(csum_partial_copy_generic_to_user)
27397 CFI_STARTPROC
27398+
27399+#ifdef CONFIG_PAX_MEMORY_UDEREF
27400+ pushl_cfi %gs
27401+ popl_cfi %es
27402+ jmp csum_partial_copy_generic
27403+#endif
27404+
27405+ENTRY(csum_partial_copy_generic_from_user)
27406+
27407+#ifdef CONFIG_PAX_MEMORY_UDEREF
27408+ pushl_cfi %gs
27409+ popl_cfi %ds
27410+#endif
27411+
27412+ENTRY(csum_partial_copy_generic)
27413 pushl_cfi %ebx
27414 CFI_REL_OFFSET ebx, 0
27415 pushl_cfi %edi
27416@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
27417 subl %ebx, %edi
27418 lea -1(%esi),%edx
27419 andl $-32,%edx
27420- lea 3f(%ebx,%ebx), %ebx
27421+ lea 3f(%ebx,%ebx,2), %ebx
27422 testl %esi, %esi
27423 jmp *%ebx
27424 1: addl $64,%esi
27425@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
27426 jb 5f
27427 SRC( movw (%esi), %dx )
27428 leal 2(%esi), %esi
27429-DST( movw %dx, (%edi) )
27430+DST( movw %dx, %es:(%edi) )
27431 leal 2(%edi), %edi
27432 je 6f
27433 shll $16,%edx
27434 5:
27435 SRC( movb (%esi), %dl )
27436-DST( movb %dl, (%edi) )
27437+DST( movb %dl, %es:(%edi) )
27438 6: addl %edx, %eax
27439 adcl $0, %eax
27440 7:
27441 .section .fixup, "ax"
27442 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
27443- movl $-EFAULT, (%ebx)
27444+ movl $-EFAULT, %ss:(%ebx)
27445 # zero the complete destination (computing the rest is too much work)
27446 movl ARGBASE+8(%esp),%edi # dst
27447 movl ARGBASE+12(%esp),%ecx # len
27448@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
27449 rep; stosb
27450 jmp 7b
27451 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27452- movl $-EFAULT, (%ebx)
27453+ movl $-EFAULT, %ss:(%ebx)
27454 jmp 7b
27455 .previous
27456
27457+#ifdef CONFIG_PAX_MEMORY_UDEREF
27458+ pushl_cfi %ss
27459+ popl_cfi %ds
27460+ pushl_cfi %ss
27461+ popl_cfi %es
27462+#endif
27463+
27464 popl_cfi %esi
27465 CFI_RESTORE esi
27466 popl_cfi %edi
27467@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
27468 CFI_RESTORE ebx
27469 ret
27470 CFI_ENDPROC
27471-ENDPROC(csum_partial_copy_generic)
27472+ENDPROC(csum_partial_copy_generic_to_user)
27473
27474 #undef ROUND
27475 #undef ROUND1
27476diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
27477index f2145cf..cea889d 100644
27478--- a/arch/x86/lib/clear_page_64.S
27479+++ b/arch/x86/lib/clear_page_64.S
27480@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
27481 movl $4096/8,%ecx
27482 xorl %eax,%eax
27483 rep stosq
27484+ pax_force_retaddr
27485 ret
27486 CFI_ENDPROC
27487 ENDPROC(clear_page_c)
27488@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
27489 movl $4096,%ecx
27490 xorl %eax,%eax
27491 rep stosb
27492+ pax_force_retaddr
27493 ret
27494 CFI_ENDPROC
27495 ENDPROC(clear_page_c_e)
27496@@ -43,6 +45,7 @@ ENTRY(clear_page)
27497 leaq 64(%rdi),%rdi
27498 jnz .Lloop
27499 nop
27500+ pax_force_retaddr
27501 ret
27502 CFI_ENDPROC
27503 .Lclear_page_end:
27504@@ -58,7 +61,7 @@ ENDPROC(clear_page)
27505
27506 #include <asm/cpufeature.h>
27507
27508- .section .altinstr_replacement,"ax"
27509+ .section .altinstr_replacement,"a"
27510 1: .byte 0xeb /* jmp <disp8> */
27511 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
27512 2: .byte 0xeb /* jmp <disp8> */
27513diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
27514index 1e572c5..2a162cd 100644
27515--- a/arch/x86/lib/cmpxchg16b_emu.S
27516+++ b/arch/x86/lib/cmpxchg16b_emu.S
27517@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
27518
27519 popf
27520 mov $1, %al
27521+ pax_force_retaddr
27522 ret
27523
27524 not_same:
27525 popf
27526 xor %al,%al
27527+ pax_force_retaddr
27528 ret
27529
27530 CFI_ENDPROC
27531diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
27532index 176cca6..1166c50 100644
27533--- a/arch/x86/lib/copy_page_64.S
27534+++ b/arch/x86/lib/copy_page_64.S
27535@@ -9,6 +9,7 @@ copy_page_rep:
27536 CFI_STARTPROC
27537 movl $4096/8, %ecx
27538 rep movsq
27539+ pax_force_retaddr
27540 ret
27541 CFI_ENDPROC
27542 ENDPROC(copy_page_rep)
27543@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
27544
27545 ENTRY(copy_page)
27546 CFI_STARTPROC
27547- subq $2*8, %rsp
27548- CFI_ADJUST_CFA_OFFSET 2*8
27549+ subq $3*8, %rsp
27550+ CFI_ADJUST_CFA_OFFSET 3*8
27551 movq %rbx, (%rsp)
27552 CFI_REL_OFFSET rbx, 0
27553 movq %r12, 1*8(%rsp)
27554 CFI_REL_OFFSET r12, 1*8
27555+ movq %r13, 2*8(%rsp)
27556+ CFI_REL_OFFSET r13, 2*8
27557
27558 movl $(4096/64)-5, %ecx
27559 .p2align 4
27560@@ -36,7 +39,7 @@ ENTRY(copy_page)
27561 movq 0x8*2(%rsi), %rdx
27562 movq 0x8*3(%rsi), %r8
27563 movq 0x8*4(%rsi), %r9
27564- movq 0x8*5(%rsi), %r10
27565+ movq 0x8*5(%rsi), %r13
27566 movq 0x8*6(%rsi), %r11
27567 movq 0x8*7(%rsi), %r12
27568
27569@@ -47,7 +50,7 @@ ENTRY(copy_page)
27570 movq %rdx, 0x8*2(%rdi)
27571 movq %r8, 0x8*3(%rdi)
27572 movq %r9, 0x8*4(%rdi)
27573- movq %r10, 0x8*5(%rdi)
27574+ movq %r13, 0x8*5(%rdi)
27575 movq %r11, 0x8*6(%rdi)
27576 movq %r12, 0x8*7(%rdi)
27577
27578@@ -66,7 +69,7 @@ ENTRY(copy_page)
27579 movq 0x8*2(%rsi), %rdx
27580 movq 0x8*3(%rsi), %r8
27581 movq 0x8*4(%rsi), %r9
27582- movq 0x8*5(%rsi), %r10
27583+ movq 0x8*5(%rsi), %r13
27584 movq 0x8*6(%rsi), %r11
27585 movq 0x8*7(%rsi), %r12
27586
27587@@ -75,7 +78,7 @@ ENTRY(copy_page)
27588 movq %rdx, 0x8*2(%rdi)
27589 movq %r8, 0x8*3(%rdi)
27590 movq %r9, 0x8*4(%rdi)
27591- movq %r10, 0x8*5(%rdi)
27592+ movq %r13, 0x8*5(%rdi)
27593 movq %r11, 0x8*6(%rdi)
27594 movq %r12, 0x8*7(%rdi)
27595
27596@@ -87,8 +90,11 @@ ENTRY(copy_page)
27597 CFI_RESTORE rbx
27598 movq 1*8(%rsp), %r12
27599 CFI_RESTORE r12
27600- addq $2*8, %rsp
27601- CFI_ADJUST_CFA_OFFSET -2*8
27602+ movq 2*8(%rsp), %r13
27603+ CFI_RESTORE r13
27604+ addq $3*8, %rsp
27605+ CFI_ADJUST_CFA_OFFSET -3*8
27606+ pax_force_retaddr
27607 ret
27608 .Lcopy_page_end:
27609 CFI_ENDPROC
27610@@ -99,7 +105,7 @@ ENDPROC(copy_page)
27611
27612 #include <asm/cpufeature.h>
27613
27614- .section .altinstr_replacement,"ax"
27615+ .section .altinstr_replacement,"a"
27616 1: .byte 0xeb /* jmp <disp8> */
27617 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
27618 2:
27619diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
27620index a30ca15..6b3f4e1 100644
27621--- a/arch/x86/lib/copy_user_64.S
27622+++ b/arch/x86/lib/copy_user_64.S
27623@@ -18,31 +18,7 @@
27624 #include <asm/alternative-asm.h>
27625 #include <asm/asm.h>
27626 #include <asm/smap.h>
27627-
27628-/*
27629- * By placing feature2 after feature1 in altinstructions section, we logically
27630- * implement:
27631- * If CPU has feature2, jmp to alt2 is used
27632- * else if CPU has feature1, jmp to alt1 is used
27633- * else jmp to orig is used.
27634- */
27635- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
27636-0:
27637- .byte 0xe9 /* 32bit jump */
27638- .long \orig-1f /* by default jump to orig */
27639-1:
27640- .section .altinstr_replacement,"ax"
27641-2: .byte 0xe9 /* near jump with 32bit immediate */
27642- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
27643-3: .byte 0xe9 /* near jump with 32bit immediate */
27644- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
27645- .previous
27646-
27647- .section .altinstructions,"a"
27648- altinstruction_entry 0b,2b,\feature1,5,5
27649- altinstruction_entry 0b,3b,\feature2,5,5
27650- .previous
27651- .endm
27652+#include <asm/pgtable.h>
27653
27654 .macro ALIGN_DESTINATION
27655 #ifdef FIX_ALIGNMENT
27656@@ -70,52 +46,6 @@
27657 #endif
27658 .endm
27659
27660-/* Standard copy_to_user with segment limit checking */
27661-ENTRY(_copy_to_user)
27662- CFI_STARTPROC
27663- GET_THREAD_INFO(%rax)
27664- movq %rdi,%rcx
27665- addq %rdx,%rcx
27666- jc bad_to_user
27667- cmpq TI_addr_limit(%rax),%rcx
27668- ja bad_to_user
27669- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27670- copy_user_generic_unrolled,copy_user_generic_string, \
27671- copy_user_enhanced_fast_string
27672- CFI_ENDPROC
27673-ENDPROC(_copy_to_user)
27674-
27675-/* Standard copy_from_user with segment limit checking */
27676-ENTRY(_copy_from_user)
27677- CFI_STARTPROC
27678- GET_THREAD_INFO(%rax)
27679- movq %rsi,%rcx
27680- addq %rdx,%rcx
27681- jc bad_from_user
27682- cmpq TI_addr_limit(%rax),%rcx
27683- ja bad_from_user
27684- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27685- copy_user_generic_unrolled,copy_user_generic_string, \
27686- copy_user_enhanced_fast_string
27687- CFI_ENDPROC
27688-ENDPROC(_copy_from_user)
27689-
27690- .section .fixup,"ax"
27691- /* must zero dest */
27692-ENTRY(bad_from_user)
27693-bad_from_user:
27694- CFI_STARTPROC
27695- movl %edx,%ecx
27696- xorl %eax,%eax
27697- rep
27698- stosb
27699-bad_to_user:
27700- movl %edx,%eax
27701- ret
27702- CFI_ENDPROC
27703-ENDPROC(bad_from_user)
27704- .previous
27705-
27706 /*
27707 * copy_user_generic_unrolled - memory copy with exception handling.
27708 * This version is for CPUs like P4 that don't have efficient micro
27709@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
27710 */
27711 ENTRY(copy_user_generic_unrolled)
27712 CFI_STARTPROC
27713+ ASM_PAX_OPEN_USERLAND
27714 ASM_STAC
27715 cmpl $8,%edx
27716 jb 20f /* less then 8 bytes, go to byte copy loop */
27717@@ -141,19 +72,19 @@ ENTRY(copy_user_generic_unrolled)
27718 jz 17f
27719 1: movq (%rsi),%r8
27720 2: movq 1*8(%rsi),%r9
27721-3: movq 2*8(%rsi),%r10
27722+3: movq 2*8(%rsi),%rax
27723 4: movq 3*8(%rsi),%r11
27724 5: movq %r8,(%rdi)
27725 6: movq %r9,1*8(%rdi)
27726-7: movq %r10,2*8(%rdi)
27727+7: movq %rax,2*8(%rdi)
27728 8: movq %r11,3*8(%rdi)
27729 9: movq 4*8(%rsi),%r8
27730 10: movq 5*8(%rsi),%r9
27731-11: movq 6*8(%rsi),%r10
27732+11: movq 6*8(%rsi),%rax
27733 12: movq 7*8(%rsi),%r11
27734 13: movq %r8,4*8(%rdi)
27735 14: movq %r9,5*8(%rdi)
27736-15: movq %r10,6*8(%rdi)
27737+15: movq %rax,6*8(%rdi)
27738 16: movq %r11,7*8(%rdi)
27739 leaq 64(%rsi),%rsi
27740 leaq 64(%rdi),%rdi
27741@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
27742 jnz 21b
27743 23: xor %eax,%eax
27744 ASM_CLAC
27745+ ASM_PAX_CLOSE_USERLAND
27746+ pax_force_retaddr
27747 ret
27748
27749 .section .fixup,"ax"
27750@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
27751 */
27752 ENTRY(copy_user_generic_string)
27753 CFI_STARTPROC
27754+ ASM_PAX_OPEN_USERLAND
27755 ASM_STAC
27756 andl %edx,%edx
27757 jz 4f
27758@@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
27759 movsb
27760 4: xorl %eax,%eax
27761 ASM_CLAC
27762+ ASM_PAX_CLOSE_USERLAND
27763+ pax_force_retaddr
27764 ret
27765
27766 .section .fixup,"ax"
27767@@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
27768 */
27769 ENTRY(copy_user_enhanced_fast_string)
27770 CFI_STARTPROC
27771+ ASM_PAX_OPEN_USERLAND
27772 ASM_STAC
27773 andl %edx,%edx
27774 jz 2f
27775@@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
27776 movsb
27777 2: xorl %eax,%eax
27778 ASM_CLAC
27779+ ASM_PAX_CLOSE_USERLAND
27780+ pax_force_retaddr
27781 ret
27782
27783 .section .fixup,"ax"
27784diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
27785index 6a4f43c..55d26f2 100644
27786--- a/arch/x86/lib/copy_user_nocache_64.S
27787+++ b/arch/x86/lib/copy_user_nocache_64.S
27788@@ -8,6 +8,7 @@
27789
27790 #include <linux/linkage.h>
27791 #include <asm/dwarf2.h>
27792+#include <asm/alternative-asm.h>
27793
27794 #define FIX_ALIGNMENT 1
27795
27796@@ -16,6 +17,7 @@
27797 #include <asm/thread_info.h>
27798 #include <asm/asm.h>
27799 #include <asm/smap.h>
27800+#include <asm/pgtable.h>
27801
27802 .macro ALIGN_DESTINATION
27803 #ifdef FIX_ALIGNMENT
27804@@ -49,6 +51,16 @@
27805 */
27806 ENTRY(__copy_user_nocache)
27807 CFI_STARTPROC
27808+
27809+#ifdef CONFIG_PAX_MEMORY_UDEREF
27810+ mov pax_user_shadow_base,%rcx
27811+ cmp %rcx,%rsi
27812+ jae 1f
27813+ add %rcx,%rsi
27814+1:
27815+#endif
27816+
27817+ ASM_PAX_OPEN_USERLAND
27818 ASM_STAC
27819 cmpl $8,%edx
27820 jb 20f /* less then 8 bytes, go to byte copy loop */
27821@@ -59,19 +71,19 @@ ENTRY(__copy_user_nocache)
27822 jz 17f
27823 1: movq (%rsi),%r8
27824 2: movq 1*8(%rsi),%r9
27825-3: movq 2*8(%rsi),%r10
27826+3: movq 2*8(%rsi),%rax
27827 4: movq 3*8(%rsi),%r11
27828 5: movnti %r8,(%rdi)
27829 6: movnti %r9,1*8(%rdi)
27830-7: movnti %r10,2*8(%rdi)
27831+7: movnti %rax,2*8(%rdi)
27832 8: movnti %r11,3*8(%rdi)
27833 9: movq 4*8(%rsi),%r8
27834 10: movq 5*8(%rsi),%r9
27835-11: movq 6*8(%rsi),%r10
27836+11: movq 6*8(%rsi),%rax
27837 12: movq 7*8(%rsi),%r11
27838 13: movnti %r8,4*8(%rdi)
27839 14: movnti %r9,5*8(%rdi)
27840-15: movnti %r10,6*8(%rdi)
27841+15: movnti %rax,6*8(%rdi)
27842 16: movnti %r11,7*8(%rdi)
27843 leaq 64(%rsi),%rsi
27844 leaq 64(%rdi),%rdi
27845@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
27846 jnz 21b
27847 23: xorl %eax,%eax
27848 ASM_CLAC
27849+ ASM_PAX_CLOSE_USERLAND
27850 sfence
27851+ pax_force_retaddr
27852 ret
27853
27854 .section .fixup,"ax"
27855diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
27856index 2419d5f..953ee51 100644
27857--- a/arch/x86/lib/csum-copy_64.S
27858+++ b/arch/x86/lib/csum-copy_64.S
27859@@ -9,6 +9,7 @@
27860 #include <asm/dwarf2.h>
27861 #include <asm/errno.h>
27862 #include <asm/asm.h>
27863+#include <asm/alternative-asm.h>
27864
27865 /*
27866 * Checksum copy with exception handling.
27867@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
27868 CFI_RESTORE rbp
27869 addq $7*8, %rsp
27870 CFI_ADJUST_CFA_OFFSET -7*8
27871+ pax_force_retaddr 0, 1
27872 ret
27873 CFI_RESTORE_STATE
27874
27875diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
27876index 25b7ae8..c40113e 100644
27877--- a/arch/x86/lib/csum-wrappers_64.c
27878+++ b/arch/x86/lib/csum-wrappers_64.c
27879@@ -52,8 +52,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
27880 len -= 2;
27881 }
27882 }
27883- isum = csum_partial_copy_generic((__force const void *)src,
27884+ pax_open_userland();
27885+ stac();
27886+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
27887 dst, len, isum, errp, NULL);
27888+ clac();
27889+ pax_close_userland();
27890 if (unlikely(*errp))
27891 goto out_err;
27892
27893@@ -105,8 +109,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
27894 }
27895
27896 *errp = 0;
27897- return csum_partial_copy_generic(src, (void __force *)dst,
27898+ pax_open_userland();
27899+ stac();
27900+ isum = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
27901 len, isum, NULL, errp);
27902+ clac();
27903+ pax_close_userland();
27904+ return isum;
27905 }
27906 EXPORT_SYMBOL(csum_partial_copy_to_user);
27907
27908diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
27909index a451235..1daa956 100644
27910--- a/arch/x86/lib/getuser.S
27911+++ b/arch/x86/lib/getuser.S
27912@@ -33,17 +33,40 @@
27913 #include <asm/thread_info.h>
27914 #include <asm/asm.h>
27915 #include <asm/smap.h>
27916+#include <asm/segment.h>
27917+#include <asm/pgtable.h>
27918+#include <asm/alternative-asm.h>
27919+
27920+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
27921+#define __copyuser_seg gs;
27922+#else
27923+#define __copyuser_seg
27924+#endif
27925
27926 .text
27927 ENTRY(__get_user_1)
27928 CFI_STARTPROC
27929+
27930+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
27931 GET_THREAD_INFO(%_ASM_DX)
27932 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
27933 jae bad_get_user
27934 ASM_STAC
27935-1: movzbl (%_ASM_AX),%edx
27936+
27937+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27938+ mov pax_user_shadow_base,%_ASM_DX
27939+ cmp %_ASM_DX,%_ASM_AX
27940+ jae 1234f
27941+ add %_ASM_DX,%_ASM_AX
27942+1234:
27943+#endif
27944+
27945+#endif
27946+
27947+1: __copyuser_seg movzbl (%_ASM_AX),%edx
27948 xor %eax,%eax
27949 ASM_CLAC
27950+ pax_force_retaddr
27951 ret
27952 CFI_ENDPROC
27953 ENDPROC(__get_user_1)
27954@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
27955 ENTRY(__get_user_2)
27956 CFI_STARTPROC
27957 add $1,%_ASM_AX
27958+
27959+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
27960 jc bad_get_user
27961 GET_THREAD_INFO(%_ASM_DX)
27962 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
27963 jae bad_get_user
27964 ASM_STAC
27965-2: movzwl -1(%_ASM_AX),%edx
27966+
27967+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27968+ mov pax_user_shadow_base,%_ASM_DX
27969+ cmp %_ASM_DX,%_ASM_AX
27970+ jae 1234f
27971+ add %_ASM_DX,%_ASM_AX
27972+1234:
27973+#endif
27974+
27975+#endif
27976+
27977+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
27978 xor %eax,%eax
27979 ASM_CLAC
27980+ pax_force_retaddr
27981 ret
27982 CFI_ENDPROC
27983 ENDPROC(__get_user_2)
27984@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
27985 ENTRY(__get_user_4)
27986 CFI_STARTPROC
27987 add $3,%_ASM_AX
27988+
27989+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
27990 jc bad_get_user
27991 GET_THREAD_INFO(%_ASM_DX)
27992 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
27993 jae bad_get_user
27994 ASM_STAC
27995-3: movl -3(%_ASM_AX),%edx
27996+
27997+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27998+ mov pax_user_shadow_base,%_ASM_DX
27999+ cmp %_ASM_DX,%_ASM_AX
28000+ jae 1234f
28001+ add %_ASM_DX,%_ASM_AX
28002+1234:
28003+#endif
28004+
28005+#endif
28006+
28007+3: __copyuser_seg movl -3(%_ASM_AX),%edx
28008 xor %eax,%eax
28009 ASM_CLAC
28010+ pax_force_retaddr
28011 ret
28012 CFI_ENDPROC
28013 ENDPROC(__get_user_4)
28014@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
28015 GET_THREAD_INFO(%_ASM_DX)
28016 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28017 jae bad_get_user
28018+
28019+#ifdef CONFIG_PAX_MEMORY_UDEREF
28020+ mov pax_user_shadow_base,%_ASM_DX
28021+ cmp %_ASM_DX,%_ASM_AX
28022+ jae 1234f
28023+ add %_ASM_DX,%_ASM_AX
28024+1234:
28025+#endif
28026+
28027 ASM_STAC
28028 4: movq -7(%_ASM_AX),%rdx
28029 xor %eax,%eax
28030 ASM_CLAC
28031+ pax_force_retaddr
28032 ret
28033 #else
28034 add $7,%_ASM_AX
28035@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
28036 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28037 jae bad_get_user_8
28038 ASM_STAC
28039-4: movl -7(%_ASM_AX),%edx
28040-5: movl -3(%_ASM_AX),%ecx
28041+4: __copyuser_seg movl -7(%_ASM_AX),%edx
28042+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
28043 xor %eax,%eax
28044 ASM_CLAC
28045+ pax_force_retaddr
28046 ret
28047 #endif
28048 CFI_ENDPROC
28049@@ -113,6 +175,7 @@ bad_get_user:
28050 xor %edx,%edx
28051 mov $(-EFAULT),%_ASM_AX
28052 ASM_CLAC
28053+ pax_force_retaddr
28054 ret
28055 CFI_ENDPROC
28056 END(bad_get_user)
28057@@ -124,6 +187,7 @@ bad_get_user_8:
28058 xor %ecx,%ecx
28059 mov $(-EFAULT),%_ASM_AX
28060 ASM_CLAC
28061+ pax_force_retaddr
28062 ret
28063 CFI_ENDPROC
28064 END(bad_get_user_8)
28065diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
28066index 54fcffe..7be149e 100644
28067--- a/arch/x86/lib/insn.c
28068+++ b/arch/x86/lib/insn.c
28069@@ -20,8 +20,10 @@
28070
28071 #ifdef __KERNEL__
28072 #include <linux/string.h>
28073+#include <asm/pgtable_types.h>
28074 #else
28075 #include <string.h>
28076+#define ktla_ktva(addr) addr
28077 #endif
28078 #include <asm/inat.h>
28079 #include <asm/insn.h>
28080@@ -53,8 +55,8 @@
28081 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
28082 {
28083 memset(insn, 0, sizeof(*insn));
28084- insn->kaddr = kaddr;
28085- insn->next_byte = kaddr;
28086+ insn->kaddr = ktla_ktva(kaddr);
28087+ insn->next_byte = ktla_ktva(kaddr);
28088 insn->x86_64 = x86_64 ? 1 : 0;
28089 insn->opnd_bytes = 4;
28090 if (x86_64)
28091diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
28092index 05a95e7..326f2fa 100644
28093--- a/arch/x86/lib/iomap_copy_64.S
28094+++ b/arch/x86/lib/iomap_copy_64.S
28095@@ -17,6 +17,7 @@
28096
28097 #include <linux/linkage.h>
28098 #include <asm/dwarf2.h>
28099+#include <asm/alternative-asm.h>
28100
28101 /*
28102 * override generic version in lib/iomap_copy.c
28103@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
28104 CFI_STARTPROC
28105 movl %edx,%ecx
28106 rep movsd
28107+ pax_force_retaddr
28108 ret
28109 CFI_ENDPROC
28110 ENDPROC(__iowrite32_copy)
28111diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
28112index 56313a3..9b59269 100644
28113--- a/arch/x86/lib/memcpy_64.S
28114+++ b/arch/x86/lib/memcpy_64.S
28115@@ -24,7 +24,7 @@
28116 * This gets patched over the unrolled variant (below) via the
28117 * alternative instructions framework:
28118 */
28119- .section .altinstr_replacement, "ax", @progbits
28120+ .section .altinstr_replacement, "a", @progbits
28121 .Lmemcpy_c:
28122 movq %rdi, %rax
28123 movq %rdx, %rcx
28124@@ -33,6 +33,7 @@
28125 rep movsq
28126 movl %edx, %ecx
28127 rep movsb
28128+ pax_force_retaddr
28129 ret
28130 .Lmemcpy_e:
28131 .previous
28132@@ -44,11 +45,12 @@
28133 * This gets patched over the unrolled variant (below) via the
28134 * alternative instructions framework:
28135 */
28136- .section .altinstr_replacement, "ax", @progbits
28137+ .section .altinstr_replacement, "a", @progbits
28138 .Lmemcpy_c_e:
28139 movq %rdi, %rax
28140 movq %rdx, %rcx
28141 rep movsb
28142+ pax_force_retaddr
28143 ret
28144 .Lmemcpy_e_e:
28145 .previous
28146@@ -76,13 +78,13 @@ ENTRY(memcpy)
28147 */
28148 movq 0*8(%rsi), %r8
28149 movq 1*8(%rsi), %r9
28150- movq 2*8(%rsi), %r10
28151+ movq 2*8(%rsi), %rcx
28152 movq 3*8(%rsi), %r11
28153 leaq 4*8(%rsi), %rsi
28154
28155 movq %r8, 0*8(%rdi)
28156 movq %r9, 1*8(%rdi)
28157- movq %r10, 2*8(%rdi)
28158+ movq %rcx, 2*8(%rdi)
28159 movq %r11, 3*8(%rdi)
28160 leaq 4*8(%rdi), %rdi
28161 jae .Lcopy_forward_loop
28162@@ -105,12 +107,12 @@ ENTRY(memcpy)
28163 subq $0x20, %rdx
28164 movq -1*8(%rsi), %r8
28165 movq -2*8(%rsi), %r9
28166- movq -3*8(%rsi), %r10
28167+ movq -3*8(%rsi), %rcx
28168 movq -4*8(%rsi), %r11
28169 leaq -4*8(%rsi), %rsi
28170 movq %r8, -1*8(%rdi)
28171 movq %r9, -2*8(%rdi)
28172- movq %r10, -3*8(%rdi)
28173+ movq %rcx, -3*8(%rdi)
28174 movq %r11, -4*8(%rdi)
28175 leaq -4*8(%rdi), %rdi
28176 jae .Lcopy_backward_loop
28177@@ -130,12 +132,13 @@ ENTRY(memcpy)
28178 */
28179 movq 0*8(%rsi), %r8
28180 movq 1*8(%rsi), %r9
28181- movq -2*8(%rsi, %rdx), %r10
28182+ movq -2*8(%rsi, %rdx), %rcx
28183 movq -1*8(%rsi, %rdx), %r11
28184 movq %r8, 0*8(%rdi)
28185 movq %r9, 1*8(%rdi)
28186- movq %r10, -2*8(%rdi, %rdx)
28187+ movq %rcx, -2*8(%rdi, %rdx)
28188 movq %r11, -1*8(%rdi, %rdx)
28189+ pax_force_retaddr
28190 retq
28191 .p2align 4
28192 .Lless_16bytes:
28193@@ -148,6 +151,7 @@ ENTRY(memcpy)
28194 movq -1*8(%rsi, %rdx), %r9
28195 movq %r8, 0*8(%rdi)
28196 movq %r9, -1*8(%rdi, %rdx)
28197+ pax_force_retaddr
28198 retq
28199 .p2align 4
28200 .Lless_8bytes:
28201@@ -161,6 +165,7 @@ ENTRY(memcpy)
28202 movl -4(%rsi, %rdx), %r8d
28203 movl %ecx, (%rdi)
28204 movl %r8d, -4(%rdi, %rdx)
28205+ pax_force_retaddr
28206 retq
28207 .p2align 4
28208 .Lless_3bytes:
28209@@ -179,6 +184,7 @@ ENTRY(memcpy)
28210 movb %cl, (%rdi)
28211
28212 .Lend:
28213+ pax_force_retaddr
28214 retq
28215 CFI_ENDPROC
28216 ENDPROC(memcpy)
28217diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
28218index 65268a6..5aa7815 100644
28219--- a/arch/x86/lib/memmove_64.S
28220+++ b/arch/x86/lib/memmove_64.S
28221@@ -61,13 +61,13 @@ ENTRY(memmove)
28222 5:
28223 sub $0x20, %rdx
28224 movq 0*8(%rsi), %r11
28225- movq 1*8(%rsi), %r10
28226+ movq 1*8(%rsi), %rcx
28227 movq 2*8(%rsi), %r9
28228 movq 3*8(%rsi), %r8
28229 leaq 4*8(%rsi), %rsi
28230
28231 movq %r11, 0*8(%rdi)
28232- movq %r10, 1*8(%rdi)
28233+ movq %rcx, 1*8(%rdi)
28234 movq %r9, 2*8(%rdi)
28235 movq %r8, 3*8(%rdi)
28236 leaq 4*8(%rdi), %rdi
28237@@ -81,10 +81,10 @@ ENTRY(memmove)
28238 4:
28239 movq %rdx, %rcx
28240 movq -8(%rsi, %rdx), %r11
28241- lea -8(%rdi, %rdx), %r10
28242+ lea -8(%rdi, %rdx), %r9
28243 shrq $3, %rcx
28244 rep movsq
28245- movq %r11, (%r10)
28246+ movq %r11, (%r9)
28247 jmp 13f
28248 .Lmemmove_end_forward:
28249
28250@@ -95,14 +95,14 @@ ENTRY(memmove)
28251 7:
28252 movq %rdx, %rcx
28253 movq (%rsi), %r11
28254- movq %rdi, %r10
28255+ movq %rdi, %r9
28256 leaq -8(%rsi, %rdx), %rsi
28257 leaq -8(%rdi, %rdx), %rdi
28258 shrq $3, %rcx
28259 std
28260 rep movsq
28261 cld
28262- movq %r11, (%r10)
28263+ movq %r11, (%r9)
28264 jmp 13f
28265
28266 /*
28267@@ -127,13 +127,13 @@ ENTRY(memmove)
28268 8:
28269 subq $0x20, %rdx
28270 movq -1*8(%rsi), %r11
28271- movq -2*8(%rsi), %r10
28272+ movq -2*8(%rsi), %rcx
28273 movq -3*8(%rsi), %r9
28274 movq -4*8(%rsi), %r8
28275 leaq -4*8(%rsi), %rsi
28276
28277 movq %r11, -1*8(%rdi)
28278- movq %r10, -2*8(%rdi)
28279+ movq %rcx, -2*8(%rdi)
28280 movq %r9, -3*8(%rdi)
28281 movq %r8, -4*8(%rdi)
28282 leaq -4*8(%rdi), %rdi
28283@@ -151,11 +151,11 @@ ENTRY(memmove)
28284 * Move data from 16 bytes to 31 bytes.
28285 */
28286 movq 0*8(%rsi), %r11
28287- movq 1*8(%rsi), %r10
28288+ movq 1*8(%rsi), %rcx
28289 movq -2*8(%rsi, %rdx), %r9
28290 movq -1*8(%rsi, %rdx), %r8
28291 movq %r11, 0*8(%rdi)
28292- movq %r10, 1*8(%rdi)
28293+ movq %rcx, 1*8(%rdi)
28294 movq %r9, -2*8(%rdi, %rdx)
28295 movq %r8, -1*8(%rdi, %rdx)
28296 jmp 13f
28297@@ -167,9 +167,9 @@ ENTRY(memmove)
28298 * Move data from 8 bytes to 15 bytes.
28299 */
28300 movq 0*8(%rsi), %r11
28301- movq -1*8(%rsi, %rdx), %r10
28302+ movq -1*8(%rsi, %rdx), %r9
28303 movq %r11, 0*8(%rdi)
28304- movq %r10, -1*8(%rdi, %rdx)
28305+ movq %r9, -1*8(%rdi, %rdx)
28306 jmp 13f
28307 10:
28308 cmpq $4, %rdx
28309@@ -178,9 +178,9 @@ ENTRY(memmove)
28310 * Move data from 4 bytes to 7 bytes.
28311 */
28312 movl (%rsi), %r11d
28313- movl -4(%rsi, %rdx), %r10d
28314+ movl -4(%rsi, %rdx), %r9d
28315 movl %r11d, (%rdi)
28316- movl %r10d, -4(%rdi, %rdx)
28317+ movl %r9d, -4(%rdi, %rdx)
28318 jmp 13f
28319 11:
28320 cmp $2, %rdx
28321@@ -189,9 +189,9 @@ ENTRY(memmove)
28322 * Move data from 2 bytes to 3 bytes.
28323 */
28324 movw (%rsi), %r11w
28325- movw -2(%rsi, %rdx), %r10w
28326+ movw -2(%rsi, %rdx), %r9w
28327 movw %r11w, (%rdi)
28328- movw %r10w, -2(%rdi, %rdx)
28329+ movw %r9w, -2(%rdi, %rdx)
28330 jmp 13f
28331 12:
28332 cmp $1, %rdx
28333@@ -202,14 +202,16 @@ ENTRY(memmove)
28334 movb (%rsi), %r11b
28335 movb %r11b, (%rdi)
28336 13:
28337+ pax_force_retaddr
28338 retq
28339 CFI_ENDPROC
28340
28341- .section .altinstr_replacement,"ax"
28342+ .section .altinstr_replacement,"a"
28343 .Lmemmove_begin_forward_efs:
28344 /* Forward moving data. */
28345 movq %rdx, %rcx
28346 rep movsb
28347+ pax_force_retaddr
28348 retq
28349 .Lmemmove_end_forward_efs:
28350 .previous
28351diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
28352index 2dcb380..50a78bc 100644
28353--- a/arch/x86/lib/memset_64.S
28354+++ b/arch/x86/lib/memset_64.S
28355@@ -16,7 +16,7 @@
28356 *
28357 * rax original destination
28358 */
28359- .section .altinstr_replacement, "ax", @progbits
28360+ .section .altinstr_replacement, "a", @progbits
28361 .Lmemset_c:
28362 movq %rdi,%r9
28363 movq %rdx,%rcx
28364@@ -30,6 +30,7 @@
28365 movl %edx,%ecx
28366 rep stosb
28367 movq %r9,%rax
28368+ pax_force_retaddr
28369 ret
28370 .Lmemset_e:
28371 .previous
28372@@ -45,13 +46,14 @@
28373 *
28374 * rax original destination
28375 */
28376- .section .altinstr_replacement, "ax", @progbits
28377+ .section .altinstr_replacement, "a", @progbits
28378 .Lmemset_c_e:
28379 movq %rdi,%r9
28380 movb %sil,%al
28381 movq %rdx,%rcx
28382 rep stosb
28383 movq %r9,%rax
28384+ pax_force_retaddr
28385 ret
28386 .Lmemset_e_e:
28387 .previous
28388@@ -59,7 +61,7 @@
28389 ENTRY(memset)
28390 ENTRY(__memset)
28391 CFI_STARTPROC
28392- movq %rdi,%r10
28393+ movq %rdi,%r11
28394
28395 /* expand byte value */
28396 movzbl %sil,%ecx
28397@@ -117,7 +119,8 @@ ENTRY(__memset)
28398 jnz .Lloop_1
28399
28400 .Lende:
28401- movq %r10,%rax
28402+ movq %r11,%rax
28403+ pax_force_retaddr
28404 ret
28405
28406 CFI_RESTORE_STATE
28407diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
28408index c9f2d9b..e7fd2c0 100644
28409--- a/arch/x86/lib/mmx_32.c
28410+++ b/arch/x86/lib/mmx_32.c
28411@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28412 {
28413 void *p;
28414 int i;
28415+ unsigned long cr0;
28416
28417 if (unlikely(in_interrupt()))
28418 return __memcpy(to, from, len);
28419@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28420 kernel_fpu_begin();
28421
28422 __asm__ __volatile__ (
28423- "1: prefetch (%0)\n" /* This set is 28 bytes */
28424- " prefetch 64(%0)\n"
28425- " prefetch 128(%0)\n"
28426- " prefetch 192(%0)\n"
28427- " prefetch 256(%0)\n"
28428+ "1: prefetch (%1)\n" /* This set is 28 bytes */
28429+ " prefetch 64(%1)\n"
28430+ " prefetch 128(%1)\n"
28431+ " prefetch 192(%1)\n"
28432+ " prefetch 256(%1)\n"
28433 "2: \n"
28434 ".section .fixup, \"ax\"\n"
28435- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28436+ "3: \n"
28437+
28438+#ifdef CONFIG_PAX_KERNEXEC
28439+ " movl %%cr0, %0\n"
28440+ " movl %0, %%eax\n"
28441+ " andl $0xFFFEFFFF, %%eax\n"
28442+ " movl %%eax, %%cr0\n"
28443+#endif
28444+
28445+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28446+
28447+#ifdef CONFIG_PAX_KERNEXEC
28448+ " movl %0, %%cr0\n"
28449+#endif
28450+
28451 " jmp 2b\n"
28452 ".previous\n"
28453 _ASM_EXTABLE(1b, 3b)
28454- : : "r" (from));
28455+ : "=&r" (cr0) : "r" (from) : "ax");
28456
28457 for ( ; i > 5; i--) {
28458 __asm__ __volatile__ (
28459- "1: prefetch 320(%0)\n"
28460- "2: movq (%0), %%mm0\n"
28461- " movq 8(%0), %%mm1\n"
28462- " movq 16(%0), %%mm2\n"
28463- " movq 24(%0), %%mm3\n"
28464- " movq %%mm0, (%1)\n"
28465- " movq %%mm1, 8(%1)\n"
28466- " movq %%mm2, 16(%1)\n"
28467- " movq %%mm3, 24(%1)\n"
28468- " movq 32(%0), %%mm0\n"
28469- " movq 40(%0), %%mm1\n"
28470- " movq 48(%0), %%mm2\n"
28471- " movq 56(%0), %%mm3\n"
28472- " movq %%mm0, 32(%1)\n"
28473- " movq %%mm1, 40(%1)\n"
28474- " movq %%mm2, 48(%1)\n"
28475- " movq %%mm3, 56(%1)\n"
28476+ "1: prefetch 320(%1)\n"
28477+ "2: movq (%1), %%mm0\n"
28478+ " movq 8(%1), %%mm1\n"
28479+ " movq 16(%1), %%mm2\n"
28480+ " movq 24(%1), %%mm3\n"
28481+ " movq %%mm0, (%2)\n"
28482+ " movq %%mm1, 8(%2)\n"
28483+ " movq %%mm2, 16(%2)\n"
28484+ " movq %%mm3, 24(%2)\n"
28485+ " movq 32(%1), %%mm0\n"
28486+ " movq 40(%1), %%mm1\n"
28487+ " movq 48(%1), %%mm2\n"
28488+ " movq 56(%1), %%mm3\n"
28489+ " movq %%mm0, 32(%2)\n"
28490+ " movq %%mm1, 40(%2)\n"
28491+ " movq %%mm2, 48(%2)\n"
28492+ " movq %%mm3, 56(%2)\n"
28493 ".section .fixup, \"ax\"\n"
28494- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28495+ "3:\n"
28496+
28497+#ifdef CONFIG_PAX_KERNEXEC
28498+ " movl %%cr0, %0\n"
28499+ " movl %0, %%eax\n"
28500+ " andl $0xFFFEFFFF, %%eax\n"
28501+ " movl %%eax, %%cr0\n"
28502+#endif
28503+
28504+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28505+
28506+#ifdef CONFIG_PAX_KERNEXEC
28507+ " movl %0, %%cr0\n"
28508+#endif
28509+
28510 " jmp 2b\n"
28511 ".previous\n"
28512 _ASM_EXTABLE(1b, 3b)
28513- : : "r" (from), "r" (to) : "memory");
28514+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28515
28516 from += 64;
28517 to += 64;
28518@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
28519 static void fast_copy_page(void *to, void *from)
28520 {
28521 int i;
28522+ unsigned long cr0;
28523
28524 kernel_fpu_begin();
28525
28526@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
28527 * but that is for later. -AV
28528 */
28529 __asm__ __volatile__(
28530- "1: prefetch (%0)\n"
28531- " prefetch 64(%0)\n"
28532- " prefetch 128(%0)\n"
28533- " prefetch 192(%0)\n"
28534- " prefetch 256(%0)\n"
28535+ "1: prefetch (%1)\n"
28536+ " prefetch 64(%1)\n"
28537+ " prefetch 128(%1)\n"
28538+ " prefetch 192(%1)\n"
28539+ " prefetch 256(%1)\n"
28540 "2: \n"
28541 ".section .fixup, \"ax\"\n"
28542- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28543+ "3: \n"
28544+
28545+#ifdef CONFIG_PAX_KERNEXEC
28546+ " movl %%cr0, %0\n"
28547+ " movl %0, %%eax\n"
28548+ " andl $0xFFFEFFFF, %%eax\n"
28549+ " movl %%eax, %%cr0\n"
28550+#endif
28551+
28552+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28553+
28554+#ifdef CONFIG_PAX_KERNEXEC
28555+ " movl %0, %%cr0\n"
28556+#endif
28557+
28558 " jmp 2b\n"
28559 ".previous\n"
28560- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28561+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28562
28563 for (i = 0; i < (4096-320)/64; i++) {
28564 __asm__ __volatile__ (
28565- "1: prefetch 320(%0)\n"
28566- "2: movq (%0), %%mm0\n"
28567- " movntq %%mm0, (%1)\n"
28568- " movq 8(%0), %%mm1\n"
28569- " movntq %%mm1, 8(%1)\n"
28570- " movq 16(%0), %%mm2\n"
28571- " movntq %%mm2, 16(%1)\n"
28572- " movq 24(%0), %%mm3\n"
28573- " movntq %%mm3, 24(%1)\n"
28574- " movq 32(%0), %%mm4\n"
28575- " movntq %%mm4, 32(%1)\n"
28576- " movq 40(%0), %%mm5\n"
28577- " movntq %%mm5, 40(%1)\n"
28578- " movq 48(%0), %%mm6\n"
28579- " movntq %%mm6, 48(%1)\n"
28580- " movq 56(%0), %%mm7\n"
28581- " movntq %%mm7, 56(%1)\n"
28582+ "1: prefetch 320(%1)\n"
28583+ "2: movq (%1), %%mm0\n"
28584+ " movntq %%mm0, (%2)\n"
28585+ " movq 8(%1), %%mm1\n"
28586+ " movntq %%mm1, 8(%2)\n"
28587+ " movq 16(%1), %%mm2\n"
28588+ " movntq %%mm2, 16(%2)\n"
28589+ " movq 24(%1), %%mm3\n"
28590+ " movntq %%mm3, 24(%2)\n"
28591+ " movq 32(%1), %%mm4\n"
28592+ " movntq %%mm4, 32(%2)\n"
28593+ " movq 40(%1), %%mm5\n"
28594+ " movntq %%mm5, 40(%2)\n"
28595+ " movq 48(%1), %%mm6\n"
28596+ " movntq %%mm6, 48(%2)\n"
28597+ " movq 56(%1), %%mm7\n"
28598+ " movntq %%mm7, 56(%2)\n"
28599 ".section .fixup, \"ax\"\n"
28600- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28601+ "3:\n"
28602+
28603+#ifdef CONFIG_PAX_KERNEXEC
28604+ " movl %%cr0, %0\n"
28605+ " movl %0, %%eax\n"
28606+ " andl $0xFFFEFFFF, %%eax\n"
28607+ " movl %%eax, %%cr0\n"
28608+#endif
28609+
28610+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28611+
28612+#ifdef CONFIG_PAX_KERNEXEC
28613+ " movl %0, %%cr0\n"
28614+#endif
28615+
28616 " jmp 2b\n"
28617 ".previous\n"
28618- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
28619+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28620
28621 from += 64;
28622 to += 64;
28623@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
28624 static void fast_copy_page(void *to, void *from)
28625 {
28626 int i;
28627+ unsigned long cr0;
28628
28629 kernel_fpu_begin();
28630
28631 __asm__ __volatile__ (
28632- "1: prefetch (%0)\n"
28633- " prefetch 64(%0)\n"
28634- " prefetch 128(%0)\n"
28635- " prefetch 192(%0)\n"
28636- " prefetch 256(%0)\n"
28637+ "1: prefetch (%1)\n"
28638+ " prefetch 64(%1)\n"
28639+ " prefetch 128(%1)\n"
28640+ " prefetch 192(%1)\n"
28641+ " prefetch 256(%1)\n"
28642 "2: \n"
28643 ".section .fixup, \"ax\"\n"
28644- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28645+ "3: \n"
28646+
28647+#ifdef CONFIG_PAX_KERNEXEC
28648+ " movl %%cr0, %0\n"
28649+ " movl %0, %%eax\n"
28650+ " andl $0xFFFEFFFF, %%eax\n"
28651+ " movl %%eax, %%cr0\n"
28652+#endif
28653+
28654+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28655+
28656+#ifdef CONFIG_PAX_KERNEXEC
28657+ " movl %0, %%cr0\n"
28658+#endif
28659+
28660 " jmp 2b\n"
28661 ".previous\n"
28662- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28663+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28664
28665 for (i = 0; i < 4096/64; i++) {
28666 __asm__ __volatile__ (
28667- "1: prefetch 320(%0)\n"
28668- "2: movq (%0), %%mm0\n"
28669- " movq 8(%0), %%mm1\n"
28670- " movq 16(%0), %%mm2\n"
28671- " movq 24(%0), %%mm3\n"
28672- " movq %%mm0, (%1)\n"
28673- " movq %%mm1, 8(%1)\n"
28674- " movq %%mm2, 16(%1)\n"
28675- " movq %%mm3, 24(%1)\n"
28676- " movq 32(%0), %%mm0\n"
28677- " movq 40(%0), %%mm1\n"
28678- " movq 48(%0), %%mm2\n"
28679- " movq 56(%0), %%mm3\n"
28680- " movq %%mm0, 32(%1)\n"
28681- " movq %%mm1, 40(%1)\n"
28682- " movq %%mm2, 48(%1)\n"
28683- " movq %%mm3, 56(%1)\n"
28684+ "1: prefetch 320(%1)\n"
28685+ "2: movq (%1), %%mm0\n"
28686+ " movq 8(%1), %%mm1\n"
28687+ " movq 16(%1), %%mm2\n"
28688+ " movq 24(%1), %%mm3\n"
28689+ " movq %%mm0, (%2)\n"
28690+ " movq %%mm1, 8(%2)\n"
28691+ " movq %%mm2, 16(%2)\n"
28692+ " movq %%mm3, 24(%2)\n"
28693+ " movq 32(%1), %%mm0\n"
28694+ " movq 40(%1), %%mm1\n"
28695+ " movq 48(%1), %%mm2\n"
28696+ " movq 56(%1), %%mm3\n"
28697+ " movq %%mm0, 32(%2)\n"
28698+ " movq %%mm1, 40(%2)\n"
28699+ " movq %%mm2, 48(%2)\n"
28700+ " movq %%mm3, 56(%2)\n"
28701 ".section .fixup, \"ax\"\n"
28702- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28703+ "3:\n"
28704+
28705+#ifdef CONFIG_PAX_KERNEXEC
28706+ " movl %%cr0, %0\n"
28707+ " movl %0, %%eax\n"
28708+ " andl $0xFFFEFFFF, %%eax\n"
28709+ " movl %%eax, %%cr0\n"
28710+#endif
28711+
28712+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28713+
28714+#ifdef CONFIG_PAX_KERNEXEC
28715+ " movl %0, %%cr0\n"
28716+#endif
28717+
28718 " jmp 2b\n"
28719 ".previous\n"
28720 _ASM_EXTABLE(1b, 3b)
28721- : : "r" (from), "r" (to) : "memory");
28722+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28723
28724 from += 64;
28725 to += 64;
28726diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
28727index f6d13ee..aca5f0b 100644
28728--- a/arch/x86/lib/msr-reg.S
28729+++ b/arch/x86/lib/msr-reg.S
28730@@ -3,6 +3,7 @@
28731 #include <asm/dwarf2.h>
28732 #include <asm/asm.h>
28733 #include <asm/msr.h>
28734+#include <asm/alternative-asm.h>
28735
28736 #ifdef CONFIG_X86_64
28737 /*
28738@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
28739 CFI_STARTPROC
28740 pushq_cfi %rbx
28741 pushq_cfi %rbp
28742- movq %rdi, %r10 /* Save pointer */
28743+ movq %rdi, %r9 /* Save pointer */
28744 xorl %r11d, %r11d /* Return value */
28745 movl (%rdi), %eax
28746 movl 4(%rdi), %ecx
28747@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
28748 movl 28(%rdi), %edi
28749 CFI_REMEMBER_STATE
28750 1: \op
28751-2: movl %eax, (%r10)
28752+2: movl %eax, (%r9)
28753 movl %r11d, %eax /* Return value */
28754- movl %ecx, 4(%r10)
28755- movl %edx, 8(%r10)
28756- movl %ebx, 12(%r10)
28757- movl %ebp, 20(%r10)
28758- movl %esi, 24(%r10)
28759- movl %edi, 28(%r10)
28760+ movl %ecx, 4(%r9)
28761+ movl %edx, 8(%r9)
28762+ movl %ebx, 12(%r9)
28763+ movl %ebp, 20(%r9)
28764+ movl %esi, 24(%r9)
28765+ movl %edi, 28(%r9)
28766 popq_cfi %rbp
28767 popq_cfi %rbx
28768+ pax_force_retaddr
28769 ret
28770 3:
28771 CFI_RESTORE_STATE
28772diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
28773index fc6ba17..d4d989d 100644
28774--- a/arch/x86/lib/putuser.S
28775+++ b/arch/x86/lib/putuser.S
28776@@ -16,7 +16,9 @@
28777 #include <asm/errno.h>
28778 #include <asm/asm.h>
28779 #include <asm/smap.h>
28780-
28781+#include <asm/segment.h>
28782+#include <asm/pgtable.h>
28783+#include <asm/alternative-asm.h>
28784
28785 /*
28786 * __put_user_X
28787@@ -30,57 +32,125 @@
28788 * as they get called from within inline assembly.
28789 */
28790
28791-#define ENTER CFI_STARTPROC ; \
28792- GET_THREAD_INFO(%_ASM_BX)
28793-#define EXIT ASM_CLAC ; \
28794- ret ; \
28795+#define ENTER CFI_STARTPROC
28796+#define EXIT ASM_CLAC ; \
28797+ pax_force_retaddr ; \
28798+ ret ; \
28799 CFI_ENDPROC
28800
28801+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28802+#define _DEST %_ASM_CX,%_ASM_BX
28803+#else
28804+#define _DEST %_ASM_CX
28805+#endif
28806+
28807+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28808+#define __copyuser_seg gs;
28809+#else
28810+#define __copyuser_seg
28811+#endif
28812+
28813 .text
28814 ENTRY(__put_user_1)
28815 ENTER
28816+
28817+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28818+ GET_THREAD_INFO(%_ASM_BX)
28819 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
28820 jae bad_put_user
28821 ASM_STAC
28822-1: movb %al,(%_ASM_CX)
28823+
28824+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28825+ mov pax_user_shadow_base,%_ASM_BX
28826+ cmp %_ASM_BX,%_ASM_CX
28827+ jb 1234f
28828+ xor %ebx,%ebx
28829+1234:
28830+#endif
28831+
28832+#endif
28833+
28834+1: __copyuser_seg movb %al,(_DEST)
28835 xor %eax,%eax
28836 EXIT
28837 ENDPROC(__put_user_1)
28838
28839 ENTRY(__put_user_2)
28840 ENTER
28841+
28842+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28843+ GET_THREAD_INFO(%_ASM_BX)
28844 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28845 sub $1,%_ASM_BX
28846 cmp %_ASM_BX,%_ASM_CX
28847 jae bad_put_user
28848 ASM_STAC
28849-2: movw %ax,(%_ASM_CX)
28850+
28851+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28852+ mov pax_user_shadow_base,%_ASM_BX
28853+ cmp %_ASM_BX,%_ASM_CX
28854+ jb 1234f
28855+ xor %ebx,%ebx
28856+1234:
28857+#endif
28858+
28859+#endif
28860+
28861+2: __copyuser_seg movw %ax,(_DEST)
28862 xor %eax,%eax
28863 EXIT
28864 ENDPROC(__put_user_2)
28865
28866 ENTRY(__put_user_4)
28867 ENTER
28868+
28869+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28870+ GET_THREAD_INFO(%_ASM_BX)
28871 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28872 sub $3,%_ASM_BX
28873 cmp %_ASM_BX,%_ASM_CX
28874 jae bad_put_user
28875 ASM_STAC
28876-3: movl %eax,(%_ASM_CX)
28877+
28878+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28879+ mov pax_user_shadow_base,%_ASM_BX
28880+ cmp %_ASM_BX,%_ASM_CX
28881+ jb 1234f
28882+ xor %ebx,%ebx
28883+1234:
28884+#endif
28885+
28886+#endif
28887+
28888+3: __copyuser_seg movl %eax,(_DEST)
28889 xor %eax,%eax
28890 EXIT
28891 ENDPROC(__put_user_4)
28892
28893 ENTRY(__put_user_8)
28894 ENTER
28895+
28896+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28897+ GET_THREAD_INFO(%_ASM_BX)
28898 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28899 sub $7,%_ASM_BX
28900 cmp %_ASM_BX,%_ASM_CX
28901 jae bad_put_user
28902 ASM_STAC
28903-4: mov %_ASM_AX,(%_ASM_CX)
28904+
28905+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28906+ mov pax_user_shadow_base,%_ASM_BX
28907+ cmp %_ASM_BX,%_ASM_CX
28908+ jb 1234f
28909+ xor %ebx,%ebx
28910+1234:
28911+#endif
28912+
28913+#endif
28914+
28915+4: __copyuser_seg mov %_ASM_AX,(_DEST)
28916 #ifdef CONFIG_X86_32
28917-5: movl %edx,4(%_ASM_CX)
28918+5: __copyuser_seg movl %edx,4(_DEST)
28919 #endif
28920 xor %eax,%eax
28921 EXIT
28922diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
28923index 1cad221..de671ee 100644
28924--- a/arch/x86/lib/rwlock.S
28925+++ b/arch/x86/lib/rwlock.S
28926@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
28927 FRAME
28928 0: LOCK_PREFIX
28929 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
28930+
28931+#ifdef CONFIG_PAX_REFCOUNT
28932+ jno 1234f
28933+ LOCK_PREFIX
28934+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
28935+ int $4
28936+1234:
28937+ _ASM_EXTABLE(1234b, 1234b)
28938+#endif
28939+
28940 1: rep; nop
28941 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
28942 jne 1b
28943 LOCK_PREFIX
28944 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
28945+
28946+#ifdef CONFIG_PAX_REFCOUNT
28947+ jno 1234f
28948+ LOCK_PREFIX
28949+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
28950+ int $4
28951+1234:
28952+ _ASM_EXTABLE(1234b, 1234b)
28953+#endif
28954+
28955 jnz 0b
28956 ENDFRAME
28957+ pax_force_retaddr
28958 ret
28959 CFI_ENDPROC
28960 END(__write_lock_failed)
28961@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
28962 FRAME
28963 0: LOCK_PREFIX
28964 READ_LOCK_SIZE(inc) (%__lock_ptr)
28965+
28966+#ifdef CONFIG_PAX_REFCOUNT
28967+ jno 1234f
28968+ LOCK_PREFIX
28969+ READ_LOCK_SIZE(dec) (%__lock_ptr)
28970+ int $4
28971+1234:
28972+ _ASM_EXTABLE(1234b, 1234b)
28973+#endif
28974+
28975 1: rep; nop
28976 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
28977 js 1b
28978 LOCK_PREFIX
28979 READ_LOCK_SIZE(dec) (%__lock_ptr)
28980+
28981+#ifdef CONFIG_PAX_REFCOUNT
28982+ jno 1234f
28983+ LOCK_PREFIX
28984+ READ_LOCK_SIZE(inc) (%__lock_ptr)
28985+ int $4
28986+1234:
28987+ _ASM_EXTABLE(1234b, 1234b)
28988+#endif
28989+
28990 js 0b
28991 ENDFRAME
28992+ pax_force_retaddr
28993 ret
28994 CFI_ENDPROC
28995 END(__read_lock_failed)
28996diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
28997index 5dff5f0..cadebf4 100644
28998--- a/arch/x86/lib/rwsem.S
28999+++ b/arch/x86/lib/rwsem.S
29000@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
29001 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29002 CFI_RESTORE __ASM_REG(dx)
29003 restore_common_regs
29004+ pax_force_retaddr
29005 ret
29006 CFI_ENDPROC
29007 ENDPROC(call_rwsem_down_read_failed)
29008@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
29009 movq %rax,%rdi
29010 call rwsem_down_write_failed
29011 restore_common_regs
29012+ pax_force_retaddr
29013 ret
29014 CFI_ENDPROC
29015 ENDPROC(call_rwsem_down_write_failed)
29016@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
29017 movq %rax,%rdi
29018 call rwsem_wake
29019 restore_common_regs
29020-1: ret
29021+1: pax_force_retaddr
29022+ ret
29023 CFI_ENDPROC
29024 ENDPROC(call_rwsem_wake)
29025
29026@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
29027 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29028 CFI_RESTORE __ASM_REG(dx)
29029 restore_common_regs
29030+ pax_force_retaddr
29031 ret
29032 CFI_ENDPROC
29033 ENDPROC(call_rwsem_downgrade_wake)
29034diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
29035index a63efd6..ccecad8 100644
29036--- a/arch/x86/lib/thunk_64.S
29037+++ b/arch/x86/lib/thunk_64.S
29038@@ -8,6 +8,7 @@
29039 #include <linux/linkage.h>
29040 #include <asm/dwarf2.h>
29041 #include <asm/calling.h>
29042+#include <asm/alternative-asm.h>
29043
29044 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
29045 .macro THUNK name, func, put_ret_addr_in_rdi=0
29046@@ -41,5 +42,6 @@
29047 SAVE_ARGS
29048 restore:
29049 RESTORE_ARGS
29050+ pax_force_retaddr
29051 ret
29052 CFI_ENDPROC
29053diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
29054index 3eb18ac..6890bc3 100644
29055--- a/arch/x86/lib/usercopy_32.c
29056+++ b/arch/x86/lib/usercopy_32.c
29057@@ -42,11 +42,13 @@ do { \
29058 int __d0; \
29059 might_fault(); \
29060 __asm__ __volatile__( \
29061+ __COPYUSER_SET_ES \
29062 ASM_STAC "\n" \
29063 "0: rep; stosl\n" \
29064 " movl %2,%0\n" \
29065 "1: rep; stosb\n" \
29066 "2: " ASM_CLAC "\n" \
29067+ __COPYUSER_RESTORE_ES \
29068 ".section .fixup,\"ax\"\n" \
29069 "3: lea 0(%2,%0,4),%0\n" \
29070 " jmp 2b\n" \
29071@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
29072
29073 #ifdef CONFIG_X86_INTEL_USERCOPY
29074 static unsigned long
29075-__copy_user_intel(void __user *to, const void *from, unsigned long size)
29076+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
29077 {
29078 int d0, d1;
29079 __asm__ __volatile__(
29080@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29081 " .align 2,0x90\n"
29082 "3: movl 0(%4), %%eax\n"
29083 "4: movl 4(%4), %%edx\n"
29084- "5: movl %%eax, 0(%3)\n"
29085- "6: movl %%edx, 4(%3)\n"
29086+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
29087+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
29088 "7: movl 8(%4), %%eax\n"
29089 "8: movl 12(%4),%%edx\n"
29090- "9: movl %%eax, 8(%3)\n"
29091- "10: movl %%edx, 12(%3)\n"
29092+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
29093+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
29094 "11: movl 16(%4), %%eax\n"
29095 "12: movl 20(%4), %%edx\n"
29096- "13: movl %%eax, 16(%3)\n"
29097- "14: movl %%edx, 20(%3)\n"
29098+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
29099+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
29100 "15: movl 24(%4), %%eax\n"
29101 "16: movl 28(%4), %%edx\n"
29102- "17: movl %%eax, 24(%3)\n"
29103- "18: movl %%edx, 28(%3)\n"
29104+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
29105+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
29106 "19: movl 32(%4), %%eax\n"
29107 "20: movl 36(%4), %%edx\n"
29108- "21: movl %%eax, 32(%3)\n"
29109- "22: movl %%edx, 36(%3)\n"
29110+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
29111+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
29112 "23: movl 40(%4), %%eax\n"
29113 "24: movl 44(%4), %%edx\n"
29114- "25: movl %%eax, 40(%3)\n"
29115- "26: movl %%edx, 44(%3)\n"
29116+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
29117+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
29118 "27: movl 48(%4), %%eax\n"
29119 "28: movl 52(%4), %%edx\n"
29120- "29: movl %%eax, 48(%3)\n"
29121- "30: movl %%edx, 52(%3)\n"
29122+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
29123+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
29124 "31: movl 56(%4), %%eax\n"
29125 "32: movl 60(%4), %%edx\n"
29126- "33: movl %%eax, 56(%3)\n"
29127- "34: movl %%edx, 60(%3)\n"
29128+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
29129+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
29130 " addl $-64, %0\n"
29131 " addl $64, %4\n"
29132 " addl $64, %3\n"
29133@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29134 " shrl $2, %0\n"
29135 " andl $3, %%eax\n"
29136 " cld\n"
29137+ __COPYUSER_SET_ES
29138 "99: rep; movsl\n"
29139 "36: movl %%eax, %0\n"
29140 "37: rep; movsb\n"
29141 "100:\n"
29142+ __COPYUSER_RESTORE_ES
29143 ".section .fixup,\"ax\"\n"
29144 "101: lea 0(%%eax,%0,4),%0\n"
29145 " jmp 100b\n"
29146@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29147 }
29148
29149 static unsigned long
29150+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
29151+{
29152+ int d0, d1;
29153+ __asm__ __volatile__(
29154+ " .align 2,0x90\n"
29155+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
29156+ " cmpl $67, %0\n"
29157+ " jbe 3f\n"
29158+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
29159+ " .align 2,0x90\n"
29160+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
29161+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
29162+ "5: movl %%eax, 0(%3)\n"
29163+ "6: movl %%edx, 4(%3)\n"
29164+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
29165+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
29166+ "9: movl %%eax, 8(%3)\n"
29167+ "10: movl %%edx, 12(%3)\n"
29168+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
29169+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
29170+ "13: movl %%eax, 16(%3)\n"
29171+ "14: movl %%edx, 20(%3)\n"
29172+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
29173+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
29174+ "17: movl %%eax, 24(%3)\n"
29175+ "18: movl %%edx, 28(%3)\n"
29176+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
29177+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
29178+ "21: movl %%eax, 32(%3)\n"
29179+ "22: movl %%edx, 36(%3)\n"
29180+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
29181+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
29182+ "25: movl %%eax, 40(%3)\n"
29183+ "26: movl %%edx, 44(%3)\n"
29184+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
29185+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
29186+ "29: movl %%eax, 48(%3)\n"
29187+ "30: movl %%edx, 52(%3)\n"
29188+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
29189+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
29190+ "33: movl %%eax, 56(%3)\n"
29191+ "34: movl %%edx, 60(%3)\n"
29192+ " addl $-64, %0\n"
29193+ " addl $64, %4\n"
29194+ " addl $64, %3\n"
29195+ " cmpl $63, %0\n"
29196+ " ja 1b\n"
29197+ "35: movl %0, %%eax\n"
29198+ " shrl $2, %0\n"
29199+ " andl $3, %%eax\n"
29200+ " cld\n"
29201+ "99: rep; "__copyuser_seg" movsl\n"
29202+ "36: movl %%eax, %0\n"
29203+ "37: rep; "__copyuser_seg" movsb\n"
29204+ "100:\n"
29205+ ".section .fixup,\"ax\"\n"
29206+ "101: lea 0(%%eax,%0,4),%0\n"
29207+ " jmp 100b\n"
29208+ ".previous\n"
29209+ _ASM_EXTABLE(1b,100b)
29210+ _ASM_EXTABLE(2b,100b)
29211+ _ASM_EXTABLE(3b,100b)
29212+ _ASM_EXTABLE(4b,100b)
29213+ _ASM_EXTABLE(5b,100b)
29214+ _ASM_EXTABLE(6b,100b)
29215+ _ASM_EXTABLE(7b,100b)
29216+ _ASM_EXTABLE(8b,100b)
29217+ _ASM_EXTABLE(9b,100b)
29218+ _ASM_EXTABLE(10b,100b)
29219+ _ASM_EXTABLE(11b,100b)
29220+ _ASM_EXTABLE(12b,100b)
29221+ _ASM_EXTABLE(13b,100b)
29222+ _ASM_EXTABLE(14b,100b)
29223+ _ASM_EXTABLE(15b,100b)
29224+ _ASM_EXTABLE(16b,100b)
29225+ _ASM_EXTABLE(17b,100b)
29226+ _ASM_EXTABLE(18b,100b)
29227+ _ASM_EXTABLE(19b,100b)
29228+ _ASM_EXTABLE(20b,100b)
29229+ _ASM_EXTABLE(21b,100b)
29230+ _ASM_EXTABLE(22b,100b)
29231+ _ASM_EXTABLE(23b,100b)
29232+ _ASM_EXTABLE(24b,100b)
29233+ _ASM_EXTABLE(25b,100b)
29234+ _ASM_EXTABLE(26b,100b)
29235+ _ASM_EXTABLE(27b,100b)
29236+ _ASM_EXTABLE(28b,100b)
29237+ _ASM_EXTABLE(29b,100b)
29238+ _ASM_EXTABLE(30b,100b)
29239+ _ASM_EXTABLE(31b,100b)
29240+ _ASM_EXTABLE(32b,100b)
29241+ _ASM_EXTABLE(33b,100b)
29242+ _ASM_EXTABLE(34b,100b)
29243+ _ASM_EXTABLE(35b,100b)
29244+ _ASM_EXTABLE(36b,100b)
29245+ _ASM_EXTABLE(37b,100b)
29246+ _ASM_EXTABLE(99b,101b)
29247+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
29248+ : "1"(to), "2"(from), "0"(size)
29249+ : "eax", "edx", "memory");
29250+ return size;
29251+}
29252+
29253+static unsigned long __size_overflow(3)
29254 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29255 {
29256 int d0, d1;
29257 __asm__ __volatile__(
29258 " .align 2,0x90\n"
29259- "0: movl 32(%4), %%eax\n"
29260+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29261 " cmpl $67, %0\n"
29262 " jbe 2f\n"
29263- "1: movl 64(%4), %%eax\n"
29264+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29265 " .align 2,0x90\n"
29266- "2: movl 0(%4), %%eax\n"
29267- "21: movl 4(%4), %%edx\n"
29268+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29269+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29270 " movl %%eax, 0(%3)\n"
29271 " movl %%edx, 4(%3)\n"
29272- "3: movl 8(%4), %%eax\n"
29273- "31: movl 12(%4),%%edx\n"
29274+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29275+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29276 " movl %%eax, 8(%3)\n"
29277 " movl %%edx, 12(%3)\n"
29278- "4: movl 16(%4), %%eax\n"
29279- "41: movl 20(%4), %%edx\n"
29280+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29281+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29282 " movl %%eax, 16(%3)\n"
29283 " movl %%edx, 20(%3)\n"
29284- "10: movl 24(%4), %%eax\n"
29285- "51: movl 28(%4), %%edx\n"
29286+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29287+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29288 " movl %%eax, 24(%3)\n"
29289 " movl %%edx, 28(%3)\n"
29290- "11: movl 32(%4), %%eax\n"
29291- "61: movl 36(%4), %%edx\n"
29292+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29293+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29294 " movl %%eax, 32(%3)\n"
29295 " movl %%edx, 36(%3)\n"
29296- "12: movl 40(%4), %%eax\n"
29297- "71: movl 44(%4), %%edx\n"
29298+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29299+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29300 " movl %%eax, 40(%3)\n"
29301 " movl %%edx, 44(%3)\n"
29302- "13: movl 48(%4), %%eax\n"
29303- "81: movl 52(%4), %%edx\n"
29304+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29305+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29306 " movl %%eax, 48(%3)\n"
29307 " movl %%edx, 52(%3)\n"
29308- "14: movl 56(%4), %%eax\n"
29309- "91: movl 60(%4), %%edx\n"
29310+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29311+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29312 " movl %%eax, 56(%3)\n"
29313 " movl %%edx, 60(%3)\n"
29314 " addl $-64, %0\n"
29315@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29316 " shrl $2, %0\n"
29317 " andl $3, %%eax\n"
29318 " cld\n"
29319- "6: rep; movsl\n"
29320+ "6: rep; "__copyuser_seg" movsl\n"
29321 " movl %%eax,%0\n"
29322- "7: rep; movsb\n"
29323+ "7: rep; "__copyuser_seg" movsb\n"
29324 "8:\n"
29325 ".section .fixup,\"ax\"\n"
29326 "9: lea 0(%%eax,%0,4),%0\n"
29327@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29328 * hyoshiok@miraclelinux.com
29329 */
29330
29331-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29332+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
29333 const void __user *from, unsigned long size)
29334 {
29335 int d0, d1;
29336
29337 __asm__ __volatile__(
29338 " .align 2,0x90\n"
29339- "0: movl 32(%4), %%eax\n"
29340+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29341 " cmpl $67, %0\n"
29342 " jbe 2f\n"
29343- "1: movl 64(%4), %%eax\n"
29344+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29345 " .align 2,0x90\n"
29346- "2: movl 0(%4), %%eax\n"
29347- "21: movl 4(%4), %%edx\n"
29348+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29349+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29350 " movnti %%eax, 0(%3)\n"
29351 " movnti %%edx, 4(%3)\n"
29352- "3: movl 8(%4), %%eax\n"
29353- "31: movl 12(%4),%%edx\n"
29354+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29355+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29356 " movnti %%eax, 8(%3)\n"
29357 " movnti %%edx, 12(%3)\n"
29358- "4: movl 16(%4), %%eax\n"
29359- "41: movl 20(%4), %%edx\n"
29360+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29361+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29362 " movnti %%eax, 16(%3)\n"
29363 " movnti %%edx, 20(%3)\n"
29364- "10: movl 24(%4), %%eax\n"
29365- "51: movl 28(%4), %%edx\n"
29366+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29367+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29368 " movnti %%eax, 24(%3)\n"
29369 " movnti %%edx, 28(%3)\n"
29370- "11: movl 32(%4), %%eax\n"
29371- "61: movl 36(%4), %%edx\n"
29372+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29373+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29374 " movnti %%eax, 32(%3)\n"
29375 " movnti %%edx, 36(%3)\n"
29376- "12: movl 40(%4), %%eax\n"
29377- "71: movl 44(%4), %%edx\n"
29378+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29379+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29380 " movnti %%eax, 40(%3)\n"
29381 " movnti %%edx, 44(%3)\n"
29382- "13: movl 48(%4), %%eax\n"
29383- "81: movl 52(%4), %%edx\n"
29384+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29385+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29386 " movnti %%eax, 48(%3)\n"
29387 " movnti %%edx, 52(%3)\n"
29388- "14: movl 56(%4), %%eax\n"
29389- "91: movl 60(%4), %%edx\n"
29390+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29391+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29392 " movnti %%eax, 56(%3)\n"
29393 " movnti %%edx, 60(%3)\n"
29394 " addl $-64, %0\n"
29395@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29396 " shrl $2, %0\n"
29397 " andl $3, %%eax\n"
29398 " cld\n"
29399- "6: rep; movsl\n"
29400+ "6: rep; "__copyuser_seg" movsl\n"
29401 " movl %%eax,%0\n"
29402- "7: rep; movsb\n"
29403+ "7: rep; "__copyuser_seg" movsb\n"
29404 "8:\n"
29405 ".section .fixup,\"ax\"\n"
29406 "9: lea 0(%%eax,%0,4),%0\n"
29407@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29408 return size;
29409 }
29410
29411-static unsigned long __copy_user_intel_nocache(void *to,
29412+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
29413 const void __user *from, unsigned long size)
29414 {
29415 int d0, d1;
29416
29417 __asm__ __volatile__(
29418 " .align 2,0x90\n"
29419- "0: movl 32(%4), %%eax\n"
29420+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29421 " cmpl $67, %0\n"
29422 " jbe 2f\n"
29423- "1: movl 64(%4), %%eax\n"
29424+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29425 " .align 2,0x90\n"
29426- "2: movl 0(%4), %%eax\n"
29427- "21: movl 4(%4), %%edx\n"
29428+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29429+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29430 " movnti %%eax, 0(%3)\n"
29431 " movnti %%edx, 4(%3)\n"
29432- "3: movl 8(%4), %%eax\n"
29433- "31: movl 12(%4),%%edx\n"
29434+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29435+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29436 " movnti %%eax, 8(%3)\n"
29437 " movnti %%edx, 12(%3)\n"
29438- "4: movl 16(%4), %%eax\n"
29439- "41: movl 20(%4), %%edx\n"
29440+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29441+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29442 " movnti %%eax, 16(%3)\n"
29443 " movnti %%edx, 20(%3)\n"
29444- "10: movl 24(%4), %%eax\n"
29445- "51: movl 28(%4), %%edx\n"
29446+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29447+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29448 " movnti %%eax, 24(%3)\n"
29449 " movnti %%edx, 28(%3)\n"
29450- "11: movl 32(%4), %%eax\n"
29451- "61: movl 36(%4), %%edx\n"
29452+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29453+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29454 " movnti %%eax, 32(%3)\n"
29455 " movnti %%edx, 36(%3)\n"
29456- "12: movl 40(%4), %%eax\n"
29457- "71: movl 44(%4), %%edx\n"
29458+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29459+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29460 " movnti %%eax, 40(%3)\n"
29461 " movnti %%edx, 44(%3)\n"
29462- "13: movl 48(%4), %%eax\n"
29463- "81: movl 52(%4), %%edx\n"
29464+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29465+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29466 " movnti %%eax, 48(%3)\n"
29467 " movnti %%edx, 52(%3)\n"
29468- "14: movl 56(%4), %%eax\n"
29469- "91: movl 60(%4), %%edx\n"
29470+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29471+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29472 " movnti %%eax, 56(%3)\n"
29473 " movnti %%edx, 60(%3)\n"
29474 " addl $-64, %0\n"
29475@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
29476 " shrl $2, %0\n"
29477 " andl $3, %%eax\n"
29478 " cld\n"
29479- "6: rep; movsl\n"
29480+ "6: rep; "__copyuser_seg" movsl\n"
29481 " movl %%eax,%0\n"
29482- "7: rep; movsb\n"
29483+ "7: rep; "__copyuser_seg" movsb\n"
29484 "8:\n"
29485 ".section .fixup,\"ax\"\n"
29486 "9: lea 0(%%eax,%0,4),%0\n"
29487@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
29488 */
29489 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
29490 unsigned long size);
29491-unsigned long __copy_user_intel(void __user *to, const void *from,
29492+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
29493+ unsigned long size);
29494+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
29495 unsigned long size);
29496 unsigned long __copy_user_zeroing_intel_nocache(void *to,
29497 const void __user *from, unsigned long size);
29498 #endif /* CONFIG_X86_INTEL_USERCOPY */
29499
29500 /* Generic arbitrary sized copy. */
29501-#define __copy_user(to, from, size) \
29502+#define __copy_user(to, from, size, prefix, set, restore) \
29503 do { \
29504 int __d0, __d1, __d2; \
29505 __asm__ __volatile__( \
29506+ set \
29507 " cmp $7,%0\n" \
29508 " jbe 1f\n" \
29509 " movl %1,%0\n" \
29510 " negl %0\n" \
29511 " andl $7,%0\n" \
29512 " subl %0,%3\n" \
29513- "4: rep; movsb\n" \
29514+ "4: rep; "prefix"movsb\n" \
29515 " movl %3,%0\n" \
29516 " shrl $2,%0\n" \
29517 " andl $3,%3\n" \
29518 " .align 2,0x90\n" \
29519- "0: rep; movsl\n" \
29520+ "0: rep; "prefix"movsl\n" \
29521 " movl %3,%0\n" \
29522- "1: rep; movsb\n" \
29523+ "1: rep; "prefix"movsb\n" \
29524 "2:\n" \
29525+ restore \
29526 ".section .fixup,\"ax\"\n" \
29527 "5: addl %3,%0\n" \
29528 " jmp 2b\n" \
29529@@ -538,14 +650,14 @@ do { \
29530 " negl %0\n" \
29531 " andl $7,%0\n" \
29532 " subl %0,%3\n" \
29533- "4: rep; movsb\n" \
29534+ "4: rep; "__copyuser_seg"movsb\n" \
29535 " movl %3,%0\n" \
29536 " shrl $2,%0\n" \
29537 " andl $3,%3\n" \
29538 " .align 2,0x90\n" \
29539- "0: rep; movsl\n" \
29540+ "0: rep; "__copyuser_seg"movsl\n" \
29541 " movl %3,%0\n" \
29542- "1: rep; movsb\n" \
29543+ "1: rep; "__copyuser_seg"movsb\n" \
29544 "2:\n" \
29545 ".section .fixup,\"ax\"\n" \
29546 "5: addl %3,%0\n" \
29547@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
29548 {
29549 stac();
29550 if (movsl_is_ok(to, from, n))
29551- __copy_user(to, from, n);
29552+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
29553 else
29554- n = __copy_user_intel(to, from, n);
29555+ n = __generic_copy_to_user_intel(to, from, n);
29556 clac();
29557 return n;
29558 }
29559@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
29560 {
29561 stac();
29562 if (movsl_is_ok(to, from, n))
29563- __copy_user(to, from, n);
29564+ __copy_user(to, from, n, __copyuser_seg, "", "");
29565 else
29566- n = __copy_user_intel((void __user *)to,
29567- (const void *)from, n);
29568+ n = __generic_copy_from_user_intel(to, from, n);
29569 clac();
29570 return n;
29571 }
29572@@ -632,60 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
29573 if (n > 64 && cpu_has_xmm2)
29574 n = __copy_user_intel_nocache(to, from, n);
29575 else
29576- __copy_user(to, from, n);
29577+ __copy_user(to, from, n, __copyuser_seg, "", "");
29578 #else
29579- __copy_user(to, from, n);
29580+ __copy_user(to, from, n, __copyuser_seg, "", "");
29581 #endif
29582 clac();
29583 return n;
29584 }
29585 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
29586
29587-/**
29588- * copy_to_user: - Copy a block of data into user space.
29589- * @to: Destination address, in user space.
29590- * @from: Source address, in kernel space.
29591- * @n: Number of bytes to copy.
29592- *
29593- * Context: User context only. This function may sleep.
29594- *
29595- * Copy data from kernel space to user space.
29596- *
29597- * Returns number of bytes that could not be copied.
29598- * On success, this will be zero.
29599- */
29600-unsigned long
29601-copy_to_user(void __user *to, const void *from, unsigned long n)
29602+#ifdef CONFIG_PAX_MEMORY_UDEREF
29603+void __set_fs(mm_segment_t x)
29604 {
29605- if (access_ok(VERIFY_WRITE, to, n))
29606- n = __copy_to_user(to, from, n);
29607- return n;
29608+ switch (x.seg) {
29609+ case 0:
29610+ loadsegment(gs, 0);
29611+ break;
29612+ case TASK_SIZE_MAX:
29613+ loadsegment(gs, __USER_DS);
29614+ break;
29615+ case -1UL:
29616+ loadsegment(gs, __KERNEL_DS);
29617+ break;
29618+ default:
29619+ BUG();
29620+ }
29621 }
29622-EXPORT_SYMBOL(copy_to_user);
29623+EXPORT_SYMBOL(__set_fs);
29624
29625-/**
29626- * copy_from_user: - Copy a block of data from user space.
29627- * @to: Destination address, in kernel space.
29628- * @from: Source address, in user space.
29629- * @n: Number of bytes to copy.
29630- *
29631- * Context: User context only. This function may sleep.
29632- *
29633- * Copy data from user space to kernel space.
29634- *
29635- * Returns number of bytes that could not be copied.
29636- * On success, this will be zero.
29637- *
29638- * If some data could not be copied, this function will pad the copied
29639- * data to the requested size using zero bytes.
29640- */
29641-unsigned long
29642-_copy_from_user(void *to, const void __user *from, unsigned long n)
29643+void set_fs(mm_segment_t x)
29644 {
29645- if (access_ok(VERIFY_READ, from, n))
29646- n = __copy_from_user(to, from, n);
29647- else
29648- memset(to, 0, n);
29649- return n;
29650+ current_thread_info()->addr_limit = x;
29651+ __set_fs(x);
29652 }
29653-EXPORT_SYMBOL(_copy_from_user);
29654+EXPORT_SYMBOL(set_fs);
29655+#endif
29656diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
29657index 906fea3..0194a18 100644
29658--- a/arch/x86/lib/usercopy_64.c
29659+++ b/arch/x86/lib/usercopy_64.c
29660@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29661 might_fault();
29662 /* no memory constraint because it doesn't change any memory gcc knows
29663 about */
29664+ pax_open_userland();
29665 stac();
29666 asm volatile(
29667 " testq %[size8],%[size8]\n"
29668@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29669 _ASM_EXTABLE(0b,3b)
29670 _ASM_EXTABLE(1b,2b)
29671 : [size8] "=&c"(size), [dst] "=&D" (__d0)
29672- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
29673+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
29674 [zero] "r" (0UL), [eight] "r" (8UL));
29675 clac();
29676+ pax_close_userland();
29677 return size;
29678 }
29679 EXPORT_SYMBOL(__clear_user);
29680@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
29681 }
29682 EXPORT_SYMBOL(clear_user);
29683
29684-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
29685+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
29686 {
29687- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
29688- return copy_user_generic((__force void *)to, (__force void *)from, len);
29689- }
29690- return len;
29691+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
29692+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
29693+ return len;
29694 }
29695 EXPORT_SYMBOL(copy_in_user);
29696
29697@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
29698 * it is not necessary to optimize tail handling.
29699 */
29700 unsigned long
29701-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29702+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
29703 {
29704 char c;
29705 unsigned zero_len;
29706
29707+ clac();
29708+ pax_close_userland();
29709 for (; len; --len, to++) {
29710 if (__get_user_nocheck(c, from++, sizeof(char)))
29711 break;
29712@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29713 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
29714 if (__put_user_nocheck(c, to++, sizeof(char)))
29715 break;
29716- clac();
29717 return len;
29718 }
29719diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
29720index 23d8e5f..9ccc13a 100644
29721--- a/arch/x86/mm/Makefile
29722+++ b/arch/x86/mm/Makefile
29723@@ -28,3 +28,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
29724 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
29725
29726 obj-$(CONFIG_MEMTEST) += memtest.o
29727+
29728+quote:="
29729+obj-$(CONFIG_X86_64) += uderef_64.o
29730+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
29731diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
29732index 903ec1e..c4166b2 100644
29733--- a/arch/x86/mm/extable.c
29734+++ b/arch/x86/mm/extable.c
29735@@ -6,12 +6,24 @@
29736 static inline unsigned long
29737 ex_insn_addr(const struct exception_table_entry *x)
29738 {
29739- return (unsigned long)&x->insn + x->insn;
29740+ unsigned long reloc = 0;
29741+
29742+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29743+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29744+#endif
29745+
29746+ return (unsigned long)&x->insn + x->insn + reloc;
29747 }
29748 static inline unsigned long
29749 ex_fixup_addr(const struct exception_table_entry *x)
29750 {
29751- return (unsigned long)&x->fixup + x->fixup;
29752+ unsigned long reloc = 0;
29753+
29754+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29755+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29756+#endif
29757+
29758+ return (unsigned long)&x->fixup + x->fixup + reloc;
29759 }
29760
29761 int fixup_exception(struct pt_regs *regs)
29762@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
29763 unsigned long new_ip;
29764
29765 #ifdef CONFIG_PNPBIOS
29766- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
29767+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
29768 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
29769 extern u32 pnp_bios_is_utter_crap;
29770 pnp_bios_is_utter_crap = 1;
29771@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
29772 i += 4;
29773 p->fixup -= i;
29774 i += 4;
29775+
29776+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29777+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
29778+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29779+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29780+#endif
29781+
29782 }
29783 }
29784
29785diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
29786index 654be4a..a4a3da1 100644
29787--- a/arch/x86/mm/fault.c
29788+++ b/arch/x86/mm/fault.c
29789@@ -14,11 +14,18 @@
29790 #include <linux/hugetlb.h> /* hstate_index_to_shift */
29791 #include <linux/prefetch.h> /* prefetchw */
29792 #include <linux/context_tracking.h> /* exception_enter(), ... */
29793+#include <linux/unistd.h>
29794+#include <linux/compiler.h>
29795
29796 #include <asm/traps.h> /* dotraplinkage, ... */
29797 #include <asm/pgalloc.h> /* pgd_*(), ... */
29798 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
29799 #include <asm/fixmap.h> /* VSYSCALL_START */
29800+#include <asm/tlbflush.h>
29801+
29802+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29803+#include <asm/stacktrace.h>
29804+#endif
29805
29806 /*
29807 * Page fault error code bits:
29808@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
29809 int ret = 0;
29810
29811 /* kprobe_running() needs smp_processor_id() */
29812- if (kprobes_built_in() && !user_mode_vm(regs)) {
29813+ if (kprobes_built_in() && !user_mode(regs)) {
29814 preempt_disable();
29815 if (kprobe_running() && kprobe_fault_handler(regs, 14))
29816 ret = 1;
29817@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
29818 return !instr_lo || (instr_lo>>1) == 1;
29819 case 0x00:
29820 /* Prefetch instruction is 0x0F0D or 0x0F18 */
29821- if (probe_kernel_address(instr, opcode))
29822+ if (user_mode(regs)) {
29823+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29824+ return 0;
29825+ } else if (probe_kernel_address(instr, opcode))
29826 return 0;
29827
29828 *prefetch = (instr_lo == 0xF) &&
29829@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
29830 while (instr < max_instr) {
29831 unsigned char opcode;
29832
29833- if (probe_kernel_address(instr, opcode))
29834+ if (user_mode(regs)) {
29835+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29836+ break;
29837+ } else if (probe_kernel_address(instr, opcode))
29838 break;
29839
29840 instr++;
29841@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
29842 force_sig_info(si_signo, &info, tsk);
29843 }
29844
29845+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
29846+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
29847+#endif
29848+
29849+#ifdef CONFIG_PAX_EMUTRAMP
29850+static int pax_handle_fetch_fault(struct pt_regs *regs);
29851+#endif
29852+
29853+#ifdef CONFIG_PAX_PAGEEXEC
29854+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
29855+{
29856+ pgd_t *pgd;
29857+ pud_t *pud;
29858+ pmd_t *pmd;
29859+
29860+ pgd = pgd_offset(mm, address);
29861+ if (!pgd_present(*pgd))
29862+ return NULL;
29863+ pud = pud_offset(pgd, address);
29864+ if (!pud_present(*pud))
29865+ return NULL;
29866+ pmd = pmd_offset(pud, address);
29867+ if (!pmd_present(*pmd))
29868+ return NULL;
29869+ return pmd;
29870+}
29871+#endif
29872+
29873 DEFINE_SPINLOCK(pgd_lock);
29874 LIST_HEAD(pgd_list);
29875
29876@@ -232,10 +273,27 @@ void vmalloc_sync_all(void)
29877 for (address = VMALLOC_START & PMD_MASK;
29878 address >= TASK_SIZE && address < FIXADDR_TOP;
29879 address += PMD_SIZE) {
29880+
29881+#ifdef CONFIG_PAX_PER_CPU_PGD
29882+ unsigned long cpu;
29883+#else
29884 struct page *page;
29885+#endif
29886
29887 spin_lock(&pgd_lock);
29888+
29889+#ifdef CONFIG_PAX_PER_CPU_PGD
29890+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29891+ pgd_t *pgd = get_cpu_pgd(cpu, user);
29892+ pmd_t *ret;
29893+
29894+ ret = vmalloc_sync_one(pgd, address);
29895+ if (!ret)
29896+ break;
29897+ pgd = get_cpu_pgd(cpu, kernel);
29898+#else
29899 list_for_each_entry(page, &pgd_list, lru) {
29900+ pgd_t *pgd;
29901 spinlock_t *pgt_lock;
29902 pmd_t *ret;
29903
29904@@ -243,8 +301,14 @@ void vmalloc_sync_all(void)
29905 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
29906
29907 spin_lock(pgt_lock);
29908- ret = vmalloc_sync_one(page_address(page), address);
29909+ pgd = page_address(page);
29910+#endif
29911+
29912+ ret = vmalloc_sync_one(pgd, address);
29913+
29914+#ifndef CONFIG_PAX_PER_CPU_PGD
29915 spin_unlock(pgt_lock);
29916+#endif
29917
29918 if (!ret)
29919 break;
29920@@ -278,6 +342,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
29921 * an interrupt in the middle of a task switch..
29922 */
29923 pgd_paddr = read_cr3();
29924+
29925+#ifdef CONFIG_PAX_PER_CPU_PGD
29926+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
29927+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
29928+#endif
29929+
29930 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
29931 if (!pmd_k)
29932 return -1;
29933@@ -373,11 +443,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
29934 * happen within a race in page table update. In the later
29935 * case just flush:
29936 */
29937- pgd = pgd_offset(current->active_mm, address);
29938+
29939 pgd_ref = pgd_offset_k(address);
29940 if (pgd_none(*pgd_ref))
29941 return -1;
29942
29943+#ifdef CONFIG_PAX_PER_CPU_PGD
29944+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
29945+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
29946+ if (pgd_none(*pgd)) {
29947+ set_pgd(pgd, *pgd_ref);
29948+ arch_flush_lazy_mmu_mode();
29949+ } else {
29950+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
29951+ }
29952+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
29953+#else
29954+ pgd = pgd_offset(current->active_mm, address);
29955+#endif
29956+
29957 if (pgd_none(*pgd)) {
29958 set_pgd(pgd, *pgd_ref);
29959 arch_flush_lazy_mmu_mode();
29960@@ -543,7 +627,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
29961 static int is_errata100(struct pt_regs *regs, unsigned long address)
29962 {
29963 #ifdef CONFIG_X86_64
29964- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
29965+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
29966 return 1;
29967 #endif
29968 return 0;
29969@@ -570,7 +654,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
29970 }
29971
29972 static const char nx_warning[] = KERN_CRIT
29973-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
29974+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
29975
29976 static void
29977 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
29978@@ -579,15 +663,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
29979 if (!oops_may_print())
29980 return;
29981
29982- if (error_code & PF_INSTR) {
29983+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
29984 unsigned int level;
29985
29986 pte_t *pte = lookup_address(address, &level);
29987
29988 if (pte && pte_present(*pte) && !pte_exec(*pte))
29989- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
29990+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
29991 }
29992
29993+#ifdef CONFIG_PAX_KERNEXEC
29994+ if (init_mm.start_code <= address && address < init_mm.end_code) {
29995+ if (current->signal->curr_ip)
29996+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
29997+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
29998+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
29999+ else
30000+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
30001+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30002+ }
30003+#endif
30004+
30005 printk(KERN_ALERT "BUG: unable to handle kernel ");
30006 if (address < PAGE_SIZE)
30007 printk(KERN_CONT "NULL pointer dereference");
30008@@ -750,6 +846,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
30009 return;
30010 }
30011 #endif
30012+
30013+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30014+ if (pax_is_fetch_fault(regs, error_code, address)) {
30015+
30016+#ifdef CONFIG_PAX_EMUTRAMP
30017+ switch (pax_handle_fetch_fault(regs)) {
30018+ case 2:
30019+ return;
30020+ }
30021+#endif
30022+
30023+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30024+ do_group_exit(SIGKILL);
30025+ }
30026+#endif
30027+
30028 /* Kernel addresses are always protection faults: */
30029 if (address >= TASK_SIZE)
30030 error_code |= PF_PROT;
30031@@ -835,7 +947,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
30032 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
30033 printk(KERN_ERR
30034 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
30035- tsk->comm, tsk->pid, address);
30036+ tsk->comm, task_pid_nr(tsk), address);
30037 code = BUS_MCEERR_AR;
30038 }
30039 #endif
30040@@ -898,6 +1010,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
30041 return 1;
30042 }
30043
30044+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30045+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
30046+{
30047+ pte_t *pte;
30048+ pmd_t *pmd;
30049+ spinlock_t *ptl;
30050+ unsigned char pte_mask;
30051+
30052+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
30053+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
30054+ return 0;
30055+
30056+ /* PaX: it's our fault, let's handle it if we can */
30057+
30058+ /* PaX: take a look at read faults before acquiring any locks */
30059+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
30060+ /* instruction fetch attempt from a protected page in user mode */
30061+ up_read(&mm->mmap_sem);
30062+
30063+#ifdef CONFIG_PAX_EMUTRAMP
30064+ switch (pax_handle_fetch_fault(regs)) {
30065+ case 2:
30066+ return 1;
30067+ }
30068+#endif
30069+
30070+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30071+ do_group_exit(SIGKILL);
30072+ }
30073+
30074+ pmd = pax_get_pmd(mm, address);
30075+ if (unlikely(!pmd))
30076+ return 0;
30077+
30078+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
30079+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
30080+ pte_unmap_unlock(pte, ptl);
30081+ return 0;
30082+ }
30083+
30084+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
30085+ /* write attempt to a protected page in user mode */
30086+ pte_unmap_unlock(pte, ptl);
30087+ return 0;
30088+ }
30089+
30090+#ifdef CONFIG_SMP
30091+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
30092+#else
30093+ if (likely(address > get_limit(regs->cs)))
30094+#endif
30095+ {
30096+ set_pte(pte, pte_mkread(*pte));
30097+ __flush_tlb_one(address);
30098+ pte_unmap_unlock(pte, ptl);
30099+ up_read(&mm->mmap_sem);
30100+ return 1;
30101+ }
30102+
30103+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
30104+
30105+ /*
30106+ * PaX: fill DTLB with user rights and retry
30107+ */
30108+ __asm__ __volatile__ (
30109+ "orb %2,(%1)\n"
30110+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
30111+/*
30112+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
30113+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
30114+ * page fault when examined during a TLB load attempt. this is true not only
30115+ * for PTEs holding a non-present entry but also present entries that will
30116+ * raise a page fault (such as those set up by PaX, or the copy-on-write
30117+ * mechanism). in effect it means that we do *not* need to flush the TLBs
30118+ * for our target pages since their PTEs are simply not in the TLBs at all.
30119+
30120+ * the best thing in omitting it is that we gain around 15-20% speed in the
30121+ * fast path of the page fault handler and can get rid of tracing since we
30122+ * can no longer flush unintended entries.
30123+ */
30124+ "invlpg (%0)\n"
30125+#endif
30126+ __copyuser_seg"testb $0,(%0)\n"
30127+ "xorb %3,(%1)\n"
30128+ :
30129+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
30130+ : "memory", "cc");
30131+ pte_unmap_unlock(pte, ptl);
30132+ up_read(&mm->mmap_sem);
30133+ return 1;
30134+}
30135+#endif
30136+
30137 /*
30138 * Handle a spurious fault caused by a stale TLB entry.
30139 *
30140@@ -964,6 +1169,9 @@ int show_unhandled_signals = 1;
30141 static inline int
30142 access_error(unsigned long error_code, struct vm_area_struct *vma)
30143 {
30144+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
30145+ return 1;
30146+
30147 if (error_code & PF_WRITE) {
30148 /* write, present and write, not present: */
30149 if (unlikely(!(vma->vm_flags & VM_WRITE)))
30150@@ -992,7 +1200,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
30151 if (error_code & PF_USER)
30152 return false;
30153
30154- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
30155+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
30156 return false;
30157
30158 return true;
30159@@ -1008,18 +1216,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30160 {
30161 struct vm_area_struct *vma;
30162 struct task_struct *tsk;
30163- unsigned long address;
30164 struct mm_struct *mm;
30165 int fault;
30166 int write = error_code & PF_WRITE;
30167 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
30168 (write ? FAULT_FLAG_WRITE : 0);
30169
30170- tsk = current;
30171- mm = tsk->mm;
30172-
30173 /* Get the faulting address: */
30174- address = read_cr2();
30175+ unsigned long address = read_cr2();
30176+
30177+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30178+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
30179+ if (!search_exception_tables(regs->ip)) {
30180+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30181+ bad_area_nosemaphore(regs, error_code, address);
30182+ return;
30183+ }
30184+ if (address < pax_user_shadow_base) {
30185+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30186+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
30187+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
30188+ } else
30189+ address -= pax_user_shadow_base;
30190+ }
30191+#endif
30192+
30193+ tsk = current;
30194+ mm = tsk->mm;
30195
30196 /*
30197 * Detect and handle instructions that would cause a page fault for
30198@@ -1080,7 +1303,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30199 * User-mode registers count as a user access even for any
30200 * potential system fault or CPU buglet:
30201 */
30202- if (user_mode_vm(regs)) {
30203+ if (user_mode(regs)) {
30204 local_irq_enable();
30205 error_code |= PF_USER;
30206 } else {
30207@@ -1142,6 +1365,11 @@ retry:
30208 might_sleep();
30209 }
30210
30211+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30212+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
30213+ return;
30214+#endif
30215+
30216 vma = find_vma(mm, address);
30217 if (unlikely(!vma)) {
30218 bad_area(regs, error_code, address);
30219@@ -1153,18 +1381,24 @@ retry:
30220 bad_area(regs, error_code, address);
30221 return;
30222 }
30223- if (error_code & PF_USER) {
30224- /*
30225- * Accessing the stack below %sp is always a bug.
30226- * The large cushion allows instructions like enter
30227- * and pusha to work. ("enter $65535, $31" pushes
30228- * 32 pointers and then decrements %sp by 65535.)
30229- */
30230- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
30231- bad_area(regs, error_code, address);
30232- return;
30233- }
30234+ /*
30235+ * Accessing the stack below %sp is always a bug.
30236+ * The large cushion allows instructions like enter
30237+ * and pusha to work. ("enter $65535, $31" pushes
30238+ * 32 pointers and then decrements %sp by 65535.)
30239+ */
30240+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
30241+ bad_area(regs, error_code, address);
30242+ return;
30243 }
30244+
30245+#ifdef CONFIG_PAX_SEGMEXEC
30246+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
30247+ bad_area(regs, error_code, address);
30248+ return;
30249+ }
30250+#endif
30251+
30252 if (unlikely(expand_stack(vma, address))) {
30253 bad_area(regs, error_code, address);
30254 return;
30255@@ -1230,3 +1464,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
30256 __do_page_fault(regs, error_code);
30257 exception_exit(prev_state);
30258 }
30259+
30260+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30261+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
30262+{
30263+ struct mm_struct *mm = current->mm;
30264+ unsigned long ip = regs->ip;
30265+
30266+ if (v8086_mode(regs))
30267+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
30268+
30269+#ifdef CONFIG_PAX_PAGEEXEC
30270+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
30271+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
30272+ return true;
30273+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
30274+ return true;
30275+ return false;
30276+ }
30277+#endif
30278+
30279+#ifdef CONFIG_PAX_SEGMEXEC
30280+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
30281+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
30282+ return true;
30283+ return false;
30284+ }
30285+#endif
30286+
30287+ return false;
30288+}
30289+#endif
30290+
30291+#ifdef CONFIG_PAX_EMUTRAMP
30292+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
30293+{
30294+ int err;
30295+
30296+ do { /* PaX: libffi trampoline emulation */
30297+ unsigned char mov, jmp;
30298+ unsigned int addr1, addr2;
30299+
30300+#ifdef CONFIG_X86_64
30301+ if ((regs->ip + 9) >> 32)
30302+ break;
30303+#endif
30304+
30305+ err = get_user(mov, (unsigned char __user *)regs->ip);
30306+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30307+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30308+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30309+
30310+ if (err)
30311+ break;
30312+
30313+ if (mov == 0xB8 && jmp == 0xE9) {
30314+ regs->ax = addr1;
30315+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30316+ return 2;
30317+ }
30318+ } while (0);
30319+
30320+ do { /* PaX: gcc trampoline emulation #1 */
30321+ unsigned char mov1, mov2;
30322+ unsigned short jmp;
30323+ unsigned int addr1, addr2;
30324+
30325+#ifdef CONFIG_X86_64
30326+ if ((regs->ip + 11) >> 32)
30327+ break;
30328+#endif
30329+
30330+ err = get_user(mov1, (unsigned char __user *)regs->ip);
30331+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30332+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
30333+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30334+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
30335+
30336+ if (err)
30337+ break;
30338+
30339+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
30340+ regs->cx = addr1;
30341+ regs->ax = addr2;
30342+ regs->ip = addr2;
30343+ return 2;
30344+ }
30345+ } while (0);
30346+
30347+ do { /* PaX: gcc trampoline emulation #2 */
30348+ unsigned char mov, jmp;
30349+ unsigned int addr1, addr2;
30350+
30351+#ifdef CONFIG_X86_64
30352+ if ((regs->ip + 9) >> 32)
30353+ break;
30354+#endif
30355+
30356+ err = get_user(mov, (unsigned char __user *)regs->ip);
30357+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30358+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30359+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30360+
30361+ if (err)
30362+ break;
30363+
30364+ if (mov == 0xB9 && jmp == 0xE9) {
30365+ regs->cx = addr1;
30366+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30367+ return 2;
30368+ }
30369+ } while (0);
30370+
30371+ return 1; /* PaX in action */
30372+}
30373+
30374+#ifdef CONFIG_X86_64
30375+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
30376+{
30377+ int err;
30378+
30379+ do { /* PaX: libffi trampoline emulation */
30380+ unsigned short mov1, mov2, jmp1;
30381+ unsigned char stcclc, jmp2;
30382+ unsigned long addr1, addr2;
30383+
30384+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30385+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30386+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30387+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30388+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
30389+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
30390+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
30391+
30392+ if (err)
30393+ break;
30394+
30395+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30396+ regs->r11 = addr1;
30397+ regs->r10 = addr2;
30398+ if (stcclc == 0xF8)
30399+ regs->flags &= ~X86_EFLAGS_CF;
30400+ else
30401+ regs->flags |= X86_EFLAGS_CF;
30402+ regs->ip = addr1;
30403+ return 2;
30404+ }
30405+ } while (0);
30406+
30407+ do { /* PaX: gcc trampoline emulation #1 */
30408+ unsigned short mov1, mov2, jmp1;
30409+ unsigned char jmp2;
30410+ unsigned int addr1;
30411+ unsigned long addr2;
30412+
30413+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30414+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
30415+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
30416+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
30417+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
30418+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
30419+
30420+ if (err)
30421+ break;
30422+
30423+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30424+ regs->r11 = addr1;
30425+ regs->r10 = addr2;
30426+ regs->ip = addr1;
30427+ return 2;
30428+ }
30429+ } while (0);
30430+
30431+ do { /* PaX: gcc trampoline emulation #2 */
30432+ unsigned short mov1, mov2, jmp1;
30433+ unsigned char jmp2;
30434+ unsigned long addr1, addr2;
30435+
30436+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30437+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30438+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30439+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30440+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
30441+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
30442+
30443+ if (err)
30444+ break;
30445+
30446+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30447+ regs->r11 = addr1;
30448+ regs->r10 = addr2;
30449+ regs->ip = addr1;
30450+ return 2;
30451+ }
30452+ } while (0);
30453+
30454+ return 1; /* PaX in action */
30455+}
30456+#endif
30457+
30458+/*
30459+ * PaX: decide what to do with offenders (regs->ip = fault address)
30460+ *
30461+ * returns 1 when task should be killed
30462+ * 2 when gcc trampoline was detected
30463+ */
30464+static int pax_handle_fetch_fault(struct pt_regs *regs)
30465+{
30466+ if (v8086_mode(regs))
30467+ return 1;
30468+
30469+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
30470+ return 1;
30471+
30472+#ifdef CONFIG_X86_32
30473+ return pax_handle_fetch_fault_32(regs);
30474+#else
30475+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
30476+ return pax_handle_fetch_fault_32(regs);
30477+ else
30478+ return pax_handle_fetch_fault_64(regs);
30479+#endif
30480+}
30481+#endif
30482+
30483+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30484+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
30485+{
30486+ long i;
30487+
30488+ printk(KERN_ERR "PAX: bytes at PC: ");
30489+ for (i = 0; i < 20; i++) {
30490+ unsigned char c;
30491+ if (get_user(c, (unsigned char __force_user *)pc+i))
30492+ printk(KERN_CONT "?? ");
30493+ else
30494+ printk(KERN_CONT "%02x ", c);
30495+ }
30496+ printk("\n");
30497+
30498+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
30499+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
30500+ unsigned long c;
30501+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
30502+#ifdef CONFIG_X86_32
30503+ printk(KERN_CONT "???????? ");
30504+#else
30505+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
30506+ printk(KERN_CONT "???????? ???????? ");
30507+ else
30508+ printk(KERN_CONT "???????????????? ");
30509+#endif
30510+ } else {
30511+#ifdef CONFIG_X86_64
30512+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
30513+ printk(KERN_CONT "%08x ", (unsigned int)c);
30514+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
30515+ } else
30516+#endif
30517+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
30518+ }
30519+ }
30520+ printk("\n");
30521+}
30522+#endif
30523+
30524+/**
30525+ * probe_kernel_write(): safely attempt to write to a location
30526+ * @dst: address to write to
30527+ * @src: pointer to the data that shall be written
30528+ * @size: size of the data chunk
30529+ *
30530+ * Safely write to address @dst from the buffer at @src. If a kernel fault
30531+ * happens, handle that and return -EFAULT.
30532+ */
30533+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
30534+{
30535+ long ret;
30536+ mm_segment_t old_fs = get_fs();
30537+
30538+ set_fs(KERNEL_DS);
30539+ pagefault_disable();
30540+ pax_open_kernel();
30541+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
30542+ pax_close_kernel();
30543+ pagefault_enable();
30544+ set_fs(old_fs);
30545+
30546+ return ret ? -EFAULT : 0;
30547+}
30548diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
30549index dd74e46..7d26398 100644
30550--- a/arch/x86/mm/gup.c
30551+++ b/arch/x86/mm/gup.c
30552@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
30553 addr = start;
30554 len = (unsigned long) nr_pages << PAGE_SHIFT;
30555 end = start + len;
30556- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30557+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30558 (void __user *)start, len)))
30559 return 0;
30560
30561diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
30562index 4500142..53a363c 100644
30563--- a/arch/x86/mm/highmem_32.c
30564+++ b/arch/x86/mm/highmem_32.c
30565@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
30566 idx = type + KM_TYPE_NR*smp_processor_id();
30567 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
30568 BUG_ON(!pte_none(*(kmap_pte-idx)));
30569+
30570+ pax_open_kernel();
30571 set_pte(kmap_pte-idx, mk_pte(page, prot));
30572+ pax_close_kernel();
30573+
30574 arch_flush_lazy_mmu_mode();
30575
30576 return (void *)vaddr;
30577diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
30578index 7e73e8c..11d3b86 100644
30579--- a/arch/x86/mm/hugetlbpage.c
30580+++ b/arch/x86/mm/hugetlbpage.c
30581@@ -84,23 +84,30 @@ int pud_huge(pud_t pud)
30582 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
30583 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
30584 unsigned long addr, unsigned long len,
30585- unsigned long pgoff, unsigned long flags)
30586+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30587 {
30588 struct hstate *h = hstate_file(file);
30589 struct vm_unmapped_area_info info;
30590-
30591+
30592 info.flags = 0;
30593 info.length = len;
30594 info.low_limit = TASK_UNMAPPED_BASE;
30595+
30596+#ifdef CONFIG_PAX_RANDMMAP
30597+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30598+ info.low_limit += current->mm->delta_mmap;
30599+#endif
30600+
30601 info.high_limit = TASK_SIZE;
30602 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30603 info.align_offset = 0;
30604+ info.threadstack_offset = offset;
30605 return vm_unmapped_area(&info);
30606 }
30607
30608 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30609 unsigned long addr0, unsigned long len,
30610- unsigned long pgoff, unsigned long flags)
30611+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30612 {
30613 struct hstate *h = hstate_file(file);
30614 struct vm_unmapped_area_info info;
30615@@ -112,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30616 info.high_limit = current->mm->mmap_base;
30617 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30618 info.align_offset = 0;
30619+ info.threadstack_offset = offset;
30620 addr = vm_unmapped_area(&info);
30621
30622 /*
30623@@ -124,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30624 VM_BUG_ON(addr != -ENOMEM);
30625 info.flags = 0;
30626 info.low_limit = TASK_UNMAPPED_BASE;
30627+
30628+#ifdef CONFIG_PAX_RANDMMAP
30629+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30630+ info.low_limit += current->mm->delta_mmap;
30631+#endif
30632+
30633 info.high_limit = TASK_SIZE;
30634 addr = vm_unmapped_area(&info);
30635 }
30636@@ -138,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30637 struct hstate *h = hstate_file(file);
30638 struct mm_struct *mm = current->mm;
30639 struct vm_area_struct *vma;
30640+ unsigned long pax_task_size = TASK_SIZE;
30641+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
30642
30643 if (len & ~huge_page_mask(h))
30644 return -EINVAL;
30645- if (len > TASK_SIZE)
30646+
30647+#ifdef CONFIG_PAX_SEGMEXEC
30648+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
30649+ pax_task_size = SEGMEXEC_TASK_SIZE;
30650+#endif
30651+
30652+ pax_task_size -= PAGE_SIZE;
30653+
30654+ if (len > pax_task_size)
30655 return -ENOMEM;
30656
30657 if (flags & MAP_FIXED) {
30658@@ -150,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30659 return addr;
30660 }
30661
30662+#ifdef CONFIG_PAX_RANDMMAP
30663+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30664+#endif
30665+
30666 if (addr) {
30667 addr = ALIGN(addr, huge_page_size(h));
30668 vma = find_vma(mm, addr);
30669- if (TASK_SIZE - len >= addr &&
30670- (!vma || addr + len <= vma->vm_start))
30671+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
30672 return addr;
30673 }
30674 if (mm->get_unmapped_area == arch_get_unmapped_area)
30675 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
30676- pgoff, flags);
30677+ pgoff, flags, offset);
30678 else
30679 return hugetlb_get_unmapped_area_topdown(file, addr, len,
30680- pgoff, flags);
30681+ pgoff, flags, offset);
30682 }
30683
30684 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
30685diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
30686index 04664cd..dae6e5d 100644
30687--- a/arch/x86/mm/init.c
30688+++ b/arch/x86/mm/init.c
30689@@ -4,6 +4,7 @@
30690 #include <linux/swap.h>
30691 #include <linux/memblock.h>
30692 #include <linux/bootmem.h> /* for max_low_pfn */
30693+#include <linux/tboot.h>
30694
30695 #include <asm/cacheflush.h>
30696 #include <asm/e820.h>
30697@@ -17,6 +18,8 @@
30698 #include <asm/proto.h>
30699 #include <asm/dma.h> /* for MAX_DMA_PFN */
30700 #include <asm/microcode.h>
30701+#include <asm/desc.h>
30702+#include <asm/bios_ebda.h>
30703
30704 #include "mm_internal.h"
30705
30706@@ -465,7 +468,18 @@ void __init init_mem_mapping(void)
30707 early_ioremap_page_table_range_init();
30708 #endif
30709
30710+#ifdef CONFIG_PAX_PER_CPU_PGD
30711+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
30712+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30713+ KERNEL_PGD_PTRS);
30714+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
30715+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30716+ KERNEL_PGD_PTRS);
30717+ load_cr3(get_cpu_pgd(0, kernel));
30718+#else
30719 load_cr3(swapper_pg_dir);
30720+#endif
30721+
30722 __flush_tlb_all();
30723
30724 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
30725@@ -481,10 +495,40 @@ void __init init_mem_mapping(void)
30726 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
30727 * mmio resources as well as potential bios/acpi data regions.
30728 */
30729+
30730+#ifdef CONFIG_GRKERNSEC_KMEM
30731+static unsigned int ebda_start __read_only;
30732+static unsigned int ebda_end __read_only;
30733+#endif
30734+
30735 int devmem_is_allowed(unsigned long pagenr)
30736 {
30737- if (pagenr < 256)
30738+#ifdef CONFIG_GRKERNSEC_KMEM
30739+ /* allow BDA */
30740+ if (!pagenr)
30741 return 1;
30742+ /* allow EBDA */
30743+ if (pagenr >= ebda_start && pagenr < ebda_end)
30744+ return 1;
30745+ /* if tboot is in use, allow access to its hardcoded serial log range */
30746+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
30747+ return 1;
30748+#else
30749+ if (!pagenr)
30750+ return 1;
30751+#ifdef CONFIG_VM86
30752+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
30753+ return 1;
30754+#endif
30755+#endif
30756+
30757+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
30758+ return 1;
30759+#ifdef CONFIG_GRKERNSEC_KMEM
30760+ /* throw out everything else below 1MB */
30761+ if (pagenr <= 256)
30762+ return 0;
30763+#endif
30764 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
30765 return 0;
30766 if (!page_is_ram(pagenr))
30767@@ -530,8 +574,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
30768 #endif
30769 }
30770
30771+#ifdef CONFIG_GRKERNSEC_KMEM
30772+static inline void gr_init_ebda(void)
30773+{
30774+ unsigned int ebda_addr;
30775+ unsigned int ebda_size = 0;
30776+
30777+ ebda_addr = get_bios_ebda();
30778+ if (ebda_addr) {
30779+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
30780+ ebda_size <<= 10;
30781+ }
30782+ if (ebda_addr && ebda_size) {
30783+ ebda_start = ebda_addr >> PAGE_SHIFT;
30784+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
30785+ } else {
30786+ ebda_start = 0x9f000 >> PAGE_SHIFT;
30787+ ebda_end = 0xa0000 >> PAGE_SHIFT;
30788+ }
30789+}
30790+#else
30791+static inline void gr_init_ebda(void) { }
30792+#endif
30793+
30794 void free_initmem(void)
30795 {
30796+#ifdef CONFIG_PAX_KERNEXEC
30797+#ifdef CONFIG_X86_32
30798+ /* PaX: limit KERNEL_CS to actual size */
30799+ unsigned long addr, limit;
30800+ struct desc_struct d;
30801+ int cpu;
30802+#else
30803+ pgd_t *pgd;
30804+ pud_t *pud;
30805+ pmd_t *pmd;
30806+ unsigned long addr, end;
30807+#endif
30808+#endif
30809+
30810+ gr_init_ebda();
30811+
30812+#ifdef CONFIG_PAX_KERNEXEC
30813+#ifdef CONFIG_X86_32
30814+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
30815+ limit = (limit - 1UL) >> PAGE_SHIFT;
30816+
30817+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
30818+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30819+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
30820+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
30821+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
30822+ }
30823+
30824+ /* PaX: make KERNEL_CS read-only */
30825+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
30826+ if (!paravirt_enabled())
30827+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
30828+/*
30829+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
30830+ pgd = pgd_offset_k(addr);
30831+ pud = pud_offset(pgd, addr);
30832+ pmd = pmd_offset(pud, addr);
30833+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30834+ }
30835+*/
30836+#ifdef CONFIG_X86_PAE
30837+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
30838+/*
30839+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
30840+ pgd = pgd_offset_k(addr);
30841+ pud = pud_offset(pgd, addr);
30842+ pmd = pmd_offset(pud, addr);
30843+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30844+ }
30845+*/
30846+#endif
30847+
30848+#ifdef CONFIG_MODULES
30849+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
30850+#endif
30851+
30852+#else
30853+ /* PaX: make kernel code/rodata read-only, rest non-executable */
30854+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
30855+ pgd = pgd_offset_k(addr);
30856+ pud = pud_offset(pgd, addr);
30857+ pmd = pmd_offset(pud, addr);
30858+ if (!pmd_present(*pmd))
30859+ continue;
30860+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
30861+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30862+ else
30863+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30864+ }
30865+
30866+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
30867+ end = addr + KERNEL_IMAGE_SIZE;
30868+ for (; addr < end; addr += PMD_SIZE) {
30869+ pgd = pgd_offset_k(addr);
30870+ pud = pud_offset(pgd, addr);
30871+ pmd = pmd_offset(pud, addr);
30872+ if (!pmd_present(*pmd))
30873+ continue;
30874+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
30875+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30876+ }
30877+#endif
30878+
30879+ flush_tlb_all();
30880+#endif
30881+
30882 free_init_pages("unused kernel",
30883 (unsigned long)(&__init_begin),
30884 (unsigned long)(&__init_end));
30885diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
30886index 4287f1f..3b99c71 100644
30887--- a/arch/x86/mm/init_32.c
30888+++ b/arch/x86/mm/init_32.c
30889@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
30890 bool __read_mostly __vmalloc_start_set = false;
30891
30892 /*
30893- * Creates a middle page table and puts a pointer to it in the
30894- * given global directory entry. This only returns the gd entry
30895- * in non-PAE compilation mode, since the middle layer is folded.
30896- */
30897-static pmd_t * __init one_md_table_init(pgd_t *pgd)
30898-{
30899- pud_t *pud;
30900- pmd_t *pmd_table;
30901-
30902-#ifdef CONFIG_X86_PAE
30903- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
30904- pmd_table = (pmd_t *)alloc_low_page();
30905- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
30906- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
30907- pud = pud_offset(pgd, 0);
30908- BUG_ON(pmd_table != pmd_offset(pud, 0));
30909-
30910- return pmd_table;
30911- }
30912-#endif
30913- pud = pud_offset(pgd, 0);
30914- pmd_table = pmd_offset(pud, 0);
30915-
30916- return pmd_table;
30917-}
30918-
30919-/*
30920 * Create a page table and place a pointer to it in a middle page
30921 * directory entry:
30922 */
30923@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
30924 pte_t *page_table = (pte_t *)alloc_low_page();
30925
30926 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
30927+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30928+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
30929+#else
30930 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
30931+#endif
30932 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
30933 }
30934
30935 return pte_offset_kernel(pmd, 0);
30936 }
30937
30938+static pmd_t * __init one_md_table_init(pgd_t *pgd)
30939+{
30940+ pud_t *pud;
30941+ pmd_t *pmd_table;
30942+
30943+ pud = pud_offset(pgd, 0);
30944+ pmd_table = pmd_offset(pud, 0);
30945+
30946+ return pmd_table;
30947+}
30948+
30949 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
30950 {
30951 int pgd_idx = pgd_index(vaddr);
30952@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
30953 int pgd_idx, pmd_idx;
30954 unsigned long vaddr;
30955 pgd_t *pgd;
30956+ pud_t *pud;
30957 pmd_t *pmd;
30958 pte_t *pte = NULL;
30959 unsigned long count = page_table_range_init_count(start, end);
30960@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
30961 pgd = pgd_base + pgd_idx;
30962
30963 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
30964- pmd = one_md_table_init(pgd);
30965- pmd = pmd + pmd_index(vaddr);
30966+ pud = pud_offset(pgd, vaddr);
30967+ pmd = pmd_offset(pud, vaddr);
30968+
30969+#ifdef CONFIG_X86_PAE
30970+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
30971+#endif
30972+
30973 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
30974 pmd++, pmd_idx++) {
30975 pte = page_table_kmap_check(one_page_table_init(pmd),
30976@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
30977 }
30978 }
30979
30980-static inline int is_kernel_text(unsigned long addr)
30981+static inline int is_kernel_text(unsigned long start, unsigned long end)
30982 {
30983- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
30984- return 1;
30985- return 0;
30986+ if ((start > ktla_ktva((unsigned long)_etext) ||
30987+ end <= ktla_ktva((unsigned long)_stext)) &&
30988+ (start > ktla_ktva((unsigned long)_einittext) ||
30989+ end <= ktla_ktva((unsigned long)_sinittext)) &&
30990+
30991+#ifdef CONFIG_ACPI_SLEEP
30992+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
30993+#endif
30994+
30995+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
30996+ return 0;
30997+ return 1;
30998 }
30999
31000 /*
31001@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
31002 unsigned long last_map_addr = end;
31003 unsigned long start_pfn, end_pfn;
31004 pgd_t *pgd_base = swapper_pg_dir;
31005- int pgd_idx, pmd_idx, pte_ofs;
31006+ unsigned int pgd_idx, pmd_idx, pte_ofs;
31007 unsigned long pfn;
31008 pgd_t *pgd;
31009+ pud_t *pud;
31010 pmd_t *pmd;
31011 pte_t *pte;
31012 unsigned pages_2m, pages_4k;
31013@@ -291,8 +295,13 @@ repeat:
31014 pfn = start_pfn;
31015 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31016 pgd = pgd_base + pgd_idx;
31017- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
31018- pmd = one_md_table_init(pgd);
31019+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
31020+ pud = pud_offset(pgd, 0);
31021+ pmd = pmd_offset(pud, 0);
31022+
31023+#ifdef CONFIG_X86_PAE
31024+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31025+#endif
31026
31027 if (pfn >= end_pfn)
31028 continue;
31029@@ -304,14 +313,13 @@ repeat:
31030 #endif
31031 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
31032 pmd++, pmd_idx++) {
31033- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
31034+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
31035
31036 /*
31037 * Map with big pages if possible, otherwise
31038 * create normal page tables:
31039 */
31040 if (use_pse) {
31041- unsigned int addr2;
31042 pgprot_t prot = PAGE_KERNEL_LARGE;
31043 /*
31044 * first pass will use the same initial
31045@@ -322,11 +330,7 @@ repeat:
31046 _PAGE_PSE);
31047
31048 pfn &= PMD_MASK >> PAGE_SHIFT;
31049- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
31050- PAGE_OFFSET + PAGE_SIZE-1;
31051-
31052- if (is_kernel_text(addr) ||
31053- is_kernel_text(addr2))
31054+ if (is_kernel_text(address, address + PMD_SIZE))
31055 prot = PAGE_KERNEL_LARGE_EXEC;
31056
31057 pages_2m++;
31058@@ -343,7 +347,7 @@ repeat:
31059 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31060 pte += pte_ofs;
31061 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
31062- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
31063+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
31064 pgprot_t prot = PAGE_KERNEL;
31065 /*
31066 * first pass will use the same initial
31067@@ -351,7 +355,7 @@ repeat:
31068 */
31069 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
31070
31071- if (is_kernel_text(addr))
31072+ if (is_kernel_text(address, address + PAGE_SIZE))
31073 prot = PAGE_KERNEL_EXEC;
31074
31075 pages_4k++;
31076@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
31077
31078 pud = pud_offset(pgd, va);
31079 pmd = pmd_offset(pud, va);
31080- if (!pmd_present(*pmd))
31081+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
31082 break;
31083
31084 /* should not be large page here */
31085@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
31086
31087 static void __init pagetable_init(void)
31088 {
31089- pgd_t *pgd_base = swapper_pg_dir;
31090-
31091- permanent_kmaps_init(pgd_base);
31092+ permanent_kmaps_init(swapper_pg_dir);
31093 }
31094
31095-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31096+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31097 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31098
31099 /* user-defined highmem size */
31100@@ -787,10 +789,10 @@ void __init mem_init(void)
31101 ((unsigned long)&__init_end -
31102 (unsigned long)&__init_begin) >> 10,
31103
31104- (unsigned long)&_etext, (unsigned long)&_edata,
31105- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
31106+ (unsigned long)&_sdata, (unsigned long)&_edata,
31107+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
31108
31109- (unsigned long)&_text, (unsigned long)&_etext,
31110+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
31111 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
31112
31113 /*
31114@@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
31115 if (!kernel_set_to_readonly)
31116 return;
31117
31118+ start = ktla_ktva(start);
31119 pr_debug("Set kernel text: %lx - %lx for read write\n",
31120 start, start+size);
31121
31122@@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
31123 if (!kernel_set_to_readonly)
31124 return;
31125
31126+ start = ktla_ktva(start);
31127 pr_debug("Set kernel text: %lx - %lx for read only\n",
31128 start, start+size);
31129
31130@@ -922,6 +926,7 @@ void mark_rodata_ro(void)
31131 unsigned long start = PFN_ALIGN(_text);
31132 unsigned long size = PFN_ALIGN(_etext) - start;
31133
31134+ start = ktla_ktva(start);
31135 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
31136 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
31137 size >> 10);
31138diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
31139index 104d56a..62ba13f 100644
31140--- a/arch/x86/mm/init_64.c
31141+++ b/arch/x86/mm/init_64.c
31142@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
31143 * around without checking the pgd every time.
31144 */
31145
31146-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
31147+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
31148 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31149
31150 int force_personality32;
31151@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31152
31153 for (address = start; address <= end; address += PGDIR_SIZE) {
31154 const pgd_t *pgd_ref = pgd_offset_k(address);
31155+
31156+#ifdef CONFIG_PAX_PER_CPU_PGD
31157+ unsigned long cpu;
31158+#else
31159 struct page *page;
31160+#endif
31161
31162 if (pgd_none(*pgd_ref))
31163 continue;
31164
31165 spin_lock(&pgd_lock);
31166+
31167+#ifdef CONFIG_PAX_PER_CPU_PGD
31168+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31169+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
31170+
31171+ if (pgd_none(*pgd))
31172+ set_pgd(pgd, *pgd_ref);
31173+ else
31174+ BUG_ON(pgd_page_vaddr(*pgd)
31175+ != pgd_page_vaddr(*pgd_ref));
31176+ pgd = pgd_offset_cpu(cpu, kernel, address);
31177+#else
31178 list_for_each_entry(page, &pgd_list, lru) {
31179 pgd_t *pgd;
31180 spinlock_t *pgt_lock;
31181@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31182 /* the pgt_lock only for Xen */
31183 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31184 spin_lock(pgt_lock);
31185+#endif
31186
31187 if (pgd_none(*pgd))
31188 set_pgd(pgd, *pgd_ref);
31189@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31190 BUG_ON(pgd_page_vaddr(*pgd)
31191 != pgd_page_vaddr(*pgd_ref));
31192
31193+#ifndef CONFIG_PAX_PER_CPU_PGD
31194 spin_unlock(pgt_lock);
31195+#endif
31196+
31197 }
31198 spin_unlock(&pgd_lock);
31199 }
31200@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
31201 {
31202 if (pgd_none(*pgd)) {
31203 pud_t *pud = (pud_t *)spp_getpage();
31204- pgd_populate(&init_mm, pgd, pud);
31205+ pgd_populate_kernel(&init_mm, pgd, pud);
31206 if (pud != pud_offset(pgd, 0))
31207 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
31208 pud, pud_offset(pgd, 0));
31209@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
31210 {
31211 if (pud_none(*pud)) {
31212 pmd_t *pmd = (pmd_t *) spp_getpage();
31213- pud_populate(&init_mm, pud, pmd);
31214+ pud_populate_kernel(&init_mm, pud, pmd);
31215 if (pmd != pmd_offset(pud, 0))
31216 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
31217 pmd, pmd_offset(pud, 0));
31218@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
31219 pmd = fill_pmd(pud, vaddr);
31220 pte = fill_pte(pmd, vaddr);
31221
31222+ pax_open_kernel();
31223 set_pte(pte, new_pte);
31224+ pax_close_kernel();
31225
31226 /*
31227 * It's enough to flush this one mapping.
31228@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
31229 pgd = pgd_offset_k((unsigned long)__va(phys));
31230 if (pgd_none(*pgd)) {
31231 pud = (pud_t *) spp_getpage();
31232- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
31233- _PAGE_USER));
31234+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
31235 }
31236 pud = pud_offset(pgd, (unsigned long)__va(phys));
31237 if (pud_none(*pud)) {
31238 pmd = (pmd_t *) spp_getpage();
31239- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
31240- _PAGE_USER));
31241+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
31242 }
31243 pmd = pmd_offset(pud, phys);
31244 BUG_ON(!pmd_none(*pmd));
31245@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
31246 prot);
31247
31248 spin_lock(&init_mm.page_table_lock);
31249- pud_populate(&init_mm, pud, pmd);
31250+ pud_populate_kernel(&init_mm, pud, pmd);
31251 spin_unlock(&init_mm.page_table_lock);
31252 }
31253 __flush_tlb_all();
31254@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
31255 page_size_mask);
31256
31257 spin_lock(&init_mm.page_table_lock);
31258- pgd_populate(&init_mm, pgd, pud);
31259+ pgd_populate_kernel(&init_mm, pgd, pud);
31260 spin_unlock(&init_mm.page_table_lock);
31261 pgd_changed = true;
31262 }
31263@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
31264 static struct vm_area_struct gate_vma = {
31265 .vm_start = VSYSCALL_START,
31266 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
31267- .vm_page_prot = PAGE_READONLY_EXEC,
31268- .vm_flags = VM_READ | VM_EXEC
31269+ .vm_page_prot = PAGE_READONLY,
31270+ .vm_flags = VM_READ
31271 };
31272
31273 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31274@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
31275
31276 const char *arch_vma_name(struct vm_area_struct *vma)
31277 {
31278- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31279+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31280 return "[vdso]";
31281 if (vma == &gate_vma)
31282 return "[vsyscall]";
31283diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
31284index 7b179b4..6bd17777 100644
31285--- a/arch/x86/mm/iomap_32.c
31286+++ b/arch/x86/mm/iomap_32.c
31287@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
31288 type = kmap_atomic_idx_push();
31289 idx = type + KM_TYPE_NR * smp_processor_id();
31290 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31291+
31292+ pax_open_kernel();
31293 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
31294+ pax_close_kernel();
31295+
31296 arch_flush_lazy_mmu_mode();
31297
31298 return (void *)vaddr;
31299diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
31300index 0215e2c..1c62dab 100644
31301--- a/arch/x86/mm/ioremap.c
31302+++ b/arch/x86/mm/ioremap.c
31303@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
31304 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
31305 int is_ram = page_is_ram(pfn);
31306
31307- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
31308+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
31309 return NULL;
31310 WARN_ON_ONCE(is_ram);
31311 }
31312@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
31313 *
31314 * Caller must ensure there is only one unmapping for the same pointer.
31315 */
31316-void iounmap(volatile void __iomem *addr)
31317+void iounmap(const volatile void __iomem *addr)
31318 {
31319 struct vm_struct *p, *o;
31320
31321@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31322
31323 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
31324 if (page_is_ram(start >> PAGE_SHIFT))
31325+#ifdef CONFIG_HIGHMEM
31326+ if ((start >> PAGE_SHIFT) < max_low_pfn)
31327+#endif
31328 return __va(phys);
31329
31330 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
31331@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31332 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
31333 {
31334 if (page_is_ram(phys >> PAGE_SHIFT))
31335+#ifdef CONFIG_HIGHMEM
31336+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
31337+#endif
31338 return;
31339
31340 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
31341@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
31342 early_param("early_ioremap_debug", early_ioremap_debug_setup);
31343
31344 static __initdata int after_paging_init;
31345-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
31346+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
31347
31348 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
31349 {
31350@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
31351 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
31352
31353 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
31354- memset(bm_pte, 0, sizeof(bm_pte));
31355- pmd_populate_kernel(&init_mm, pmd, bm_pte);
31356+ pmd_populate_user(&init_mm, pmd, bm_pte);
31357
31358 /*
31359 * The boot-ioremap range spans multiple pmds, for which
31360diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
31361index d87dd6d..bf3fa66 100644
31362--- a/arch/x86/mm/kmemcheck/kmemcheck.c
31363+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
31364@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
31365 * memory (e.g. tracked pages)? For now, we need this to avoid
31366 * invoking kmemcheck for PnP BIOS calls.
31367 */
31368- if (regs->flags & X86_VM_MASK)
31369+ if (v8086_mode(regs))
31370 return false;
31371- if (regs->cs != __KERNEL_CS)
31372+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
31373 return false;
31374
31375 pte = kmemcheck_pte_lookup(address);
31376diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
31377index 25e7e13..1964579 100644
31378--- a/arch/x86/mm/mmap.c
31379+++ b/arch/x86/mm/mmap.c
31380@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
31381 * Leave an at least ~128 MB hole with possible stack randomization.
31382 */
31383 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
31384-#define MAX_GAP (TASK_SIZE/6*5)
31385+#define MAX_GAP (pax_task_size/6*5)
31386
31387 static int mmap_is_legacy(void)
31388 {
31389@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
31390 return rnd << PAGE_SHIFT;
31391 }
31392
31393-static unsigned long mmap_base(void)
31394+static unsigned long mmap_base(struct mm_struct *mm)
31395 {
31396 unsigned long gap = rlimit(RLIMIT_STACK);
31397+ unsigned long pax_task_size = TASK_SIZE;
31398+
31399+#ifdef CONFIG_PAX_SEGMEXEC
31400+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31401+ pax_task_size = SEGMEXEC_TASK_SIZE;
31402+#endif
31403
31404 if (gap < MIN_GAP)
31405 gap = MIN_GAP;
31406 else if (gap > MAX_GAP)
31407 gap = MAX_GAP;
31408
31409- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
31410+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
31411 }
31412
31413 /*
31414 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
31415 * does, but not when emulating X86_32
31416 */
31417-static unsigned long mmap_legacy_base(void)
31418+static unsigned long mmap_legacy_base(struct mm_struct *mm)
31419 {
31420- if (mmap_is_ia32())
31421+ if (mmap_is_ia32()) {
31422+
31423+#ifdef CONFIG_PAX_SEGMEXEC
31424+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31425+ return SEGMEXEC_TASK_UNMAPPED_BASE;
31426+ else
31427+#endif
31428+
31429 return TASK_UNMAPPED_BASE;
31430- else
31431+ } else
31432 return TASK_UNMAPPED_BASE + mmap_rnd();
31433 }
31434
31435@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
31436 */
31437 void arch_pick_mmap_layout(struct mm_struct *mm)
31438 {
31439- mm->mmap_legacy_base = mmap_legacy_base();
31440- mm->mmap_base = mmap_base();
31441+ mm->mmap_legacy_base = mmap_legacy_base(mm);
31442+ mm->mmap_base = mmap_base(mm);
31443+
31444+#ifdef CONFIG_PAX_RANDMMAP
31445+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
31446+ mm->mmap_legacy_base += mm->delta_mmap;
31447+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
31448+ }
31449+#endif
31450
31451 if (mmap_is_legacy()) {
31452 mm->mmap_base = mm->mmap_legacy_base;
31453diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
31454index 0057a7a..95c7edd 100644
31455--- a/arch/x86/mm/mmio-mod.c
31456+++ b/arch/x86/mm/mmio-mod.c
31457@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
31458 break;
31459 default:
31460 {
31461- unsigned char *ip = (unsigned char *)instptr;
31462+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
31463 my_trace->opcode = MMIO_UNKNOWN_OP;
31464 my_trace->width = 0;
31465 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
31466@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
31467 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31468 void __iomem *addr)
31469 {
31470- static atomic_t next_id;
31471+ static atomic_unchecked_t next_id;
31472 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
31473 /* These are page-unaligned. */
31474 struct mmiotrace_map map = {
31475@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31476 .private = trace
31477 },
31478 .phys = offset,
31479- .id = atomic_inc_return(&next_id)
31480+ .id = atomic_inc_return_unchecked(&next_id)
31481 };
31482 map.map_id = trace->id;
31483
31484@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
31485 ioremap_trace_core(offset, size, addr);
31486 }
31487
31488-static void iounmap_trace_core(volatile void __iomem *addr)
31489+static void iounmap_trace_core(const volatile void __iomem *addr)
31490 {
31491 struct mmiotrace_map map = {
31492 .phys = 0,
31493@@ -328,7 +328,7 @@ not_enabled:
31494 }
31495 }
31496
31497-void mmiotrace_iounmap(volatile void __iomem *addr)
31498+void mmiotrace_iounmap(const volatile void __iomem *addr)
31499 {
31500 might_sleep();
31501 if (is_enabled()) /* recheck and proper locking in *_core() */
31502diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
31503index 8bf93ba..dbcd670 100644
31504--- a/arch/x86/mm/numa.c
31505+++ b/arch/x86/mm/numa.c
31506@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
31507 return true;
31508 }
31509
31510-static int __init numa_register_memblks(struct numa_meminfo *mi)
31511+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
31512 {
31513 unsigned long uninitialized_var(pfn_align);
31514 int i, nid;
31515diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
31516index d0b1773..4c3327c 100644
31517--- a/arch/x86/mm/pageattr-test.c
31518+++ b/arch/x86/mm/pageattr-test.c
31519@@ -36,7 +36,7 @@ enum {
31520
31521 static int pte_testbit(pte_t pte)
31522 {
31523- return pte_flags(pte) & _PAGE_UNUSED1;
31524+ return pte_flags(pte) & _PAGE_CPA_TEST;
31525 }
31526
31527 struct split_state {
31528diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
31529index bb32480..75f2f5e 100644
31530--- a/arch/x86/mm/pageattr.c
31531+++ b/arch/x86/mm/pageattr.c
31532@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31533 */
31534 #ifdef CONFIG_PCI_BIOS
31535 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
31536- pgprot_val(forbidden) |= _PAGE_NX;
31537+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31538 #endif
31539
31540 /*
31541@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31542 * Does not cover __inittext since that is gone later on. On
31543 * 64bit we do not enforce !NX on the low mapping
31544 */
31545- if (within(address, (unsigned long)_text, (unsigned long)_etext))
31546- pgprot_val(forbidden) |= _PAGE_NX;
31547+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
31548+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31549
31550+#ifdef CONFIG_DEBUG_RODATA
31551 /*
31552 * The .rodata section needs to be read-only. Using the pfn
31553 * catches all aliases.
31554@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31555 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
31556 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
31557 pgprot_val(forbidden) |= _PAGE_RW;
31558+#endif
31559
31560 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
31561 /*
31562@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31563 }
31564 #endif
31565
31566+#ifdef CONFIG_PAX_KERNEXEC
31567+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
31568+ pgprot_val(forbidden) |= _PAGE_RW;
31569+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31570+ }
31571+#endif
31572+
31573 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
31574
31575 return prot;
31576@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
31577 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
31578 {
31579 /* change init_mm */
31580+ pax_open_kernel();
31581 set_pte_atomic(kpte, pte);
31582+
31583 #ifdef CONFIG_X86_32
31584 if (!SHARED_KERNEL_PMD) {
31585+
31586+#ifdef CONFIG_PAX_PER_CPU_PGD
31587+ unsigned long cpu;
31588+#else
31589 struct page *page;
31590+#endif
31591
31592+#ifdef CONFIG_PAX_PER_CPU_PGD
31593+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31594+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
31595+#else
31596 list_for_each_entry(page, &pgd_list, lru) {
31597- pgd_t *pgd;
31598+ pgd_t *pgd = (pgd_t *)page_address(page);
31599+#endif
31600+
31601 pud_t *pud;
31602 pmd_t *pmd;
31603
31604- pgd = (pgd_t *)page_address(page) + pgd_index(address);
31605+ pgd += pgd_index(address);
31606 pud = pud_offset(pgd, address);
31607 pmd = pmd_offset(pud, address);
31608 set_pte_atomic((pte_t *)pmd, pte);
31609 }
31610 }
31611 #endif
31612+ pax_close_kernel();
31613 }
31614
31615 static int
31616diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
31617index 6574388..87e9bef 100644
31618--- a/arch/x86/mm/pat.c
31619+++ b/arch/x86/mm/pat.c
31620@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
31621
31622 if (!entry) {
31623 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
31624- current->comm, current->pid, start, end - 1);
31625+ current->comm, task_pid_nr(current), start, end - 1);
31626 return -EINVAL;
31627 }
31628
31629@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31630
31631 while (cursor < to) {
31632 if (!devmem_is_allowed(pfn)) {
31633- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
31634- current->comm, from, to - 1);
31635+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
31636+ current->comm, from, to - 1, cursor);
31637 return 0;
31638 }
31639 cursor += PAGE_SIZE;
31640@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
31641 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
31642 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
31643 "for [mem %#010Lx-%#010Lx]\n",
31644- current->comm, current->pid,
31645+ current->comm, task_pid_nr(current),
31646 cattr_name(flags),
31647 base, (unsigned long long)(base + size-1));
31648 return -EINVAL;
31649@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31650 flags = lookup_memtype(paddr);
31651 if (want_flags != flags) {
31652 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
31653- current->comm, current->pid,
31654+ current->comm, task_pid_nr(current),
31655 cattr_name(want_flags),
31656 (unsigned long long)paddr,
31657 (unsigned long long)(paddr + size - 1),
31658@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31659 free_memtype(paddr, paddr + size);
31660 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
31661 " for [mem %#010Lx-%#010Lx], got %s\n",
31662- current->comm, current->pid,
31663+ current->comm, task_pid_nr(current),
31664 cattr_name(want_flags),
31665 (unsigned long long)paddr,
31666 (unsigned long long)(paddr + size - 1),
31667diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
31668index 415f6c4..d319983 100644
31669--- a/arch/x86/mm/pat_rbtree.c
31670+++ b/arch/x86/mm/pat_rbtree.c
31671@@ -160,7 +160,7 @@ success:
31672
31673 failure:
31674 printk(KERN_INFO "%s:%d conflicting memory types "
31675- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
31676+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
31677 end, cattr_name(found_type), cattr_name(match->type));
31678 return -EBUSY;
31679 }
31680diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
31681index 9f0614d..92ae64a 100644
31682--- a/arch/x86/mm/pf_in.c
31683+++ b/arch/x86/mm/pf_in.c
31684@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
31685 int i;
31686 enum reason_type rv = OTHERS;
31687
31688- p = (unsigned char *)ins_addr;
31689+ p = (unsigned char *)ktla_ktva(ins_addr);
31690 p += skip_prefix(p, &prf);
31691 p += get_opcode(p, &opcode);
31692
31693@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
31694 struct prefix_bits prf;
31695 int i;
31696
31697- p = (unsigned char *)ins_addr;
31698+ p = (unsigned char *)ktla_ktva(ins_addr);
31699 p += skip_prefix(p, &prf);
31700 p += get_opcode(p, &opcode);
31701
31702@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
31703 struct prefix_bits prf;
31704 int i;
31705
31706- p = (unsigned char *)ins_addr;
31707+ p = (unsigned char *)ktla_ktva(ins_addr);
31708 p += skip_prefix(p, &prf);
31709 p += get_opcode(p, &opcode);
31710
31711@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
31712 struct prefix_bits prf;
31713 int i;
31714
31715- p = (unsigned char *)ins_addr;
31716+ p = (unsigned char *)ktla_ktva(ins_addr);
31717 p += skip_prefix(p, &prf);
31718 p += get_opcode(p, &opcode);
31719 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
31720@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
31721 struct prefix_bits prf;
31722 int i;
31723
31724- p = (unsigned char *)ins_addr;
31725+ p = (unsigned char *)ktla_ktva(ins_addr);
31726 p += skip_prefix(p, &prf);
31727 p += get_opcode(p, &opcode);
31728 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
31729diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
31730index dfa537a..fd45c64 100644
31731--- a/arch/x86/mm/pgtable.c
31732+++ b/arch/x86/mm/pgtable.c
31733@@ -91,10 +91,67 @@ static inline void pgd_list_del(pgd_t *pgd)
31734 list_del(&page->lru);
31735 }
31736
31737-#define UNSHARED_PTRS_PER_PGD \
31738- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31739+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31740+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
31741
31742+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
31743+{
31744+ unsigned int count = USER_PGD_PTRS;
31745
31746+ if (!pax_user_shadow_base)
31747+ return;
31748+
31749+ while (count--)
31750+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
31751+}
31752+#endif
31753+
31754+#ifdef CONFIG_PAX_PER_CPU_PGD
31755+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
31756+{
31757+ unsigned int count = USER_PGD_PTRS;
31758+
31759+ while (count--) {
31760+ pgd_t pgd;
31761+
31762+#ifdef CONFIG_X86_64
31763+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
31764+#else
31765+ pgd = *src++;
31766+#endif
31767+
31768+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31769+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
31770+#endif
31771+
31772+ *dst++ = pgd;
31773+ }
31774+
31775+}
31776+#endif
31777+
31778+#ifdef CONFIG_X86_64
31779+#define pxd_t pud_t
31780+#define pyd_t pgd_t
31781+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
31782+#define pxd_free(mm, pud) pud_free((mm), (pud))
31783+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
31784+#define pyd_offset(mm, address) pgd_offset((mm), (address))
31785+#define PYD_SIZE PGDIR_SIZE
31786+#else
31787+#define pxd_t pmd_t
31788+#define pyd_t pud_t
31789+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
31790+#define pxd_free(mm, pud) pmd_free((mm), (pud))
31791+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
31792+#define pyd_offset(mm, address) pud_offset((mm), (address))
31793+#define PYD_SIZE PUD_SIZE
31794+#endif
31795+
31796+#ifdef CONFIG_PAX_PER_CPU_PGD
31797+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
31798+static inline void pgd_dtor(pgd_t *pgd) {}
31799+#else
31800 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
31801 {
31802 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
31803@@ -135,6 +192,7 @@ static void pgd_dtor(pgd_t *pgd)
31804 pgd_list_del(pgd);
31805 spin_unlock(&pgd_lock);
31806 }
31807+#endif
31808
31809 /*
31810 * List of all pgd's needed for non-PAE so it can invalidate entries
31811@@ -147,7 +205,7 @@ static void pgd_dtor(pgd_t *pgd)
31812 * -- nyc
31813 */
31814
31815-#ifdef CONFIG_X86_PAE
31816+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
31817 /*
31818 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
31819 * updating the top-level pagetable entries to guarantee the
31820@@ -159,7 +217,7 @@ static void pgd_dtor(pgd_t *pgd)
31821 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
31822 * and initialize the kernel pmds here.
31823 */
31824-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
31825+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31826
31827 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31828 {
31829@@ -177,36 +235,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31830 */
31831 flush_tlb_mm(mm);
31832 }
31833+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
31834+#define PREALLOCATED_PXDS USER_PGD_PTRS
31835 #else /* !CONFIG_X86_PAE */
31836
31837 /* No need to prepopulate any pagetable entries in non-PAE modes. */
31838-#define PREALLOCATED_PMDS 0
31839+#define PREALLOCATED_PXDS 0
31840
31841 #endif /* CONFIG_X86_PAE */
31842
31843-static void free_pmds(pmd_t *pmds[])
31844+static void free_pxds(pxd_t *pxds[])
31845 {
31846 int i;
31847
31848- for(i = 0; i < PREALLOCATED_PMDS; i++)
31849- if (pmds[i])
31850- free_page((unsigned long)pmds[i]);
31851+ for(i = 0; i < PREALLOCATED_PXDS; i++)
31852+ if (pxds[i])
31853+ free_page((unsigned long)pxds[i]);
31854 }
31855
31856-static int preallocate_pmds(pmd_t *pmds[])
31857+static int preallocate_pxds(pxd_t *pxds[])
31858 {
31859 int i;
31860 bool failed = false;
31861
31862- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31863- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
31864- if (pmd == NULL)
31865+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31866+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
31867+ if (pxd == NULL)
31868 failed = true;
31869- pmds[i] = pmd;
31870+ pxds[i] = pxd;
31871 }
31872
31873 if (failed) {
31874- free_pmds(pmds);
31875+ free_pxds(pxds);
31876 return -ENOMEM;
31877 }
31878
31879@@ -219,49 +279,52 @@ static int preallocate_pmds(pmd_t *pmds[])
31880 * preallocate which never got a corresponding vma will need to be
31881 * freed manually.
31882 */
31883-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
31884+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
31885 {
31886 int i;
31887
31888- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31889+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31890 pgd_t pgd = pgdp[i];
31891
31892 if (pgd_val(pgd) != 0) {
31893- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
31894+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
31895
31896- pgdp[i] = native_make_pgd(0);
31897+ set_pgd(pgdp + i, native_make_pgd(0));
31898
31899- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
31900- pmd_free(mm, pmd);
31901+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
31902+ pxd_free(mm, pxd);
31903 }
31904 }
31905 }
31906
31907-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
31908+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
31909 {
31910- pud_t *pud;
31911+ pyd_t *pyd;
31912 int i;
31913
31914- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
31915+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
31916 return;
31917
31918- pud = pud_offset(pgd, 0);
31919-
31920- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
31921- pmd_t *pmd = pmds[i];
31922+#ifdef CONFIG_X86_64
31923+ pyd = pyd_offset(mm, 0L);
31924+#else
31925+ pyd = pyd_offset(pgd, 0L);
31926+#endif
31927
31928+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
31929+ pxd_t *pxd = pxds[i];
31930 if (i >= KERNEL_PGD_BOUNDARY)
31931- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
31932- sizeof(pmd_t) * PTRS_PER_PMD);
31933+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
31934+ sizeof(pxd_t) * PTRS_PER_PMD);
31935
31936- pud_populate(mm, pud, pmd);
31937+ pyd_populate(mm, pyd, pxd);
31938 }
31939 }
31940
31941 pgd_t *pgd_alloc(struct mm_struct *mm)
31942 {
31943 pgd_t *pgd;
31944- pmd_t *pmds[PREALLOCATED_PMDS];
31945+ pxd_t *pxds[PREALLOCATED_PXDS];
31946
31947 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
31948
31949@@ -270,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
31950
31951 mm->pgd = pgd;
31952
31953- if (preallocate_pmds(pmds) != 0)
31954+ if (preallocate_pxds(pxds) != 0)
31955 goto out_free_pgd;
31956
31957 if (paravirt_pgd_alloc(mm) != 0)
31958- goto out_free_pmds;
31959+ goto out_free_pxds;
31960
31961 /*
31962 * Make sure that pre-populating the pmds is atomic with
31963@@ -284,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
31964 spin_lock(&pgd_lock);
31965
31966 pgd_ctor(mm, pgd);
31967- pgd_prepopulate_pmd(mm, pgd, pmds);
31968+ pgd_prepopulate_pxd(mm, pgd, pxds);
31969
31970 spin_unlock(&pgd_lock);
31971
31972 return pgd;
31973
31974-out_free_pmds:
31975- free_pmds(pmds);
31976+out_free_pxds:
31977+ free_pxds(pxds);
31978 out_free_pgd:
31979 free_page((unsigned long)pgd);
31980 out:
31981@@ -300,7 +363,7 @@ out:
31982
31983 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
31984 {
31985- pgd_mop_up_pmds(mm, pgd);
31986+ pgd_mop_up_pxds(mm, pgd);
31987 pgd_dtor(pgd);
31988 paravirt_pgd_free(mm, pgd);
31989 free_page((unsigned long)pgd);
31990diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
31991index a69bcb8..19068ab 100644
31992--- a/arch/x86/mm/pgtable_32.c
31993+++ b/arch/x86/mm/pgtable_32.c
31994@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
31995 return;
31996 }
31997 pte = pte_offset_kernel(pmd, vaddr);
31998+
31999+ pax_open_kernel();
32000 if (pte_val(pteval))
32001 set_pte_at(&init_mm, vaddr, pte, pteval);
32002 else
32003 pte_clear(&init_mm, vaddr, pte);
32004+ pax_close_kernel();
32005
32006 /*
32007 * It's enough to flush this one mapping.
32008diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
32009index e666cbb..61788c45 100644
32010--- a/arch/x86/mm/physaddr.c
32011+++ b/arch/x86/mm/physaddr.c
32012@@ -10,7 +10,7 @@
32013 #ifdef CONFIG_X86_64
32014
32015 #ifdef CONFIG_DEBUG_VIRTUAL
32016-unsigned long __phys_addr(unsigned long x)
32017+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32018 {
32019 unsigned long y = x - __START_KERNEL_map;
32020
32021@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
32022 #else
32023
32024 #ifdef CONFIG_DEBUG_VIRTUAL
32025-unsigned long __phys_addr(unsigned long x)
32026+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32027 {
32028 unsigned long phys_addr = x - PAGE_OFFSET;
32029 /* VMALLOC_* aren't constants */
32030diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
32031index 90555bf..f5f1828 100644
32032--- a/arch/x86/mm/setup_nx.c
32033+++ b/arch/x86/mm/setup_nx.c
32034@@ -5,8 +5,10 @@
32035 #include <asm/pgtable.h>
32036 #include <asm/proto.h>
32037
32038+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32039 static int disable_nx;
32040
32041+#ifndef CONFIG_PAX_PAGEEXEC
32042 /*
32043 * noexec = on|off
32044 *
32045@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
32046 return 0;
32047 }
32048 early_param("noexec", noexec_setup);
32049+#endif
32050+
32051+#endif
32052
32053 void x86_configure_nx(void)
32054 {
32055+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32056 if (cpu_has_nx && !disable_nx)
32057 __supported_pte_mask |= _PAGE_NX;
32058 else
32059+#endif
32060 __supported_pte_mask &= ~_PAGE_NX;
32061 }
32062
32063diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
32064index 282375f..e03a98f 100644
32065--- a/arch/x86/mm/tlb.c
32066+++ b/arch/x86/mm/tlb.c
32067@@ -48,7 +48,11 @@ void leave_mm(int cpu)
32068 BUG();
32069 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
32070 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
32071+
32072+#ifndef CONFIG_PAX_PER_CPU_PGD
32073 load_cr3(swapper_pg_dir);
32074+#endif
32075+
32076 }
32077 }
32078 EXPORT_SYMBOL_GPL(leave_mm);
32079diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
32080new file mode 100644
32081index 0000000..dace51c
32082--- /dev/null
32083+++ b/arch/x86/mm/uderef_64.c
32084@@ -0,0 +1,37 @@
32085+#include <linux/mm.h>
32086+#include <asm/pgtable.h>
32087+#include <asm/uaccess.h>
32088+
32089+#ifdef CONFIG_PAX_MEMORY_UDEREF
32090+/* PaX: due to the special call convention these functions must
32091+ * - remain leaf functions under all configurations,
32092+ * - never be called directly, only dereferenced from the wrappers.
32093+ */
32094+void __pax_open_userland(void)
32095+{
32096+ unsigned int cpu;
32097+
32098+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32099+ return;
32100+
32101+ cpu = raw_get_cpu();
32102+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
32103+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
32104+ raw_put_cpu_no_resched();
32105+}
32106+EXPORT_SYMBOL(__pax_open_userland);
32107+
32108+void __pax_close_userland(void)
32109+{
32110+ unsigned int cpu;
32111+
32112+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32113+ return;
32114+
32115+ cpu = raw_get_cpu();
32116+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
32117+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
32118+ raw_put_cpu_no_resched();
32119+}
32120+EXPORT_SYMBOL(__pax_close_userland);
32121+#endif
32122diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
32123index 877b9a1..a8ecf42 100644
32124--- a/arch/x86/net/bpf_jit.S
32125+++ b/arch/x86/net/bpf_jit.S
32126@@ -9,6 +9,7 @@
32127 */
32128 #include <linux/linkage.h>
32129 #include <asm/dwarf2.h>
32130+#include <asm/alternative-asm.h>
32131
32132 /*
32133 * Calling convention :
32134@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
32135 jle bpf_slow_path_word
32136 mov (SKBDATA,%rsi),%eax
32137 bswap %eax /* ntohl() */
32138+ pax_force_retaddr
32139 ret
32140
32141 sk_load_half:
32142@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
32143 jle bpf_slow_path_half
32144 movzwl (SKBDATA,%rsi),%eax
32145 rol $8,%ax # ntohs()
32146+ pax_force_retaddr
32147 ret
32148
32149 sk_load_byte:
32150@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
32151 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
32152 jle bpf_slow_path_byte
32153 movzbl (SKBDATA,%rsi),%eax
32154+ pax_force_retaddr
32155 ret
32156
32157 /**
32158@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
32159 movzbl (SKBDATA,%rsi),%ebx
32160 and $15,%bl
32161 shl $2,%bl
32162+ pax_force_retaddr
32163 ret
32164
32165 /* rsi contains offset and can be scratched */
32166@@ -109,6 +114,7 @@ bpf_slow_path_word:
32167 js bpf_error
32168 mov -12(%rbp),%eax
32169 bswap %eax
32170+ pax_force_retaddr
32171 ret
32172
32173 bpf_slow_path_half:
32174@@ -117,12 +123,14 @@ bpf_slow_path_half:
32175 mov -12(%rbp),%ax
32176 rol $8,%ax
32177 movzwl %ax,%eax
32178+ pax_force_retaddr
32179 ret
32180
32181 bpf_slow_path_byte:
32182 bpf_slow_path_common(1)
32183 js bpf_error
32184 movzbl -12(%rbp),%eax
32185+ pax_force_retaddr
32186 ret
32187
32188 bpf_slow_path_byte_msh:
32189@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
32190 and $15,%al
32191 shl $2,%al
32192 xchg %eax,%ebx
32193+ pax_force_retaddr
32194 ret
32195
32196 #define sk_negative_common(SIZE) \
32197@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
32198 sk_negative_common(4)
32199 mov (%rax), %eax
32200 bswap %eax
32201+ pax_force_retaddr
32202 ret
32203
32204 bpf_slow_path_half_neg:
32205@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
32206 mov (%rax),%ax
32207 rol $8,%ax
32208 movzwl %ax,%eax
32209+ pax_force_retaddr
32210 ret
32211
32212 bpf_slow_path_byte_neg:
32213@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
32214 .globl sk_load_byte_negative_offset
32215 sk_negative_common(1)
32216 movzbl (%rax), %eax
32217+ pax_force_retaddr
32218 ret
32219
32220 bpf_slow_path_byte_msh_neg:
32221@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
32222 and $15,%al
32223 shl $2,%al
32224 xchg %eax,%ebx
32225+ pax_force_retaddr
32226 ret
32227
32228 bpf_error:
32229@@ -197,4 +210,5 @@ bpf_error:
32230 xor %eax,%eax
32231 mov -8(%rbp),%rbx
32232 leaveq
32233+ pax_force_retaddr
32234 ret
32235diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
32236index 79c216a..08d39cc 100644
32237--- a/arch/x86/net/bpf_jit_comp.c
32238+++ b/arch/x86/net/bpf_jit_comp.c
32239@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
32240 return ptr + len;
32241 }
32242
32243+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32244+#define MAX_INSTR_CODE_SIZE 96
32245+#else
32246+#define MAX_INSTR_CODE_SIZE 64
32247+#endif
32248+
32249 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
32250
32251 #define EMIT1(b1) EMIT(b1, 1)
32252 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
32253 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
32254 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
32255+
32256+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32257+/* original constant will appear in ecx */
32258+#define DILUTE_CONST_SEQUENCE(_off, _key) \
32259+do { \
32260+ /* mov ecx, randkey */ \
32261+ EMIT1(0xb9); \
32262+ EMIT(_key, 4); \
32263+ /* xor ecx, randkey ^ off */ \
32264+ EMIT2(0x81, 0xf1); \
32265+ EMIT((_key) ^ (_off), 4); \
32266+} while (0)
32267+
32268+#define EMIT1_off32(b1, _off) \
32269+do { \
32270+ switch (b1) { \
32271+ case 0x05: /* add eax, imm32 */ \
32272+ case 0x2d: /* sub eax, imm32 */ \
32273+ case 0x25: /* and eax, imm32 */ \
32274+ case 0x0d: /* or eax, imm32 */ \
32275+ case 0xb8: /* mov eax, imm32 */ \
32276+ case 0x35: /* xor eax, imm32 */ \
32277+ case 0x3d: /* cmp eax, imm32 */ \
32278+ case 0xa9: /* test eax, imm32 */ \
32279+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32280+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
32281+ break; \
32282+ case 0xbb: /* mov ebx, imm32 */ \
32283+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32284+ /* mov ebx, ecx */ \
32285+ EMIT2(0x89, 0xcb); \
32286+ break; \
32287+ case 0xbe: /* mov esi, imm32 */ \
32288+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32289+ /* mov esi, ecx */ \
32290+ EMIT2(0x89, 0xce); \
32291+ break; \
32292+ case 0xe8: /* call rel imm32, always to known funcs */ \
32293+ EMIT1(b1); \
32294+ EMIT(_off, 4); \
32295+ break; \
32296+ case 0xe9: /* jmp rel imm32 */ \
32297+ EMIT1(b1); \
32298+ EMIT(_off, 4); \
32299+ /* prevent fall-through, we're not called if off = 0 */ \
32300+ EMIT(0xcccccccc, 4); \
32301+ EMIT(0xcccccccc, 4); \
32302+ break; \
32303+ default: \
32304+ BUILD_BUG(); \
32305+ } \
32306+} while (0)
32307+
32308+#define EMIT2_off32(b1, b2, _off) \
32309+do { \
32310+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
32311+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
32312+ EMIT(randkey, 4); \
32313+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
32314+ EMIT((_off) - randkey, 4); \
32315+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
32316+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32317+ /* imul eax, ecx */ \
32318+ EMIT3(0x0f, 0xaf, 0xc1); \
32319+ } else { \
32320+ BUILD_BUG(); \
32321+ } \
32322+} while (0)
32323+#else
32324 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
32325+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
32326+#endif
32327
32328 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
32329 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
32330@@ -91,6 +168,24 @@ do { \
32331 #define X86_JBE 0x76
32332 #define X86_JA 0x77
32333
32334+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32335+#define APPEND_FLOW_VERIFY() \
32336+do { \
32337+ /* mov ecx, randkey */ \
32338+ EMIT1(0xb9); \
32339+ EMIT(randkey, 4); \
32340+ /* cmp ecx, randkey */ \
32341+ EMIT2(0x81, 0xf9); \
32342+ EMIT(randkey, 4); \
32343+ /* jz after 8 int 3s */ \
32344+ EMIT2(0x74, 0x08); \
32345+ EMIT(0xcccccccc, 4); \
32346+ EMIT(0xcccccccc, 4); \
32347+} while (0)
32348+#else
32349+#define APPEND_FLOW_VERIFY() do { } while (0)
32350+#endif
32351+
32352 #define EMIT_COND_JMP(op, offset) \
32353 do { \
32354 if (is_near(offset)) \
32355@@ -98,6 +193,7 @@ do { \
32356 else { \
32357 EMIT2(0x0f, op + 0x10); \
32358 EMIT(offset, 4); /* jxx .+off32 */ \
32359+ APPEND_FLOW_VERIFY(); \
32360 } \
32361 } while (0)
32362
32363@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
32364 return -1;
32365 }
32366
32367-struct bpf_binary_header {
32368- unsigned int pages;
32369- /* Note : for security reasons, bpf code will follow a randomly
32370- * sized amount of int3 instructions
32371- */
32372- u8 image[];
32373-};
32374-
32375-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
32376+/* Note : for security reasons, bpf code will follow a randomly
32377+ * sized amount of int3 instructions
32378+ */
32379+static u8 *bpf_alloc_binary(unsigned int proglen,
32380 u8 **image_ptr)
32381 {
32382 unsigned int sz, hole;
32383- struct bpf_binary_header *header;
32384+ u8 *header;
32385
32386 /* Most of BPF filters are really small,
32387 * but if some of them fill a page, allow at least
32388 * 128 extra bytes to insert a random section of int3
32389 */
32390- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
32391- header = module_alloc(sz);
32392+ sz = round_up(proglen + 128, PAGE_SIZE);
32393+ header = module_alloc_exec(sz);
32394 if (!header)
32395 return NULL;
32396
32397+ pax_open_kernel();
32398 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
32399+ pax_close_kernel();
32400
32401- header->pages = sz / PAGE_SIZE;
32402- hole = sz - (proglen + sizeof(*header));
32403+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
32404
32405 /* insert a random number of int3 instructions before BPF code */
32406- *image_ptr = &header->image[prandom_u32() % hole];
32407+ *image_ptr = &header[prandom_u32() % hole];
32408 return header;
32409 }
32410
32411 void bpf_jit_compile(struct sk_filter *fp)
32412 {
32413- u8 temp[64];
32414+ u8 temp[MAX_INSTR_CODE_SIZE];
32415 u8 *prog;
32416 unsigned int proglen, oldproglen = 0;
32417 int ilen, i;
32418 int t_offset, f_offset;
32419 u8 t_op, f_op, seen = 0, pass;
32420 u8 *image = NULL;
32421- struct bpf_binary_header *header = NULL;
32422+ u8 *header = NULL;
32423 u8 *func;
32424 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
32425 unsigned int cleanup_addr; /* epilogue code offset */
32426 unsigned int *addrs;
32427 const struct sock_filter *filter = fp->insns;
32428 int flen = fp->len;
32429+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32430+ unsigned int randkey;
32431+#endif
32432
32433 if (!bpf_jit_enable)
32434 return;
32435@@ -202,11 +297,15 @@ void bpf_jit_compile(struct sk_filter *fp)
32436 if (addrs == NULL)
32437 return;
32438
32439+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32440+ randkey = get_random_int();
32441+#endif
32442+
32443 /* Before first pass, make a rough estimation of addrs[]
32444- * each bpf instruction is translated to less than 64 bytes
32445+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
32446 */
32447 for (proglen = 0, i = 0; i < flen; i++) {
32448- proglen += 64;
32449+ proglen += MAX_INSTR_CODE_SIZE;
32450 addrs[i] = proglen;
32451 }
32452 cleanup_addr = proglen; /* epilogue address */
32453@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
32454 case BPF_S_ALU_MUL_K: /* A *= K */
32455 if (is_imm8(K))
32456 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
32457- else {
32458- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
32459- EMIT(K, 4);
32460- }
32461+ else
32462+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
32463 break;
32464 case BPF_S_ALU_DIV_X: /* A /= X; */
32465 seen |= SEEN_XREG;
32466@@ -360,13 +457,23 @@ void bpf_jit_compile(struct sk_filter *fp)
32467 break;
32468 case BPF_S_ALU_MOD_K: /* A %= K; */
32469 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
32470+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32471+ DILUTE_CONST_SEQUENCE(K, randkey);
32472+#else
32473 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
32474+#endif
32475 EMIT2(0xf7, 0xf1); /* div %ecx */
32476 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
32477 break;
32478 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
32479+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32480+ DILUTE_CONST_SEQUENCE(K, randkey);
32481+ // imul rax, rcx
32482+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
32483+#else
32484 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
32485 EMIT(K, 4);
32486+#endif
32487 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
32488 break;
32489 case BPF_S_ALU_AND_X:
32490@@ -637,8 +744,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
32491 if (is_imm8(K)) {
32492 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
32493 } else {
32494- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
32495- EMIT(K, 4);
32496+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
32497 }
32498 } else {
32499 EMIT2(0x89,0xde); /* mov %ebx,%esi */
32500@@ -728,10 +834,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32501 if (unlikely(proglen + ilen > oldproglen)) {
32502 pr_err("bpb_jit_compile fatal error\n");
32503 kfree(addrs);
32504- module_free(NULL, header);
32505+ module_free_exec(NULL, image);
32506 return;
32507 }
32508+ pax_open_kernel();
32509 memcpy(image + proglen, temp, ilen);
32510+ pax_close_kernel();
32511 }
32512 proglen += ilen;
32513 addrs[i] = proglen;
32514@@ -764,7 +872,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32515
32516 if (image) {
32517 bpf_flush_icache(header, image + proglen);
32518- set_memory_ro((unsigned long)header, header->pages);
32519 fp->bpf_func = (void *)image;
32520 }
32521 out:
32522@@ -776,9 +883,7 @@ void bpf_jit_free(struct sk_filter *fp)
32523 {
32524 if (fp->bpf_func != sk_run_filter) {
32525 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
32526- struct bpf_binary_header *header = (void *)addr;
32527-
32528- set_memory_rw(addr, header->pages);
32529- module_free(NULL, header);
32530+ set_memory_rw(addr, 1);
32531+ module_free_exec(NULL, (void *)addr);
32532 }
32533 }
32534diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
32535index d6aa6e8..266395a 100644
32536--- a/arch/x86/oprofile/backtrace.c
32537+++ b/arch/x86/oprofile/backtrace.c
32538@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
32539 struct stack_frame_ia32 *fp;
32540 unsigned long bytes;
32541
32542- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32543+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32544 if (bytes != sizeof(bufhead))
32545 return NULL;
32546
32547- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
32548+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
32549
32550 oprofile_add_trace(bufhead[0].return_address);
32551
32552@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
32553 struct stack_frame bufhead[2];
32554 unsigned long bytes;
32555
32556- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32557+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32558 if (bytes != sizeof(bufhead))
32559 return NULL;
32560
32561@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
32562 {
32563 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
32564
32565- if (!user_mode_vm(regs)) {
32566+ if (!user_mode(regs)) {
32567 unsigned long stack = kernel_stack_pointer(regs);
32568 if (depth)
32569 dump_trace(NULL, regs, (unsigned long *)stack, 0,
32570diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
32571index 48768df..ba9143c 100644
32572--- a/arch/x86/oprofile/nmi_int.c
32573+++ b/arch/x86/oprofile/nmi_int.c
32574@@ -23,6 +23,7 @@
32575 #include <asm/nmi.h>
32576 #include <asm/msr.h>
32577 #include <asm/apic.h>
32578+#include <asm/pgtable.h>
32579
32580 #include "op_counter.h"
32581 #include "op_x86_model.h"
32582@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
32583 if (ret)
32584 return ret;
32585
32586- if (!model->num_virt_counters)
32587- model->num_virt_counters = model->num_counters;
32588+ if (!model->num_virt_counters) {
32589+ pax_open_kernel();
32590+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
32591+ pax_close_kernel();
32592+ }
32593
32594 mux_init(ops);
32595
32596diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
32597index b2b9443..be58856 100644
32598--- a/arch/x86/oprofile/op_model_amd.c
32599+++ b/arch/x86/oprofile/op_model_amd.c
32600@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
32601 num_counters = AMD64_NUM_COUNTERS;
32602 }
32603
32604- op_amd_spec.num_counters = num_counters;
32605- op_amd_spec.num_controls = num_counters;
32606- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32607+ pax_open_kernel();
32608+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
32609+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
32610+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32611+ pax_close_kernel();
32612
32613 return 0;
32614 }
32615diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
32616index d90528e..0127e2b 100644
32617--- a/arch/x86/oprofile/op_model_ppro.c
32618+++ b/arch/x86/oprofile/op_model_ppro.c
32619@@ -19,6 +19,7 @@
32620 #include <asm/msr.h>
32621 #include <asm/apic.h>
32622 #include <asm/nmi.h>
32623+#include <asm/pgtable.h>
32624
32625 #include "op_x86_model.h"
32626 #include "op_counter.h"
32627@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
32628
32629 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
32630
32631- op_arch_perfmon_spec.num_counters = num_counters;
32632- op_arch_perfmon_spec.num_controls = num_counters;
32633+ pax_open_kernel();
32634+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
32635+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
32636+ pax_close_kernel();
32637 }
32638
32639 static int arch_perfmon_init(struct oprofile_operations *ignore)
32640diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
32641index 71e8a67..6a313bb 100644
32642--- a/arch/x86/oprofile/op_x86_model.h
32643+++ b/arch/x86/oprofile/op_x86_model.h
32644@@ -52,7 +52,7 @@ struct op_x86_model_spec {
32645 void (*switch_ctrl)(struct op_x86_model_spec const *model,
32646 struct op_msrs const * const msrs);
32647 #endif
32648-};
32649+} __do_const;
32650
32651 struct op_counter_config;
32652
32653diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
32654index 372e9b8..e775a6c 100644
32655--- a/arch/x86/pci/irq.c
32656+++ b/arch/x86/pci/irq.c
32657@@ -50,7 +50,7 @@ struct irq_router {
32658 struct irq_router_handler {
32659 u16 vendor;
32660 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
32661-};
32662+} __do_const;
32663
32664 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
32665 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
32666@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
32667 return 0;
32668 }
32669
32670-static __initdata struct irq_router_handler pirq_routers[] = {
32671+static __initconst const struct irq_router_handler pirq_routers[] = {
32672 { PCI_VENDOR_ID_INTEL, intel_router_probe },
32673 { PCI_VENDOR_ID_AL, ali_router_probe },
32674 { PCI_VENDOR_ID_ITE, ite_router_probe },
32675@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
32676 static void __init pirq_find_router(struct irq_router *r)
32677 {
32678 struct irq_routing_table *rt = pirq_table;
32679- struct irq_router_handler *h;
32680+ const struct irq_router_handler *h;
32681
32682 #ifdef CONFIG_PCI_BIOS
32683 if (!rt->signature) {
32684@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
32685 return 0;
32686 }
32687
32688-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
32689+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
32690 {
32691 .callback = fix_broken_hp_bios_irq9,
32692 .ident = "HP Pavilion N5400 Series Laptop",
32693diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
32694index 6eb18c4..20d83de 100644
32695--- a/arch/x86/pci/mrst.c
32696+++ b/arch/x86/pci/mrst.c
32697@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
32698 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
32699 pci_mmcfg_late_init();
32700 pcibios_enable_irq = mrst_pci_irq_enable;
32701- pci_root_ops = pci_mrst_ops;
32702+ pax_open_kernel();
32703+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
32704+ pax_close_kernel();
32705 pci_soc_mode = 1;
32706 /* Continue with standard init */
32707 return 1;
32708diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
32709index c77b24a..c979855 100644
32710--- a/arch/x86/pci/pcbios.c
32711+++ b/arch/x86/pci/pcbios.c
32712@@ -79,7 +79,7 @@ union bios32 {
32713 static struct {
32714 unsigned long address;
32715 unsigned short segment;
32716-} bios32_indirect = { 0, __KERNEL_CS };
32717+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
32718
32719 /*
32720 * Returns the entry point for the given service, NULL on error
32721@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
32722 unsigned long length; /* %ecx */
32723 unsigned long entry; /* %edx */
32724 unsigned long flags;
32725+ struct desc_struct d, *gdt;
32726
32727 local_irq_save(flags);
32728- __asm__("lcall *(%%edi); cld"
32729+
32730+ gdt = get_cpu_gdt_table(smp_processor_id());
32731+
32732+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
32733+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32734+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
32735+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32736+
32737+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
32738 : "=a" (return_code),
32739 "=b" (address),
32740 "=c" (length),
32741 "=d" (entry)
32742 : "0" (service),
32743 "1" (0),
32744- "D" (&bios32_indirect));
32745+ "D" (&bios32_indirect),
32746+ "r"(__PCIBIOS_DS)
32747+ : "memory");
32748+
32749+ pax_open_kernel();
32750+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
32751+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
32752+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
32753+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
32754+ pax_close_kernel();
32755+
32756 local_irq_restore(flags);
32757
32758 switch (return_code) {
32759- case 0:
32760- return address + entry;
32761- case 0x80: /* Not present */
32762- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32763- return 0;
32764- default: /* Shouldn't happen */
32765- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32766- service, return_code);
32767+ case 0: {
32768+ int cpu;
32769+ unsigned char flags;
32770+
32771+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
32772+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
32773+ printk(KERN_WARNING "bios32_service: not valid\n");
32774 return 0;
32775+ }
32776+ address = address + PAGE_OFFSET;
32777+ length += 16UL; /* some BIOSs underreport this... */
32778+ flags = 4;
32779+ if (length >= 64*1024*1024) {
32780+ length >>= PAGE_SHIFT;
32781+ flags |= 8;
32782+ }
32783+
32784+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32785+ gdt = get_cpu_gdt_table(cpu);
32786+ pack_descriptor(&d, address, length, 0x9b, flags);
32787+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32788+ pack_descriptor(&d, address, length, 0x93, flags);
32789+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32790+ }
32791+ return entry;
32792+ }
32793+ case 0x80: /* Not present */
32794+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32795+ return 0;
32796+ default: /* Shouldn't happen */
32797+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32798+ service, return_code);
32799+ return 0;
32800 }
32801 }
32802
32803 static struct {
32804 unsigned long address;
32805 unsigned short segment;
32806-} pci_indirect = { 0, __KERNEL_CS };
32807+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
32808
32809-static int pci_bios_present;
32810+static int pci_bios_present __read_only;
32811
32812 static int check_pcibios(void)
32813 {
32814@@ -131,11 +174,13 @@ static int check_pcibios(void)
32815 unsigned long flags, pcibios_entry;
32816
32817 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
32818- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
32819+ pci_indirect.address = pcibios_entry;
32820
32821 local_irq_save(flags);
32822- __asm__(
32823- "lcall *(%%edi); cld\n\t"
32824+ __asm__("movw %w6, %%ds\n\t"
32825+ "lcall *%%ss:(%%edi); cld\n\t"
32826+ "push %%ss\n\t"
32827+ "pop %%ds\n\t"
32828 "jc 1f\n\t"
32829 "xor %%ah, %%ah\n"
32830 "1:"
32831@@ -144,7 +189,8 @@ static int check_pcibios(void)
32832 "=b" (ebx),
32833 "=c" (ecx)
32834 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
32835- "D" (&pci_indirect)
32836+ "D" (&pci_indirect),
32837+ "r" (__PCIBIOS_DS)
32838 : "memory");
32839 local_irq_restore(flags);
32840
32841@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32842
32843 switch (len) {
32844 case 1:
32845- __asm__("lcall *(%%esi); cld\n\t"
32846+ __asm__("movw %w6, %%ds\n\t"
32847+ "lcall *%%ss:(%%esi); cld\n\t"
32848+ "push %%ss\n\t"
32849+ "pop %%ds\n\t"
32850 "jc 1f\n\t"
32851 "xor %%ah, %%ah\n"
32852 "1:"
32853@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32854 : "1" (PCIBIOS_READ_CONFIG_BYTE),
32855 "b" (bx),
32856 "D" ((long)reg),
32857- "S" (&pci_indirect));
32858+ "S" (&pci_indirect),
32859+ "r" (__PCIBIOS_DS));
32860 /*
32861 * Zero-extend the result beyond 8 bits, do not trust the
32862 * BIOS having done it:
32863@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32864 *value &= 0xff;
32865 break;
32866 case 2:
32867- __asm__("lcall *(%%esi); cld\n\t"
32868+ __asm__("movw %w6, %%ds\n\t"
32869+ "lcall *%%ss:(%%esi); cld\n\t"
32870+ "push %%ss\n\t"
32871+ "pop %%ds\n\t"
32872 "jc 1f\n\t"
32873 "xor %%ah, %%ah\n"
32874 "1:"
32875@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32876 : "1" (PCIBIOS_READ_CONFIG_WORD),
32877 "b" (bx),
32878 "D" ((long)reg),
32879- "S" (&pci_indirect));
32880+ "S" (&pci_indirect),
32881+ "r" (__PCIBIOS_DS));
32882 /*
32883 * Zero-extend the result beyond 16 bits, do not trust the
32884 * BIOS having done it:
32885@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32886 *value &= 0xffff;
32887 break;
32888 case 4:
32889- __asm__("lcall *(%%esi); cld\n\t"
32890+ __asm__("movw %w6, %%ds\n\t"
32891+ "lcall *%%ss:(%%esi); cld\n\t"
32892+ "push %%ss\n\t"
32893+ "pop %%ds\n\t"
32894 "jc 1f\n\t"
32895 "xor %%ah, %%ah\n"
32896 "1:"
32897@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32898 : "1" (PCIBIOS_READ_CONFIG_DWORD),
32899 "b" (bx),
32900 "D" ((long)reg),
32901- "S" (&pci_indirect));
32902+ "S" (&pci_indirect),
32903+ "r" (__PCIBIOS_DS));
32904 break;
32905 }
32906
32907@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32908
32909 switch (len) {
32910 case 1:
32911- __asm__("lcall *(%%esi); cld\n\t"
32912+ __asm__("movw %w6, %%ds\n\t"
32913+ "lcall *%%ss:(%%esi); cld\n\t"
32914+ "push %%ss\n\t"
32915+ "pop %%ds\n\t"
32916 "jc 1f\n\t"
32917 "xor %%ah, %%ah\n"
32918 "1:"
32919@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32920 "c" (value),
32921 "b" (bx),
32922 "D" ((long)reg),
32923- "S" (&pci_indirect));
32924+ "S" (&pci_indirect),
32925+ "r" (__PCIBIOS_DS));
32926 break;
32927 case 2:
32928- __asm__("lcall *(%%esi); cld\n\t"
32929+ __asm__("movw %w6, %%ds\n\t"
32930+ "lcall *%%ss:(%%esi); cld\n\t"
32931+ "push %%ss\n\t"
32932+ "pop %%ds\n\t"
32933 "jc 1f\n\t"
32934 "xor %%ah, %%ah\n"
32935 "1:"
32936@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32937 "c" (value),
32938 "b" (bx),
32939 "D" ((long)reg),
32940- "S" (&pci_indirect));
32941+ "S" (&pci_indirect),
32942+ "r" (__PCIBIOS_DS));
32943 break;
32944 case 4:
32945- __asm__("lcall *(%%esi); cld\n\t"
32946+ __asm__("movw %w6, %%ds\n\t"
32947+ "lcall *%%ss:(%%esi); cld\n\t"
32948+ "push %%ss\n\t"
32949+ "pop %%ds\n\t"
32950 "jc 1f\n\t"
32951 "xor %%ah, %%ah\n"
32952 "1:"
32953@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32954 "c" (value),
32955 "b" (bx),
32956 "D" ((long)reg),
32957- "S" (&pci_indirect));
32958+ "S" (&pci_indirect),
32959+ "r" (__PCIBIOS_DS));
32960 break;
32961 }
32962
32963@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
32964
32965 DBG("PCI: Fetching IRQ routing table... ");
32966 __asm__("push %%es\n\t"
32967+ "movw %w8, %%ds\n\t"
32968 "push %%ds\n\t"
32969 "pop %%es\n\t"
32970- "lcall *(%%esi); cld\n\t"
32971+ "lcall *%%ss:(%%esi); cld\n\t"
32972 "pop %%es\n\t"
32973+ "push %%ss\n\t"
32974+ "pop %%ds\n"
32975 "jc 1f\n\t"
32976 "xor %%ah, %%ah\n"
32977 "1:"
32978@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
32979 "1" (0),
32980 "D" ((long) &opt),
32981 "S" (&pci_indirect),
32982- "m" (opt)
32983+ "m" (opt),
32984+ "r" (__PCIBIOS_DS)
32985 : "memory");
32986 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
32987 if (ret & 0xff00)
32988@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
32989 {
32990 int ret;
32991
32992- __asm__("lcall *(%%esi); cld\n\t"
32993+ __asm__("movw %w5, %%ds\n\t"
32994+ "lcall *%%ss:(%%esi); cld\n\t"
32995+ "push %%ss\n\t"
32996+ "pop %%ds\n"
32997 "jc 1f\n\t"
32998 "xor %%ah, %%ah\n"
32999 "1:"
33000@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33001 : "0" (PCIBIOS_SET_PCI_HW_INT),
33002 "b" ((dev->bus->number << 8) | dev->devfn),
33003 "c" ((irq << 8) | (pin + 10)),
33004- "S" (&pci_indirect));
33005+ "S" (&pci_indirect),
33006+ "r" (__PCIBIOS_DS));
33007 return !(ret & 0xff00);
33008 }
33009 EXPORT_SYMBOL(pcibios_set_irq_routing);
33010diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
33011index 40e4469..d915bf9 100644
33012--- a/arch/x86/platform/efi/efi_32.c
33013+++ b/arch/x86/platform/efi/efi_32.c
33014@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
33015 {
33016 struct desc_ptr gdt_descr;
33017
33018+#ifdef CONFIG_PAX_KERNEXEC
33019+ struct desc_struct d;
33020+#endif
33021+
33022 local_irq_save(efi_rt_eflags);
33023
33024 load_cr3(initial_page_table);
33025 __flush_tlb_all();
33026
33027+#ifdef CONFIG_PAX_KERNEXEC
33028+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
33029+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33030+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
33031+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33032+#endif
33033+
33034 gdt_descr.address = __pa(get_cpu_gdt_table(0));
33035 gdt_descr.size = GDT_SIZE - 1;
33036 load_gdt(&gdt_descr);
33037@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
33038 {
33039 struct desc_ptr gdt_descr;
33040
33041+#ifdef CONFIG_PAX_KERNEXEC
33042+ struct desc_struct d;
33043+
33044+ memset(&d, 0, sizeof d);
33045+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33046+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33047+#endif
33048+
33049 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
33050 gdt_descr.size = GDT_SIZE - 1;
33051 load_gdt(&gdt_descr);
33052
33053+#ifdef CONFIG_PAX_PER_CPU_PGD
33054+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33055+#else
33056 load_cr3(swapper_pg_dir);
33057+#endif
33058+
33059 __flush_tlb_all();
33060
33061 local_irq_restore(efi_rt_eflags);
33062diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
33063index 39a0e7f1..872396e 100644
33064--- a/arch/x86/platform/efi/efi_64.c
33065+++ b/arch/x86/platform/efi/efi_64.c
33066@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
33067 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
33068 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
33069 }
33070+
33071+#ifdef CONFIG_PAX_PER_CPU_PGD
33072+ load_cr3(swapper_pg_dir);
33073+#endif
33074+
33075 __flush_tlb_all();
33076 }
33077
33078@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
33079 for (pgd = 0; pgd < n_pgds; pgd++)
33080 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
33081 kfree(save_pgd);
33082+
33083+#ifdef CONFIG_PAX_PER_CPU_PGD
33084+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33085+#endif
33086+
33087 __flush_tlb_all();
33088 local_irq_restore(efi_flags);
33089 early_code_mapping_set_exec(0);
33090diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
33091index fbe66e6..eae5e38 100644
33092--- a/arch/x86/platform/efi/efi_stub_32.S
33093+++ b/arch/x86/platform/efi/efi_stub_32.S
33094@@ -6,7 +6,9 @@
33095 */
33096
33097 #include <linux/linkage.h>
33098+#include <linux/init.h>
33099 #include <asm/page_types.h>
33100+#include <asm/segment.h>
33101
33102 /*
33103 * efi_call_phys(void *, ...) is a function with variable parameters.
33104@@ -20,7 +22,7 @@
33105 * service functions will comply with gcc calling convention, too.
33106 */
33107
33108-.text
33109+__INIT
33110 ENTRY(efi_call_phys)
33111 /*
33112 * 0. The function can only be called in Linux kernel. So CS has been
33113@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
33114 * The mapping of lower virtual memory has been created in prelog and
33115 * epilog.
33116 */
33117- movl $1f, %edx
33118- subl $__PAGE_OFFSET, %edx
33119- jmp *%edx
33120+#ifdef CONFIG_PAX_KERNEXEC
33121+ movl $(__KERNEXEC_EFI_DS), %edx
33122+ mov %edx, %ds
33123+ mov %edx, %es
33124+ mov %edx, %ss
33125+ addl $2f,(1f)
33126+ ljmp *(1f)
33127+
33128+__INITDATA
33129+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
33130+.previous
33131+
33132+2:
33133+ subl $2b,(1b)
33134+#else
33135+ jmp 1f-__PAGE_OFFSET
33136 1:
33137+#endif
33138
33139 /*
33140 * 2. Now on the top of stack is the return
33141@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
33142 * parameter 2, ..., param n. To make things easy, we save the return
33143 * address of efi_call_phys in a global variable.
33144 */
33145- popl %edx
33146- movl %edx, saved_return_addr
33147- /* get the function pointer into ECX*/
33148- popl %ecx
33149- movl %ecx, efi_rt_function_ptr
33150- movl $2f, %edx
33151- subl $__PAGE_OFFSET, %edx
33152- pushl %edx
33153+ popl (saved_return_addr)
33154+ popl (efi_rt_function_ptr)
33155
33156 /*
33157 * 3. Clear PG bit in %CR0.
33158@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
33159 /*
33160 * 5. Call the physical function.
33161 */
33162- jmp *%ecx
33163+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
33164
33165-2:
33166 /*
33167 * 6. After EFI runtime service returns, control will return to
33168 * following instruction. We'd better readjust stack pointer first.
33169@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
33170 movl %cr0, %edx
33171 orl $0x80000000, %edx
33172 movl %edx, %cr0
33173- jmp 1f
33174-1:
33175+
33176 /*
33177 * 8. Now restore the virtual mode from flat mode by
33178 * adding EIP with PAGE_OFFSET.
33179 */
33180- movl $1f, %edx
33181- jmp *%edx
33182+#ifdef CONFIG_PAX_KERNEXEC
33183+ movl $(__KERNEL_DS), %edx
33184+ mov %edx, %ds
33185+ mov %edx, %es
33186+ mov %edx, %ss
33187+ ljmp $(__KERNEL_CS),$1f
33188+#else
33189+ jmp 1f+__PAGE_OFFSET
33190+#endif
33191 1:
33192
33193 /*
33194 * 9. Balance the stack. And because EAX contain the return value,
33195 * we'd better not clobber it.
33196 */
33197- leal efi_rt_function_ptr, %edx
33198- movl (%edx), %ecx
33199- pushl %ecx
33200+ pushl (efi_rt_function_ptr)
33201
33202 /*
33203- * 10. Push the saved return address onto the stack and return.
33204+ * 10. Return to the saved return address.
33205 */
33206- leal saved_return_addr, %edx
33207- movl (%edx), %ecx
33208- pushl %ecx
33209- ret
33210+ jmpl *(saved_return_addr)
33211 ENDPROC(efi_call_phys)
33212 .previous
33213
33214-.data
33215+__INITDATA
33216 saved_return_addr:
33217 .long 0
33218 efi_rt_function_ptr:
33219diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
33220index 4c07cca..2c8427d 100644
33221--- a/arch/x86/platform/efi/efi_stub_64.S
33222+++ b/arch/x86/platform/efi/efi_stub_64.S
33223@@ -7,6 +7,7 @@
33224 */
33225
33226 #include <linux/linkage.h>
33227+#include <asm/alternative-asm.h>
33228
33229 #define SAVE_XMM \
33230 mov %rsp, %rax; \
33231@@ -40,6 +41,7 @@ ENTRY(efi_call0)
33232 call *%rdi
33233 addq $32, %rsp
33234 RESTORE_XMM
33235+ pax_force_retaddr 0, 1
33236 ret
33237 ENDPROC(efi_call0)
33238
33239@@ -50,6 +52,7 @@ ENTRY(efi_call1)
33240 call *%rdi
33241 addq $32, %rsp
33242 RESTORE_XMM
33243+ pax_force_retaddr 0, 1
33244 ret
33245 ENDPROC(efi_call1)
33246
33247@@ -60,6 +63,7 @@ ENTRY(efi_call2)
33248 call *%rdi
33249 addq $32, %rsp
33250 RESTORE_XMM
33251+ pax_force_retaddr 0, 1
33252 ret
33253 ENDPROC(efi_call2)
33254
33255@@ -71,6 +75,7 @@ ENTRY(efi_call3)
33256 call *%rdi
33257 addq $32, %rsp
33258 RESTORE_XMM
33259+ pax_force_retaddr 0, 1
33260 ret
33261 ENDPROC(efi_call3)
33262
33263@@ -83,6 +88,7 @@ ENTRY(efi_call4)
33264 call *%rdi
33265 addq $32, %rsp
33266 RESTORE_XMM
33267+ pax_force_retaddr 0, 1
33268 ret
33269 ENDPROC(efi_call4)
33270
33271@@ -96,6 +102,7 @@ ENTRY(efi_call5)
33272 call *%rdi
33273 addq $48, %rsp
33274 RESTORE_XMM
33275+ pax_force_retaddr 0, 1
33276 ret
33277 ENDPROC(efi_call5)
33278
33279@@ -112,5 +119,6 @@ ENTRY(efi_call6)
33280 call *%rdi
33281 addq $48, %rsp
33282 RESTORE_XMM
33283+ pax_force_retaddr 0, 1
33284 ret
33285 ENDPROC(efi_call6)
33286diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
33287index 47fe66f..6206449 100644
33288--- a/arch/x86/platform/mrst/mrst.c
33289+++ b/arch/x86/platform/mrst/mrst.c
33290@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
33291 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
33292 int sfi_mrtc_num;
33293
33294-static void mrst_power_off(void)
33295+static __noreturn void mrst_power_off(void)
33296 {
33297+ BUG();
33298 }
33299
33300-static void mrst_reboot(void)
33301+static __noreturn void mrst_reboot(void)
33302 {
33303 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
33304+ BUG();
33305 }
33306
33307 /* parse all the mtimer info to a static mtimer array */
33308diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
33309index d6ee929..3637cb5 100644
33310--- a/arch/x86/platform/olpc/olpc_dt.c
33311+++ b/arch/x86/platform/olpc/olpc_dt.c
33312@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
33313 return res;
33314 }
33315
33316-static struct of_pdt_ops prom_olpc_ops __initdata = {
33317+static struct of_pdt_ops prom_olpc_ops __initconst = {
33318 .nextprop = olpc_dt_nextprop,
33319 .getproplen = olpc_dt_getproplen,
33320 .getproperty = olpc_dt_getproperty,
33321diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
33322index 1cf5b30..fd45732 100644
33323--- a/arch/x86/power/cpu.c
33324+++ b/arch/x86/power/cpu.c
33325@@ -137,11 +137,8 @@ static void do_fpu_end(void)
33326 static void fix_processor_context(void)
33327 {
33328 int cpu = smp_processor_id();
33329- struct tss_struct *t = &per_cpu(init_tss, cpu);
33330-#ifdef CONFIG_X86_64
33331- struct desc_struct *desc = get_cpu_gdt_table(cpu);
33332- tss_desc tss;
33333-#endif
33334+ struct tss_struct *t = init_tss + cpu;
33335+
33336 set_tss_desc(cpu, t); /*
33337 * This just modifies memory; should not be
33338 * necessary. But... This is necessary, because
33339@@ -150,10 +147,6 @@ static void fix_processor_context(void)
33340 */
33341
33342 #ifdef CONFIG_X86_64
33343- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
33344- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
33345- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
33346-
33347 syscall_init(); /* This sets MSR_*STAR and related */
33348 #endif
33349 load_TR_desc(); /* This does ltr */
33350diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
33351index a44f457..9140171 100644
33352--- a/arch/x86/realmode/init.c
33353+++ b/arch/x86/realmode/init.c
33354@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
33355 __va(real_mode_header->trampoline_header);
33356
33357 #ifdef CONFIG_X86_32
33358- trampoline_header->start = __pa_symbol(startup_32_smp);
33359+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
33360+
33361+#ifdef CONFIG_PAX_KERNEXEC
33362+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
33363+#endif
33364+
33365+ trampoline_header->boot_cs = __BOOT_CS;
33366 trampoline_header->gdt_limit = __BOOT_DS + 7;
33367 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
33368 #else
33369@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
33370 *trampoline_cr4_features = read_cr4();
33371
33372 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
33373- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
33374+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
33375 trampoline_pgd[511] = init_level4_pgt[511].pgd;
33376 #endif
33377 }
33378diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
33379index 8869287..d577672 100644
33380--- a/arch/x86/realmode/rm/Makefile
33381+++ b/arch/x86/realmode/rm/Makefile
33382@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
33383 $(call cc-option, -fno-unit-at-a-time)) \
33384 $(call cc-option, -fno-stack-protector) \
33385 $(call cc-option, -mpreferred-stack-boundary=2)
33386+ifdef CONSTIFY_PLUGIN
33387+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
33388+endif
33389 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
33390 GCOV_PROFILE := n
33391diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
33392index a28221d..93c40f1 100644
33393--- a/arch/x86/realmode/rm/header.S
33394+++ b/arch/x86/realmode/rm/header.S
33395@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
33396 #endif
33397 /* APM/BIOS reboot */
33398 .long pa_machine_real_restart_asm
33399-#ifdef CONFIG_X86_64
33400+#ifdef CONFIG_X86_32
33401+ .long __KERNEL_CS
33402+#else
33403 .long __KERNEL32_CS
33404 #endif
33405 END(real_mode_header)
33406diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
33407index c1b2791..f9e31c7 100644
33408--- a/arch/x86/realmode/rm/trampoline_32.S
33409+++ b/arch/x86/realmode/rm/trampoline_32.S
33410@@ -25,6 +25,12 @@
33411 #include <asm/page_types.h>
33412 #include "realmode.h"
33413
33414+#ifdef CONFIG_PAX_KERNEXEC
33415+#define ta(X) (X)
33416+#else
33417+#define ta(X) (pa_ ## X)
33418+#endif
33419+
33420 .text
33421 .code16
33422
33423@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
33424
33425 cli # We should be safe anyway
33426
33427- movl tr_start, %eax # where we need to go
33428-
33429 movl $0xA5A5A5A5, trampoline_status
33430 # write marker for master knows we're running
33431
33432@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
33433 movw $1, %dx # protected mode (PE) bit
33434 lmsw %dx # into protected mode
33435
33436- ljmpl $__BOOT_CS, $pa_startup_32
33437+ ljmpl *(trampoline_header)
33438
33439 .section ".text32","ax"
33440 .code32
33441@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
33442 .balign 8
33443 GLOBAL(trampoline_header)
33444 tr_start: .space 4
33445- tr_gdt_pad: .space 2
33446+ tr_boot_cs: .space 2
33447 tr_gdt: .space 6
33448 END(trampoline_header)
33449
33450diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
33451index bb360dc..d0fd8f8 100644
33452--- a/arch/x86/realmode/rm/trampoline_64.S
33453+++ b/arch/x86/realmode/rm/trampoline_64.S
33454@@ -94,6 +94,7 @@ ENTRY(startup_32)
33455 movl %edx, %gs
33456
33457 movl pa_tr_cr4, %eax
33458+ andl $~X86_CR4_PCIDE, %eax
33459 movl %eax, %cr4 # Enable PAE mode
33460
33461 # Setup trampoline 4 level pagetables
33462@@ -107,7 +108,7 @@ ENTRY(startup_32)
33463 wrmsr
33464
33465 # Enable paging and in turn activate Long Mode
33466- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
33467+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
33468 movl %eax, %cr0
33469
33470 /*
33471diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
33472index e812034..c747134 100644
33473--- a/arch/x86/tools/Makefile
33474+++ b/arch/x86/tools/Makefile
33475@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
33476
33477 $(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
33478
33479-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
33480+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
33481 hostprogs-y += relocs
33482 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
33483 relocs: $(obj)/relocs
33484diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
33485index f7bab68..b6d9886 100644
33486--- a/arch/x86/tools/relocs.c
33487+++ b/arch/x86/tools/relocs.c
33488@@ -1,5 +1,7 @@
33489 /* This is included from relocs_32/64.c */
33490
33491+#include "../../../include/generated/autoconf.h"
33492+
33493 #define ElfW(type) _ElfW(ELF_BITS, type)
33494 #define _ElfW(bits, type) __ElfW(bits, type)
33495 #define __ElfW(bits, type) Elf##bits##_##type
33496@@ -11,6 +13,7 @@
33497 #define Elf_Sym ElfW(Sym)
33498
33499 static Elf_Ehdr ehdr;
33500+static Elf_Phdr *phdr;
33501
33502 struct relocs {
33503 uint32_t *offset;
33504@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
33505 }
33506 }
33507
33508+static void read_phdrs(FILE *fp)
33509+{
33510+ unsigned int i;
33511+
33512+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
33513+ if (!phdr) {
33514+ die("Unable to allocate %d program headers\n",
33515+ ehdr.e_phnum);
33516+ }
33517+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
33518+ die("Seek to %d failed: %s\n",
33519+ ehdr.e_phoff, strerror(errno));
33520+ }
33521+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
33522+ die("Cannot read ELF program headers: %s\n",
33523+ strerror(errno));
33524+ }
33525+ for(i = 0; i < ehdr.e_phnum; i++) {
33526+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
33527+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
33528+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
33529+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
33530+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
33531+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
33532+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
33533+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
33534+ }
33535+
33536+}
33537+
33538 static void read_shdrs(FILE *fp)
33539 {
33540- int i;
33541+ unsigned int i;
33542 Elf_Shdr shdr;
33543
33544 secs = calloc(ehdr.e_shnum, sizeof(struct section));
33545@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
33546
33547 static void read_strtabs(FILE *fp)
33548 {
33549- int i;
33550+ unsigned int i;
33551 for (i = 0; i < ehdr.e_shnum; i++) {
33552 struct section *sec = &secs[i];
33553 if (sec->shdr.sh_type != SHT_STRTAB) {
33554@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
33555
33556 static void read_symtabs(FILE *fp)
33557 {
33558- int i,j;
33559+ unsigned int i,j;
33560 for (i = 0; i < ehdr.e_shnum; i++) {
33561 struct section *sec = &secs[i];
33562 if (sec->shdr.sh_type != SHT_SYMTAB) {
33563@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
33564 }
33565
33566
33567-static void read_relocs(FILE *fp)
33568+static void read_relocs(FILE *fp, int use_real_mode)
33569 {
33570- int i,j;
33571+ unsigned int i,j;
33572+ uint32_t base;
33573+
33574 for (i = 0; i < ehdr.e_shnum; i++) {
33575 struct section *sec = &secs[i];
33576 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33577@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
33578 die("Cannot read symbol table: %s\n",
33579 strerror(errno));
33580 }
33581+ base = 0;
33582+
33583+#ifdef CONFIG_X86_32
33584+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
33585+ if (phdr[j].p_type != PT_LOAD )
33586+ continue;
33587+ 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)
33588+ continue;
33589+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
33590+ break;
33591+ }
33592+#endif
33593+
33594 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
33595 Elf_Rel *rel = &sec->reltab[j];
33596- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
33597+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
33598 rel->r_info = elf_xword_to_cpu(rel->r_info);
33599 #if (SHT_REL_TYPE == SHT_RELA)
33600 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
33601@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
33602
33603 static void print_absolute_symbols(void)
33604 {
33605- int i;
33606+ unsigned int i;
33607 const char *format;
33608
33609 if (ELF_BITS == 64)
33610@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
33611 for (i = 0; i < ehdr.e_shnum; i++) {
33612 struct section *sec = &secs[i];
33613 char *sym_strtab;
33614- int j;
33615+ unsigned int j;
33616
33617 if (sec->shdr.sh_type != SHT_SYMTAB) {
33618 continue;
33619@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
33620
33621 static void print_absolute_relocs(void)
33622 {
33623- int i, printed = 0;
33624+ unsigned int i, printed = 0;
33625 const char *format;
33626
33627 if (ELF_BITS == 64)
33628@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
33629 struct section *sec_applies, *sec_symtab;
33630 char *sym_strtab;
33631 Elf_Sym *sh_symtab;
33632- int j;
33633+ unsigned int j;
33634 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33635 continue;
33636 }
33637@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
33638 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
33639 Elf_Sym *sym, const char *symname))
33640 {
33641- int i;
33642+ unsigned int i;
33643 /* Walk through the relocations */
33644 for (i = 0; i < ehdr.e_shnum; i++) {
33645 char *sym_strtab;
33646 Elf_Sym *sh_symtab;
33647 struct section *sec_applies, *sec_symtab;
33648- int j;
33649+ unsigned int j;
33650 struct section *sec = &secs[i];
33651
33652 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33653@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33654 {
33655 unsigned r_type = ELF32_R_TYPE(rel->r_info);
33656 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
33657+ char *sym_strtab = sec->link->link->strtab;
33658+
33659+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
33660+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
33661+ return 0;
33662+
33663+#ifdef CONFIG_PAX_KERNEXEC
33664+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
33665+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
33666+ return 0;
33667+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
33668+ return 0;
33669+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
33670+ return 0;
33671+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
33672+ return 0;
33673+#endif
33674
33675 switch (r_type) {
33676 case R_386_NONE:
33677@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
33678
33679 static void emit_relocs(int as_text, int use_real_mode)
33680 {
33681- int i;
33682+ unsigned int i;
33683 int (*write_reloc)(uint32_t, FILE *) = write32;
33684 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33685 const char *symname);
33686@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
33687 {
33688 regex_init(use_real_mode);
33689 read_ehdr(fp);
33690+ read_phdrs(fp);
33691 read_shdrs(fp);
33692 read_strtabs(fp);
33693 read_symtabs(fp);
33694- read_relocs(fp);
33695+ read_relocs(fp, use_real_mode);
33696 if (ELF_BITS == 64)
33697 percpu_init();
33698 if (show_absolute_syms) {
33699diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
33700index 80ffa5b..a33bd15 100644
33701--- a/arch/x86/um/tls_32.c
33702+++ b/arch/x86/um/tls_32.c
33703@@ -260,7 +260,7 @@ out:
33704 if (unlikely(task == current &&
33705 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
33706 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
33707- "without flushed TLS.", current->pid);
33708+ "without flushed TLS.", task_pid_nr(current));
33709 }
33710
33711 return 0;
33712diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
33713index fd14be1..e3c79c0 100644
33714--- a/arch/x86/vdso/Makefile
33715+++ b/arch/x86/vdso/Makefile
33716@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
33717 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
33718 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
33719
33720-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33721+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33722 GCOV_PROFILE := n
33723
33724 #
33725diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
33726index d6bfb87..876ee18 100644
33727--- a/arch/x86/vdso/vdso32-setup.c
33728+++ b/arch/x86/vdso/vdso32-setup.c
33729@@ -25,6 +25,7 @@
33730 #include <asm/tlbflush.h>
33731 #include <asm/vdso.h>
33732 #include <asm/proto.h>
33733+#include <asm/mman.h>
33734
33735 enum {
33736 VDSO_DISABLED = 0,
33737@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
33738 void enable_sep_cpu(void)
33739 {
33740 int cpu = get_cpu();
33741- struct tss_struct *tss = &per_cpu(init_tss, cpu);
33742+ struct tss_struct *tss = init_tss + cpu;
33743
33744 if (!boot_cpu_has(X86_FEATURE_SEP)) {
33745 put_cpu();
33746@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
33747 gate_vma.vm_start = FIXADDR_USER_START;
33748 gate_vma.vm_end = FIXADDR_USER_END;
33749 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
33750- gate_vma.vm_page_prot = __P101;
33751+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
33752
33753 return 0;
33754 }
33755@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33756 if (compat)
33757 addr = VDSO_HIGH_BASE;
33758 else {
33759- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
33760+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
33761 if (IS_ERR_VALUE(addr)) {
33762 ret = addr;
33763 goto up_fail;
33764 }
33765 }
33766
33767- current->mm->context.vdso = (void *)addr;
33768+ current->mm->context.vdso = addr;
33769
33770 if (compat_uses_vma || !compat) {
33771 /*
33772@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33773 }
33774
33775 current_thread_info()->sysenter_return =
33776- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33777+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33778
33779 up_fail:
33780 if (ret)
33781- current->mm->context.vdso = NULL;
33782+ current->mm->context.vdso = 0;
33783
33784 up_write(&mm->mmap_sem);
33785
33786@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
33787
33788 const char *arch_vma_name(struct vm_area_struct *vma)
33789 {
33790- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
33791+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
33792 return "[vdso]";
33793+
33794+#ifdef CONFIG_PAX_SEGMEXEC
33795+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
33796+ return "[vdso]";
33797+#endif
33798+
33799 return NULL;
33800 }
33801
33802@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
33803 * Check to see if the corresponding task was created in compat vdso
33804 * mode.
33805 */
33806- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
33807+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
33808 return &gate_vma;
33809 return NULL;
33810 }
33811diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
33812index 431e875..cbb23f3 100644
33813--- a/arch/x86/vdso/vma.c
33814+++ b/arch/x86/vdso/vma.c
33815@@ -16,8 +16,6 @@
33816 #include <asm/vdso.h>
33817 #include <asm/page.h>
33818
33819-unsigned int __read_mostly vdso_enabled = 1;
33820-
33821 extern char vdso_start[], vdso_end[];
33822 extern unsigned short vdso_sync_cpuid;
33823
33824@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
33825 * unaligned here as a result of stack start randomization.
33826 */
33827 addr = PAGE_ALIGN(addr);
33828- addr = align_vdso_addr(addr);
33829
33830 return addr;
33831 }
33832@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
33833 unsigned size)
33834 {
33835 struct mm_struct *mm = current->mm;
33836- unsigned long addr;
33837+ unsigned long addr = 0;
33838 int ret;
33839
33840- if (!vdso_enabled)
33841- return 0;
33842-
33843 down_write(&mm->mmap_sem);
33844+
33845+#ifdef CONFIG_PAX_RANDMMAP
33846+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
33847+#endif
33848+
33849 addr = vdso_addr(mm->start_stack, size);
33850+ addr = align_vdso_addr(addr);
33851 addr = get_unmapped_area(NULL, addr, size, 0, 0);
33852 if (IS_ERR_VALUE(addr)) {
33853 ret = addr;
33854 goto up_fail;
33855 }
33856
33857- current->mm->context.vdso = (void *)addr;
33858+ mm->context.vdso = addr;
33859
33860 ret = install_special_mapping(mm, addr, size,
33861 VM_READ|VM_EXEC|
33862 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
33863 pages);
33864- if (ret) {
33865- current->mm->context.vdso = NULL;
33866- goto up_fail;
33867- }
33868+ if (ret)
33869+ mm->context.vdso = 0;
33870
33871 up_fail:
33872 up_write(&mm->mmap_sem);
33873@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33874 vdsox32_size);
33875 }
33876 #endif
33877-
33878-static __init int vdso_setup(char *s)
33879-{
33880- vdso_enabled = simple_strtoul(s, NULL, 0);
33881- return 0;
33882-}
33883-__setup("vdso=", vdso_setup);
33884diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
33885index 193097e..7590269 100644
33886--- a/arch/x86/xen/enlighten.c
33887+++ b/arch/x86/xen/enlighten.c
33888@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
33889
33890 struct shared_info xen_dummy_shared_info;
33891
33892-void *xen_initial_gdt;
33893-
33894 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
33895 __read_mostly int xen_have_vector_callback;
33896 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
33897@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
33898 {
33899 unsigned long va = dtr->address;
33900 unsigned int size = dtr->size + 1;
33901- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
33902- unsigned long frames[pages];
33903+ unsigned long frames[65536 / PAGE_SIZE];
33904 int f;
33905
33906 /*
33907@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
33908 {
33909 unsigned long va = dtr->address;
33910 unsigned int size = dtr->size + 1;
33911- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
33912- unsigned long frames[pages];
33913+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
33914 int f;
33915
33916 /*
33917@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
33918 * 8-byte entries, or 16 4k pages..
33919 */
33920
33921- BUG_ON(size > 65536);
33922+ BUG_ON(size > GDT_SIZE);
33923 BUG_ON(va & ~PAGE_MASK);
33924
33925 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
33926@@ -985,7 +981,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
33927 return 0;
33928 }
33929
33930-static void set_xen_basic_apic_ops(void)
33931+static void __init set_xen_basic_apic_ops(void)
33932 {
33933 apic->read = xen_apic_read;
33934 apic->write = xen_apic_write;
33935@@ -1290,30 +1286,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
33936 #endif
33937 };
33938
33939-static void xen_reboot(int reason)
33940+static __noreturn void xen_reboot(int reason)
33941 {
33942 struct sched_shutdown r = { .reason = reason };
33943
33944- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
33945- BUG();
33946+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
33947+ BUG();
33948 }
33949
33950-static void xen_restart(char *msg)
33951+static __noreturn void xen_restart(char *msg)
33952 {
33953 xen_reboot(SHUTDOWN_reboot);
33954 }
33955
33956-static void xen_emergency_restart(void)
33957+static __noreturn void xen_emergency_restart(void)
33958 {
33959 xen_reboot(SHUTDOWN_reboot);
33960 }
33961
33962-static void xen_machine_halt(void)
33963+static __noreturn void xen_machine_halt(void)
33964 {
33965 xen_reboot(SHUTDOWN_poweroff);
33966 }
33967
33968-static void xen_machine_power_off(void)
33969+static __noreturn void xen_machine_power_off(void)
33970 {
33971 if (pm_power_off)
33972 pm_power_off();
33973@@ -1464,7 +1460,17 @@ asmlinkage void __init xen_start_kernel(void)
33974 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
33975
33976 /* Work out if we support NX */
33977- x86_configure_nx();
33978+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33979+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
33980+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
33981+ unsigned l, h;
33982+
33983+ __supported_pte_mask |= _PAGE_NX;
33984+ rdmsr(MSR_EFER, l, h);
33985+ l |= EFER_NX;
33986+ wrmsr(MSR_EFER, l, h);
33987+ }
33988+#endif
33989
33990 xen_setup_features();
33991
33992@@ -1495,13 +1501,6 @@ asmlinkage void __init xen_start_kernel(void)
33993
33994 machine_ops = xen_machine_ops;
33995
33996- /*
33997- * The only reliable way to retain the initial address of the
33998- * percpu gdt_page is to remember it here, so we can go and
33999- * mark it RW later, when the initial percpu area is freed.
34000- */
34001- xen_initial_gdt = &per_cpu(gdt_page, 0);
34002-
34003 xen_smp_init();
34004
34005 #ifdef CONFIG_ACPI_NUMA
34006diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
34007index fdc3ba2..3daee39 100644
34008--- a/arch/x86/xen/mmu.c
34009+++ b/arch/x86/xen/mmu.c
34010@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34011 /* L3_k[510] -> level2_kernel_pgt
34012 * L3_i[511] -> level2_fixmap_pgt */
34013 convert_pfn_mfn(level3_kernel_pgt);
34014+ convert_pfn_mfn(level3_vmalloc_start_pgt);
34015+ convert_pfn_mfn(level3_vmalloc_end_pgt);
34016+ convert_pfn_mfn(level3_vmemmap_pgt);
34017
34018 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
34019 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
34020@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34021 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
34022 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
34023 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
34024+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
34025+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
34026+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
34027 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
34028 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
34029+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
34030 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
34031 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
34032
34033@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
34034 pv_mmu_ops.set_pud = xen_set_pud;
34035 #if PAGETABLE_LEVELS == 4
34036 pv_mmu_ops.set_pgd = xen_set_pgd;
34037+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
34038 #endif
34039
34040 /* This will work as long as patching hasn't happened yet
34041@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
34042 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
34043 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
34044 .set_pgd = xen_set_pgd_hyper,
34045+ .set_pgd_batched = xen_set_pgd_hyper,
34046
34047 .alloc_pud = xen_alloc_pmd_init,
34048 .release_pud = xen_release_pmd_init,
34049diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
34050index b81c88e..2cbe7b8 100644
34051--- a/arch/x86/xen/smp.c
34052+++ b/arch/x86/xen/smp.c
34053@@ -272,11 +272,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
34054 {
34055 BUG_ON(smp_processor_id() != 0);
34056 native_smp_prepare_boot_cpu();
34057-
34058- /* We've switched to the "real" per-cpu gdt, so make sure the
34059- old memory can be recycled */
34060- make_lowmem_page_readwrite(xen_initial_gdt);
34061-
34062 xen_filter_cpu_maps();
34063 xen_setup_vcpu_info_placement();
34064 }
34065@@ -346,7 +341,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34066 ctxt->user_regs.ss = __KERNEL_DS;
34067 #ifdef CONFIG_X86_32
34068 ctxt->user_regs.fs = __KERNEL_PERCPU;
34069- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
34070+ savesegment(gs, ctxt->user_regs.gs);
34071 #else
34072 ctxt->gs_base_kernel = per_cpu_offset(cpu);
34073 #endif
34074@@ -356,8 +351,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34075
34076 {
34077 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
34078- ctxt->user_regs.ds = __USER_DS;
34079- ctxt->user_regs.es = __USER_DS;
34080+ ctxt->user_regs.ds = __KERNEL_DS;
34081+ ctxt->user_regs.es = __KERNEL_DS;
34082
34083 xen_copy_trap_info(ctxt->trap_ctxt);
34084
34085@@ -402,13 +397,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
34086 int rc;
34087
34088 per_cpu(current_task, cpu) = idle;
34089+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
34090 #ifdef CONFIG_X86_32
34091 irq_ctx_init(cpu);
34092 #else
34093 clear_tsk_thread_flag(idle, TIF_FORK);
34094- per_cpu(kernel_stack, cpu) =
34095- (unsigned long)task_stack_page(idle) -
34096- KERNEL_STACK_OFFSET + THREAD_SIZE;
34097+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
34098 #endif
34099 xen_setup_runstate_info(cpu);
34100 xen_setup_timer(cpu);
34101@@ -678,7 +672,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
34102
34103 void __init xen_smp_init(void)
34104 {
34105- smp_ops = xen_smp_ops;
34106+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
34107 xen_fill_possible_map();
34108 xen_init_spinlocks();
34109 }
34110diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
34111index 33ca6e4..0ded929 100644
34112--- a/arch/x86/xen/xen-asm_32.S
34113+++ b/arch/x86/xen/xen-asm_32.S
34114@@ -84,14 +84,14 @@ ENTRY(xen_iret)
34115 ESP_OFFSET=4 # bytes pushed onto stack
34116
34117 /*
34118- * Store vcpu_info pointer for easy access. Do it this way to
34119- * avoid having to reload %fs
34120+ * Store vcpu_info pointer for easy access.
34121 */
34122 #ifdef CONFIG_SMP
34123- GET_THREAD_INFO(%eax)
34124- movl %ss:TI_cpu(%eax), %eax
34125- movl %ss:__per_cpu_offset(,%eax,4), %eax
34126- mov %ss:xen_vcpu(%eax), %eax
34127+ push %fs
34128+ mov $(__KERNEL_PERCPU), %eax
34129+ mov %eax, %fs
34130+ mov PER_CPU_VAR(xen_vcpu), %eax
34131+ pop %fs
34132 #else
34133 movl %ss:xen_vcpu, %eax
34134 #endif
34135diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
34136index 7faed58..ba4427c 100644
34137--- a/arch/x86/xen/xen-head.S
34138+++ b/arch/x86/xen/xen-head.S
34139@@ -19,6 +19,17 @@ ENTRY(startup_xen)
34140 #ifdef CONFIG_X86_32
34141 mov %esi,xen_start_info
34142 mov $init_thread_union+THREAD_SIZE,%esp
34143+#ifdef CONFIG_SMP
34144+ movl $cpu_gdt_table,%edi
34145+ movl $__per_cpu_load,%eax
34146+ movw %ax,__KERNEL_PERCPU + 2(%edi)
34147+ rorl $16,%eax
34148+ movb %al,__KERNEL_PERCPU + 4(%edi)
34149+ movb %ah,__KERNEL_PERCPU + 7(%edi)
34150+ movl $__per_cpu_end - 1,%eax
34151+ subl $__per_cpu_start,%eax
34152+ movw %ax,__KERNEL_PERCPU + 0(%edi)
34153+#endif
34154 #else
34155 mov %rsi,xen_start_info
34156 mov $init_thread_union+THREAD_SIZE,%rsp
34157diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
34158index 86782c5..fa272c8 100644
34159--- a/arch/x86/xen/xen-ops.h
34160+++ b/arch/x86/xen/xen-ops.h
34161@@ -10,8 +10,6 @@
34162 extern const char xen_hypervisor_callback[];
34163 extern const char xen_failsafe_callback[];
34164
34165-extern void *xen_initial_gdt;
34166-
34167 struct trap_info;
34168 void xen_copy_trap_info(struct trap_info *traps);
34169
34170diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
34171index 525bd3d..ef888b1 100644
34172--- a/arch/xtensa/variants/dc232b/include/variant/core.h
34173+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
34174@@ -119,9 +119,9 @@
34175 ----------------------------------------------------------------------*/
34176
34177 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
34178-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
34179 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
34180 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
34181+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34182
34183 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
34184 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
34185diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
34186index 2f33760..835e50a 100644
34187--- a/arch/xtensa/variants/fsf/include/variant/core.h
34188+++ b/arch/xtensa/variants/fsf/include/variant/core.h
34189@@ -11,6 +11,7 @@
34190 #ifndef _XTENSA_CORE_H
34191 #define _XTENSA_CORE_H
34192
34193+#include <linux/const.h>
34194
34195 /****************************************************************************
34196 Parameters Useful for Any Code, USER or PRIVILEGED
34197@@ -112,9 +113,9 @@
34198 ----------------------------------------------------------------------*/
34199
34200 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34201-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34202 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34203 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34204+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34205
34206 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
34207 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
34208diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
34209index af00795..2bb8105 100644
34210--- a/arch/xtensa/variants/s6000/include/variant/core.h
34211+++ b/arch/xtensa/variants/s6000/include/variant/core.h
34212@@ -11,6 +11,7 @@
34213 #ifndef _XTENSA_CORE_CONFIGURATION_H
34214 #define _XTENSA_CORE_CONFIGURATION_H
34215
34216+#include <linux/const.h>
34217
34218 /****************************************************************************
34219 Parameters Useful for Any Code, USER or PRIVILEGED
34220@@ -118,9 +119,9 @@
34221 ----------------------------------------------------------------------*/
34222
34223 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34224-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34225 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34226 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34227+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34228
34229 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
34230 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
34231diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
34232index 290792a..416f287 100644
34233--- a/block/blk-cgroup.c
34234+++ b/block/blk-cgroup.c
34235@@ -808,7 +808,7 @@ static void blkcg_css_free(struct cgroup *cgroup)
34236
34237 static struct cgroup_subsys_state *blkcg_css_alloc(struct cgroup *cgroup)
34238 {
34239- static atomic64_t id_seq = ATOMIC64_INIT(0);
34240+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
34241 struct blkcg *blkcg;
34242 struct cgroup *parent = cgroup->parent;
34243
34244@@ -823,7 +823,7 @@ static struct cgroup_subsys_state *blkcg_css_alloc(struct cgroup *cgroup)
34245
34246 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
34247 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
34248- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
34249+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
34250 done:
34251 spin_lock_init(&blkcg->lock);
34252 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
34253diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
34254index 4b8d9b54..ff76220 100644
34255--- a/block/blk-iopoll.c
34256+++ b/block/blk-iopoll.c
34257@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
34258 }
34259 EXPORT_SYMBOL(blk_iopoll_complete);
34260
34261-static void blk_iopoll_softirq(struct softirq_action *h)
34262+static void blk_iopoll_softirq(void)
34263 {
34264 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
34265 int rearm = 0, budget = blk_iopoll_budget;
34266diff --git a/block/blk-map.c b/block/blk-map.c
34267index 623e1cd..ca1e109 100644
34268--- a/block/blk-map.c
34269+++ b/block/blk-map.c
34270@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
34271 if (!len || !kbuf)
34272 return -EINVAL;
34273
34274- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
34275+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
34276 if (do_copy)
34277 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
34278 else
34279diff --git a/block/blk-softirq.c b/block/blk-softirq.c
34280index ec9e606..2244d4e 100644
34281--- a/block/blk-softirq.c
34282+++ b/block/blk-softirq.c
34283@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
34284 * Softirq action handler - move entries to local list and loop over them
34285 * while passing them to the queue registered handler.
34286 */
34287-static void blk_done_softirq(struct softirq_action *h)
34288+static void blk_done_softirq(void)
34289 {
34290 struct list_head *cpu_list, local_list;
34291
34292diff --git a/block/bsg.c b/block/bsg.c
34293index 420a5a9..23834aa 100644
34294--- a/block/bsg.c
34295+++ b/block/bsg.c
34296@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
34297 struct sg_io_v4 *hdr, struct bsg_device *bd,
34298 fmode_t has_write_perm)
34299 {
34300+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34301+ unsigned char *cmdptr;
34302+
34303 if (hdr->request_len > BLK_MAX_CDB) {
34304 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
34305 if (!rq->cmd)
34306 return -ENOMEM;
34307- }
34308+ cmdptr = rq->cmd;
34309+ } else
34310+ cmdptr = tmpcmd;
34311
34312- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
34313+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
34314 hdr->request_len))
34315 return -EFAULT;
34316
34317+ if (cmdptr != rq->cmd)
34318+ memcpy(rq->cmd, cmdptr, hdr->request_len);
34319+
34320 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
34321 if (blk_verify_command(rq->cmd, has_write_perm))
34322 return -EPERM;
34323diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
34324index 7e5d474..0cf0017 100644
34325--- a/block/compat_ioctl.c
34326+++ b/block/compat_ioctl.c
34327@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
34328 err |= __get_user(f->spec1, &uf->spec1);
34329 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
34330 err |= __get_user(name, &uf->name);
34331- f->name = compat_ptr(name);
34332+ f->name = (void __force_kernel *)compat_ptr(name);
34333 if (err) {
34334 err = -EFAULT;
34335 goto out;
34336diff --git a/block/genhd.c b/block/genhd.c
34337index dadf42b..48dc887 100644
34338--- a/block/genhd.c
34339+++ b/block/genhd.c
34340@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
34341
34342 /*
34343 * Register device numbers dev..(dev+range-1)
34344- * range must be nonzero
34345+ * Noop if @range is zero.
34346 * The hash chain is sorted on range, so that subranges can override.
34347 */
34348 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
34349 struct kobject *(*probe)(dev_t, int *, void *),
34350 int (*lock)(dev_t, void *), void *data)
34351 {
34352- kobj_map(bdev_map, devt, range, module, probe, lock, data);
34353+ if (range)
34354+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
34355 }
34356
34357 EXPORT_SYMBOL(blk_register_region);
34358
34359+/* undo blk_register_region(), noop if @range is zero */
34360 void blk_unregister_region(dev_t devt, unsigned long range)
34361 {
34362- kobj_unmap(bdev_map, devt, range);
34363+ if (range)
34364+ kobj_unmap(bdev_map, devt, range);
34365 }
34366
34367 EXPORT_SYMBOL(blk_unregister_region);
34368diff --git a/block/partitions/efi.c b/block/partitions/efi.c
34369index c85fc89..51e690b 100644
34370--- a/block/partitions/efi.c
34371+++ b/block/partitions/efi.c
34372@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
34373 if (!gpt)
34374 return NULL;
34375
34376+ if (!le32_to_cpu(gpt->num_partition_entries))
34377+ return NULL;
34378+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
34379+ if (!pte)
34380+ return NULL;
34381+
34382 count = le32_to_cpu(gpt->num_partition_entries) *
34383 le32_to_cpu(gpt->sizeof_partition_entry);
34384- if (!count)
34385- return NULL;
34386- pte = kmalloc(count, GFP_KERNEL);
34387- if (!pte)
34388- return NULL;
34389-
34390 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
34391 (u8 *) pte,
34392 count) < count) {
34393diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
34394index a5ffcc9..3cedc9c 100644
34395--- a/block/scsi_ioctl.c
34396+++ b/block/scsi_ioctl.c
34397@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
34398 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
34399 struct sg_io_hdr *hdr, fmode_t mode)
34400 {
34401- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
34402+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34403+ unsigned char *cmdptr;
34404+
34405+ if (rq->cmd != rq->__cmd)
34406+ cmdptr = rq->cmd;
34407+ else
34408+ cmdptr = tmpcmd;
34409+
34410+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
34411 return -EFAULT;
34412+
34413+ if (cmdptr != rq->cmd)
34414+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
34415+
34416 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
34417 return -EPERM;
34418
34419@@ -434,6 +446,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34420 int err;
34421 unsigned int in_len, out_len, bytes, opcode, cmdlen;
34422 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
34423+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34424+ unsigned char *cmdptr;
34425
34426 if (!sic)
34427 return -EINVAL;
34428@@ -467,9 +481,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34429 */
34430 err = -EFAULT;
34431 rq->cmd_len = cmdlen;
34432- if (copy_from_user(rq->cmd, sic->data, cmdlen))
34433+
34434+ if (rq->cmd != rq->__cmd)
34435+ cmdptr = rq->cmd;
34436+ else
34437+ cmdptr = tmpcmd;
34438+
34439+ if (copy_from_user(cmdptr, sic->data, cmdlen))
34440 goto error;
34441
34442+ if (rq->cmd != cmdptr)
34443+ memcpy(rq->cmd, cmdptr, cmdlen);
34444+
34445 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
34446 goto error;
34447
34448diff --git a/crypto/api.c b/crypto/api.c
34449index 3b61803..37c4c72 100644
34450--- a/crypto/api.c
34451+++ b/crypto/api.c
34452@@ -34,6 +34,8 @@ EXPORT_SYMBOL_GPL(crypto_alg_sem);
34453 BLOCKING_NOTIFIER_HEAD(crypto_chain);
34454 EXPORT_SYMBOL_GPL(crypto_chain);
34455
34456+static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg);
34457+
34458 struct crypto_alg *crypto_mod_get(struct crypto_alg *alg)
34459 {
34460 return try_module_get(alg->cra_module) ? crypto_alg_get(alg) : NULL;
34461@@ -144,8 +146,11 @@ static struct crypto_alg *crypto_larval_add(const char *name, u32 type,
34462 }
34463 up_write(&crypto_alg_sem);
34464
34465- if (alg != &larval->alg)
34466+ if (alg != &larval->alg) {
34467 kfree(larval);
34468+ if (crypto_is_larval(alg))
34469+ alg = crypto_larval_wait(alg);
34470+ }
34471
34472 return alg;
34473 }
34474diff --git a/crypto/cryptd.c b/crypto/cryptd.c
34475index 7bdd61b..afec999 100644
34476--- a/crypto/cryptd.c
34477+++ b/crypto/cryptd.c
34478@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
34479
34480 struct cryptd_blkcipher_request_ctx {
34481 crypto_completion_t complete;
34482-};
34483+} __no_const;
34484
34485 struct cryptd_hash_ctx {
34486 struct crypto_shash *child;
34487@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
34488
34489 struct cryptd_aead_request_ctx {
34490 crypto_completion_t complete;
34491-};
34492+} __no_const;
34493
34494 static void cryptd_queue_worker(struct work_struct *work);
34495
34496diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
34497index f8c920c..ab2cb5a 100644
34498--- a/crypto/pcrypt.c
34499+++ b/crypto/pcrypt.c
34500@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
34501 int ret;
34502
34503 pinst->kobj.kset = pcrypt_kset;
34504- ret = kobject_add(&pinst->kobj, NULL, name);
34505+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
34506 if (!ret)
34507 kobject_uevent(&pinst->kobj, KOBJ_ADD);
34508
34509diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
34510index f220d64..d359ad6 100644
34511--- a/drivers/acpi/apei/apei-internal.h
34512+++ b/drivers/acpi/apei/apei-internal.h
34513@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
34514 struct apei_exec_ins_type {
34515 u32 flags;
34516 apei_exec_ins_func_t run;
34517-};
34518+} __do_const;
34519
34520 struct apei_exec_context {
34521 u32 ip;
34522diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
34523index 33dc6a0..4b24b47 100644
34524--- a/drivers/acpi/apei/cper.c
34525+++ b/drivers/acpi/apei/cper.c
34526@@ -39,12 +39,12 @@
34527 */
34528 u64 cper_next_record_id(void)
34529 {
34530- static atomic64_t seq;
34531+ static atomic64_unchecked_t seq;
34532
34533- if (!atomic64_read(&seq))
34534- atomic64_set(&seq, ((u64)get_seconds()) << 32);
34535+ if (!atomic64_read_unchecked(&seq))
34536+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
34537
34538- return atomic64_inc_return(&seq);
34539+ return atomic64_inc_return_unchecked(&seq);
34540 }
34541 EXPORT_SYMBOL_GPL(cper_next_record_id);
34542
34543diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
34544index ec9b57d..9682b3a 100644
34545--- a/drivers/acpi/apei/ghes.c
34546+++ b/drivers/acpi/apei/ghes.c
34547@@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
34548 const struct acpi_hest_generic *generic,
34549 const struct acpi_hest_generic_status *estatus)
34550 {
34551- static atomic_t seqno;
34552+ static atomic_unchecked_t seqno;
34553 unsigned int curr_seqno;
34554 char pfx_seq[64];
34555
34556@@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
34557 else
34558 pfx = KERN_ERR;
34559 }
34560- curr_seqno = atomic_inc_return(&seqno);
34561+ curr_seqno = atomic_inc_return_unchecked(&seqno);
34562 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
34563 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
34564 pfx_seq, generic->header.source_id);
34565diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
34566index be60399..778b33e8 100644
34567--- a/drivers/acpi/bgrt.c
34568+++ b/drivers/acpi/bgrt.c
34569@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
34570 return -ENODEV;
34571
34572 sysfs_bin_attr_init(&image_attr);
34573- image_attr.private = bgrt_image;
34574- image_attr.size = bgrt_image_size;
34575+ pax_open_kernel();
34576+ *(void **)&image_attr.private = bgrt_image;
34577+ *(size_t *)&image_attr.size = bgrt_image_size;
34578+ pax_close_kernel();
34579
34580 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
34581 if (!bgrt_kobj)
34582diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
34583index cb96296..b81293b 100644
34584--- a/drivers/acpi/blacklist.c
34585+++ b/drivers/acpi/blacklist.c
34586@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
34587 u32 is_critical_error;
34588 };
34589
34590-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
34591+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
34592
34593 /*
34594 * POLICY: If *anything* doesn't work, put it on the blacklist.
34595@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
34596 return 0;
34597 }
34598
34599-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
34600+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
34601 {
34602 .callback = dmi_disable_osi_vista,
34603 .ident = "Fujitsu Siemens",
34604diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
34605index f98dd00..7b69865 100644
34606--- a/drivers/acpi/processor_idle.c
34607+++ b/drivers/acpi/processor_idle.c
34608@@ -992,7 +992,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
34609 {
34610 int i, count = CPUIDLE_DRIVER_STATE_START;
34611 struct acpi_processor_cx *cx;
34612- struct cpuidle_state *state;
34613+ cpuidle_state_no_const *state;
34614 struct cpuidle_driver *drv = &acpi_idle_driver;
34615
34616 if (!pr->flags.power_setup_done)
34617diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
34618index 05306a5..733d1f0 100644
34619--- a/drivers/acpi/sysfs.c
34620+++ b/drivers/acpi/sysfs.c
34621@@ -423,11 +423,11 @@ static u32 num_counters;
34622 static struct attribute **all_attrs;
34623 static u32 acpi_gpe_count;
34624
34625-static struct attribute_group interrupt_stats_attr_group = {
34626+static attribute_group_no_const interrupt_stats_attr_group = {
34627 .name = "interrupts",
34628 };
34629
34630-static struct kobj_attribute *counter_attrs;
34631+static kobj_attribute_no_const *counter_attrs;
34632
34633 static void delete_gpe_attr_array(void)
34634 {
34635diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
34636index acfd0f7..e5acb08 100644
34637--- a/drivers/ata/libahci.c
34638+++ b/drivers/ata/libahci.c
34639@@ -1231,7 +1231,7 @@ int ahci_kick_engine(struct ata_port *ap)
34640 }
34641 EXPORT_SYMBOL_GPL(ahci_kick_engine);
34642
34643-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34644+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34645 struct ata_taskfile *tf, int is_cmd, u16 flags,
34646 unsigned long timeout_msec)
34647 {
34648diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
34649index c24354d..335c975 100644
34650--- a/drivers/ata/libata-core.c
34651+++ b/drivers/ata/libata-core.c
34652@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
34653 static void ata_dev_xfermask(struct ata_device *dev);
34654 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
34655
34656-atomic_t ata_print_id = ATOMIC_INIT(0);
34657+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
34658
34659 struct ata_force_param {
34660 const char *name;
34661@@ -4792,7 +4792,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
34662 struct ata_port *ap;
34663 unsigned int tag;
34664
34665- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34666+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34667 ap = qc->ap;
34668
34669 qc->flags = 0;
34670@@ -4808,7 +4808,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
34671 struct ata_port *ap;
34672 struct ata_link *link;
34673
34674- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34675+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34676 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
34677 ap = qc->ap;
34678 link = qc->dev->link;
34679@@ -5927,6 +5927,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34680 return;
34681
34682 spin_lock(&lock);
34683+ pax_open_kernel();
34684
34685 for (cur = ops->inherits; cur; cur = cur->inherits) {
34686 void **inherit = (void **)cur;
34687@@ -5940,8 +5941,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34688 if (IS_ERR(*pp))
34689 *pp = NULL;
34690
34691- ops->inherits = NULL;
34692+ *(struct ata_port_operations **)&ops->inherits = NULL;
34693
34694+ pax_close_kernel();
34695 spin_unlock(&lock);
34696 }
34697
34698@@ -6134,7 +6136,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
34699
34700 /* give ports names and add SCSI hosts */
34701 for (i = 0; i < host->n_ports; i++) {
34702- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
34703+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
34704 host->ports[i]->local_port_no = i + 1;
34705 }
34706
34707diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
34708index b1e880a..8cf82e1 100644
34709--- a/drivers/ata/libata-scsi.c
34710+++ b/drivers/ata/libata-scsi.c
34711@@ -4104,7 +4104,7 @@ int ata_sas_port_init(struct ata_port *ap)
34712
34713 if (rc)
34714 return rc;
34715- ap->print_id = atomic_inc_return(&ata_print_id);
34716+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
34717 return 0;
34718 }
34719 EXPORT_SYMBOL_GPL(ata_sas_port_init);
34720diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
34721index 577d902b..cb4781e 100644
34722--- a/drivers/ata/libata.h
34723+++ b/drivers/ata/libata.h
34724@@ -53,7 +53,7 @@ enum {
34725 ATA_DNXFER_QUIET = (1 << 31),
34726 };
34727
34728-extern atomic_t ata_print_id;
34729+extern atomic_unchecked_t ata_print_id;
34730 extern int atapi_passthru16;
34731 extern int libata_fua;
34732 extern int libata_noacpi;
34733diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
34734index 848ed32..132f39d 100644
34735--- a/drivers/ata/pata_arasan_cf.c
34736+++ b/drivers/ata/pata_arasan_cf.c
34737@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
34738 /* Handle platform specific quirks */
34739 if (quirk) {
34740 if (quirk & CF_BROKEN_PIO) {
34741- ap->ops->set_piomode = NULL;
34742+ pax_open_kernel();
34743+ *(void **)&ap->ops->set_piomode = NULL;
34744+ pax_close_kernel();
34745 ap->pio_mask = 0;
34746 }
34747 if (quirk & CF_BROKEN_MWDMA)
34748diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
34749index f9b983a..887b9d8 100644
34750--- a/drivers/atm/adummy.c
34751+++ b/drivers/atm/adummy.c
34752@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
34753 vcc->pop(vcc, skb);
34754 else
34755 dev_kfree_skb_any(skb);
34756- atomic_inc(&vcc->stats->tx);
34757+ atomic_inc_unchecked(&vcc->stats->tx);
34758
34759 return 0;
34760 }
34761diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
34762index 62a7607..cc4be104 100644
34763--- a/drivers/atm/ambassador.c
34764+++ b/drivers/atm/ambassador.c
34765@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
34766 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
34767
34768 // VC layer stats
34769- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34770+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34771
34772 // free the descriptor
34773 kfree (tx_descr);
34774@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34775 dump_skb ("<<<", vc, skb);
34776
34777 // VC layer stats
34778- atomic_inc(&atm_vcc->stats->rx);
34779+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34780 __net_timestamp(skb);
34781 // end of our responsibility
34782 atm_vcc->push (atm_vcc, skb);
34783@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34784 } else {
34785 PRINTK (KERN_INFO, "dropped over-size frame");
34786 // should we count this?
34787- atomic_inc(&atm_vcc->stats->rx_drop);
34788+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34789 }
34790
34791 } else {
34792@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
34793 }
34794
34795 if (check_area (skb->data, skb->len)) {
34796- atomic_inc(&atm_vcc->stats->tx_err);
34797+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
34798 return -ENOMEM; // ?
34799 }
34800
34801diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
34802index 0e3f8f9..765a7a5 100644
34803--- a/drivers/atm/atmtcp.c
34804+++ b/drivers/atm/atmtcp.c
34805@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34806 if (vcc->pop) vcc->pop(vcc,skb);
34807 else dev_kfree_skb(skb);
34808 if (dev_data) return 0;
34809- atomic_inc(&vcc->stats->tx_err);
34810+ atomic_inc_unchecked(&vcc->stats->tx_err);
34811 return -ENOLINK;
34812 }
34813 size = skb->len+sizeof(struct atmtcp_hdr);
34814@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34815 if (!new_skb) {
34816 if (vcc->pop) vcc->pop(vcc,skb);
34817 else dev_kfree_skb(skb);
34818- atomic_inc(&vcc->stats->tx_err);
34819+ atomic_inc_unchecked(&vcc->stats->tx_err);
34820 return -ENOBUFS;
34821 }
34822 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
34823@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34824 if (vcc->pop) vcc->pop(vcc,skb);
34825 else dev_kfree_skb(skb);
34826 out_vcc->push(out_vcc,new_skb);
34827- atomic_inc(&vcc->stats->tx);
34828- atomic_inc(&out_vcc->stats->rx);
34829+ atomic_inc_unchecked(&vcc->stats->tx);
34830+ atomic_inc_unchecked(&out_vcc->stats->rx);
34831 return 0;
34832 }
34833
34834@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34835 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
34836 read_unlock(&vcc_sklist_lock);
34837 if (!out_vcc) {
34838- atomic_inc(&vcc->stats->tx_err);
34839+ atomic_inc_unchecked(&vcc->stats->tx_err);
34840 goto done;
34841 }
34842 skb_pull(skb,sizeof(struct atmtcp_hdr));
34843@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34844 __net_timestamp(new_skb);
34845 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
34846 out_vcc->push(out_vcc,new_skb);
34847- atomic_inc(&vcc->stats->tx);
34848- atomic_inc(&out_vcc->stats->rx);
34849+ atomic_inc_unchecked(&vcc->stats->tx);
34850+ atomic_inc_unchecked(&out_vcc->stats->rx);
34851 done:
34852 if (vcc->pop) vcc->pop(vcc,skb);
34853 else dev_kfree_skb(skb);
34854diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
34855index b1955ba..b179940 100644
34856--- a/drivers/atm/eni.c
34857+++ b/drivers/atm/eni.c
34858@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
34859 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
34860 vcc->dev->number);
34861 length = 0;
34862- atomic_inc(&vcc->stats->rx_err);
34863+ atomic_inc_unchecked(&vcc->stats->rx_err);
34864 }
34865 else {
34866 length = ATM_CELL_SIZE-1; /* no HEC */
34867@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34868 size);
34869 }
34870 eff = length = 0;
34871- atomic_inc(&vcc->stats->rx_err);
34872+ atomic_inc_unchecked(&vcc->stats->rx_err);
34873 }
34874 else {
34875 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
34876@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34877 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
34878 vcc->dev->number,vcc->vci,length,size << 2,descr);
34879 length = eff = 0;
34880- atomic_inc(&vcc->stats->rx_err);
34881+ atomic_inc_unchecked(&vcc->stats->rx_err);
34882 }
34883 }
34884 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
34885@@ -767,7 +767,7 @@ rx_dequeued++;
34886 vcc->push(vcc,skb);
34887 pushed++;
34888 }
34889- atomic_inc(&vcc->stats->rx);
34890+ atomic_inc_unchecked(&vcc->stats->rx);
34891 }
34892 wake_up(&eni_dev->rx_wait);
34893 }
34894@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
34895 PCI_DMA_TODEVICE);
34896 if (vcc->pop) vcc->pop(vcc,skb);
34897 else dev_kfree_skb_irq(skb);
34898- atomic_inc(&vcc->stats->tx);
34899+ atomic_inc_unchecked(&vcc->stats->tx);
34900 wake_up(&eni_dev->tx_wait);
34901 dma_complete++;
34902 }
34903diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
34904index b41c948..a002b17 100644
34905--- a/drivers/atm/firestream.c
34906+++ b/drivers/atm/firestream.c
34907@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
34908 }
34909 }
34910
34911- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34912+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34913
34914 fs_dprintk (FS_DEBUG_TXMEM, "i");
34915 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
34916@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
34917 #endif
34918 skb_put (skb, qe->p1 & 0xffff);
34919 ATM_SKB(skb)->vcc = atm_vcc;
34920- atomic_inc(&atm_vcc->stats->rx);
34921+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34922 __net_timestamp(skb);
34923 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
34924 atm_vcc->push (atm_vcc, skb);
34925@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
34926 kfree (pe);
34927 }
34928 if (atm_vcc)
34929- atomic_inc(&atm_vcc->stats->rx_drop);
34930+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34931 break;
34932 case 0x1f: /* Reassembly abort: no buffers. */
34933 /* Silently increment error counter. */
34934 if (atm_vcc)
34935- atomic_inc(&atm_vcc->stats->rx_drop);
34936+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34937 break;
34938 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
34939 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
34940diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
34941index 204814e..cede831 100644
34942--- a/drivers/atm/fore200e.c
34943+++ b/drivers/atm/fore200e.c
34944@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
34945 #endif
34946 /* check error condition */
34947 if (*entry->status & STATUS_ERROR)
34948- atomic_inc(&vcc->stats->tx_err);
34949+ atomic_inc_unchecked(&vcc->stats->tx_err);
34950 else
34951- atomic_inc(&vcc->stats->tx);
34952+ atomic_inc_unchecked(&vcc->stats->tx);
34953 }
34954 }
34955
34956@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
34957 if (skb == NULL) {
34958 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
34959
34960- atomic_inc(&vcc->stats->rx_drop);
34961+ atomic_inc_unchecked(&vcc->stats->rx_drop);
34962 return -ENOMEM;
34963 }
34964
34965@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
34966
34967 dev_kfree_skb_any(skb);
34968
34969- atomic_inc(&vcc->stats->rx_drop);
34970+ atomic_inc_unchecked(&vcc->stats->rx_drop);
34971 return -ENOMEM;
34972 }
34973
34974 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
34975
34976 vcc->push(vcc, skb);
34977- atomic_inc(&vcc->stats->rx);
34978+ atomic_inc_unchecked(&vcc->stats->rx);
34979
34980 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
34981
34982@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
34983 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
34984 fore200e->atm_dev->number,
34985 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
34986- atomic_inc(&vcc->stats->rx_err);
34987+ atomic_inc_unchecked(&vcc->stats->rx_err);
34988 }
34989 }
34990
34991@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
34992 goto retry_here;
34993 }
34994
34995- atomic_inc(&vcc->stats->tx_err);
34996+ atomic_inc_unchecked(&vcc->stats->tx_err);
34997
34998 fore200e->tx_sat++;
34999 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
35000diff --git a/drivers/atm/he.c b/drivers/atm/he.c
35001index 507362a..a845e57 100644
35002--- a/drivers/atm/he.c
35003+++ b/drivers/atm/he.c
35004@@ -1698,7 +1698,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35005
35006 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
35007 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
35008- atomic_inc(&vcc->stats->rx_drop);
35009+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35010 goto return_host_buffers;
35011 }
35012
35013@@ -1725,7 +1725,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35014 RBRQ_LEN_ERR(he_dev->rbrq_head)
35015 ? "LEN_ERR" : "",
35016 vcc->vpi, vcc->vci);
35017- atomic_inc(&vcc->stats->rx_err);
35018+ atomic_inc_unchecked(&vcc->stats->rx_err);
35019 goto return_host_buffers;
35020 }
35021
35022@@ -1777,7 +1777,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35023 vcc->push(vcc, skb);
35024 spin_lock(&he_dev->global_lock);
35025
35026- atomic_inc(&vcc->stats->rx);
35027+ atomic_inc_unchecked(&vcc->stats->rx);
35028
35029 return_host_buffers:
35030 ++pdus_assembled;
35031@@ -2103,7 +2103,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
35032 tpd->vcc->pop(tpd->vcc, tpd->skb);
35033 else
35034 dev_kfree_skb_any(tpd->skb);
35035- atomic_inc(&tpd->vcc->stats->tx_err);
35036+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
35037 }
35038 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
35039 return;
35040@@ -2515,7 +2515,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35041 vcc->pop(vcc, skb);
35042 else
35043 dev_kfree_skb_any(skb);
35044- atomic_inc(&vcc->stats->tx_err);
35045+ atomic_inc_unchecked(&vcc->stats->tx_err);
35046 return -EINVAL;
35047 }
35048
35049@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35050 vcc->pop(vcc, skb);
35051 else
35052 dev_kfree_skb_any(skb);
35053- atomic_inc(&vcc->stats->tx_err);
35054+ atomic_inc_unchecked(&vcc->stats->tx_err);
35055 return -EINVAL;
35056 }
35057 #endif
35058@@ -2538,7 +2538,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35059 vcc->pop(vcc, skb);
35060 else
35061 dev_kfree_skb_any(skb);
35062- atomic_inc(&vcc->stats->tx_err);
35063+ atomic_inc_unchecked(&vcc->stats->tx_err);
35064 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35065 return -ENOMEM;
35066 }
35067@@ -2580,7 +2580,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35068 vcc->pop(vcc, skb);
35069 else
35070 dev_kfree_skb_any(skb);
35071- atomic_inc(&vcc->stats->tx_err);
35072+ atomic_inc_unchecked(&vcc->stats->tx_err);
35073 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35074 return -ENOMEM;
35075 }
35076@@ -2611,7 +2611,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35077 __enqueue_tpd(he_dev, tpd, cid);
35078 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35079
35080- atomic_inc(&vcc->stats->tx);
35081+ atomic_inc_unchecked(&vcc->stats->tx);
35082
35083 return 0;
35084 }
35085diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
35086index 1dc0519..1aadaf7 100644
35087--- a/drivers/atm/horizon.c
35088+++ b/drivers/atm/horizon.c
35089@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
35090 {
35091 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
35092 // VC layer stats
35093- atomic_inc(&vcc->stats->rx);
35094+ atomic_inc_unchecked(&vcc->stats->rx);
35095 __net_timestamp(skb);
35096 // end of our responsibility
35097 vcc->push (vcc, skb);
35098@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
35099 dev->tx_iovec = NULL;
35100
35101 // VC layer stats
35102- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35103+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35104
35105 // free the skb
35106 hrz_kfree_skb (skb);
35107diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
35108index 272f009..a18ba55 100644
35109--- a/drivers/atm/idt77252.c
35110+++ b/drivers/atm/idt77252.c
35111@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
35112 else
35113 dev_kfree_skb(skb);
35114
35115- atomic_inc(&vcc->stats->tx);
35116+ atomic_inc_unchecked(&vcc->stats->tx);
35117 }
35118
35119 atomic_dec(&scq->used);
35120@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35121 if ((sb = dev_alloc_skb(64)) == NULL) {
35122 printk("%s: Can't allocate buffers for aal0.\n",
35123 card->name);
35124- atomic_add(i, &vcc->stats->rx_drop);
35125+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35126 break;
35127 }
35128 if (!atm_charge(vcc, sb->truesize)) {
35129 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
35130 card->name);
35131- atomic_add(i - 1, &vcc->stats->rx_drop);
35132+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
35133 dev_kfree_skb(sb);
35134 break;
35135 }
35136@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35137 ATM_SKB(sb)->vcc = vcc;
35138 __net_timestamp(sb);
35139 vcc->push(vcc, sb);
35140- atomic_inc(&vcc->stats->rx);
35141+ atomic_inc_unchecked(&vcc->stats->rx);
35142
35143 cell += ATM_CELL_PAYLOAD;
35144 }
35145@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35146 "(CDC: %08x)\n",
35147 card->name, len, rpp->len, readl(SAR_REG_CDC));
35148 recycle_rx_pool_skb(card, rpp);
35149- atomic_inc(&vcc->stats->rx_err);
35150+ atomic_inc_unchecked(&vcc->stats->rx_err);
35151 return;
35152 }
35153 if (stat & SAR_RSQE_CRC) {
35154 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
35155 recycle_rx_pool_skb(card, rpp);
35156- atomic_inc(&vcc->stats->rx_err);
35157+ atomic_inc_unchecked(&vcc->stats->rx_err);
35158 return;
35159 }
35160 if (skb_queue_len(&rpp->queue) > 1) {
35161@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35162 RXPRINTK("%s: Can't alloc RX skb.\n",
35163 card->name);
35164 recycle_rx_pool_skb(card, rpp);
35165- atomic_inc(&vcc->stats->rx_err);
35166+ atomic_inc_unchecked(&vcc->stats->rx_err);
35167 return;
35168 }
35169 if (!atm_charge(vcc, skb->truesize)) {
35170@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35171 __net_timestamp(skb);
35172
35173 vcc->push(vcc, skb);
35174- atomic_inc(&vcc->stats->rx);
35175+ atomic_inc_unchecked(&vcc->stats->rx);
35176
35177 return;
35178 }
35179@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35180 __net_timestamp(skb);
35181
35182 vcc->push(vcc, skb);
35183- atomic_inc(&vcc->stats->rx);
35184+ atomic_inc_unchecked(&vcc->stats->rx);
35185
35186 if (skb->truesize > SAR_FB_SIZE_3)
35187 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
35188@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
35189 if (vcc->qos.aal != ATM_AAL0) {
35190 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
35191 card->name, vpi, vci);
35192- atomic_inc(&vcc->stats->rx_drop);
35193+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35194 goto drop;
35195 }
35196
35197 if ((sb = dev_alloc_skb(64)) == NULL) {
35198 printk("%s: Can't allocate buffers for AAL0.\n",
35199 card->name);
35200- atomic_inc(&vcc->stats->rx_err);
35201+ atomic_inc_unchecked(&vcc->stats->rx_err);
35202 goto drop;
35203 }
35204
35205@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
35206 ATM_SKB(sb)->vcc = vcc;
35207 __net_timestamp(sb);
35208 vcc->push(vcc, sb);
35209- atomic_inc(&vcc->stats->rx);
35210+ atomic_inc_unchecked(&vcc->stats->rx);
35211
35212 drop:
35213 skb_pull(queue, 64);
35214@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35215
35216 if (vc == NULL) {
35217 printk("%s: NULL connection in send().\n", card->name);
35218- atomic_inc(&vcc->stats->tx_err);
35219+ atomic_inc_unchecked(&vcc->stats->tx_err);
35220 dev_kfree_skb(skb);
35221 return -EINVAL;
35222 }
35223 if (!test_bit(VCF_TX, &vc->flags)) {
35224 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
35225- atomic_inc(&vcc->stats->tx_err);
35226+ atomic_inc_unchecked(&vcc->stats->tx_err);
35227 dev_kfree_skb(skb);
35228 return -EINVAL;
35229 }
35230@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35231 break;
35232 default:
35233 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
35234- atomic_inc(&vcc->stats->tx_err);
35235+ atomic_inc_unchecked(&vcc->stats->tx_err);
35236 dev_kfree_skb(skb);
35237 return -EINVAL;
35238 }
35239
35240 if (skb_shinfo(skb)->nr_frags != 0) {
35241 printk("%s: No scatter-gather yet.\n", card->name);
35242- atomic_inc(&vcc->stats->tx_err);
35243+ atomic_inc_unchecked(&vcc->stats->tx_err);
35244 dev_kfree_skb(skb);
35245 return -EINVAL;
35246 }
35247@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35248
35249 err = queue_skb(card, vc, skb, oam);
35250 if (err) {
35251- atomic_inc(&vcc->stats->tx_err);
35252+ atomic_inc_unchecked(&vcc->stats->tx_err);
35253 dev_kfree_skb(skb);
35254 return err;
35255 }
35256@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
35257 skb = dev_alloc_skb(64);
35258 if (!skb) {
35259 printk("%s: Out of memory in send_oam().\n", card->name);
35260- atomic_inc(&vcc->stats->tx_err);
35261+ atomic_inc_unchecked(&vcc->stats->tx_err);
35262 return -ENOMEM;
35263 }
35264 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
35265diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
35266index 4217f29..88f547a 100644
35267--- a/drivers/atm/iphase.c
35268+++ b/drivers/atm/iphase.c
35269@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
35270 status = (u_short) (buf_desc_ptr->desc_mode);
35271 if (status & (RX_CER | RX_PTE | RX_OFL))
35272 {
35273- atomic_inc(&vcc->stats->rx_err);
35274+ atomic_inc_unchecked(&vcc->stats->rx_err);
35275 IF_ERR(printk("IA: bad packet, dropping it");)
35276 if (status & RX_CER) {
35277 IF_ERR(printk(" cause: packet CRC error\n");)
35278@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
35279 len = dma_addr - buf_addr;
35280 if (len > iadev->rx_buf_sz) {
35281 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
35282- atomic_inc(&vcc->stats->rx_err);
35283+ atomic_inc_unchecked(&vcc->stats->rx_err);
35284 goto out_free_desc;
35285 }
35286
35287@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35288 ia_vcc = INPH_IA_VCC(vcc);
35289 if (ia_vcc == NULL)
35290 {
35291- atomic_inc(&vcc->stats->rx_err);
35292+ atomic_inc_unchecked(&vcc->stats->rx_err);
35293 atm_return(vcc, skb->truesize);
35294 dev_kfree_skb_any(skb);
35295 goto INCR_DLE;
35296@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35297 if ((length > iadev->rx_buf_sz) || (length >
35298 (skb->len - sizeof(struct cpcs_trailer))))
35299 {
35300- atomic_inc(&vcc->stats->rx_err);
35301+ atomic_inc_unchecked(&vcc->stats->rx_err);
35302 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
35303 length, skb->len);)
35304 atm_return(vcc, skb->truesize);
35305@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35306
35307 IF_RX(printk("rx_dle_intr: skb push");)
35308 vcc->push(vcc,skb);
35309- atomic_inc(&vcc->stats->rx);
35310+ atomic_inc_unchecked(&vcc->stats->rx);
35311 iadev->rx_pkt_cnt++;
35312 }
35313 INCR_DLE:
35314@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
35315 {
35316 struct k_sonet_stats *stats;
35317 stats = &PRIV(_ia_dev[board])->sonet_stats;
35318- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
35319- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
35320- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
35321- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
35322- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
35323- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
35324- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
35325- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
35326- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
35327+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
35328+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
35329+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
35330+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
35331+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
35332+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
35333+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
35334+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
35335+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
35336 }
35337 ia_cmds.status = 0;
35338 break;
35339@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35340 if ((desc == 0) || (desc > iadev->num_tx_desc))
35341 {
35342 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
35343- atomic_inc(&vcc->stats->tx);
35344+ atomic_inc_unchecked(&vcc->stats->tx);
35345 if (vcc->pop)
35346 vcc->pop(vcc, skb);
35347 else
35348@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35349 ATM_DESC(skb) = vcc->vci;
35350 skb_queue_tail(&iadev->tx_dma_q, skb);
35351
35352- atomic_inc(&vcc->stats->tx);
35353+ atomic_inc_unchecked(&vcc->stats->tx);
35354 iadev->tx_pkt_cnt++;
35355 /* Increment transaction counter */
35356 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
35357
35358 #if 0
35359 /* add flow control logic */
35360- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
35361+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
35362 if (iavcc->vc_desc_cnt > 10) {
35363 vcc->tx_quota = vcc->tx_quota * 3 / 4;
35364 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
35365diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
35366index fa7d701..1e404c7 100644
35367--- a/drivers/atm/lanai.c
35368+++ b/drivers/atm/lanai.c
35369@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
35370 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
35371 lanai_endtx(lanai, lvcc);
35372 lanai_free_skb(lvcc->tx.atmvcc, skb);
35373- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
35374+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
35375 }
35376
35377 /* Try to fill the buffer - don't call unless there is backlog */
35378@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
35379 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
35380 __net_timestamp(skb);
35381 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
35382- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
35383+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
35384 out:
35385 lvcc->rx.buf.ptr = end;
35386 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
35387@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35388 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
35389 "vcc %d\n", lanai->number, (unsigned int) s, vci);
35390 lanai->stats.service_rxnotaal5++;
35391- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35392+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35393 return 0;
35394 }
35395 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
35396@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35397 int bytes;
35398 read_unlock(&vcc_sklist_lock);
35399 DPRINTK("got trashed rx pdu on vci %d\n", vci);
35400- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35401+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35402 lvcc->stats.x.aal5.service_trash++;
35403 bytes = (SERVICE_GET_END(s) * 16) -
35404 (((unsigned long) lvcc->rx.buf.ptr) -
35405@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35406 }
35407 if (s & SERVICE_STREAM) {
35408 read_unlock(&vcc_sklist_lock);
35409- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35410+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35411 lvcc->stats.x.aal5.service_stream++;
35412 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
35413 "PDU on VCI %d!\n", lanai->number, vci);
35414@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35415 return 0;
35416 }
35417 DPRINTK("got rx crc error on vci %d\n", vci);
35418- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35419+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35420 lvcc->stats.x.aal5.service_rxcrc++;
35421 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
35422 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
35423diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
35424index 6587dc2..149833d 100644
35425--- a/drivers/atm/nicstar.c
35426+++ b/drivers/atm/nicstar.c
35427@@ -1641,7 +1641,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35428 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
35429 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
35430 card->index);
35431- atomic_inc(&vcc->stats->tx_err);
35432+ atomic_inc_unchecked(&vcc->stats->tx_err);
35433 dev_kfree_skb_any(skb);
35434 return -EINVAL;
35435 }
35436@@ -1649,7 +1649,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35437 if (!vc->tx) {
35438 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
35439 card->index);
35440- atomic_inc(&vcc->stats->tx_err);
35441+ atomic_inc_unchecked(&vcc->stats->tx_err);
35442 dev_kfree_skb_any(skb);
35443 return -EINVAL;
35444 }
35445@@ -1657,14 +1657,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35446 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
35447 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
35448 card->index);
35449- atomic_inc(&vcc->stats->tx_err);
35450+ atomic_inc_unchecked(&vcc->stats->tx_err);
35451 dev_kfree_skb_any(skb);
35452 return -EINVAL;
35453 }
35454
35455 if (skb_shinfo(skb)->nr_frags != 0) {
35456 printk("nicstar%d: No scatter-gather yet.\n", card->index);
35457- atomic_inc(&vcc->stats->tx_err);
35458+ atomic_inc_unchecked(&vcc->stats->tx_err);
35459 dev_kfree_skb_any(skb);
35460 return -EINVAL;
35461 }
35462@@ -1712,11 +1712,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35463 }
35464
35465 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
35466- atomic_inc(&vcc->stats->tx_err);
35467+ atomic_inc_unchecked(&vcc->stats->tx_err);
35468 dev_kfree_skb_any(skb);
35469 return -EIO;
35470 }
35471- atomic_inc(&vcc->stats->tx);
35472+ atomic_inc_unchecked(&vcc->stats->tx);
35473
35474 return 0;
35475 }
35476@@ -2033,14 +2033,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35477 printk
35478 ("nicstar%d: Can't allocate buffers for aal0.\n",
35479 card->index);
35480- atomic_add(i, &vcc->stats->rx_drop);
35481+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35482 break;
35483 }
35484 if (!atm_charge(vcc, sb->truesize)) {
35485 RXPRINTK
35486 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
35487 card->index);
35488- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35489+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35490 dev_kfree_skb_any(sb);
35491 break;
35492 }
35493@@ -2055,7 +2055,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35494 ATM_SKB(sb)->vcc = vcc;
35495 __net_timestamp(sb);
35496 vcc->push(vcc, sb);
35497- atomic_inc(&vcc->stats->rx);
35498+ atomic_inc_unchecked(&vcc->stats->rx);
35499 cell += ATM_CELL_PAYLOAD;
35500 }
35501
35502@@ -2072,7 +2072,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35503 if (iovb == NULL) {
35504 printk("nicstar%d: Out of iovec buffers.\n",
35505 card->index);
35506- atomic_inc(&vcc->stats->rx_drop);
35507+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35508 recycle_rx_buf(card, skb);
35509 return;
35510 }
35511@@ -2096,7 +2096,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35512 small or large buffer itself. */
35513 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
35514 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
35515- atomic_inc(&vcc->stats->rx_err);
35516+ atomic_inc_unchecked(&vcc->stats->rx_err);
35517 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35518 NS_MAX_IOVECS);
35519 NS_PRV_IOVCNT(iovb) = 0;
35520@@ -2116,7 +2116,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35521 ("nicstar%d: Expected a small buffer, and this is not one.\n",
35522 card->index);
35523 which_list(card, skb);
35524- atomic_inc(&vcc->stats->rx_err);
35525+ atomic_inc_unchecked(&vcc->stats->rx_err);
35526 recycle_rx_buf(card, skb);
35527 vc->rx_iov = NULL;
35528 recycle_iov_buf(card, iovb);
35529@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35530 ("nicstar%d: Expected a large buffer, and this is not one.\n",
35531 card->index);
35532 which_list(card, skb);
35533- atomic_inc(&vcc->stats->rx_err);
35534+ atomic_inc_unchecked(&vcc->stats->rx_err);
35535 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35536 NS_PRV_IOVCNT(iovb));
35537 vc->rx_iov = NULL;
35538@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35539 printk(" - PDU size mismatch.\n");
35540 else
35541 printk(".\n");
35542- atomic_inc(&vcc->stats->rx_err);
35543+ atomic_inc_unchecked(&vcc->stats->rx_err);
35544 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35545 NS_PRV_IOVCNT(iovb));
35546 vc->rx_iov = NULL;
35547@@ -2166,7 +2166,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35548 /* skb points to a small buffer */
35549 if (!atm_charge(vcc, skb->truesize)) {
35550 push_rxbufs(card, skb);
35551- atomic_inc(&vcc->stats->rx_drop);
35552+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35553 } else {
35554 skb_put(skb, len);
35555 dequeue_sm_buf(card, skb);
35556@@ -2176,7 +2176,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35557 ATM_SKB(skb)->vcc = vcc;
35558 __net_timestamp(skb);
35559 vcc->push(vcc, skb);
35560- atomic_inc(&vcc->stats->rx);
35561+ atomic_inc_unchecked(&vcc->stats->rx);
35562 }
35563 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
35564 struct sk_buff *sb;
35565@@ -2187,7 +2187,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35566 if (len <= NS_SMBUFSIZE) {
35567 if (!atm_charge(vcc, sb->truesize)) {
35568 push_rxbufs(card, sb);
35569- atomic_inc(&vcc->stats->rx_drop);
35570+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35571 } else {
35572 skb_put(sb, len);
35573 dequeue_sm_buf(card, sb);
35574@@ -2197,7 +2197,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35575 ATM_SKB(sb)->vcc = vcc;
35576 __net_timestamp(sb);
35577 vcc->push(vcc, sb);
35578- atomic_inc(&vcc->stats->rx);
35579+ atomic_inc_unchecked(&vcc->stats->rx);
35580 }
35581
35582 push_rxbufs(card, skb);
35583@@ -2206,7 +2206,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35584
35585 if (!atm_charge(vcc, skb->truesize)) {
35586 push_rxbufs(card, skb);
35587- atomic_inc(&vcc->stats->rx_drop);
35588+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35589 } else {
35590 dequeue_lg_buf(card, skb);
35591 #ifdef NS_USE_DESTRUCTORS
35592@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35593 ATM_SKB(skb)->vcc = vcc;
35594 __net_timestamp(skb);
35595 vcc->push(vcc, skb);
35596- atomic_inc(&vcc->stats->rx);
35597+ atomic_inc_unchecked(&vcc->stats->rx);
35598 }
35599
35600 push_rxbufs(card, sb);
35601@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35602 printk
35603 ("nicstar%d: Out of huge buffers.\n",
35604 card->index);
35605- atomic_inc(&vcc->stats->rx_drop);
35606+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35607 recycle_iovec_rx_bufs(card,
35608 (struct iovec *)
35609 iovb->data,
35610@@ -2291,7 +2291,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35611 card->hbpool.count++;
35612 } else
35613 dev_kfree_skb_any(hb);
35614- atomic_inc(&vcc->stats->rx_drop);
35615+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35616 } else {
35617 /* Copy the small buffer to the huge buffer */
35618 sb = (struct sk_buff *)iov->iov_base;
35619@@ -2328,7 +2328,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35620 #endif /* NS_USE_DESTRUCTORS */
35621 __net_timestamp(hb);
35622 vcc->push(vcc, hb);
35623- atomic_inc(&vcc->stats->rx);
35624+ atomic_inc_unchecked(&vcc->stats->rx);
35625 }
35626 }
35627
35628diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
35629index 32784d1..4a8434a 100644
35630--- a/drivers/atm/solos-pci.c
35631+++ b/drivers/atm/solos-pci.c
35632@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
35633 }
35634 atm_charge(vcc, skb->truesize);
35635 vcc->push(vcc, skb);
35636- atomic_inc(&vcc->stats->rx);
35637+ atomic_inc_unchecked(&vcc->stats->rx);
35638 break;
35639
35640 case PKT_STATUS:
35641@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
35642 vcc = SKB_CB(oldskb)->vcc;
35643
35644 if (vcc) {
35645- atomic_inc(&vcc->stats->tx);
35646+ atomic_inc_unchecked(&vcc->stats->tx);
35647 solos_pop(vcc, oldskb);
35648 } else {
35649 dev_kfree_skb_irq(oldskb);
35650diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
35651index 0215934..ce9f5b1 100644
35652--- a/drivers/atm/suni.c
35653+++ b/drivers/atm/suni.c
35654@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
35655
35656
35657 #define ADD_LIMITED(s,v) \
35658- atomic_add((v),&stats->s); \
35659- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
35660+ atomic_add_unchecked((v),&stats->s); \
35661+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
35662
35663
35664 static void suni_hz(unsigned long from_timer)
35665diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
35666index 5120a96..e2572bd 100644
35667--- a/drivers/atm/uPD98402.c
35668+++ b/drivers/atm/uPD98402.c
35669@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
35670 struct sonet_stats tmp;
35671 int error = 0;
35672
35673- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35674+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35675 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
35676 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
35677 if (zero && !error) {
35678@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
35679
35680
35681 #define ADD_LIMITED(s,v) \
35682- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
35683- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
35684- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35685+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
35686+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
35687+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35688
35689
35690 static void stat_event(struct atm_dev *dev)
35691@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
35692 if (reason & uPD98402_INT_PFM) stat_event(dev);
35693 if (reason & uPD98402_INT_PCO) {
35694 (void) GET(PCOCR); /* clear interrupt cause */
35695- atomic_add(GET(HECCT),
35696+ atomic_add_unchecked(GET(HECCT),
35697 &PRIV(dev)->sonet_stats.uncorr_hcs);
35698 }
35699 if ((reason & uPD98402_INT_RFO) &&
35700@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
35701 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
35702 uPD98402_INT_LOS),PIMR); /* enable them */
35703 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
35704- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35705- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
35706- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
35707+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35708+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
35709+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
35710 return 0;
35711 }
35712
35713diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
35714index 969c3c2..9b72956 100644
35715--- a/drivers/atm/zatm.c
35716+++ b/drivers/atm/zatm.c
35717@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35718 }
35719 if (!size) {
35720 dev_kfree_skb_irq(skb);
35721- if (vcc) atomic_inc(&vcc->stats->rx_err);
35722+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
35723 continue;
35724 }
35725 if (!atm_charge(vcc,skb->truesize)) {
35726@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35727 skb->len = size;
35728 ATM_SKB(skb)->vcc = vcc;
35729 vcc->push(vcc,skb);
35730- atomic_inc(&vcc->stats->rx);
35731+ atomic_inc_unchecked(&vcc->stats->rx);
35732 }
35733 zout(pos & 0xffff,MTA(mbx));
35734 #if 0 /* probably a stupid idea */
35735@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
35736 skb_queue_head(&zatm_vcc->backlog,skb);
35737 break;
35738 }
35739- atomic_inc(&vcc->stats->tx);
35740+ atomic_inc_unchecked(&vcc->stats->tx);
35741 wake_up(&zatm_vcc->tx_wait);
35742 }
35743
35744diff --git a/drivers/base/bus.c b/drivers/base/bus.c
35745index d414331..b4dd4ba 100644
35746--- a/drivers/base/bus.c
35747+++ b/drivers/base/bus.c
35748@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
35749 return -EINVAL;
35750
35751 mutex_lock(&subsys->p->mutex);
35752- list_add_tail(&sif->node, &subsys->p->interfaces);
35753+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
35754 if (sif->add_dev) {
35755 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35756 while ((dev = subsys_dev_iter_next(&iter)))
35757@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
35758 subsys = sif->subsys;
35759
35760 mutex_lock(&subsys->p->mutex);
35761- list_del_init(&sif->node);
35762+ pax_list_del_init((struct list_head *)&sif->node);
35763 if (sif->remove_dev) {
35764 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35765 while ((dev = subsys_dev_iter_next(&iter)))
35766diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
35767index 7413d06..79155fa 100644
35768--- a/drivers/base/devtmpfs.c
35769+++ b/drivers/base/devtmpfs.c
35770@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
35771 if (!thread)
35772 return 0;
35773
35774- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
35775+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
35776 if (err)
35777 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
35778 else
35779@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
35780 *err = sys_unshare(CLONE_NEWNS);
35781 if (*err)
35782 goto out;
35783- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
35784+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
35785 if (*err)
35786 goto out;
35787- sys_chdir("/.."); /* will traverse into overmounted root */
35788- sys_chroot(".");
35789+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
35790+ sys_chroot((char __force_user *)".");
35791 complete(&setup_done);
35792 while (1) {
35793 spin_lock(&req_lock);
35794diff --git a/drivers/base/node.c b/drivers/base/node.c
35795index 7616a77c..8f57f51 100644
35796--- a/drivers/base/node.c
35797+++ b/drivers/base/node.c
35798@@ -626,7 +626,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
35799 struct node_attr {
35800 struct device_attribute attr;
35801 enum node_states state;
35802-};
35803+} __do_const;
35804
35805 static ssize_t show_node_state(struct device *dev,
35806 struct device_attribute *attr, char *buf)
35807diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
35808index bfb8955..42c9b9a 100644
35809--- a/drivers/base/power/domain.c
35810+++ b/drivers/base/power/domain.c
35811@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
35812 {
35813 struct cpuidle_driver *cpuidle_drv;
35814 struct gpd_cpu_data *cpu_data;
35815- struct cpuidle_state *idle_state;
35816+ cpuidle_state_no_const *idle_state;
35817 int ret = 0;
35818
35819 if (IS_ERR_OR_NULL(genpd) || state < 0)
35820@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
35821 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
35822 {
35823 struct gpd_cpu_data *cpu_data;
35824- struct cpuidle_state *idle_state;
35825+ cpuidle_state_no_const *idle_state;
35826 int ret = 0;
35827
35828 if (IS_ERR_OR_NULL(genpd))
35829diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
35830index a53ebd2..8f73eeb 100644
35831--- a/drivers/base/power/sysfs.c
35832+++ b/drivers/base/power/sysfs.c
35833@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
35834 return -EIO;
35835 }
35836 }
35837- return sprintf(buf, p);
35838+ return sprintf(buf, "%s", p);
35839 }
35840
35841 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
35842diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
35843index 2d56f41..8830f19 100644
35844--- a/drivers/base/power/wakeup.c
35845+++ b/drivers/base/power/wakeup.c
35846@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
35847 * They need to be modified together atomically, so it's better to use one
35848 * atomic variable to hold them both.
35849 */
35850-static atomic_t combined_event_count = ATOMIC_INIT(0);
35851+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
35852
35853 #define IN_PROGRESS_BITS (sizeof(int) * 4)
35854 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
35855
35856 static void split_counters(unsigned int *cnt, unsigned int *inpr)
35857 {
35858- unsigned int comb = atomic_read(&combined_event_count);
35859+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
35860
35861 *cnt = (comb >> IN_PROGRESS_BITS);
35862 *inpr = comb & MAX_IN_PROGRESS;
35863@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
35864 ws->start_prevent_time = ws->last_time;
35865
35866 /* Increment the counter of events in progress. */
35867- cec = atomic_inc_return(&combined_event_count);
35868+ cec = atomic_inc_return_unchecked(&combined_event_count);
35869
35870 trace_wakeup_source_activate(ws->name, cec);
35871 }
35872@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
35873 * Increment the counter of registered wakeup events and decrement the
35874 * couter of wakeup events in progress simultaneously.
35875 */
35876- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
35877+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
35878 trace_wakeup_source_deactivate(ws->name, cec);
35879
35880 split_counters(&cnt, &inpr);
35881diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
35882index e8d11b6..7b1b36f 100644
35883--- a/drivers/base/syscore.c
35884+++ b/drivers/base/syscore.c
35885@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
35886 void register_syscore_ops(struct syscore_ops *ops)
35887 {
35888 mutex_lock(&syscore_ops_lock);
35889- list_add_tail(&ops->node, &syscore_ops_list);
35890+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
35891 mutex_unlock(&syscore_ops_lock);
35892 }
35893 EXPORT_SYMBOL_GPL(register_syscore_ops);
35894@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
35895 void unregister_syscore_ops(struct syscore_ops *ops)
35896 {
35897 mutex_lock(&syscore_ops_lock);
35898- list_del(&ops->node);
35899+ pax_list_del((struct list_head *)&ops->node);
35900 mutex_unlock(&syscore_ops_lock);
35901 }
35902 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
35903diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
35904index 62b6c2c..4a11354 100644
35905--- a/drivers/block/cciss.c
35906+++ b/drivers/block/cciss.c
35907@@ -1189,6 +1189,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
35908 int err;
35909 u32 cp;
35910
35911+ memset(&arg64, 0, sizeof(arg64));
35912+
35913 err = 0;
35914 err |=
35915 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
35916@@ -3010,7 +3012,7 @@ static void start_io(ctlr_info_t *h)
35917 while (!list_empty(&h->reqQ)) {
35918 c = list_entry(h->reqQ.next, CommandList_struct, list);
35919 /* can't do anything if fifo is full */
35920- if ((h->access.fifo_full(h))) {
35921+ if ((h->access->fifo_full(h))) {
35922 dev_warn(&h->pdev->dev, "fifo full\n");
35923 break;
35924 }
35925@@ -3020,7 +3022,7 @@ static void start_io(ctlr_info_t *h)
35926 h->Qdepth--;
35927
35928 /* Tell the controller execute command */
35929- h->access.submit_command(h, c);
35930+ h->access->submit_command(h, c);
35931
35932 /* Put job onto the completed Q */
35933 addQ(&h->cmpQ, c);
35934@@ -3446,17 +3448,17 @@ startio:
35935
35936 static inline unsigned long get_next_completion(ctlr_info_t *h)
35937 {
35938- return h->access.command_completed(h);
35939+ return h->access->command_completed(h);
35940 }
35941
35942 static inline int interrupt_pending(ctlr_info_t *h)
35943 {
35944- return h->access.intr_pending(h);
35945+ return h->access->intr_pending(h);
35946 }
35947
35948 static inline long interrupt_not_for_us(ctlr_info_t *h)
35949 {
35950- return ((h->access.intr_pending(h) == 0) ||
35951+ return ((h->access->intr_pending(h) == 0) ||
35952 (h->interrupts_enabled == 0));
35953 }
35954
35955@@ -3489,7 +3491,7 @@ static inline u32 next_command(ctlr_info_t *h)
35956 u32 a;
35957
35958 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
35959- return h->access.command_completed(h);
35960+ return h->access->command_completed(h);
35961
35962 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
35963 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
35964@@ -4046,7 +4048,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
35965 trans_support & CFGTBL_Trans_use_short_tags);
35966
35967 /* Change the access methods to the performant access methods */
35968- h->access = SA5_performant_access;
35969+ h->access = &SA5_performant_access;
35970 h->transMethod = CFGTBL_Trans_Performant;
35971
35972 return;
35973@@ -4319,7 +4321,7 @@ static int cciss_pci_init(ctlr_info_t *h)
35974 if (prod_index < 0)
35975 return -ENODEV;
35976 h->product_name = products[prod_index].product_name;
35977- h->access = *(products[prod_index].access);
35978+ h->access = products[prod_index].access;
35979
35980 if (cciss_board_disabled(h)) {
35981 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
35982@@ -5051,7 +5053,7 @@ reinit_after_soft_reset:
35983 }
35984
35985 /* make sure the board interrupts are off */
35986- h->access.set_intr_mask(h, CCISS_INTR_OFF);
35987+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
35988 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
35989 if (rc)
35990 goto clean2;
35991@@ -5101,7 +5103,7 @@ reinit_after_soft_reset:
35992 * fake ones to scoop up any residual completions.
35993 */
35994 spin_lock_irqsave(&h->lock, flags);
35995- h->access.set_intr_mask(h, CCISS_INTR_OFF);
35996+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
35997 spin_unlock_irqrestore(&h->lock, flags);
35998 free_irq(h->intr[h->intr_mode], h);
35999 rc = cciss_request_irq(h, cciss_msix_discard_completions,
36000@@ -5121,9 +5123,9 @@ reinit_after_soft_reset:
36001 dev_info(&h->pdev->dev, "Board READY.\n");
36002 dev_info(&h->pdev->dev,
36003 "Waiting for stale completions to drain.\n");
36004- h->access.set_intr_mask(h, CCISS_INTR_ON);
36005+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36006 msleep(10000);
36007- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36008+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36009
36010 rc = controller_reset_failed(h->cfgtable);
36011 if (rc)
36012@@ -5146,7 +5148,7 @@ reinit_after_soft_reset:
36013 cciss_scsi_setup(h);
36014
36015 /* Turn the interrupts on so we can service requests */
36016- h->access.set_intr_mask(h, CCISS_INTR_ON);
36017+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36018
36019 /* Get the firmware version */
36020 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
36021@@ -5218,7 +5220,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
36022 kfree(flush_buf);
36023 if (return_code != IO_OK)
36024 dev_warn(&h->pdev->dev, "Error flushing cache\n");
36025- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36026+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36027 free_irq(h->intr[h->intr_mode], h);
36028 }
36029
36030diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
36031index 7fda30e..eb5dfe0 100644
36032--- a/drivers/block/cciss.h
36033+++ b/drivers/block/cciss.h
36034@@ -101,7 +101,7 @@ struct ctlr_info
36035 /* information about each logical volume */
36036 drive_info_struct *drv[CISS_MAX_LUN];
36037
36038- struct access_method access;
36039+ struct access_method *access;
36040
36041 /* queue and queue Info */
36042 struct list_head reqQ;
36043diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
36044index 639d26b..fd6ad1f 100644
36045--- a/drivers/block/cpqarray.c
36046+++ b/drivers/block/cpqarray.c
36047@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36048 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
36049 goto Enomem4;
36050 }
36051- hba[i]->access.set_intr_mask(hba[i], 0);
36052+ hba[i]->access->set_intr_mask(hba[i], 0);
36053 if (request_irq(hba[i]->intr, do_ida_intr,
36054 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
36055 {
36056@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36057 add_timer(&hba[i]->timer);
36058
36059 /* Enable IRQ now that spinlock and rate limit timer are set up */
36060- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36061+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36062
36063 for(j=0; j<NWD; j++) {
36064 struct gendisk *disk = ida_gendisk[i][j];
36065@@ -694,7 +694,7 @@ DBGINFO(
36066 for(i=0; i<NR_PRODUCTS; i++) {
36067 if (board_id == products[i].board_id) {
36068 c->product_name = products[i].product_name;
36069- c->access = *(products[i].access);
36070+ c->access = products[i].access;
36071 break;
36072 }
36073 }
36074@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
36075 hba[ctlr]->intr = intr;
36076 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
36077 hba[ctlr]->product_name = products[j].product_name;
36078- hba[ctlr]->access = *(products[j].access);
36079+ hba[ctlr]->access = products[j].access;
36080 hba[ctlr]->ctlr = ctlr;
36081 hba[ctlr]->board_id = board_id;
36082 hba[ctlr]->pci_dev = NULL; /* not PCI */
36083@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
36084
36085 while((c = h->reqQ) != NULL) {
36086 /* Can't do anything if we're busy */
36087- if (h->access.fifo_full(h) == 0)
36088+ if (h->access->fifo_full(h) == 0)
36089 return;
36090
36091 /* Get the first entry from the request Q */
36092@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
36093 h->Qdepth--;
36094
36095 /* Tell the controller to do our bidding */
36096- h->access.submit_command(h, c);
36097+ h->access->submit_command(h, c);
36098
36099 /* Get onto the completion Q */
36100 addQ(&h->cmpQ, c);
36101@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36102 unsigned long flags;
36103 __u32 a,a1;
36104
36105- istat = h->access.intr_pending(h);
36106+ istat = h->access->intr_pending(h);
36107 /* Is this interrupt for us? */
36108 if (istat == 0)
36109 return IRQ_NONE;
36110@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36111 */
36112 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
36113 if (istat & FIFO_NOT_EMPTY) {
36114- while((a = h->access.command_completed(h))) {
36115+ while((a = h->access->command_completed(h))) {
36116 a1 = a; a &= ~3;
36117 if ((c = h->cmpQ) == NULL)
36118 {
36119@@ -1193,6 +1193,7 @@ out_passthru:
36120 ida_pci_info_struct pciinfo;
36121
36122 if (!arg) return -EINVAL;
36123+ memset(&pciinfo, 0, sizeof(pciinfo));
36124 pciinfo.bus = host->pci_dev->bus->number;
36125 pciinfo.dev_fn = host->pci_dev->devfn;
36126 pciinfo.board_id = host->board_id;
36127@@ -1447,11 +1448,11 @@ static int sendcmd(
36128 /*
36129 * Disable interrupt
36130 */
36131- info_p->access.set_intr_mask(info_p, 0);
36132+ info_p->access->set_intr_mask(info_p, 0);
36133 /* Make sure there is room in the command FIFO */
36134 /* Actually it should be completely empty at this time. */
36135 for (i = 200000; i > 0; i--) {
36136- temp = info_p->access.fifo_full(info_p);
36137+ temp = info_p->access->fifo_full(info_p);
36138 if (temp != 0) {
36139 break;
36140 }
36141@@ -1464,7 +1465,7 @@ DBG(
36142 /*
36143 * Send the cmd
36144 */
36145- info_p->access.submit_command(info_p, c);
36146+ info_p->access->submit_command(info_p, c);
36147 complete = pollcomplete(ctlr);
36148
36149 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
36150@@ -1547,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
36151 * we check the new geometry. Then turn interrupts back on when
36152 * we're done.
36153 */
36154- host->access.set_intr_mask(host, 0);
36155+ host->access->set_intr_mask(host, 0);
36156 getgeometry(ctlr);
36157- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
36158+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
36159
36160 for(i=0; i<NWD; i++) {
36161 struct gendisk *disk = ida_gendisk[ctlr][i];
36162@@ -1589,7 +1590,7 @@ static int pollcomplete(int ctlr)
36163 /* Wait (up to 2 seconds) for a command to complete */
36164
36165 for (i = 200000; i > 0; i--) {
36166- done = hba[ctlr]->access.command_completed(hba[ctlr]);
36167+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
36168 if (done == 0) {
36169 udelay(10); /* a short fixed delay */
36170 } else
36171diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
36172index be73e9d..7fbf140 100644
36173--- a/drivers/block/cpqarray.h
36174+++ b/drivers/block/cpqarray.h
36175@@ -99,7 +99,7 @@ struct ctlr_info {
36176 drv_info_t drv[NWD];
36177 struct proc_dir_entry *proc;
36178
36179- struct access_method access;
36180+ struct access_method *access;
36181
36182 cmdlist_t *reqQ;
36183 cmdlist_t *cmpQ;
36184diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
36185index 2d7f608..11245fe 100644
36186--- a/drivers/block/drbd/drbd_int.h
36187+++ b/drivers/block/drbd/drbd_int.h
36188@@ -582,7 +582,7 @@ struct drbd_epoch {
36189 struct drbd_tconn *tconn;
36190 struct list_head list;
36191 unsigned int barrier_nr;
36192- atomic_t epoch_size; /* increased on every request added. */
36193+ atomic_unchecked_t epoch_size; /* increased on every request added. */
36194 atomic_t active; /* increased on every req. added, and dec on every finished. */
36195 unsigned long flags;
36196 };
36197@@ -1022,7 +1022,7 @@ struct drbd_conf {
36198 unsigned int al_tr_number;
36199 int al_tr_cycle;
36200 wait_queue_head_t seq_wait;
36201- atomic_t packet_seq;
36202+ atomic_unchecked_t packet_seq;
36203 unsigned int peer_seq;
36204 spinlock_t peer_seq_lock;
36205 unsigned int minor;
36206@@ -1572,7 +1572,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
36207 char __user *uoptval;
36208 int err;
36209
36210- uoptval = (char __user __force *)optval;
36211+ uoptval = (char __force_user *)optval;
36212
36213 set_fs(KERNEL_DS);
36214 if (level == SOL_SOCKET)
36215diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
36216index 55635ed..40e837c 100644
36217--- a/drivers/block/drbd/drbd_main.c
36218+++ b/drivers/block/drbd/drbd_main.c
36219@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
36220 p->sector = sector;
36221 p->block_id = block_id;
36222 p->blksize = blksize;
36223- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36224+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36225 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
36226 }
36227
36228@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
36229 return -EIO;
36230 p->sector = cpu_to_be64(req->i.sector);
36231 p->block_id = (unsigned long)req;
36232- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36233+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36234 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
36235 if (mdev->state.conn >= C_SYNC_SOURCE &&
36236 mdev->state.conn <= C_PAUSED_SYNC_T)
36237@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
36238 {
36239 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
36240
36241- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
36242- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
36243+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
36244+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
36245 kfree(tconn->current_epoch);
36246
36247 idr_destroy(&tconn->volumes);
36248diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
36249index 8cc1e64..ba7ffa9 100644
36250--- a/drivers/block/drbd/drbd_nl.c
36251+++ b/drivers/block/drbd/drbd_nl.c
36252@@ -3440,7 +3440,7 @@ out:
36253
36254 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36255 {
36256- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36257+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36258 struct sk_buff *msg;
36259 struct drbd_genlmsghdr *d_out;
36260 unsigned seq;
36261@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36262 return;
36263 }
36264
36265- seq = atomic_inc_return(&drbd_genl_seq);
36266+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
36267 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
36268 if (!msg)
36269 goto failed;
36270diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
36271index cc29cd3..d4b058b 100644
36272--- a/drivers/block/drbd/drbd_receiver.c
36273+++ b/drivers/block/drbd/drbd_receiver.c
36274@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
36275 {
36276 int err;
36277
36278- atomic_set(&mdev->packet_seq, 0);
36279+ atomic_set_unchecked(&mdev->packet_seq, 0);
36280 mdev->peer_seq = 0;
36281
36282 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
36283@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36284 do {
36285 next_epoch = NULL;
36286
36287- epoch_size = atomic_read(&epoch->epoch_size);
36288+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
36289
36290 switch (ev & ~EV_CLEANUP) {
36291 case EV_PUT:
36292@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36293 rv = FE_DESTROYED;
36294 } else {
36295 epoch->flags = 0;
36296- atomic_set(&epoch->epoch_size, 0);
36297+ atomic_set_unchecked(&epoch->epoch_size, 0);
36298 /* atomic_set(&epoch->active, 0); is already zero */
36299 if (rv == FE_STILL_LIVE)
36300 rv = FE_RECYCLED;
36301@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36302 conn_wait_active_ee_empty(tconn);
36303 drbd_flush(tconn);
36304
36305- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36306+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36307 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
36308 if (epoch)
36309 break;
36310@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36311 }
36312
36313 epoch->flags = 0;
36314- atomic_set(&epoch->epoch_size, 0);
36315+ atomic_set_unchecked(&epoch->epoch_size, 0);
36316 atomic_set(&epoch->active, 0);
36317
36318 spin_lock(&tconn->epoch_lock);
36319- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36320+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36321 list_add(&epoch->list, &tconn->current_epoch->list);
36322 tconn->current_epoch = epoch;
36323 tconn->epochs++;
36324@@ -2172,7 +2172,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36325
36326 err = wait_for_and_update_peer_seq(mdev, peer_seq);
36327 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
36328- atomic_inc(&tconn->current_epoch->epoch_size);
36329+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
36330 err2 = drbd_drain_block(mdev, pi->size);
36331 if (!err)
36332 err = err2;
36333@@ -2206,7 +2206,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36334
36335 spin_lock(&tconn->epoch_lock);
36336 peer_req->epoch = tconn->current_epoch;
36337- atomic_inc(&peer_req->epoch->epoch_size);
36338+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
36339 atomic_inc(&peer_req->epoch->active);
36340 spin_unlock(&tconn->epoch_lock);
36341
36342@@ -4347,7 +4347,7 @@ struct data_cmd {
36343 int expect_payload;
36344 size_t pkt_size;
36345 int (*fn)(struct drbd_tconn *, struct packet_info *);
36346-};
36347+} __do_const;
36348
36349 static struct data_cmd drbd_cmd_handler[] = {
36350 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
36351@@ -4467,7 +4467,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
36352 if (!list_empty(&tconn->current_epoch->list))
36353 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
36354 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
36355- atomic_set(&tconn->current_epoch->epoch_size, 0);
36356+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
36357 tconn->send.seen_any_write_yet = false;
36358
36359 conn_info(tconn, "Connection closed\n");
36360@@ -5223,7 +5223,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
36361 struct asender_cmd {
36362 size_t pkt_size;
36363 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
36364-};
36365+} __do_const;
36366
36367 static struct asender_cmd asender_tbl[] = {
36368 [P_PING] = { 0, got_Ping },
36369diff --git a/drivers/block/loop.c b/drivers/block/loop.c
36370index 40e7155..df5c79a 100644
36371--- a/drivers/block/loop.c
36372+++ b/drivers/block/loop.c
36373@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
36374
36375 file_start_write(file);
36376 set_fs(get_ds());
36377- bw = file->f_op->write(file, buf, len, &pos);
36378+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
36379 set_fs(old_fs);
36380 file_end_write(file);
36381 if (likely(bw == len))
36382diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
36383index f5d0ea1..c62380a 100644
36384--- a/drivers/block/pktcdvd.c
36385+++ b/drivers/block/pktcdvd.c
36386@@ -84,7 +84,7 @@
36387 #define MAX_SPEED 0xffff
36388
36389 #define ZONE(sector, pd) (((sector) + (pd)->offset) & \
36390- ~(sector_t)((pd)->settings.size - 1))
36391+ ~(sector_t)((pd)->settings.size - 1UL))
36392
36393 static DEFINE_MUTEX(pktcdvd_mutex);
36394 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
36395diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
36396index 8a3aff7..d7538c2 100644
36397--- a/drivers/cdrom/cdrom.c
36398+++ b/drivers/cdrom/cdrom.c
36399@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
36400 ENSURE(reset, CDC_RESET);
36401 ENSURE(generic_packet, CDC_GENERIC_PACKET);
36402 cdi->mc_flags = 0;
36403- cdo->n_minors = 0;
36404 cdi->options = CDO_USE_FFLAGS;
36405
36406 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
36407@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
36408 else
36409 cdi->cdda_method = CDDA_OLD;
36410
36411- if (!cdo->generic_packet)
36412- cdo->generic_packet = cdrom_dummy_generic_packet;
36413+ if (!cdo->generic_packet) {
36414+ pax_open_kernel();
36415+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
36416+ pax_close_kernel();
36417+ }
36418
36419 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
36420 mutex_lock(&cdrom_mutex);
36421@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
36422 if (cdi->exit)
36423 cdi->exit(cdi);
36424
36425- cdi->ops->n_minors--;
36426 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
36427 }
36428
36429@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
36430 */
36431 nr = nframes;
36432 do {
36433- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36434+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36435 if (cgc.buffer)
36436 break;
36437
36438@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
36439 struct cdrom_device_info *cdi;
36440 int ret;
36441
36442- ret = scnprintf(info + *pos, max_size - *pos, header);
36443+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
36444 if (!ret)
36445 return 1;
36446
36447diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
36448index 5980cb9..6d7bd7e 100644
36449--- a/drivers/cdrom/gdrom.c
36450+++ b/drivers/cdrom/gdrom.c
36451@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
36452 .audio_ioctl = gdrom_audio_ioctl,
36453 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
36454 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
36455- .n_minors = 1,
36456 };
36457
36458 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
36459diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
36460index 1421997..33f5d6d 100644
36461--- a/drivers/char/Kconfig
36462+++ b/drivers/char/Kconfig
36463@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
36464
36465 config DEVKMEM
36466 bool "/dev/kmem virtual device support"
36467- default y
36468+ default n
36469+ depends on !GRKERNSEC_KMEM
36470 help
36471 Say Y here if you want to support the /dev/kmem device. The
36472 /dev/kmem device is rarely used, but can be used for certain
36473@@ -570,6 +571,7 @@ config DEVPORT
36474 bool
36475 depends on !M68K
36476 depends on ISA || PCI
36477+ depends on !GRKERNSEC_KMEM
36478 default y
36479
36480 source "drivers/s390/char/Kconfig"
36481diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
36482index a48e05b..6bac831 100644
36483--- a/drivers/char/agp/compat_ioctl.c
36484+++ b/drivers/char/agp/compat_ioctl.c
36485@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
36486 return -ENOMEM;
36487 }
36488
36489- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
36490+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
36491 sizeof(*usegment) * ureserve.seg_count)) {
36492 kfree(usegment);
36493 kfree(ksegment);
36494diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
36495index 1b19239..b87b143 100644
36496--- a/drivers/char/agp/frontend.c
36497+++ b/drivers/char/agp/frontend.c
36498@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36499 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
36500 return -EFAULT;
36501
36502- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
36503+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
36504 return -EFAULT;
36505
36506 client = agp_find_client_by_pid(reserve.pid);
36507@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36508 if (segment == NULL)
36509 return -ENOMEM;
36510
36511- if (copy_from_user(segment, (void __user *) reserve.seg_list,
36512+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
36513 sizeof(struct agp_segment) * reserve.seg_count)) {
36514 kfree(segment);
36515 return -EFAULT;
36516diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
36517index 4f94375..413694e 100644
36518--- a/drivers/char/genrtc.c
36519+++ b/drivers/char/genrtc.c
36520@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
36521 switch (cmd) {
36522
36523 case RTC_PLL_GET:
36524+ memset(&pll, 0, sizeof(pll));
36525 if (get_rtc_pll(&pll))
36526 return -EINVAL;
36527 else
36528diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
36529index 448ce5e..3a76625 100644
36530--- a/drivers/char/hpet.c
36531+++ b/drivers/char/hpet.c
36532@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
36533 }
36534
36535 static int
36536-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
36537+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
36538 struct hpet_info *info)
36539 {
36540 struct hpet_timer __iomem *timer;
36541diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
36542index 86fe45c..c0ea948 100644
36543--- a/drivers/char/hw_random/intel-rng.c
36544+++ b/drivers/char/hw_random/intel-rng.c
36545@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
36546
36547 if (no_fwh_detect)
36548 return -ENODEV;
36549- printk(warning);
36550+ printk("%s", warning);
36551 return -EBUSY;
36552 }
36553
36554diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
36555index 4445fa1..7c6de37 100644
36556--- a/drivers/char/ipmi/ipmi_msghandler.c
36557+++ b/drivers/char/ipmi/ipmi_msghandler.c
36558@@ -420,7 +420,7 @@ struct ipmi_smi {
36559 struct proc_dir_entry *proc_dir;
36560 char proc_dir_name[10];
36561
36562- atomic_t stats[IPMI_NUM_STATS];
36563+ atomic_unchecked_t stats[IPMI_NUM_STATS];
36564
36565 /*
36566 * run_to_completion duplicate of smb_info, smi_info
36567@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
36568
36569
36570 #define ipmi_inc_stat(intf, stat) \
36571- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
36572+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
36573 #define ipmi_get_stat(intf, stat) \
36574- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
36575+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
36576
36577 static int is_lan_addr(struct ipmi_addr *addr)
36578 {
36579@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
36580 INIT_LIST_HEAD(&intf->cmd_rcvrs);
36581 init_waitqueue_head(&intf->waitq);
36582 for (i = 0; i < IPMI_NUM_STATS; i++)
36583- atomic_set(&intf->stats[i], 0);
36584+ atomic_set_unchecked(&intf->stats[i], 0);
36585
36586 intf->proc_dir = NULL;
36587
36588diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
36589index af4b23f..79806fc 100644
36590--- a/drivers/char/ipmi/ipmi_si_intf.c
36591+++ b/drivers/char/ipmi/ipmi_si_intf.c
36592@@ -275,7 +275,7 @@ struct smi_info {
36593 unsigned char slave_addr;
36594
36595 /* Counters and things for the proc filesystem. */
36596- atomic_t stats[SI_NUM_STATS];
36597+ atomic_unchecked_t stats[SI_NUM_STATS];
36598
36599 struct task_struct *thread;
36600
36601@@ -284,9 +284,9 @@ struct smi_info {
36602 };
36603
36604 #define smi_inc_stat(smi, stat) \
36605- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
36606+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
36607 #define smi_get_stat(smi, stat) \
36608- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
36609+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
36610
36611 #define SI_MAX_PARMS 4
36612
36613@@ -3258,7 +3258,7 @@ static int try_smi_init(struct smi_info *new_smi)
36614 atomic_set(&new_smi->req_events, 0);
36615 new_smi->run_to_completion = 0;
36616 for (i = 0; i < SI_NUM_STATS; i++)
36617- atomic_set(&new_smi->stats[i], 0);
36618+ atomic_set_unchecked(&new_smi->stats[i], 0);
36619
36620 new_smi->interrupt_disabled = 1;
36621 atomic_set(&new_smi->stop_operation, 0);
36622diff --git a/drivers/char/mem.c b/drivers/char/mem.c
36623index f895a8c..2bc9147 100644
36624--- a/drivers/char/mem.c
36625+++ b/drivers/char/mem.c
36626@@ -18,6 +18,7 @@
36627 #include <linux/raw.h>
36628 #include <linux/tty.h>
36629 #include <linux/capability.h>
36630+#include <linux/security.h>
36631 #include <linux/ptrace.h>
36632 #include <linux/device.h>
36633 #include <linux/highmem.h>
36634@@ -37,6 +38,10 @@
36635
36636 #define DEVPORT_MINOR 4
36637
36638+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36639+extern const struct file_operations grsec_fops;
36640+#endif
36641+
36642 static inline unsigned long size_inside_page(unsigned long start,
36643 unsigned long size)
36644 {
36645@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36646
36647 while (cursor < to) {
36648 if (!devmem_is_allowed(pfn)) {
36649+#ifdef CONFIG_GRKERNSEC_KMEM
36650+ gr_handle_mem_readwrite(from, to);
36651+#else
36652 printk(KERN_INFO
36653 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
36654 current->comm, from, to);
36655+#endif
36656 return 0;
36657 }
36658 cursor += PAGE_SIZE;
36659@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36660 }
36661 return 1;
36662 }
36663+#elif defined(CONFIG_GRKERNSEC_KMEM)
36664+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36665+{
36666+ return 0;
36667+}
36668 #else
36669 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36670 {
36671@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36672
36673 while (count > 0) {
36674 unsigned long remaining;
36675+ char *temp;
36676
36677 sz = size_inside_page(p, count);
36678
36679@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36680 if (!ptr)
36681 return -EFAULT;
36682
36683- remaining = copy_to_user(buf, ptr, sz);
36684+#ifdef CONFIG_PAX_USERCOPY
36685+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36686+ if (!temp) {
36687+ unxlate_dev_mem_ptr(p, ptr);
36688+ return -ENOMEM;
36689+ }
36690+ memcpy(temp, ptr, sz);
36691+#else
36692+ temp = ptr;
36693+#endif
36694+
36695+ remaining = copy_to_user(buf, temp, sz);
36696+
36697+#ifdef CONFIG_PAX_USERCOPY
36698+ kfree(temp);
36699+#endif
36700+
36701 unxlate_dev_mem_ptr(p, ptr);
36702 if (remaining)
36703 return -EFAULT;
36704@@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36705 size_t count, loff_t *ppos)
36706 {
36707 unsigned long p = *ppos;
36708- ssize_t low_count, read, sz;
36709+ ssize_t low_count, read, sz, err = 0;
36710 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
36711- int err = 0;
36712
36713 read = 0;
36714 if (p < (unsigned long) high_memory) {
36715@@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36716 }
36717 #endif
36718 while (low_count > 0) {
36719+ char *temp;
36720+
36721 sz = size_inside_page(p, low_count);
36722
36723 /*
36724@@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36725 */
36726 kbuf = xlate_dev_kmem_ptr((char *)p);
36727
36728- if (copy_to_user(buf, kbuf, sz))
36729+#ifdef CONFIG_PAX_USERCOPY
36730+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36731+ if (!temp)
36732+ return -ENOMEM;
36733+ memcpy(temp, kbuf, sz);
36734+#else
36735+ temp = kbuf;
36736+#endif
36737+
36738+ err = copy_to_user(buf, temp, sz);
36739+
36740+#ifdef CONFIG_PAX_USERCOPY
36741+ kfree(temp);
36742+#endif
36743+
36744+ if (err)
36745 return -EFAULT;
36746 buf += sz;
36747 p += sz;
36748@@ -822,6 +869,9 @@ static const struct memdev {
36749 #ifdef CONFIG_PRINTK
36750 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
36751 #endif
36752+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36753+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
36754+#endif
36755 };
36756
36757 static int memory_open(struct inode *inode, struct file *filp)
36758@@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
36759 continue;
36760
36761 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
36762- NULL, devlist[minor].name);
36763+ NULL, "%s", devlist[minor].name);
36764 }
36765
36766 return tty_init();
36767diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
36768index 9df78e2..01ba9ae 100644
36769--- a/drivers/char/nvram.c
36770+++ b/drivers/char/nvram.c
36771@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
36772
36773 spin_unlock_irq(&rtc_lock);
36774
36775- if (copy_to_user(buf, contents, tmp - contents))
36776+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
36777 return -EFAULT;
36778
36779 *ppos = i;
36780diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
36781index 5c5cc00..ac9edb7 100644
36782--- a/drivers/char/pcmcia/synclink_cs.c
36783+++ b/drivers/char/pcmcia/synclink_cs.c
36784@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36785
36786 if (debug_level >= DEBUG_LEVEL_INFO)
36787 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
36788- __FILE__, __LINE__, info->device_name, port->count);
36789+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
36790
36791- WARN_ON(!port->count);
36792+ WARN_ON(!atomic_read(&port->count));
36793
36794 if (tty_port_close_start(port, tty, filp) == 0)
36795 goto cleanup;
36796@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36797 cleanup:
36798 if (debug_level >= DEBUG_LEVEL_INFO)
36799 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
36800- tty->driver->name, port->count);
36801+ tty->driver->name, atomic_read(&port->count));
36802 }
36803
36804 /* Wait until the transmitter is empty.
36805@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36806
36807 if (debug_level >= DEBUG_LEVEL_INFO)
36808 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
36809- __FILE__, __LINE__, tty->driver->name, port->count);
36810+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
36811
36812 /* If port is closing, signal caller to try again */
36813 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
36814@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36815 goto cleanup;
36816 }
36817 spin_lock(&port->lock);
36818- port->count++;
36819+ atomic_inc(&port->count);
36820 spin_unlock(&port->lock);
36821 spin_unlock_irqrestore(&info->netlock, flags);
36822
36823- if (port->count == 1) {
36824+ if (atomic_read(&port->count) == 1) {
36825 /* 1st open on this device, init hardware */
36826 retval = startup(info, tty);
36827 if (retval < 0)
36828@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
36829 unsigned short new_crctype;
36830
36831 /* return error if TTY interface open */
36832- if (info->port.count)
36833+ if (atomic_read(&info->port.count))
36834 return -EBUSY;
36835
36836 switch (encoding)
36837@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
36838
36839 /* arbitrate between network and tty opens */
36840 spin_lock_irqsave(&info->netlock, flags);
36841- if (info->port.count != 0 || info->netcount != 0) {
36842+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
36843 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
36844 spin_unlock_irqrestore(&info->netlock, flags);
36845 return -EBUSY;
36846@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36847 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
36848
36849 /* return error if TTY interface open */
36850- if (info->port.count)
36851+ if (atomic_read(&info->port.count))
36852 return -EBUSY;
36853
36854 if (cmd != SIOCWANDEV)
36855diff --git a/drivers/char/random.c b/drivers/char/random.c
36856index 0d91fe5..f8e37b0 100644
36857--- a/drivers/char/random.c
36858+++ b/drivers/char/random.c
36859@@ -272,8 +272,13 @@
36860 /*
36861 * Configuration information
36862 */
36863+#ifdef CONFIG_GRKERNSEC_RANDNET
36864+#define INPUT_POOL_WORDS 512
36865+#define OUTPUT_POOL_WORDS 128
36866+#else
36867 #define INPUT_POOL_WORDS 128
36868 #define OUTPUT_POOL_WORDS 32
36869+#endif
36870 #define SEC_XFER_SIZE 512
36871 #define EXTRACT_SIZE 10
36872
36873@@ -313,10 +318,17 @@ static struct poolinfo {
36874 int poolwords;
36875 int tap1, tap2, tap3, tap4, tap5;
36876 } poolinfo_table[] = {
36877+#ifdef CONFIG_GRKERNSEC_RANDNET
36878+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
36879+ { 512, 411, 308, 208, 104, 1 },
36880+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
36881+ { 128, 103, 76, 51, 25, 1 },
36882+#else
36883 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
36884 { 128, 103, 76, 51, 25, 1 },
36885 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
36886 { 32, 26, 20, 14, 7, 1 },
36887+#endif
36888 #if 0
36889 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
36890 { 2048, 1638, 1231, 819, 411, 1 },
36891@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
36892 input_rotate += i ? 7 : 14;
36893 }
36894
36895- ACCESS_ONCE(r->input_rotate) = input_rotate;
36896- ACCESS_ONCE(r->add_ptr) = i;
36897+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
36898+ ACCESS_ONCE_RW(r->add_ptr) = i;
36899 smp_wmb();
36900
36901 if (out)
36902@@ -1032,7 +1044,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
36903
36904 extract_buf(r, tmp);
36905 i = min_t(int, nbytes, EXTRACT_SIZE);
36906- if (copy_to_user(buf, tmp, i)) {
36907+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
36908 ret = -EFAULT;
36909 break;
36910 }
36911@@ -1368,7 +1380,7 @@ EXPORT_SYMBOL(generate_random_uuid);
36912 #include <linux/sysctl.h>
36913
36914 static int min_read_thresh = 8, min_write_thresh;
36915-static int max_read_thresh = INPUT_POOL_WORDS * 32;
36916+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
36917 static int max_write_thresh = INPUT_POOL_WORDS * 32;
36918 static char sysctl_bootid[16];
36919
36920@@ -1384,7 +1396,7 @@ static char sysctl_bootid[16];
36921 static int proc_do_uuid(struct ctl_table *table, int write,
36922 void __user *buffer, size_t *lenp, loff_t *ppos)
36923 {
36924- struct ctl_table fake_table;
36925+ ctl_table_no_const fake_table;
36926 unsigned char buf[64], tmp_uuid[16], *uuid;
36927
36928 uuid = table->data;
36929diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
36930index bf2349db..5456d53 100644
36931--- a/drivers/char/sonypi.c
36932+++ b/drivers/char/sonypi.c
36933@@ -54,6 +54,7 @@
36934
36935 #include <asm/uaccess.h>
36936 #include <asm/io.h>
36937+#include <asm/local.h>
36938
36939 #include <linux/sonypi.h>
36940
36941@@ -490,7 +491,7 @@ static struct sonypi_device {
36942 spinlock_t fifo_lock;
36943 wait_queue_head_t fifo_proc_list;
36944 struct fasync_struct *fifo_async;
36945- int open_count;
36946+ local_t open_count;
36947 int model;
36948 struct input_dev *input_jog_dev;
36949 struct input_dev *input_key_dev;
36950@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
36951 static int sonypi_misc_release(struct inode *inode, struct file *file)
36952 {
36953 mutex_lock(&sonypi_device.lock);
36954- sonypi_device.open_count--;
36955+ local_dec(&sonypi_device.open_count);
36956 mutex_unlock(&sonypi_device.lock);
36957 return 0;
36958 }
36959@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
36960 {
36961 mutex_lock(&sonypi_device.lock);
36962 /* Flush input queue on first open */
36963- if (!sonypi_device.open_count)
36964+ if (!local_read(&sonypi_device.open_count))
36965 kfifo_reset(&sonypi_device.fifo);
36966- sonypi_device.open_count++;
36967+ local_inc(&sonypi_device.open_count);
36968 mutex_unlock(&sonypi_device.lock);
36969
36970 return 0;
36971diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
36972index 64420b3..5c40b56 100644
36973--- a/drivers/char/tpm/tpm_acpi.c
36974+++ b/drivers/char/tpm/tpm_acpi.c
36975@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
36976 virt = acpi_os_map_memory(start, len);
36977 if (!virt) {
36978 kfree(log->bios_event_log);
36979+ log->bios_event_log = NULL;
36980 printk("%s: ERROR - Unable to map memory\n", __func__);
36981 return -EIO;
36982 }
36983
36984- memcpy_fromio(log->bios_event_log, virt, len);
36985+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
36986
36987 acpi_os_unmap_memory(virt, len);
36988 return 0;
36989diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
36990index 84ddc55..1d32f1e 100644
36991--- a/drivers/char/tpm/tpm_eventlog.c
36992+++ b/drivers/char/tpm/tpm_eventlog.c
36993@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
36994 event = addr;
36995
36996 if ((event->event_type == 0 && event->event_size == 0) ||
36997- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
36998+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
36999 return NULL;
37000
37001 return addr;
37002@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
37003 return NULL;
37004
37005 if ((event->event_type == 0 && event->event_size == 0) ||
37006- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
37007+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
37008 return NULL;
37009
37010 (*pos)++;
37011@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
37012 int i;
37013
37014 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
37015- seq_putc(m, data[i]);
37016+ if (!seq_putc(m, data[i]))
37017+ return -EFAULT;
37018
37019 return 0;
37020 }
37021diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
37022index fc45567..fa2a590 100644
37023--- a/drivers/char/virtio_console.c
37024+++ b/drivers/char/virtio_console.c
37025@@ -682,7 +682,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
37026 if (to_user) {
37027 ssize_t ret;
37028
37029- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
37030+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
37031 if (ret)
37032 return -EFAULT;
37033 } else {
37034@@ -785,7 +785,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
37035 if (!port_has_data(port) && !port->host_connected)
37036 return 0;
37037
37038- return fill_readbuf(port, ubuf, count, true);
37039+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
37040 }
37041
37042 static int wait_port_writable(struct port *port, bool nonblock)
37043diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
37044index a33f46f..a720eed 100644
37045--- a/drivers/clk/clk-composite.c
37046+++ b/drivers/clk/clk-composite.c
37047@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
37048 struct clk *clk;
37049 struct clk_init_data init;
37050 struct clk_composite *composite;
37051- struct clk_ops *clk_composite_ops;
37052+ clk_ops_no_const *clk_composite_ops;
37053
37054 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
37055 if (!composite) {
37056diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
37057index 5bb848c..f00ff83 100644
37058--- a/drivers/clk/socfpga/clk.c
37059+++ b/drivers/clk/socfpga/clk.c
37060@@ -22,6 +22,7 @@
37061 #include <linux/clk-provider.h>
37062 #include <linux/io.h>
37063 #include <linux/of.h>
37064+#include <asm/pgtable.h>
37065
37066 /* Clock Manager offsets */
37067 #define CLKMGR_CTRL 0x0
37068@@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
37069 streq(clk_name, "periph_pll") ||
37070 streq(clk_name, "sdram_pll")) {
37071 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
37072- clk_pll_ops.enable = clk_gate_ops.enable;
37073- clk_pll_ops.disable = clk_gate_ops.disable;
37074+ pax_open_kernel();
37075+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
37076+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
37077+ pax_close_kernel();
37078 }
37079
37080 clk = clk_register(NULL, &socfpga_clk->hw.hw);
37081diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
37082index 3926402..37b580d 100644
37083--- a/drivers/cpufreq/acpi-cpufreq.c
37084+++ b/drivers/cpufreq/acpi-cpufreq.c
37085@@ -173,7 +173,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
37086 return sprintf(buf, "%u\n", boost_enabled);
37087 }
37088
37089-static struct global_attr global_boost = __ATTR(boost, 0644,
37090+static global_attr_no_const global_boost = __ATTR(boost, 0644,
37091 show_global_boost,
37092 store_global_boost);
37093
37094@@ -722,8 +722,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37095 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
37096 per_cpu(acfreq_data, cpu) = data;
37097
37098- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
37099- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37100+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
37101+ pax_open_kernel();
37102+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37103+ pax_close_kernel();
37104+ }
37105
37106 result = acpi_processor_register_performance(data->acpi_data, cpu);
37107 if (result)
37108@@ -851,7 +854,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37109 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
37110 break;
37111 case ACPI_ADR_SPACE_FIXED_HARDWARE:
37112- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37113+ pax_open_kernel();
37114+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37115+ pax_close_kernel();
37116 policy->cur = get_cur_freq_on_cpu(cpu);
37117 break;
37118 default:
37119@@ -862,8 +867,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37120 acpi_processor_notify_smm(THIS_MODULE);
37121
37122 /* Check for APERF/MPERF support in hardware */
37123- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
37124- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
37125+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
37126+ pax_open_kernel();
37127+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
37128+ pax_close_kernel();
37129+ }
37130
37131 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
37132 for (i = 0; i < perf->state_count; i++)
37133diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
37134index f0a5e2b..0a7ee46 100644
37135--- a/drivers/cpufreq/cpufreq.c
37136+++ b/drivers/cpufreq/cpufreq.c
37137@@ -1959,7 +1959,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
37138 return NOTIFY_OK;
37139 }
37140
37141-static struct notifier_block __refdata cpufreq_cpu_notifier = {
37142+static struct notifier_block cpufreq_cpu_notifier = {
37143 .notifier_call = cpufreq_cpu_callback,
37144 };
37145
37146@@ -1991,8 +1991,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
37147
37148 pr_debug("trying to register driver %s\n", driver_data->name);
37149
37150- if (driver_data->setpolicy)
37151- driver_data->flags |= CPUFREQ_CONST_LOOPS;
37152+ if (driver_data->setpolicy) {
37153+ pax_open_kernel();
37154+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
37155+ pax_close_kernel();
37156+ }
37157
37158 write_lock_irqsave(&cpufreq_driver_lock, flags);
37159 if (cpufreq_driver) {
37160diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
37161index e59afaa..a53a3ff 100644
37162--- a/drivers/cpufreq/cpufreq_governor.c
37163+++ b/drivers/cpufreq/cpufreq_governor.c
37164@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37165 struct dbs_data *dbs_data;
37166 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
37167 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
37168- struct od_ops *od_ops = NULL;
37169+ const struct od_ops *od_ops = NULL;
37170 struct od_dbs_tuners *od_tuners = NULL;
37171 struct cs_dbs_tuners *cs_tuners = NULL;
37172 struct cpu_dbs_common_info *cpu_cdbs;
37173@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37174
37175 if ((cdata->governor == GOV_CONSERVATIVE) &&
37176 (!policy->governor->initialized)) {
37177- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37178+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37179
37180 cpufreq_register_notifier(cs_ops->notifier_block,
37181 CPUFREQ_TRANSITION_NOTIFIER);
37182@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37183
37184 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
37185 (policy->governor->initialized == 1)) {
37186- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37187+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37188
37189 cpufreq_unregister_notifier(cs_ops->notifier_block,
37190 CPUFREQ_TRANSITION_NOTIFIER);
37191diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
37192index d5f12b4..421daae 100644
37193--- a/drivers/cpufreq/cpufreq_governor.h
37194+++ b/drivers/cpufreq/cpufreq_governor.h
37195@@ -204,7 +204,7 @@ struct common_dbs_data {
37196 void (*exit)(struct dbs_data *dbs_data);
37197
37198 /* Governor specific ops, see below */
37199- void *gov_ops;
37200+ const void *gov_ops;
37201 };
37202
37203 /* Governer Per policy data */
37204diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
37205index c087347..dad6268 100644
37206--- a/drivers/cpufreq/cpufreq_ondemand.c
37207+++ b/drivers/cpufreq/cpufreq_ondemand.c
37208@@ -615,14 +615,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
37209 (struct cpufreq_policy *, unsigned int, unsigned int),
37210 unsigned int powersave_bias)
37211 {
37212- od_ops.powersave_bias_target = f;
37213+ pax_open_kernel();
37214+ *(void **)&od_ops.powersave_bias_target = f;
37215+ pax_close_kernel();
37216 od_set_powersave_bias(powersave_bias);
37217 }
37218 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
37219
37220 void od_unregister_powersave_bias_handler(void)
37221 {
37222- od_ops.powersave_bias_target = generic_powersave_bias_target;
37223+ pax_open_kernel();
37224+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
37225+ pax_close_kernel();
37226 od_set_powersave_bias(0);
37227 }
37228 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
37229diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
37230index d37568c..fbb19a1 100644
37231--- a/drivers/cpufreq/cpufreq_stats.c
37232+++ b/drivers/cpufreq/cpufreq_stats.c
37233@@ -365,7 +365,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
37234 }
37235
37236 /* priority=1 so this will get called before cpufreq_remove_dev */
37237-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
37238+static struct notifier_block cpufreq_stat_cpu_notifier = {
37239 .notifier_call = cpufreq_stat_cpu_callback,
37240 .priority = 1,
37241 };
37242diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
37243index 9ee7817..17b658e 100644
37244--- a/drivers/cpufreq/p4-clockmod.c
37245+++ b/drivers/cpufreq/p4-clockmod.c
37246@@ -160,10 +160,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37247 case 0x0F: /* Core Duo */
37248 case 0x16: /* Celeron Core */
37249 case 0x1C: /* Atom */
37250- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37251+ pax_open_kernel();
37252+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37253+ pax_close_kernel();
37254 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
37255 case 0x0D: /* Pentium M (Dothan) */
37256- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37257+ pax_open_kernel();
37258+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37259+ pax_close_kernel();
37260 /* fall through */
37261 case 0x09: /* Pentium M (Banias) */
37262 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
37263@@ -175,7 +179,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37264
37265 /* on P-4s, the TSC runs with constant frequency independent whether
37266 * throttling is active or not. */
37267- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37268+ pax_open_kernel();
37269+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37270+ pax_close_kernel();
37271
37272 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
37273 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
37274diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
37275index 880ee29..2445bc6 100644
37276--- a/drivers/cpufreq/sparc-us3-cpufreq.c
37277+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
37278@@ -18,14 +18,12 @@
37279 #include <asm/head.h>
37280 #include <asm/timer.h>
37281
37282-static struct cpufreq_driver *cpufreq_us3_driver;
37283-
37284 struct us3_freq_percpu_info {
37285 struct cpufreq_frequency_table table[4];
37286 };
37287
37288 /* Indexed by cpu number. */
37289-static struct us3_freq_percpu_info *us3_freq_table;
37290+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
37291
37292 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
37293 * in the Safari config register.
37294@@ -186,12 +184,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
37295
37296 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
37297 {
37298- if (cpufreq_us3_driver)
37299- us3_set_cpu_divider_index(policy, 0);
37300+ us3_set_cpu_divider_index(policy->cpu, 0);
37301
37302 return 0;
37303 }
37304
37305+static int __init us3_freq_init(void);
37306+static void __exit us3_freq_exit(void);
37307+
37308+static struct cpufreq_driver cpufreq_us3_driver = {
37309+ .init = us3_freq_cpu_init,
37310+ .verify = us3_freq_verify,
37311+ .target = us3_freq_target,
37312+ .get = us3_freq_get,
37313+ .exit = us3_freq_cpu_exit,
37314+ .owner = THIS_MODULE,
37315+ .name = "UltraSPARC-III",
37316+
37317+};
37318+
37319 static int __init us3_freq_init(void)
37320 {
37321 unsigned long manuf, impl, ver;
37322@@ -208,57 +219,15 @@ static int __init us3_freq_init(void)
37323 (impl == CHEETAH_IMPL ||
37324 impl == CHEETAH_PLUS_IMPL ||
37325 impl == JAGUAR_IMPL ||
37326- impl == PANTHER_IMPL)) {
37327- struct cpufreq_driver *driver;
37328-
37329- ret = -ENOMEM;
37330- driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
37331- if (!driver)
37332- goto err_out;
37333-
37334- us3_freq_table = kzalloc(
37335- (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
37336- GFP_KERNEL);
37337- if (!us3_freq_table)
37338- goto err_out;
37339-
37340- driver->init = us3_freq_cpu_init;
37341- driver->verify = us3_freq_verify;
37342- driver->target = us3_freq_target;
37343- driver->get = us3_freq_get;
37344- driver->exit = us3_freq_cpu_exit;
37345- driver->owner = THIS_MODULE,
37346- strcpy(driver->name, "UltraSPARC-III");
37347-
37348- cpufreq_us3_driver = driver;
37349- ret = cpufreq_register_driver(driver);
37350- if (ret)
37351- goto err_out;
37352-
37353- return 0;
37354-
37355-err_out:
37356- if (driver) {
37357- kfree(driver);
37358- cpufreq_us3_driver = NULL;
37359- }
37360- kfree(us3_freq_table);
37361- us3_freq_table = NULL;
37362- return ret;
37363- }
37364+ impl == PANTHER_IMPL))
37365+ return cpufreq_register_driver(&cpufreq_us3_driver);
37366
37367 return -ENODEV;
37368 }
37369
37370 static void __exit us3_freq_exit(void)
37371 {
37372- if (cpufreq_us3_driver) {
37373- cpufreq_unregister_driver(cpufreq_us3_driver);
37374- kfree(cpufreq_us3_driver);
37375- cpufreq_us3_driver = NULL;
37376- kfree(us3_freq_table);
37377- us3_freq_table = NULL;
37378- }
37379+ cpufreq_unregister_driver(&cpufreq_us3_driver);
37380 }
37381
37382 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
37383diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
37384index 0915e71..53376ed 100644
37385--- a/drivers/cpufreq/speedstep-centrino.c
37386+++ b/drivers/cpufreq/speedstep-centrino.c
37387@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
37388 !cpu_has(cpu, X86_FEATURE_EST))
37389 return -ENODEV;
37390
37391- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
37392- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37393+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
37394+ pax_open_kernel();
37395+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37396+ pax_close_kernel();
37397+ }
37398
37399 if (policy->cpu != 0)
37400 return -ENODEV;
37401diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
37402index fdc432f..98e64e2 100644
37403--- a/drivers/cpuidle/cpuidle.c
37404+++ b/drivers/cpuidle/cpuidle.c
37405@@ -254,7 +254,7 @@ static int poll_idle(struct cpuidle_device *dev,
37406
37407 static void poll_idle_init(struct cpuidle_driver *drv)
37408 {
37409- struct cpuidle_state *state = &drv->states[0];
37410+ cpuidle_state_no_const *state = &drv->states[0];
37411
37412 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
37413 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
37414diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
37415index ea2f8e7..70ac501 100644
37416--- a/drivers/cpuidle/governor.c
37417+++ b/drivers/cpuidle/governor.c
37418@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
37419 mutex_lock(&cpuidle_lock);
37420 if (__cpuidle_find_governor(gov->name) == NULL) {
37421 ret = 0;
37422- list_add_tail(&gov->governor_list, &cpuidle_governors);
37423+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
37424 if (!cpuidle_curr_governor ||
37425 cpuidle_curr_governor->rating < gov->rating)
37426 cpuidle_switch_governor(gov);
37427@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
37428 new_gov = cpuidle_replace_governor(gov->rating);
37429 cpuidle_switch_governor(new_gov);
37430 }
37431- list_del(&gov->governor_list);
37432+ pax_list_del((struct list_head *)&gov->governor_list);
37433 mutex_unlock(&cpuidle_lock);
37434 }
37435
37436diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
37437index 428754a..8bdf9cc 100644
37438--- a/drivers/cpuidle/sysfs.c
37439+++ b/drivers/cpuidle/sysfs.c
37440@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
37441 NULL
37442 };
37443
37444-static struct attribute_group cpuidle_attr_group = {
37445+static attribute_group_no_const cpuidle_attr_group = {
37446 .attrs = cpuidle_default_attrs,
37447 .name = "cpuidle",
37448 };
37449diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
37450index 12fea3e..1e28f47 100644
37451--- a/drivers/crypto/hifn_795x.c
37452+++ b/drivers/crypto/hifn_795x.c
37453@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
37454 MODULE_PARM_DESC(hifn_pll_ref,
37455 "PLL reference clock (pci[freq] or ext[freq], default ext)");
37456
37457-static atomic_t hifn_dev_number;
37458+static atomic_unchecked_t hifn_dev_number;
37459
37460 #define ACRYPTO_OP_DECRYPT 0
37461 #define ACRYPTO_OP_ENCRYPT 1
37462@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
37463 goto err_out_disable_pci_device;
37464
37465 snprintf(name, sizeof(name), "hifn%d",
37466- atomic_inc_return(&hifn_dev_number)-1);
37467+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
37468
37469 err = pci_request_regions(pdev, name);
37470 if (err)
37471diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
37472index e94e619..f7e249c 100644
37473--- a/drivers/devfreq/devfreq.c
37474+++ b/drivers/devfreq/devfreq.c
37475@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
37476 goto err_out;
37477 }
37478
37479- list_add(&governor->node, &devfreq_governor_list);
37480+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
37481
37482 list_for_each_entry(devfreq, &devfreq_list, node) {
37483 int ret = 0;
37484@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
37485 }
37486 }
37487
37488- list_del(&governor->node);
37489+ pax_list_del((struct list_head *)&governor->node);
37490 err_out:
37491 mutex_unlock(&devfreq_list_lock);
37492
37493diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
37494index 5039fbc..841169f 100644
37495--- a/drivers/dma/sh/shdma.c
37496+++ b/drivers/dma/sh/shdma.c
37497@@ -488,7 +488,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
37498 return ret;
37499 }
37500
37501-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
37502+static struct notifier_block sh_dmae_nmi_notifier = {
37503 .notifier_call = sh_dmae_nmi_handler,
37504
37505 /* Run before NMI debug handler and KGDB */
37506diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
37507index 211021d..201d47f 100644
37508--- a/drivers/edac/edac_device.c
37509+++ b/drivers/edac/edac_device.c
37510@@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
37511 */
37512 int edac_device_alloc_index(void)
37513 {
37514- static atomic_t device_indexes = ATOMIC_INIT(0);
37515+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
37516
37517- return atomic_inc_return(&device_indexes) - 1;
37518+ return atomic_inc_return_unchecked(&device_indexes) - 1;
37519 }
37520 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
37521
37522diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
37523index e7c32c4..6397af1 100644
37524--- a/drivers/edac/edac_mc_sysfs.c
37525+++ b/drivers/edac/edac_mc_sysfs.c
37526@@ -148,7 +148,7 @@ static const char * const edac_caps[] = {
37527 struct dev_ch_attribute {
37528 struct device_attribute attr;
37529 int channel;
37530-};
37531+} __do_const;
37532
37533 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
37534 struct dev_ch_attribute dev_attr_legacy_##_name = \
37535@@ -1005,14 +1005,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
37536 }
37537
37538 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
37539+ pax_open_kernel();
37540 if (mci->get_sdram_scrub_rate) {
37541- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37542- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37543+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37544+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37545 }
37546 if (mci->set_sdram_scrub_rate) {
37547- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37548- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37549+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37550+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37551 }
37552+ pax_close_kernel();
37553 err = device_create_file(&mci->dev,
37554 &dev_attr_sdram_scrub_rate);
37555 if (err) {
37556diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
37557index dd370f9..0281629 100644
37558--- a/drivers/edac/edac_pci.c
37559+++ b/drivers/edac/edac_pci.c
37560@@ -29,7 +29,7 @@
37561
37562 static DEFINE_MUTEX(edac_pci_ctls_mutex);
37563 static LIST_HEAD(edac_pci_list);
37564-static atomic_t pci_indexes = ATOMIC_INIT(0);
37565+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
37566
37567 /*
37568 * edac_pci_alloc_ctl_info
37569@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
37570 */
37571 int edac_pci_alloc_index(void)
37572 {
37573- return atomic_inc_return(&pci_indexes) - 1;
37574+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
37575 }
37576 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
37577
37578diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
37579index e8658e4..22746d6 100644
37580--- a/drivers/edac/edac_pci_sysfs.c
37581+++ b/drivers/edac/edac_pci_sysfs.c
37582@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
37583 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
37584 static int edac_pci_poll_msec = 1000; /* one second workq period */
37585
37586-static atomic_t pci_parity_count = ATOMIC_INIT(0);
37587-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
37588+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
37589+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
37590
37591 static struct kobject *edac_pci_top_main_kobj;
37592 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
37593@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
37594 void *value;
37595 ssize_t(*show) (void *, char *);
37596 ssize_t(*store) (void *, const char *, size_t);
37597-};
37598+} __do_const;
37599
37600 /* Set of show/store abstract level functions for PCI Parity object */
37601 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
37602@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37603 edac_printk(KERN_CRIT, EDAC_PCI,
37604 "Signaled System Error on %s\n",
37605 pci_name(dev));
37606- atomic_inc(&pci_nonparity_count);
37607+ atomic_inc_unchecked(&pci_nonparity_count);
37608 }
37609
37610 if (status & (PCI_STATUS_PARITY)) {
37611@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37612 "Master Data Parity Error on %s\n",
37613 pci_name(dev));
37614
37615- atomic_inc(&pci_parity_count);
37616+ atomic_inc_unchecked(&pci_parity_count);
37617 }
37618
37619 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37620@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37621 "Detected Parity Error on %s\n",
37622 pci_name(dev));
37623
37624- atomic_inc(&pci_parity_count);
37625+ atomic_inc_unchecked(&pci_parity_count);
37626 }
37627 }
37628
37629@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37630 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
37631 "Signaled System Error on %s\n",
37632 pci_name(dev));
37633- atomic_inc(&pci_nonparity_count);
37634+ atomic_inc_unchecked(&pci_nonparity_count);
37635 }
37636
37637 if (status & (PCI_STATUS_PARITY)) {
37638@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37639 "Master Data Parity Error on "
37640 "%s\n", pci_name(dev));
37641
37642- atomic_inc(&pci_parity_count);
37643+ atomic_inc_unchecked(&pci_parity_count);
37644 }
37645
37646 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37647@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37648 "Detected Parity Error on %s\n",
37649 pci_name(dev));
37650
37651- atomic_inc(&pci_parity_count);
37652+ atomic_inc_unchecked(&pci_parity_count);
37653 }
37654 }
37655 }
37656@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
37657 if (!check_pci_errors)
37658 return;
37659
37660- before_count = atomic_read(&pci_parity_count);
37661+ before_count = atomic_read_unchecked(&pci_parity_count);
37662
37663 /* scan all PCI devices looking for a Parity Error on devices and
37664 * bridges.
37665@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
37666 /* Only if operator has selected panic on PCI Error */
37667 if (edac_pci_get_panic_on_pe()) {
37668 /* If the count is different 'after' from 'before' */
37669- if (before_count != atomic_read(&pci_parity_count))
37670+ if (before_count != atomic_read_unchecked(&pci_parity_count))
37671 panic("EDAC: PCI Parity Error");
37672 }
37673 }
37674diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
37675index 51b7e3a..aa8a3e8 100644
37676--- a/drivers/edac/mce_amd.h
37677+++ b/drivers/edac/mce_amd.h
37678@@ -77,7 +77,7 @@ struct amd_decoder_ops {
37679 bool (*mc0_mce)(u16, u8);
37680 bool (*mc1_mce)(u16, u8);
37681 bool (*mc2_mce)(u16, u8);
37682-};
37683+} __no_const;
37684
37685 void amd_report_gart_errors(bool);
37686 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
37687diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
37688index 57ea7f4..af06b76 100644
37689--- a/drivers/firewire/core-card.c
37690+++ b/drivers/firewire/core-card.c
37691@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
37692 const struct fw_card_driver *driver,
37693 struct device *device)
37694 {
37695- static atomic_t index = ATOMIC_INIT(-1);
37696+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
37697
37698- card->index = atomic_inc_return(&index);
37699+ card->index = atomic_inc_return_unchecked(&index);
37700 card->driver = driver;
37701 card->device = device;
37702 card->current_tlabel = 0;
37703@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
37704
37705 void fw_core_remove_card(struct fw_card *card)
37706 {
37707- struct fw_card_driver dummy_driver = dummy_driver_template;
37708+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
37709
37710 card->driver->update_phy_reg(card, 4,
37711 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
37712diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
37713index de4aa40..49ab1f2 100644
37714--- a/drivers/firewire/core-device.c
37715+++ b/drivers/firewire/core-device.c
37716@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
37717 struct config_rom_attribute {
37718 struct device_attribute attr;
37719 u32 key;
37720-};
37721+} __do_const;
37722
37723 static ssize_t show_immediate(struct device *dev,
37724 struct device_attribute *dattr, char *buf)
37725diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
37726index 28a94c7..58da63a 100644
37727--- a/drivers/firewire/core-transaction.c
37728+++ b/drivers/firewire/core-transaction.c
37729@@ -38,6 +38,7 @@
37730 #include <linux/timer.h>
37731 #include <linux/types.h>
37732 #include <linux/workqueue.h>
37733+#include <linux/sched.h>
37734
37735 #include <asm/byteorder.h>
37736
37737diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
37738index 515a42c..5ecf3ba 100644
37739--- a/drivers/firewire/core.h
37740+++ b/drivers/firewire/core.h
37741@@ -111,6 +111,7 @@ struct fw_card_driver {
37742
37743 int (*stop_iso)(struct fw_iso_context *ctx);
37744 };
37745+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
37746
37747 void fw_card_initialize(struct fw_card *card,
37748 const struct fw_card_driver *driver, struct device *device);
37749diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
37750index 94a58a0..f5eba42 100644
37751--- a/drivers/firmware/dmi-id.c
37752+++ b/drivers/firmware/dmi-id.c
37753@@ -16,7 +16,7 @@
37754 struct dmi_device_attribute{
37755 struct device_attribute dev_attr;
37756 int field;
37757-};
37758+} __do_const;
37759 #define to_dmi_dev_attr(_dev_attr) \
37760 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
37761
37762diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
37763index 232fa8f..386c255 100644
37764--- a/drivers/firmware/dmi_scan.c
37765+++ b/drivers/firmware/dmi_scan.c
37766@@ -504,11 +504,6 @@ void __init dmi_scan_machine(void)
37767 }
37768 }
37769 else {
37770- /*
37771- * no iounmap() for that ioremap(); it would be a no-op, but
37772- * it's so early in setup that sucker gets confused into doing
37773- * what it shouldn't if we actually call it.
37774- */
37775 p = dmi_ioremap(0xF0000, 0x10000);
37776 if (p == NULL)
37777 goto error;
37778@@ -806,7 +801,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
37779 if (buf == NULL)
37780 return -1;
37781
37782- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
37783+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
37784
37785 iounmap(buf);
37786 return 0;
37787diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
37788index 5145fa3..0d3babd 100644
37789--- a/drivers/firmware/efi/efi.c
37790+++ b/drivers/firmware/efi/efi.c
37791@@ -65,14 +65,16 @@ static struct attribute_group efi_subsys_attr_group = {
37792 };
37793
37794 static struct efivars generic_efivars;
37795-static struct efivar_operations generic_ops;
37796+static efivar_operations_no_const generic_ops __read_only;
37797
37798 static int generic_ops_register(void)
37799 {
37800- generic_ops.get_variable = efi.get_variable;
37801- generic_ops.set_variable = efi.set_variable;
37802- generic_ops.get_next_variable = efi.get_next_variable;
37803- generic_ops.query_variable_store = efi_query_variable_store;
37804+ pax_open_kernel();
37805+ *(void **)&generic_ops.get_variable = efi.get_variable;
37806+ *(void **)&generic_ops.set_variable = efi.set_variable;
37807+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
37808+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
37809+ pax_close_kernel();
37810
37811 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
37812 }
37813diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
37814index 8a7432a..28fb839 100644
37815--- a/drivers/firmware/efi/efivars.c
37816+++ b/drivers/firmware/efi/efivars.c
37817@@ -452,7 +452,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
37818 static int
37819 create_efivars_bin_attributes(void)
37820 {
37821- struct bin_attribute *attr;
37822+ bin_attribute_no_const *attr;
37823 int error;
37824
37825 /* new_var */
37826diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
37827index 2a90ba6..07f3733 100644
37828--- a/drivers/firmware/google/memconsole.c
37829+++ b/drivers/firmware/google/memconsole.c
37830@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
37831 if (!found_memconsole())
37832 return -ENODEV;
37833
37834- memconsole_bin_attr.size = memconsole_length;
37835+ pax_open_kernel();
37836+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
37837+ pax_close_kernel();
37838
37839 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
37840
37841diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
37842index 2729e3d..f9deca1 100644
37843--- a/drivers/gpio/gpio-ich.c
37844+++ b/drivers/gpio/gpio-ich.c
37845@@ -71,7 +71,7 @@ struct ichx_desc {
37846 /* Some chipsets have quirks, let these use their own request/get */
37847 int (*request)(struct gpio_chip *chip, unsigned offset);
37848 int (*get)(struct gpio_chip *chip, unsigned offset);
37849-};
37850+} __do_const;
37851
37852 static struct {
37853 spinlock_t lock;
37854diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
37855index 9902732..64b62dd 100644
37856--- a/drivers/gpio/gpio-vr41xx.c
37857+++ b/drivers/gpio/gpio-vr41xx.c
37858@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
37859 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
37860 maskl, pendl, maskh, pendh);
37861
37862- atomic_inc(&irq_err_count);
37863+ atomic_inc_unchecked(&irq_err_count);
37864
37865 return -EINVAL;
37866 }
37867diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
37868index 6a64749..0767a9f 100644
37869--- a/drivers/gpu/drm/drm_crtc_helper.c
37870+++ b/drivers/gpu/drm/drm_crtc_helper.c
37871@@ -322,7 +322,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
37872 struct drm_crtc *tmp;
37873 int crtc_mask = 1;
37874
37875- WARN(!crtc, "checking null crtc?\n");
37876+ BUG_ON(!crtc);
37877
37878 dev = crtc->dev;
37879
37880diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
37881index 99fcd7c..13cf6c5 100644
37882--- a/drivers/gpu/drm/drm_drv.c
37883+++ b/drivers/gpu/drm/drm_drv.c
37884@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
37885 /**
37886 * Copy and IOCTL return string to user space
37887 */
37888-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
37889+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
37890 {
37891 int len;
37892
37893@@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
37894 struct drm_file *file_priv = filp->private_data;
37895 struct drm_device *dev;
37896 const struct drm_ioctl_desc *ioctl = NULL;
37897- drm_ioctl_t *func;
37898+ drm_ioctl_no_const_t func;
37899 unsigned int nr = DRM_IOCTL_NR(cmd);
37900 int retcode = -EINVAL;
37901 char stack_kdata[128];
37902@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
37903 return -ENODEV;
37904
37905 atomic_inc(&dev->ioctl_count);
37906- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
37907+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
37908 ++file_priv->ioctl_count;
37909
37910 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
37911diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
37912index 3a24385..4e426e0 100644
37913--- a/drivers/gpu/drm/drm_fops.c
37914+++ b/drivers/gpu/drm/drm_fops.c
37915@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
37916 }
37917
37918 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
37919- atomic_set(&dev->counts[i], 0);
37920+ atomic_set_unchecked(&dev->counts[i], 0);
37921
37922 dev->sigdata.lock = NULL;
37923
37924@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
37925 if (drm_device_is_unplugged(dev))
37926 return -ENODEV;
37927
37928- if (!dev->open_count++)
37929+ if (local_inc_return(&dev->open_count) == 1)
37930 need_setup = 1;
37931 mutex_lock(&dev->struct_mutex);
37932 old_imapping = inode->i_mapping;
37933@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
37934 retcode = drm_open_helper(inode, filp, dev);
37935 if (retcode)
37936 goto err_undo;
37937- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
37938+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
37939 if (need_setup) {
37940 retcode = drm_setup(dev);
37941 if (retcode)
37942@@ -166,7 +166,7 @@ err_undo:
37943 iput(container_of(dev->dev_mapping, struct inode, i_data));
37944 dev->dev_mapping = old_mapping;
37945 mutex_unlock(&dev->struct_mutex);
37946- dev->open_count--;
37947+ local_dec(&dev->open_count);
37948 return retcode;
37949 }
37950 EXPORT_SYMBOL(drm_open);
37951@@ -456,7 +456,7 @@ int drm_release(struct inode *inode, struct file *filp)
37952
37953 mutex_lock(&drm_global_mutex);
37954
37955- DRM_DEBUG("open_count = %d\n", dev->open_count);
37956+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
37957
37958 if (dev->driver->preclose)
37959 dev->driver->preclose(dev, file_priv);
37960@@ -465,10 +465,10 @@ int drm_release(struct inode *inode, struct file *filp)
37961 * Begin inline drm_release
37962 */
37963
37964- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
37965+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
37966 task_pid_nr(current),
37967 (long)old_encode_dev(file_priv->minor->device),
37968- dev->open_count);
37969+ local_read(&dev->open_count));
37970
37971 /* Release any auth tokens that might point to this file_priv,
37972 (do that under the drm_global_mutex) */
37973@@ -565,8 +565,8 @@ int drm_release(struct inode *inode, struct file *filp)
37974 * End inline drm_release
37975 */
37976
37977- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
37978- if (!--dev->open_count) {
37979+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
37980+ if (local_dec_and_test(&dev->open_count)) {
37981 if (atomic_read(&dev->ioctl_count)) {
37982 DRM_ERROR("Device busy: %d\n",
37983 atomic_read(&dev->ioctl_count));
37984diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
37985index f731116..629842c 100644
37986--- a/drivers/gpu/drm/drm_global.c
37987+++ b/drivers/gpu/drm/drm_global.c
37988@@ -36,7 +36,7 @@
37989 struct drm_global_item {
37990 struct mutex mutex;
37991 void *object;
37992- int refcount;
37993+ atomic_t refcount;
37994 };
37995
37996 static struct drm_global_item glob[DRM_GLOBAL_NUM];
37997@@ -49,7 +49,7 @@ void drm_global_init(void)
37998 struct drm_global_item *item = &glob[i];
37999 mutex_init(&item->mutex);
38000 item->object = NULL;
38001- item->refcount = 0;
38002+ atomic_set(&item->refcount, 0);
38003 }
38004 }
38005
38006@@ -59,7 +59,7 @@ void drm_global_release(void)
38007 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
38008 struct drm_global_item *item = &glob[i];
38009 BUG_ON(item->object != NULL);
38010- BUG_ON(item->refcount != 0);
38011+ BUG_ON(atomic_read(&item->refcount) != 0);
38012 }
38013 }
38014
38015@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38016 void *object;
38017
38018 mutex_lock(&item->mutex);
38019- if (item->refcount == 0) {
38020+ if (atomic_read(&item->refcount) == 0) {
38021 item->object = kzalloc(ref->size, GFP_KERNEL);
38022 if (unlikely(item->object == NULL)) {
38023 ret = -ENOMEM;
38024@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38025 goto out_err;
38026
38027 }
38028- ++item->refcount;
38029+ atomic_inc(&item->refcount);
38030 ref->object = item->object;
38031 object = item->object;
38032 mutex_unlock(&item->mutex);
38033@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
38034 struct drm_global_item *item = &glob[ref->global_type];
38035
38036 mutex_lock(&item->mutex);
38037- BUG_ON(item->refcount == 0);
38038+ BUG_ON(atomic_read(&item->refcount) == 0);
38039 BUG_ON(ref->object != item->object);
38040- if (--item->refcount == 0) {
38041+ if (atomic_dec_and_test(&item->refcount)) {
38042 ref->release(ref);
38043 item->object = NULL;
38044 }
38045diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
38046index d4b20ce..77a8d41 100644
38047--- a/drivers/gpu/drm/drm_info.c
38048+++ b/drivers/gpu/drm/drm_info.c
38049@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
38050 struct drm_local_map *map;
38051 struct drm_map_list *r_list;
38052
38053- /* Hardcoded from _DRM_FRAME_BUFFER,
38054- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
38055- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
38056- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
38057+ static const char * const types[] = {
38058+ [_DRM_FRAME_BUFFER] = "FB",
38059+ [_DRM_REGISTERS] = "REG",
38060+ [_DRM_SHM] = "SHM",
38061+ [_DRM_AGP] = "AGP",
38062+ [_DRM_SCATTER_GATHER] = "SG",
38063+ [_DRM_CONSISTENT] = "PCI",
38064+ [_DRM_GEM] = "GEM" };
38065 const char *type;
38066 int i;
38067
38068@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
38069 map = r_list->map;
38070 if (!map)
38071 continue;
38072- if (map->type < 0 || map->type > 5)
38073+ if (map->type >= ARRAY_SIZE(types))
38074 type = "??";
38075 else
38076 type = types[map->type];
38077@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
38078 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
38079 vma->vm_flags & VM_LOCKED ? 'l' : '-',
38080 vma->vm_flags & VM_IO ? 'i' : '-',
38081+#ifdef CONFIG_GRKERNSEC_HIDESYM
38082+ 0);
38083+#else
38084 vma->vm_pgoff);
38085+#endif
38086
38087 #if defined(__i386__)
38088 pgprot = pgprot_val(vma->vm_page_prot);
38089diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
38090index 2f4c434..dd12cd2 100644
38091--- a/drivers/gpu/drm/drm_ioc32.c
38092+++ b/drivers/gpu/drm/drm_ioc32.c
38093@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
38094 request = compat_alloc_user_space(nbytes);
38095 if (!access_ok(VERIFY_WRITE, request, nbytes))
38096 return -EFAULT;
38097- list = (struct drm_buf_desc *) (request + 1);
38098+ list = (struct drm_buf_desc __user *) (request + 1);
38099
38100 if (__put_user(count, &request->count)
38101 || __put_user(list, &request->list))
38102@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
38103 request = compat_alloc_user_space(nbytes);
38104 if (!access_ok(VERIFY_WRITE, request, nbytes))
38105 return -EFAULT;
38106- list = (struct drm_buf_pub *) (request + 1);
38107+ list = (struct drm_buf_pub __user *) (request + 1);
38108
38109 if (__put_user(count, &request->count)
38110 || __put_user(list, &request->list))
38111@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
38112 return 0;
38113 }
38114
38115-drm_ioctl_compat_t *drm_compat_ioctls[] = {
38116+drm_ioctl_compat_t drm_compat_ioctls[] = {
38117 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
38118 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
38119 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
38120@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
38121 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38122 {
38123 unsigned int nr = DRM_IOCTL_NR(cmd);
38124- drm_ioctl_compat_t *fn;
38125 int ret;
38126
38127 /* Assume that ioctls without an explicit compat routine will just
38128@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38129 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
38130 return drm_ioctl(filp, cmd, arg);
38131
38132- fn = drm_compat_ioctls[nr];
38133-
38134- if (fn != NULL)
38135- ret = (*fn) (filp, cmd, arg);
38136+ if (drm_compat_ioctls[nr] != NULL)
38137+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
38138 else
38139 ret = drm_ioctl(filp, cmd, arg);
38140
38141diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
38142index ffd7a7b..a64643e 100644
38143--- a/drivers/gpu/drm/drm_ioctl.c
38144+++ b/drivers/gpu/drm/drm_ioctl.c
38145@@ -265,7 +265,7 @@ int drm_getstats(struct drm_device *dev, void *data,
38146 stats->data[i].value =
38147 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
38148 else
38149- stats->data[i].value = atomic_read(&dev->counts[i]);
38150+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
38151 stats->data[i].type = dev->types[i];
38152 }
38153
38154diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
38155index d752c96..fe08455 100644
38156--- a/drivers/gpu/drm/drm_lock.c
38157+++ b/drivers/gpu/drm/drm_lock.c
38158@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38159 if (drm_lock_take(&master->lock, lock->context)) {
38160 master->lock.file_priv = file_priv;
38161 master->lock.lock_time = jiffies;
38162- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
38163+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
38164 break; /* Got lock */
38165 }
38166
38167@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38168 return -EINVAL;
38169 }
38170
38171- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
38172+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
38173
38174 if (drm_lock_free(&master->lock, lock->context)) {
38175 /* FIXME: Should really bail out here. */
38176diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
38177index 327ca19..684d3c0 100644
38178--- a/drivers/gpu/drm/drm_stub.c
38179+++ b/drivers/gpu/drm/drm_stub.c
38180@@ -495,7 +495,7 @@ void drm_unplug_dev(struct drm_device *dev)
38181
38182 drm_device_set_unplugged(dev);
38183
38184- if (dev->open_count == 0) {
38185+ if (local_read(&dev->open_count) == 0) {
38186 drm_put_dev(dev);
38187 }
38188 mutex_unlock(&drm_global_mutex);
38189diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
38190index 2290b3b..22056a1 100644
38191--- a/drivers/gpu/drm/drm_sysfs.c
38192+++ b/drivers/gpu/drm/drm_sysfs.c
38193@@ -524,7 +524,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
38194 int drm_sysfs_device_add(struct drm_minor *minor)
38195 {
38196 int err;
38197- char *minor_str;
38198+ const char *minor_str;
38199
38200 minor->kdev.parent = minor->dev->dev;
38201
38202diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
38203index ada49ed..29275a0 100644
38204--- a/drivers/gpu/drm/i810/i810_dma.c
38205+++ b/drivers/gpu/drm/i810/i810_dma.c
38206@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
38207 dma->buflist[vertex->idx],
38208 vertex->discard, vertex->used);
38209
38210- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38211- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38212+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38213+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38214 sarea_priv->last_enqueue = dev_priv->counter - 1;
38215 sarea_priv->last_dispatch = (int)hw_status[5];
38216
38217@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
38218 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
38219 mc->last_render);
38220
38221- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38222- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38223+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38224+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38225 sarea_priv->last_enqueue = dev_priv->counter - 1;
38226 sarea_priv->last_dispatch = (int)hw_status[5];
38227
38228diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
38229index 6e0acad..93c8289 100644
38230--- a/drivers/gpu/drm/i810/i810_drv.h
38231+++ b/drivers/gpu/drm/i810/i810_drv.h
38232@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
38233 int page_flipping;
38234
38235 wait_queue_head_t irq_queue;
38236- atomic_t irq_received;
38237- atomic_t irq_emitted;
38238+ atomic_unchecked_t irq_received;
38239+ atomic_unchecked_t irq_emitted;
38240
38241 int front_offset;
38242 } drm_i810_private_t;
38243diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
38244index 47d6c74..279123f 100644
38245--- a/drivers/gpu/drm/i915/i915_debugfs.c
38246+++ b/drivers/gpu/drm/i915/i915_debugfs.c
38247@@ -541,7 +541,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
38248 I915_READ(GTIMR));
38249 }
38250 seq_printf(m, "Interrupts received: %d\n",
38251- atomic_read(&dev_priv->irq_received));
38252+ atomic_read_unchecked(&dev_priv->irq_received));
38253 for_each_ring(ring, dev_priv, i) {
38254 if (IS_GEN6(dev) || IS_GEN7(dev)) {
38255 seq_printf(m,
38256diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
38257index f466980..8f2883f 100644
38258--- a/drivers/gpu/drm/i915/i915_dma.c
38259+++ b/drivers/gpu/drm/i915/i915_dma.c
38260@@ -1260,7 +1260,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
38261 bool can_switch;
38262
38263 spin_lock(&dev->count_lock);
38264- can_switch = (dev->open_count == 0);
38265+ can_switch = (local_read(&dev->open_count) == 0);
38266 spin_unlock(&dev->count_lock);
38267 return can_switch;
38268 }
38269diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
38270index 1929bff..dab130d 100644
38271--- a/drivers/gpu/drm/i915/i915_drv.h
38272+++ b/drivers/gpu/drm/i915/i915_drv.h
38273@@ -1028,7 +1028,7 @@ typedef struct drm_i915_private {
38274 drm_dma_handle_t *status_page_dmah;
38275 struct resource mch_res;
38276
38277- atomic_t irq_received;
38278+ atomic_unchecked_t irq_received;
38279
38280 /* protects the irq masks */
38281 spinlock_t irq_lock;
38282diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38283index 87a3227..cd13d8f 100644
38284--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38285+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38286@@ -727,9 +727,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
38287
38288 static int
38289 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
38290- int count)
38291+ unsigned int count)
38292 {
38293- int i;
38294+ unsigned int i;
38295 int relocs_total = 0;
38296 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
38297
38298diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
38299index 3c59584..500f2e9 100644
38300--- a/drivers/gpu/drm/i915/i915_ioc32.c
38301+++ b/drivers/gpu/drm/i915/i915_ioc32.c
38302@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
38303 (unsigned long)request);
38304 }
38305
38306-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38307+static drm_ioctl_compat_t i915_compat_ioctls[] = {
38308 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
38309 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
38310 [DRM_I915_GETPARAM] = compat_i915_getparam,
38311@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38312 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38313 {
38314 unsigned int nr = DRM_IOCTL_NR(cmd);
38315- drm_ioctl_compat_t *fn = NULL;
38316 int ret;
38317
38318 if (nr < DRM_COMMAND_BASE)
38319 return drm_compat_ioctl(filp, cmd, arg);
38320
38321- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
38322- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38323-
38324- if (fn != NULL)
38325+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
38326+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38327 ret = (*fn) (filp, cmd, arg);
38328- else
38329+ } else
38330 ret = drm_ioctl(filp, cmd, arg);
38331
38332 return ret;
38333diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
38334index 3d92a7c..9a9cfd7 100644
38335--- a/drivers/gpu/drm/i915/i915_irq.c
38336+++ b/drivers/gpu/drm/i915/i915_irq.c
38337@@ -970,7 +970,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
38338 int pipe;
38339 u32 pipe_stats[I915_MAX_PIPES];
38340
38341- atomic_inc(&dev_priv->irq_received);
38342+ atomic_inc_unchecked(&dev_priv->irq_received);
38343
38344 while (true) {
38345 iir = I915_READ(VLV_IIR);
38346@@ -1187,7 +1187,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
38347 irqreturn_t ret = IRQ_NONE;
38348 int i;
38349
38350- atomic_inc(&dev_priv->irq_received);
38351+ atomic_inc_unchecked(&dev_priv->irq_received);
38352
38353 /* We get interrupts on unclaimed registers, so check for this before we
38354 * do any I915_{READ,WRITE}. */
38355@@ -1307,7 +1307,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
38356 int ret = IRQ_NONE;
38357 u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier;
38358
38359- atomic_inc(&dev_priv->irq_received);
38360+ atomic_inc_unchecked(&dev_priv->irq_received);
38361
38362 /* disable master interrupt before clearing iir */
38363 de_ier = I915_READ(DEIER);
38364@@ -2566,7 +2566,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
38365 {
38366 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38367
38368- atomic_set(&dev_priv->irq_received, 0);
38369+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38370
38371 I915_WRITE(HWSTAM, 0xeffe);
38372
38373@@ -2588,7 +2588,7 @@ static void ivybridge_irq_preinstall(struct drm_device *dev)
38374 {
38375 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38376
38377- atomic_set(&dev_priv->irq_received, 0);
38378+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38379
38380 I915_WRITE(HWSTAM, 0xeffe);
38381
38382@@ -2616,7 +2616,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
38383 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38384 int pipe;
38385
38386- atomic_set(&dev_priv->irq_received, 0);
38387+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38388
38389 /* VLV magic */
38390 I915_WRITE(VLV_IMR, 0);
38391@@ -2928,7 +2928,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
38392 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38393 int pipe;
38394
38395- atomic_set(&dev_priv->irq_received, 0);
38396+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38397
38398 for_each_pipe(pipe)
38399 I915_WRITE(PIPESTAT(pipe), 0);
38400@@ -3007,7 +3007,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
38401 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38402 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38403
38404- atomic_inc(&dev_priv->irq_received);
38405+ atomic_inc_unchecked(&dev_priv->irq_received);
38406
38407 iir = I915_READ16(IIR);
38408 if (iir == 0)
38409@@ -3082,7 +3082,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
38410 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38411 int pipe;
38412
38413- atomic_set(&dev_priv->irq_received, 0);
38414+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38415
38416 if (I915_HAS_HOTPLUG(dev)) {
38417 I915_WRITE(PORT_HOTPLUG_EN, 0);
38418@@ -3181,7 +3181,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
38419 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38420 int pipe, ret = IRQ_NONE;
38421
38422- atomic_inc(&dev_priv->irq_received);
38423+ atomic_inc_unchecked(&dev_priv->irq_received);
38424
38425 iir = I915_READ(IIR);
38426 do {
38427@@ -3305,7 +3305,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
38428 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38429 int pipe;
38430
38431- atomic_set(&dev_priv->irq_received, 0);
38432+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38433
38434 I915_WRITE(PORT_HOTPLUG_EN, 0);
38435 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
38436@@ -3414,7 +3414,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
38437 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38438 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38439
38440- atomic_inc(&dev_priv->irq_received);
38441+ atomic_inc_unchecked(&dev_priv->irq_received);
38442
38443 iir = I915_READ(IIR);
38444
38445diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
38446index be79f47..95e150b 100644
38447--- a/drivers/gpu/drm/i915/intel_display.c
38448+++ b/drivers/gpu/drm/i915/intel_display.c
38449@@ -9418,13 +9418,13 @@ struct intel_quirk {
38450 int subsystem_vendor;
38451 int subsystem_device;
38452 void (*hook)(struct drm_device *dev);
38453-};
38454+} __do_const;
38455
38456 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
38457 struct intel_dmi_quirk {
38458 void (*hook)(struct drm_device *dev);
38459 const struct dmi_system_id (*dmi_id_list)[];
38460-};
38461+} __do_const;
38462
38463 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38464 {
38465@@ -9432,18 +9432,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38466 return 1;
38467 }
38468
38469-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38470+static const struct dmi_system_id intel_dmi_quirks_table[] = {
38471 {
38472- .dmi_id_list = &(const struct dmi_system_id[]) {
38473- {
38474- .callback = intel_dmi_reverse_brightness,
38475- .ident = "NCR Corporation",
38476- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38477- DMI_MATCH(DMI_PRODUCT_NAME, ""),
38478- },
38479- },
38480- { } /* terminating entry */
38481+ .callback = intel_dmi_reverse_brightness,
38482+ .ident = "NCR Corporation",
38483+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38484+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
38485 },
38486+ },
38487+ { } /* terminating entry */
38488+};
38489+
38490+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38491+ {
38492+ .dmi_id_list = &intel_dmi_quirks_table,
38493 .hook = quirk_invert_brightness,
38494 },
38495 };
38496diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
38497index 54558a0..2d97005 100644
38498--- a/drivers/gpu/drm/mga/mga_drv.h
38499+++ b/drivers/gpu/drm/mga/mga_drv.h
38500@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
38501 u32 clear_cmd;
38502 u32 maccess;
38503
38504- atomic_t vbl_received; /**< Number of vblanks received. */
38505+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
38506 wait_queue_head_t fence_queue;
38507- atomic_t last_fence_retired;
38508+ atomic_unchecked_t last_fence_retired;
38509 u32 next_fence_to_post;
38510
38511 unsigned int fb_cpp;
38512diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
38513index 709e90d..89a1c0d 100644
38514--- a/drivers/gpu/drm/mga/mga_ioc32.c
38515+++ b/drivers/gpu/drm/mga/mga_ioc32.c
38516@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
38517 return 0;
38518 }
38519
38520-drm_ioctl_compat_t *mga_compat_ioctls[] = {
38521+drm_ioctl_compat_t mga_compat_ioctls[] = {
38522 [DRM_MGA_INIT] = compat_mga_init,
38523 [DRM_MGA_GETPARAM] = compat_mga_getparam,
38524 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
38525@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
38526 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38527 {
38528 unsigned int nr = DRM_IOCTL_NR(cmd);
38529- drm_ioctl_compat_t *fn = NULL;
38530 int ret;
38531
38532 if (nr < DRM_COMMAND_BASE)
38533 return drm_compat_ioctl(filp, cmd, arg);
38534
38535- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
38536- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38537-
38538- if (fn != NULL)
38539+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
38540+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38541 ret = (*fn) (filp, cmd, arg);
38542- else
38543+ } else
38544 ret = drm_ioctl(filp, cmd, arg);
38545
38546 return ret;
38547diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
38548index 598c281..60d590e 100644
38549--- a/drivers/gpu/drm/mga/mga_irq.c
38550+++ b/drivers/gpu/drm/mga/mga_irq.c
38551@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
38552 if (crtc != 0)
38553 return 0;
38554
38555- return atomic_read(&dev_priv->vbl_received);
38556+ return atomic_read_unchecked(&dev_priv->vbl_received);
38557 }
38558
38559
38560@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38561 /* VBLANK interrupt */
38562 if (status & MGA_VLINEPEN) {
38563 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
38564- atomic_inc(&dev_priv->vbl_received);
38565+ atomic_inc_unchecked(&dev_priv->vbl_received);
38566 drm_handle_vblank(dev, 0);
38567 handled = 1;
38568 }
38569@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38570 if ((prim_start & ~0x03) != (prim_end & ~0x03))
38571 MGA_WRITE(MGA_PRIMEND, prim_end);
38572
38573- atomic_inc(&dev_priv->last_fence_retired);
38574+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
38575 DRM_WAKEUP(&dev_priv->fence_queue);
38576 handled = 1;
38577 }
38578@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
38579 * using fences.
38580 */
38581 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
38582- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
38583+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
38584 - *sequence) <= (1 << 23)));
38585
38586 *sequence = cur_fence;
38587diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
38588index 3e72876..d1c15ad 100644
38589--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
38590+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
38591@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
38592 struct bit_table {
38593 const char id;
38594 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
38595-};
38596+} __no_const;
38597
38598 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
38599
38600diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
38601index 41ff7e0..fa854ef 100644
38602--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
38603+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
38604@@ -92,7 +92,6 @@ struct nouveau_drm {
38605 struct drm_global_reference mem_global_ref;
38606 struct ttm_bo_global_ref bo_global_ref;
38607 struct ttm_bo_device bdev;
38608- atomic_t validate_sequence;
38609 int (*move)(struct nouveau_channel *,
38610 struct ttm_buffer_object *,
38611 struct ttm_mem_reg *, struct ttm_mem_reg *);
38612diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38613index 08214bc..9208577 100644
38614--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38615+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38616@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
38617 unsigned long arg)
38618 {
38619 unsigned int nr = DRM_IOCTL_NR(cmd);
38620- drm_ioctl_compat_t *fn = NULL;
38621+ drm_ioctl_compat_t fn = NULL;
38622 int ret;
38623
38624 if (nr < DRM_COMMAND_BASE)
38625diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
38626index 25d3495..d81aaf6 100644
38627--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
38628+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
38629@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
38630 bool can_switch;
38631
38632 spin_lock(&dev->count_lock);
38633- can_switch = (dev->open_count == 0);
38634+ can_switch = (local_read(&dev->open_count) == 0);
38635 spin_unlock(&dev->count_lock);
38636 return can_switch;
38637 }
38638diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
38639index 1dfd84c..104896c 100644
38640--- a/drivers/gpu/drm/qxl/qxl_ttm.c
38641+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
38642@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
38643 }
38644 }
38645
38646-static struct vm_operations_struct qxl_ttm_vm_ops;
38647+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
38648 static const struct vm_operations_struct *ttm_vm_ops;
38649
38650 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38651@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
38652 return r;
38653 if (unlikely(ttm_vm_ops == NULL)) {
38654 ttm_vm_ops = vma->vm_ops;
38655+ pax_open_kernel();
38656 qxl_ttm_vm_ops = *ttm_vm_ops;
38657 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
38658+ pax_close_kernel();
38659 }
38660 vma->vm_ops = &qxl_ttm_vm_ops;
38661 return 0;
38662@@ -556,25 +558,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
38663 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
38664 {
38665 #if defined(CONFIG_DEBUG_FS)
38666- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
38667- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
38668- unsigned i;
38669+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
38670+ {
38671+ .name = "qxl_mem_mm",
38672+ .show = &qxl_mm_dump_table,
38673+ },
38674+ {
38675+ .name = "qxl_surf_mm",
38676+ .show = &qxl_mm_dump_table,
38677+ }
38678+ };
38679
38680- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
38681- if (i == 0)
38682- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
38683- else
38684- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
38685- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
38686- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
38687- qxl_mem_types_list[i].driver_features = 0;
38688- if (i == 0)
38689- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38690- else
38691- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38692+ pax_open_kernel();
38693+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38694+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38695+ pax_close_kernel();
38696
38697- }
38698- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
38699+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
38700 #else
38701 return 0;
38702 #endif
38703diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
38704index d4660cf..70dbe65 100644
38705--- a/drivers/gpu/drm/r128/r128_cce.c
38706+++ b/drivers/gpu/drm/r128/r128_cce.c
38707@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
38708
38709 /* GH: Simple idle check.
38710 */
38711- atomic_set(&dev_priv->idle_count, 0);
38712+ atomic_set_unchecked(&dev_priv->idle_count, 0);
38713
38714 /* We don't support anything other than bus-mastering ring mode,
38715 * but the ring can be in either AGP or PCI space for the ring
38716diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
38717index 930c71b..499aded 100644
38718--- a/drivers/gpu/drm/r128/r128_drv.h
38719+++ b/drivers/gpu/drm/r128/r128_drv.h
38720@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
38721 int is_pci;
38722 unsigned long cce_buffers_offset;
38723
38724- atomic_t idle_count;
38725+ atomic_unchecked_t idle_count;
38726
38727 int page_flipping;
38728 int current_page;
38729 u32 crtc_offset;
38730 u32 crtc_offset_cntl;
38731
38732- atomic_t vbl_received;
38733+ atomic_unchecked_t vbl_received;
38734
38735 u32 color_fmt;
38736 unsigned int front_offset;
38737diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
38738index a954c54..9cc595c 100644
38739--- a/drivers/gpu/drm/r128/r128_ioc32.c
38740+++ b/drivers/gpu/drm/r128/r128_ioc32.c
38741@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
38742 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
38743 }
38744
38745-drm_ioctl_compat_t *r128_compat_ioctls[] = {
38746+drm_ioctl_compat_t r128_compat_ioctls[] = {
38747 [DRM_R128_INIT] = compat_r128_init,
38748 [DRM_R128_DEPTH] = compat_r128_depth,
38749 [DRM_R128_STIPPLE] = compat_r128_stipple,
38750@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
38751 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38752 {
38753 unsigned int nr = DRM_IOCTL_NR(cmd);
38754- drm_ioctl_compat_t *fn = NULL;
38755 int ret;
38756
38757 if (nr < DRM_COMMAND_BASE)
38758 return drm_compat_ioctl(filp, cmd, arg);
38759
38760- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
38761- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
38762-
38763- if (fn != NULL)
38764+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
38765+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
38766 ret = (*fn) (filp, cmd, arg);
38767- else
38768+ } else
38769 ret = drm_ioctl(filp, cmd, arg);
38770
38771 return ret;
38772diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
38773index 2ea4f09..d391371 100644
38774--- a/drivers/gpu/drm/r128/r128_irq.c
38775+++ b/drivers/gpu/drm/r128/r128_irq.c
38776@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
38777 if (crtc != 0)
38778 return 0;
38779
38780- return atomic_read(&dev_priv->vbl_received);
38781+ return atomic_read_unchecked(&dev_priv->vbl_received);
38782 }
38783
38784 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
38785@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
38786 /* VBLANK interrupt */
38787 if (status & R128_CRTC_VBLANK_INT) {
38788 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
38789- atomic_inc(&dev_priv->vbl_received);
38790+ atomic_inc_unchecked(&dev_priv->vbl_received);
38791 drm_handle_vblank(dev, 0);
38792 return IRQ_HANDLED;
38793 }
38794diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
38795index 19bb7e6..de7e2a2 100644
38796--- a/drivers/gpu/drm/r128/r128_state.c
38797+++ b/drivers/gpu/drm/r128/r128_state.c
38798@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
38799
38800 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
38801 {
38802- if (atomic_read(&dev_priv->idle_count) == 0)
38803+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
38804 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
38805 else
38806- atomic_set(&dev_priv->idle_count, 0);
38807+ atomic_set_unchecked(&dev_priv->idle_count, 0);
38808 }
38809
38810 #endif
38811diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
38812index af85299..ed9ac8d 100644
38813--- a/drivers/gpu/drm/radeon/mkregtable.c
38814+++ b/drivers/gpu/drm/radeon/mkregtable.c
38815@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
38816 regex_t mask_rex;
38817 regmatch_t match[4];
38818 char buf[1024];
38819- size_t end;
38820+ long end;
38821 int len;
38822 int done = 0;
38823 int r;
38824 unsigned o;
38825 struct offset *offset;
38826 char last_reg_s[10];
38827- int last_reg;
38828+ unsigned long last_reg;
38829
38830 if (regcomp
38831 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
38832diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
38833index 63398ae..669e045 100644
38834--- a/drivers/gpu/drm/radeon/radeon_device.c
38835+++ b/drivers/gpu/drm/radeon/radeon_device.c
38836@@ -1105,7 +1105,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
38837 bool can_switch;
38838
38839 spin_lock(&dev->count_lock);
38840- can_switch = (dev->open_count == 0);
38841+ can_switch = (local_read(&dev->open_count) == 0);
38842 spin_unlock(&dev->count_lock);
38843 return can_switch;
38844 }
38845diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
38846index b369d42..8dd04eb 100644
38847--- a/drivers/gpu/drm/radeon/radeon_drv.h
38848+++ b/drivers/gpu/drm/radeon/radeon_drv.h
38849@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
38850
38851 /* SW interrupt */
38852 wait_queue_head_t swi_queue;
38853- atomic_t swi_emitted;
38854+ atomic_unchecked_t swi_emitted;
38855 int vblank_crtc;
38856 uint32_t irq_enable_reg;
38857 uint32_t r500_disp_irq_reg;
38858diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
38859index c180df8..5fd8186 100644
38860--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
38861+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
38862@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
38863 request = compat_alloc_user_space(sizeof(*request));
38864 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
38865 || __put_user(req32.param, &request->param)
38866- || __put_user((void __user *)(unsigned long)req32.value,
38867+ || __put_user((unsigned long)req32.value,
38868 &request->value))
38869 return -EFAULT;
38870
38871@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
38872 #define compat_radeon_cp_setparam NULL
38873 #endif /* X86_64 || IA64 */
38874
38875-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
38876+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
38877 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
38878 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
38879 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
38880@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
38881 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38882 {
38883 unsigned int nr = DRM_IOCTL_NR(cmd);
38884- drm_ioctl_compat_t *fn = NULL;
38885 int ret;
38886
38887 if (nr < DRM_COMMAND_BASE)
38888 return drm_compat_ioctl(filp, cmd, arg);
38889
38890- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
38891- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
38892-
38893- if (fn != NULL)
38894+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
38895+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
38896 ret = (*fn) (filp, cmd, arg);
38897- else
38898+ } else
38899 ret = drm_ioctl(filp, cmd, arg);
38900
38901 return ret;
38902diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
38903index 8d68e97..9dcfed8 100644
38904--- a/drivers/gpu/drm/radeon/radeon_irq.c
38905+++ b/drivers/gpu/drm/radeon/radeon_irq.c
38906@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
38907 unsigned int ret;
38908 RING_LOCALS;
38909
38910- atomic_inc(&dev_priv->swi_emitted);
38911- ret = atomic_read(&dev_priv->swi_emitted);
38912+ atomic_inc_unchecked(&dev_priv->swi_emitted);
38913+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
38914
38915 BEGIN_RING(4);
38916 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
38917@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
38918 drm_radeon_private_t *dev_priv =
38919 (drm_radeon_private_t *) dev->dev_private;
38920
38921- atomic_set(&dev_priv->swi_emitted, 0);
38922+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
38923 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
38924
38925 dev->max_vblank_count = 0x001fffff;
38926diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
38927index 4d20910..6726b6d 100644
38928--- a/drivers/gpu/drm/radeon/radeon_state.c
38929+++ b/drivers/gpu/drm/radeon/radeon_state.c
38930@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
38931 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
38932 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
38933
38934- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
38935+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
38936 sarea_priv->nbox * sizeof(depth_boxes[0])))
38937 return -EFAULT;
38938
38939@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
38940 {
38941 drm_radeon_private_t *dev_priv = dev->dev_private;
38942 drm_radeon_getparam_t *param = data;
38943- int value;
38944+ int value = 0;
38945
38946 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
38947
38948diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
38949index 6c0ce89..57a2529 100644
38950--- a/drivers/gpu/drm/radeon/radeon_ttm.c
38951+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
38952@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
38953 man->size = size >> PAGE_SHIFT;
38954 }
38955
38956-static struct vm_operations_struct radeon_ttm_vm_ops;
38957+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
38958 static const struct vm_operations_struct *ttm_vm_ops = NULL;
38959
38960 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38961@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
38962 }
38963 if (unlikely(ttm_vm_ops == NULL)) {
38964 ttm_vm_ops = vma->vm_ops;
38965+ pax_open_kernel();
38966 radeon_ttm_vm_ops = *ttm_vm_ops;
38967 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
38968+ pax_close_kernel();
38969 }
38970 vma->vm_ops = &radeon_ttm_vm_ops;
38971 return 0;
38972@@ -853,38 +855,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
38973 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
38974 {
38975 #if defined(CONFIG_DEBUG_FS)
38976- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
38977- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
38978+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
38979+ {
38980+ .name = "radeon_vram_mm",
38981+ .show = &radeon_mm_dump_table,
38982+ },
38983+ {
38984+ .name = "radeon_gtt_mm",
38985+ .show = &radeon_mm_dump_table,
38986+ },
38987+ {
38988+ .name = "ttm_page_pool",
38989+ .show = &ttm_page_alloc_debugfs,
38990+ },
38991+ {
38992+ .name = "ttm_dma_page_pool",
38993+ .show = &ttm_dma_page_alloc_debugfs,
38994+ },
38995+ };
38996 unsigned i;
38997
38998- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
38999- if (i == 0)
39000- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
39001- else
39002- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
39003- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39004- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
39005- radeon_mem_types_list[i].driver_features = 0;
39006- if (i == 0)
39007- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39008- else
39009- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39010-
39011- }
39012- /* Add ttm page pool to debugfs */
39013- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
39014- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39015- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
39016- radeon_mem_types_list[i].driver_features = 0;
39017- radeon_mem_types_list[i++].data = NULL;
39018+ pax_open_kernel();
39019+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39020+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39021+ pax_close_kernel();
39022 #ifdef CONFIG_SWIOTLB
39023- if (swiotlb_nr_tbl()) {
39024- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
39025- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39026- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
39027- radeon_mem_types_list[i].driver_features = 0;
39028- radeon_mem_types_list[i++].data = NULL;
39029- }
39030+ if (swiotlb_nr_tbl())
39031+ i++;
39032 #endif
39033 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
39034
39035diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
39036index d8ddfb3..609de1d 100644
39037--- a/drivers/gpu/drm/radeon/rs690.c
39038+++ b/drivers/gpu/drm/radeon/rs690.c
39039@@ -345,9 +345,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
39040 if (max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
39041 rdev->pm.sideport_bandwidth.full)
39042 max_bandwidth = rdev->pm.sideport_bandwidth;
39043- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
39044+ read_delay_latency.full = dfixed_const(800 * 1000);
39045 read_delay_latency.full = dfixed_div(read_delay_latency,
39046 rdev->pm.igp_sideport_mclk);
39047+ a.full = dfixed_const(370);
39048+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
39049 } else {
39050 if (max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
39051 rdev->pm.k8_bandwidth.full)
39052diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
39053index dbc2def..0a9f710 100644
39054--- a/drivers/gpu/drm/ttm/ttm_memory.c
39055+++ b/drivers/gpu/drm/ttm/ttm_memory.c
39056@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
39057 zone->glob = glob;
39058 glob->zone_kernel = zone;
39059 ret = kobject_init_and_add(
39060- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39061+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39062 if (unlikely(ret != 0)) {
39063 kobject_put(&zone->kobj);
39064 return ret;
39065@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
39066 zone->glob = glob;
39067 glob->zone_dma32 = zone;
39068 ret = kobject_init_and_add(
39069- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39070+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39071 if (unlikely(ret != 0)) {
39072 kobject_put(&zone->kobj);
39073 return ret;
39074diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39075index bd2a3b4..122d9ad 100644
39076--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
39077+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39078@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
39079 static int ttm_pool_mm_shrink(struct shrinker *shrink,
39080 struct shrink_control *sc)
39081 {
39082- static atomic_t start_pool = ATOMIC_INIT(0);
39083+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
39084 unsigned i;
39085- unsigned pool_offset = atomic_add_return(1, &start_pool);
39086+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
39087 struct ttm_page_pool *pool;
39088 int shrink_pages = sc->nr_to_scan;
39089
39090diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
39091index 97e9d61..bf23c461 100644
39092--- a/drivers/gpu/drm/udl/udl_fb.c
39093+++ b/drivers/gpu/drm/udl/udl_fb.c
39094@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
39095 fb_deferred_io_cleanup(info);
39096 kfree(info->fbdefio);
39097 info->fbdefio = NULL;
39098- info->fbops->fb_mmap = udl_fb_mmap;
39099 }
39100
39101 pr_warn("released /dev/fb%d user=%d count=%d\n",
39102diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
39103index 893a650..6190d3b 100644
39104--- a/drivers/gpu/drm/via/via_drv.h
39105+++ b/drivers/gpu/drm/via/via_drv.h
39106@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
39107 typedef uint32_t maskarray_t[5];
39108
39109 typedef struct drm_via_irq {
39110- atomic_t irq_received;
39111+ atomic_unchecked_t irq_received;
39112 uint32_t pending_mask;
39113 uint32_t enable_mask;
39114 wait_queue_head_t irq_queue;
39115@@ -75,7 +75,7 @@ typedef struct drm_via_private {
39116 struct timeval last_vblank;
39117 int last_vblank_valid;
39118 unsigned usec_per_vblank;
39119- atomic_t vbl_received;
39120+ atomic_unchecked_t vbl_received;
39121 drm_via_state_t hc_state;
39122 char pci_buf[VIA_PCI_BUF_SIZE];
39123 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
39124diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
39125index ac98964..5dbf512 100644
39126--- a/drivers/gpu/drm/via/via_irq.c
39127+++ b/drivers/gpu/drm/via/via_irq.c
39128@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
39129 if (crtc != 0)
39130 return 0;
39131
39132- return atomic_read(&dev_priv->vbl_received);
39133+ return atomic_read_unchecked(&dev_priv->vbl_received);
39134 }
39135
39136 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39137@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39138
39139 status = VIA_READ(VIA_REG_INTERRUPT);
39140 if (status & VIA_IRQ_VBLANK_PENDING) {
39141- atomic_inc(&dev_priv->vbl_received);
39142- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
39143+ atomic_inc_unchecked(&dev_priv->vbl_received);
39144+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
39145 do_gettimeofday(&cur_vblank);
39146 if (dev_priv->last_vblank_valid) {
39147 dev_priv->usec_per_vblank =
39148@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39149 dev_priv->last_vblank = cur_vblank;
39150 dev_priv->last_vblank_valid = 1;
39151 }
39152- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
39153+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
39154 DRM_DEBUG("US per vblank is: %u\n",
39155 dev_priv->usec_per_vblank);
39156 }
39157@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39158
39159 for (i = 0; i < dev_priv->num_irqs; ++i) {
39160 if (status & cur_irq->pending_mask) {
39161- atomic_inc(&cur_irq->irq_received);
39162+ atomic_inc_unchecked(&cur_irq->irq_received);
39163 DRM_WAKEUP(&cur_irq->irq_queue);
39164 handled = 1;
39165 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
39166@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
39167 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39168 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
39169 masks[irq][4]));
39170- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
39171+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
39172 } else {
39173 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39174 (((cur_irq_sequence =
39175- atomic_read(&cur_irq->irq_received)) -
39176+ atomic_read_unchecked(&cur_irq->irq_received)) -
39177 *sequence) <= (1 << 23)));
39178 }
39179 *sequence = cur_irq_sequence;
39180@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
39181 }
39182
39183 for (i = 0; i < dev_priv->num_irqs; ++i) {
39184- atomic_set(&cur_irq->irq_received, 0);
39185+ atomic_set_unchecked(&cur_irq->irq_received, 0);
39186 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
39187 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
39188 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
39189@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
39190 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
39191 case VIA_IRQ_RELATIVE:
39192 irqwait->request.sequence +=
39193- atomic_read(&cur_irq->irq_received);
39194+ atomic_read_unchecked(&cur_irq->irq_received);
39195 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
39196 case VIA_IRQ_ABSOLUTE:
39197 break;
39198diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39199index 13aeda7..4a952d1 100644
39200--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39201+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39202@@ -290,7 +290,7 @@ struct vmw_private {
39203 * Fencing and IRQs.
39204 */
39205
39206- atomic_t marker_seq;
39207+ atomic_unchecked_t marker_seq;
39208 wait_queue_head_t fence_queue;
39209 wait_queue_head_t fifo_queue;
39210 int fence_queue_waiters; /* Protected by hw_mutex */
39211diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39212index 3eb1486..0a47ee9 100644
39213--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39214+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39215@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
39216 (unsigned int) min,
39217 (unsigned int) fifo->capabilities);
39218
39219- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39220+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39221 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
39222 vmw_marker_queue_init(&fifo->marker_queue);
39223 return vmw_fifo_send_fence(dev_priv, &dummy);
39224@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
39225 if (reserveable)
39226 iowrite32(bytes, fifo_mem +
39227 SVGA_FIFO_RESERVED);
39228- return fifo_mem + (next_cmd >> 2);
39229+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
39230 } else {
39231 need_bounce = true;
39232 }
39233@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39234
39235 fm = vmw_fifo_reserve(dev_priv, bytes);
39236 if (unlikely(fm == NULL)) {
39237- *seqno = atomic_read(&dev_priv->marker_seq);
39238+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39239 ret = -ENOMEM;
39240 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
39241 false, 3*HZ);
39242@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39243 }
39244
39245 do {
39246- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
39247+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
39248 } while (*seqno == 0);
39249
39250 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
39251diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39252index c509d40..3b640c3 100644
39253--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39254+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39255@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
39256 int ret;
39257
39258 num_clips = arg->num_clips;
39259- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39260+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39261
39262 if (unlikely(num_clips == 0))
39263 return 0;
39264@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
39265 int ret;
39266
39267 num_clips = arg->num_clips;
39268- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39269+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39270
39271 if (unlikely(num_clips == 0))
39272 return 0;
39273diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39274index 4640adb..e1384ed 100644
39275--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39276+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39277@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
39278 * emitted. Then the fence is stale and signaled.
39279 */
39280
39281- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
39282+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
39283 > VMW_FENCE_WRAP);
39284
39285 return ret;
39286@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
39287
39288 if (fifo_idle)
39289 down_read(&fifo_state->rwsem);
39290- signal_seq = atomic_read(&dev_priv->marker_seq);
39291+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
39292 ret = 0;
39293
39294 for (;;) {
39295diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39296index 8a8725c2..afed796 100644
39297--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39298+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39299@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
39300 while (!vmw_lag_lt(queue, us)) {
39301 spin_lock(&queue->lock);
39302 if (list_empty(&queue->head))
39303- seqno = atomic_read(&dev_priv->marker_seq);
39304+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39305 else {
39306 marker = list_first_entry(&queue->head,
39307 struct vmw_marker, head);
39308diff --git a/drivers/gpu/host1x/drm/dc.c b/drivers/gpu/host1x/drm/dc.c
39309index 5360e5a..c2c0d26 100644
39310--- a/drivers/gpu/host1x/drm/dc.c
39311+++ b/drivers/gpu/host1x/drm/dc.c
39312@@ -1004,7 +1004,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
39313 }
39314
39315 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
39316- dc->debugfs_files[i].data = dc;
39317+ *(void **)&dc->debugfs_files[i].data = dc;
39318
39319 err = drm_debugfs_create_files(dc->debugfs_files,
39320 ARRAY_SIZE(debugfs_files),
39321diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
39322index 36668d1..9f4ccb0 100644
39323--- a/drivers/hid/hid-core.c
39324+++ b/drivers/hid/hid-core.c
39325@@ -63,6 +63,8 @@ struct hid_report *hid_register_report(struct hid_device *device, unsigned type,
39326 struct hid_report_enum *report_enum = device->report_enum + type;
39327 struct hid_report *report;
39328
39329+ if (id >= HID_MAX_IDS)
39330+ return NULL;
39331 if (report_enum->report_id_hash[id])
39332 return report_enum->report_id_hash[id];
39333
39334@@ -404,8 +406,10 @@ static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
39335
39336 case HID_GLOBAL_ITEM_TAG_REPORT_ID:
39337 parser->global.report_id = item_udata(item);
39338- if (parser->global.report_id == 0) {
39339- hid_err(parser->device, "report_id 0 is invalid\n");
39340+ if (parser->global.report_id == 0 ||
39341+ parser->global.report_id >= HID_MAX_IDS) {
39342+ hid_err(parser->device, "report_id %u is invalid\n",
39343+ parser->global.report_id);
39344 return -1;
39345 }
39346 return 0;
39347@@ -575,7 +579,7 @@ static void hid_close_report(struct hid_device *device)
39348 for (i = 0; i < HID_REPORT_TYPES; i++) {
39349 struct hid_report_enum *report_enum = device->report_enum + i;
39350
39351- for (j = 0; j < 256; j++) {
39352+ for (j = 0; j < HID_MAX_IDS; j++) {
39353 struct hid_report *report = report_enum->report_id_hash[j];
39354 if (report)
39355 hid_free_report(report);
39356@@ -755,6 +759,56 @@ int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size)
39357 }
39358 EXPORT_SYMBOL_GPL(hid_parse_report);
39359
39360+static const char * const hid_report_names[] = {
39361+ "HID_INPUT_REPORT",
39362+ "HID_OUTPUT_REPORT",
39363+ "HID_FEATURE_REPORT",
39364+};
39365+/**
39366+ * hid_validate_report - validate existing device report
39367+ *
39368+ * @device: hid device
39369+ * @type: which report type to examine
39370+ * @id: which report ID to examine (0 for first)
39371+ * @fields: expected number of fields
39372+ * @report_counts: expected number of values per field
39373+ *
39374+ * Validate the report details after parsing.
39375+ */
39376+struct hid_report *hid_validate_report(struct hid_device *hid,
39377+ unsigned int type, unsigned int id,
39378+ unsigned int fields,
39379+ unsigned int report_counts)
39380+{
39381+ struct hid_report *report;
39382+ unsigned int i;
39383+
39384+ if (type > HID_FEATURE_REPORT) {
39385+ hid_err(hid, "invalid HID report %u\n", type);
39386+ return NULL;
39387+ }
39388+
39389+ report = hid->report_enum[type].report_id_hash[id];
39390+ if (!report) {
39391+ hid_err(hid, "missing %s %u\n", hid_report_names[type], id);
39392+ return NULL;
39393+ }
39394+ if (report->maxfield < fields) {
39395+ hid_err(hid, "not enough fields in %s %u\n",
39396+ hid_report_names[type], id);
39397+ return NULL;
39398+ }
39399+ for (i = 0; i < fields; i++) {
39400+ if (report->field[i]->report_count < report_counts) {
39401+ hid_err(hid, "not enough values in %s %u fields\n",
39402+ hid_report_names[type], id);
39403+ return NULL;
39404+ }
39405+ }
39406+ return report;
39407+}
39408+EXPORT_SYMBOL_GPL(hid_validate_report);
39409+
39410 /**
39411 * hid_open_report - open a driver-specific device report
39412 *
39413@@ -1152,7 +1206,12 @@ EXPORT_SYMBOL_GPL(hid_output_report);
39414
39415 int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
39416 {
39417- unsigned size = field->report_size;
39418+ unsigned size;
39419+
39420+ if (!field)
39421+ return -1;
39422+
39423+ size = field->report_size;
39424
39425 hid_dump_input(field->report->device, field->usage + offset, value);
39426
39427@@ -2285,7 +2344,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
39428
39429 int hid_add_device(struct hid_device *hdev)
39430 {
39431- static atomic_t id = ATOMIC_INIT(0);
39432+ static atomic_unchecked_t id = ATOMIC_INIT(0);
39433 int ret;
39434
39435 if (WARN_ON(hdev->status & HID_STAT_ADDED))
39436@@ -2319,7 +2378,7 @@ int hid_add_device(struct hid_device *hdev)
39437 /* XXX hack, any other cleaner solution after the driver core
39438 * is converted to allow more than 20 bytes as the device name? */
39439 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
39440- hdev->vendor, hdev->product, atomic_inc_return(&id));
39441+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
39442
39443 hid_debug_register(hdev, dev_name(&hdev->dev));
39444 ret = device_add(&hdev->dev);
39445diff --git a/drivers/hid/hid-lenovo-tpkbd.c b/drivers/hid/hid-lenovo-tpkbd.c
39446index 07837f5..b697ada 100644
39447--- a/drivers/hid/hid-lenovo-tpkbd.c
39448+++ b/drivers/hid/hid-lenovo-tpkbd.c
39449@@ -341,6 +341,11 @@ static int tpkbd_probe_tp(struct hid_device *hdev)
39450 char *name_mute, *name_micmute;
39451 int ret;
39452
39453+ /* Validate required reports. */
39454+ if (!hid_validate_report(hdev, HID_OUTPUT_REPORT, 4, 4, 1) ||
39455+ !hid_validate_report(hdev, HID_OUTPUT_REPORT, 3, 1, 2))
39456+ return -ENODEV;
39457+
39458 if (sysfs_create_group(&hdev->dev.kobj,
39459 &tpkbd_attr_group_pointer)) {
39460 hid_warn(hdev, "Could not create sysfs group\n");
39461diff --git a/drivers/hid/hid-lg2ff.c b/drivers/hid/hid-lg2ff.c
39462index b3cd150..9805197 100644
39463--- a/drivers/hid/hid-lg2ff.c
39464+++ b/drivers/hid/hid-lg2ff.c
39465@@ -64,26 +64,13 @@ int lg2ff_init(struct hid_device *hid)
39466 struct hid_report *report;
39467 struct hid_input *hidinput = list_entry(hid->inputs.next,
39468 struct hid_input, list);
39469- struct list_head *report_list =
39470- &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39471 struct input_dev *dev = hidinput->input;
39472 int error;
39473
39474- if (list_empty(report_list)) {
39475- hid_err(hid, "no output report found\n");
39476+ /* Check that the report looks ok */
39477+ report = hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 7);
39478+ if (!report)
39479 return -ENODEV;
39480- }
39481-
39482- report = list_entry(report_list->next, struct hid_report, list);
39483-
39484- if (report->maxfield < 1) {
39485- hid_err(hid, "output report is empty\n");
39486- return -ENODEV;
39487- }
39488- if (report->field[0]->report_count < 7) {
39489- hid_err(hid, "not enough values in the field\n");
39490- return -ENODEV;
39491- }
39492
39493 lg2ff = kmalloc(sizeof(struct lg2ff_device), GFP_KERNEL);
39494 if (!lg2ff)
39495diff --git a/drivers/hid/hid-lg3ff.c b/drivers/hid/hid-lg3ff.c
39496index e52f181..53ac79b 100644
39497--- a/drivers/hid/hid-lg3ff.c
39498+++ b/drivers/hid/hid-lg3ff.c
39499@@ -66,10 +66,11 @@ static int hid_lg3ff_play(struct input_dev *dev, void *data,
39500 int x, y;
39501
39502 /*
39503- * Maxusage should always be 63 (maximum fields)
39504- * likely a better way to ensure this data is clean
39505+ * Available values in the field should always be 63, but we only use up to
39506+ * 35. Instead, clear the entire area, however big it is.
39507 */
39508- memset(report->field[0]->value, 0, sizeof(__s32)*report->field[0]->maxusage);
39509+ memset(report->field[0]->value, 0,
39510+ sizeof(__s32) * report->field[0]->report_count);
39511
39512 switch (effect->type) {
39513 case FF_CONSTANT:
39514@@ -129,32 +130,14 @@ static const signed short ff3_joystick_ac[] = {
39515 int lg3ff_init(struct hid_device *hid)
39516 {
39517 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
39518- struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39519 struct input_dev *dev = hidinput->input;
39520- struct hid_report *report;
39521- struct hid_field *field;
39522 const signed short *ff_bits = ff3_joystick_ac;
39523 int error;
39524 int i;
39525
39526- /* Find the report to use */
39527- if (list_empty(report_list)) {
39528- hid_err(hid, "No output report found\n");
39529- return -1;
39530- }
39531-
39532 /* Check that the report looks ok */
39533- report = list_entry(report_list->next, struct hid_report, list);
39534- if (!report) {
39535- hid_err(hid, "NULL output report\n");
39536- return -1;
39537- }
39538-
39539- field = report->field[0];
39540- if (!field) {
39541- hid_err(hid, "NULL field\n");
39542- return -1;
39543- }
39544+ if (!hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 35))
39545+ return -ENODEV;
39546
39547 /* Assume single fixed device G940 */
39548 for (i = 0; ff_bits[i] >= 0; i++)
39549diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c
39550index 0ddae2a..8b89f0f 100644
39551--- a/drivers/hid/hid-lg4ff.c
39552+++ b/drivers/hid/hid-lg4ff.c
39553@@ -484,34 +484,16 @@ static enum led_brightness lg4ff_led_get_brightness(struct led_classdev *led_cde
39554 int lg4ff_init(struct hid_device *hid)
39555 {
39556 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
39557- struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39558 struct input_dev *dev = hidinput->input;
39559- struct hid_report *report;
39560- struct hid_field *field;
39561 struct lg4ff_device_entry *entry;
39562 struct lg_drv_data *drv_data;
39563 struct usb_device_descriptor *udesc;
39564 int error, i, j;
39565 __u16 bcdDevice, rev_maj, rev_min;
39566
39567- /* Find the report to use */
39568- if (list_empty(report_list)) {
39569- hid_err(hid, "No output report found\n");
39570- return -1;
39571- }
39572-
39573 /* Check that the report looks ok */
39574- report = list_entry(report_list->next, struct hid_report, list);
39575- if (!report) {
39576- hid_err(hid, "NULL output report\n");
39577+ if (!hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 7))
39578 return -1;
39579- }
39580-
39581- field = report->field[0];
39582- if (!field) {
39583- hid_err(hid, "NULL field\n");
39584- return -1;
39585- }
39586
39587 /* Check what wheel has been connected */
39588 for (i = 0; i < ARRAY_SIZE(lg4ff_devices); i++) {
39589diff --git a/drivers/hid/hid-lgff.c b/drivers/hid/hid-lgff.c
39590index d7ea8c8..a84fb40 100644
39591--- a/drivers/hid/hid-lgff.c
39592+++ b/drivers/hid/hid-lgff.c
39593@@ -128,27 +128,14 @@ static void hid_lgff_set_autocenter(struct input_dev *dev, u16 magnitude)
39594 int lgff_init(struct hid_device* hid)
39595 {
39596 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
39597- struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39598 struct input_dev *dev = hidinput->input;
39599- struct hid_report *report;
39600- struct hid_field *field;
39601 const signed short *ff_bits = ff_joystick;
39602 int error;
39603 int i;
39604
39605- /* Find the report to use */
39606- if (list_empty(report_list)) {
39607- hid_err(hid, "No output report found\n");
39608- return -1;
39609- }
39610-
39611 /* Check that the report looks ok */
39612- report = list_entry(report_list->next, struct hid_report, list);
39613- field = report->field[0];
39614- if (!field) {
39615- hid_err(hid, "NULL field\n");
39616- return -1;
39617- }
39618+ if (!hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 7))
39619+ return -ENODEV;
39620
39621 for (i = 0; i < ARRAY_SIZE(devices); i++) {
39622 if (dev->id.vendor == devices[i].idVendor &&
39623diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
39624index cd33084..7b99c2a 100644
39625--- a/drivers/hid/hid-logitech-dj.c
39626+++ b/drivers/hid/hid-logitech-dj.c
39627@@ -461,7 +461,7 @@ static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev,
39628 struct hid_report *report;
39629 struct hid_report_enum *output_report_enum;
39630 u8 *data = (u8 *)(&dj_report->device_index);
39631- int i;
39632+ unsigned int i, length;
39633
39634 output_report_enum = &hdev->report_enum[HID_OUTPUT_REPORT];
39635 report = output_report_enum->report_id_hash[REPORT_ID_DJ_SHORT];
39636@@ -471,7 +471,9 @@ static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev,
39637 return -ENODEV;
39638 }
39639
39640- for (i = 0; i < report->field[0]->report_count; i++)
39641+ length = min_t(size_t, sizeof(*dj_report) - 1,
39642+ report->field[0]->report_count);
39643+ for (i = 0; i < length; i++)
39644 report->field[0]->value[i] = data[i];
39645
39646 hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
39647@@ -783,6 +785,12 @@ static int logi_dj_probe(struct hid_device *hdev,
39648 goto hid_parse_fail;
39649 }
39650
39651+ if (!hid_validate_report(hdev, HID_OUTPUT_REPORT, REPORT_ID_DJ_SHORT,
39652+ 1, 3)) {
39653+ retval = -ENODEV;
39654+ goto hid_parse_fail;
39655+ }
39656+
39657 /* Starts the usb device and connects to upper interfaces hiddev and
39658 * hidraw */
39659 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
39660diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
39661index cb0e361..2aa275e 100644
39662--- a/drivers/hid/hid-multitouch.c
39663+++ b/drivers/hid/hid-multitouch.c
39664@@ -330,9 +330,18 @@ static void mt_feature_mapping(struct hid_device *hdev,
39665 break;
39666 }
39667 }
39668+ /* Ignore if value index is out of bounds. */
39669+ if (td->inputmode_index < 0 ||
39670+ td->inputmode_index >= field->report_count) {
39671+ dev_err(&hdev->dev, "HID_DG_INPUTMODE out of range\n");
39672+ td->inputmode = -1;
39673+ }
39674
39675 break;
39676 case HID_DG_CONTACTMAX:
39677+ /* Ignore if value count is out of bounds. */
39678+ if (field->report_count < 1)
39679+ break;
39680 td->maxcontact_report_id = field->report->id;
39681 td->maxcontacts = field->value[0];
39682 if (!td->maxcontacts &&
39683@@ -743,15 +752,21 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report)
39684 unsigned count;
39685 int r, n;
39686
39687+ if (report->maxfield == 0)
39688+ return;
39689+
39690 /*
39691 * Includes multi-packet support where subsequent
39692 * packets are sent with zero contactcount.
39693 */
39694- if (td->cc_index >= 0) {
39695- struct hid_field *field = report->field[td->cc_index];
39696- int value = field->value[td->cc_value_index];
39697- if (value)
39698- td->num_expected = value;
39699+ if (td->cc_index >= 0 && td->cc_index < report->maxfield) {
39700+ field = report->field[td->cc_index];
39701+ if (td->cc_value_index >= 0 &&
39702+ td->cc_value_index < field->report_count) {
39703+ int value = field->value[td->cc_value_index];
39704+ if (value)
39705+ td->num_expected = value;
39706+ }
39707 }
39708
39709 for (r = 0; r < report->maxfield; r++) {
39710diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c
39711index ef95102..5482156 100644
39712--- a/drivers/hid/hid-ntrig.c
39713+++ b/drivers/hid/hid-ntrig.c
39714@@ -115,7 +115,8 @@ static inline int ntrig_get_mode(struct hid_device *hdev)
39715 struct hid_report *report = hdev->report_enum[HID_FEATURE_REPORT].
39716 report_id_hash[0x0d];
39717
39718- if (!report)
39719+ if (!report || report->maxfield < 1 ||
39720+ report->field[0]->report_count < 1)
39721 return -EINVAL;
39722
39723 hid_hw_request(hdev, report, HID_REQ_GET_REPORT);
39724diff --git a/drivers/hid/hid-picolcd_core.c b/drivers/hid/hid-picolcd_core.c
39725index b48092d..72bba1e 100644
39726--- a/drivers/hid/hid-picolcd_core.c
39727+++ b/drivers/hid/hid-picolcd_core.c
39728@@ -290,7 +290,7 @@ static ssize_t picolcd_operation_mode_store(struct device *dev,
39729 buf += 10;
39730 cnt -= 10;
39731 }
39732- if (!report)
39733+ if (!report || report->maxfield < 1)
39734 return -EINVAL;
39735
39736 while (cnt > 0 && (buf[cnt-1] == '\n' || buf[cnt-1] == '\r'))
39737diff --git a/drivers/hid/hid-pl.c b/drivers/hid/hid-pl.c
39738index d29112f..2dcd7d9 100644
39739--- a/drivers/hid/hid-pl.c
39740+++ b/drivers/hid/hid-pl.c
39741@@ -132,8 +132,14 @@ static int plff_init(struct hid_device *hid)
39742 strong = &report->field[0]->value[2];
39743 weak = &report->field[0]->value[3];
39744 debug("detected single-field device");
39745- } else if (report->maxfield >= 4 && report->field[0]->maxusage == 1 &&
39746- report->field[0]->usage[0].hid == (HID_UP_LED | 0x43)) {
39747+ } else if (report->field[0]->maxusage == 1 &&
39748+ report->field[0]->usage[0].hid ==
39749+ (HID_UP_LED | 0x43) &&
39750+ report->maxfield >= 4 &&
39751+ report->field[0]->report_count >= 1 &&
39752+ report->field[1]->report_count >= 1 &&
39753+ report->field[2]->report_count >= 1 &&
39754+ report->field[3]->report_count >= 1) {
39755 report->field[0]->value[0] = 0x00;
39756 report->field[1]->value[0] = 0x00;
39757 strong = &report->field[2]->value[0];
39758diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
39759index ca749810..aa34755 100644
39760--- a/drivers/hid/hid-sensor-hub.c
39761+++ b/drivers/hid/hid-sensor-hub.c
39762@@ -221,7 +221,8 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
39763
39764 mutex_lock(&data->mutex);
39765 report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
39766- if (!report || (field_index >= report->maxfield)) {
39767+ if (!report || (field_index >= report->maxfield) ||
39768+ report->field[field_index]->report_count < 1) {
39769 ret = -EINVAL;
39770 goto done_proc;
39771 }
39772diff --git a/drivers/hid/hid-steelseries.c b/drivers/hid/hid-steelseries.c
39773index d164911..ef42e86 100644
39774--- a/drivers/hid/hid-steelseries.c
39775+++ b/drivers/hid/hid-steelseries.c
39776@@ -249,6 +249,11 @@ static int steelseries_srws1_probe(struct hid_device *hdev,
39777 goto err_free;
39778 }
39779
39780+ if (!hid_validate_report(hdev, HID_OUTPUT_REPORT, 0, 1, 16)) {
39781+ ret = -ENODEV;
39782+ goto err_free;
39783+ }
39784+
39785 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
39786 if (ret) {
39787 hid_err(hdev, "hw start failed\n");
39788diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
39789index c13fb5b..55a3802 100644
39790--- a/drivers/hid/hid-wiimote-debug.c
39791+++ b/drivers/hid/hid-wiimote-debug.c
39792@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
39793 else if (size == 0)
39794 return -EIO;
39795
39796- if (copy_to_user(u, buf, size))
39797+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
39798 return -EFAULT;
39799
39800 *off += size;
39801diff --git a/drivers/hid/hid-zpff.c b/drivers/hid/hid-zpff.c
39802index 6ec28a3..b124991 100644
39803--- a/drivers/hid/hid-zpff.c
39804+++ b/drivers/hid/hid-zpff.c
39805@@ -68,22 +68,12 @@ static int zpff_init(struct hid_device *hid)
39806 struct hid_report *report;
39807 struct hid_input *hidinput = list_entry(hid->inputs.next,
39808 struct hid_input, list);
39809- struct list_head *report_list =
39810- &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39811 struct input_dev *dev = hidinput->input;
39812 int error;
39813
39814- if (list_empty(report_list)) {
39815- hid_err(hid, "no output report found\n");
39816+ report = hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 4, 1);
39817+ if (!report)
39818 return -ENODEV;
39819- }
39820-
39821- report = list_entry(report_list->next, struct hid_report, list);
39822-
39823- if (report->maxfield < 4) {
39824- hid_err(hid, "not enough fields in report\n");
39825- return -ENODEV;
39826- }
39827
39828 zpff = kzalloc(sizeof(struct zpff_device), GFP_KERNEL);
39829 if (!zpff)
39830diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
39831index fc307e0..2b255e8 100644
39832--- a/drivers/hid/uhid.c
39833+++ b/drivers/hid/uhid.c
39834@@ -47,7 +47,7 @@ struct uhid_device {
39835 struct mutex report_lock;
39836 wait_queue_head_t report_wait;
39837 atomic_t report_done;
39838- atomic_t report_id;
39839+ atomic_unchecked_t report_id;
39840 struct uhid_event report_buf;
39841 };
39842
39843@@ -187,7 +187,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
39844
39845 spin_lock_irqsave(&uhid->qlock, flags);
39846 ev->type = UHID_FEATURE;
39847- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
39848+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
39849 ev->u.feature.rnum = rnum;
39850 ev->u.feature.rtype = report_type;
39851
39852@@ -471,7 +471,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
39853 spin_lock_irqsave(&uhid->qlock, flags);
39854
39855 /* id for old report; drop it silently */
39856- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
39857+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
39858 goto unlock;
39859 if (atomic_read(&uhid->report_done))
39860 goto unlock;
39861diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
39862index 6de6c98..18319e9 100644
39863--- a/drivers/hv/channel.c
39864+++ b/drivers/hv/channel.c
39865@@ -406,8 +406,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
39866 int ret = 0;
39867 int t;
39868
39869- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
39870- atomic_inc(&vmbus_connection.next_gpadl_handle);
39871+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
39872+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
39873
39874 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
39875 if (ret)
39876diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
39877index 88f4096..e50452e 100644
39878--- a/drivers/hv/hv.c
39879+++ b/drivers/hv/hv.c
39880@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
39881 u64 output_address = (output) ? virt_to_phys(output) : 0;
39882 u32 output_address_hi = output_address >> 32;
39883 u32 output_address_lo = output_address & 0xFFFFFFFF;
39884- void *hypercall_page = hv_context.hypercall_page;
39885+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
39886
39887 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
39888 "=a"(hv_status_lo) : "d" (control_hi),
39889diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
39890index deb5c25..ed2d4fd 100644
39891--- a/drivers/hv/hv_balloon.c
39892+++ b/drivers/hv/hv_balloon.c
39893@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
39894
39895 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
39896 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
39897-static atomic_t trans_id = ATOMIC_INIT(0);
39898+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
39899
39900 static int dm_ring_size = (5 * PAGE_SIZE);
39901
39902@@ -825,7 +825,7 @@ static void hot_add_req(struct work_struct *dummy)
39903 memset(&resp, 0, sizeof(struct dm_hot_add_response));
39904 resp.hdr.type = DM_MEM_HOT_ADD_RESPONSE;
39905 resp.hdr.size = sizeof(struct dm_hot_add_response);
39906- resp.hdr.trans_id = atomic_inc_return(&trans_id);
39907+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39908
39909 #ifdef CONFIG_MEMORY_HOTPLUG
39910 pg_start = dm->ha_wrk.ha_page_range.finfo.start_page;
39911@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
39912 memset(&status, 0, sizeof(struct dm_status));
39913 status.hdr.type = DM_STATUS_REPORT;
39914 status.hdr.size = sizeof(struct dm_status);
39915- status.hdr.trans_id = atomic_inc_return(&trans_id);
39916+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39917
39918 /*
39919 * The host expects the guest to report free memory.
39920@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
39921 * send the status. This can happen if we were interrupted
39922 * after we picked our transaction ID.
39923 */
39924- if (status.hdr.trans_id != atomic_read(&trans_id))
39925+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
39926 return;
39927
39928 vmbus_sendpacket(dm->dev->channel, &status,
39929@@ -1081,7 +1081,7 @@ static void balloon_up(struct work_struct *dummy)
39930 bl_resp = (struct dm_balloon_response *)send_buffer;
39931 memset(send_buffer, 0, PAGE_SIZE);
39932 bl_resp->hdr.type = DM_BALLOON_RESPONSE;
39933- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
39934+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39935 bl_resp->hdr.size = sizeof(struct dm_balloon_response);
39936 bl_resp->more_pages = 1;
39937
39938@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
39939
39940 memset(&resp, 0, sizeof(struct dm_unballoon_response));
39941 resp.hdr.type = DM_UNBALLOON_RESPONSE;
39942- resp.hdr.trans_id = atomic_inc_return(&trans_id);
39943+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39944 resp.hdr.size = sizeof(struct dm_unballoon_response);
39945
39946 vmbus_sendpacket(dm_device.dev->channel, &resp,
39947@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
39948 memset(&version_req, 0, sizeof(struct dm_version_request));
39949 version_req.hdr.type = DM_VERSION_REQUEST;
39950 version_req.hdr.size = sizeof(struct dm_version_request);
39951- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
39952+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39953 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
39954 version_req.is_last_attempt = 1;
39955
39956@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
39957 memset(&version_req, 0, sizeof(struct dm_version_request));
39958 version_req.hdr.type = DM_VERSION_REQUEST;
39959 version_req.hdr.size = sizeof(struct dm_version_request);
39960- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
39961+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39962 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
39963 version_req.is_last_attempt = 0;
39964
39965@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
39966 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
39967 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
39968 cap_msg.hdr.size = sizeof(struct dm_capabilities);
39969- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
39970+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39971
39972 cap_msg.caps.cap_bits.balloon = 1;
39973 cap_msg.caps.cap_bits.hot_add = 1;
39974diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
39975index d84918f..7f38f9f 100644
39976--- a/drivers/hv/hyperv_vmbus.h
39977+++ b/drivers/hv/hyperv_vmbus.h
39978@@ -595,7 +595,7 @@ enum vmbus_connect_state {
39979 struct vmbus_connection {
39980 enum vmbus_connect_state conn_state;
39981
39982- atomic_t next_gpadl_handle;
39983+ atomic_unchecked_t next_gpadl_handle;
39984
39985 /*
39986 * Represents channel interrupts. Each bit position represents a
39987diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
39988index e8e071f..5b4b245 100644
39989--- a/drivers/hv/vmbus_drv.c
39990+++ b/drivers/hv/vmbus_drv.c
39991@@ -672,10 +672,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
39992 {
39993 int ret = 0;
39994
39995- static atomic_t device_num = ATOMIC_INIT(0);
39996+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
39997
39998 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
39999- atomic_inc_return(&device_num));
40000+ atomic_inc_return_unchecked(&device_num));
40001
40002 child_device_obj->device.bus = &hv_bus;
40003 child_device_obj->device.parent = &hv_acpi_dev->dev;
40004diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
40005index 6351aba..dc4aaf4 100644
40006--- a/drivers/hwmon/acpi_power_meter.c
40007+++ b/drivers/hwmon/acpi_power_meter.c
40008@@ -117,7 +117,7 @@ struct sensor_template {
40009 struct device_attribute *devattr,
40010 const char *buf, size_t count);
40011 int index;
40012-};
40013+} __do_const;
40014
40015 /* Averaging interval */
40016 static int update_avg_interval(struct acpi_power_meter_resource *resource)
40017@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
40018 struct sensor_template *attrs)
40019 {
40020 struct device *dev = &resource->acpi_dev->dev;
40021- struct sensor_device_attribute *sensors =
40022+ sensor_device_attribute_no_const *sensors =
40023 &resource->sensors[resource->num_sensors];
40024 int res = 0;
40025
40026diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
40027index 62c2e32..8f2859a 100644
40028--- a/drivers/hwmon/applesmc.c
40029+++ b/drivers/hwmon/applesmc.c
40030@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
40031 {
40032 struct applesmc_node_group *grp;
40033 struct applesmc_dev_attr *node;
40034- struct attribute *attr;
40035+ attribute_no_const *attr;
40036 int ret, i;
40037
40038 for (grp = groups; grp->format; grp++) {
40039diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
40040index b25c643..a13460d 100644
40041--- a/drivers/hwmon/asus_atk0110.c
40042+++ b/drivers/hwmon/asus_atk0110.c
40043@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
40044 struct atk_sensor_data {
40045 struct list_head list;
40046 struct atk_data *data;
40047- struct device_attribute label_attr;
40048- struct device_attribute input_attr;
40049- struct device_attribute limit1_attr;
40050- struct device_attribute limit2_attr;
40051+ device_attribute_no_const label_attr;
40052+ device_attribute_no_const input_attr;
40053+ device_attribute_no_const limit1_attr;
40054+ device_attribute_no_const limit2_attr;
40055 char label_attr_name[ATTR_NAME_SIZE];
40056 char input_attr_name[ATTR_NAME_SIZE];
40057 char limit1_attr_name[ATTR_NAME_SIZE];
40058@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
40059 static struct device_attribute atk_name_attr =
40060 __ATTR(name, 0444, atk_name_show, NULL);
40061
40062-static void atk_init_attribute(struct device_attribute *attr, char *name,
40063+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
40064 sysfs_show_func show)
40065 {
40066 sysfs_attr_init(&attr->attr);
40067diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
40068index 2e5e2dc..5208b31 100644
40069--- a/drivers/hwmon/coretemp.c
40070+++ b/drivers/hwmon/coretemp.c
40071@@ -785,7 +785,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
40072 return NOTIFY_OK;
40073 }
40074
40075-static struct notifier_block coretemp_cpu_notifier __refdata = {
40076+static struct notifier_block coretemp_cpu_notifier = {
40077 .notifier_call = coretemp_cpu_callback,
40078 };
40079
40080diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
40081index 1429f6e..ee03d59 100644
40082--- a/drivers/hwmon/ibmaem.c
40083+++ b/drivers/hwmon/ibmaem.c
40084@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
40085 struct aem_rw_sensor_template *rw)
40086 {
40087 struct device *dev = &data->pdev->dev;
40088- struct sensor_device_attribute *sensors = data->sensors;
40089+ sensor_device_attribute_no_const *sensors = data->sensors;
40090 int err;
40091
40092 /* Set up read-only sensors */
40093diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
40094index 708081b..fe2d4ab 100644
40095--- a/drivers/hwmon/iio_hwmon.c
40096+++ b/drivers/hwmon/iio_hwmon.c
40097@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
40098 {
40099 struct device *dev = &pdev->dev;
40100 struct iio_hwmon_state *st;
40101- struct sensor_device_attribute *a;
40102+ sensor_device_attribute_no_const *a;
40103 int ret, i;
40104 int in_i = 1, temp_i = 1, curr_i = 1;
40105 enum iio_chan_type type;
40106diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
40107index 9add6092..ee7ba3f 100644
40108--- a/drivers/hwmon/pmbus/pmbus_core.c
40109+++ b/drivers/hwmon/pmbus/pmbus_core.c
40110@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
40111 return 0;
40112 }
40113
40114-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
40115+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
40116 const char *name,
40117 umode_t mode,
40118 ssize_t (*show)(struct device *dev,
40119@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
40120 dev_attr->store = store;
40121 }
40122
40123-static void pmbus_attr_init(struct sensor_device_attribute *a,
40124+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
40125 const char *name,
40126 umode_t mode,
40127 ssize_t (*show)(struct device *dev,
40128@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
40129 u16 reg, u8 mask)
40130 {
40131 struct pmbus_boolean *boolean;
40132- struct sensor_device_attribute *a;
40133+ sensor_device_attribute_no_const *a;
40134
40135 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
40136 if (!boolean)
40137@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
40138 bool update, bool readonly)
40139 {
40140 struct pmbus_sensor *sensor;
40141- struct device_attribute *a;
40142+ device_attribute_no_const *a;
40143
40144 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
40145 if (!sensor)
40146@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
40147 const char *lstring, int index)
40148 {
40149 struct pmbus_label *label;
40150- struct device_attribute *a;
40151+ device_attribute_no_const *a;
40152
40153 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
40154 if (!label)
40155diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
40156index 2507f90..1645765 100644
40157--- a/drivers/hwmon/sht15.c
40158+++ b/drivers/hwmon/sht15.c
40159@@ -169,7 +169,7 @@ struct sht15_data {
40160 int supply_uv;
40161 bool supply_uv_valid;
40162 struct work_struct update_supply_work;
40163- atomic_t interrupt_handled;
40164+ atomic_unchecked_t interrupt_handled;
40165 };
40166
40167 /**
40168@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
40169 ret = gpio_direction_input(data->pdata->gpio_data);
40170 if (ret)
40171 return ret;
40172- atomic_set(&data->interrupt_handled, 0);
40173+ atomic_set_unchecked(&data->interrupt_handled, 0);
40174
40175 enable_irq(gpio_to_irq(data->pdata->gpio_data));
40176 if (gpio_get_value(data->pdata->gpio_data) == 0) {
40177 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
40178 /* Only relevant if the interrupt hasn't occurred. */
40179- if (!atomic_read(&data->interrupt_handled))
40180+ if (!atomic_read_unchecked(&data->interrupt_handled))
40181 schedule_work(&data->read_work);
40182 }
40183 ret = wait_event_timeout(data->wait_queue,
40184@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
40185
40186 /* First disable the interrupt */
40187 disable_irq_nosync(irq);
40188- atomic_inc(&data->interrupt_handled);
40189+ atomic_inc_unchecked(&data->interrupt_handled);
40190 /* Then schedule a reading work struct */
40191 if (data->state != SHT15_READING_NOTHING)
40192 schedule_work(&data->read_work);
40193@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
40194 * If not, then start the interrupt again - care here as could
40195 * have gone low in meantime so verify it hasn't!
40196 */
40197- atomic_set(&data->interrupt_handled, 0);
40198+ atomic_set_unchecked(&data->interrupt_handled, 0);
40199 enable_irq(gpio_to_irq(data->pdata->gpio_data));
40200 /* If still not occurred or another handler was scheduled */
40201 if (gpio_get_value(data->pdata->gpio_data)
40202- || atomic_read(&data->interrupt_handled))
40203+ || atomic_read_unchecked(&data->interrupt_handled))
40204 return;
40205 }
40206
40207diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
40208index 38944e9..ae9e5ed 100644
40209--- a/drivers/hwmon/via-cputemp.c
40210+++ b/drivers/hwmon/via-cputemp.c
40211@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
40212 return NOTIFY_OK;
40213 }
40214
40215-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
40216+static struct notifier_block via_cputemp_cpu_notifier = {
40217 .notifier_call = via_cputemp_cpu_callback,
40218 };
40219
40220diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
40221index 07f01ac..d79ad3d 100644
40222--- a/drivers/i2c/busses/i2c-amd756-s4882.c
40223+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
40224@@ -43,7 +43,7 @@
40225 extern struct i2c_adapter amd756_smbus;
40226
40227 static struct i2c_adapter *s4882_adapter;
40228-static struct i2c_algorithm *s4882_algo;
40229+static i2c_algorithm_no_const *s4882_algo;
40230
40231 /* Wrapper access functions for multiplexed SMBus */
40232 static DEFINE_MUTEX(amd756_lock);
40233diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
40234index 2ca268d..c6acbdf 100644
40235--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
40236+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
40237@@ -41,7 +41,7 @@
40238 extern struct i2c_adapter *nforce2_smbus;
40239
40240 static struct i2c_adapter *s4985_adapter;
40241-static struct i2c_algorithm *s4985_algo;
40242+static i2c_algorithm_no_const *s4985_algo;
40243
40244 /* Wrapper access functions for multiplexed SMBus */
40245 static DEFINE_MUTEX(nforce2_lock);
40246diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
40247index c3ccdea..5b3dc1a 100644
40248--- a/drivers/i2c/i2c-dev.c
40249+++ b/drivers/i2c/i2c-dev.c
40250@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
40251 break;
40252 }
40253
40254- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
40255+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
40256 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
40257 if (IS_ERR(rdwr_pa[i].buf)) {
40258 res = PTR_ERR(rdwr_pa[i].buf);
40259diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
40260index 0b510ba..4fbb5085 100644
40261--- a/drivers/ide/ide-cd.c
40262+++ b/drivers/ide/ide-cd.c
40263@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
40264 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
40265 if ((unsigned long)buf & alignment
40266 || blk_rq_bytes(rq) & q->dma_pad_mask
40267- || object_is_on_stack(buf))
40268+ || object_starts_on_stack(buf))
40269 drive->dma = 0;
40270 }
40271 }
40272diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
40273index e145931..08bfc59 100644
40274--- a/drivers/iio/industrialio-core.c
40275+++ b/drivers/iio/industrialio-core.c
40276@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
40277 }
40278
40279 static
40280-int __iio_device_attr_init(struct device_attribute *dev_attr,
40281+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
40282 const char *postfix,
40283 struct iio_chan_spec const *chan,
40284 ssize_t (*readfunc)(struct device *dev,
40285diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
40286index 784b97c..c9ceadf 100644
40287--- a/drivers/infiniband/core/cm.c
40288+++ b/drivers/infiniband/core/cm.c
40289@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
40290
40291 struct cm_counter_group {
40292 struct kobject obj;
40293- atomic_long_t counter[CM_ATTR_COUNT];
40294+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
40295 };
40296
40297 struct cm_counter_attribute {
40298@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
40299 struct ib_mad_send_buf *msg = NULL;
40300 int ret;
40301
40302- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40303+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40304 counter[CM_REQ_COUNTER]);
40305
40306 /* Quick state check to discard duplicate REQs. */
40307@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
40308 if (!cm_id_priv)
40309 return;
40310
40311- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40312+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40313 counter[CM_REP_COUNTER]);
40314 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
40315 if (ret)
40316@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
40317 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
40318 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
40319 spin_unlock_irq(&cm_id_priv->lock);
40320- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40321+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40322 counter[CM_RTU_COUNTER]);
40323 goto out;
40324 }
40325@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
40326 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
40327 dreq_msg->local_comm_id);
40328 if (!cm_id_priv) {
40329- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40330+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40331 counter[CM_DREQ_COUNTER]);
40332 cm_issue_drep(work->port, work->mad_recv_wc);
40333 return -EINVAL;
40334@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
40335 case IB_CM_MRA_REP_RCVD:
40336 break;
40337 case IB_CM_TIMEWAIT:
40338- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40339+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40340 counter[CM_DREQ_COUNTER]);
40341 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40342 goto unlock;
40343@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
40344 cm_free_msg(msg);
40345 goto deref;
40346 case IB_CM_DREQ_RCVD:
40347- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40348+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40349 counter[CM_DREQ_COUNTER]);
40350 goto unlock;
40351 default:
40352@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
40353 ib_modify_mad(cm_id_priv->av.port->mad_agent,
40354 cm_id_priv->msg, timeout)) {
40355 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
40356- atomic_long_inc(&work->port->
40357+ atomic_long_inc_unchecked(&work->port->
40358 counter_group[CM_RECV_DUPLICATES].
40359 counter[CM_MRA_COUNTER]);
40360 goto out;
40361@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
40362 break;
40363 case IB_CM_MRA_REQ_RCVD:
40364 case IB_CM_MRA_REP_RCVD:
40365- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40366+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40367 counter[CM_MRA_COUNTER]);
40368 /* fall through */
40369 default:
40370@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
40371 case IB_CM_LAP_IDLE:
40372 break;
40373 case IB_CM_MRA_LAP_SENT:
40374- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40375+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40376 counter[CM_LAP_COUNTER]);
40377 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40378 goto unlock;
40379@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
40380 cm_free_msg(msg);
40381 goto deref;
40382 case IB_CM_LAP_RCVD:
40383- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40384+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40385 counter[CM_LAP_COUNTER]);
40386 goto unlock;
40387 default:
40388@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
40389 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
40390 if (cur_cm_id_priv) {
40391 spin_unlock_irq(&cm.lock);
40392- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40393+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40394 counter[CM_SIDR_REQ_COUNTER]);
40395 goto out; /* Duplicate message. */
40396 }
40397@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
40398 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
40399 msg->retries = 1;
40400
40401- atomic_long_add(1 + msg->retries,
40402+ atomic_long_add_unchecked(1 + msg->retries,
40403 &port->counter_group[CM_XMIT].counter[attr_index]);
40404 if (msg->retries)
40405- atomic_long_add(msg->retries,
40406+ atomic_long_add_unchecked(msg->retries,
40407 &port->counter_group[CM_XMIT_RETRIES].
40408 counter[attr_index]);
40409
40410@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
40411 }
40412
40413 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
40414- atomic_long_inc(&port->counter_group[CM_RECV].
40415+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
40416 counter[attr_id - CM_ATTR_ID_OFFSET]);
40417
40418 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
40419@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
40420 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
40421
40422 return sprintf(buf, "%ld\n",
40423- atomic_long_read(&group->counter[cm_attr->index]));
40424+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
40425 }
40426
40427 static const struct sysfs_ops cm_counter_ops = {
40428diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
40429index 9f5ad7c..588cd84 100644
40430--- a/drivers/infiniband/core/fmr_pool.c
40431+++ b/drivers/infiniband/core/fmr_pool.c
40432@@ -98,8 +98,8 @@ struct ib_fmr_pool {
40433
40434 struct task_struct *thread;
40435
40436- atomic_t req_ser;
40437- atomic_t flush_ser;
40438+ atomic_unchecked_t req_ser;
40439+ atomic_unchecked_t flush_ser;
40440
40441 wait_queue_head_t force_wait;
40442 };
40443@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40444 struct ib_fmr_pool *pool = pool_ptr;
40445
40446 do {
40447- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
40448+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
40449 ib_fmr_batch_release(pool);
40450
40451- atomic_inc(&pool->flush_ser);
40452+ atomic_inc_unchecked(&pool->flush_ser);
40453 wake_up_interruptible(&pool->force_wait);
40454
40455 if (pool->flush_function)
40456@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40457 }
40458
40459 set_current_state(TASK_INTERRUPTIBLE);
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 !kthread_should_stop())
40463 schedule();
40464 __set_current_state(TASK_RUNNING);
40465@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
40466 pool->dirty_watermark = params->dirty_watermark;
40467 pool->dirty_len = 0;
40468 spin_lock_init(&pool->pool_lock);
40469- atomic_set(&pool->req_ser, 0);
40470- atomic_set(&pool->flush_ser, 0);
40471+ atomic_set_unchecked(&pool->req_ser, 0);
40472+ atomic_set_unchecked(&pool->flush_ser, 0);
40473 init_waitqueue_head(&pool->force_wait);
40474
40475 pool->thread = kthread_run(ib_fmr_cleanup_thread,
40476@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
40477 }
40478 spin_unlock_irq(&pool->pool_lock);
40479
40480- serial = atomic_inc_return(&pool->req_ser);
40481+ serial = atomic_inc_return_unchecked(&pool->req_ser);
40482 wake_up_process(pool->thread);
40483
40484 if (wait_event_interruptible(pool->force_wait,
40485- atomic_read(&pool->flush_ser) - serial >= 0))
40486+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
40487 return -EINTR;
40488
40489 return 0;
40490@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
40491 } else {
40492 list_add_tail(&fmr->list, &pool->dirty_list);
40493 if (++pool->dirty_len >= pool->dirty_watermark) {
40494- atomic_inc(&pool->req_ser);
40495+ atomic_inc_unchecked(&pool->req_ser);
40496 wake_up_process(pool->thread);
40497 }
40498 }
40499diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
40500index 4cb8eb2..146bf60 100644
40501--- a/drivers/infiniband/hw/cxgb4/mem.c
40502+++ b/drivers/infiniband/hw/cxgb4/mem.c
40503@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40504 int err;
40505 struct fw_ri_tpte tpt;
40506 u32 stag_idx;
40507- static atomic_t key;
40508+ static atomic_unchecked_t key;
40509
40510 if (c4iw_fatal_error(rdev))
40511 return -EIO;
40512@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40513 if (rdev->stats.stag.cur > rdev->stats.stag.max)
40514 rdev->stats.stag.max = rdev->stats.stag.cur;
40515 mutex_unlock(&rdev->stats.lock);
40516- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
40517+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
40518 }
40519 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
40520 __func__, stag_state, type, pdid, stag_idx);
40521diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
40522index 79b3dbc..96e5fcc 100644
40523--- a/drivers/infiniband/hw/ipath/ipath_rc.c
40524+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
40525@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40526 struct ib_atomic_eth *ateth;
40527 struct ipath_ack_entry *e;
40528 u64 vaddr;
40529- atomic64_t *maddr;
40530+ atomic64_unchecked_t *maddr;
40531 u64 sdata;
40532 u32 rkey;
40533 u8 next;
40534@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40535 IB_ACCESS_REMOTE_ATOMIC)))
40536 goto nack_acc_unlck;
40537 /* Perform atomic OP and save result. */
40538- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40539+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40540 sdata = be64_to_cpu(ateth->swap_data);
40541 e = &qp->s_ack_queue[qp->r_head_ack_queue];
40542 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
40543- (u64) atomic64_add_return(sdata, maddr) - sdata :
40544+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40545 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40546 be64_to_cpu(ateth->compare_data),
40547 sdata);
40548diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
40549index 1f95bba..9530f87 100644
40550--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
40551+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
40552@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
40553 unsigned long flags;
40554 struct ib_wc wc;
40555 u64 sdata;
40556- atomic64_t *maddr;
40557+ atomic64_unchecked_t *maddr;
40558 enum ib_wc_status send_status;
40559
40560 /*
40561@@ -382,11 +382,11 @@ again:
40562 IB_ACCESS_REMOTE_ATOMIC)))
40563 goto acc_err;
40564 /* Perform atomic OP and save result. */
40565- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40566+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40567 sdata = wqe->wr.wr.atomic.compare_add;
40568 *(u64 *) sqp->s_sge.sge.vaddr =
40569 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
40570- (u64) atomic64_add_return(sdata, maddr) - sdata :
40571+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40572 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40573 sdata, wqe->wr.wr.atomic.swap);
40574 goto send_comp;
40575diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
40576index f2a3f48..673ec79 100644
40577--- a/drivers/infiniband/hw/mlx4/mad.c
40578+++ b/drivers/infiniband/hw/mlx4/mad.c
40579@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
40580
40581 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
40582 {
40583- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
40584+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
40585 cpu_to_be64(0xff00000000000000LL);
40586 }
40587
40588diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
40589index 25b2cdf..099ff97 100644
40590--- a/drivers/infiniband/hw/mlx4/mcg.c
40591+++ b/drivers/infiniband/hw/mlx4/mcg.c
40592@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
40593 {
40594 char name[20];
40595
40596- atomic_set(&ctx->tid, 0);
40597+ atomic_set_unchecked(&ctx->tid, 0);
40598 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
40599 ctx->mcg_wq = create_singlethread_workqueue(name);
40600 if (!ctx->mcg_wq)
40601diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40602index f61ec26..ebf72cf 100644
40603--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
40604+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40605@@ -398,7 +398,7 @@ struct mlx4_ib_demux_ctx {
40606 struct list_head mcg_mgid0_list;
40607 struct workqueue_struct *mcg_wq;
40608 struct mlx4_ib_demux_pv_ctx **tun;
40609- atomic_t tid;
40610+ atomic_unchecked_t tid;
40611 int flushing; /* flushing the work queue */
40612 };
40613
40614diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
40615index 9d3e5c1..d9afe4a 100644
40616--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
40617+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
40618@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
40619 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
40620 }
40621
40622-int mthca_QUERY_FW(struct mthca_dev *dev)
40623+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
40624 {
40625 struct mthca_mailbox *mailbox;
40626 u32 *outbox;
40627diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
40628index ed9a989..e0c5871 100644
40629--- a/drivers/infiniband/hw/mthca/mthca_mr.c
40630+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
40631@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
40632 return key;
40633 }
40634
40635-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40636+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40637 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
40638 {
40639 struct mthca_mailbox *mailbox;
40640diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
40641index 4291410..d2ab1fb 100644
40642--- a/drivers/infiniband/hw/nes/nes.c
40643+++ b/drivers/infiniband/hw/nes/nes.c
40644@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
40645 LIST_HEAD(nes_adapter_list);
40646 static LIST_HEAD(nes_dev_list);
40647
40648-atomic_t qps_destroyed;
40649+atomic_unchecked_t qps_destroyed;
40650
40651 static unsigned int ee_flsh_adapter;
40652 static unsigned int sysfs_nonidx_addr;
40653@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
40654 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
40655 struct nes_adapter *nesadapter = nesdev->nesadapter;
40656
40657- atomic_inc(&qps_destroyed);
40658+ atomic_inc_unchecked(&qps_destroyed);
40659
40660 /* Free the control structures */
40661
40662diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
40663index 33cc589..3bd6538 100644
40664--- a/drivers/infiniband/hw/nes/nes.h
40665+++ b/drivers/infiniband/hw/nes/nes.h
40666@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
40667 extern unsigned int wqm_quanta;
40668 extern struct list_head nes_adapter_list;
40669
40670-extern atomic_t cm_connects;
40671-extern atomic_t cm_accepts;
40672-extern atomic_t cm_disconnects;
40673-extern atomic_t cm_closes;
40674-extern atomic_t cm_connecteds;
40675-extern atomic_t cm_connect_reqs;
40676-extern atomic_t cm_rejects;
40677-extern atomic_t mod_qp_timouts;
40678-extern atomic_t qps_created;
40679-extern atomic_t qps_destroyed;
40680-extern atomic_t sw_qps_destroyed;
40681+extern atomic_unchecked_t cm_connects;
40682+extern atomic_unchecked_t cm_accepts;
40683+extern atomic_unchecked_t cm_disconnects;
40684+extern atomic_unchecked_t cm_closes;
40685+extern atomic_unchecked_t cm_connecteds;
40686+extern atomic_unchecked_t cm_connect_reqs;
40687+extern atomic_unchecked_t cm_rejects;
40688+extern atomic_unchecked_t mod_qp_timouts;
40689+extern atomic_unchecked_t qps_created;
40690+extern atomic_unchecked_t qps_destroyed;
40691+extern atomic_unchecked_t sw_qps_destroyed;
40692 extern u32 mh_detected;
40693 extern u32 mh_pauses_sent;
40694 extern u32 cm_packets_sent;
40695@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
40696 extern u32 cm_packets_received;
40697 extern u32 cm_packets_dropped;
40698 extern u32 cm_packets_retrans;
40699-extern atomic_t cm_listens_created;
40700-extern atomic_t cm_listens_destroyed;
40701+extern atomic_unchecked_t cm_listens_created;
40702+extern atomic_unchecked_t cm_listens_destroyed;
40703 extern u32 cm_backlog_drops;
40704-extern atomic_t cm_loopbacks;
40705-extern atomic_t cm_nodes_created;
40706-extern atomic_t cm_nodes_destroyed;
40707-extern atomic_t cm_accel_dropped_pkts;
40708-extern atomic_t cm_resets_recvd;
40709-extern atomic_t pau_qps_created;
40710-extern atomic_t pau_qps_destroyed;
40711+extern atomic_unchecked_t cm_loopbacks;
40712+extern atomic_unchecked_t cm_nodes_created;
40713+extern atomic_unchecked_t cm_nodes_destroyed;
40714+extern atomic_unchecked_t cm_accel_dropped_pkts;
40715+extern atomic_unchecked_t cm_resets_recvd;
40716+extern atomic_unchecked_t pau_qps_created;
40717+extern atomic_unchecked_t pau_qps_destroyed;
40718
40719 extern u32 int_mod_timer_init;
40720 extern u32 int_mod_cq_depth_256;
40721diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
40722index 24b9f1a..00fd004 100644
40723--- a/drivers/infiniband/hw/nes/nes_cm.c
40724+++ b/drivers/infiniband/hw/nes/nes_cm.c
40725@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
40726 u32 cm_packets_retrans;
40727 u32 cm_packets_created;
40728 u32 cm_packets_received;
40729-atomic_t cm_listens_created;
40730-atomic_t cm_listens_destroyed;
40731+atomic_unchecked_t cm_listens_created;
40732+atomic_unchecked_t cm_listens_destroyed;
40733 u32 cm_backlog_drops;
40734-atomic_t cm_loopbacks;
40735-atomic_t cm_nodes_created;
40736-atomic_t cm_nodes_destroyed;
40737-atomic_t cm_accel_dropped_pkts;
40738-atomic_t cm_resets_recvd;
40739+atomic_unchecked_t cm_loopbacks;
40740+atomic_unchecked_t cm_nodes_created;
40741+atomic_unchecked_t cm_nodes_destroyed;
40742+atomic_unchecked_t cm_accel_dropped_pkts;
40743+atomic_unchecked_t cm_resets_recvd;
40744
40745 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
40746 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
40747@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
40748
40749 static struct nes_cm_core *g_cm_core;
40750
40751-atomic_t cm_connects;
40752-atomic_t cm_accepts;
40753-atomic_t cm_disconnects;
40754-atomic_t cm_closes;
40755-atomic_t cm_connecteds;
40756-atomic_t cm_connect_reqs;
40757-atomic_t cm_rejects;
40758+atomic_unchecked_t cm_connects;
40759+atomic_unchecked_t cm_accepts;
40760+atomic_unchecked_t cm_disconnects;
40761+atomic_unchecked_t cm_closes;
40762+atomic_unchecked_t cm_connecteds;
40763+atomic_unchecked_t cm_connect_reqs;
40764+atomic_unchecked_t cm_rejects;
40765
40766 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
40767 {
40768@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
40769 kfree(listener);
40770 listener = NULL;
40771 ret = 0;
40772- atomic_inc(&cm_listens_destroyed);
40773+ atomic_inc_unchecked(&cm_listens_destroyed);
40774 } else {
40775 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
40776 }
40777@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
40778 cm_node->rem_mac);
40779
40780 add_hte_node(cm_core, cm_node);
40781- atomic_inc(&cm_nodes_created);
40782+ atomic_inc_unchecked(&cm_nodes_created);
40783
40784 return cm_node;
40785 }
40786@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
40787 }
40788
40789 atomic_dec(&cm_core->node_cnt);
40790- atomic_inc(&cm_nodes_destroyed);
40791+ atomic_inc_unchecked(&cm_nodes_destroyed);
40792 nesqp = cm_node->nesqp;
40793 if (nesqp) {
40794 nesqp->cm_node = NULL;
40795@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
40796
40797 static void drop_packet(struct sk_buff *skb)
40798 {
40799- atomic_inc(&cm_accel_dropped_pkts);
40800+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40801 dev_kfree_skb_any(skb);
40802 }
40803
40804@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
40805 {
40806
40807 int reset = 0; /* whether to send reset in case of err.. */
40808- atomic_inc(&cm_resets_recvd);
40809+ atomic_inc_unchecked(&cm_resets_recvd);
40810 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
40811 " refcnt=%d\n", cm_node, cm_node->state,
40812 atomic_read(&cm_node->ref_count));
40813@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
40814 rem_ref_cm_node(cm_node->cm_core, cm_node);
40815 return NULL;
40816 }
40817- atomic_inc(&cm_loopbacks);
40818+ atomic_inc_unchecked(&cm_loopbacks);
40819 loopbackremotenode->loopbackpartner = cm_node;
40820 loopbackremotenode->tcp_cntxt.rcv_wscale =
40821 NES_CM_DEFAULT_RCV_WND_SCALE;
40822@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
40823 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
40824 else {
40825 rem_ref_cm_node(cm_core, cm_node);
40826- atomic_inc(&cm_accel_dropped_pkts);
40827+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40828 dev_kfree_skb_any(skb);
40829 }
40830 break;
40831@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40832
40833 if ((cm_id) && (cm_id->event_handler)) {
40834 if (issue_disconn) {
40835- atomic_inc(&cm_disconnects);
40836+ atomic_inc_unchecked(&cm_disconnects);
40837 cm_event.event = IW_CM_EVENT_DISCONNECT;
40838 cm_event.status = disconn_status;
40839 cm_event.local_addr = cm_id->local_addr;
40840@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40841 }
40842
40843 if (issue_close) {
40844- atomic_inc(&cm_closes);
40845+ atomic_inc_unchecked(&cm_closes);
40846 nes_disconnect(nesqp, 1);
40847
40848 cm_id->provider_data = nesqp;
40849@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40850
40851 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
40852 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
40853- atomic_inc(&cm_accepts);
40854+ atomic_inc_unchecked(&cm_accepts);
40855
40856 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
40857 netdev_refcnt_read(nesvnic->netdev));
40858@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
40859 struct nes_cm_core *cm_core;
40860 u8 *start_buff;
40861
40862- atomic_inc(&cm_rejects);
40863+ atomic_inc_unchecked(&cm_rejects);
40864 cm_node = (struct nes_cm_node *)cm_id->provider_data;
40865 loopback = cm_node->loopbackpartner;
40866 cm_core = cm_node->cm_core;
40867@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40868 ntohl(cm_id->local_addr.sin_addr.s_addr),
40869 ntohs(cm_id->local_addr.sin_port));
40870
40871- atomic_inc(&cm_connects);
40872+ atomic_inc_unchecked(&cm_connects);
40873 nesqp->active_conn = 1;
40874
40875 /* cache the cm_id in the qp */
40876@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
40877 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
40878 return err;
40879 }
40880- atomic_inc(&cm_listens_created);
40881+ atomic_inc_unchecked(&cm_listens_created);
40882 }
40883
40884 cm_id->add_ref(cm_id);
40885@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
40886
40887 if (nesqp->destroyed)
40888 return;
40889- atomic_inc(&cm_connecteds);
40890+ atomic_inc_unchecked(&cm_connecteds);
40891 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
40892 " local port 0x%04X. jiffies = %lu.\n",
40893 nesqp->hwqp.qp_id,
40894@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
40895
40896 cm_id->add_ref(cm_id);
40897 ret = cm_id->event_handler(cm_id, &cm_event);
40898- atomic_inc(&cm_closes);
40899+ atomic_inc_unchecked(&cm_closes);
40900 cm_event.event = IW_CM_EVENT_CLOSE;
40901 cm_event.status = 0;
40902 cm_event.provider_data = cm_id->provider_data;
40903@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
40904 return;
40905 cm_id = cm_node->cm_id;
40906
40907- atomic_inc(&cm_connect_reqs);
40908+ atomic_inc_unchecked(&cm_connect_reqs);
40909 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
40910 cm_node, cm_id, jiffies);
40911
40912@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
40913 return;
40914 cm_id = cm_node->cm_id;
40915
40916- atomic_inc(&cm_connect_reqs);
40917+ atomic_inc_unchecked(&cm_connect_reqs);
40918 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
40919 cm_node, cm_id, jiffies);
40920
40921diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
40922index 4166452..fc952c3 100644
40923--- a/drivers/infiniband/hw/nes/nes_mgt.c
40924+++ b/drivers/infiniband/hw/nes/nes_mgt.c
40925@@ -40,8 +40,8 @@
40926 #include "nes.h"
40927 #include "nes_mgt.h"
40928
40929-atomic_t pau_qps_created;
40930-atomic_t pau_qps_destroyed;
40931+atomic_unchecked_t pau_qps_created;
40932+atomic_unchecked_t pau_qps_destroyed;
40933
40934 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
40935 {
40936@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
40937 {
40938 struct sk_buff *skb;
40939 unsigned long flags;
40940- atomic_inc(&pau_qps_destroyed);
40941+ atomic_inc_unchecked(&pau_qps_destroyed);
40942
40943 /* Free packets that have not yet been forwarded */
40944 /* Lock is acquired by skb_dequeue when removing the skb */
40945@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
40946 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
40947 skb_queue_head_init(&nesqp->pau_list);
40948 spin_lock_init(&nesqp->pau_lock);
40949- atomic_inc(&pau_qps_created);
40950+ atomic_inc_unchecked(&pau_qps_created);
40951 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
40952 }
40953
40954diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
40955index 49eb511..a774366 100644
40956--- a/drivers/infiniband/hw/nes/nes_nic.c
40957+++ b/drivers/infiniband/hw/nes/nes_nic.c
40958@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
40959 target_stat_values[++index] = mh_detected;
40960 target_stat_values[++index] = mh_pauses_sent;
40961 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
40962- target_stat_values[++index] = atomic_read(&cm_connects);
40963- target_stat_values[++index] = atomic_read(&cm_accepts);
40964- target_stat_values[++index] = atomic_read(&cm_disconnects);
40965- target_stat_values[++index] = atomic_read(&cm_connecteds);
40966- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
40967- target_stat_values[++index] = atomic_read(&cm_rejects);
40968- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
40969- target_stat_values[++index] = atomic_read(&qps_created);
40970- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
40971- target_stat_values[++index] = atomic_read(&qps_destroyed);
40972- target_stat_values[++index] = atomic_read(&cm_closes);
40973+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
40974+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
40975+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
40976+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
40977+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
40978+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
40979+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
40980+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
40981+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
40982+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
40983+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
40984 target_stat_values[++index] = cm_packets_sent;
40985 target_stat_values[++index] = cm_packets_bounced;
40986 target_stat_values[++index] = cm_packets_created;
40987 target_stat_values[++index] = cm_packets_received;
40988 target_stat_values[++index] = cm_packets_dropped;
40989 target_stat_values[++index] = cm_packets_retrans;
40990- target_stat_values[++index] = atomic_read(&cm_listens_created);
40991- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
40992+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
40993+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
40994 target_stat_values[++index] = cm_backlog_drops;
40995- target_stat_values[++index] = atomic_read(&cm_loopbacks);
40996- target_stat_values[++index] = atomic_read(&cm_nodes_created);
40997- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
40998- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
40999- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
41000+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
41001+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
41002+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
41003+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
41004+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
41005 target_stat_values[++index] = nesadapter->free_4kpbl;
41006 target_stat_values[++index] = nesadapter->free_256pbl;
41007 target_stat_values[++index] = int_mod_timer_init;
41008 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
41009 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
41010 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
41011- target_stat_values[++index] = atomic_read(&pau_qps_created);
41012- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
41013+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
41014+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
41015 }
41016
41017 /**
41018diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
41019index 5b53ca5..443da3c 100644
41020--- a/drivers/infiniband/hw/nes/nes_verbs.c
41021+++ b/drivers/infiniband/hw/nes/nes_verbs.c
41022@@ -46,9 +46,9 @@
41023
41024 #include <rdma/ib_umem.h>
41025
41026-atomic_t mod_qp_timouts;
41027-atomic_t qps_created;
41028-atomic_t sw_qps_destroyed;
41029+atomic_unchecked_t mod_qp_timouts;
41030+atomic_unchecked_t qps_created;
41031+atomic_unchecked_t sw_qps_destroyed;
41032
41033 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
41034
41035@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
41036 if (init_attr->create_flags)
41037 return ERR_PTR(-EINVAL);
41038
41039- atomic_inc(&qps_created);
41040+ atomic_inc_unchecked(&qps_created);
41041 switch (init_attr->qp_type) {
41042 case IB_QPT_RC:
41043 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
41044@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
41045 struct iw_cm_event cm_event;
41046 int ret = 0;
41047
41048- atomic_inc(&sw_qps_destroyed);
41049+ atomic_inc_unchecked(&sw_qps_destroyed);
41050 nesqp->destroyed = 1;
41051
41052 /* Blow away the connection if it exists. */
41053diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
41054index 4a9af79..b993f75 100644
41055--- a/drivers/infiniband/hw/qib/qib.h
41056+++ b/drivers/infiniband/hw/qib/qib.h
41057@@ -52,6 +52,7 @@
41058 #include <linux/kref.h>
41059 #include <linux/sched.h>
41060 #include <linux/kthread.h>
41061+#include <linux/slab.h>
41062
41063 #include "qib_common.h"
41064 #include "qib_verbs.h"
41065diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
41066index da739d9..da1c7f4 100644
41067--- a/drivers/input/gameport/gameport.c
41068+++ b/drivers/input/gameport/gameport.c
41069@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
41070 */
41071 static void gameport_init_port(struct gameport *gameport)
41072 {
41073- static atomic_t gameport_no = ATOMIC_INIT(0);
41074+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
41075
41076 __module_get(THIS_MODULE);
41077
41078 mutex_init(&gameport->drv_mutex);
41079 device_initialize(&gameport->dev);
41080 dev_set_name(&gameport->dev, "gameport%lu",
41081- (unsigned long)atomic_inc_return(&gameport_no) - 1);
41082+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
41083 gameport->dev.bus = &gameport_bus;
41084 gameport->dev.release = gameport_release_port;
41085 if (gameport->parent)
41086diff --git a/drivers/input/input.c b/drivers/input/input.c
41087index c044699..174d71a 100644
41088--- a/drivers/input/input.c
41089+++ b/drivers/input/input.c
41090@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
41091 */
41092 int input_register_device(struct input_dev *dev)
41093 {
41094- static atomic_t input_no = ATOMIC_INIT(0);
41095+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
41096 struct input_devres *devres = NULL;
41097 struct input_handler *handler;
41098 unsigned int packet_size;
41099@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
41100 dev->setkeycode = input_default_setkeycode;
41101
41102 dev_set_name(&dev->dev, "input%ld",
41103- (unsigned long) atomic_inc_return(&input_no) - 1);
41104+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
41105
41106 error = device_add(&dev->dev);
41107 if (error)
41108diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
41109index 04c69af..5f92d00 100644
41110--- a/drivers/input/joystick/sidewinder.c
41111+++ b/drivers/input/joystick/sidewinder.c
41112@@ -30,6 +30,7 @@
41113 #include <linux/kernel.h>
41114 #include <linux/module.h>
41115 #include <linux/slab.h>
41116+#include <linux/sched.h>
41117 #include <linux/init.h>
41118 #include <linux/input.h>
41119 #include <linux/gameport.h>
41120diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
41121index 75e3b10..fb390fd 100644
41122--- a/drivers/input/joystick/xpad.c
41123+++ b/drivers/input/joystick/xpad.c
41124@@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
41125
41126 static int xpad_led_probe(struct usb_xpad *xpad)
41127 {
41128- static atomic_t led_seq = ATOMIC_INIT(0);
41129+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
41130 long led_no;
41131 struct xpad_led *led;
41132 struct led_classdev *led_cdev;
41133@@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
41134 if (!led)
41135 return -ENOMEM;
41136
41137- led_no = (long)atomic_inc_return(&led_seq) - 1;
41138+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
41139
41140 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
41141 led->xpad = xpad;
41142diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
41143index e204f26..8459f15 100644
41144--- a/drivers/input/misc/ims-pcu.c
41145+++ b/drivers/input/misc/ims-pcu.c
41146@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
41147
41148 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
41149 {
41150- static atomic_t device_no = ATOMIC_INIT(0);
41151+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
41152
41153 const struct ims_pcu_device_info *info;
41154 u8 device_id;
41155@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
41156 }
41157
41158 /* Device appears to be operable, complete initialization */
41159- pcu->device_no = atomic_inc_return(&device_no) - 1;
41160+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
41161
41162 error = ims_pcu_setup_backlight(pcu);
41163 if (error)
41164diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
41165index 2f0b39d..7370f13 100644
41166--- a/drivers/input/mouse/psmouse.h
41167+++ b/drivers/input/mouse/psmouse.h
41168@@ -116,7 +116,7 @@ struct psmouse_attribute {
41169 ssize_t (*set)(struct psmouse *psmouse, void *data,
41170 const char *buf, size_t count);
41171 bool protect;
41172-};
41173+} __do_const;
41174 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
41175
41176 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
41177diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
41178index 4c842c3..590b0bf 100644
41179--- a/drivers/input/mousedev.c
41180+++ b/drivers/input/mousedev.c
41181@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
41182
41183 spin_unlock_irq(&client->packet_lock);
41184
41185- if (copy_to_user(buffer, data, count))
41186+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
41187 return -EFAULT;
41188
41189 return count;
41190diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
41191index 25fc597..558bf3b3 100644
41192--- a/drivers/input/serio/serio.c
41193+++ b/drivers/input/serio/serio.c
41194@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
41195 */
41196 static void serio_init_port(struct serio *serio)
41197 {
41198- static atomic_t serio_no = ATOMIC_INIT(0);
41199+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
41200
41201 __module_get(THIS_MODULE);
41202
41203@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
41204 mutex_init(&serio->drv_mutex);
41205 device_initialize(&serio->dev);
41206 dev_set_name(&serio->dev, "serio%ld",
41207- (long)atomic_inc_return(&serio_no) - 1);
41208+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
41209 serio->dev.bus = &serio_bus;
41210 serio->dev.release = serio_release_port;
41211 serio->dev.groups = serio_device_attr_groups;
41212diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
41213index 59df2e7..8f1cafb 100644
41214--- a/drivers/input/serio/serio_raw.c
41215+++ b/drivers/input/serio/serio_raw.c
41216@@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
41217
41218 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41219 {
41220- static atomic_t serio_raw_no = ATOMIC_INIT(0);
41221+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
41222 struct serio_raw *serio_raw;
41223 int err;
41224
41225@@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41226 }
41227
41228 snprintf(serio_raw->name, sizeof(serio_raw->name),
41229- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
41230+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
41231 kref_init(&serio_raw->kref);
41232 INIT_LIST_HEAD(&serio_raw->client_list);
41233 init_waitqueue_head(&serio_raw->wait);
41234diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
41235index fbe9ca7..dbee61d 100644
41236--- a/drivers/iommu/iommu.c
41237+++ b/drivers/iommu/iommu.c
41238@@ -583,7 +583,7 @@ static struct notifier_block iommu_bus_nb = {
41239 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
41240 {
41241 bus_register_notifier(bus, &iommu_bus_nb);
41242- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
41243+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
41244 }
41245
41246 /**
41247diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
41248index 39f81ae..2660096 100644
41249--- a/drivers/iommu/irq_remapping.c
41250+++ b/drivers/iommu/irq_remapping.c
41251@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
41252 void panic_if_irq_remap(const char *msg)
41253 {
41254 if (irq_remapping_enabled)
41255- panic(msg);
41256+ panic("%s", msg);
41257 }
41258
41259 static void ir_ack_apic_edge(struct irq_data *data)
41260@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
41261
41262 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
41263 {
41264- chip->irq_print_chip = ir_print_prefix;
41265- chip->irq_ack = ir_ack_apic_edge;
41266- chip->irq_eoi = ir_ack_apic_level;
41267- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41268+ pax_open_kernel();
41269+ *(void **)&chip->irq_print_chip = ir_print_prefix;
41270+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
41271+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
41272+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41273+ pax_close_kernel();
41274 }
41275
41276 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
41277diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
41278index ee7c503..5d4ce08 100644
41279--- a/drivers/irqchip/irq-gic.c
41280+++ b/drivers/irqchip/irq-gic.c
41281@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
41282 * Supported arch specific GIC irq extension.
41283 * Default make them NULL.
41284 */
41285-struct irq_chip gic_arch_extn = {
41286+irq_chip_no_const gic_arch_extn = {
41287 .irq_eoi = NULL,
41288 .irq_mask = NULL,
41289 .irq_unmask = NULL,
41290@@ -333,7 +333,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
41291 chained_irq_exit(chip, desc);
41292 }
41293
41294-static struct irq_chip gic_chip = {
41295+static irq_chip_no_const gic_chip __read_only = {
41296 .name = "GIC",
41297 .irq_mask = gic_mask_irq,
41298 .irq_unmask = gic_unmask_irq,
41299diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
41300index ac6f72b..81150f2 100644
41301--- a/drivers/isdn/capi/capi.c
41302+++ b/drivers/isdn/capi/capi.c
41303@@ -81,8 +81,8 @@ struct capiminor {
41304
41305 struct capi20_appl *ap;
41306 u32 ncci;
41307- atomic_t datahandle;
41308- atomic_t msgid;
41309+ atomic_unchecked_t datahandle;
41310+ atomic_unchecked_t msgid;
41311
41312 struct tty_port port;
41313 int ttyinstop;
41314@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
41315 capimsg_setu16(s, 2, mp->ap->applid);
41316 capimsg_setu8 (s, 4, CAPI_DATA_B3);
41317 capimsg_setu8 (s, 5, CAPI_RESP);
41318- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
41319+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
41320 capimsg_setu32(s, 8, mp->ncci);
41321 capimsg_setu16(s, 12, datahandle);
41322 }
41323@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
41324 mp->outbytes -= len;
41325 spin_unlock_bh(&mp->outlock);
41326
41327- datahandle = atomic_inc_return(&mp->datahandle);
41328+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
41329 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
41330 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41331 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41332 capimsg_setu16(skb->data, 2, mp->ap->applid);
41333 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
41334 capimsg_setu8 (skb->data, 5, CAPI_REQ);
41335- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
41336+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
41337 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
41338 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
41339 capimsg_setu16(skb->data, 16, len); /* Data length */
41340diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
41341index 600c79b..3752bab 100644
41342--- a/drivers/isdn/gigaset/interface.c
41343+++ b/drivers/isdn/gigaset/interface.c
41344@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
41345 }
41346 tty->driver_data = cs;
41347
41348- ++cs->port.count;
41349+ atomic_inc(&cs->port.count);
41350
41351- if (cs->port.count == 1) {
41352+ if (atomic_read(&cs->port.count) == 1) {
41353 tty_port_tty_set(&cs->port, tty);
41354 cs->port.low_latency = 1;
41355 }
41356@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
41357
41358 if (!cs->connected)
41359 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
41360- else if (!cs->port.count)
41361+ else if (!atomic_read(&cs->port.count))
41362 dev_warn(cs->dev, "%s: device not opened\n", __func__);
41363- else if (!--cs->port.count)
41364+ else if (!atomic_dec_return(&cs->port.count))
41365 tty_port_tty_set(&cs->port, NULL);
41366
41367 mutex_unlock(&cs->mutex);
41368diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
41369index d0a41cb..f0cdb8c 100644
41370--- a/drivers/isdn/gigaset/usb-gigaset.c
41371+++ b/drivers/isdn/gigaset/usb-gigaset.c
41372@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
41373 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
41374 memcpy(cs->hw.usb->bchars, buf, 6);
41375 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
41376- 0, 0, &buf, 6, 2000);
41377+ 0, 0, buf, 6, 2000);
41378 }
41379
41380 static void gigaset_freebcshw(struct bc_state *bcs)
41381diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
41382index 4d9b195..455075c 100644
41383--- a/drivers/isdn/hardware/avm/b1.c
41384+++ b/drivers/isdn/hardware/avm/b1.c
41385@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
41386 }
41387 if (left) {
41388 if (t4file->user) {
41389- if (copy_from_user(buf, dp, left))
41390+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41391 return -EFAULT;
41392 } else {
41393 memcpy(buf, dp, left);
41394@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
41395 }
41396 if (left) {
41397 if (config->user) {
41398- if (copy_from_user(buf, dp, left))
41399+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41400 return -EFAULT;
41401 } else {
41402 memcpy(buf, dp, left);
41403diff --git a/drivers/isdn/hisax/amd7930_fn.c b/drivers/isdn/hisax/amd7930_fn.c
41404index 1063bab..36817e0 100644
41405--- a/drivers/isdn/hisax/amd7930_fn.c
41406+++ b/drivers/isdn/hisax/amd7930_fn.c
41407@@ -314,7 +314,7 @@ Amd7930_empty_Dfifo(struct IsdnCardState *cs, int flag)
41408
41409 t += sprintf(t, "Amd7930: empty_Dfifo cnt: %d |", cs->rcvidx);
41410 QuickHex(t, cs->rcvbuf, cs->rcvidx);
41411- debugl1(cs, cs->dlog);
41412+ debugl1(cs, "%s", cs->dlog);
41413 }
41414 /* moves received data in sk-buffer */
41415 memcpy(skb_put(skb, cs->rcvidx), cs->rcvbuf, cs->rcvidx);
41416@@ -406,7 +406,7 @@ Amd7930_fill_Dfifo(struct IsdnCardState *cs)
41417
41418 t += sprintf(t, "Amd7930: fill_Dfifo cnt: %d |", count);
41419 QuickHex(t, deb_ptr, count);
41420- debugl1(cs, cs->dlog);
41421+ debugl1(cs, "%s", cs->dlog);
41422 }
41423 /* AMD interrupts on */
41424 AmdIrqOn(cs);
41425diff --git a/drivers/isdn/hisax/avm_pci.c b/drivers/isdn/hisax/avm_pci.c
41426index ee9b9a0..d1427bd 100644
41427--- a/drivers/isdn/hisax/avm_pci.c
41428+++ b/drivers/isdn/hisax/avm_pci.c
41429@@ -285,7 +285,7 @@ hdlc_empty_fifo(struct BCState *bcs, int count)
41430 t += sprintf(t, "hdlc_empty_fifo %c cnt %d",
41431 bcs->channel ? 'B' : 'A', count);
41432 QuickHex(t, p, count);
41433- debugl1(cs, bcs->blog);
41434+ debugl1(cs, "%s", bcs->blog);
41435 }
41436 }
41437
41438@@ -345,7 +345,7 @@ hdlc_fill_fifo(struct BCState *bcs)
41439 t += sprintf(t, "hdlc_fill_fifo %c cnt %d",
41440 bcs->channel ? 'B' : 'A', count);
41441 QuickHex(t, p, count);
41442- debugl1(cs, bcs->blog);
41443+ debugl1(cs, "%s", bcs->blog);
41444 }
41445 }
41446
41447diff --git a/drivers/isdn/hisax/config.c b/drivers/isdn/hisax/config.c
41448index bf04d2a..b33f53b 100644
41449--- a/drivers/isdn/hisax/config.c
41450+++ b/drivers/isdn/hisax/config.c
41451@@ -1896,7 +1896,7 @@ static void EChannel_proc_rcv(struct hisax_d_if *d_if)
41452 ptr--;
41453 *ptr++ = '\n';
41454 *ptr = 0;
41455- HiSax_putstatus(cs, NULL, cs->dlog);
41456+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41457 } else
41458 HiSax_putstatus(cs, "LogEcho: ",
41459 "warning Frame too big (%d)",
41460diff --git a/drivers/isdn/hisax/diva.c b/drivers/isdn/hisax/diva.c
41461index 8d0cf6e..4fc90de 100644
41462--- a/drivers/isdn/hisax/diva.c
41463+++ b/drivers/isdn/hisax/diva.c
41464@@ -427,7 +427,7 @@ Memhscx_empty_fifo(struct BCState *bcs, int count)
41465 t += sprintf(t, "hscx_empty_fifo %c cnt %d",
41466 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41467 QuickHex(t, ptr, count);
41468- debugl1(cs, bcs->blog);
41469+ debugl1(cs, "%s", bcs->blog);
41470 }
41471 }
41472
41473@@ -469,7 +469,7 @@ Memhscx_fill_fifo(struct BCState *bcs)
41474 t += sprintf(t, "hscx_fill_fifo %c cnt %d",
41475 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41476 QuickHex(t, ptr, count);
41477- debugl1(cs, bcs->blog);
41478+ debugl1(cs, "%s", bcs->blog);
41479 }
41480 }
41481
41482diff --git a/drivers/isdn/hisax/elsa.c b/drivers/isdn/hisax/elsa.c
41483index 1df6f9a..2be1c8a 100644
41484--- a/drivers/isdn/hisax/elsa.c
41485+++ b/drivers/isdn/hisax/elsa.c
41486@@ -535,7 +535,7 @@ check_arcofi(struct IsdnCardState *cs)
41487 t = tmp;
41488 t += sprintf(tmp, "Arcofi data");
41489 QuickHex(t, p, cs->dc.isac.mon_rxp);
41490- debugl1(cs, tmp);
41491+ debugl1(cs, "%s", tmp);
41492 if ((cs->dc.isac.mon_rxp == 2) && (cs->dc.isac.mon_rx[0] == 0xa0)) {
41493 switch (cs->dc.isac.mon_rx[1]) {
41494 case 0x80:
41495diff --git a/drivers/isdn/hisax/elsa_ser.c b/drivers/isdn/hisax/elsa_ser.c
41496index d4c98d3..3f84dd8 100644
41497--- a/drivers/isdn/hisax/elsa_ser.c
41498+++ b/drivers/isdn/hisax/elsa_ser.c
41499@@ -344,7 +344,7 @@ static inline void receive_chars(struct IsdnCardState *cs,
41500
41501 t += sprintf(t, "modem read cnt %d", cs->hw.elsa.rcvcnt);
41502 QuickHex(t, cs->hw.elsa.rcvbuf, cs->hw.elsa.rcvcnt);
41503- debugl1(cs, tmp);
41504+ debugl1(cs, "%s", tmp);
41505 }
41506 cs->hw.elsa.rcvcnt = 0;
41507 }
41508diff --git a/drivers/isdn/hisax/hfc_pci.c b/drivers/isdn/hisax/hfc_pci.c
41509index 3ccd724..497bd02 100644
41510--- a/drivers/isdn/hisax/hfc_pci.c
41511+++ b/drivers/isdn/hisax/hfc_pci.c
41512@@ -901,7 +901,7 @@ Begin:
41513 ptr--;
41514 *ptr++ = '\n';
41515 *ptr = 0;
41516- HiSax_putstatus(cs, NULL, cs->dlog);
41517+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41518 } else
41519 HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", total - 3);
41520 }
41521diff --git a/drivers/isdn/hisax/hfc_sx.c b/drivers/isdn/hisax/hfc_sx.c
41522index dc4574f..fa1fefd 100644
41523--- a/drivers/isdn/hisax/hfc_sx.c
41524+++ b/drivers/isdn/hisax/hfc_sx.c
41525@@ -674,7 +674,7 @@ receive_emsg(struct IsdnCardState *cs)
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)", skb->len);
41533 }
41534diff --git a/drivers/isdn/hisax/hscx_irq.c b/drivers/isdn/hisax/hscx_irq.c
41535index f398d48..a8d6188 100644
41536--- a/drivers/isdn/hisax/hscx_irq.c
41537+++ b/drivers/isdn/hisax/hscx_irq.c
41538@@ -75,7 +75,7 @@ hscx_empty_fifo(struct BCState *bcs, int count)
41539 t += sprintf(t, "hscx_empty_fifo %c cnt %d",
41540 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41541 QuickHex(t, ptr, count);
41542- debugl1(cs, bcs->blog);
41543+ debugl1(cs, "%s", bcs->blog);
41544 }
41545 }
41546
41547@@ -115,7 +115,7 @@ hscx_fill_fifo(struct BCState *bcs)
41548 t += sprintf(t, "hscx_fill_fifo %c cnt %d",
41549 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41550 QuickHex(t, ptr, count);
41551- debugl1(cs, bcs->blog);
41552+ debugl1(cs, "%s", bcs->blog);
41553 }
41554 }
41555
41556diff --git a/drivers/isdn/hisax/icc.c b/drivers/isdn/hisax/icc.c
41557index db5321f..51dae91 100644
41558--- a/drivers/isdn/hisax/icc.c
41559+++ b/drivers/isdn/hisax/icc.c
41560@@ -134,7 +134,7 @@ icc_empty_fifo(struct IsdnCardState *cs, int count)
41561
41562 t += sprintf(t, "icc_empty_fifo cnt %d", count);
41563 QuickHex(t, ptr, count);
41564- debugl1(cs, cs->dlog);
41565+ debugl1(cs, "%s", cs->dlog);
41566 }
41567 }
41568
41569@@ -176,7 +176,7 @@ icc_fill_fifo(struct IsdnCardState *cs)
41570
41571 t += sprintf(t, "icc_fill_fifo cnt %d", count);
41572 QuickHex(t, ptr, count);
41573- debugl1(cs, cs->dlog);
41574+ debugl1(cs, "%s", cs->dlog);
41575 }
41576 }
41577
41578diff --git a/drivers/isdn/hisax/ipacx.c b/drivers/isdn/hisax/ipacx.c
41579index 74feb5c..5faa5de 100644
41580--- a/drivers/isdn/hisax/ipacx.c
41581+++ b/drivers/isdn/hisax/ipacx.c
41582@@ -260,7 +260,7 @@ dch_empty_fifo(struct IsdnCardState *cs, int count)
41583
41584 t += sprintf(t, "dch_empty_fifo() cnt %d", count);
41585 QuickHex(t, ptr, count);
41586- debugl1(cs, cs->dlog);
41587+ debugl1(cs, "%s", cs->dlog);
41588 }
41589 }
41590
41591@@ -307,7 +307,7 @@ dch_fill_fifo(struct IsdnCardState *cs)
41592
41593 t += sprintf(t, "dch_fill_fifo() cnt %d", count);
41594 QuickHex(t, ptr, count);
41595- debugl1(cs, cs->dlog);
41596+ debugl1(cs, "%s", cs->dlog);
41597 }
41598 }
41599
41600@@ -539,7 +539,7 @@ bch_empty_fifo(struct BCState *bcs, int count)
41601
41602 t += sprintf(t, "bch_empty_fifo() B-%d cnt %d", hscx, count);
41603 QuickHex(t, ptr, count);
41604- debugl1(cs, bcs->blog);
41605+ debugl1(cs, "%s", bcs->blog);
41606 }
41607 }
41608
41609@@ -582,7 +582,7 @@ bch_fill_fifo(struct BCState *bcs)
41610
41611 t += sprintf(t, "chb_fill_fifo() B-%d cnt %d", hscx, count);
41612 QuickHex(t, ptr, count);
41613- debugl1(cs, bcs->blog);
41614+ debugl1(cs, "%s", bcs->blog);
41615 }
41616 }
41617
41618diff --git a/drivers/isdn/hisax/isac.c b/drivers/isdn/hisax/isac.c
41619index a365ccc..7fdf78f 100644
41620--- a/drivers/isdn/hisax/isac.c
41621+++ b/drivers/isdn/hisax/isac.c
41622@@ -137,7 +137,7 @@ isac_empty_fifo(struct IsdnCardState *cs, int count)
41623
41624 t += sprintf(t, "isac_empty_fifo cnt %d", count);
41625 QuickHex(t, ptr, count);
41626- debugl1(cs, cs->dlog);
41627+ debugl1(cs, "%s", cs->dlog);
41628 }
41629 }
41630
41631@@ -179,7 +179,7 @@ isac_fill_fifo(struct IsdnCardState *cs)
41632
41633 t += sprintf(t, "isac_fill_fifo cnt %d", count);
41634 QuickHex(t, ptr, count);
41635- debugl1(cs, cs->dlog);
41636+ debugl1(cs, "%s", cs->dlog);
41637 }
41638 }
41639
41640diff --git a/drivers/isdn/hisax/isar.c b/drivers/isdn/hisax/isar.c
41641index 7fdf347..f4956c7 100644
41642--- a/drivers/isdn/hisax/isar.c
41643+++ b/drivers/isdn/hisax/isar.c
41644@@ -74,7 +74,7 @@ sendmsg(struct IsdnCardState *cs, u_char his, u_char creg, u_char len,
41645 t = tmp;
41646 t += sprintf(t, "sendmbox cnt %d", len);
41647 QuickHex(t, &msg[len-i], (i > 64) ? 64 : i);
41648- debugl1(cs, tmp);
41649+ debugl1(cs, "%s", tmp);
41650 i -= 64;
41651 }
41652 }
41653@@ -105,7 +105,7 @@ rcv_mbox(struct IsdnCardState *cs, struct isar_reg *ireg, u_char *msg)
41654 t = tmp;
41655 t += sprintf(t, "rcv_mbox cnt %d", ireg->clsb);
41656 QuickHex(t, &msg[ireg->clsb - i], (i > 64) ? 64 : i);
41657- debugl1(cs, tmp);
41658+ debugl1(cs, "%s", tmp);
41659 i -= 64;
41660 }
41661 }
41662@@ -1248,7 +1248,7 @@ isar_int_main(struct IsdnCardState *cs)
41663 tp += sprintf(debbuf, "msg iis(%x) msb(%x)",
41664 ireg->iis, ireg->cmsb);
41665 QuickHex(tp, (u_char *)ireg->par, ireg->clsb);
41666- debugl1(cs, debbuf);
41667+ debugl1(cs, "%s", debbuf);
41668 }
41669 break;
41670 case ISAR_IIS_INVMSG:
41671diff --git a/drivers/isdn/hisax/jade.c b/drivers/isdn/hisax/jade.c
41672index f946c58..e2ae787 100644
41673--- a/drivers/isdn/hisax/jade.c
41674+++ b/drivers/isdn/hisax/jade.c
41675@@ -81,10 +81,7 @@ modejade(struct BCState *bcs, int mode, int bc)
41676 int jade = bcs->hw.hscx.hscx;
41677
41678 if (cs->debug & L1_DEB_HSCX) {
41679- char tmp[40];
41680- sprintf(tmp, "jade %c mode %d ichan %d",
41681- 'A' + jade, mode, bc);
41682- debugl1(cs, tmp);
41683+ debugl1(cs, "jade %c mode %d ichan %d", 'A' + jade, mode, bc);
41684 }
41685 bcs->mode = mode;
41686 bcs->channel = bc;
41687@@ -257,23 +254,18 @@ void
41688 clear_pending_jade_ints(struct IsdnCardState *cs)
41689 {
41690 int val;
41691- char tmp[64];
41692
41693 cs->BC_Write_Reg(cs, 0, jade_HDLC_IMR, 0x00);
41694 cs->BC_Write_Reg(cs, 1, jade_HDLC_IMR, 0x00);
41695
41696 val = cs->BC_Read_Reg(cs, 1, jade_HDLC_ISR);
41697- sprintf(tmp, "jade B ISTA %x", val);
41698- debugl1(cs, tmp);
41699+ debugl1(cs, "jade B ISTA %x", val);
41700 val = cs->BC_Read_Reg(cs, 0, jade_HDLC_ISR);
41701- sprintf(tmp, "jade A ISTA %x", val);
41702- debugl1(cs, tmp);
41703+ debugl1(cs, "jade A ISTA %x", val);
41704 val = cs->BC_Read_Reg(cs, 1, jade_HDLC_STAR);
41705- sprintf(tmp, "jade B STAR %x", val);
41706- debugl1(cs, tmp);
41707+ debugl1(cs, "jade B STAR %x", val);
41708 val = cs->BC_Read_Reg(cs, 0, jade_HDLC_STAR);
41709- sprintf(tmp, "jade A STAR %x", val);
41710- debugl1(cs, tmp);
41711+ debugl1(cs, "jade A STAR %x", val);
41712 /* Unmask ints */
41713 cs->BC_Write_Reg(cs, 0, jade_HDLC_IMR, 0xF8);
41714 cs->BC_Write_Reg(cs, 1, jade_HDLC_IMR, 0xF8);
41715diff --git a/drivers/isdn/hisax/jade_irq.c b/drivers/isdn/hisax/jade_irq.c
41716index f521fc8..b930da9 100644
41717--- a/drivers/isdn/hisax/jade_irq.c
41718+++ b/drivers/isdn/hisax/jade_irq.c
41719@@ -65,7 +65,7 @@ jade_empty_fifo(struct BCState *bcs, int count)
41720 t += sprintf(t, "jade_empty_fifo %c cnt %d",
41721 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41722 QuickHex(t, ptr, count);
41723- debugl1(cs, bcs->blog);
41724+ debugl1(cs, "%s", bcs->blog);
41725 }
41726 }
41727
41728@@ -105,7 +105,7 @@ jade_fill_fifo(struct BCState *bcs)
41729 t += sprintf(t, "jade_fill_fifo %c cnt %d",
41730 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41731 QuickHex(t, ptr, count);
41732- debugl1(cs, bcs->blog);
41733+ debugl1(cs, "%s", bcs->blog);
41734 }
41735 }
41736
41737diff --git a/drivers/isdn/hisax/l3_1tr6.c b/drivers/isdn/hisax/l3_1tr6.c
41738index 4c1bca5..875402e 100644
41739--- a/drivers/isdn/hisax/l3_1tr6.c
41740+++ b/drivers/isdn/hisax/l3_1tr6.c
41741@@ -63,7 +63,7 @@ l3_1tr6_error(struct l3_process *pc, u_char *msg, struct sk_buff *skb)
41742 {
41743 dev_kfree_skb(skb);
41744 if (pc->st->l3.debug & L3_DEB_WARN)
41745- l3_debug(pc->st, msg);
41746+ l3_debug(pc->st, "%s", msg);
41747 l3_1tr6_release_req(pc, 0, NULL);
41748 }
41749
41750@@ -161,7 +161,6 @@ l3_1tr6_setup(struct l3_process *pc, u_char pr, void *arg)
41751 {
41752 u_char *p;
41753 int bcfound = 0;
41754- char tmp[80];
41755 struct sk_buff *skb = arg;
41756
41757 /* Channel Identification */
41758@@ -214,10 +213,9 @@ l3_1tr6_setup(struct l3_process *pc, u_char pr, void *arg)
41759 /* Signal all services, linklevel takes care of Service-Indicator */
41760 if (bcfound) {
41761 if ((pc->para.setup.si1 != 7) && (pc->st->l3.debug & L3_DEB_WARN)) {
41762- sprintf(tmp, "non-digital call: %s -> %s",
41763+ l3_debug(pc->st, "non-digital call: %s -> %s",
41764 pc->para.setup.phone,
41765 pc->para.setup.eazmsn);
41766- l3_debug(pc->st, tmp);
41767 }
41768 newl3state(pc, 6);
41769 pc->st->l3.l3l4(pc->st, CC_SETUP | INDICATION, pc);
41770@@ -301,7 +299,7 @@ l3_1tr6_info(struct l3_process *pc, u_char pr, void *arg)
41771 {
41772 u_char *p;
41773 int i, tmpcharge = 0;
41774- char a_charge[8], tmp[32];
41775+ char a_charge[8];
41776 struct sk_buff *skb = arg;
41777
41778 p = skb->data;
41779@@ -316,8 +314,8 @@ l3_1tr6_info(struct l3_process *pc, u_char pr, void *arg)
41780 pc->st->l3.l3l4(pc->st, CC_CHARGE | INDICATION, pc);
41781 }
41782 if (pc->st->l3.debug & L3_DEB_CHARGE) {
41783- sprintf(tmp, "charging info %d", pc->para.chargeinfo);
41784- l3_debug(pc->st, tmp);
41785+ l3_debug(pc->st, "charging info %d",
41786+ pc->para.chargeinfo);
41787 }
41788 } else if (pc->st->l3.debug & L3_DEB_CHARGE)
41789 l3_debug(pc->st, "charging info not found");
41790@@ -399,7 +397,7 @@ l3_1tr6_disc(struct l3_process *pc, u_char pr, void *arg)
41791 struct sk_buff *skb = arg;
41792 u_char *p;
41793 int i, tmpcharge = 0;
41794- char a_charge[8], tmp[32];
41795+ char a_charge[8];
41796
41797 StopAllL3Timer(pc);
41798 p = skb->data;
41799@@ -414,8 +412,8 @@ l3_1tr6_disc(struct l3_process *pc, u_char pr, void *arg)
41800 pc->st->l3.l3l4(pc->st, CC_CHARGE | INDICATION, pc);
41801 }
41802 if (pc->st->l3.debug & L3_DEB_CHARGE) {
41803- sprintf(tmp, "charging info %d", pc->para.chargeinfo);
41804- l3_debug(pc->st, tmp);
41805+ l3_debug(pc->st, "charging info %d",
41806+ pc->para.chargeinfo);
41807 }
41808 } else if (pc->st->l3.debug & L3_DEB_CHARGE)
41809 l3_debug(pc->st, "charging info not found");
41810@@ -746,7 +744,6 @@ up1tr6(struct PStack *st, int pr, void *arg)
41811 int i, mt, cr;
41812 struct l3_process *proc;
41813 struct sk_buff *skb = arg;
41814- char tmp[80];
41815
41816 switch (pr) {
41817 case (DL_DATA | INDICATION):
41818@@ -762,26 +759,23 @@ up1tr6(struct PStack *st, int pr, void *arg)
41819 }
41820 if (skb->len < 4) {
41821 if (st->l3.debug & L3_DEB_PROTERR) {
41822- sprintf(tmp, "up1tr6 len only %d", skb->len);
41823- l3_debug(st, tmp);
41824+ l3_debug(st, "up1tr6 len only %d", skb->len);
41825 }
41826 dev_kfree_skb(skb);
41827 return;
41828 }
41829 if ((skb->data[0] & 0xfe) != PROTO_DIS_N0) {
41830 if (st->l3.debug & L3_DEB_PROTERR) {
41831- sprintf(tmp, "up1tr6%sunexpected discriminator %x message len %d",
41832+ l3_debug(st, "up1tr6%sunexpected discriminator %x message len %d",
41833 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41834 skb->data[0], skb->len);
41835- l3_debug(st, tmp);
41836 }
41837 dev_kfree_skb(skb);
41838 return;
41839 }
41840 if (skb->data[1] != 1) {
41841 if (st->l3.debug & L3_DEB_PROTERR) {
41842- sprintf(tmp, "up1tr6 CR len not 1");
41843- l3_debug(st, tmp);
41844+ l3_debug(st, "up1tr6 CR len not 1");
41845 }
41846 dev_kfree_skb(skb);
41847 return;
41848@@ -791,9 +785,8 @@ up1tr6(struct PStack *st, int pr, void *arg)
41849 if (skb->data[0] == PROTO_DIS_N0) {
41850 dev_kfree_skb(skb);
41851 if (st->l3.debug & L3_DEB_STATE) {
41852- sprintf(tmp, "up1tr6%s N0 mt %x unhandled",
41853+ l3_debug(st, "up1tr6%s N0 mt %x unhandled",
41854 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ", mt);
41855- l3_debug(st, tmp);
41856 }
41857 } else if (skb->data[0] == PROTO_DIS_N1) {
41858 if (!(proc = getl3proc(st, cr))) {
41859@@ -801,8 +794,7 @@ up1tr6(struct PStack *st, int pr, void *arg)
41860 if (cr < 128) {
41861 if (!(proc = new_l3_process(st, cr))) {
41862 if (st->l3.debug & L3_DEB_PROTERR) {
41863- sprintf(tmp, "up1tr6 no roc mem");
41864- l3_debug(st, tmp);
41865+ l3_debug(st, "up1tr6 no roc mem");
41866 }
41867 dev_kfree_skb(skb);
41868 return;
41869@@ -821,8 +813,7 @@ up1tr6(struct PStack *st, int pr, void *arg)
41870 } else {
41871 if (!(proc = new_l3_process(st, cr))) {
41872 if (st->l3.debug & L3_DEB_PROTERR) {
41873- sprintf(tmp, "up1tr6 no roc mem");
41874- l3_debug(st, tmp);
41875+ l3_debug(st, "up1tr6 no roc mem");
41876 }
41877 dev_kfree_skb(skb);
41878 return;
41879@@ -837,18 +828,16 @@ up1tr6(struct PStack *st, int pr, void *arg)
41880 if (i == ARRAY_SIZE(datastln1)) {
41881 dev_kfree_skb(skb);
41882 if (st->l3.debug & L3_DEB_STATE) {
41883- sprintf(tmp, "up1tr6%sstate %d mt %x unhandled",
41884+ l3_debug(st, "up1tr6%sstate %d mt %x unhandled",
41885 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41886 proc->state, mt);
41887- l3_debug(st, tmp);
41888 }
41889 return;
41890 } else {
41891 if (st->l3.debug & L3_DEB_STATE) {
41892- sprintf(tmp, "up1tr6%sstate %d mt %x",
41893+ l3_debug(st, "up1tr6%sstate %d mt %x",
41894 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41895 proc->state, mt);
41896- l3_debug(st, tmp);
41897 }
41898 datastln1[i].rout(proc, pr, skb);
41899 }
41900@@ -861,7 +850,6 @@ down1tr6(struct PStack *st, int pr, void *arg)
41901 int i, cr;
41902 struct l3_process *proc;
41903 struct Channel *chan;
41904- char tmp[80];
41905
41906 if ((DL_ESTABLISH | REQUEST) == pr) {
41907 l3_msg(st, pr, NULL);
41908@@ -888,15 +876,13 @@ down1tr6(struct PStack *st, int pr, void *arg)
41909 break;
41910 if (i == ARRAY_SIZE(downstl)) {
41911 if (st->l3.debug & L3_DEB_STATE) {
41912- sprintf(tmp, "down1tr6 state %d prim %d unhandled",
41913+ l3_debug(st, "down1tr6 state %d prim %d unhandled",
41914 proc->state, pr);
41915- l3_debug(st, tmp);
41916 }
41917 } else {
41918 if (st->l3.debug & L3_DEB_STATE) {
41919- sprintf(tmp, "down1tr6 state %d prim %d",
41920+ l3_debug(st, "down1tr6 state %d prim %d",
41921 proc->state, pr);
41922- l3_debug(st, tmp);
41923 }
41924 downstl[i].rout(proc, pr, arg);
41925 }
41926diff --git a/drivers/isdn/hisax/netjet.c b/drivers/isdn/hisax/netjet.c
41927index b646eed..233e432 100644
41928--- a/drivers/isdn/hisax/netjet.c
41929+++ b/drivers/isdn/hisax/netjet.c
41930@@ -176,7 +176,7 @@ static void printframe(struct IsdnCardState *cs, u_char *buf, int count, char *s
41931 else
41932 j = i;
41933 QuickHex(t, p, j);
41934- debugl1(cs, tmp);
41935+ debugl1(cs, "%s", tmp);
41936 p += j;
41937 i -= j;
41938 t = tmp;
41939diff --git a/drivers/isdn/hisax/q931.c b/drivers/isdn/hisax/q931.c
41940index 041bf52..af1b020 100644
41941--- a/drivers/isdn/hisax/q931.c
41942+++ b/drivers/isdn/hisax/q931.c
41943@@ -1179,7 +1179,7 @@ LogFrame(struct IsdnCardState *cs, u_char *buf, int size)
41944 dp--;
41945 *dp++ = '\n';
41946 *dp = 0;
41947- HiSax_putstatus(cs, NULL, cs->dlog);
41948+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41949 } else
41950 HiSax_putstatus(cs, "LogFrame: ", "warning Frame too big (%d)", size);
41951 }
41952@@ -1246,7 +1246,7 @@ dlogframe(struct IsdnCardState *cs, struct sk_buff *skb, int dir)
41953 }
41954 if (finish) {
41955 *dp = 0;
41956- HiSax_putstatus(cs, NULL, cs->dlog);
41957+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41958 return;
41959 }
41960 if ((0xfe & buf[0]) == PROTO_DIS_N0) { /* 1TR6 */
41961@@ -1509,5 +1509,5 @@ dlogframe(struct IsdnCardState *cs, struct sk_buff *skb, int dir)
41962 dp += sprintf(dp, "Unknown protocol %x!", buf[0]);
41963 }
41964 *dp = 0;
41965- HiSax_putstatus(cs, NULL, cs->dlog);
41966+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41967 }
41968diff --git a/drivers/isdn/hisax/w6692.c b/drivers/isdn/hisax/w6692.c
41969index d8cac69..a858955 100644
41970--- a/drivers/isdn/hisax/w6692.c
41971+++ b/drivers/isdn/hisax/w6692.c
41972@@ -154,7 +154,7 @@ W6692_empty_fifo(struct IsdnCardState *cs, int count)
41973
41974 t += sprintf(t, "W6692_empty_fifo cnt %d", count);
41975 QuickHex(t, ptr, count);
41976- debugl1(cs, cs->dlog);
41977+ debugl1(cs, "%s", cs->dlog);
41978 }
41979 }
41980
41981@@ -196,7 +196,7 @@ W6692_fill_fifo(struct IsdnCardState *cs)
41982
41983 t += sprintf(t, "W6692_fill_fifo cnt %d", count);
41984 QuickHex(t, ptr, count);
41985- debugl1(cs, cs->dlog);
41986+ debugl1(cs, "%s", cs->dlog);
41987 }
41988 }
41989
41990@@ -226,7 +226,7 @@ W6692B_empty_fifo(struct BCState *bcs, int count)
41991 t += sprintf(t, "W6692B_empty_fifo %c cnt %d",
41992 bcs->channel + '1', count);
41993 QuickHex(t, ptr, count);
41994- debugl1(cs, bcs->blog);
41995+ debugl1(cs, "%s", bcs->blog);
41996 }
41997 }
41998
41999@@ -264,7 +264,7 @@ W6692B_fill_fifo(struct BCState *bcs)
42000 t += sprintf(t, "W6692B_fill_fifo %c cnt %d",
42001 bcs->channel + '1', count);
42002 QuickHex(t, ptr, count);
42003- debugl1(cs, bcs->blog);
42004+ debugl1(cs, "%s", bcs->blog);
42005 }
42006 }
42007
42008diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
42009index 9bb12ba..d4262f7 100644
42010--- a/drivers/isdn/i4l/isdn_common.c
42011+++ b/drivers/isdn/i4l/isdn_common.c
42012@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
42013 } else
42014 return -EINVAL;
42015 case IIOCDBGVAR:
42016+ if (!capable(CAP_SYS_RAWIO))
42017+ return -EPERM;
42018 if (arg) {
42019 if (copy_to_user(argp, &dev, sizeof(ulong)))
42020 return -EFAULT;
42021diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
42022index 3c5f249..5fac4d0 100644
42023--- a/drivers/isdn/i4l/isdn_tty.c
42024+++ b/drivers/isdn/i4l/isdn_tty.c
42025@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
42026
42027 #ifdef ISDN_DEBUG_MODEM_OPEN
42028 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
42029- port->count);
42030+ atomic_read(&port->count));
42031 #endif
42032- port->count++;
42033+ atomic_inc(&port->count);
42034 port->tty = tty;
42035 /*
42036 * Start up serial port
42037@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42038 #endif
42039 return;
42040 }
42041- if ((tty->count == 1) && (port->count != 1)) {
42042+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
42043 /*
42044 * Uh, oh. tty->count is 1, which means that the tty
42045 * structure will be freed. Info->count should always
42046@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42047 * serial port won't be shutdown.
42048 */
42049 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
42050- "info->count is %d\n", port->count);
42051- port->count = 1;
42052+ "info->count is %d\n", atomic_read(&port->count));
42053+ atomic_set(&port->count, 1);
42054 }
42055- if (--port->count < 0) {
42056+ if (atomic_dec_return(&port->count) < 0) {
42057 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
42058- info->line, port->count);
42059- port->count = 0;
42060+ info->line, atomic_read(&port->count));
42061+ atomic_set(&port->count, 0);
42062 }
42063- if (port->count) {
42064+ if (atomic_read(&port->count)) {
42065 #ifdef ISDN_DEBUG_MODEM_OPEN
42066 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
42067 #endif
42068@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
42069 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
42070 return;
42071 isdn_tty_shutdown(info);
42072- port->count = 0;
42073+ atomic_set(&port->count, 0);
42074 port->flags &= ~ASYNC_NORMAL_ACTIVE;
42075 port->tty = NULL;
42076 wake_up_interruptible(&port->open_wait);
42077@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
42078 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
42079 modem_info *info = &dev->mdm.info[i];
42080
42081- if (info->port.count == 0)
42082+ if (atomic_read(&info->port.count) == 0)
42083 continue;
42084 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
42085 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
42086diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
42087index e74df7c..03a03ba 100644
42088--- a/drivers/isdn/icn/icn.c
42089+++ b/drivers/isdn/icn/icn.c
42090@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
42091 if (count > len)
42092 count = len;
42093 if (user) {
42094- if (copy_from_user(msg, buf, count))
42095+ if (count > sizeof msg || copy_from_user(msg, buf, count))
42096 return -EFAULT;
42097 } else
42098 memcpy(msg, buf, count);
42099diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
42100index 6a8405d..0bd1c7e 100644
42101--- a/drivers/leds/leds-clevo-mail.c
42102+++ b/drivers/leds/leds-clevo-mail.c
42103@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
42104 * detected as working, but in reality it is not) as low as
42105 * possible.
42106 */
42107-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
42108+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
42109 {
42110 .callback = clevo_mail_led_dmi_callback,
42111 .ident = "Clevo D410J",
42112diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
42113index 64e204e..c6bf189 100644
42114--- a/drivers/leds/leds-ss4200.c
42115+++ b/drivers/leds/leds-ss4200.c
42116@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
42117 * detected as working, but in reality it is not) as low as
42118 * possible.
42119 */
42120-static struct dmi_system_id __initdata nas_led_whitelist[] = {
42121+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
42122 {
42123 .callback = ss4200_led_dmi_callback,
42124 .ident = "Intel SS4200-E",
42125diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
42126index 0bf1e4e..b4bf44e 100644
42127--- a/drivers/lguest/core.c
42128+++ b/drivers/lguest/core.c
42129@@ -97,9 +97,17 @@ static __init int map_switcher(void)
42130 * The end address needs +1 because __get_vm_area allocates an
42131 * extra guard page, so we need space for that.
42132 */
42133+
42134+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
42135+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42136+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
42137+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42138+#else
42139 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42140 VM_ALLOC, switcher_addr, switcher_addr
42141 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42142+#endif
42143+
42144 if (!switcher_vma) {
42145 err = -ENOMEM;
42146 printk("lguest: could not map switcher pages high\n");
42147@@ -124,7 +132,7 @@ static __init int map_switcher(void)
42148 * Now the Switcher is mapped at the right address, we can't fail!
42149 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
42150 */
42151- memcpy(switcher_vma->addr, start_switcher_text,
42152+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
42153 end_switcher_text - start_switcher_text);
42154
42155 printk(KERN_INFO "lguest: mapped switcher at %p\n",
42156diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
42157index a35d8d1..59fb772 100644
42158--- a/drivers/lguest/page_tables.c
42159+++ b/drivers/lguest/page_tables.c
42160@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
42161 /*:*/
42162
42163 #ifdef CONFIG_X86_PAE
42164-static void release_pmd(pmd_t *spmd)
42165+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
42166 {
42167 /* If the entry's not present, there's nothing to release. */
42168 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
42169diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
42170index 5169239..47cb4db 100644
42171--- a/drivers/lguest/x86/core.c
42172+++ b/drivers/lguest/x86/core.c
42173@@ -59,7 +59,7 @@ static struct {
42174 /* Offset from where switcher.S was compiled to where we've copied it */
42175 static unsigned long switcher_offset(void)
42176 {
42177- return switcher_addr - (unsigned long)start_switcher_text;
42178+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
42179 }
42180
42181 /* This cpu's struct lguest_pages (after the Switcher text page) */
42182@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
42183 * These copies are pretty cheap, so we do them unconditionally: */
42184 /* Save the current Host top-level page directory.
42185 */
42186+
42187+#ifdef CONFIG_PAX_PER_CPU_PGD
42188+ pages->state.host_cr3 = read_cr3();
42189+#else
42190 pages->state.host_cr3 = __pa(current->mm->pgd);
42191+#endif
42192+
42193 /*
42194 * Set up the Guest's page tables to see this CPU's pages (and no
42195 * other CPU's pages).
42196@@ -475,7 +481,7 @@ void __init lguest_arch_host_init(void)
42197 * compiled-in switcher code and the high-mapped copy we just made.
42198 */
42199 for (i = 0; i < IDT_ENTRIES; i++)
42200- default_idt_entries[i] += switcher_offset();
42201+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
42202
42203 /*
42204 * Set up the Switcher's per-cpu areas.
42205@@ -558,7 +564,7 @@ void __init lguest_arch_host_init(void)
42206 * it will be undisturbed when we switch. To change %cs and jump we
42207 * need this structure to feed to Intel's "lcall" instruction.
42208 */
42209- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
42210+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
42211 lguest_entry.segment = LGUEST_CS;
42212
42213 /*
42214diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
42215index 40634b0..4f5855e 100644
42216--- a/drivers/lguest/x86/switcher_32.S
42217+++ b/drivers/lguest/x86/switcher_32.S
42218@@ -87,6 +87,7 @@
42219 #include <asm/page.h>
42220 #include <asm/segment.h>
42221 #include <asm/lguest.h>
42222+#include <asm/processor-flags.h>
42223
42224 // We mark the start of the code to copy
42225 // It's placed in .text tho it's never run here
42226@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
42227 // Changes type when we load it: damn Intel!
42228 // For after we switch over our page tables
42229 // That entry will be read-only: we'd crash.
42230+
42231+#ifdef CONFIG_PAX_KERNEXEC
42232+ mov %cr0, %edx
42233+ xor $X86_CR0_WP, %edx
42234+ mov %edx, %cr0
42235+#endif
42236+
42237 movl $(GDT_ENTRY_TSS*8), %edx
42238 ltr %dx
42239
42240@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
42241 // Let's clear it again for our return.
42242 // The GDT descriptor of the Host
42243 // Points to the table after two "size" bytes
42244- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
42245+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
42246 // Clear "used" from type field (byte 5, bit 2)
42247- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
42248+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
42249+
42250+#ifdef CONFIG_PAX_KERNEXEC
42251+ mov %cr0, %eax
42252+ xor $X86_CR0_WP, %eax
42253+ mov %eax, %cr0
42254+#endif
42255
42256 // Once our page table's switched, the Guest is live!
42257 // The Host fades as we run this final step.
42258@@ -295,13 +309,12 @@ deliver_to_host:
42259 // I consulted gcc, and it gave
42260 // These instructions, which I gladly credit:
42261 leal (%edx,%ebx,8), %eax
42262- movzwl (%eax),%edx
42263- movl 4(%eax), %eax
42264- xorw %ax, %ax
42265- orl %eax, %edx
42266+ movl 4(%eax), %edx
42267+ movw (%eax), %dx
42268 // Now the address of the handler's in %edx
42269 // We call it now: its "iret" drops us home.
42270- jmp *%edx
42271+ ljmp $__KERNEL_CS, $1f
42272+1: jmp *%edx
42273
42274 // Every interrupt can come to us here
42275 // But we must truly tell each apart.
42276diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
42277index 0003992..854bbce 100644
42278--- a/drivers/md/bcache/closure.h
42279+++ b/drivers/md/bcache/closure.h
42280@@ -622,7 +622,7 @@ static inline void closure_wake_up(struct closure_waitlist *list)
42281 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
42282 struct workqueue_struct *wq)
42283 {
42284- BUG_ON(object_is_on_stack(cl));
42285+ BUG_ON(object_starts_on_stack(cl));
42286 closure_set_ip(cl);
42287 cl->fn = fn;
42288 cl->wq = wq;
42289diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
42290index 547c4c5..5be1de4 100644
42291--- a/drivers/md/bcache/super.c
42292+++ b/drivers/md/bcache/super.c
42293@@ -1644,7 +1644,7 @@ err_unlock_gc:
42294 err:
42295 closure_sync(&op.cl);
42296 /* XXX: test this, it's broken */
42297- bch_cache_set_error(c, err);
42298+ bch_cache_set_error(c, "%s", err);
42299 }
42300
42301 static bool can_attach_cache(struct cache *ca, struct cache_set *c)
42302diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
42303index a7fd821..9dcf6c3 100644
42304--- a/drivers/md/bitmap.c
42305+++ b/drivers/md/bitmap.c
42306@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
42307 chunk_kb ? "KB" : "B");
42308 if (bitmap->storage.file) {
42309 seq_printf(seq, ", file: ");
42310- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
42311+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
42312 }
42313
42314 seq_printf(seq, "\n");
42315diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
42316index f1b7586..a49c4bd 100644
42317--- a/drivers/md/dm-ioctl.c
42318+++ b/drivers/md/dm-ioctl.c
42319@@ -1739,7 +1739,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
42320 cmd == DM_LIST_VERSIONS_CMD)
42321 return 0;
42322
42323- if ((cmd == DM_DEV_CREATE_CMD)) {
42324+ if (cmd == DM_DEV_CREATE_CMD) {
42325 if (!*param->name) {
42326 DMWARN("name not supplied when creating device");
42327 return -EINVAL;
42328diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
42329index 699b5be..eac0a15 100644
42330--- a/drivers/md/dm-raid1.c
42331+++ b/drivers/md/dm-raid1.c
42332@@ -40,7 +40,7 @@ enum dm_raid1_error {
42333
42334 struct mirror {
42335 struct mirror_set *ms;
42336- atomic_t error_count;
42337+ atomic_unchecked_t error_count;
42338 unsigned long error_type;
42339 struct dm_dev *dev;
42340 sector_t offset;
42341@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
42342 struct mirror *m;
42343
42344 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
42345- if (!atomic_read(&m->error_count))
42346+ if (!atomic_read_unchecked(&m->error_count))
42347 return m;
42348
42349 return NULL;
42350@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
42351 * simple way to tell if a device has encountered
42352 * errors.
42353 */
42354- atomic_inc(&m->error_count);
42355+ atomic_inc_unchecked(&m->error_count);
42356
42357 if (test_and_set_bit(error_type, &m->error_type))
42358 return;
42359@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
42360 struct mirror *m = get_default_mirror(ms);
42361
42362 do {
42363- if (likely(!atomic_read(&m->error_count)))
42364+ if (likely(!atomic_read_unchecked(&m->error_count)))
42365 return m;
42366
42367 if (m-- == ms->mirror)
42368@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
42369 {
42370 struct mirror *default_mirror = get_default_mirror(m->ms);
42371
42372- return !atomic_read(&default_mirror->error_count);
42373+ return !atomic_read_unchecked(&default_mirror->error_count);
42374 }
42375
42376 static int mirror_available(struct mirror_set *ms, struct bio *bio)
42377@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
42378 */
42379 if (likely(region_in_sync(ms, region, 1)))
42380 m = choose_mirror(ms, bio->bi_sector);
42381- else if (m && atomic_read(&m->error_count))
42382+ else if (m && atomic_read_unchecked(&m->error_count))
42383 m = NULL;
42384
42385 if (likely(m))
42386@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
42387 }
42388
42389 ms->mirror[mirror].ms = ms;
42390- atomic_set(&(ms->mirror[mirror].error_count), 0);
42391+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
42392 ms->mirror[mirror].error_type = 0;
42393 ms->mirror[mirror].offset = offset;
42394
42395@@ -1340,7 +1340,7 @@ static void mirror_resume(struct dm_target *ti)
42396 */
42397 static char device_status_char(struct mirror *m)
42398 {
42399- if (!atomic_read(&(m->error_count)))
42400+ if (!atomic_read_unchecked(&(m->error_count)))
42401 return 'A';
42402
42403 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
42404diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
42405index d907ca6..cfb8384 100644
42406--- a/drivers/md/dm-stripe.c
42407+++ b/drivers/md/dm-stripe.c
42408@@ -20,7 +20,7 @@ struct stripe {
42409 struct dm_dev *dev;
42410 sector_t physical_start;
42411
42412- atomic_t error_count;
42413+ atomic_unchecked_t error_count;
42414 };
42415
42416 struct stripe_c {
42417@@ -185,7 +185,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
42418 kfree(sc);
42419 return r;
42420 }
42421- atomic_set(&(sc->stripe[i].error_count), 0);
42422+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
42423 }
42424
42425 ti->private = sc;
42426@@ -326,7 +326,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
42427 DMEMIT("%d ", sc->stripes);
42428 for (i = 0; i < sc->stripes; i++) {
42429 DMEMIT("%s ", sc->stripe[i].dev->name);
42430- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
42431+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
42432 'D' : 'A';
42433 }
42434 buffer[i] = '\0';
42435@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
42436 */
42437 for (i = 0; i < sc->stripes; i++)
42438 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
42439- atomic_inc(&(sc->stripe[i].error_count));
42440- if (atomic_read(&(sc->stripe[i].error_count)) <
42441+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
42442+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
42443 DM_IO_ERROR_THRESHOLD)
42444 schedule_work(&sc->trigger_event);
42445 }
42446diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
42447index f221812..aca962b 100644
42448--- a/drivers/md/dm-table.c
42449+++ b/drivers/md/dm-table.c
42450@@ -354,7 +354,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
42451 if (!dev_size)
42452 return 0;
42453
42454- if ((start >= dev_size) || (start + len > dev_size)) {
42455+ if ((start >= dev_size) || (len > dev_size - start)) {
42456 DMWARN("%s: %s too small for target: "
42457 "start=%llu, len=%llu, dev_size=%llu",
42458 dm_device_name(ti->table->md), bdevname(bdev, b),
42459diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
42460index 60bce43..9b997d0 100644
42461--- a/drivers/md/dm-thin-metadata.c
42462+++ b/drivers/md/dm-thin-metadata.c
42463@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42464 {
42465 pmd->info.tm = pmd->tm;
42466 pmd->info.levels = 2;
42467- pmd->info.value_type.context = pmd->data_sm;
42468+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42469 pmd->info.value_type.size = sizeof(__le64);
42470 pmd->info.value_type.inc = data_block_inc;
42471 pmd->info.value_type.dec = data_block_dec;
42472@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42473
42474 pmd->bl_info.tm = pmd->tm;
42475 pmd->bl_info.levels = 1;
42476- pmd->bl_info.value_type.context = pmd->data_sm;
42477+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42478 pmd->bl_info.value_type.size = sizeof(__le64);
42479 pmd->bl_info.value_type.inc = data_block_inc;
42480 pmd->bl_info.value_type.dec = data_block_dec;
42481diff --git a/drivers/md/dm.c b/drivers/md/dm.c
42482index 9e39d2b..fb879a7 100644
42483--- a/drivers/md/dm.c
42484+++ b/drivers/md/dm.c
42485@@ -178,9 +178,9 @@ struct mapped_device {
42486 /*
42487 * Event handling.
42488 */
42489- atomic_t event_nr;
42490+ atomic_unchecked_t event_nr;
42491 wait_queue_head_t eventq;
42492- atomic_t uevent_seq;
42493+ atomic_unchecked_t uevent_seq;
42494 struct list_head uevent_list;
42495 spinlock_t uevent_lock; /* Protect access to uevent_list */
42496
42497@@ -1916,8 +1916,8 @@ static struct mapped_device *alloc_dev(int minor)
42498 spin_lock_init(&md->deferred_lock);
42499 atomic_set(&md->holders, 1);
42500 atomic_set(&md->open_count, 0);
42501- atomic_set(&md->event_nr, 0);
42502- atomic_set(&md->uevent_seq, 0);
42503+ atomic_set_unchecked(&md->event_nr, 0);
42504+ atomic_set_unchecked(&md->uevent_seq, 0);
42505 INIT_LIST_HEAD(&md->uevent_list);
42506 spin_lock_init(&md->uevent_lock);
42507
42508@@ -2068,7 +2068,7 @@ static void event_callback(void *context)
42509
42510 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
42511
42512- atomic_inc(&md->event_nr);
42513+ atomic_inc_unchecked(&md->event_nr);
42514 wake_up(&md->eventq);
42515 }
42516
42517@@ -2716,18 +2716,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
42518
42519 uint32_t dm_next_uevent_seq(struct mapped_device *md)
42520 {
42521- return atomic_add_return(1, &md->uevent_seq);
42522+ return atomic_add_return_unchecked(1, &md->uevent_seq);
42523 }
42524
42525 uint32_t dm_get_event_nr(struct mapped_device *md)
42526 {
42527- return atomic_read(&md->event_nr);
42528+ return atomic_read_unchecked(&md->event_nr);
42529 }
42530
42531 int dm_wait_event(struct mapped_device *md, int event_nr)
42532 {
42533 return wait_event_interruptible(md->eventq,
42534- (event_nr != atomic_read(&md->event_nr)));
42535+ (event_nr != atomic_read_unchecked(&md->event_nr)));
42536 }
42537
42538 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
42539diff --git a/drivers/md/md.c b/drivers/md/md.c
42540index 9f13e13..411a5b8 100644
42541--- a/drivers/md/md.c
42542+++ b/drivers/md/md.c
42543@@ -234,10 +234,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
42544 * start build, activate spare
42545 */
42546 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
42547-static atomic_t md_event_count;
42548+static atomic_unchecked_t md_event_count;
42549 void md_new_event(struct mddev *mddev)
42550 {
42551- atomic_inc(&md_event_count);
42552+ atomic_inc_unchecked(&md_event_count);
42553 wake_up(&md_event_waiters);
42554 }
42555 EXPORT_SYMBOL_GPL(md_new_event);
42556@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
42557 */
42558 static void md_new_event_inintr(struct mddev *mddev)
42559 {
42560- atomic_inc(&md_event_count);
42561+ atomic_inc_unchecked(&md_event_count);
42562 wake_up(&md_event_waiters);
42563 }
42564
42565@@ -1502,7 +1502,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
42566 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
42567 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
42568 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
42569- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42570+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42571
42572 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
42573 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
42574@@ -1746,7 +1746,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
42575 else
42576 sb->resync_offset = cpu_to_le64(0);
42577
42578- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
42579+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
42580
42581 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
42582 sb->size = cpu_to_le64(mddev->dev_sectors);
42583@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
42584 static ssize_t
42585 errors_show(struct md_rdev *rdev, char *page)
42586 {
42587- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
42588+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
42589 }
42590
42591 static ssize_t
42592@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
42593 char *e;
42594 unsigned long n = simple_strtoul(buf, &e, 10);
42595 if (*buf && (*e == 0 || *e == '\n')) {
42596- atomic_set(&rdev->corrected_errors, n);
42597+ atomic_set_unchecked(&rdev->corrected_errors, n);
42598 return len;
42599 }
42600 return -EINVAL;
42601@@ -3208,8 +3208,8 @@ int md_rdev_init(struct md_rdev *rdev)
42602 rdev->sb_loaded = 0;
42603 rdev->bb_page = NULL;
42604 atomic_set(&rdev->nr_pending, 0);
42605- atomic_set(&rdev->read_errors, 0);
42606- atomic_set(&rdev->corrected_errors, 0);
42607+ atomic_set_unchecked(&rdev->read_errors, 0);
42608+ atomic_set_unchecked(&rdev->corrected_errors, 0);
42609
42610 INIT_LIST_HEAD(&rdev->same_set);
42611 init_waitqueue_head(&rdev->blocked_wait);
42612@@ -7024,7 +7024,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
42613
42614 spin_unlock(&pers_lock);
42615 seq_printf(seq, "\n");
42616- seq->poll_event = atomic_read(&md_event_count);
42617+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42618 return 0;
42619 }
42620 if (v == (void*)2) {
42621@@ -7127,7 +7127,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
42622 return error;
42623
42624 seq = file->private_data;
42625- seq->poll_event = atomic_read(&md_event_count);
42626+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42627 return error;
42628 }
42629
42630@@ -7141,7 +7141,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
42631 /* always allow read */
42632 mask = POLLIN | POLLRDNORM;
42633
42634- if (seq->poll_event != atomic_read(&md_event_count))
42635+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
42636 mask |= POLLERR | POLLPRI;
42637 return mask;
42638 }
42639@@ -7185,7 +7185,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
42640 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
42641 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
42642 (int)part_stat_read(&disk->part0, sectors[1]) -
42643- atomic_read(&disk->sync_io);
42644+ atomic_read_unchecked(&disk->sync_io);
42645 /* sync IO will cause sync_io to increase before the disk_stats
42646 * as sync_io is counted when a request starts, and
42647 * disk_stats is counted when it completes.
42648diff --git a/drivers/md/md.h b/drivers/md/md.h
42649index 20f02c0..fd8c821 100644
42650--- a/drivers/md/md.h
42651+++ b/drivers/md/md.h
42652@@ -94,13 +94,13 @@ struct md_rdev {
42653 * only maintained for arrays that
42654 * support hot removal
42655 */
42656- atomic_t read_errors; /* number of consecutive read errors that
42657+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
42658 * we have tried to ignore.
42659 */
42660 struct timespec last_read_error; /* monotonic time since our
42661 * last read error
42662 */
42663- atomic_t corrected_errors; /* number of corrected read errors,
42664+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
42665 * for reporting to userspace and storing
42666 * in superblock.
42667 */
42668@@ -442,7 +442,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
42669
42670 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
42671 {
42672- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42673+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42674 }
42675
42676 struct md_personality
42677diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
42678index 3e6d115..ffecdeb 100644
42679--- a/drivers/md/persistent-data/dm-space-map.h
42680+++ b/drivers/md/persistent-data/dm-space-map.h
42681@@ -71,6 +71,7 @@ struct dm_space_map {
42682 dm_sm_threshold_fn fn,
42683 void *context);
42684 };
42685+typedef struct dm_space_map __no_const dm_space_map_no_const;
42686
42687 /*----------------------------------------------------------------*/
42688
42689diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
42690index d60412c..8d4c982 100644
42691--- a/drivers/md/raid1.c
42692+++ b/drivers/md/raid1.c
42693@@ -1823,7 +1823,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
42694 if (r1_sync_page_io(rdev, sect, s,
42695 bio->bi_io_vec[idx].bv_page,
42696 READ) != 0)
42697- atomic_add(s, &rdev->corrected_errors);
42698+ atomic_add_unchecked(s, &rdev->corrected_errors);
42699 }
42700 sectors -= s;
42701 sect += s;
42702@@ -2050,7 +2050,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
42703 test_bit(In_sync, &rdev->flags)) {
42704 if (r1_sync_page_io(rdev, sect, s,
42705 conf->tmppage, READ)) {
42706- atomic_add(s, &rdev->corrected_errors);
42707+ atomic_add_unchecked(s, &rdev->corrected_errors);
42708 printk(KERN_INFO
42709 "md/raid1:%s: read error corrected "
42710 "(%d sectors at %llu on %s)\n",
42711diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
42712index df7b0a0..a257495 100644
42713--- a/drivers/md/raid10.c
42714+++ b/drivers/md/raid10.c
42715@@ -1962,7 +1962,7 @@ static void end_sync_read(struct bio *bio, int error)
42716 /* The write handler will notice the lack of
42717 * R10BIO_Uptodate and record any errors etc
42718 */
42719- atomic_add(r10_bio->sectors,
42720+ atomic_add_unchecked(r10_bio->sectors,
42721 &conf->mirrors[d].rdev->corrected_errors);
42722
42723 /* for reconstruct, we always reschedule after a read.
42724@@ -2320,7 +2320,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42725 {
42726 struct timespec cur_time_mon;
42727 unsigned long hours_since_last;
42728- unsigned int read_errors = atomic_read(&rdev->read_errors);
42729+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
42730
42731 ktime_get_ts(&cur_time_mon);
42732
42733@@ -2342,9 +2342,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42734 * overflowing the shift of read_errors by hours_since_last.
42735 */
42736 if (hours_since_last >= 8 * sizeof(read_errors))
42737- atomic_set(&rdev->read_errors, 0);
42738+ atomic_set_unchecked(&rdev->read_errors, 0);
42739 else
42740- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
42741+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
42742 }
42743
42744 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
42745@@ -2398,8 +2398,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42746 return;
42747
42748 check_decay_read_errors(mddev, rdev);
42749- atomic_inc(&rdev->read_errors);
42750- if (atomic_read(&rdev->read_errors) > max_read_errors) {
42751+ atomic_inc_unchecked(&rdev->read_errors);
42752+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
42753 char b[BDEVNAME_SIZE];
42754 bdevname(rdev->bdev, b);
42755
42756@@ -2407,7 +2407,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42757 "md/raid10:%s: %s: Raid device exceeded "
42758 "read_error threshold [cur %d:max %d]\n",
42759 mdname(mddev), b,
42760- atomic_read(&rdev->read_errors), max_read_errors);
42761+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
42762 printk(KERN_NOTICE
42763 "md/raid10:%s: %s: Failing raid device\n",
42764 mdname(mddev), b);
42765@@ -2562,7 +2562,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42766 sect +
42767 choose_data_offset(r10_bio, rdev)),
42768 bdevname(rdev->bdev, b));
42769- atomic_add(s, &rdev->corrected_errors);
42770+ atomic_add_unchecked(s, &rdev->corrected_errors);
42771 }
42772
42773 rdev_dec_pending(rdev, mddev);
42774diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
42775index 78ea443..7d57513 100644
42776--- a/drivers/md/raid5.c
42777+++ b/drivers/md/raid5.c
42778@@ -1764,21 +1764,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
42779 mdname(conf->mddev), STRIPE_SECTORS,
42780 (unsigned long long)s,
42781 bdevname(rdev->bdev, b));
42782- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
42783+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
42784 clear_bit(R5_ReadError, &sh->dev[i].flags);
42785 clear_bit(R5_ReWrite, &sh->dev[i].flags);
42786 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
42787 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
42788
42789- if (atomic_read(&rdev->read_errors))
42790- atomic_set(&rdev->read_errors, 0);
42791+ if (atomic_read_unchecked(&rdev->read_errors))
42792+ atomic_set_unchecked(&rdev->read_errors, 0);
42793 } else {
42794 const char *bdn = bdevname(rdev->bdev, b);
42795 int retry = 0;
42796 int set_bad = 0;
42797
42798 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
42799- atomic_inc(&rdev->read_errors);
42800+ atomic_inc_unchecked(&rdev->read_errors);
42801 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
42802 printk_ratelimited(
42803 KERN_WARNING
42804@@ -1806,7 +1806,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
42805 mdname(conf->mddev),
42806 (unsigned long long)s,
42807 bdn);
42808- } else if (atomic_read(&rdev->read_errors)
42809+ } else if (atomic_read_unchecked(&rdev->read_errors)
42810 > conf->max_nr_stripes)
42811 printk(KERN_WARNING
42812 "md/raid:%s: Too many read errors, failing device %s.\n",
42813diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
42814index 401ef64..836e563 100644
42815--- a/drivers/media/dvb-core/dvbdev.c
42816+++ b/drivers/media/dvb-core/dvbdev.c
42817@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
42818 const struct dvb_device *template, void *priv, int type)
42819 {
42820 struct dvb_device *dvbdev;
42821- struct file_operations *dvbdevfops;
42822+ file_operations_no_const *dvbdevfops;
42823 struct device *clsdev;
42824 int minor;
42825 int id;
42826diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
42827index 9b6c3bb..baeb5c7 100644
42828--- a/drivers/media/dvb-frontends/dib3000.h
42829+++ b/drivers/media/dvb-frontends/dib3000.h
42830@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
42831 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
42832 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
42833 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
42834-};
42835+} __no_const;
42836
42837 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
42838 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
42839diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
42840index ecf21d9..b992428d 100644
42841--- a/drivers/media/pci/cx88/cx88-video.c
42842+++ b/drivers/media/pci/cx88/cx88-video.c
42843@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
42844
42845 /* ------------------------------------------------------------------ */
42846
42847-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42848-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42849-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42850+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42851+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42852+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42853
42854 module_param_array(video_nr, int, NULL, 0444);
42855 module_param_array(vbi_nr, int, NULL, 0444);
42856diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
42857index c08ae3e..eb59af1 100644
42858--- a/drivers/media/pci/ivtv/ivtv-driver.c
42859+++ b/drivers/media/pci/ivtv/ivtv-driver.c
42860@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
42861 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
42862
42863 /* ivtv instance counter */
42864-static atomic_t ivtv_instance = ATOMIC_INIT(0);
42865+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
42866
42867 /* Parameter declarations */
42868 static int cardtype[IVTV_MAX_CARDS];
42869diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
42870index dfd0a21..6bbb465 100644
42871--- a/drivers/media/platform/omap/omap_vout.c
42872+++ b/drivers/media/platform/omap/omap_vout.c
42873@@ -63,7 +63,6 @@ enum omap_vout_channels {
42874 OMAP_VIDEO2,
42875 };
42876
42877-static struct videobuf_queue_ops video_vbq_ops;
42878 /* Variables configurable through module params*/
42879 static u32 video1_numbuffers = 3;
42880 static u32 video2_numbuffers = 3;
42881@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
42882 {
42883 struct videobuf_queue *q;
42884 struct omap_vout_device *vout = NULL;
42885+ static struct videobuf_queue_ops video_vbq_ops = {
42886+ .buf_setup = omap_vout_buffer_setup,
42887+ .buf_prepare = omap_vout_buffer_prepare,
42888+ .buf_release = omap_vout_buffer_release,
42889+ .buf_queue = omap_vout_buffer_queue,
42890+ };
42891
42892 vout = video_drvdata(file);
42893 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
42894@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
42895 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
42896
42897 q = &vout->vbq;
42898- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
42899- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
42900- video_vbq_ops.buf_release = omap_vout_buffer_release;
42901- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
42902 spin_lock_init(&vout->vbq_lock);
42903
42904 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
42905diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
42906index 04e6490..2df65bf 100644
42907--- a/drivers/media/platform/s5p-tv/mixer.h
42908+++ b/drivers/media/platform/s5p-tv/mixer.h
42909@@ -156,7 +156,7 @@ struct mxr_layer {
42910 /** layer index (unique identifier) */
42911 int idx;
42912 /** callbacks for layer methods */
42913- struct mxr_layer_ops ops;
42914+ struct mxr_layer_ops *ops;
42915 /** format array */
42916 const struct mxr_format **fmt_array;
42917 /** size of format array */
42918diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42919index b93a21f..2535195 100644
42920--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42921+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42922@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
42923 {
42924 struct mxr_layer *layer;
42925 int ret;
42926- struct mxr_layer_ops ops = {
42927+ static struct mxr_layer_ops ops = {
42928 .release = mxr_graph_layer_release,
42929 .buffer_set = mxr_graph_buffer_set,
42930 .stream_set = mxr_graph_stream_set,
42931diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
42932index b713403..53cb5ad 100644
42933--- a/drivers/media/platform/s5p-tv/mixer_reg.c
42934+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
42935@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
42936 layer->update_buf = next;
42937 }
42938
42939- layer->ops.buffer_set(layer, layer->update_buf);
42940+ layer->ops->buffer_set(layer, layer->update_buf);
42941
42942 if (done && done != layer->shadow_buf)
42943 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
42944diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
42945index 641b1f0..49cff30 100644
42946--- a/drivers/media/platform/s5p-tv/mixer_video.c
42947+++ b/drivers/media/platform/s5p-tv/mixer_video.c
42948@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
42949 layer->geo.src.height = layer->geo.src.full_height;
42950
42951 mxr_geometry_dump(mdev, &layer->geo);
42952- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42953+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42954 mxr_geometry_dump(mdev, &layer->geo);
42955 }
42956
42957@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
42958 layer->geo.dst.full_width = mbus_fmt.width;
42959 layer->geo.dst.full_height = mbus_fmt.height;
42960 layer->geo.dst.field = mbus_fmt.field;
42961- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42962+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42963
42964 mxr_geometry_dump(mdev, &layer->geo);
42965 }
42966@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
42967 /* set source size to highest accepted value */
42968 geo->src.full_width = max(geo->dst.full_width, pix->width);
42969 geo->src.full_height = max(geo->dst.full_height, pix->height);
42970- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42971+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42972 mxr_geometry_dump(mdev, &layer->geo);
42973 /* set cropping to total visible screen */
42974 geo->src.width = pix->width;
42975@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
42976 geo->src.x_offset = 0;
42977 geo->src.y_offset = 0;
42978 /* assure consistency of geometry */
42979- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
42980+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
42981 mxr_geometry_dump(mdev, &layer->geo);
42982 /* set full size to lowest possible value */
42983 geo->src.full_width = 0;
42984 geo->src.full_height = 0;
42985- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42986+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42987 mxr_geometry_dump(mdev, &layer->geo);
42988
42989 /* returning results */
42990@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
42991 target->width = s->r.width;
42992 target->height = s->r.height;
42993
42994- layer->ops.fix_geometry(layer, stage, s->flags);
42995+ layer->ops->fix_geometry(layer, stage, s->flags);
42996
42997 /* retrieve update selection rectangle */
42998 res.left = target->x_offset;
42999@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
43000 mxr_output_get(mdev);
43001
43002 mxr_layer_update_output(layer);
43003- layer->ops.format_set(layer);
43004+ layer->ops->format_set(layer);
43005 /* enabling layer in hardware */
43006 spin_lock_irqsave(&layer->enq_slock, flags);
43007 layer->state = MXR_LAYER_STREAMING;
43008 spin_unlock_irqrestore(&layer->enq_slock, flags);
43009
43010- layer->ops.stream_set(layer, MXR_ENABLE);
43011+ layer->ops->stream_set(layer, MXR_ENABLE);
43012 mxr_streamer_get(mdev);
43013
43014 return 0;
43015@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
43016 spin_unlock_irqrestore(&layer->enq_slock, flags);
43017
43018 /* disabling layer in hardware */
43019- layer->ops.stream_set(layer, MXR_DISABLE);
43020+ layer->ops->stream_set(layer, MXR_DISABLE);
43021 /* remove one streamer */
43022 mxr_streamer_put(mdev);
43023 /* allow changes in output configuration */
43024@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
43025
43026 void mxr_layer_release(struct mxr_layer *layer)
43027 {
43028- if (layer->ops.release)
43029- layer->ops.release(layer);
43030+ if (layer->ops->release)
43031+ layer->ops->release(layer);
43032 }
43033
43034 void mxr_base_layer_release(struct mxr_layer *layer)
43035@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
43036
43037 layer->mdev = mdev;
43038 layer->idx = idx;
43039- layer->ops = *ops;
43040+ layer->ops = ops;
43041
43042 spin_lock_init(&layer->enq_slock);
43043 INIT_LIST_HEAD(&layer->enq_list);
43044diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43045index 3d13a63..da31bf1 100644
43046--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43047+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43048@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
43049 {
43050 struct mxr_layer *layer;
43051 int ret;
43052- struct mxr_layer_ops ops = {
43053+ static struct mxr_layer_ops ops = {
43054 .release = mxr_vp_layer_release,
43055 .buffer_set = mxr_vp_buffer_set,
43056 .stream_set = mxr_vp_stream_set,
43057diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
43058index 545c04c..a14bded 100644
43059--- a/drivers/media/radio/radio-cadet.c
43060+++ b/drivers/media/radio/radio-cadet.c
43061@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43062 unsigned char readbuf[RDS_BUFFER];
43063 int i = 0;
43064
43065+ if (count > RDS_BUFFER)
43066+ return -EFAULT;
43067 mutex_lock(&dev->lock);
43068 if (dev->rdsstat == 0)
43069 cadet_start_rds(dev);
43070@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43071 while (i < count && dev->rdsin != dev->rdsout)
43072 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
43073
43074- if (i && copy_to_user(data, readbuf, i))
43075+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
43076 i = -EFAULT;
43077 unlock:
43078 mutex_unlock(&dev->lock);
43079diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
43080index bd4d3a7..ffc0b9d 100644
43081--- a/drivers/media/radio/radio-maxiradio.c
43082+++ b/drivers/media/radio/radio-maxiradio.c
43083@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
43084 /* TEA5757 pin mappings */
43085 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
43086
43087-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
43088+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
43089
43090 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
43091 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
43092diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
43093index 8fa18ab..caee70f 100644
43094--- a/drivers/media/radio/radio-shark.c
43095+++ b/drivers/media/radio/radio-shark.c
43096@@ -79,7 +79,7 @@ struct shark_device {
43097 u32 last_val;
43098 };
43099
43100-static atomic_t shark_instance = ATOMIC_INIT(0);
43101+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43102
43103 static void shark_write_val(struct snd_tea575x *tea, u32 val)
43104 {
43105diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
43106index 9fb6697..f167415 100644
43107--- a/drivers/media/radio/radio-shark2.c
43108+++ b/drivers/media/radio/radio-shark2.c
43109@@ -74,7 +74,7 @@ struct shark_device {
43110 u8 *transfer_buffer;
43111 };
43112
43113-static atomic_t shark_instance = ATOMIC_INIT(0);
43114+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43115
43116 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
43117 {
43118diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
43119index 9c9084c..a9e8dfb 100644
43120--- a/drivers/media/radio/radio-si476x.c
43121+++ b/drivers/media/radio/radio-si476x.c
43122@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
43123 struct si476x_radio *radio;
43124 struct v4l2_ctrl *ctrl;
43125
43126- static atomic_t instance = ATOMIC_INIT(0);
43127+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
43128
43129 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
43130 if (!radio)
43131diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
43132index 1cf382a..c22998c 100644
43133--- a/drivers/media/rc/rc-main.c
43134+++ b/drivers/media/rc/rc-main.c
43135@@ -1030,7 +1030,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
43136 int rc_register_device(struct rc_dev *dev)
43137 {
43138 static bool raw_init = false; /* raw decoders loaded? */
43139- static atomic_t devno = ATOMIC_INIT(0);
43140+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
43141 struct rc_map *rc_map;
43142 const char *path;
43143 int rc;
43144@@ -1061,7 +1061,7 @@ int rc_register_device(struct rc_dev *dev)
43145 */
43146 mutex_lock(&dev->lock);
43147
43148- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
43149+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
43150 dev_set_name(&dev->dev, "rc%ld", dev->devno);
43151 dev_set_drvdata(&dev->dev, dev);
43152 rc = device_add(&dev->dev);
43153diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
43154index 3940bb0..fb3952a 100644
43155--- a/drivers/media/usb/dvb-usb/cxusb.c
43156+++ b/drivers/media/usb/dvb-usb/cxusb.c
43157@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
43158
43159 struct dib0700_adapter_state {
43160 int (*set_param_save) (struct dvb_frontend *);
43161-};
43162+} __no_const;
43163
43164 static int dib7070_set_param_override(struct dvb_frontend *fe)
43165 {
43166diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
43167index 6e237b6..dc25556 100644
43168--- a/drivers/media/usb/dvb-usb/dw2102.c
43169+++ b/drivers/media/usb/dvb-usb/dw2102.c
43170@@ -118,7 +118,7 @@ struct su3000_state {
43171
43172 struct s6x0_state {
43173 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
43174-};
43175+} __no_const;
43176
43177 /* debug */
43178 static int dvb_usb_dw2102_debug;
43179diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43180index 8f7a6a4..59502dd 100644
43181--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43182+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43183@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
43184 __u32 reserved;
43185 };
43186
43187-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43188+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43189 enum v4l2_memory memory)
43190 {
43191 void __user *up_pln;
43192@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43193 return 0;
43194 }
43195
43196-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43197+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43198 enum v4l2_memory memory)
43199 {
43200 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
43201@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
43202 put_user(kp->start_block, &up->start_block) ||
43203 put_user(kp->blocks, &up->blocks) ||
43204 put_user(tmp, &up->edid) ||
43205- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
43206+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
43207 return -EFAULT;
43208 return 0;
43209 }
43210diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
43211index 02d1b63..5fd6b16 100644
43212--- a/drivers/media/v4l2-core/v4l2-device.c
43213+++ b/drivers/media/v4l2-core/v4l2-device.c
43214@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
43215 EXPORT_SYMBOL_GPL(v4l2_device_put);
43216
43217 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
43218- atomic_t *instance)
43219+ atomic_unchecked_t *instance)
43220 {
43221- int num = atomic_inc_return(instance) - 1;
43222+ int num = atomic_inc_return_unchecked(instance) - 1;
43223 int len = strlen(basename);
43224
43225 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
43226diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
43227index 68e6b5e..d8b923e 100644
43228--- a/drivers/media/v4l2-core/v4l2-ioctl.c
43229+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
43230@@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
43231 struct file *file, void *fh, void *p);
43232 } u;
43233 void (*debug)(const void *arg, bool write_only);
43234-};
43235+} __do_const;
43236+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
43237
43238 /* This control needs a priority check */
43239 #define INFO_FL_PRIO (1 << 0)
43240@@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
43241 struct video_device *vfd = video_devdata(file);
43242 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
43243 bool write_only = false;
43244- struct v4l2_ioctl_info default_info;
43245+ v4l2_ioctl_info_no_const default_info;
43246 const struct v4l2_ioctl_info *info;
43247 void *fh = file->private_data;
43248 struct v4l2_fh *vfh = NULL;
43249@@ -2194,7 +2195,7 @@ done:
43250 }
43251
43252 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43253- void * __user *user_ptr, void ***kernel_ptr)
43254+ void __user **user_ptr, void ***kernel_ptr)
43255 {
43256 int ret = 0;
43257
43258@@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43259 ret = -EINVAL;
43260 break;
43261 }
43262- *user_ptr = (void __user *)buf->m.planes;
43263+ *user_ptr = (void __force_user *)buf->m.planes;
43264 *kernel_ptr = (void *)&buf->m.planes;
43265 *array_size = sizeof(struct v4l2_plane) * buf->length;
43266 ret = 1;
43267@@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43268 ret = -EINVAL;
43269 break;
43270 }
43271- *user_ptr = (void __user *)ctrls->controls;
43272+ *user_ptr = (void __force_user *)ctrls->controls;
43273 *kernel_ptr = (void *)&ctrls->controls;
43274 *array_size = sizeof(struct v4l2_ext_control)
43275 * ctrls->count;
43276diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
43277index 767ff4d..c69d259 100644
43278--- a/drivers/message/fusion/mptbase.c
43279+++ b/drivers/message/fusion/mptbase.c
43280@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43281 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
43282 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
43283
43284+#ifdef CONFIG_GRKERNSEC_HIDESYM
43285+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
43286+#else
43287 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
43288 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
43289+#endif
43290+
43291 /*
43292 * Rounding UP to nearest 4-kB boundary here...
43293 */
43294@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43295 ioc->facts.GlobalCredits);
43296
43297 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
43298+#ifdef CONFIG_GRKERNSEC_HIDESYM
43299+ NULL, NULL);
43300+#else
43301 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
43302+#endif
43303 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
43304 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
43305 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
43306diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
43307index dd239bd..689c4f7 100644
43308--- a/drivers/message/fusion/mptsas.c
43309+++ b/drivers/message/fusion/mptsas.c
43310@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
43311 return 0;
43312 }
43313
43314+static inline void
43315+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43316+{
43317+ if (phy_info->port_details) {
43318+ phy_info->port_details->rphy = rphy;
43319+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43320+ ioc->name, rphy));
43321+ }
43322+
43323+ if (rphy) {
43324+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43325+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43326+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43327+ ioc->name, rphy, rphy->dev.release));
43328+ }
43329+}
43330+
43331 /* no mutex */
43332 static void
43333 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
43334@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
43335 return NULL;
43336 }
43337
43338-static inline void
43339-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43340-{
43341- if (phy_info->port_details) {
43342- phy_info->port_details->rphy = rphy;
43343- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43344- ioc->name, rphy));
43345- }
43346-
43347- if (rphy) {
43348- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43349- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43350- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43351- ioc->name, rphy, rphy->dev.release));
43352- }
43353-}
43354-
43355 static inline struct sas_port *
43356 mptsas_get_port(struct mptsas_phyinfo *phy_info)
43357 {
43358diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
43359index 727819c..ad74694 100644
43360--- a/drivers/message/fusion/mptscsih.c
43361+++ b/drivers/message/fusion/mptscsih.c
43362@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
43363
43364 h = shost_priv(SChost);
43365
43366- if (h) {
43367- if (h->info_kbuf == NULL)
43368- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43369- return h->info_kbuf;
43370- h->info_kbuf[0] = '\0';
43371+ if (!h)
43372+ return NULL;
43373
43374- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43375- h->info_kbuf[size-1] = '\0';
43376- }
43377+ if (h->info_kbuf == NULL)
43378+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43379+ return h->info_kbuf;
43380+ h->info_kbuf[0] = '\0';
43381+
43382+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43383+ h->info_kbuf[size-1] = '\0';
43384
43385 return h->info_kbuf;
43386 }
43387diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
43388index b7d87cd..9890039 100644
43389--- a/drivers/message/i2o/i2o_proc.c
43390+++ b/drivers/message/i2o/i2o_proc.c
43391@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
43392 "Array Controller Device"
43393 };
43394
43395-static char *chtostr(char *tmp, u8 *chars, int n)
43396-{
43397- tmp[0] = 0;
43398- return strncat(tmp, (char *)chars, n);
43399-}
43400-
43401 static int i2o_report_query_status(struct seq_file *seq, int block_status,
43402 char *group)
43403 {
43404@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43405 } *result;
43406
43407 i2o_exec_execute_ddm_table ddm_table;
43408- char tmp[28 + 1];
43409
43410 result = kmalloc(sizeof(*result), GFP_KERNEL);
43411 if (!result)
43412@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43413
43414 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
43415 seq_printf(seq, "%-#8x", ddm_table.module_id);
43416- seq_printf(seq, "%-29s",
43417- chtostr(tmp, ddm_table.module_name_version, 28));
43418+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
43419 seq_printf(seq, "%9d ", ddm_table.data_size);
43420 seq_printf(seq, "%8d", ddm_table.code_size);
43421
43422@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43423
43424 i2o_driver_result_table *result;
43425 i2o_driver_store_table *dst;
43426- char tmp[28 + 1];
43427
43428 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
43429 if (result == NULL)
43430@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43431
43432 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
43433 seq_printf(seq, "%-#8x", dst->module_id);
43434- seq_printf(seq, "%-29s",
43435- chtostr(tmp, dst->module_name_version, 28));
43436- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
43437+ seq_printf(seq, "%-.28s", dst->module_name_version);
43438+ seq_printf(seq, "%-.8s", dst->date);
43439 seq_printf(seq, "%8d ", dst->module_size);
43440 seq_printf(seq, "%8d ", dst->mpb_size);
43441 seq_printf(seq, "0x%04x", dst->module_flags);
43442@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43443 // == (allow) 512d bytes (max)
43444 static u16 *work16 = (u16 *) work32;
43445 int token;
43446- char tmp[16 + 1];
43447
43448 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
43449
43450@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43451 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
43452 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
43453 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
43454- seq_printf(seq, "Vendor info : %s\n",
43455- chtostr(tmp, (u8 *) (work32 + 2), 16));
43456- seq_printf(seq, "Product info : %s\n",
43457- chtostr(tmp, (u8 *) (work32 + 6), 16));
43458- seq_printf(seq, "Description : %s\n",
43459- chtostr(tmp, (u8 *) (work32 + 10), 16));
43460- seq_printf(seq, "Product rev. : %s\n",
43461- chtostr(tmp, (u8 *) (work32 + 14), 8));
43462+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
43463+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
43464+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
43465+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
43466
43467 seq_printf(seq, "Serial number : ");
43468 print_serial_number(seq, (u8 *) (work32 + 16),
43469@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43470 u8 pad[256]; // allow up to 256 byte (max) serial number
43471 } result;
43472
43473- char tmp[24 + 1];
43474-
43475 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
43476
43477 if (token < 0) {
43478@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43479 }
43480
43481 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
43482- seq_printf(seq, "Module name : %s\n",
43483- chtostr(tmp, result.module_name, 24));
43484- seq_printf(seq, "Module revision : %s\n",
43485- chtostr(tmp, result.module_rev, 8));
43486+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
43487+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
43488
43489 seq_printf(seq, "Serial number : ");
43490 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
43491@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43492 u8 instance_number[4];
43493 } result;
43494
43495- char tmp[64 + 1];
43496-
43497 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
43498
43499 if (token < 0) {
43500@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43501 return 0;
43502 }
43503
43504- seq_printf(seq, "Device name : %s\n",
43505- chtostr(tmp, result.device_name, 64));
43506- seq_printf(seq, "Service name : %s\n",
43507- chtostr(tmp, result.service_name, 64));
43508- seq_printf(seq, "Physical name : %s\n",
43509- chtostr(tmp, result.physical_location, 64));
43510- seq_printf(seq, "Instance number : %s\n",
43511- chtostr(tmp, result.instance_number, 4));
43512+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
43513+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
43514+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
43515+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
43516
43517 return 0;
43518 }
43519diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
43520index a8c08f3..155fe3d 100644
43521--- a/drivers/message/i2o/iop.c
43522+++ b/drivers/message/i2o/iop.c
43523@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
43524
43525 spin_lock_irqsave(&c->context_list_lock, flags);
43526
43527- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
43528- atomic_inc(&c->context_list_counter);
43529+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
43530+ atomic_inc_unchecked(&c->context_list_counter);
43531
43532- entry->context = atomic_read(&c->context_list_counter);
43533+ entry->context = atomic_read_unchecked(&c->context_list_counter);
43534
43535 list_add(&entry->list, &c->context_list);
43536
43537@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
43538
43539 #if BITS_PER_LONG == 64
43540 spin_lock_init(&c->context_list_lock);
43541- atomic_set(&c->context_list_counter, 0);
43542+ atomic_set_unchecked(&c->context_list_counter, 0);
43543 INIT_LIST_HEAD(&c->context_list);
43544 #endif
43545
43546diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
43547index fcbb2e9..2635e11 100644
43548--- a/drivers/mfd/janz-cmodio.c
43549+++ b/drivers/mfd/janz-cmodio.c
43550@@ -13,6 +13,7 @@
43551
43552 #include <linux/kernel.h>
43553 #include <linux/module.h>
43554+#include <linux/slab.h>
43555 #include <linux/init.h>
43556 #include <linux/pci.h>
43557 #include <linux/interrupt.h>
43558diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
43559index 9aa6d1e..1631bfc 100644
43560--- a/drivers/mfd/twl4030-irq.c
43561+++ b/drivers/mfd/twl4030-irq.c
43562@@ -35,6 +35,7 @@
43563 #include <linux/of.h>
43564 #include <linux/irqdomain.h>
43565 #include <linux/i2c/twl.h>
43566+#include <asm/pgtable.h>
43567
43568 #include "twl-core.h"
43569
43570@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
43571 * Install an irq handler for each of the SIH modules;
43572 * clone dummy irq_chip since PIH can't *do* anything
43573 */
43574- twl4030_irq_chip = dummy_irq_chip;
43575- twl4030_irq_chip.name = "twl4030";
43576+ pax_open_kernel();
43577+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
43578+ *(const char **)&twl4030_irq_chip.name = "twl4030";
43579
43580- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43581+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43582+ pax_close_kernel();
43583
43584 for (i = irq_base; i < irq_end; i++) {
43585 irq_set_chip_and_handler(i, &twl4030_irq_chip,
43586diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
43587index 277a8db..0e0b754 100644
43588--- a/drivers/mfd/twl6030-irq.c
43589+++ b/drivers/mfd/twl6030-irq.c
43590@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
43591 * install an irq handler for each of the modules;
43592 * clone dummy irq_chip since PIH can't *do* anything
43593 */
43594- twl6030_irq_chip = dummy_irq_chip;
43595- twl6030_irq_chip.name = "twl6030";
43596- twl6030_irq_chip.irq_set_type = NULL;
43597- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43598+ pax_open_kernel();
43599+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
43600+ *(const char **)&twl6030_irq_chip.name = "twl6030";
43601+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
43602+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43603+ pax_close_kernel();
43604
43605 for (i = irq_base; i < irq_end; i++) {
43606 irq_set_chip_and_handler(i, &twl6030_irq_chip,
43607diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
43608index f32550a..e3e52a2 100644
43609--- a/drivers/misc/c2port/core.c
43610+++ b/drivers/misc/c2port/core.c
43611@@ -920,7 +920,9 @@ struct c2port_device *c2port_device_register(char *name,
43612 mutex_init(&c2dev->mutex);
43613
43614 /* Create binary file */
43615- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43616+ pax_open_kernel();
43617+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43618+ pax_close_kernel();
43619 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
43620 if (unlikely(ret))
43621 goto error_device_create_bin_file;
43622diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
43623index 36f5d52..32311c3 100644
43624--- a/drivers/misc/kgdbts.c
43625+++ b/drivers/misc/kgdbts.c
43626@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
43627 char before[BREAK_INSTR_SIZE];
43628 char after[BREAK_INSTR_SIZE];
43629
43630- probe_kernel_read(before, (char *)kgdbts_break_test,
43631+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
43632 BREAK_INSTR_SIZE);
43633 init_simple_test();
43634 ts.tst = plant_and_detach_test;
43635@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
43636 /* Activate test with initial breakpoint */
43637 if (!is_early)
43638 kgdb_breakpoint();
43639- probe_kernel_read(after, (char *)kgdbts_break_test,
43640+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
43641 BREAK_INSTR_SIZE);
43642 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
43643 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
43644diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
43645index 036effe..b3a6336 100644
43646--- a/drivers/misc/lis3lv02d/lis3lv02d.c
43647+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
43648@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
43649 * the lid is closed. This leads to interrupts as soon as a little move
43650 * is done.
43651 */
43652- atomic_inc(&lis3->count);
43653+ atomic_inc_unchecked(&lis3->count);
43654
43655 wake_up_interruptible(&lis3->misc_wait);
43656 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
43657@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
43658 if (lis3->pm_dev)
43659 pm_runtime_get_sync(lis3->pm_dev);
43660
43661- atomic_set(&lis3->count, 0);
43662+ atomic_set_unchecked(&lis3->count, 0);
43663 return 0;
43664 }
43665
43666@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
43667 add_wait_queue(&lis3->misc_wait, &wait);
43668 while (true) {
43669 set_current_state(TASK_INTERRUPTIBLE);
43670- data = atomic_xchg(&lis3->count, 0);
43671+ data = atomic_xchg_unchecked(&lis3->count, 0);
43672 if (data)
43673 break;
43674
43675@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
43676 struct lis3lv02d, miscdev);
43677
43678 poll_wait(file, &lis3->misc_wait, wait);
43679- if (atomic_read(&lis3->count))
43680+ if (atomic_read_unchecked(&lis3->count))
43681 return POLLIN | POLLRDNORM;
43682 return 0;
43683 }
43684diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
43685index c439c82..1f20f57 100644
43686--- a/drivers/misc/lis3lv02d/lis3lv02d.h
43687+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
43688@@ -297,7 +297,7 @@ struct lis3lv02d {
43689 struct input_polled_dev *idev; /* input device */
43690 struct platform_device *pdev; /* platform device */
43691 struct regulator_bulk_data regulators[2];
43692- atomic_t count; /* interrupt count after last read */
43693+ atomic_unchecked_t count; /* interrupt count after last read */
43694 union axis_conversion ac; /* hw -> logical axis */
43695 int mapped_btns[3];
43696
43697diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
43698index 2f30bad..c4c13d0 100644
43699--- a/drivers/misc/sgi-gru/gruhandles.c
43700+++ b/drivers/misc/sgi-gru/gruhandles.c
43701@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
43702 unsigned long nsec;
43703
43704 nsec = CLKS2NSEC(clks);
43705- atomic_long_inc(&mcs_op_statistics[op].count);
43706- atomic_long_add(nsec, &mcs_op_statistics[op].total);
43707+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
43708+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
43709 if (mcs_op_statistics[op].max < nsec)
43710 mcs_op_statistics[op].max = nsec;
43711 }
43712diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
43713index 4f76359..cdfcb2e 100644
43714--- a/drivers/misc/sgi-gru/gruprocfs.c
43715+++ b/drivers/misc/sgi-gru/gruprocfs.c
43716@@ -32,9 +32,9 @@
43717
43718 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
43719
43720-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
43721+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
43722 {
43723- unsigned long val = atomic_long_read(v);
43724+ unsigned long val = atomic_long_read_unchecked(v);
43725
43726 seq_printf(s, "%16lu %s\n", val, id);
43727 }
43728@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
43729
43730 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
43731 for (op = 0; op < mcsop_last; op++) {
43732- count = atomic_long_read(&mcs_op_statistics[op].count);
43733- total = atomic_long_read(&mcs_op_statistics[op].total);
43734+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
43735+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
43736 max = mcs_op_statistics[op].max;
43737 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
43738 count ? total / count : 0, max);
43739diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
43740index 5c3ce24..4915ccb 100644
43741--- a/drivers/misc/sgi-gru/grutables.h
43742+++ b/drivers/misc/sgi-gru/grutables.h
43743@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
43744 * GRU statistics.
43745 */
43746 struct gru_stats_s {
43747- atomic_long_t vdata_alloc;
43748- atomic_long_t vdata_free;
43749- atomic_long_t gts_alloc;
43750- atomic_long_t gts_free;
43751- atomic_long_t gms_alloc;
43752- atomic_long_t gms_free;
43753- atomic_long_t gts_double_allocate;
43754- atomic_long_t assign_context;
43755- atomic_long_t assign_context_failed;
43756- atomic_long_t free_context;
43757- atomic_long_t load_user_context;
43758- atomic_long_t load_kernel_context;
43759- atomic_long_t lock_kernel_context;
43760- atomic_long_t unlock_kernel_context;
43761- atomic_long_t steal_user_context;
43762- atomic_long_t steal_kernel_context;
43763- atomic_long_t steal_context_failed;
43764- atomic_long_t nopfn;
43765- atomic_long_t asid_new;
43766- atomic_long_t asid_next;
43767- atomic_long_t asid_wrap;
43768- atomic_long_t asid_reuse;
43769- atomic_long_t intr;
43770- atomic_long_t intr_cbr;
43771- atomic_long_t intr_tfh;
43772- atomic_long_t intr_spurious;
43773- atomic_long_t intr_mm_lock_failed;
43774- atomic_long_t call_os;
43775- atomic_long_t call_os_wait_queue;
43776- atomic_long_t user_flush_tlb;
43777- atomic_long_t user_unload_context;
43778- atomic_long_t user_exception;
43779- atomic_long_t set_context_option;
43780- atomic_long_t check_context_retarget_intr;
43781- atomic_long_t check_context_unload;
43782- atomic_long_t tlb_dropin;
43783- atomic_long_t tlb_preload_page;
43784- atomic_long_t tlb_dropin_fail_no_asid;
43785- atomic_long_t tlb_dropin_fail_upm;
43786- atomic_long_t tlb_dropin_fail_invalid;
43787- atomic_long_t tlb_dropin_fail_range_active;
43788- atomic_long_t tlb_dropin_fail_idle;
43789- atomic_long_t tlb_dropin_fail_fmm;
43790- atomic_long_t tlb_dropin_fail_no_exception;
43791- atomic_long_t tfh_stale_on_fault;
43792- atomic_long_t mmu_invalidate_range;
43793- atomic_long_t mmu_invalidate_page;
43794- atomic_long_t flush_tlb;
43795- atomic_long_t flush_tlb_gru;
43796- atomic_long_t flush_tlb_gru_tgh;
43797- atomic_long_t flush_tlb_gru_zero_asid;
43798+ atomic_long_unchecked_t vdata_alloc;
43799+ atomic_long_unchecked_t vdata_free;
43800+ atomic_long_unchecked_t gts_alloc;
43801+ atomic_long_unchecked_t gts_free;
43802+ atomic_long_unchecked_t gms_alloc;
43803+ atomic_long_unchecked_t gms_free;
43804+ atomic_long_unchecked_t gts_double_allocate;
43805+ atomic_long_unchecked_t assign_context;
43806+ atomic_long_unchecked_t assign_context_failed;
43807+ atomic_long_unchecked_t free_context;
43808+ atomic_long_unchecked_t load_user_context;
43809+ atomic_long_unchecked_t load_kernel_context;
43810+ atomic_long_unchecked_t lock_kernel_context;
43811+ atomic_long_unchecked_t unlock_kernel_context;
43812+ atomic_long_unchecked_t steal_user_context;
43813+ atomic_long_unchecked_t steal_kernel_context;
43814+ atomic_long_unchecked_t steal_context_failed;
43815+ atomic_long_unchecked_t nopfn;
43816+ atomic_long_unchecked_t asid_new;
43817+ atomic_long_unchecked_t asid_next;
43818+ atomic_long_unchecked_t asid_wrap;
43819+ atomic_long_unchecked_t asid_reuse;
43820+ atomic_long_unchecked_t intr;
43821+ atomic_long_unchecked_t intr_cbr;
43822+ atomic_long_unchecked_t intr_tfh;
43823+ atomic_long_unchecked_t intr_spurious;
43824+ atomic_long_unchecked_t intr_mm_lock_failed;
43825+ atomic_long_unchecked_t call_os;
43826+ atomic_long_unchecked_t call_os_wait_queue;
43827+ atomic_long_unchecked_t user_flush_tlb;
43828+ atomic_long_unchecked_t user_unload_context;
43829+ atomic_long_unchecked_t user_exception;
43830+ atomic_long_unchecked_t set_context_option;
43831+ atomic_long_unchecked_t check_context_retarget_intr;
43832+ atomic_long_unchecked_t check_context_unload;
43833+ atomic_long_unchecked_t tlb_dropin;
43834+ atomic_long_unchecked_t tlb_preload_page;
43835+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
43836+ atomic_long_unchecked_t tlb_dropin_fail_upm;
43837+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
43838+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
43839+ atomic_long_unchecked_t tlb_dropin_fail_idle;
43840+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
43841+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
43842+ atomic_long_unchecked_t tfh_stale_on_fault;
43843+ atomic_long_unchecked_t mmu_invalidate_range;
43844+ atomic_long_unchecked_t mmu_invalidate_page;
43845+ atomic_long_unchecked_t flush_tlb;
43846+ atomic_long_unchecked_t flush_tlb_gru;
43847+ atomic_long_unchecked_t flush_tlb_gru_tgh;
43848+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
43849
43850- atomic_long_t copy_gpa;
43851- atomic_long_t read_gpa;
43852+ atomic_long_unchecked_t copy_gpa;
43853+ atomic_long_unchecked_t read_gpa;
43854
43855- atomic_long_t mesq_receive;
43856- atomic_long_t mesq_receive_none;
43857- atomic_long_t mesq_send;
43858- atomic_long_t mesq_send_failed;
43859- atomic_long_t mesq_noop;
43860- atomic_long_t mesq_send_unexpected_error;
43861- atomic_long_t mesq_send_lb_overflow;
43862- atomic_long_t mesq_send_qlimit_reached;
43863- atomic_long_t mesq_send_amo_nacked;
43864- atomic_long_t mesq_send_put_nacked;
43865- atomic_long_t mesq_page_overflow;
43866- atomic_long_t mesq_qf_locked;
43867- atomic_long_t mesq_qf_noop_not_full;
43868- atomic_long_t mesq_qf_switch_head_failed;
43869- atomic_long_t mesq_qf_unexpected_error;
43870- atomic_long_t mesq_noop_unexpected_error;
43871- atomic_long_t mesq_noop_lb_overflow;
43872- atomic_long_t mesq_noop_qlimit_reached;
43873- atomic_long_t mesq_noop_amo_nacked;
43874- atomic_long_t mesq_noop_put_nacked;
43875- atomic_long_t mesq_noop_page_overflow;
43876+ atomic_long_unchecked_t mesq_receive;
43877+ atomic_long_unchecked_t mesq_receive_none;
43878+ atomic_long_unchecked_t mesq_send;
43879+ atomic_long_unchecked_t mesq_send_failed;
43880+ atomic_long_unchecked_t mesq_noop;
43881+ atomic_long_unchecked_t mesq_send_unexpected_error;
43882+ atomic_long_unchecked_t mesq_send_lb_overflow;
43883+ atomic_long_unchecked_t mesq_send_qlimit_reached;
43884+ atomic_long_unchecked_t mesq_send_amo_nacked;
43885+ atomic_long_unchecked_t mesq_send_put_nacked;
43886+ atomic_long_unchecked_t mesq_page_overflow;
43887+ atomic_long_unchecked_t mesq_qf_locked;
43888+ atomic_long_unchecked_t mesq_qf_noop_not_full;
43889+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
43890+ atomic_long_unchecked_t mesq_qf_unexpected_error;
43891+ atomic_long_unchecked_t mesq_noop_unexpected_error;
43892+ atomic_long_unchecked_t mesq_noop_lb_overflow;
43893+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
43894+ atomic_long_unchecked_t mesq_noop_amo_nacked;
43895+ atomic_long_unchecked_t mesq_noop_put_nacked;
43896+ atomic_long_unchecked_t mesq_noop_page_overflow;
43897
43898 };
43899
43900@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
43901 tghop_invalidate, mcsop_last};
43902
43903 struct mcs_op_statistic {
43904- atomic_long_t count;
43905- atomic_long_t total;
43906+ atomic_long_unchecked_t count;
43907+ atomic_long_unchecked_t total;
43908 unsigned long max;
43909 };
43910
43911@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
43912
43913 #define STAT(id) do { \
43914 if (gru_options & OPT_STATS) \
43915- atomic_long_inc(&gru_stats.id); \
43916+ atomic_long_inc_unchecked(&gru_stats.id); \
43917 } while (0)
43918
43919 #ifdef CONFIG_SGI_GRU_DEBUG
43920diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
43921index c862cd4..0d176fe 100644
43922--- a/drivers/misc/sgi-xp/xp.h
43923+++ b/drivers/misc/sgi-xp/xp.h
43924@@ -288,7 +288,7 @@ struct xpc_interface {
43925 xpc_notify_func, void *);
43926 void (*received) (short, int, void *);
43927 enum xp_retval (*partid_to_nasids) (short, void *);
43928-};
43929+} __no_const;
43930
43931 extern struct xpc_interface xpc_interface;
43932
43933diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
43934index b94d5f7..7f494c5 100644
43935--- a/drivers/misc/sgi-xp/xpc.h
43936+++ b/drivers/misc/sgi-xp/xpc.h
43937@@ -835,6 +835,7 @@ struct xpc_arch_operations {
43938 void (*received_payload) (struct xpc_channel *, void *);
43939 void (*notify_senders_of_disconnect) (struct xpc_channel *);
43940 };
43941+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
43942
43943 /* struct xpc_partition act_state values (for XPC HB) */
43944
43945@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
43946 /* found in xpc_main.c */
43947 extern struct device *xpc_part;
43948 extern struct device *xpc_chan;
43949-extern struct xpc_arch_operations xpc_arch_ops;
43950+extern xpc_arch_operations_no_const xpc_arch_ops;
43951 extern int xpc_disengage_timelimit;
43952 extern int xpc_disengage_timedout;
43953 extern int xpc_activate_IRQ_rcvd;
43954diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
43955index 82dc574..8539ab2 100644
43956--- a/drivers/misc/sgi-xp/xpc_main.c
43957+++ b/drivers/misc/sgi-xp/xpc_main.c
43958@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
43959 .notifier_call = xpc_system_die,
43960 };
43961
43962-struct xpc_arch_operations xpc_arch_ops;
43963+xpc_arch_operations_no_const xpc_arch_ops;
43964
43965 /*
43966 * Timer function to enforce the timelimit on the partition disengage.
43967@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
43968
43969 if (((die_args->trapnr == X86_TRAP_MF) ||
43970 (die_args->trapnr == X86_TRAP_XF)) &&
43971- !user_mode_vm(die_args->regs))
43972+ !user_mode(die_args->regs))
43973 xpc_die_deactivate();
43974
43975 break;
43976diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
43977index 837fc73..acb5862 100644
43978--- a/drivers/mmc/core/mmc_ops.c
43979+++ b/drivers/mmc/core/mmc_ops.c
43980@@ -213,7 +213,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
43981 void *data_buf;
43982 int is_on_stack;
43983
43984- is_on_stack = object_is_on_stack(buf);
43985+ is_on_stack = object_starts_on_stack(buf);
43986 if (is_on_stack) {
43987 /*
43988 * dma onto stack is unsafe/nonportable, but callers to this
43989diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
43990index 81b2994..dce857e 100644
43991--- a/drivers/mmc/host/dw_mmc.h
43992+++ b/drivers/mmc/host/dw_mmc.h
43993@@ -203,5 +203,5 @@ struct dw_mci_drv_data {
43994 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
43995 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
43996 int (*parse_dt)(struct dw_mci *host);
43997-};
43998+} __do_const;
43999 #endif /* _DW_MMC_H_ */
44000diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
44001index 926aaf6..8e153e2 100644
44002--- a/drivers/mmc/host/sdhci-s3c.c
44003+++ b/drivers/mmc/host/sdhci-s3c.c
44004@@ -664,9 +664,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
44005 * we can use overriding functions instead of default.
44006 */
44007 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
44008- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44009- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44010- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44011+ pax_open_kernel();
44012+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44013+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44014+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44015+ pax_close_kernel();
44016 }
44017
44018 /* It supports additional host capabilities if needed */
44019diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
44020index 0c8bb6b..6f35deb 100644
44021--- a/drivers/mtd/nand/denali.c
44022+++ b/drivers/mtd/nand/denali.c
44023@@ -24,6 +24,7 @@
44024 #include <linux/slab.h>
44025 #include <linux/mtd/mtd.h>
44026 #include <linux/module.h>
44027+#include <linux/slab.h>
44028
44029 #include "denali.h"
44030
44031diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
44032index 51b9d6a..52af9a7 100644
44033--- a/drivers/mtd/nftlmount.c
44034+++ b/drivers/mtd/nftlmount.c
44035@@ -24,6 +24,7 @@
44036 #include <asm/errno.h>
44037 #include <linux/delay.h>
44038 #include <linux/slab.h>
44039+#include <linux/sched.h>
44040 #include <linux/mtd/mtd.h>
44041 #include <linux/mtd/nand.h>
44042 #include <linux/mtd/nftl.h>
44043diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
44044index f9d5615..99dd95f 100644
44045--- a/drivers/mtd/sm_ftl.c
44046+++ b/drivers/mtd/sm_ftl.c
44047@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
44048 #define SM_CIS_VENDOR_OFFSET 0x59
44049 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
44050 {
44051- struct attribute_group *attr_group;
44052+ attribute_group_no_const *attr_group;
44053 struct attribute **attributes;
44054 struct sm_sysfs_attribute *vendor_attribute;
44055
44056diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
44057index e48cb33..72e73fc 100644
44058--- a/drivers/net/bonding/bond_main.c
44059+++ b/drivers/net/bonding/bond_main.c
44060@@ -4832,7 +4832,7 @@ static unsigned int bond_get_num_tx_queues(void)
44061 return tx_queues;
44062 }
44063
44064-static struct rtnl_link_ops bond_link_ops __read_mostly = {
44065+static struct rtnl_link_ops bond_link_ops = {
44066 .kind = "bond",
44067 .priv_size = sizeof(struct bonding),
44068 .setup = bond_setup,
44069@@ -4957,8 +4957,8 @@ static void __exit bonding_exit(void)
44070
44071 bond_destroy_debugfs();
44072
44073- rtnl_link_unregister(&bond_link_ops);
44074 unregister_pernet_subsys(&bond_net_ops);
44075+ rtnl_link_unregister(&bond_link_ops);
44076
44077 #ifdef CONFIG_NET_POLL_CONTROLLER
44078 /*
44079diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
44080index e1d2643..7f4133b 100644
44081--- a/drivers/net/ethernet/8390/ax88796.c
44082+++ b/drivers/net/ethernet/8390/ax88796.c
44083@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
44084 if (ax->plat->reg_offsets)
44085 ei_local->reg_offset = ax->plat->reg_offsets;
44086 else {
44087+ resource_size_t _mem_size = mem_size;
44088+ do_div(_mem_size, 0x18);
44089 ei_local->reg_offset = ax->reg_offsets;
44090 for (ret = 0; ret < 0x18; ret++)
44091- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
44092+ ax->reg_offsets[ret] = _mem_size * ret;
44093 }
44094
44095 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
44096diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44097index c07a6d0..ca88c45 100644
44098--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44099+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44100@@ -1137,7 +1137,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
44101 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
44102 {
44103 /* RX_MODE controlling object */
44104- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
44105+ bnx2x_init_rx_mode_obj(bp);
44106
44107 /* multicast configuration controlling object */
44108 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
44109diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44110index 8f03c98..dd0ef10 100644
44111--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44112+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44113@@ -2345,15 +2345,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
44114 return rc;
44115 }
44116
44117-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44118- struct bnx2x_rx_mode_obj *o)
44119+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
44120 {
44121 if (CHIP_IS_E1x(bp)) {
44122- o->wait_comp = bnx2x_empty_rx_mode_wait;
44123- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
44124+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
44125+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
44126 } else {
44127- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
44128- o->config_rx_mode = bnx2x_set_rx_mode_e2;
44129+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
44130+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
44131 }
44132 }
44133
44134diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44135index 798dfe9..05d0a44 100644
44136--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44137+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44138@@ -1311,8 +1311,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
44139
44140 /********************* RX MODE ****************/
44141
44142-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44143- struct bnx2x_rx_mode_obj *o);
44144+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
44145
44146 /**
44147 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
44148diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
44149index cd63d11..b67dd78 100644
44150--- a/drivers/net/ethernet/broadcom/tg3.h
44151+++ b/drivers/net/ethernet/broadcom/tg3.h
44152@@ -147,6 +147,7 @@
44153 #define CHIPREV_ID_5750_A0 0x4000
44154 #define CHIPREV_ID_5750_A1 0x4001
44155 #define CHIPREV_ID_5750_A3 0x4003
44156+#define CHIPREV_ID_5750_C1 0x4201
44157 #define CHIPREV_ID_5750_C2 0x4202
44158 #define CHIPREV_ID_5752_A0_HW 0x5000
44159 #define CHIPREV_ID_5752_A0 0x6000
44160diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44161index 8cffcdf..aadf043 100644
44162--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44163+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44164@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
44165 */
44166 struct l2t_skb_cb {
44167 arp_failure_handler_func arp_failure_handler;
44168-};
44169+} __no_const;
44170
44171 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
44172
44173diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
44174index 4c83003..2a2a5b9 100644
44175--- a/drivers/net/ethernet/dec/tulip/de4x5.c
44176+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
44177@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
44178 for (i=0; i<ETH_ALEN; i++) {
44179 tmp.addr[i] = dev->dev_addr[i];
44180 }
44181- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
44182+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
44183 break;
44184
44185 case DE4X5_SET_HWADDR: /* Set the hardware address */
44186@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
44187 spin_lock_irqsave(&lp->lock, flags);
44188 memcpy(&statbuf, &lp->pktStats, ioc->len);
44189 spin_unlock_irqrestore(&lp->lock, flags);
44190- if (copy_to_user(ioc->data, &statbuf, ioc->len))
44191+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
44192 return -EFAULT;
44193 break;
44194 }
44195diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
44196index 3d91a5e..1014702 100644
44197--- a/drivers/net/ethernet/emulex/benet/be_main.c
44198+++ b/drivers/net/ethernet/emulex/benet/be_main.c
44199@@ -469,7 +469,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
44200
44201 if (wrapped)
44202 newacc += 65536;
44203- ACCESS_ONCE(*acc) = newacc;
44204+ ACCESS_ONCE_RW(*acc) = newacc;
44205 }
44206
44207 void populate_erx_stats(struct be_adapter *adapter,
44208diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
44209index 934e1ae..b262e6b 100644
44210--- a/drivers/net/ethernet/faraday/ftgmac100.c
44211+++ b/drivers/net/ethernet/faraday/ftgmac100.c
44212@@ -31,6 +31,8 @@
44213 #include <linux/netdevice.h>
44214 #include <linux/phy.h>
44215 #include <linux/platform_device.h>
44216+#include <linux/interrupt.h>
44217+#include <linux/irqreturn.h>
44218 #include <net/ip.h>
44219
44220 #include "ftgmac100.h"
44221diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
44222index 4658f4c..407d155 100644
44223--- a/drivers/net/ethernet/faraday/ftmac100.c
44224+++ b/drivers/net/ethernet/faraday/ftmac100.c
44225@@ -31,6 +31,8 @@
44226 #include <linux/module.h>
44227 #include <linux/netdevice.h>
44228 #include <linux/platform_device.h>
44229+#include <linux/interrupt.h>
44230+#include <linux/irqreturn.h>
44231
44232 #include "ftmac100.h"
44233
44234diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44235index 331987d..3be1135 100644
44236--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44237+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44238@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
44239 }
44240
44241 /* update the base incval used to calculate frequency adjustment */
44242- ACCESS_ONCE(adapter->base_incval) = incval;
44243+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
44244 smp_mb();
44245
44246 /* need lock to prevent incorrect read while modifying cyclecounter */
44247diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44248index fbe5363..266b4e3 100644
44249--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
44250+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44251@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44252 struct __vxge_hw_fifo *fifo;
44253 struct vxge_hw_fifo_config *config;
44254 u32 txdl_size, txdl_per_memblock;
44255- struct vxge_hw_mempool_cbs fifo_mp_callback;
44256+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
44257+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
44258+ };
44259+
44260 struct __vxge_hw_virtualpath *vpath;
44261
44262 if ((vp == NULL) || (attr == NULL)) {
44263@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44264 goto exit;
44265 }
44266
44267- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
44268-
44269 fifo->mempool =
44270 __vxge_hw_mempool_create(vpath->hldev,
44271 fifo->config->memblock_size,
44272diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44273index 345d987..af69721 100644
44274--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44275+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44276@@ -2011,7 +2011,9 @@ int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
44277 op_mode = QLC_83XX_DEFAULT_OPMODE;
44278
44279 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
44280- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44281+ pax_open_kernel();
44282+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44283+ pax_close_kernel();
44284 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44285 } else {
44286 return -EIO;
44287diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44288index 599d1fd..59868fe 100644
44289--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44290+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44291@@ -191,17 +191,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
44292 case QLCNIC_NON_PRIV_FUNC:
44293 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
44294 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44295- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44296+ pax_open_kernel();
44297+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44298+ pax_close_kernel();
44299 break;
44300 case QLCNIC_PRIV_FUNC:
44301 ahw->op_mode = QLCNIC_PRIV_FUNC;
44302 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
44303- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44304+ pax_open_kernel();
44305+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44306+ pax_close_kernel();
44307 break;
44308 case QLCNIC_MGMT_FUNC:
44309 ahw->op_mode = QLCNIC_MGMT_FUNC;
44310 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44311- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44312+ pax_open_kernel();
44313+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44314+ pax_close_kernel();
44315 break;
44316 default:
44317 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
44318diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
44319index 85e5c97..76f97ec 100644
44320--- a/drivers/net/ethernet/realtek/r8169.c
44321+++ b/drivers/net/ethernet/realtek/r8169.c
44322@@ -759,22 +759,22 @@ struct rtl8169_private {
44323 struct mdio_ops {
44324 void (*write)(struct rtl8169_private *, int, int);
44325 int (*read)(struct rtl8169_private *, int);
44326- } mdio_ops;
44327+ } __no_const mdio_ops;
44328
44329 struct pll_power_ops {
44330 void (*down)(struct rtl8169_private *);
44331 void (*up)(struct rtl8169_private *);
44332- } pll_power_ops;
44333+ } __no_const pll_power_ops;
44334
44335 struct jumbo_ops {
44336 void (*enable)(struct rtl8169_private *);
44337 void (*disable)(struct rtl8169_private *);
44338- } jumbo_ops;
44339+ } __no_const jumbo_ops;
44340
44341 struct csi_ops {
44342 void (*write)(struct rtl8169_private *, int, int);
44343 u32 (*read)(struct rtl8169_private *, int);
44344- } csi_ops;
44345+ } __no_const csi_ops;
44346
44347 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
44348 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
44349diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
44350index b495394..0748c54 100644
44351--- a/drivers/net/ethernet/sfc/ptp.c
44352+++ b/drivers/net/ethernet/sfc/ptp.c
44353@@ -535,7 +535,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
44354 (u32)((u64)ptp->start.dma_addr >> 32));
44355
44356 /* Clear flag that signals MC ready */
44357- ACCESS_ONCE(*start) = 0;
44358+ ACCESS_ONCE_RW(*start) = 0;
44359 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
44360 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
44361
44362diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44363index 50617c5..b13724c 100644
44364--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44365+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44366@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
44367
44368 writel(value, ioaddr + MMC_CNTRL);
44369
44370- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44371- MMC_CNTRL, value);
44372+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44373+// MMC_CNTRL, value);
44374 }
44375
44376 /* To mask all all interrupts.*/
44377diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
44378index e6fe0d8..2b7d752 100644
44379--- a/drivers/net/hyperv/hyperv_net.h
44380+++ b/drivers/net/hyperv/hyperv_net.h
44381@@ -101,7 +101,7 @@ struct rndis_device {
44382
44383 enum rndis_device_state state;
44384 bool link_state;
44385- atomic_t new_req_id;
44386+ atomic_unchecked_t new_req_id;
44387
44388 spinlock_t request_lock;
44389 struct list_head req_list;
44390diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
44391index 0775f0a..d4fb316 100644
44392--- a/drivers/net/hyperv/rndis_filter.c
44393+++ b/drivers/net/hyperv/rndis_filter.c
44394@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
44395 * template
44396 */
44397 set = &rndis_msg->msg.set_req;
44398- set->req_id = atomic_inc_return(&dev->new_req_id);
44399+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44400
44401 /* Add to the request list */
44402 spin_lock_irqsave(&dev->request_lock, flags);
44403@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
44404
44405 /* Setup the rndis set */
44406 halt = &request->request_msg.msg.halt_req;
44407- halt->req_id = atomic_inc_return(&dev->new_req_id);
44408+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44409
44410 /* Ignore return since this msg is optional. */
44411 rndis_filter_send_request(dev, request);
44412diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
44413index bf0d55e..82bcfbd1 100644
44414--- a/drivers/net/ieee802154/fakehard.c
44415+++ b/drivers/net/ieee802154/fakehard.c
44416@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
44417 phy->transmit_power = 0xbf;
44418
44419 dev->netdev_ops = &fake_ops;
44420- dev->ml_priv = &fake_mlme;
44421+ dev->ml_priv = (void *)&fake_mlme;
44422
44423 priv = netdev_priv(dev);
44424 priv->phy = phy;
44425diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
44426index 16b43bf..ead0c35 100644
44427--- a/drivers/net/macvlan.c
44428+++ b/drivers/net/macvlan.c
44429@@ -934,13 +934,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
44430 int macvlan_link_register(struct rtnl_link_ops *ops)
44431 {
44432 /* common fields */
44433- ops->priv_size = sizeof(struct macvlan_dev);
44434- ops->validate = macvlan_validate;
44435- ops->maxtype = IFLA_MACVLAN_MAX;
44436- ops->policy = macvlan_policy;
44437- ops->changelink = macvlan_changelink;
44438- ops->get_size = macvlan_get_size;
44439- ops->fill_info = macvlan_fill_info;
44440+ pax_open_kernel();
44441+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
44442+ *(void **)&ops->validate = macvlan_validate;
44443+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
44444+ *(const void **)&ops->policy = macvlan_policy;
44445+ *(void **)&ops->changelink = macvlan_changelink;
44446+ *(void **)&ops->get_size = macvlan_get_size;
44447+ *(void **)&ops->fill_info = macvlan_fill_info;
44448+ pax_close_kernel();
44449
44450 return rtnl_link_register(ops);
44451 };
44452@@ -996,7 +998,7 @@ static int macvlan_device_event(struct notifier_block *unused,
44453 return NOTIFY_DONE;
44454 }
44455
44456-static struct notifier_block macvlan_notifier_block __read_mostly = {
44457+static struct notifier_block macvlan_notifier_block = {
44458 .notifier_call = macvlan_device_event,
44459 };
44460
44461diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
44462index ea53abb..2e4d087 100644
44463--- a/drivers/net/macvtap.c
44464+++ b/drivers/net/macvtap.c
44465@@ -1286,7 +1286,7 @@ static int macvtap_device_event(struct notifier_block *unused,
44466 return NOTIFY_DONE;
44467 }
44468
44469-static struct notifier_block macvtap_notifier_block __read_mostly = {
44470+static struct notifier_block macvtap_notifier_block = {
44471 .notifier_call = macvtap_device_event,
44472 };
44473
44474diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
44475index daec9b0..6428fcb 100644
44476--- a/drivers/net/phy/mdio-bitbang.c
44477+++ b/drivers/net/phy/mdio-bitbang.c
44478@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
44479 struct mdiobb_ctrl *ctrl = bus->priv;
44480
44481 module_put(ctrl->ops->owner);
44482+ mdiobus_unregister(bus);
44483 mdiobus_free(bus);
44484 }
44485 EXPORT_SYMBOL(free_mdio_bitbang);
44486diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
44487index 72ff14b..11d442d 100644
44488--- a/drivers/net/ppp/ppp_generic.c
44489+++ b/drivers/net/ppp/ppp_generic.c
44490@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44491 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
44492 struct ppp_stats stats;
44493 struct ppp_comp_stats cstats;
44494- char *vers;
44495
44496 switch (cmd) {
44497 case SIOCGPPPSTATS:
44498@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44499 break;
44500
44501 case SIOCGPPPVER:
44502- vers = PPP_VERSION;
44503- if (copy_to_user(addr, vers, strlen(vers) + 1))
44504+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
44505 break;
44506 err = 0;
44507 break;
44508diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
44509index 1252d9c..80e660b 100644
44510--- a/drivers/net/slip/slhc.c
44511+++ b/drivers/net/slip/slhc.c
44512@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
44513 register struct tcphdr *thp;
44514 register struct iphdr *ip;
44515 register struct cstate *cs;
44516- int len, hdrlen;
44517+ long len, hdrlen;
44518 unsigned char *cp = icp;
44519
44520 /* We've got a compressed packet; read the change byte */
44521diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
44522index bff7e0b..7315137 100644
44523--- a/drivers/net/team/team.c
44524+++ b/drivers/net/team/team.c
44525@@ -2702,7 +2702,7 @@ static int team_device_event(struct notifier_block *unused,
44526 return NOTIFY_DONE;
44527 }
44528
44529-static struct notifier_block team_notifier_block __read_mostly = {
44530+static struct notifier_block team_notifier_block = {
44531 .notifier_call = team_device_event,
44532 };
44533
44534diff --git a/drivers/net/tun.c b/drivers/net/tun.c
44535index 71af122..b3c20f3 100644
44536--- a/drivers/net/tun.c
44537+++ b/drivers/net/tun.c
44538@@ -1691,11 +1691,11 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
44539 INIT_LIST_HEAD(&tun->disabled);
44540 err = tun_attach(tun, file);
44541 if (err < 0)
44542- goto err_free_dev;
44543+ goto err_free_flow;
44544
44545 err = register_netdevice(tun->dev);
44546 if (err < 0)
44547- goto err_free_dev;
44548+ goto err_detach;
44549
44550 if (device_create_file(&tun->dev->dev, &dev_attr_tun_flags) ||
44551 device_create_file(&tun->dev->dev, &dev_attr_owner) ||
44552@@ -1739,7 +1739,12 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
44553 strcpy(ifr->ifr_name, tun->dev->name);
44554 return 0;
44555
44556- err_free_dev:
44557+err_detach:
44558+ tun_detach_all(dev);
44559+err_free_flow:
44560+ tun_flow_uninit(tun);
44561+ security_tun_dev_free_security(tun->security);
44562+err_free_dev:
44563 free_netdev(dev);
44564 return err;
44565 }
44566@@ -1869,7 +1874,7 @@ unlock:
44567 }
44568
44569 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44570- unsigned long arg, int ifreq_len)
44571+ unsigned long arg, size_t ifreq_len)
44572 {
44573 struct tun_file *tfile = file->private_data;
44574 struct tun_struct *tun;
44575@@ -1881,6 +1886,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44576 int vnet_hdr_sz;
44577 int ret;
44578
44579+ if (ifreq_len > sizeof ifr)
44580+ return -EFAULT;
44581+
44582 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
44583 if (copy_from_user(&ifr, argp, ifreq_len))
44584 return -EFAULT;
44585diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
44586index 86292e6..8d34433 100644
44587--- a/drivers/net/usb/hso.c
44588+++ b/drivers/net/usb/hso.c
44589@@ -71,7 +71,7 @@
44590 #include <asm/byteorder.h>
44591 #include <linux/serial_core.h>
44592 #include <linux/serial.h>
44593-
44594+#include <asm/local.h>
44595
44596 #define MOD_AUTHOR "Option Wireless"
44597 #define MOD_DESCRIPTION "USB High Speed Option driver"
44598@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
44599 struct urb *urb;
44600
44601 urb = serial->rx_urb[0];
44602- if (serial->port.count > 0) {
44603+ if (atomic_read(&serial->port.count) > 0) {
44604 count = put_rxbuf_data(urb, serial);
44605 if (count == -1)
44606 return;
44607@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
44608 DUMP1(urb->transfer_buffer, urb->actual_length);
44609
44610 /* Anyone listening? */
44611- if (serial->port.count == 0)
44612+ if (atomic_read(&serial->port.count) == 0)
44613 return;
44614
44615 if (status == 0) {
44616@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44617 tty_port_tty_set(&serial->port, tty);
44618
44619 /* check for port already opened, if not set the termios */
44620- serial->port.count++;
44621- if (serial->port.count == 1) {
44622+ if (atomic_inc_return(&serial->port.count) == 1) {
44623 serial->rx_state = RX_IDLE;
44624 /* Force default termio settings */
44625 _hso_serial_set_termios(tty, NULL);
44626@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44627 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
44628 if (result) {
44629 hso_stop_serial_device(serial->parent);
44630- serial->port.count--;
44631+ atomic_dec(&serial->port.count);
44632 kref_put(&serial->parent->ref, hso_serial_ref_free);
44633 }
44634 } else {
44635@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
44636
44637 /* reset the rts and dtr */
44638 /* do the actual close */
44639- serial->port.count--;
44640+ atomic_dec(&serial->port.count);
44641
44642- if (serial->port.count <= 0) {
44643- serial->port.count = 0;
44644+ if (atomic_read(&serial->port.count) <= 0) {
44645+ atomic_set(&serial->port.count, 0);
44646 tty_port_tty_set(&serial->port, NULL);
44647 if (!usb_gone)
44648 hso_stop_serial_device(serial->parent);
44649@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
44650
44651 /* the actual setup */
44652 spin_lock_irqsave(&serial->serial_lock, flags);
44653- if (serial->port.count)
44654+ if (atomic_read(&serial->port.count))
44655 _hso_serial_set_termios(tty, old);
44656 else
44657 tty->termios = *old;
44658@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
44659 D1("Pending read interrupt on port %d\n", i);
44660 spin_lock(&serial->serial_lock);
44661 if (serial->rx_state == RX_IDLE &&
44662- serial->port.count > 0) {
44663+ atomic_read(&serial->port.count) > 0) {
44664 /* Setup and send a ctrl req read on
44665 * port i */
44666 if (!serial->rx_urb_filled[0]) {
44667@@ -3062,7 +3061,7 @@ static int hso_resume(struct usb_interface *iface)
44668 /* Start all serial ports */
44669 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
44670 if (serial_table[i] && (serial_table[i]->interface == iface)) {
44671- if (dev2ser(serial_table[i])->port.count) {
44672+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
44673 result =
44674 hso_start_serial_device(serial_table[i], GFP_NOIO);
44675 hso_kick_transmit(dev2ser(serial_table[i]));
44676diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
44677index a79e9d3..78cd4fa 100644
44678--- a/drivers/net/usb/sierra_net.c
44679+++ b/drivers/net/usb/sierra_net.c
44680@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
44681 /* atomic counter partially included in MAC address to make sure 2 devices
44682 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
44683 */
44684-static atomic_t iface_counter = ATOMIC_INIT(0);
44685+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
44686
44687 /*
44688 * SYNC Timer Delay definition used to set the expiry time
44689@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
44690 dev->net->netdev_ops = &sierra_net_device_ops;
44691
44692 /* change MAC addr to include, ifacenum, and to be unique */
44693- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
44694+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
44695 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
44696
44697 /* we will have to manufacture ethernet headers, prepare template */
44698diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
44699index 767f7af..8162b9d 100644
44700--- a/drivers/net/vxlan.c
44701+++ b/drivers/net/vxlan.c
44702@@ -1868,7 +1868,7 @@ nla_put_failure:
44703 return -EMSGSIZE;
44704 }
44705
44706-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
44707+static struct rtnl_link_ops vxlan_link_ops = {
44708 .kind = "vxlan",
44709 .maxtype = IFLA_VXLAN_MAX,
44710 .policy = vxlan_policy,
44711diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
44712index 0b60295..b8bfa5b 100644
44713--- a/drivers/net/wimax/i2400m/rx.c
44714+++ b/drivers/net/wimax/i2400m/rx.c
44715@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
44716 if (i2400m->rx_roq == NULL)
44717 goto error_roq_alloc;
44718
44719- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
44720+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
44721 GFP_KERNEL);
44722 if (rd == NULL) {
44723 result = -ENOMEM;
44724diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
44725index 34c8a33..3261fdc 100644
44726--- a/drivers/net/wireless/at76c50x-usb.c
44727+++ b/drivers/net/wireless/at76c50x-usb.c
44728@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
44729 }
44730
44731 /* Convert timeout from the DFU status to jiffies */
44732-static inline unsigned long at76_get_timeout(struct dfu_status *s)
44733+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
44734 {
44735 return msecs_to_jiffies((s->poll_timeout[2] << 16)
44736 | (s->poll_timeout[1] << 8)
44737diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c
44738index 2b3426b..05fa1e9 100644
44739--- a/drivers/net/wireless/ath/ath10k/core.c
44740+++ b/drivers/net/wireless/ath/ath10k/core.c
44741@@ -507,7 +507,7 @@ EXPORT_SYMBOL(ath10k_core_destroy);
44742
44743 int ath10k_core_register(struct ath10k *ar)
44744 {
44745- struct ath10k_htc_ops htc_ops;
44746+ ath10k_htc_ops_no_const htc_ops;
44747 struct bmi_target_info target_info;
44748 int status;
44749
44750diff --git a/drivers/net/wireless/ath/ath10k/hif.h b/drivers/net/wireless/ath/ath10k/hif.h
44751index 73a24d4..889099f 100644
44752--- a/drivers/net/wireless/ath/ath10k/hif.h
44753+++ b/drivers/net/wireless/ath/ath10k/hif.h
44754@@ -29,6 +29,7 @@ struct ath10k_hif_cb {
44755 struct sk_buff *wbuf,
44756 u8 pipe_id);
44757 };
44758+typedef struct ath10k_hif_cb __no_const ath10k_hif_cb_no_const;
44759
44760 struct ath10k_hif_ops {
44761 /* Send the head of a buffer to HIF for transmission to the target. */
44762diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
44763index 74363c9..fd80b19 100644
44764--- a/drivers/net/wireless/ath/ath10k/htc.c
44765+++ b/drivers/net/wireless/ath/ath10k/htc.c
44766@@ -963,7 +963,7 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
44767 struct ath10k_htc *ath10k_htc_create(struct ath10k *ar,
44768 struct ath10k_htc_ops *htc_ops)
44769 {
44770- struct ath10k_hif_cb htc_callbacks;
44771+ ath10k_hif_cb_no_const htc_callbacks;
44772 struct ath10k_htc_ep *ep = NULL;
44773 struct ath10k_htc *htc = NULL;
44774
44775diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
44776index fa45844..e29a8cf 100644
44777--- a/drivers/net/wireless/ath/ath10k/htc.h
44778+++ b/drivers/net/wireless/ath/ath10k/htc.h
44779@@ -272,6 +272,7 @@ enum ath10k_htc_ep_id {
44780 struct ath10k_htc_ops {
44781 void (*target_send_suspend_complete)(struct ath10k *ar);
44782 };
44783+typedef struct ath10k_htc_ops __no_const ath10k_htc_ops_no_const;
44784
44785 struct ath10k_htc_ep_ops {
44786 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
44787diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44788index 8d78253..bebbb68 100644
44789--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44790+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44791@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44792 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
44793 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
44794
44795- ACCESS_ONCE(ads->ds_link) = i->link;
44796- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
44797+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
44798+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
44799
44800 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
44801 ctl6 = SM(i->keytype, AR_EncrType);
44802@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44803
44804 if ((i->is_first || i->is_last) &&
44805 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
44806- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
44807+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
44808 | set11nTries(i->rates, 1)
44809 | set11nTries(i->rates, 2)
44810 | set11nTries(i->rates, 3)
44811 | (i->dur_update ? AR_DurUpdateEna : 0)
44812 | SM(0, AR_BurstDur);
44813
44814- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
44815+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
44816 | set11nRate(i->rates, 1)
44817 | set11nRate(i->rates, 2)
44818 | set11nRate(i->rates, 3);
44819 } else {
44820- ACCESS_ONCE(ads->ds_ctl2) = 0;
44821- ACCESS_ONCE(ads->ds_ctl3) = 0;
44822+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
44823+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
44824 }
44825
44826 if (!i->is_first) {
44827- ACCESS_ONCE(ads->ds_ctl0) = 0;
44828- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44829- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44830+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
44831+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44832+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44833 return;
44834 }
44835
44836@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44837 break;
44838 }
44839
44840- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44841+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44842 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44843 | SM(i->txpower, AR_XmitPower)
44844 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44845@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44846 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
44847 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
44848
44849- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44850- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44851+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44852+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44853
44854 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
44855 return;
44856
44857- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44858+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44859 | set11nPktDurRTSCTS(i->rates, 1);
44860
44861- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44862+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44863 | set11nPktDurRTSCTS(i->rates, 3);
44864
44865- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44866+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44867 | set11nRateFlags(i->rates, 1)
44868 | set11nRateFlags(i->rates, 2)
44869 | set11nRateFlags(i->rates, 3)
44870diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44871index 5163abd..3ada4c2 100644
44872--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44873+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44874@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44875 (i->qcu << AR_TxQcuNum_S) | desc_len;
44876
44877 checksum += val;
44878- ACCESS_ONCE(ads->info) = val;
44879+ ACCESS_ONCE_RW(ads->info) = val;
44880
44881 checksum += i->link;
44882- ACCESS_ONCE(ads->link) = i->link;
44883+ ACCESS_ONCE_RW(ads->link) = i->link;
44884
44885 checksum += i->buf_addr[0];
44886- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
44887+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
44888 checksum += i->buf_addr[1];
44889- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
44890+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
44891 checksum += i->buf_addr[2];
44892- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
44893+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
44894 checksum += i->buf_addr[3];
44895- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
44896+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
44897
44898 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
44899- ACCESS_ONCE(ads->ctl3) = val;
44900+ ACCESS_ONCE_RW(ads->ctl3) = val;
44901 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
44902- ACCESS_ONCE(ads->ctl5) = val;
44903+ ACCESS_ONCE_RW(ads->ctl5) = val;
44904 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
44905- ACCESS_ONCE(ads->ctl7) = val;
44906+ ACCESS_ONCE_RW(ads->ctl7) = val;
44907 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
44908- ACCESS_ONCE(ads->ctl9) = val;
44909+ ACCESS_ONCE_RW(ads->ctl9) = val;
44910
44911 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
44912- ACCESS_ONCE(ads->ctl10) = checksum;
44913+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
44914
44915 if (i->is_first || i->is_last) {
44916- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
44917+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
44918 | set11nTries(i->rates, 1)
44919 | set11nTries(i->rates, 2)
44920 | set11nTries(i->rates, 3)
44921 | (i->dur_update ? AR_DurUpdateEna : 0)
44922 | SM(0, AR_BurstDur);
44923
44924- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
44925+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
44926 | set11nRate(i->rates, 1)
44927 | set11nRate(i->rates, 2)
44928 | set11nRate(i->rates, 3);
44929 } else {
44930- ACCESS_ONCE(ads->ctl13) = 0;
44931- ACCESS_ONCE(ads->ctl14) = 0;
44932+ ACCESS_ONCE_RW(ads->ctl13) = 0;
44933+ ACCESS_ONCE_RW(ads->ctl14) = 0;
44934 }
44935
44936 ads->ctl20 = 0;
44937@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44938
44939 ctl17 = SM(i->keytype, AR_EncrType);
44940 if (!i->is_first) {
44941- ACCESS_ONCE(ads->ctl11) = 0;
44942- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44943- ACCESS_ONCE(ads->ctl15) = 0;
44944- ACCESS_ONCE(ads->ctl16) = 0;
44945- ACCESS_ONCE(ads->ctl17) = ctl17;
44946- ACCESS_ONCE(ads->ctl18) = 0;
44947- ACCESS_ONCE(ads->ctl19) = 0;
44948+ ACCESS_ONCE_RW(ads->ctl11) = 0;
44949+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44950+ ACCESS_ONCE_RW(ads->ctl15) = 0;
44951+ ACCESS_ONCE_RW(ads->ctl16) = 0;
44952+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44953+ ACCESS_ONCE_RW(ads->ctl18) = 0;
44954+ ACCESS_ONCE_RW(ads->ctl19) = 0;
44955 return;
44956 }
44957
44958- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
44959+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
44960 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44961 | SM(i->txpower, AR_XmitPower)
44962 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44963@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44964 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
44965 ctl12 |= SM(val, AR_PAPRDChainMask);
44966
44967- ACCESS_ONCE(ads->ctl12) = ctl12;
44968- ACCESS_ONCE(ads->ctl17) = ctl17;
44969+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
44970+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44971
44972- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
44973+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
44974 | set11nPktDurRTSCTS(i->rates, 1);
44975
44976- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
44977+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
44978 | set11nPktDurRTSCTS(i->rates, 3);
44979
44980- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
44981+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
44982 | set11nRateFlags(i->rates, 1)
44983 | set11nRateFlags(i->rates, 2)
44984 | set11nRateFlags(i->rates, 3)
44985 | SM(i->rtscts_rate, AR_RTSCTSRate);
44986
44987- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
44988+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
44989 }
44990
44991 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
44992diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
44993index cd74b3a..6a28d24 100644
44994--- a/drivers/net/wireless/ath/ath9k/hw.h
44995+++ b/drivers/net/wireless/ath/ath9k/hw.h
44996@@ -652,7 +652,7 @@ struct ath_hw_private_ops {
44997
44998 /* ANI */
44999 void (*ani_cache_ini_regs)(struct ath_hw *ah);
45000-};
45001+} __no_const;
45002
45003 /**
45004 * struct ath_spec_scan - parameters for Atheros spectral scan
45005@@ -721,7 +721,7 @@ struct ath_hw_ops {
45006 struct ath_spec_scan *param);
45007 void (*spectral_scan_trigger)(struct ath_hw *ah);
45008 void (*spectral_scan_wait)(struct ath_hw *ah);
45009-};
45010+} __no_const;
45011
45012 struct ath_nf_limits {
45013 s16 max;
45014diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
45015index 9581d07..84f6a76 100644
45016--- a/drivers/net/wireless/iwlegacy/3945-mac.c
45017+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
45018@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
45019 */
45020 if (il3945_mod_params.disable_hw_scan) {
45021 D_INFO("Disabling hw_scan\n");
45022- il3945_mac_ops.hw_scan = NULL;
45023+ pax_open_kernel();
45024+ *(void **)&il3945_mac_ops.hw_scan = NULL;
45025+ pax_close_kernel();
45026 }
45027
45028 D_INFO("*** LOAD DRIVER ***\n");
45029diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45030index d532948..e0d8bb1 100644
45031--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45032+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45033@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
45034 {
45035 struct iwl_priv *priv = file->private_data;
45036 char buf[64];
45037- int buf_size;
45038+ size_t buf_size;
45039 u32 offset, len;
45040
45041 memset(buf, 0, sizeof(buf));
45042@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
45043 struct iwl_priv *priv = file->private_data;
45044
45045 char buf[8];
45046- int buf_size;
45047+ size_t buf_size;
45048 u32 reset_flag;
45049
45050 memset(buf, 0, sizeof(buf));
45051@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
45052 {
45053 struct iwl_priv *priv = file->private_data;
45054 char buf[8];
45055- int buf_size;
45056+ size_t buf_size;
45057 int ht40;
45058
45059 memset(buf, 0, sizeof(buf));
45060@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
45061 {
45062 struct iwl_priv *priv = file->private_data;
45063 char buf[8];
45064- int buf_size;
45065+ size_t buf_size;
45066 int value;
45067
45068 memset(buf, 0, sizeof(buf));
45069@@ -698,10 +698,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
45070 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
45071 DEBUGFS_READ_FILE_OPS(current_sleep_command);
45072
45073-static const char *fmt_value = " %-30s %10u\n";
45074-static const char *fmt_hex = " %-30s 0x%02X\n";
45075-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
45076-static const char *fmt_header =
45077+static const char fmt_value[] = " %-30s %10u\n";
45078+static const char fmt_hex[] = " %-30s 0x%02X\n";
45079+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
45080+static const char fmt_header[] =
45081 "%-32s current cumulative delta max\n";
45082
45083 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
45084@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
45085 {
45086 struct iwl_priv *priv = file->private_data;
45087 char buf[8];
45088- int buf_size;
45089+ size_t buf_size;
45090 int clear;
45091
45092 memset(buf, 0, sizeof(buf));
45093@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
45094 {
45095 struct iwl_priv *priv = file->private_data;
45096 char buf[8];
45097- int buf_size;
45098+ size_t buf_size;
45099 int trace;
45100
45101 memset(buf, 0, sizeof(buf));
45102@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
45103 {
45104 struct iwl_priv *priv = file->private_data;
45105 char buf[8];
45106- int buf_size;
45107+ size_t buf_size;
45108 int missed;
45109
45110 memset(buf, 0, sizeof(buf));
45111@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
45112
45113 struct iwl_priv *priv = file->private_data;
45114 char buf[8];
45115- int buf_size;
45116+ size_t buf_size;
45117 int plcp;
45118
45119 memset(buf, 0, sizeof(buf));
45120@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
45121
45122 struct iwl_priv *priv = file->private_data;
45123 char buf[8];
45124- int buf_size;
45125+ size_t buf_size;
45126 int flush;
45127
45128 memset(buf, 0, sizeof(buf));
45129@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
45130
45131 struct iwl_priv *priv = file->private_data;
45132 char buf[8];
45133- int buf_size;
45134+ size_t buf_size;
45135 int rts;
45136
45137 if (!priv->cfg->ht_params)
45138@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
45139 {
45140 struct iwl_priv *priv = file->private_data;
45141 char buf[8];
45142- int buf_size;
45143+ size_t buf_size;
45144
45145 memset(buf, 0, sizeof(buf));
45146 buf_size = min(count, sizeof(buf) - 1);
45147@@ -2254,7 +2254,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
45148 struct iwl_priv *priv = file->private_data;
45149 u32 event_log_flag;
45150 char buf[8];
45151- int buf_size;
45152+ size_t buf_size;
45153
45154 /* check that the interface is up */
45155 if (!iwl_is_ready(priv))
45156@@ -2308,7 +2308,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
45157 struct iwl_priv *priv = file->private_data;
45158 char buf[8];
45159 u32 calib_disabled;
45160- int buf_size;
45161+ size_t buf_size;
45162
45163 memset(buf, 0, sizeof(buf));
45164 buf_size = min(count, sizeof(buf) - 1);
45165diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
45166index 1531a4f..21d2641 100644
45167--- a/drivers/net/wireless/iwlwifi/dvm/main.c
45168+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
45169@@ -1180,7 +1180,7 @@ static void iwl_option_config(struct iwl_priv *priv)
45170 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
45171 {
45172 struct iwl_nvm_data *data = priv->nvm_data;
45173- char *debug_msg;
45174+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
45175
45176 if (data->sku_cap_11n_enable &&
45177 !priv->cfg->ht_params) {
45178@@ -1194,7 +1194,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
45179 return -EINVAL;
45180 }
45181
45182- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
45183 IWL_DEBUG_INFO(priv, debug_msg,
45184 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
45185 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
45186diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
45187index 390e2f0..75cfbaf 100644
45188--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
45189+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
45190@@ -1350,7 +1350,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
45191 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
45192
45193 char buf[8];
45194- int buf_size;
45195+ size_t buf_size;
45196 u32 reset_flag;
45197
45198 memset(buf, 0, sizeof(buf));
45199@@ -1371,7 +1371,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
45200 {
45201 struct iwl_trans *trans = file->private_data;
45202 char buf[8];
45203- int buf_size;
45204+ size_t buf_size;
45205 int csr;
45206
45207 memset(buf, 0, sizeof(buf));
45208diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
45209index cb34c78..9fec0dc 100644
45210--- a/drivers/net/wireless/mac80211_hwsim.c
45211+++ b/drivers/net/wireless/mac80211_hwsim.c
45212@@ -2195,25 +2195,19 @@ static int __init init_mac80211_hwsim(void)
45213
45214 if (channels > 1) {
45215 hwsim_if_comb.num_different_channels = channels;
45216- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45217- mac80211_hwsim_ops.cancel_hw_scan =
45218- mac80211_hwsim_cancel_hw_scan;
45219- mac80211_hwsim_ops.sw_scan_start = NULL;
45220- mac80211_hwsim_ops.sw_scan_complete = NULL;
45221- mac80211_hwsim_ops.remain_on_channel =
45222- mac80211_hwsim_roc;
45223- mac80211_hwsim_ops.cancel_remain_on_channel =
45224- mac80211_hwsim_croc;
45225- mac80211_hwsim_ops.add_chanctx =
45226- mac80211_hwsim_add_chanctx;
45227- mac80211_hwsim_ops.remove_chanctx =
45228- mac80211_hwsim_remove_chanctx;
45229- mac80211_hwsim_ops.change_chanctx =
45230- mac80211_hwsim_change_chanctx;
45231- mac80211_hwsim_ops.assign_vif_chanctx =
45232- mac80211_hwsim_assign_vif_chanctx;
45233- mac80211_hwsim_ops.unassign_vif_chanctx =
45234- mac80211_hwsim_unassign_vif_chanctx;
45235+ pax_open_kernel();
45236+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45237+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
45238+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
45239+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
45240+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
45241+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
45242+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
45243+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
45244+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
45245+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
45246+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
45247+ pax_close_kernel();
45248 }
45249
45250 spin_lock_init(&hwsim_radio_lock);
45251diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
45252index 8169a85..7fa3b47 100644
45253--- a/drivers/net/wireless/rndis_wlan.c
45254+++ b/drivers/net/wireless/rndis_wlan.c
45255@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
45256
45257 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
45258
45259- if (rts_threshold < 0 || rts_threshold > 2347)
45260+ if (rts_threshold > 2347)
45261 rts_threshold = 2347;
45262
45263 tmp = cpu_to_le32(rts_threshold);
45264diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
45265index ee3fc57..ed5ddc9 100644
45266--- a/drivers/net/wireless/rt2x00/rt2x00.h
45267+++ b/drivers/net/wireless/rt2x00/rt2x00.h
45268@@ -386,7 +386,7 @@ struct rt2x00_intf {
45269 * for hardware which doesn't support hardware
45270 * sequence counting.
45271 */
45272- atomic_t seqno;
45273+ atomic_unchecked_t seqno;
45274 };
45275
45276 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
45277diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
45278index aa95c6c..a59dd67 100644
45279--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
45280+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
45281@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
45282 * sequence counter given by mac80211.
45283 */
45284 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
45285- seqno = atomic_add_return(0x10, &intf->seqno);
45286+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
45287 else
45288- seqno = atomic_read(&intf->seqno);
45289+ seqno = atomic_read_unchecked(&intf->seqno);
45290
45291 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
45292 hdr->seq_ctrl |= cpu_to_le16(seqno);
45293diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
45294index e2b3d9c..67a5184 100644
45295--- a/drivers/net/wireless/ti/wl1251/sdio.c
45296+++ b/drivers/net/wireless/ti/wl1251/sdio.c
45297@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
45298
45299 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
45300
45301- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45302- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45303+ pax_open_kernel();
45304+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45305+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45306+ pax_close_kernel();
45307
45308 wl1251_info("using dedicated interrupt line");
45309 } else {
45310- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45311- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45312+ pax_open_kernel();
45313+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45314+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45315+ pax_close_kernel();
45316
45317 wl1251_info("using SDIO interrupt");
45318 }
45319diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
45320index 1c627da..69f7d17 100644
45321--- a/drivers/net/wireless/ti/wl12xx/main.c
45322+++ b/drivers/net/wireless/ti/wl12xx/main.c
45323@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45324 sizeof(wl->conf.mem));
45325
45326 /* read data preparation is only needed by wl127x */
45327- wl->ops->prepare_read = wl127x_prepare_read;
45328+ pax_open_kernel();
45329+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45330+ pax_close_kernel();
45331
45332 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45333 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45334@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45335 sizeof(wl->conf.mem));
45336
45337 /* read data preparation is only needed by wl127x */
45338- wl->ops->prepare_read = wl127x_prepare_read;
45339+ pax_open_kernel();
45340+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45341+ pax_close_kernel();
45342
45343 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45344 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45345diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
45346index 7aa0eb8..5a9ef38 100644
45347--- a/drivers/net/wireless/ti/wl18xx/main.c
45348+++ b/drivers/net/wireless/ti/wl18xx/main.c
45349@@ -1730,8 +1730,10 @@ static int wl18xx_setup(struct wl1271 *wl)
45350 }
45351
45352 if (!checksum_param) {
45353- wl18xx_ops.set_rx_csum = NULL;
45354- wl18xx_ops.init_vif = NULL;
45355+ pax_open_kernel();
45356+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
45357+ *(void **)&wl18xx_ops.init_vif = NULL;
45358+ pax_close_kernel();
45359 }
45360
45361 /* Enable 11a Band only if we have 5G antennas */
45362diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
45363index 7ef0b4a..ff65c28 100644
45364--- a/drivers/net/wireless/zd1211rw/zd_usb.c
45365+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
45366@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
45367 {
45368 struct zd_usb *usb = urb->context;
45369 struct zd_usb_interrupt *intr = &usb->intr;
45370- int len;
45371+ unsigned int len;
45372 u16 int_num;
45373
45374 ZD_ASSERT(in_interrupt());
45375diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
45376index d93b2b6..ae50401 100644
45377--- a/drivers/oprofile/buffer_sync.c
45378+++ b/drivers/oprofile/buffer_sync.c
45379@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
45380 if (cookie == NO_COOKIE)
45381 offset = pc;
45382 if (cookie == INVALID_COOKIE) {
45383- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45384+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45385 offset = pc;
45386 }
45387 if (cookie != last_cookie) {
45388@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
45389 /* add userspace sample */
45390
45391 if (!mm) {
45392- atomic_inc(&oprofile_stats.sample_lost_no_mm);
45393+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
45394 return 0;
45395 }
45396
45397 cookie = lookup_dcookie(mm, s->eip, &offset);
45398
45399 if (cookie == INVALID_COOKIE) {
45400- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45401+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45402 return 0;
45403 }
45404
45405@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
45406 /* ignore backtraces if failed to add a sample */
45407 if (state == sb_bt_start) {
45408 state = sb_bt_ignore;
45409- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
45410+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
45411 }
45412 }
45413 release_mm(mm);
45414diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
45415index c0cc4e7..44d4e54 100644
45416--- a/drivers/oprofile/event_buffer.c
45417+++ b/drivers/oprofile/event_buffer.c
45418@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
45419 }
45420
45421 if (buffer_pos == buffer_size) {
45422- atomic_inc(&oprofile_stats.event_lost_overflow);
45423+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
45424 return;
45425 }
45426
45427diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
45428index ed2c3ec..deda85a 100644
45429--- a/drivers/oprofile/oprof.c
45430+++ b/drivers/oprofile/oprof.c
45431@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
45432 if (oprofile_ops.switch_events())
45433 return;
45434
45435- atomic_inc(&oprofile_stats.multiplex_counter);
45436+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
45437 start_switch_worker();
45438 }
45439
45440diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
45441index 84a208d..d61b0a1 100644
45442--- a/drivers/oprofile/oprofile_files.c
45443+++ b/drivers/oprofile/oprofile_files.c
45444@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
45445
45446 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
45447
45448-static ssize_t timeout_read(struct file *file, char __user *buf,
45449+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
45450 size_t count, loff_t *offset)
45451 {
45452 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
45453diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
45454index 917d28e..d62d981 100644
45455--- a/drivers/oprofile/oprofile_stats.c
45456+++ b/drivers/oprofile/oprofile_stats.c
45457@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
45458 cpu_buf->sample_invalid_eip = 0;
45459 }
45460
45461- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
45462- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
45463- atomic_set(&oprofile_stats.event_lost_overflow, 0);
45464- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
45465- atomic_set(&oprofile_stats.multiplex_counter, 0);
45466+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
45467+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
45468+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
45469+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
45470+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
45471 }
45472
45473
45474diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
45475index 38b6fc0..b5cbfce 100644
45476--- a/drivers/oprofile/oprofile_stats.h
45477+++ b/drivers/oprofile/oprofile_stats.h
45478@@ -13,11 +13,11 @@
45479 #include <linux/atomic.h>
45480
45481 struct oprofile_stat_struct {
45482- atomic_t sample_lost_no_mm;
45483- atomic_t sample_lost_no_mapping;
45484- atomic_t bt_lost_no_mapping;
45485- atomic_t event_lost_overflow;
45486- atomic_t multiplex_counter;
45487+ atomic_unchecked_t sample_lost_no_mm;
45488+ atomic_unchecked_t sample_lost_no_mapping;
45489+ atomic_unchecked_t bt_lost_no_mapping;
45490+ atomic_unchecked_t event_lost_overflow;
45491+ atomic_unchecked_t multiplex_counter;
45492 };
45493
45494 extern struct oprofile_stat_struct oprofile_stats;
45495diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
45496index 7c12d9c..558bf3bb 100644
45497--- a/drivers/oprofile/oprofilefs.c
45498+++ b/drivers/oprofile/oprofilefs.c
45499@@ -190,7 +190,7 @@ static const struct file_operations atomic_ro_fops = {
45500
45501
45502 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
45503- char const *name, atomic_t *val)
45504+ char const *name, atomic_unchecked_t *val)
45505 {
45506 return __oprofilefs_create_file(sb, root, name,
45507 &atomic_ro_fops, 0444, val);
45508diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
45509index 61be1d9..dec05d7 100644
45510--- a/drivers/oprofile/timer_int.c
45511+++ b/drivers/oprofile/timer_int.c
45512@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
45513 return NOTIFY_OK;
45514 }
45515
45516-static struct notifier_block __refdata oprofile_cpu_notifier = {
45517+static struct notifier_block oprofile_cpu_notifier = {
45518 .notifier_call = oprofile_cpu_notify,
45519 };
45520
45521diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
45522index 92ed045..62d39bd7 100644
45523--- a/drivers/parport/procfs.c
45524+++ b/drivers/parport/procfs.c
45525@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
45526
45527 *ppos += len;
45528
45529- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
45530+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
45531 }
45532
45533 #ifdef CONFIG_PARPORT_1284
45534@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
45535
45536 *ppos += len;
45537
45538- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
45539+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
45540 }
45541 #endif /* IEEE1284.3 support. */
45542
45543diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
45544index c35e8ad..fc33beb 100644
45545--- a/drivers/pci/hotplug/acpiphp_ibm.c
45546+++ b/drivers/pci/hotplug/acpiphp_ibm.c
45547@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
45548 goto init_cleanup;
45549 }
45550
45551- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45552+ pax_open_kernel();
45553+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45554+ pax_close_kernel();
45555 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
45556
45557 return retval;
45558diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
45559index a6a71c4..c91097b 100644
45560--- a/drivers/pci/hotplug/cpcihp_generic.c
45561+++ b/drivers/pci/hotplug/cpcihp_generic.c
45562@@ -73,7 +73,6 @@ static u16 port;
45563 static unsigned int enum_bit;
45564 static u8 enum_mask;
45565
45566-static struct cpci_hp_controller_ops generic_hpc_ops;
45567 static struct cpci_hp_controller generic_hpc;
45568
45569 static int __init validate_parameters(void)
45570@@ -139,6 +138,10 @@ static int query_enum(void)
45571 return ((value & enum_mask) == enum_mask);
45572 }
45573
45574+static struct cpci_hp_controller_ops generic_hpc_ops = {
45575+ .query_enum = query_enum,
45576+};
45577+
45578 static int __init cpcihp_generic_init(void)
45579 {
45580 int status;
45581@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
45582 pci_dev_put(dev);
45583
45584 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
45585- generic_hpc_ops.query_enum = query_enum;
45586 generic_hpc.ops = &generic_hpc_ops;
45587
45588 status = cpci_hp_register_controller(&generic_hpc);
45589diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
45590index 449b4bb..257e2e8 100644
45591--- a/drivers/pci/hotplug/cpcihp_zt5550.c
45592+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
45593@@ -59,7 +59,6 @@
45594 /* local variables */
45595 static bool debug;
45596 static bool poll;
45597-static struct cpci_hp_controller_ops zt5550_hpc_ops;
45598 static struct cpci_hp_controller zt5550_hpc;
45599
45600 /* Primary cPCI bus bridge device */
45601@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
45602 return 0;
45603 }
45604
45605+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
45606+ .query_enum = zt5550_hc_query_enum,
45607+};
45608+
45609 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
45610 {
45611 int status;
45612@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
45613 dbg("returned from zt5550_hc_config");
45614
45615 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
45616- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
45617 zt5550_hpc.ops = &zt5550_hpc_ops;
45618 if(!poll) {
45619 zt5550_hpc.irq = hc_dev->irq;
45620 zt5550_hpc.irq_flags = IRQF_SHARED;
45621 zt5550_hpc.dev_id = hc_dev;
45622
45623- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45624- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45625- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45626+ pax_open_kernel();
45627+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45628+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45629+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45630+ pax_open_kernel();
45631 } else {
45632 info("using ENUM# polling mode");
45633 }
45634diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
45635index 76ba8a1..20ca857 100644
45636--- a/drivers/pci/hotplug/cpqphp_nvram.c
45637+++ b/drivers/pci/hotplug/cpqphp_nvram.c
45638@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
45639
45640 void compaq_nvram_init (void __iomem *rom_start)
45641 {
45642+
45643+#ifndef CONFIG_PAX_KERNEXEC
45644 if (rom_start) {
45645 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
45646 }
45647+#endif
45648+
45649 dbg("int15 entry = %p\n", compaq_int15_entry_point);
45650
45651 /* initialize our int15 lock */
45652diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
45653index ec20f74..c1d961e 100644
45654--- a/drivers/pci/hotplug/pci_hotplug_core.c
45655+++ b/drivers/pci/hotplug/pci_hotplug_core.c
45656@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
45657 return -EINVAL;
45658 }
45659
45660- slot->ops->owner = owner;
45661- slot->ops->mod_name = mod_name;
45662+ pax_open_kernel();
45663+ *(struct module **)&slot->ops->owner = owner;
45664+ *(const char **)&slot->ops->mod_name = mod_name;
45665+ pax_close_kernel();
45666
45667 mutex_lock(&pci_hp_mutex);
45668 /*
45669diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
45670index 7d72c5e..edce02c 100644
45671--- a/drivers/pci/hotplug/pciehp_core.c
45672+++ b/drivers/pci/hotplug/pciehp_core.c
45673@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
45674 struct slot *slot = ctrl->slot;
45675 struct hotplug_slot *hotplug = NULL;
45676 struct hotplug_slot_info *info = NULL;
45677- struct hotplug_slot_ops *ops = NULL;
45678+ hotplug_slot_ops_no_const *ops = NULL;
45679 char name[SLOT_NAME_SIZE];
45680 int retval = -ENOMEM;
45681
45682diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
45683index c0dbe1f..94cf3d8 100644
45684--- a/drivers/pci/pci-sysfs.c
45685+++ b/drivers/pci/pci-sysfs.c
45686@@ -1073,7 +1073,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
45687 {
45688 /* allocate attribute structure, piggyback attribute name */
45689 int name_len = write_combine ? 13 : 10;
45690- struct bin_attribute *res_attr;
45691+ bin_attribute_no_const *res_attr;
45692 int retval;
45693
45694 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
45695@@ -1258,7 +1258,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
45696 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
45697 {
45698 int retval;
45699- struct bin_attribute *attr;
45700+ bin_attribute_no_const *attr;
45701
45702 /* If the device has VPD, try to expose it in sysfs. */
45703 if (dev->vpd) {
45704@@ -1305,7 +1305,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
45705 {
45706 int retval;
45707 int rom_size = 0;
45708- struct bin_attribute *attr;
45709+ bin_attribute_no_const *attr;
45710
45711 if (!sysfs_initialized)
45712 return -EACCES;
45713diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
45714index d1182c4..2a138ec 100644
45715--- a/drivers/pci/pci.h
45716+++ b/drivers/pci/pci.h
45717@@ -92,7 +92,7 @@ struct pci_vpd_ops {
45718 struct pci_vpd {
45719 unsigned int len;
45720 const struct pci_vpd_ops *ops;
45721- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
45722+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
45723 };
45724
45725 int pci_vpd_pci22_init(struct pci_dev *dev);
45726diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
45727index 403a443..034e050 100644
45728--- a/drivers/pci/pcie/aspm.c
45729+++ b/drivers/pci/pcie/aspm.c
45730@@ -27,9 +27,9 @@
45731 #define MODULE_PARAM_PREFIX "pcie_aspm."
45732
45733 /* Note: those are not register definitions */
45734-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
45735-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
45736-#define ASPM_STATE_L1 (4) /* L1 state */
45737+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
45738+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
45739+#define ASPM_STATE_L1 (4U) /* L1 state */
45740 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
45741 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
45742
45743diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
45744index 46ada5c..20da716 100644
45745--- a/drivers/pci/probe.c
45746+++ b/drivers/pci/probe.c
45747@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
45748 struct pci_bus_region region, inverted_region;
45749 bool bar_too_big = false, bar_disabled = false;
45750
45751- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
45752+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
45753
45754 /* No printks while decoding is disabled! */
45755 if (!dev->mmio_always_on) {
45756diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
45757index cdc7836..528635c 100644
45758--- a/drivers/pci/proc.c
45759+++ b/drivers/pci/proc.c
45760@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
45761 static int __init pci_proc_init(void)
45762 {
45763 struct pci_dev *dev = NULL;
45764+
45765+#ifdef CONFIG_GRKERNSEC_PROC_ADD
45766+#ifdef CONFIG_GRKERNSEC_PROC_USER
45767+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
45768+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45769+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
45770+#endif
45771+#else
45772 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
45773+#endif
45774 proc_create("devices", 0, proc_bus_pci_dir,
45775 &proc_bus_pci_dev_operations);
45776 proc_initialized = 1;
45777diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
45778index 3e5b4497..dcdfb70 100644
45779--- a/drivers/platform/x86/chromeos_laptop.c
45780+++ b/drivers/platform/x86/chromeos_laptop.c
45781@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
45782 return 0;
45783 }
45784
45785-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
45786+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
45787 {
45788 .ident = "Samsung Series 5 550 - Touchpad",
45789 .matches = {
45790diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
45791index 62f8030..c7f2a45 100644
45792--- a/drivers/platform/x86/msi-laptop.c
45793+++ b/drivers/platform/x86/msi-laptop.c
45794@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
45795
45796 if (!quirks->ec_read_only) {
45797 /* allow userland write sysfs file */
45798- dev_attr_bluetooth.store = store_bluetooth;
45799- dev_attr_wlan.store = store_wlan;
45800- dev_attr_threeg.store = store_threeg;
45801- dev_attr_bluetooth.attr.mode |= S_IWUSR;
45802- dev_attr_wlan.attr.mode |= S_IWUSR;
45803- dev_attr_threeg.attr.mode |= S_IWUSR;
45804+ pax_open_kernel();
45805+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
45806+ *(void **)&dev_attr_wlan.store = store_wlan;
45807+ *(void **)&dev_attr_threeg.store = store_threeg;
45808+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
45809+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
45810+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
45811+ pax_close_kernel();
45812 }
45813
45814 /* disable hardware control by fn key */
45815diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
45816index 3a1b6bf..b453930 100644
45817--- a/drivers/platform/x86/sony-laptop.c
45818+++ b/drivers/platform/x86/sony-laptop.c
45819@@ -2486,7 +2486,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
45820 }
45821
45822 /* High speed charging function */
45823-static struct device_attribute *hsc_handle;
45824+static device_attribute_no_const *hsc_handle;
45825
45826 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
45827 struct device_attribute *attr,
45828diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
45829index 54d31c0..3f896d3 100644
45830--- a/drivers/platform/x86/thinkpad_acpi.c
45831+++ b/drivers/platform/x86/thinkpad_acpi.c
45832@@ -2093,7 +2093,7 @@ static int hotkey_mask_get(void)
45833 return 0;
45834 }
45835
45836-void static hotkey_mask_warn_incomplete_mask(void)
45837+static void hotkey_mask_warn_incomplete_mask(void)
45838 {
45839 /* log only what the user can fix... */
45840 const u32 wantedmask = hotkey_driver_mask &
45841@@ -2324,11 +2324,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
45842 }
45843 }
45844
45845-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45846- struct tp_nvram_state *newn,
45847- const u32 event_mask)
45848-{
45849-
45850 #define TPACPI_COMPARE_KEY(__scancode, __member) \
45851 do { \
45852 if ((event_mask & (1 << __scancode)) && \
45853@@ -2342,36 +2337,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45854 tpacpi_hotkey_send_key(__scancode); \
45855 } while (0)
45856
45857- void issue_volchange(const unsigned int oldvol,
45858- const unsigned int newvol)
45859- {
45860- unsigned int i = oldvol;
45861+static void issue_volchange(const unsigned int oldvol,
45862+ const unsigned int newvol,
45863+ const u32 event_mask)
45864+{
45865+ unsigned int i = oldvol;
45866
45867- while (i > newvol) {
45868- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45869- i--;
45870- }
45871- while (i < newvol) {
45872- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45873- i++;
45874- }
45875+ while (i > newvol) {
45876+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45877+ i--;
45878 }
45879+ while (i < newvol) {
45880+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45881+ i++;
45882+ }
45883+}
45884
45885- void issue_brightnesschange(const unsigned int oldbrt,
45886- const unsigned int newbrt)
45887- {
45888- unsigned int i = oldbrt;
45889+static void issue_brightnesschange(const unsigned int oldbrt,
45890+ const unsigned int newbrt,
45891+ const u32 event_mask)
45892+{
45893+ unsigned int i = oldbrt;
45894
45895- while (i > newbrt) {
45896- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45897- i--;
45898- }
45899- while (i < newbrt) {
45900- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45901- i++;
45902- }
45903+ while (i > newbrt) {
45904+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45905+ i--;
45906+ }
45907+ while (i < newbrt) {
45908+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45909+ i++;
45910 }
45911+}
45912
45913+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45914+ struct tp_nvram_state *newn,
45915+ const u32 event_mask)
45916+{
45917 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
45918 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
45919 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
45920@@ -2405,7 +2406,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45921 oldn->volume_level != newn->volume_level) {
45922 /* recently muted, or repeated mute keypress, or
45923 * multiple presses ending in mute */
45924- issue_volchange(oldn->volume_level, newn->volume_level);
45925+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45926 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
45927 }
45928 } else {
45929@@ -2415,7 +2416,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45930 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45931 }
45932 if (oldn->volume_level != newn->volume_level) {
45933- issue_volchange(oldn->volume_level, newn->volume_level);
45934+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45935 } else if (oldn->volume_toggle != newn->volume_toggle) {
45936 /* repeated vol up/down keypress at end of scale ? */
45937 if (newn->volume_level == 0)
45938@@ -2428,7 +2429,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45939 /* handle brightness */
45940 if (oldn->brightness_level != newn->brightness_level) {
45941 issue_brightnesschange(oldn->brightness_level,
45942- newn->brightness_level);
45943+ newn->brightness_level,
45944+ event_mask);
45945 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
45946 /* repeated key presses that didn't change state */
45947 if (newn->brightness_level == 0)
45948@@ -2437,10 +2439,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45949 && !tp_features.bright_unkfw)
45950 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45951 }
45952+}
45953
45954 #undef TPACPI_COMPARE_KEY
45955 #undef TPACPI_MAY_SEND_KEY
45956-}
45957
45958 /*
45959 * Polling driver
45960diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
45961index 769d265..a3a05ca 100644
45962--- a/drivers/pnp/pnpbios/bioscalls.c
45963+++ b/drivers/pnp/pnpbios/bioscalls.c
45964@@ -58,7 +58,7 @@ do { \
45965 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
45966 } while(0)
45967
45968-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
45969+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
45970 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
45971
45972 /*
45973@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
45974
45975 cpu = get_cpu();
45976 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
45977+
45978+ pax_open_kernel();
45979 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
45980+ pax_close_kernel();
45981
45982 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
45983 spin_lock_irqsave(&pnp_bios_lock, flags);
45984@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
45985 :"memory");
45986 spin_unlock_irqrestore(&pnp_bios_lock, flags);
45987
45988+ pax_open_kernel();
45989 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
45990+ pax_close_kernel();
45991+
45992 put_cpu();
45993
45994 /* If we get here and this is set then the PnP BIOS faulted on us. */
45995@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
45996 return status;
45997 }
45998
45999-void pnpbios_calls_init(union pnp_bios_install_struct *header)
46000+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
46001 {
46002 int i;
46003
46004@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
46005 pnp_bios_callpoint.offset = header->fields.pm16offset;
46006 pnp_bios_callpoint.segment = PNP_CS16;
46007
46008+ pax_open_kernel();
46009+
46010 for_each_possible_cpu(i) {
46011 struct desc_struct *gdt = get_cpu_gdt_table(i);
46012 if (!gdt)
46013@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
46014 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
46015 (unsigned long)__va(header->fields.pm16dseg));
46016 }
46017+
46018+ pax_close_kernel();
46019 }
46020diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
46021index d95e101..67f0c3f 100644
46022--- a/drivers/pnp/resource.c
46023+++ b/drivers/pnp/resource.c
46024@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
46025 return 1;
46026
46027 /* check if the resource is valid */
46028- if (*irq < 0 || *irq > 15)
46029+ if (*irq > 15)
46030 return 0;
46031
46032 /* check if the resource is reserved */
46033@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
46034 return 1;
46035
46036 /* check if the resource is valid */
46037- if (*dma < 0 || *dma == 4 || *dma > 7)
46038+ if (*dma == 4 || *dma > 7)
46039 return 0;
46040
46041 /* check if the resource is reserved */
46042diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
46043index 0c52e2a..3421ab7 100644
46044--- a/drivers/power/pda_power.c
46045+++ b/drivers/power/pda_power.c
46046@@ -37,7 +37,11 @@ static int polling;
46047
46048 #if IS_ENABLED(CONFIG_USB_PHY)
46049 static struct usb_phy *transceiver;
46050-static struct notifier_block otg_nb;
46051+static int otg_handle_notification(struct notifier_block *nb,
46052+ unsigned long event, void *unused);
46053+static struct notifier_block otg_nb = {
46054+ .notifier_call = otg_handle_notification
46055+};
46056 #endif
46057
46058 static struct regulator *ac_draw;
46059@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
46060
46061 #if IS_ENABLED(CONFIG_USB_PHY)
46062 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
46063- otg_nb.notifier_call = otg_handle_notification;
46064 ret = usb_register_notifier(transceiver, &otg_nb);
46065 if (ret) {
46066 dev_err(dev, "failure to register otg notifier\n");
46067diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
46068index cc439fd..8fa30df 100644
46069--- a/drivers/power/power_supply.h
46070+++ b/drivers/power/power_supply.h
46071@@ -16,12 +16,12 @@ struct power_supply;
46072
46073 #ifdef CONFIG_SYSFS
46074
46075-extern void power_supply_init_attrs(struct device_type *dev_type);
46076+extern void power_supply_init_attrs(void);
46077 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
46078
46079 #else
46080
46081-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
46082+static inline void power_supply_init_attrs(void) {}
46083 #define power_supply_uevent NULL
46084
46085 #endif /* CONFIG_SYSFS */
46086diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
46087index 3b2d5df..3207114 100644
46088--- a/drivers/power/power_supply_core.c
46089+++ b/drivers/power/power_supply_core.c
46090@@ -24,7 +24,10 @@
46091 struct class *power_supply_class;
46092 EXPORT_SYMBOL_GPL(power_supply_class);
46093
46094-static struct device_type power_supply_dev_type;
46095+extern const struct attribute_group *power_supply_attr_groups[];
46096+static struct device_type power_supply_dev_type = {
46097+ .groups = power_supply_attr_groups,
46098+};
46099
46100 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
46101 struct power_supply *supply)
46102@@ -558,7 +561,7 @@ static int __init power_supply_class_init(void)
46103 return PTR_ERR(power_supply_class);
46104
46105 power_supply_class->dev_uevent = power_supply_uevent;
46106- power_supply_init_attrs(&power_supply_dev_type);
46107+ power_supply_init_attrs();
46108
46109 return 0;
46110 }
46111diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
46112index 29178f7..c65f324 100644
46113--- a/drivers/power/power_supply_sysfs.c
46114+++ b/drivers/power/power_supply_sysfs.c
46115@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
46116 .is_visible = power_supply_attr_is_visible,
46117 };
46118
46119-static const struct attribute_group *power_supply_attr_groups[] = {
46120+const struct attribute_group *power_supply_attr_groups[] = {
46121 &power_supply_attr_group,
46122 NULL,
46123 };
46124
46125-void power_supply_init_attrs(struct device_type *dev_type)
46126+void power_supply_init_attrs(void)
46127 {
46128 int i;
46129
46130- dev_type->groups = power_supply_attr_groups;
46131-
46132 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
46133 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
46134 }
46135diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
46136index 288c75a..065bc84 100644
46137--- a/drivers/regulator/core.c
46138+++ b/drivers/regulator/core.c
46139@@ -3544,7 +3544,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
46140 {
46141 const struct regulation_constraints *constraints = NULL;
46142 const struct regulator_init_data *init_data;
46143- static atomic_t regulator_no = ATOMIC_INIT(0);
46144+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
46145 struct regulator_dev *rdev;
46146 struct device *dev;
46147 int ret, i;
46148@@ -3614,7 +3614,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
46149 rdev->dev.of_node = config->of_node;
46150 rdev->dev.parent = dev;
46151 dev_set_name(&rdev->dev, "regulator.%d",
46152- atomic_inc_return(&regulator_no) - 1);
46153+ atomic_inc_return_unchecked(&regulator_no) - 1);
46154 ret = device_register(&rdev->dev);
46155 if (ret != 0) {
46156 put_device(&rdev->dev);
46157diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
46158index d428ef9..fdc0357 100644
46159--- a/drivers/regulator/max8660.c
46160+++ b/drivers/regulator/max8660.c
46161@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
46162 max8660->shadow_regs[MAX8660_OVER1] = 5;
46163 } else {
46164 /* Otherwise devices can be toggled via software */
46165- max8660_dcdc_ops.enable = max8660_dcdc_enable;
46166- max8660_dcdc_ops.disable = max8660_dcdc_disable;
46167+ pax_open_kernel();
46168+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
46169+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
46170+ pax_close_kernel();
46171 }
46172
46173 /*
46174diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
46175index 0c5195a..637a453d 100644
46176--- a/drivers/regulator/max8973-regulator.c
46177+++ b/drivers/regulator/max8973-regulator.c
46178@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
46179 if (!pdata || !pdata->enable_ext_control) {
46180 max->desc.enable_reg = MAX8973_VOUT;
46181 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
46182- max->ops.enable = regulator_enable_regmap;
46183- max->ops.disable = regulator_disable_regmap;
46184- max->ops.is_enabled = regulator_is_enabled_regmap;
46185+ pax_open_kernel();
46186+ *(void **)&max->ops.enable = regulator_enable_regmap;
46187+ *(void **)&max->ops.disable = regulator_disable_regmap;
46188+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
46189+ pax_close_kernel();
46190 }
46191
46192 if (pdata) {
46193diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
46194index 1037e07..e64dea1 100644
46195--- a/drivers/regulator/mc13892-regulator.c
46196+++ b/drivers/regulator/mc13892-regulator.c
46197@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
46198 }
46199 mc13xxx_unlock(mc13892);
46200
46201- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
46202+ pax_open_kernel();
46203+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
46204 = mc13892_vcam_set_mode;
46205- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
46206+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
46207 = mc13892_vcam_get_mode;
46208+ pax_close_kernel();
46209
46210 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
46211 ARRAY_SIZE(mc13892_regulators));
46212diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
46213index be06d71..264aee9 100644
46214--- a/drivers/rtc/rtc-cmos.c
46215+++ b/drivers/rtc/rtc-cmos.c
46216@@ -731,7 +731,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
46217 hpet_rtc_timer_init();
46218
46219 /* export at least the first block of NVRAM */
46220- nvram.size = address_space - NVRAM_OFFSET;
46221+ pax_open_kernel();
46222+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
46223+ pax_close_kernel();
46224 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
46225 if (retval < 0) {
46226 dev_dbg(dev, "can't create nvram file? %d\n", retval);
46227diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
46228index d049393..bb20be0 100644
46229--- a/drivers/rtc/rtc-dev.c
46230+++ b/drivers/rtc/rtc-dev.c
46231@@ -16,6 +16,7 @@
46232 #include <linux/module.h>
46233 #include <linux/rtc.h>
46234 #include <linux/sched.h>
46235+#include <linux/grsecurity.h>
46236 #include "rtc-core.h"
46237
46238 static dev_t rtc_devt;
46239@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
46240 if (copy_from_user(&tm, uarg, sizeof(tm)))
46241 return -EFAULT;
46242
46243+ gr_log_timechange();
46244+
46245 return rtc_set_time(rtc, &tm);
46246
46247 case RTC_PIE_ON:
46248diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
46249index ca18fd1..055e42d 100644
46250--- a/drivers/rtc/rtc-ds1307.c
46251+++ b/drivers/rtc/rtc-ds1307.c
46252@@ -107,7 +107,7 @@ struct ds1307 {
46253 u8 offset; /* register's offset */
46254 u8 regs[11];
46255 u16 nvram_offset;
46256- struct bin_attribute *nvram;
46257+ bin_attribute_no_const *nvram;
46258 enum ds_type type;
46259 unsigned long flags;
46260 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
46261diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
46262index fcb0329..d77b7f2 100644
46263--- a/drivers/rtc/rtc-m48t59.c
46264+++ b/drivers/rtc/rtc-m48t59.c
46265@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
46266 if (IS_ERR(m48t59->rtc))
46267 return PTR_ERR(m48t59->rtc);
46268
46269- m48t59_nvram_attr.size = pdata->offset;
46270+ pax_open_kernel();
46271+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
46272+ pax_close_kernel();
46273
46274 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
46275 if (ret)
46276diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
46277index e693af6..2e525b6 100644
46278--- a/drivers/scsi/bfa/bfa_fcpim.h
46279+++ b/drivers/scsi/bfa/bfa_fcpim.h
46280@@ -36,7 +36,7 @@ struct bfa_iotag_s {
46281
46282 struct bfa_itn_s {
46283 bfa_isr_func_t isr;
46284-};
46285+} __no_const;
46286
46287 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
46288 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
46289diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
46290index 90814fe..4384138 100644
46291--- a/drivers/scsi/bfa/bfa_ioc.h
46292+++ b/drivers/scsi/bfa/bfa_ioc.h
46293@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
46294 bfa_ioc_disable_cbfn_t disable_cbfn;
46295 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
46296 bfa_ioc_reset_cbfn_t reset_cbfn;
46297-};
46298+} __no_const;
46299
46300 /*
46301 * IOC event notification mechanism.
46302@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
46303 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
46304 enum bfi_ioc_state fwstate);
46305 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
46306-};
46307+} __no_const;
46308
46309 /*
46310 * Queue element to wait for room in request queue. FIFO order is
46311diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
46312index c9382d6..6619864 100644
46313--- a/drivers/scsi/fcoe/fcoe_sysfs.c
46314+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
46315@@ -33,8 +33,8 @@
46316 */
46317 #include "libfcoe.h"
46318
46319-static atomic_t ctlr_num;
46320-static atomic_t fcf_num;
46321+static atomic_unchecked_t ctlr_num;
46322+static atomic_unchecked_t fcf_num;
46323
46324 /*
46325 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
46326@@ -681,7 +681,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
46327 if (!ctlr)
46328 goto out;
46329
46330- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
46331+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
46332 ctlr->f = f;
46333 ctlr->mode = FIP_CONN_TYPE_FABRIC;
46334 INIT_LIST_HEAD(&ctlr->fcfs);
46335@@ -898,7 +898,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
46336 fcf->dev.parent = &ctlr->dev;
46337 fcf->dev.bus = &fcoe_bus_type;
46338 fcf->dev.type = &fcoe_fcf_device_type;
46339- fcf->id = atomic_inc_return(&fcf_num) - 1;
46340+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
46341 fcf->state = FCOE_FCF_STATE_UNKNOWN;
46342
46343 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
46344@@ -934,8 +934,8 @@ int __init fcoe_sysfs_setup(void)
46345 {
46346 int error;
46347
46348- atomic_set(&ctlr_num, 0);
46349- atomic_set(&fcf_num, 0);
46350+ atomic_set_unchecked(&ctlr_num, 0);
46351+ atomic_set_unchecked(&fcf_num, 0);
46352
46353 error = bus_register(&fcoe_bus_type);
46354 if (error)
46355diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
46356index df0c3c7..b00e1d0 100644
46357--- a/drivers/scsi/hosts.c
46358+++ b/drivers/scsi/hosts.c
46359@@ -42,7 +42,7 @@
46360 #include "scsi_logging.h"
46361
46362
46363-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46364+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46365
46366
46367 static void scsi_host_cls_release(struct device *dev)
46368@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
46369 * subtract one because we increment first then return, but we need to
46370 * know what the next host number was before increment
46371 */
46372- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
46373+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
46374 shost->dma_channel = 0xff;
46375
46376 /* These three are default values which can be overridden */
46377diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
46378index 7f4f790..b75b92a 100644
46379--- a/drivers/scsi/hpsa.c
46380+++ b/drivers/scsi/hpsa.c
46381@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
46382 unsigned long flags;
46383
46384 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
46385- return h->access.command_completed(h, q);
46386+ return h->access->command_completed(h, q);
46387
46388 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
46389 a = rq->head[rq->current_entry];
46390@@ -3422,7 +3422,7 @@ static void start_io(struct ctlr_info *h)
46391 while (!list_empty(&h->reqQ)) {
46392 c = list_entry(h->reqQ.next, struct CommandList, list);
46393 /* can't do anything if fifo is full */
46394- if ((h->access.fifo_full(h))) {
46395+ if ((h->access->fifo_full(h))) {
46396 dev_warn(&h->pdev->dev, "fifo full\n");
46397 break;
46398 }
46399@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
46400
46401 /* Tell the controller execute command */
46402 spin_unlock_irqrestore(&h->lock, flags);
46403- h->access.submit_command(h, c);
46404+ h->access->submit_command(h, c);
46405 spin_lock_irqsave(&h->lock, flags);
46406 }
46407 spin_unlock_irqrestore(&h->lock, flags);
46408@@ -3452,17 +3452,17 @@ static void start_io(struct ctlr_info *h)
46409
46410 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
46411 {
46412- return h->access.command_completed(h, q);
46413+ return h->access->command_completed(h, q);
46414 }
46415
46416 static inline bool interrupt_pending(struct ctlr_info *h)
46417 {
46418- return h->access.intr_pending(h);
46419+ return h->access->intr_pending(h);
46420 }
46421
46422 static inline long interrupt_not_for_us(struct ctlr_info *h)
46423 {
46424- return (h->access.intr_pending(h) == 0) ||
46425+ return (h->access->intr_pending(h) == 0) ||
46426 (h->interrupts_enabled == 0);
46427 }
46428
46429@@ -4364,7 +4364,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
46430 if (prod_index < 0)
46431 return -ENODEV;
46432 h->product_name = products[prod_index].product_name;
46433- h->access = *(products[prod_index].access);
46434+ h->access = products[prod_index].access;
46435
46436 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
46437 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
46438@@ -4646,7 +4646,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
46439
46440 assert_spin_locked(&lockup_detector_lock);
46441 remove_ctlr_from_lockup_detector_list(h);
46442- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46443+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46444 spin_lock_irqsave(&h->lock, flags);
46445 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
46446 spin_unlock_irqrestore(&h->lock, flags);
46447@@ -4823,7 +4823,7 @@ reinit_after_soft_reset:
46448 }
46449
46450 /* make sure the board interrupts are off */
46451- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46452+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46453
46454 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
46455 goto clean2;
46456@@ -4857,7 +4857,7 @@ reinit_after_soft_reset:
46457 * fake ones to scoop up any residual completions.
46458 */
46459 spin_lock_irqsave(&h->lock, flags);
46460- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46461+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46462 spin_unlock_irqrestore(&h->lock, flags);
46463 free_irqs(h);
46464 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
46465@@ -4876,9 +4876,9 @@ reinit_after_soft_reset:
46466 dev_info(&h->pdev->dev, "Board READY.\n");
46467 dev_info(&h->pdev->dev,
46468 "Waiting for stale completions to drain.\n");
46469- h->access.set_intr_mask(h, HPSA_INTR_ON);
46470+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46471 msleep(10000);
46472- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46473+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46474
46475 rc = controller_reset_failed(h->cfgtable);
46476 if (rc)
46477@@ -4899,7 +4899,7 @@ reinit_after_soft_reset:
46478 }
46479
46480 /* Turn the interrupts on so we can service requests */
46481- h->access.set_intr_mask(h, HPSA_INTR_ON);
46482+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46483
46484 hpsa_hba_inquiry(h);
46485 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
46486@@ -4954,7 +4954,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
46487 * To write all data in the battery backed cache to disks
46488 */
46489 hpsa_flush_cache(h);
46490- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46491+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46492 hpsa_free_irqs_and_disable_msix(h);
46493 }
46494
46495@@ -5122,7 +5122,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
46496 return;
46497 }
46498 /* Change the access methods to the performant access methods */
46499- h->access = SA5_performant_access;
46500+ h->access = &SA5_performant_access;
46501 h->transMethod = CFGTBL_Trans_Performant;
46502 }
46503
46504diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
46505index 9816479..c5d4e97 100644
46506--- a/drivers/scsi/hpsa.h
46507+++ b/drivers/scsi/hpsa.h
46508@@ -79,7 +79,7 @@ struct ctlr_info {
46509 unsigned int msix_vector;
46510 unsigned int msi_vector;
46511 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
46512- struct access_method access;
46513+ struct access_method *access;
46514
46515 /* queue and queue Info */
46516 struct list_head reqQ;
46517diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
46518index 5879929..32b241d 100644
46519--- a/drivers/scsi/libfc/fc_exch.c
46520+++ b/drivers/scsi/libfc/fc_exch.c
46521@@ -100,12 +100,12 @@ struct fc_exch_mgr {
46522 u16 pool_max_index;
46523
46524 struct {
46525- atomic_t no_free_exch;
46526- atomic_t no_free_exch_xid;
46527- atomic_t xid_not_found;
46528- atomic_t xid_busy;
46529- atomic_t seq_not_found;
46530- atomic_t non_bls_resp;
46531+ atomic_unchecked_t no_free_exch;
46532+ atomic_unchecked_t no_free_exch_xid;
46533+ atomic_unchecked_t xid_not_found;
46534+ atomic_unchecked_t xid_busy;
46535+ atomic_unchecked_t seq_not_found;
46536+ atomic_unchecked_t non_bls_resp;
46537 } stats;
46538 };
46539
46540@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
46541 /* allocate memory for exchange */
46542 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
46543 if (!ep) {
46544- atomic_inc(&mp->stats.no_free_exch);
46545+ atomic_inc_unchecked(&mp->stats.no_free_exch);
46546 goto out;
46547 }
46548 memset(ep, 0, sizeof(*ep));
46549@@ -797,7 +797,7 @@ out:
46550 return ep;
46551 err:
46552 spin_unlock_bh(&pool->lock);
46553- atomic_inc(&mp->stats.no_free_exch_xid);
46554+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
46555 mempool_free(ep, mp->ep_pool);
46556 return NULL;
46557 }
46558@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46559 xid = ntohs(fh->fh_ox_id); /* we originated exch */
46560 ep = fc_exch_find(mp, xid);
46561 if (!ep) {
46562- atomic_inc(&mp->stats.xid_not_found);
46563+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46564 reject = FC_RJT_OX_ID;
46565 goto out;
46566 }
46567@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46568 ep = fc_exch_find(mp, xid);
46569 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
46570 if (ep) {
46571- atomic_inc(&mp->stats.xid_busy);
46572+ atomic_inc_unchecked(&mp->stats.xid_busy);
46573 reject = FC_RJT_RX_ID;
46574 goto rel;
46575 }
46576@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46577 }
46578 xid = ep->xid; /* get our XID */
46579 } else if (!ep) {
46580- atomic_inc(&mp->stats.xid_not_found);
46581+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46582 reject = FC_RJT_RX_ID; /* XID not found */
46583 goto out;
46584 }
46585@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46586 } else {
46587 sp = &ep->seq;
46588 if (sp->id != fh->fh_seq_id) {
46589- atomic_inc(&mp->stats.seq_not_found);
46590+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46591 if (f_ctl & FC_FC_END_SEQ) {
46592 /*
46593 * Update sequence_id based on incoming last
46594@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46595
46596 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
46597 if (!ep) {
46598- atomic_inc(&mp->stats.xid_not_found);
46599+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46600 goto out;
46601 }
46602 if (ep->esb_stat & ESB_ST_COMPLETE) {
46603- atomic_inc(&mp->stats.xid_not_found);
46604+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46605 goto rel;
46606 }
46607 if (ep->rxid == FC_XID_UNKNOWN)
46608 ep->rxid = ntohs(fh->fh_rx_id);
46609 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
46610- atomic_inc(&mp->stats.xid_not_found);
46611+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46612 goto rel;
46613 }
46614 if (ep->did != ntoh24(fh->fh_s_id) &&
46615 ep->did != FC_FID_FLOGI) {
46616- atomic_inc(&mp->stats.xid_not_found);
46617+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46618 goto rel;
46619 }
46620 sof = fr_sof(fp);
46621@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46622 sp->ssb_stat |= SSB_ST_RESP;
46623 sp->id = fh->fh_seq_id;
46624 } else if (sp->id != fh->fh_seq_id) {
46625- atomic_inc(&mp->stats.seq_not_found);
46626+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46627 goto rel;
46628 }
46629
46630@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46631 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
46632
46633 if (!sp)
46634- atomic_inc(&mp->stats.xid_not_found);
46635+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46636 else
46637- atomic_inc(&mp->stats.non_bls_resp);
46638+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
46639
46640 fc_frame_free(fp);
46641 }
46642@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
46643
46644 list_for_each_entry(ema, &lport->ema_list, ema_list) {
46645 mp = ema->mp;
46646- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
46647+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
46648 st->fc_no_free_exch_xid +=
46649- atomic_read(&mp->stats.no_free_exch_xid);
46650- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
46651- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
46652- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
46653- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
46654+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
46655+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
46656+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
46657+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
46658+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
46659 }
46660 }
46661 EXPORT_SYMBOL(fc_exch_update_stats);
46662diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
46663index 161c98e..6d563b3 100644
46664--- a/drivers/scsi/libsas/sas_ata.c
46665+++ b/drivers/scsi/libsas/sas_ata.c
46666@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
46667 .postreset = ata_std_postreset,
46668 .error_handler = ata_std_error_handler,
46669 .post_internal_cmd = sas_ata_post_internal,
46670- .qc_defer = ata_std_qc_defer,
46671+ .qc_defer = ata_std_qc_defer,
46672 .qc_prep = ata_noop_qc_prep,
46673 .qc_issue = sas_ata_qc_issue,
46674 .qc_fill_rtf = sas_ata_qc_fill_rtf,
46675diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
46676index 93f222d..73e977b 100644
46677--- a/drivers/scsi/lpfc/lpfc.h
46678+++ b/drivers/scsi/lpfc/lpfc.h
46679@@ -431,7 +431,7 @@ struct lpfc_vport {
46680 struct dentry *debug_nodelist;
46681 struct dentry *vport_debugfs_root;
46682 struct lpfc_debugfs_trc *disc_trc;
46683- atomic_t disc_trc_cnt;
46684+ atomic_unchecked_t disc_trc_cnt;
46685 #endif
46686 uint8_t stat_data_enabled;
46687 uint8_t stat_data_blocked;
46688@@ -865,8 +865,8 @@ struct lpfc_hba {
46689 struct timer_list fabric_block_timer;
46690 unsigned long bit_flags;
46691 #define FABRIC_COMANDS_BLOCKED 0
46692- atomic_t num_rsrc_err;
46693- atomic_t num_cmd_success;
46694+ atomic_unchecked_t num_rsrc_err;
46695+ atomic_unchecked_t num_cmd_success;
46696 unsigned long last_rsrc_error_time;
46697 unsigned long last_ramp_down_time;
46698 unsigned long last_ramp_up_time;
46699@@ -902,7 +902,7 @@ struct lpfc_hba {
46700
46701 struct dentry *debug_slow_ring_trc;
46702 struct lpfc_debugfs_trc *slow_ring_trc;
46703- atomic_t slow_ring_trc_cnt;
46704+ atomic_unchecked_t slow_ring_trc_cnt;
46705 /* iDiag debugfs sub-directory */
46706 struct dentry *idiag_root;
46707 struct dentry *idiag_pci_cfg;
46708diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
46709index 60084e6..0e2e700 100644
46710--- a/drivers/scsi/lpfc/lpfc_debugfs.c
46711+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
46712@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
46713
46714 #include <linux/debugfs.h>
46715
46716-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46717+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46718 static unsigned long lpfc_debugfs_start_time = 0L;
46719
46720 /* iDiag */
46721@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
46722 lpfc_debugfs_enable = 0;
46723
46724 len = 0;
46725- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
46726+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
46727 (lpfc_debugfs_max_disc_trc - 1);
46728 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
46729 dtp = vport->disc_trc + i;
46730@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
46731 lpfc_debugfs_enable = 0;
46732
46733 len = 0;
46734- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
46735+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
46736 (lpfc_debugfs_max_slow_ring_trc - 1);
46737 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
46738 dtp = phba->slow_ring_trc + i;
46739@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
46740 !vport || !vport->disc_trc)
46741 return;
46742
46743- index = atomic_inc_return(&vport->disc_trc_cnt) &
46744+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
46745 (lpfc_debugfs_max_disc_trc - 1);
46746 dtp = vport->disc_trc + index;
46747 dtp->fmt = fmt;
46748 dtp->data1 = data1;
46749 dtp->data2 = data2;
46750 dtp->data3 = data3;
46751- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46752+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46753 dtp->jif = jiffies;
46754 #endif
46755 return;
46756@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
46757 !phba || !phba->slow_ring_trc)
46758 return;
46759
46760- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
46761+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
46762 (lpfc_debugfs_max_slow_ring_trc - 1);
46763 dtp = phba->slow_ring_trc + index;
46764 dtp->fmt = fmt;
46765 dtp->data1 = data1;
46766 dtp->data2 = data2;
46767 dtp->data3 = data3;
46768- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46769+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46770 dtp->jif = jiffies;
46771 #endif
46772 return;
46773@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46774 "slow_ring buffer\n");
46775 goto debug_failed;
46776 }
46777- atomic_set(&phba->slow_ring_trc_cnt, 0);
46778+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
46779 memset(phba->slow_ring_trc, 0,
46780 (sizeof(struct lpfc_debugfs_trc) *
46781 lpfc_debugfs_max_slow_ring_trc));
46782@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46783 "buffer\n");
46784 goto debug_failed;
46785 }
46786- atomic_set(&vport->disc_trc_cnt, 0);
46787+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
46788
46789 snprintf(name, sizeof(name), "discovery_trace");
46790 vport->debug_disc_trc =
46791diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
46792index e0b20fa..30c2c0d 100644
46793--- a/drivers/scsi/lpfc/lpfc_init.c
46794+++ b/drivers/scsi/lpfc/lpfc_init.c
46795@@ -10936,8 +10936,10 @@ lpfc_init(void)
46796 "misc_register returned with status %d", error);
46797
46798 if (lpfc_enable_npiv) {
46799- lpfc_transport_functions.vport_create = lpfc_vport_create;
46800- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46801+ pax_open_kernel();
46802+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
46803+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46804+ pax_close_kernel();
46805 }
46806 lpfc_transport_template =
46807 fc_attach_transport(&lpfc_transport_functions);
46808diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
46809index 243de1d..f40e3e5 100644
46810--- a/drivers/scsi/lpfc/lpfc_scsi.c
46811+++ b/drivers/scsi/lpfc/lpfc_scsi.c
46812@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
46813 uint32_t evt_posted;
46814
46815 spin_lock_irqsave(&phba->hbalock, flags);
46816- atomic_inc(&phba->num_rsrc_err);
46817+ atomic_inc_unchecked(&phba->num_rsrc_err);
46818 phba->last_rsrc_error_time = jiffies;
46819
46820 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
46821@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
46822 unsigned long flags;
46823 struct lpfc_hba *phba = vport->phba;
46824 uint32_t evt_posted;
46825- atomic_inc(&phba->num_cmd_success);
46826+ atomic_inc_unchecked(&phba->num_cmd_success);
46827
46828 if (vport->cfg_lun_queue_depth <= queue_depth)
46829 return;
46830@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46831 unsigned long num_rsrc_err, num_cmd_success;
46832 int i;
46833
46834- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
46835- num_cmd_success = atomic_read(&phba->num_cmd_success);
46836+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
46837+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
46838
46839 /*
46840 * The error and success command counters are global per
46841@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46842 }
46843 }
46844 lpfc_destroy_vport_work_array(phba, vports);
46845- atomic_set(&phba->num_rsrc_err, 0);
46846- atomic_set(&phba->num_cmd_success, 0);
46847+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46848+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46849 }
46850
46851 /**
46852@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
46853 }
46854 }
46855 lpfc_destroy_vport_work_array(phba, vports);
46856- atomic_set(&phba->num_rsrc_err, 0);
46857- atomic_set(&phba->num_cmd_success, 0);
46858+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46859+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46860 }
46861
46862 /**
46863diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
46864index 1eb7b028..b2a6080 100644
46865--- a/drivers/scsi/pmcraid.c
46866+++ b/drivers/scsi/pmcraid.c
46867@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
46868 res->scsi_dev = scsi_dev;
46869 scsi_dev->hostdata = res;
46870 res->change_detected = 0;
46871- atomic_set(&res->read_failures, 0);
46872- atomic_set(&res->write_failures, 0);
46873+ atomic_set_unchecked(&res->read_failures, 0);
46874+ atomic_set_unchecked(&res->write_failures, 0);
46875 rc = 0;
46876 }
46877 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
46878@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
46879
46880 /* If this was a SCSI read/write command keep count of errors */
46881 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
46882- atomic_inc(&res->read_failures);
46883+ atomic_inc_unchecked(&res->read_failures);
46884 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
46885- atomic_inc(&res->write_failures);
46886+ atomic_inc_unchecked(&res->write_failures);
46887
46888 if (!RES_IS_GSCSI(res->cfg_entry) &&
46889 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
46890@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
46891 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46892 * hrrq_id assigned here in queuecommand
46893 */
46894- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46895+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46896 pinstance->num_hrrq;
46897 cmd->cmd_done = pmcraid_io_done;
46898
46899@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
46900 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46901 * hrrq_id assigned here in queuecommand
46902 */
46903- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46904+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46905 pinstance->num_hrrq;
46906
46907 if (request_size) {
46908@@ -4483,7 +4483,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
46909
46910 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
46911 /* add resources only after host is added into system */
46912- if (!atomic_read(&pinstance->expose_resources))
46913+ if (!atomic_read_unchecked(&pinstance->expose_resources))
46914 return;
46915
46916 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
46917@@ -5310,8 +5310,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
46918 init_waitqueue_head(&pinstance->reset_wait_q);
46919
46920 atomic_set(&pinstance->outstanding_cmds, 0);
46921- atomic_set(&pinstance->last_message_id, 0);
46922- atomic_set(&pinstance->expose_resources, 0);
46923+ atomic_set_unchecked(&pinstance->last_message_id, 0);
46924+ atomic_set_unchecked(&pinstance->expose_resources, 0);
46925
46926 INIT_LIST_HEAD(&pinstance->free_res_q);
46927 INIT_LIST_HEAD(&pinstance->used_res_q);
46928@@ -6024,7 +6024,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
46929 /* Schedule worker thread to handle CCN and take care of adding and
46930 * removing devices to OS
46931 */
46932- atomic_set(&pinstance->expose_resources, 1);
46933+ atomic_set_unchecked(&pinstance->expose_resources, 1);
46934 schedule_work(&pinstance->worker_q);
46935 return rc;
46936
46937diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
46938index e1d150f..6c6df44 100644
46939--- a/drivers/scsi/pmcraid.h
46940+++ b/drivers/scsi/pmcraid.h
46941@@ -748,7 +748,7 @@ struct pmcraid_instance {
46942 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
46943
46944 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
46945- atomic_t last_message_id;
46946+ atomic_unchecked_t last_message_id;
46947
46948 /* configuration table */
46949 struct pmcraid_config_table *cfg_table;
46950@@ -777,7 +777,7 @@ struct pmcraid_instance {
46951 atomic_t outstanding_cmds;
46952
46953 /* should add/delete resources to mid-layer now ?*/
46954- atomic_t expose_resources;
46955+ atomic_unchecked_t expose_resources;
46956
46957
46958
46959@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
46960 struct pmcraid_config_table_entry_ext cfg_entry_ext;
46961 };
46962 struct scsi_device *scsi_dev; /* Link scsi_device structure */
46963- atomic_t read_failures; /* count of failed READ commands */
46964- atomic_t write_failures; /* count of failed WRITE commands */
46965+ atomic_unchecked_t read_failures; /* count of failed READ commands */
46966+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
46967
46968 /* To indicate add/delete/modify during CCN */
46969 u8 change_detected;
46970diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
46971index d7a99ae..801df70 100644
46972--- a/drivers/scsi/qla2xxx/qla_attr.c
46973+++ b/drivers/scsi/qla2xxx/qla_attr.c
46974@@ -2004,7 +2004,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
46975 return 0;
46976 }
46977
46978-struct fc_function_template qla2xxx_transport_functions = {
46979+fc_function_template_no_const qla2xxx_transport_functions = {
46980
46981 .show_host_node_name = 1,
46982 .show_host_port_name = 1,
46983@@ -2051,7 +2051,7 @@ struct fc_function_template qla2xxx_transport_functions = {
46984 .bsg_timeout = qla24xx_bsg_timeout,
46985 };
46986
46987-struct fc_function_template qla2xxx_transport_vport_functions = {
46988+fc_function_template_no_const qla2xxx_transport_vport_functions = {
46989
46990 .show_host_node_name = 1,
46991 .show_host_port_name = 1,
46992diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
46993index 2d98232..a84298e 100644
46994--- a/drivers/scsi/qla2xxx/qla_gbl.h
46995+++ b/drivers/scsi/qla2xxx/qla_gbl.h
46996@@ -528,8 +528,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
46997 struct device_attribute;
46998 extern struct device_attribute *qla2x00_host_attrs[];
46999 struct fc_function_template;
47000-extern struct fc_function_template qla2xxx_transport_functions;
47001-extern struct fc_function_template qla2xxx_transport_vport_functions;
47002+extern fc_function_template_no_const qla2xxx_transport_functions;
47003+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
47004 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
47005 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
47006 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
47007diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
47008index 3e21e9f..426ba79 100644
47009--- a/drivers/scsi/qla2xxx/qla_os.c
47010+++ b/drivers/scsi/qla2xxx/qla_os.c
47011@@ -1570,8 +1570,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
47012 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
47013 /* Ok, a 64bit DMA mask is applicable. */
47014 ha->flags.enable_64bit_addressing = 1;
47015- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
47016- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
47017+ pax_open_kernel();
47018+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
47019+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
47020+ pax_close_kernel();
47021 return;
47022 }
47023 }
47024diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
47025index ddf16a8..80f4dd0 100644
47026--- a/drivers/scsi/qla4xxx/ql4_def.h
47027+++ b/drivers/scsi/qla4xxx/ql4_def.h
47028@@ -291,7 +291,7 @@ struct ddb_entry {
47029 * (4000 only) */
47030 atomic_t relogin_timer; /* Max Time to wait for
47031 * relogin to complete */
47032- atomic_t relogin_retry_count; /* Num of times relogin has been
47033+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
47034 * retried */
47035 uint32_t default_time2wait; /* Default Min time between
47036 * relogins (+aens) */
47037diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
47038index b246b3c..897004d 100644
47039--- a/drivers/scsi/qla4xxx/ql4_os.c
47040+++ b/drivers/scsi/qla4xxx/ql4_os.c
47041@@ -2971,12 +2971,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
47042 */
47043 if (!iscsi_is_session_online(cls_sess)) {
47044 /* Reset retry relogin timer */
47045- atomic_inc(&ddb_entry->relogin_retry_count);
47046+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
47047 DEBUG2(ql4_printk(KERN_INFO, ha,
47048 "%s: index[%d] relogin timed out-retrying"
47049 " relogin (%d), retry (%d)\n", __func__,
47050 ddb_entry->fw_ddb_index,
47051- atomic_read(&ddb_entry->relogin_retry_count),
47052+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
47053 ddb_entry->default_time2wait + 4));
47054 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
47055 atomic_set(&ddb_entry->retry_relogin_timer,
47056@@ -5081,7 +5081,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
47057
47058 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
47059 atomic_set(&ddb_entry->relogin_timer, 0);
47060- atomic_set(&ddb_entry->relogin_retry_count, 0);
47061+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
47062 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
47063 ddb_entry->default_relogin_timeout =
47064 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
47065diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
47066index eaa808e..95f8841 100644
47067--- a/drivers/scsi/scsi.c
47068+++ b/drivers/scsi/scsi.c
47069@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
47070 unsigned long timeout;
47071 int rtn = 0;
47072
47073- atomic_inc(&cmd->device->iorequest_cnt);
47074+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
47075
47076 /* check if the device is still usable */
47077 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
47078diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
47079index 124392f..75eb43e 100644
47080--- a/drivers/scsi/scsi_lib.c
47081+++ b/drivers/scsi/scsi_lib.c
47082@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
47083 shost = sdev->host;
47084 scsi_init_cmd_errh(cmd);
47085 cmd->result = DID_NO_CONNECT << 16;
47086- atomic_inc(&cmd->device->iorequest_cnt);
47087+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
47088
47089 /*
47090 * SCSI request completion path will do scsi_device_unbusy(),
47091@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
47092
47093 INIT_LIST_HEAD(&cmd->eh_entry);
47094
47095- atomic_inc(&cmd->device->iodone_cnt);
47096+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
47097 if (cmd->result)
47098- atomic_inc(&cmd->device->ioerr_cnt);
47099+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
47100
47101 disposition = scsi_decide_disposition(cmd);
47102 if (disposition != SUCCESS &&
47103diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
47104index 7e50061..71db7a6 100644
47105--- a/drivers/scsi/scsi_sysfs.c
47106+++ b/drivers/scsi/scsi_sysfs.c
47107@@ -687,7 +687,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
47108 char *buf) \
47109 { \
47110 struct scsi_device *sdev = to_scsi_device(dev); \
47111- unsigned long long count = atomic_read(&sdev->field); \
47112+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
47113 return snprintf(buf, 20, "0x%llx\n", count); \
47114 } \
47115 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
47116diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
47117index 84a1fdf..693b0d6 100644
47118--- a/drivers/scsi/scsi_tgt_lib.c
47119+++ b/drivers/scsi/scsi_tgt_lib.c
47120@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
47121 int err;
47122
47123 dprintk("%lx %u\n", uaddr, len);
47124- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
47125+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
47126 if (err) {
47127 /*
47128 * TODO: need to fixup sg_tablesize, max_segment_size,
47129diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
47130index 4628fd5..a94a1c2 100644
47131--- a/drivers/scsi/scsi_transport_fc.c
47132+++ b/drivers/scsi/scsi_transport_fc.c
47133@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
47134 * Netlink Infrastructure
47135 */
47136
47137-static atomic_t fc_event_seq;
47138+static atomic_unchecked_t fc_event_seq;
47139
47140 /**
47141 * fc_get_event_number - Obtain the next sequential FC event number
47142@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
47143 u32
47144 fc_get_event_number(void)
47145 {
47146- return atomic_add_return(1, &fc_event_seq);
47147+ return atomic_add_return_unchecked(1, &fc_event_seq);
47148 }
47149 EXPORT_SYMBOL(fc_get_event_number);
47150
47151@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
47152 {
47153 int error;
47154
47155- atomic_set(&fc_event_seq, 0);
47156+ atomic_set_unchecked(&fc_event_seq, 0);
47157
47158 error = transport_class_register(&fc_host_class);
47159 if (error)
47160@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
47161 char *cp;
47162
47163 *val = simple_strtoul(buf, &cp, 0);
47164- if ((*cp && (*cp != '\n')) || (*val < 0))
47165+ if (*cp && (*cp != '\n'))
47166 return -EINVAL;
47167 /*
47168 * Check for overflow; dev_loss_tmo is u32
47169diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
47170index abf7c40..c3240ed 100644
47171--- a/drivers/scsi/scsi_transport_iscsi.c
47172+++ b/drivers/scsi/scsi_transport_iscsi.c
47173@@ -80,7 +80,7 @@ struct iscsi_internal {
47174 struct transport_container session_cont;
47175 };
47176
47177-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
47178+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
47179 static struct workqueue_struct *iscsi_eh_timer_workq;
47180
47181 static DEFINE_IDA(iscsi_sess_ida);
47182@@ -1738,7 +1738,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
47183 int err;
47184
47185 ihost = shost->shost_data;
47186- session->sid = atomic_add_return(1, &iscsi_session_nr);
47187+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
47188
47189 if (target_id == ISCSI_MAX_TARGET) {
47190 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
47191@@ -3956,7 +3956,7 @@ static __init int iscsi_transport_init(void)
47192 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
47193 ISCSI_TRANSPORT_VERSION);
47194
47195- atomic_set(&iscsi_session_nr, 0);
47196+ atomic_set_unchecked(&iscsi_session_nr, 0);
47197
47198 err = class_register(&iscsi_transport_class);
47199 if (err)
47200diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
47201index f379c7f..e8fc69c 100644
47202--- a/drivers/scsi/scsi_transport_srp.c
47203+++ b/drivers/scsi/scsi_transport_srp.c
47204@@ -33,7 +33,7 @@
47205 #include "scsi_transport_srp_internal.h"
47206
47207 struct srp_host_attrs {
47208- atomic_t next_port_id;
47209+ atomic_unchecked_t next_port_id;
47210 };
47211 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
47212
47213@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
47214 struct Scsi_Host *shost = dev_to_shost(dev);
47215 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
47216
47217- atomic_set(&srp_host->next_port_id, 0);
47218+ atomic_set_unchecked(&srp_host->next_port_id, 0);
47219 return 0;
47220 }
47221
47222@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
47223 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
47224 rport->roles = ids->roles;
47225
47226- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
47227+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
47228 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
47229
47230 transport_setup_device(&rport->dev);
47231diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
47232index 86fcf2c..26d8594 100644
47233--- a/drivers/scsi/sd.c
47234+++ b/drivers/scsi/sd.c
47235@@ -2938,7 +2938,7 @@ static int sd_probe(struct device *dev)
47236 sdkp->disk = gd;
47237 sdkp->index = index;
47238 atomic_set(&sdkp->openers, 0);
47239- atomic_set(&sdkp->device->ioerr_cnt, 0);
47240+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
47241
47242 if (!sdp->request_queue->rq_timeout) {
47243 if (sdp->type != TYPE_MOD)
47244diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
47245index df5e961..df6b97f 100644
47246--- a/drivers/scsi/sg.c
47247+++ b/drivers/scsi/sg.c
47248@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
47249 sdp->disk->disk_name,
47250 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
47251 NULL,
47252- (char *)arg);
47253+ (char __user *)arg);
47254 case BLKTRACESTART:
47255 return blk_trace_startstop(sdp->device->request_queue, 1);
47256 case BLKTRACESTOP:
47257diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
47258index 978dda2..cb19aa0 100644
47259--- a/drivers/spi/spi.c
47260+++ b/drivers/spi/spi.c
47261@@ -1631,7 +1631,7 @@ int spi_bus_unlock(struct spi_master *master)
47262 EXPORT_SYMBOL_GPL(spi_bus_unlock);
47263
47264 /* portable code must never pass more than 32 bytes */
47265-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
47266+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
47267
47268 static u8 *buf;
47269
47270diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
47271index ee3a57f..18368c1 100644
47272--- a/drivers/staging/android/timed_output.c
47273+++ b/drivers/staging/android/timed_output.c
47274@@ -25,7 +25,7 @@
47275 #include "timed_output.h"
47276
47277 static struct class *timed_output_class;
47278-static atomic_t device_count;
47279+static atomic_unchecked_t device_count;
47280
47281 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
47282 char *buf)
47283@@ -59,7 +59,7 @@ static int create_timed_output_class(void)
47284 timed_output_class = class_create(THIS_MODULE, "timed_output");
47285 if (IS_ERR(timed_output_class))
47286 return PTR_ERR(timed_output_class);
47287- atomic_set(&device_count, 0);
47288+ atomic_set_unchecked(&device_count, 0);
47289 }
47290
47291 return 0;
47292@@ -76,7 +76,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
47293 if (ret < 0)
47294 return ret;
47295
47296- tdev->index = atomic_inc_return(&device_count);
47297+ tdev->index = atomic_inc_return_unchecked(&device_count);
47298 tdev->dev = device_create(timed_output_class, NULL,
47299 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
47300 if (IS_ERR(tdev->dev))
47301diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
47302index 3675020..e80d92c 100644
47303--- a/drivers/staging/media/solo6x10/solo6x10-core.c
47304+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
47305@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
47306
47307 static int solo_sysfs_init(struct solo_dev *solo_dev)
47308 {
47309- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
47310+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
47311 struct device *dev = &solo_dev->dev;
47312 const char *driver;
47313 int i;
47314diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47315index 3335941..2b26186 100644
47316--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
47317+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47318@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
47319
47320 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
47321 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
47322- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
47323+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
47324 if (p2m_id < 0)
47325 p2m_id = -p2m_id;
47326 }
47327diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
47328index 6f91d2e..3f011d2 100644
47329--- a/drivers/staging/media/solo6x10/solo6x10.h
47330+++ b/drivers/staging/media/solo6x10/solo6x10.h
47331@@ -238,7 +238,7 @@ struct solo_dev {
47332
47333 /* P2M DMA Engine */
47334 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
47335- atomic_t p2m_count;
47336+ atomic_unchecked_t p2m_count;
47337 int p2m_jiffies;
47338 unsigned int p2m_timeouts;
47339
47340diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
47341index 34afc16..ffe44dd 100644
47342--- a/drivers/staging/octeon/ethernet-rx.c
47343+++ b/drivers/staging/octeon/ethernet-rx.c
47344@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47345 /* Increment RX stats for virtual ports */
47346 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
47347 #ifdef CONFIG_64BIT
47348- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
47349- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
47350+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
47351+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
47352 #else
47353- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
47354- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
47355+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
47356+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
47357 #endif
47358 }
47359 netif_receive_skb(skb);
47360@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47361 dev->name);
47362 */
47363 #ifdef CONFIG_64BIT
47364- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
47365+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47366 #else
47367- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
47368+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
47369 #endif
47370 dev_kfree_skb_irq(skb);
47371 }
47372diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
47373index c3a90e7..023619a 100644
47374--- a/drivers/staging/octeon/ethernet.c
47375+++ b/drivers/staging/octeon/ethernet.c
47376@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
47377 * since the RX tasklet also increments it.
47378 */
47379 #ifdef CONFIG_64BIT
47380- atomic64_add(rx_status.dropped_packets,
47381- (atomic64_t *)&priv->stats.rx_dropped);
47382+ atomic64_add_unchecked(rx_status.dropped_packets,
47383+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47384 #else
47385- atomic_add(rx_status.dropped_packets,
47386- (atomic_t *)&priv->stats.rx_dropped);
47387+ atomic_add_unchecked(rx_status.dropped_packets,
47388+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
47389 #endif
47390 }
47391
47392diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
47393index dc23395..cf7e9b1 100644
47394--- a/drivers/staging/rtl8712/rtl871x_io.h
47395+++ b/drivers/staging/rtl8712/rtl871x_io.h
47396@@ -108,7 +108,7 @@ struct _io_ops {
47397 u8 *pmem);
47398 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
47399 u8 *pmem);
47400-};
47401+} __no_const;
47402
47403 struct io_req {
47404 struct list_head list;
47405diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
47406index 1f5088b..0e59820 100644
47407--- a/drivers/staging/sbe-2t3e3/netdev.c
47408+++ b/drivers/staging/sbe-2t3e3/netdev.c
47409@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
47410 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
47411
47412 if (rlen)
47413- if (copy_to_user(data, &resp, rlen))
47414+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
47415 return -EFAULT;
47416
47417 return 0;
47418diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
47419index a863a98..d272795 100644
47420--- a/drivers/staging/usbip/vhci.h
47421+++ b/drivers/staging/usbip/vhci.h
47422@@ -83,7 +83,7 @@ struct vhci_hcd {
47423 unsigned resuming:1;
47424 unsigned long re_timeout;
47425
47426- atomic_t seqnum;
47427+ atomic_unchecked_t seqnum;
47428
47429 /*
47430 * NOTE:
47431diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
47432index d7974cb..d78076b 100644
47433--- a/drivers/staging/usbip/vhci_hcd.c
47434+++ b/drivers/staging/usbip/vhci_hcd.c
47435@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
47436
47437 spin_lock(&vdev->priv_lock);
47438
47439- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
47440+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47441 if (priv->seqnum == 0xffff)
47442 dev_info(&urb->dev->dev, "seqnum max\n");
47443
47444@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
47445 return -ENOMEM;
47446 }
47447
47448- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
47449+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47450 if (unlink->seqnum == 0xffff)
47451 pr_info("seqnum max\n");
47452
47453@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
47454 vdev->rhport = rhport;
47455 }
47456
47457- atomic_set(&vhci->seqnum, 0);
47458+ atomic_set_unchecked(&vhci->seqnum, 0);
47459 spin_lock_init(&vhci->lock);
47460
47461 hcd->power_budget = 0; /* no limit */
47462diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
47463index d07fcb5..358e1e1 100644
47464--- a/drivers/staging/usbip/vhci_rx.c
47465+++ b/drivers/staging/usbip/vhci_rx.c
47466@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
47467 if (!urb) {
47468 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
47469 pr_info("max seqnum %d\n",
47470- atomic_read(&the_controller->seqnum));
47471+ atomic_read_unchecked(&the_controller->seqnum));
47472 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
47473 return;
47474 }
47475diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
47476index 57a08c5..5b4bb7c 100644
47477--- a/drivers/staging/vt6655/hostap.c
47478+++ b/drivers/staging/vt6655/hostap.c
47479@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
47480 *
47481 */
47482
47483+static net_device_ops_no_const apdev_netdev_ops;
47484+
47485 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47486 {
47487 PSDevice apdev_priv;
47488 struct net_device *dev = pDevice->dev;
47489 int ret;
47490- const struct net_device_ops apdev_netdev_ops = {
47491- .ndo_start_xmit = pDevice->tx_80211,
47492- };
47493
47494 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47495
47496@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47497 *apdev_priv = *pDevice;
47498 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47499
47500+ /* only half broken now */
47501+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47502 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47503
47504 pDevice->apdev->type = ARPHRD_IEEE80211;
47505diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
47506index c699a30..b90a5fd 100644
47507--- a/drivers/staging/vt6656/hostap.c
47508+++ b/drivers/staging/vt6656/hostap.c
47509@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
47510 *
47511 */
47512
47513+static net_device_ops_no_const apdev_netdev_ops;
47514+
47515 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47516 {
47517 struct vnt_private *apdev_priv;
47518 struct net_device *dev = pDevice->dev;
47519 int ret;
47520- const struct net_device_ops apdev_netdev_ops = {
47521- .ndo_start_xmit = pDevice->tx_80211,
47522- };
47523
47524 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47525
47526@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47527 *apdev_priv = *pDevice;
47528 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47529
47530+ /* only half broken now */
47531+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47532 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47533
47534 pDevice->apdev->type = ARPHRD_IEEE80211;
47535diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
47536index d128ce2..fc1f9a1 100644
47537--- a/drivers/staging/zcache/tmem.h
47538+++ b/drivers/staging/zcache/tmem.h
47539@@ -225,7 +225,7 @@ struct tmem_pamops {
47540 bool (*is_remote)(void *);
47541 int (*replace_in_obj)(void *, struct tmem_obj *);
47542 #endif
47543-};
47544+} __no_const;
47545 extern void tmem_register_pamops(struct tmem_pamops *m);
47546
47547 /* memory allocation methods provided by the host implementation */
47548@@ -234,7 +234,7 @@ struct tmem_hostops {
47549 void (*obj_free)(struct tmem_obj *, struct tmem_pool *);
47550 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
47551 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
47552-};
47553+} __no_const;
47554 extern void tmem_register_hostops(struct tmem_hostops *m);
47555
47556 /* core tmem accessor functions */
47557diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
47558index e51b09a..5ebac31 100644
47559--- a/drivers/target/sbp/sbp_target.c
47560+++ b/drivers/target/sbp/sbp_target.c
47561@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
47562
47563 #define SESSION_MAINTENANCE_INTERVAL HZ
47564
47565-static atomic_t login_id = ATOMIC_INIT(0);
47566+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
47567
47568 static void session_maintenance_work(struct work_struct *);
47569 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
47570@@ -444,7 +444,7 @@ static void sbp_management_request_login(
47571 login->lun = se_lun;
47572 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
47573 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
47574- login->login_id = atomic_inc_return(&login_id);
47575+ login->login_id = atomic_inc_return_unchecked(&login_id);
47576
47577 login->tgt_agt = sbp_target_agent_register(login);
47578 if (IS_ERR(login->tgt_agt)) {
47579diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
47580index 8f4142f..b127f7d 100644
47581--- a/drivers/target/target_core_device.c
47582+++ b/drivers/target/target_core_device.c
47583@@ -1400,7 +1400,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
47584 spin_lock_init(&dev->se_port_lock);
47585 spin_lock_init(&dev->se_tmr_lock);
47586 spin_lock_init(&dev->qf_cmd_lock);
47587- atomic_set(&dev->dev_ordered_id, 0);
47588+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
47589 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
47590 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
47591 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
47592diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
47593index d8e49d7..6fcfdec 100644
47594--- a/drivers/target/target_core_transport.c
47595+++ b/drivers/target/target_core_transport.c
47596@@ -1080,7 +1080,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
47597 * Used to determine when ORDERED commands should go from
47598 * Dormant to Active status.
47599 */
47600- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
47601+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
47602 smp_mb__after_atomic_inc();
47603 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
47604 cmd->se_ordered_id, cmd->sam_task_attr,
47605diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
47606index 33f83fe..d80f8e1 100644
47607--- a/drivers/tty/cyclades.c
47608+++ b/drivers/tty/cyclades.c
47609@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
47610 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
47611 info->port.count);
47612 #endif
47613- info->port.count++;
47614+ atomic_inc(&info->port.count);
47615 #ifdef CY_DEBUG_COUNT
47616 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
47617- current->pid, info->port.count);
47618+ current->pid, atomic_read(&info->port.count));
47619 #endif
47620
47621 /*
47622@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
47623 for (j = 0; j < cy_card[i].nports; j++) {
47624 info = &cy_card[i].ports[j];
47625
47626- if (info->port.count) {
47627+ if (atomic_read(&info->port.count)) {
47628 /* XXX is the ldisc num worth this? */
47629 struct tty_struct *tty;
47630 struct tty_ldisc *ld;
47631diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
47632index eb255e8..f637a57 100644
47633--- a/drivers/tty/hvc/hvc_console.c
47634+++ b/drivers/tty/hvc/hvc_console.c
47635@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
47636
47637 spin_lock_irqsave(&hp->port.lock, flags);
47638 /* Check and then increment for fast path open. */
47639- if (hp->port.count++ > 0) {
47640+ if (atomic_inc_return(&hp->port.count) > 1) {
47641 spin_unlock_irqrestore(&hp->port.lock, flags);
47642 hvc_kick();
47643 return 0;
47644@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47645
47646 spin_lock_irqsave(&hp->port.lock, flags);
47647
47648- if (--hp->port.count == 0) {
47649+ if (atomic_dec_return(&hp->port.count) == 0) {
47650 spin_unlock_irqrestore(&hp->port.lock, flags);
47651 /* We are done with the tty pointer now. */
47652 tty_port_tty_set(&hp->port, NULL);
47653@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47654 */
47655 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
47656 } else {
47657- if (hp->port.count < 0)
47658+ if (atomic_read(&hp->port.count) < 0)
47659 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
47660- hp->vtermno, hp->port.count);
47661+ hp->vtermno, atomic_read(&hp->port.count));
47662 spin_unlock_irqrestore(&hp->port.lock, flags);
47663 }
47664 }
47665@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
47666 * open->hangup case this can be called after the final close so prevent
47667 * that from happening for now.
47668 */
47669- if (hp->port.count <= 0) {
47670+ if (atomic_read(&hp->port.count) <= 0) {
47671 spin_unlock_irqrestore(&hp->port.lock, flags);
47672 return;
47673 }
47674
47675- hp->port.count = 0;
47676+ atomic_set(&hp->port.count, 0);
47677 spin_unlock_irqrestore(&hp->port.lock, flags);
47678 tty_port_tty_set(&hp->port, NULL);
47679
47680@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
47681 return -EPIPE;
47682
47683 /* FIXME what's this (unprotected) check for? */
47684- if (hp->port.count <= 0)
47685+ if (atomic_read(&hp->port.count) <= 0)
47686 return -EIO;
47687
47688 spin_lock_irqsave(&hp->lock, flags);
47689diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
47690index 81e939e..95ead10 100644
47691--- a/drivers/tty/hvc/hvcs.c
47692+++ b/drivers/tty/hvc/hvcs.c
47693@@ -83,6 +83,7 @@
47694 #include <asm/hvcserver.h>
47695 #include <asm/uaccess.h>
47696 #include <asm/vio.h>
47697+#include <asm/local.h>
47698
47699 /*
47700 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
47701@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
47702
47703 spin_lock_irqsave(&hvcsd->lock, flags);
47704
47705- if (hvcsd->port.count > 0) {
47706+ if (atomic_read(&hvcsd->port.count) > 0) {
47707 spin_unlock_irqrestore(&hvcsd->lock, flags);
47708 printk(KERN_INFO "HVCS: vterm state unchanged. "
47709 "The hvcs device node is still in use.\n");
47710@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
47711 }
47712 }
47713
47714- hvcsd->port.count = 0;
47715+ atomic_set(&hvcsd->port.count, 0);
47716 hvcsd->port.tty = tty;
47717 tty->driver_data = hvcsd;
47718
47719@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
47720 unsigned long flags;
47721
47722 spin_lock_irqsave(&hvcsd->lock, flags);
47723- hvcsd->port.count++;
47724+ atomic_inc(&hvcsd->port.count);
47725 hvcsd->todo_mask |= HVCS_SCHED_READ;
47726 spin_unlock_irqrestore(&hvcsd->lock, flags);
47727
47728@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47729 hvcsd = tty->driver_data;
47730
47731 spin_lock_irqsave(&hvcsd->lock, flags);
47732- if (--hvcsd->port.count == 0) {
47733+ if (atomic_dec_and_test(&hvcsd->port.count)) {
47734
47735 vio_disable_interrupts(hvcsd->vdev);
47736
47737@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47738
47739 free_irq(irq, hvcsd);
47740 return;
47741- } else if (hvcsd->port.count < 0) {
47742+ } else if (atomic_read(&hvcsd->port.count) < 0) {
47743 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
47744 " is missmanaged.\n",
47745- hvcsd->vdev->unit_address, hvcsd->port.count);
47746+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
47747 }
47748
47749 spin_unlock_irqrestore(&hvcsd->lock, flags);
47750@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47751
47752 spin_lock_irqsave(&hvcsd->lock, flags);
47753 /* Preserve this so that we know how many kref refs to put */
47754- temp_open_count = hvcsd->port.count;
47755+ temp_open_count = atomic_read(&hvcsd->port.count);
47756
47757 /*
47758 * Don't kref put inside the spinlock because the destruction
47759@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47760 tty->driver_data = NULL;
47761 hvcsd->port.tty = NULL;
47762
47763- hvcsd->port.count = 0;
47764+ atomic_set(&hvcsd->port.count, 0);
47765
47766 /* This will drop any buffered data on the floor which is OK in a hangup
47767 * scenario. */
47768@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
47769 * the middle of a write operation? This is a crummy place to do this
47770 * but we want to keep it all in the spinlock.
47771 */
47772- if (hvcsd->port.count <= 0) {
47773+ if (atomic_read(&hvcsd->port.count) <= 0) {
47774 spin_unlock_irqrestore(&hvcsd->lock, flags);
47775 return -ENODEV;
47776 }
47777@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
47778 {
47779 struct hvcs_struct *hvcsd = tty->driver_data;
47780
47781- if (!hvcsd || hvcsd->port.count <= 0)
47782+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
47783 return 0;
47784
47785 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
47786diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
47787index 4190199..48f2920 100644
47788--- a/drivers/tty/hvc/hvsi.c
47789+++ b/drivers/tty/hvc/hvsi.c
47790@@ -85,7 +85,7 @@ struct hvsi_struct {
47791 int n_outbuf;
47792 uint32_t vtermno;
47793 uint32_t virq;
47794- atomic_t seqno; /* HVSI packet sequence number */
47795+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
47796 uint16_t mctrl;
47797 uint8_t state; /* HVSI protocol state */
47798 uint8_t flags;
47799@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
47800
47801 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
47802 packet.hdr.len = sizeof(struct hvsi_query_response);
47803- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47804+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47805 packet.verb = VSV_SEND_VERSION_NUMBER;
47806 packet.u.version = HVSI_VERSION;
47807 packet.query_seqno = query_seqno+1;
47808@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
47809
47810 packet.hdr.type = VS_QUERY_PACKET_HEADER;
47811 packet.hdr.len = sizeof(struct hvsi_query);
47812- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47813+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47814 packet.verb = verb;
47815
47816 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
47817@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
47818 int wrote;
47819
47820 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
47821- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47822+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47823 packet.hdr.len = sizeof(struct hvsi_control);
47824 packet.verb = VSV_SET_MODEM_CTL;
47825 packet.mask = HVSI_TSDTR;
47826@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
47827 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
47828
47829 packet.hdr.type = VS_DATA_PACKET_HEADER;
47830- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47831+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47832 packet.hdr.len = count + sizeof(struct hvsi_header);
47833 memcpy(&packet.data, buf, count);
47834
47835@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
47836 struct hvsi_control packet __ALIGNED__;
47837
47838 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
47839- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47840+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47841 packet.hdr.len = 6;
47842 packet.verb = VSV_CLOSE_PROTOCOL;
47843
47844diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
47845index ac27671..0f627ee 100644
47846--- a/drivers/tty/hvc/hvsi_lib.c
47847+++ b/drivers/tty/hvc/hvsi_lib.c
47848@@ -9,7 +9,7 @@
47849
47850 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
47851 {
47852- packet->seqno = atomic_inc_return(&pv->seqno);
47853+ packet->seqno = atomic_inc_return_unchecked(&pv->seqno);
47854
47855 /* Assumes that always succeeds, works in practice */
47856 return pv->put_chars(pv->termno, (char *)packet, packet->len);
47857@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
47858
47859 /* Reset state */
47860 pv->established = 0;
47861- atomic_set(&pv->seqno, 0);
47862+ atomic_set_unchecked(&pv->seqno, 0);
47863
47864 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
47865
47866@@ -265,7 +265,7 @@ int hvsilib_read_mctrl(struct hvsi_priv *pv)
47867 pv->mctrl_update = 0;
47868 q.hdr.type = VS_QUERY_PACKET_HEADER;
47869 q.hdr.len = sizeof(struct hvsi_query);
47870- q.hdr.seqno = atomic_inc_return(&pv->seqno);
47871+ q.hdr.seqno = atomic_inc_return_unchecked(&pv->seqno);
47872 q.verb = VSV_SEND_MODEM_CTL_STATUS;
47873 rc = hvsi_send_packet(pv, &q.hdr);
47874 if (rc <= 0) {
47875diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
47876index 8fd72ff..34a0bed 100644
47877--- a/drivers/tty/ipwireless/tty.c
47878+++ b/drivers/tty/ipwireless/tty.c
47879@@ -29,6 +29,7 @@
47880 #include <linux/tty_driver.h>
47881 #include <linux/tty_flip.h>
47882 #include <linux/uaccess.h>
47883+#include <asm/local.h>
47884
47885 #include "tty.h"
47886 #include "network.h"
47887@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47888 mutex_unlock(&tty->ipw_tty_mutex);
47889 return -ENODEV;
47890 }
47891- if (tty->port.count == 0)
47892+ if (atomic_read(&tty->port.count) == 0)
47893 tty->tx_bytes_queued = 0;
47894
47895- tty->port.count++;
47896+ atomic_inc(&tty->port.count);
47897
47898 tty->port.tty = linux_tty;
47899 linux_tty->driver_data = tty;
47900@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47901
47902 static void do_ipw_close(struct ipw_tty *tty)
47903 {
47904- tty->port.count--;
47905-
47906- if (tty->port.count == 0) {
47907+ if (atomic_dec_return(&tty->port.count) == 0) {
47908 struct tty_struct *linux_tty = tty->port.tty;
47909
47910 if (linux_tty != NULL) {
47911@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
47912 return;
47913
47914 mutex_lock(&tty->ipw_tty_mutex);
47915- if (tty->port.count == 0) {
47916+ if (atomic_read(&tty->port.count) == 0) {
47917 mutex_unlock(&tty->ipw_tty_mutex);
47918 return;
47919 }
47920@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
47921
47922 mutex_lock(&tty->ipw_tty_mutex);
47923
47924- if (!tty->port.count) {
47925+ if (!atomic_read(&tty->port.count)) {
47926 mutex_unlock(&tty->ipw_tty_mutex);
47927 return;
47928 }
47929@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
47930 return -ENODEV;
47931
47932 mutex_lock(&tty->ipw_tty_mutex);
47933- if (!tty->port.count) {
47934+ if (!atomic_read(&tty->port.count)) {
47935 mutex_unlock(&tty->ipw_tty_mutex);
47936 return -EINVAL;
47937 }
47938@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
47939 if (!tty)
47940 return -ENODEV;
47941
47942- if (!tty->port.count)
47943+ if (!atomic_read(&tty->port.count))
47944 return -EINVAL;
47945
47946 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
47947@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
47948 if (!tty)
47949 return 0;
47950
47951- if (!tty->port.count)
47952+ if (!atomic_read(&tty->port.count))
47953 return 0;
47954
47955 return tty->tx_bytes_queued;
47956@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
47957 if (!tty)
47958 return -ENODEV;
47959
47960- if (!tty->port.count)
47961+ if (!atomic_read(&tty->port.count))
47962 return -EINVAL;
47963
47964 return get_control_lines(tty);
47965@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
47966 if (!tty)
47967 return -ENODEV;
47968
47969- if (!tty->port.count)
47970+ if (!atomic_read(&tty->port.count))
47971 return -EINVAL;
47972
47973 return set_control_lines(tty, set, clear);
47974@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
47975 if (!tty)
47976 return -ENODEV;
47977
47978- if (!tty->port.count)
47979+ if (!atomic_read(&tty->port.count))
47980 return -EINVAL;
47981
47982 /* FIXME: Exactly how is the tty object locked here .. */
47983@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
47984 * are gone */
47985 mutex_lock(&ttyj->ipw_tty_mutex);
47986 }
47987- while (ttyj->port.count)
47988+ while (atomic_read(&ttyj->port.count))
47989 do_ipw_close(ttyj);
47990 ipwireless_disassociate_network_ttys(network,
47991 ttyj->channel_idx);
47992diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
47993index 1deaca4..c8582d4 100644
47994--- a/drivers/tty/moxa.c
47995+++ b/drivers/tty/moxa.c
47996@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
47997 }
47998
47999 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
48000- ch->port.count++;
48001+ atomic_inc(&ch->port.count);
48002 tty->driver_data = ch;
48003 tty_port_tty_set(&ch->port, tty);
48004 mutex_lock(&ch->port.mutex);
48005diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
48006index 6422390..49003ac8 100644
48007--- a/drivers/tty/n_gsm.c
48008+++ b/drivers/tty/n_gsm.c
48009@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
48010 spin_lock_init(&dlci->lock);
48011 mutex_init(&dlci->mutex);
48012 dlci->fifo = &dlci->_fifo;
48013- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
48014+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
48015 kfree(dlci);
48016 return NULL;
48017 }
48018@@ -2932,7 +2932,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
48019 struct gsm_dlci *dlci = tty->driver_data;
48020 struct tty_port *port = &dlci->port;
48021
48022- port->count++;
48023+ atomic_inc(&port->count);
48024 dlci_get(dlci);
48025 dlci_get(dlci->gsm->dlci[0]);
48026 mux_get(dlci->gsm);
48027diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
48028index 4bf0fc0..433bd58 100644
48029--- a/drivers/tty/n_tty.c
48030+++ b/drivers/tty/n_tty.c
48031@@ -2217,6 +2217,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
48032 {
48033 *ops = tty_ldisc_N_TTY;
48034 ops->owner = NULL;
48035- ops->refcount = ops->flags = 0;
48036+ atomic_set(&ops->refcount, 0);
48037+ ops->flags = 0;
48038 }
48039 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
48040diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
48041index abfd990..5ab5da9 100644
48042--- a/drivers/tty/pty.c
48043+++ b/drivers/tty/pty.c
48044@@ -796,8 +796,10 @@ static void __init unix98_pty_init(void)
48045 panic("Couldn't register Unix98 pts driver");
48046
48047 /* Now create the /dev/ptmx special device */
48048+ pax_open_kernel();
48049 tty_default_fops(&ptmx_fops);
48050- ptmx_fops.open = ptmx_open;
48051+ *(void **)&ptmx_fops.open = ptmx_open;
48052+ pax_close_kernel();
48053
48054 cdev_init(&ptmx_cdev, &ptmx_fops);
48055 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
48056diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
48057index 354564e..fe50d9a 100644
48058--- a/drivers/tty/rocket.c
48059+++ b/drivers/tty/rocket.c
48060@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
48061 tty->driver_data = info;
48062 tty_port_tty_set(port, tty);
48063
48064- if (port->count++ == 0) {
48065+ if (atomic_inc_return(&port->count) == 1) {
48066 atomic_inc(&rp_num_ports_open);
48067
48068 #ifdef ROCKET_DEBUG_OPEN
48069@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
48070 #endif
48071 }
48072 #ifdef ROCKET_DEBUG_OPEN
48073- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
48074+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
48075 #endif
48076
48077 /*
48078@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
48079 spin_unlock_irqrestore(&info->port.lock, flags);
48080 return;
48081 }
48082- if (info->port.count)
48083+ if (atomic_read(&info->port.count))
48084 atomic_dec(&rp_num_ports_open);
48085 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
48086 spin_unlock_irqrestore(&info->port.lock, flags);
48087diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
48088index e2520ab..034e20b 100644
48089--- a/drivers/tty/serial/ioc4_serial.c
48090+++ b/drivers/tty/serial/ioc4_serial.c
48091@@ -437,7 +437,7 @@ struct ioc4_soft {
48092 } is_intr_info[MAX_IOC4_INTR_ENTS];
48093
48094 /* Number of entries active in the above array */
48095- atomic_t is_num_intrs;
48096+ atomic_unchecked_t is_num_intrs;
48097 } is_intr_type[IOC4_NUM_INTR_TYPES];
48098
48099 /* is_ir_lock must be held while
48100@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
48101 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
48102 || (type == IOC4_OTHER_INTR_TYPE)));
48103
48104- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
48105+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
48106 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
48107
48108 /* Save off the lower level interrupt handler */
48109@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
48110
48111 soft = arg;
48112 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
48113- num_intrs = (int)atomic_read(
48114+ num_intrs = (int)atomic_read_unchecked(
48115 &soft->is_intr_type[intr_type].is_num_intrs);
48116
48117 this_mir = this_ir = pending_intrs(soft, intr_type);
48118diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
48119index 1002054..dd644a8 100644
48120--- a/drivers/tty/serial/kgdboc.c
48121+++ b/drivers/tty/serial/kgdboc.c
48122@@ -24,8 +24,9 @@
48123 #define MAX_CONFIG_LEN 40
48124
48125 static struct kgdb_io kgdboc_io_ops;
48126+static struct kgdb_io kgdboc_io_ops_console;
48127
48128-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
48129+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
48130 static int configured = -1;
48131
48132 static char config[MAX_CONFIG_LEN];
48133@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
48134 kgdboc_unregister_kbd();
48135 if (configured == 1)
48136 kgdb_unregister_io_module(&kgdboc_io_ops);
48137+ else if (configured == 2)
48138+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
48139 }
48140
48141 static int configure_kgdboc(void)
48142@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
48143 int err;
48144 char *cptr = config;
48145 struct console *cons;
48146+ int is_console = 0;
48147
48148 err = kgdboc_option_setup(config);
48149 if (err || !strlen(config) || isspace(config[0]))
48150 goto noconfig;
48151
48152 err = -ENODEV;
48153- kgdboc_io_ops.is_console = 0;
48154 kgdb_tty_driver = NULL;
48155
48156 kgdboc_use_kms = 0;
48157@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
48158 int idx;
48159 if (cons->device && cons->device(cons, &idx) == p &&
48160 idx == tty_line) {
48161- kgdboc_io_ops.is_console = 1;
48162+ is_console = 1;
48163 break;
48164 }
48165 cons = cons->next;
48166@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
48167 kgdb_tty_line = tty_line;
48168
48169 do_register:
48170- err = kgdb_register_io_module(&kgdboc_io_ops);
48171+ if (is_console) {
48172+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
48173+ configured = 2;
48174+ } else {
48175+ err = kgdb_register_io_module(&kgdboc_io_ops);
48176+ configured = 1;
48177+ }
48178 if (err)
48179 goto noconfig;
48180
48181@@ -205,8 +214,6 @@ do_register:
48182 if (err)
48183 goto nmi_con_failed;
48184
48185- configured = 1;
48186-
48187 return 0;
48188
48189 nmi_con_failed:
48190@@ -223,7 +230,7 @@ noconfig:
48191 static int __init init_kgdboc(void)
48192 {
48193 /* Already configured? */
48194- if (configured == 1)
48195+ if (configured >= 1)
48196 return 0;
48197
48198 return configure_kgdboc();
48199@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
48200 if (config[len - 1] == '\n')
48201 config[len - 1] = '\0';
48202
48203- if (configured == 1)
48204+ if (configured >= 1)
48205 cleanup_kgdboc();
48206
48207 /* Go and configure with the new params. */
48208@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
48209 .post_exception = kgdboc_post_exp_handler,
48210 };
48211
48212+static struct kgdb_io kgdboc_io_ops_console = {
48213+ .name = "kgdboc",
48214+ .read_char = kgdboc_get_char,
48215+ .write_char = kgdboc_put_char,
48216+ .pre_exception = kgdboc_pre_exp_handler,
48217+ .post_exception = kgdboc_post_exp_handler,
48218+ .is_console = 1
48219+};
48220+
48221 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
48222 /* This is only available if kgdboc is a built in for early debugging */
48223 static int __init kgdboc_early_init(char *opt)
48224diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
48225index 2c6cfb3..048274e 100644
48226--- a/drivers/tty/serial/msm_serial.c
48227+++ b/drivers/tty/serial/msm_serial.c
48228@@ -857,7 +857,7 @@ static struct uart_driver msm_uart_driver = {
48229 .cons = MSM_CONSOLE,
48230 };
48231
48232-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
48233+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
48234
48235 static int __init msm_serial_probe(struct platform_device *pdev)
48236 {
48237@@ -867,7 +867,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
48238 int irq;
48239
48240 if (pdev->id == -1)
48241- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
48242+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
48243
48244 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
48245 return -ENXIO;
48246diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
48247index 376079b..d8de7aa 100644
48248--- a/drivers/tty/serial/samsung.c
48249+++ b/drivers/tty/serial/samsung.c
48250@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
48251 }
48252 }
48253
48254+static int s3c64xx_serial_startup(struct uart_port *port);
48255 static int s3c24xx_serial_startup(struct uart_port *port)
48256 {
48257 struct s3c24xx_uart_port *ourport = to_ourport(port);
48258 int ret;
48259
48260+ /* Startup sequence is different for s3c64xx and higher SoC's */
48261+ if (s3c24xx_serial_has_interrupt_mask(port))
48262+ return s3c64xx_serial_startup(port);
48263+
48264 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
48265 port->mapbase, port->membase);
48266
48267@@ -1124,10 +1129,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
48268 /* setup info for port */
48269 port->dev = &platdev->dev;
48270
48271- /* Startup sequence is different for s3c64xx and higher SoC's */
48272- if (s3c24xx_serial_has_interrupt_mask(port))
48273- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
48274-
48275 port->uartclk = 1;
48276
48277 if (cfg->uart_flags & UPF_CONS_FLOW) {
48278diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
48279index 28cdd28..56f1d60 100644
48280--- a/drivers/tty/serial/serial_core.c
48281+++ b/drivers/tty/serial/serial_core.c
48282@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
48283 uart_flush_buffer(tty);
48284 uart_shutdown(tty, state);
48285 spin_lock_irqsave(&port->lock, flags);
48286- port->count = 0;
48287+ atomic_set(&port->count, 0);
48288 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
48289 spin_unlock_irqrestore(&port->lock, flags);
48290 tty_port_tty_set(port, NULL);
48291@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48292 goto end;
48293 }
48294
48295- port->count++;
48296+ atomic_inc(&port->count);
48297 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
48298 retval = -ENXIO;
48299 goto err_dec_count;
48300@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48301 /*
48302 * Make sure the device is in D0 state.
48303 */
48304- if (port->count == 1)
48305+ if (atomic_read(&port->count) == 1)
48306 uart_change_pm(state, UART_PM_STATE_ON);
48307
48308 /*
48309@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48310 end:
48311 return retval;
48312 err_dec_count:
48313- port->count--;
48314+ atomic_inc(&port->count);
48315 mutex_unlock(&port->mutex);
48316 goto end;
48317 }
48318diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
48319index 8eaf1ab..85c030d 100644
48320--- a/drivers/tty/synclink.c
48321+++ b/drivers/tty/synclink.c
48322@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48323
48324 if (debug_level >= DEBUG_LEVEL_INFO)
48325 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
48326- __FILE__,__LINE__, info->device_name, info->port.count);
48327+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48328
48329 if (tty_port_close_start(&info->port, tty, filp) == 0)
48330 goto cleanup;
48331@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48332 cleanup:
48333 if (debug_level >= DEBUG_LEVEL_INFO)
48334 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
48335- tty->driver->name, info->port.count);
48336+ tty->driver->name, atomic_read(&info->port.count));
48337
48338 } /* end of mgsl_close() */
48339
48340@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
48341
48342 mgsl_flush_buffer(tty);
48343 shutdown(info);
48344-
48345- info->port.count = 0;
48346+
48347+ atomic_set(&info->port.count, 0);
48348 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48349 info->port.tty = NULL;
48350
48351@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48352
48353 if (debug_level >= DEBUG_LEVEL_INFO)
48354 printk("%s(%d):block_til_ready before block on %s count=%d\n",
48355- __FILE__,__LINE__, tty->driver->name, port->count );
48356+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48357
48358 spin_lock_irqsave(&info->irq_spinlock, flags);
48359 if (!tty_hung_up_p(filp)) {
48360 extra_count = true;
48361- port->count--;
48362+ atomic_dec(&port->count);
48363 }
48364 spin_unlock_irqrestore(&info->irq_spinlock, flags);
48365 port->blocked_open++;
48366@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48367
48368 if (debug_level >= DEBUG_LEVEL_INFO)
48369 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
48370- __FILE__,__LINE__, tty->driver->name, port->count );
48371+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48372
48373 tty_unlock(tty);
48374 schedule();
48375@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48376
48377 /* FIXME: Racy on hangup during close wait */
48378 if (extra_count)
48379- port->count++;
48380+ atomic_inc(&port->count);
48381 port->blocked_open--;
48382
48383 if (debug_level >= DEBUG_LEVEL_INFO)
48384 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
48385- __FILE__,__LINE__, tty->driver->name, port->count );
48386+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48387
48388 if (!retval)
48389 port->flags |= ASYNC_NORMAL_ACTIVE;
48390@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48391
48392 if (debug_level >= DEBUG_LEVEL_INFO)
48393 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
48394- __FILE__,__LINE__,tty->driver->name, info->port.count);
48395+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48396
48397 /* If port is closing, signal caller to try again */
48398 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48399@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48400 spin_unlock_irqrestore(&info->netlock, flags);
48401 goto cleanup;
48402 }
48403- info->port.count++;
48404+ atomic_inc(&info->port.count);
48405 spin_unlock_irqrestore(&info->netlock, flags);
48406
48407- if (info->port.count == 1) {
48408+ if (atomic_read(&info->port.count) == 1) {
48409 /* 1st open on this device, init hardware */
48410 retval = startup(info);
48411 if (retval < 0)
48412@@ -3446,8 +3446,8 @@ cleanup:
48413 if (retval) {
48414 if (tty->count == 1)
48415 info->port.tty = NULL; /* tty layer will release tty struct */
48416- if(info->port.count)
48417- info->port.count--;
48418+ if (atomic_read(&info->port.count))
48419+ atomic_dec(&info->port.count);
48420 }
48421
48422 return retval;
48423@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48424 unsigned short new_crctype;
48425
48426 /* return error if TTY interface open */
48427- if (info->port.count)
48428+ if (atomic_read(&info->port.count))
48429 return -EBUSY;
48430
48431 switch (encoding)
48432@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
48433
48434 /* arbitrate between network and tty opens */
48435 spin_lock_irqsave(&info->netlock, flags);
48436- if (info->port.count != 0 || info->netcount != 0) {
48437+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48438 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48439 spin_unlock_irqrestore(&info->netlock, flags);
48440 return -EBUSY;
48441@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48442 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48443
48444 /* return error if TTY interface open */
48445- if (info->port.count)
48446+ if (atomic_read(&info->port.count))
48447 return -EBUSY;
48448
48449 if (cmd != SIOCWANDEV)
48450diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
48451index 1abf946..1ee34fc 100644
48452--- a/drivers/tty/synclink_gt.c
48453+++ b/drivers/tty/synclink_gt.c
48454@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48455 tty->driver_data = info;
48456 info->port.tty = tty;
48457
48458- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
48459+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
48460
48461 /* If port is closing, signal caller to try again */
48462 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48463@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48464 mutex_unlock(&info->port.mutex);
48465 goto cleanup;
48466 }
48467- info->port.count++;
48468+ atomic_inc(&info->port.count);
48469 spin_unlock_irqrestore(&info->netlock, flags);
48470
48471- if (info->port.count == 1) {
48472+ if (atomic_read(&info->port.count) == 1) {
48473 /* 1st open on this device, init hardware */
48474 retval = startup(info);
48475 if (retval < 0) {
48476@@ -715,8 +715,8 @@ cleanup:
48477 if (retval) {
48478 if (tty->count == 1)
48479 info->port.tty = NULL; /* tty layer will release tty struct */
48480- if(info->port.count)
48481- info->port.count--;
48482+ if(atomic_read(&info->port.count))
48483+ atomic_dec(&info->port.count);
48484 }
48485
48486 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
48487@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48488
48489 if (sanity_check(info, tty->name, "close"))
48490 return;
48491- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
48492+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
48493
48494 if (tty_port_close_start(&info->port, tty, filp) == 0)
48495 goto cleanup;
48496@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48497 tty_port_close_end(&info->port, tty);
48498 info->port.tty = NULL;
48499 cleanup:
48500- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
48501+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
48502 }
48503
48504 static void hangup(struct tty_struct *tty)
48505@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
48506 shutdown(info);
48507
48508 spin_lock_irqsave(&info->port.lock, flags);
48509- info->port.count = 0;
48510+ atomic_set(&info->port.count, 0);
48511 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48512 info->port.tty = NULL;
48513 spin_unlock_irqrestore(&info->port.lock, flags);
48514@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48515 unsigned short new_crctype;
48516
48517 /* return error if TTY interface open */
48518- if (info->port.count)
48519+ if (atomic_read(&info->port.count))
48520 return -EBUSY;
48521
48522 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
48523@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
48524
48525 /* arbitrate between network and tty opens */
48526 spin_lock_irqsave(&info->netlock, flags);
48527- if (info->port.count != 0 || info->netcount != 0) {
48528+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48529 DBGINFO(("%s hdlc_open busy\n", dev->name));
48530 spin_unlock_irqrestore(&info->netlock, flags);
48531 return -EBUSY;
48532@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48533 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
48534
48535 /* return error if TTY interface open */
48536- if (info->port.count)
48537+ if (atomic_read(&info->port.count))
48538 return -EBUSY;
48539
48540 if (cmd != SIOCWANDEV)
48541@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
48542 if (port == NULL)
48543 continue;
48544 spin_lock(&port->lock);
48545- if ((port->port.count || port->netcount) &&
48546+ if ((atomic_read(&port->port.count) || port->netcount) &&
48547 port->pending_bh && !port->bh_running &&
48548 !port->bh_requested) {
48549 DBGISR(("%s bh queued\n", port->device_name));
48550@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48551 spin_lock_irqsave(&info->lock, flags);
48552 if (!tty_hung_up_p(filp)) {
48553 extra_count = true;
48554- port->count--;
48555+ atomic_dec(&port->count);
48556 }
48557 spin_unlock_irqrestore(&info->lock, flags);
48558 port->blocked_open++;
48559@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48560 remove_wait_queue(&port->open_wait, &wait);
48561
48562 if (extra_count)
48563- port->count++;
48564+ atomic_inc(&port->count);
48565 port->blocked_open--;
48566
48567 if (!retval)
48568diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
48569index dc6e969..5dc8786 100644
48570--- a/drivers/tty/synclinkmp.c
48571+++ b/drivers/tty/synclinkmp.c
48572@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48573
48574 if (debug_level >= DEBUG_LEVEL_INFO)
48575 printk("%s(%d):%s open(), old ref count = %d\n",
48576- __FILE__,__LINE__,tty->driver->name, info->port.count);
48577+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48578
48579 /* If port is closing, signal caller to try again */
48580 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48581@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48582 spin_unlock_irqrestore(&info->netlock, flags);
48583 goto cleanup;
48584 }
48585- info->port.count++;
48586+ atomic_inc(&info->port.count);
48587 spin_unlock_irqrestore(&info->netlock, flags);
48588
48589- if (info->port.count == 1) {
48590+ if (atomic_read(&info->port.count) == 1) {
48591 /* 1st open on this device, init hardware */
48592 retval = startup(info);
48593 if (retval < 0)
48594@@ -796,8 +796,8 @@ cleanup:
48595 if (retval) {
48596 if (tty->count == 1)
48597 info->port.tty = NULL; /* tty layer will release tty struct */
48598- if(info->port.count)
48599- info->port.count--;
48600+ if(atomic_read(&info->port.count))
48601+ atomic_dec(&info->port.count);
48602 }
48603
48604 return retval;
48605@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48606
48607 if (debug_level >= DEBUG_LEVEL_INFO)
48608 printk("%s(%d):%s close() entry, count=%d\n",
48609- __FILE__,__LINE__, info->device_name, info->port.count);
48610+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48611
48612 if (tty_port_close_start(&info->port, tty, filp) == 0)
48613 goto cleanup;
48614@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48615 cleanup:
48616 if (debug_level >= DEBUG_LEVEL_INFO)
48617 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
48618- tty->driver->name, info->port.count);
48619+ tty->driver->name, atomic_read(&info->port.count));
48620 }
48621
48622 /* Called by tty_hangup() when a hangup is signaled.
48623@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
48624 shutdown(info);
48625
48626 spin_lock_irqsave(&info->port.lock, flags);
48627- info->port.count = 0;
48628+ atomic_set(&info->port.count, 0);
48629 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48630 info->port.tty = NULL;
48631 spin_unlock_irqrestore(&info->port.lock, flags);
48632@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48633 unsigned short new_crctype;
48634
48635 /* return error if TTY interface open */
48636- if (info->port.count)
48637+ if (atomic_read(&info->port.count))
48638 return -EBUSY;
48639
48640 switch (encoding)
48641@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
48642
48643 /* arbitrate between network and tty opens */
48644 spin_lock_irqsave(&info->netlock, flags);
48645- if (info->port.count != 0 || info->netcount != 0) {
48646+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48647 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48648 spin_unlock_irqrestore(&info->netlock, flags);
48649 return -EBUSY;
48650@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48651 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48652
48653 /* return error if TTY interface open */
48654- if (info->port.count)
48655+ if (atomic_read(&info->port.count))
48656 return -EBUSY;
48657
48658 if (cmd != SIOCWANDEV)
48659@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
48660 * do not request bottom half processing if the
48661 * device is not open in a normal mode.
48662 */
48663- if ( port && (port->port.count || port->netcount) &&
48664+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
48665 port->pending_bh && !port->bh_running &&
48666 !port->bh_requested ) {
48667 if ( debug_level >= DEBUG_LEVEL_ISR )
48668@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48669
48670 if (debug_level >= DEBUG_LEVEL_INFO)
48671 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
48672- __FILE__,__LINE__, tty->driver->name, port->count );
48673+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48674
48675 spin_lock_irqsave(&info->lock, flags);
48676 if (!tty_hung_up_p(filp)) {
48677 extra_count = true;
48678- port->count--;
48679+ atomic_dec(&port->count);
48680 }
48681 spin_unlock_irqrestore(&info->lock, flags);
48682 port->blocked_open++;
48683@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48684
48685 if (debug_level >= DEBUG_LEVEL_INFO)
48686 printk("%s(%d):%s block_til_ready() count=%d\n",
48687- __FILE__,__LINE__, tty->driver->name, port->count );
48688+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48689
48690 tty_unlock(tty);
48691 schedule();
48692@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48693 remove_wait_queue(&port->open_wait, &wait);
48694
48695 if (extra_count)
48696- port->count++;
48697+ atomic_inc(&port->count);
48698 port->blocked_open--;
48699
48700 if (debug_level >= DEBUG_LEVEL_INFO)
48701 printk("%s(%d):%s block_til_ready() after, count=%d\n",
48702- __FILE__,__LINE__, tty->driver->name, port->count );
48703+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48704
48705 if (!retval)
48706 port->flags |= ASYNC_NORMAL_ACTIVE;
48707diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
48708index d5cc3ac..3263411 100644
48709--- a/drivers/tty/sysrq.c
48710+++ b/drivers/tty/sysrq.c
48711@@ -1033,7 +1033,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
48712 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
48713 size_t count, loff_t *ppos)
48714 {
48715- if (count) {
48716+ if (count && capable(CAP_SYS_ADMIN)) {
48717 char c;
48718
48719 if (get_user(c, buf))
48720diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
48721index 366af83..6db51c3 100644
48722--- a/drivers/tty/tty_io.c
48723+++ b/drivers/tty/tty_io.c
48724@@ -3467,7 +3467,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
48725
48726 void tty_default_fops(struct file_operations *fops)
48727 {
48728- *fops = tty_fops;
48729+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
48730 }
48731
48732 /*
48733diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
48734index 1afe192..73d2c20 100644
48735--- a/drivers/tty/tty_ldisc.c
48736+++ b/drivers/tty/tty_ldisc.c
48737@@ -66,7 +66,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
48738 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48739 tty_ldiscs[disc] = new_ldisc;
48740 new_ldisc->num = disc;
48741- new_ldisc->refcount = 0;
48742+ atomic_set(&new_ldisc->refcount, 0);
48743 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48744
48745 return ret;
48746@@ -94,7 +94,7 @@ int tty_unregister_ldisc(int disc)
48747 return -EINVAL;
48748
48749 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48750- if (tty_ldiscs[disc]->refcount)
48751+ if (atomic_read(&tty_ldiscs[disc]->refcount))
48752 ret = -EBUSY;
48753 else
48754 tty_ldiscs[disc] = NULL;
48755@@ -115,7 +115,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
48756 if (ldops) {
48757 ret = ERR_PTR(-EAGAIN);
48758 if (try_module_get(ldops->owner)) {
48759- ldops->refcount++;
48760+ atomic_inc(&ldops->refcount);
48761 ret = ldops;
48762 }
48763 }
48764@@ -128,7 +128,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
48765 unsigned long flags;
48766
48767 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48768- ldops->refcount--;
48769+ atomic_dec(&ldops->refcount);
48770 module_put(ldops->owner);
48771 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48772 }
48773@@ -196,7 +196,7 @@ static inline void tty_ldisc_put(struct tty_ldisc *ld)
48774 /* unreleased reader reference(s) will cause this WARN */
48775 WARN_ON(!atomic_dec_and_test(&ld->users));
48776
48777- ld->ops->refcount--;
48778+ atomic_dec(&ld->ops->refcount);
48779 module_put(ld->ops->owner);
48780 kfree(ld);
48781 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48782diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
48783index f597e88..b7f68ed 100644
48784--- a/drivers/tty/tty_port.c
48785+++ b/drivers/tty/tty_port.c
48786@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
48787 unsigned long flags;
48788
48789 spin_lock_irqsave(&port->lock, flags);
48790- port->count = 0;
48791+ atomic_set(&port->count, 0);
48792 port->flags &= ~ASYNC_NORMAL_ACTIVE;
48793 tty = port->tty;
48794 if (tty)
48795@@ -390,7 +390,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48796 /* The port lock protects the port counts */
48797 spin_lock_irqsave(&port->lock, flags);
48798 if (!tty_hung_up_p(filp))
48799- port->count--;
48800+ atomic_dec(&port->count);
48801 port->blocked_open++;
48802 spin_unlock_irqrestore(&port->lock, flags);
48803
48804@@ -432,7 +432,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48805 we must not mess that up further */
48806 spin_lock_irqsave(&port->lock, flags);
48807 if (!tty_hung_up_p(filp))
48808- port->count++;
48809+ atomic_inc(&port->count);
48810 port->blocked_open--;
48811 if (retval == 0)
48812 port->flags |= ASYNC_NORMAL_ACTIVE;
48813@@ -466,19 +466,19 @@ int tty_port_close_start(struct tty_port *port,
48814 return 0;
48815 }
48816
48817- if (tty->count == 1 && port->count != 1) {
48818+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
48819 printk(KERN_WARNING
48820 "tty_port_close_start: tty->count = 1 port count = %d.\n",
48821- port->count);
48822- port->count = 1;
48823+ atomic_read(&port->count));
48824+ atomic_set(&port->count, 1);
48825 }
48826- if (--port->count < 0) {
48827+ if (atomic_dec_return(&port->count) < 0) {
48828 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
48829- port->count);
48830- port->count = 0;
48831+ atomic_read(&port->count));
48832+ atomic_set(&port->count, 0);
48833 }
48834
48835- if (port->count) {
48836+ if (atomic_read(&port->count)) {
48837 spin_unlock_irqrestore(&port->lock, flags);
48838 if (port->ops->drop)
48839 port->ops->drop(port);
48840@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
48841 {
48842 spin_lock_irq(&port->lock);
48843 if (!tty_hung_up_p(filp))
48844- ++port->count;
48845+ atomic_inc(&port->count);
48846 spin_unlock_irq(&port->lock);
48847 tty_port_tty_set(port, tty);
48848
48849diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
48850index a9af1b9a..1e08e7f 100644
48851--- a/drivers/tty/vt/keyboard.c
48852+++ b/drivers/tty/vt/keyboard.c
48853@@ -647,6 +647,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
48854 kbd->kbdmode == VC_OFF) &&
48855 value != KVAL(K_SAK))
48856 return; /* SAK is allowed even in raw mode */
48857+
48858+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48859+ {
48860+ void *func = fn_handler[value];
48861+ if (func == fn_show_state || func == fn_show_ptregs ||
48862+ func == fn_show_mem)
48863+ return;
48864+ }
48865+#endif
48866+
48867 fn_handler[value](vc);
48868 }
48869
48870@@ -1795,9 +1805,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48871 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
48872 return -EFAULT;
48873
48874- if (!capable(CAP_SYS_TTY_CONFIG))
48875- perm = 0;
48876-
48877 switch (cmd) {
48878 case KDGKBENT:
48879 /* Ensure another thread doesn't free it under us */
48880@@ -1812,6 +1819,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48881 spin_unlock_irqrestore(&kbd_event_lock, flags);
48882 return put_user(val, &user_kbe->kb_value);
48883 case KDSKBENT:
48884+ if (!capable(CAP_SYS_TTY_CONFIG))
48885+ perm = 0;
48886+
48887 if (!perm)
48888 return -EPERM;
48889 if (!i && v == K_NOSUCHMAP) {
48890@@ -1902,9 +1912,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48891 int i, j, k;
48892 int ret;
48893
48894- if (!capable(CAP_SYS_TTY_CONFIG))
48895- perm = 0;
48896-
48897 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
48898 if (!kbs) {
48899 ret = -ENOMEM;
48900@@ -1938,6 +1945,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48901 kfree(kbs);
48902 return ((p && *p) ? -EOVERFLOW : 0);
48903 case KDSKBSENT:
48904+ if (!capable(CAP_SYS_TTY_CONFIG))
48905+ perm = 0;
48906+
48907 if (!perm) {
48908 ret = -EPERM;
48909 goto reterr;
48910diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
48911index 3b96f18..026a9bf 100644
48912--- a/drivers/uio/uio.c
48913+++ b/drivers/uio/uio.c
48914@@ -25,6 +25,7 @@
48915 #include <linux/kobject.h>
48916 #include <linux/cdev.h>
48917 #include <linux/uio_driver.h>
48918+#include <asm/local.h>
48919
48920 #define UIO_MAX_DEVICES (1U << MINORBITS)
48921
48922@@ -32,10 +33,10 @@ struct uio_device {
48923 struct module *owner;
48924 struct device *dev;
48925 int minor;
48926- atomic_t event;
48927+ atomic_unchecked_t event;
48928 struct fasync_struct *async_queue;
48929 wait_queue_head_t wait;
48930- int vma_count;
48931+ local_t vma_count;
48932 struct uio_info *info;
48933 struct kobject *map_dir;
48934 struct kobject *portio_dir;
48935@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
48936 struct device_attribute *attr, char *buf)
48937 {
48938 struct uio_device *idev = dev_get_drvdata(dev);
48939- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
48940+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
48941 }
48942
48943 static struct device_attribute uio_class_attributes[] = {
48944@@ -398,7 +399,7 @@ void uio_event_notify(struct uio_info *info)
48945 {
48946 struct uio_device *idev = info->uio_dev;
48947
48948- atomic_inc(&idev->event);
48949+ atomic_inc_unchecked(&idev->event);
48950 wake_up_interruptible(&idev->wait);
48951 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
48952 }
48953@@ -451,7 +452,7 @@ static int uio_open(struct inode *inode, struct file *filep)
48954 }
48955
48956 listener->dev = idev;
48957- listener->event_count = atomic_read(&idev->event);
48958+ listener->event_count = atomic_read_unchecked(&idev->event);
48959 filep->private_data = listener;
48960
48961 if (idev->info->open) {
48962@@ -502,7 +503,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
48963 return -EIO;
48964
48965 poll_wait(filep, &idev->wait, wait);
48966- if (listener->event_count != atomic_read(&idev->event))
48967+ if (listener->event_count != atomic_read_unchecked(&idev->event))
48968 return POLLIN | POLLRDNORM;
48969 return 0;
48970 }
48971@@ -527,7 +528,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
48972 do {
48973 set_current_state(TASK_INTERRUPTIBLE);
48974
48975- event_count = atomic_read(&idev->event);
48976+ event_count = atomic_read_unchecked(&idev->event);
48977 if (event_count != listener->event_count) {
48978 if (copy_to_user(buf, &event_count, count))
48979 retval = -EFAULT;
48980@@ -596,13 +597,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
48981 static void uio_vma_open(struct vm_area_struct *vma)
48982 {
48983 struct uio_device *idev = vma->vm_private_data;
48984- idev->vma_count++;
48985+ local_inc(&idev->vma_count);
48986 }
48987
48988 static void uio_vma_close(struct vm_area_struct *vma)
48989 {
48990 struct uio_device *idev = vma->vm_private_data;
48991- idev->vma_count--;
48992+ local_dec(&idev->vma_count);
48993 }
48994
48995 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
48996@@ -809,7 +810,7 @@ int __uio_register_device(struct module *owner,
48997 idev->owner = owner;
48998 idev->info = info;
48999 init_waitqueue_head(&idev->wait);
49000- atomic_set(&idev->event, 0);
49001+ atomic_set_unchecked(&idev->event, 0);
49002
49003 ret = uio_get_minor(idev);
49004 if (ret)
49005diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
49006index 8a7eb77..c00402f 100644
49007--- a/drivers/usb/atm/cxacru.c
49008+++ b/drivers/usb/atm/cxacru.c
49009@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
49010 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
49011 if (ret < 2)
49012 return -EINVAL;
49013- if (index < 0 || index > 0x7f)
49014+ if (index > 0x7f)
49015 return -EINVAL;
49016 pos += tmp;
49017
49018diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
49019index 5e0d33a..cc10579 100644
49020--- a/drivers/usb/atm/usbatm.c
49021+++ b/drivers/usb/atm/usbatm.c
49022@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49023 if (printk_ratelimit())
49024 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
49025 __func__, vpi, vci);
49026- atomic_inc(&vcc->stats->rx_err);
49027+ atomic_inc_unchecked(&vcc->stats->rx_err);
49028 return;
49029 }
49030
49031@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49032 if (length > ATM_MAX_AAL5_PDU) {
49033 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
49034 __func__, length, vcc);
49035- atomic_inc(&vcc->stats->rx_err);
49036+ atomic_inc_unchecked(&vcc->stats->rx_err);
49037 goto out;
49038 }
49039
49040@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49041 if (sarb->len < pdu_length) {
49042 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
49043 __func__, pdu_length, sarb->len, vcc);
49044- atomic_inc(&vcc->stats->rx_err);
49045+ atomic_inc_unchecked(&vcc->stats->rx_err);
49046 goto out;
49047 }
49048
49049 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
49050 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
49051 __func__, vcc);
49052- atomic_inc(&vcc->stats->rx_err);
49053+ atomic_inc_unchecked(&vcc->stats->rx_err);
49054 goto out;
49055 }
49056
49057@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49058 if (printk_ratelimit())
49059 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
49060 __func__, length);
49061- atomic_inc(&vcc->stats->rx_drop);
49062+ atomic_inc_unchecked(&vcc->stats->rx_drop);
49063 goto out;
49064 }
49065
49066@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49067
49068 vcc->push(vcc, skb);
49069
49070- atomic_inc(&vcc->stats->rx);
49071+ atomic_inc_unchecked(&vcc->stats->rx);
49072 out:
49073 skb_trim(sarb, 0);
49074 }
49075@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
49076 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
49077
49078 usbatm_pop(vcc, skb);
49079- atomic_inc(&vcc->stats->tx);
49080+ atomic_inc_unchecked(&vcc->stats->tx);
49081
49082 skb = skb_dequeue(&instance->sndqueue);
49083 }
49084@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
49085 if (!left--)
49086 return sprintf(page,
49087 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
49088- atomic_read(&atm_dev->stats.aal5.tx),
49089- atomic_read(&atm_dev->stats.aal5.tx_err),
49090- atomic_read(&atm_dev->stats.aal5.rx),
49091- atomic_read(&atm_dev->stats.aal5.rx_err),
49092- atomic_read(&atm_dev->stats.aal5.rx_drop));
49093+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
49094+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
49095+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
49096+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
49097+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
49098
49099 if (!left--) {
49100 if (instance->disconnected)
49101diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
49102index 2a3bbdf..91d72cf 100644
49103--- a/drivers/usb/core/devices.c
49104+++ b/drivers/usb/core/devices.c
49105@@ -126,7 +126,7 @@ static const char format_endpt[] =
49106 * time it gets called.
49107 */
49108 static struct device_connect_event {
49109- atomic_t count;
49110+ atomic_unchecked_t count;
49111 wait_queue_head_t wait;
49112 } device_event = {
49113 .count = ATOMIC_INIT(1),
49114@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
49115
49116 void usbfs_conn_disc_event(void)
49117 {
49118- atomic_add(2, &device_event.count);
49119+ atomic_add_unchecked(2, &device_event.count);
49120 wake_up(&device_event.wait);
49121 }
49122
49123@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
49124
49125 poll_wait(file, &device_event.wait, wait);
49126
49127- event_count = atomic_read(&device_event.count);
49128+ event_count = atomic_read_unchecked(&device_event.count);
49129 if (file->f_version != event_count) {
49130 file->f_version = event_count;
49131 return POLLIN | POLLRDNORM;
49132diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
49133index 014dc99..4d25fd7 100644
49134--- a/drivers/usb/core/hcd.c
49135+++ b/drivers/usb/core/hcd.c
49136@@ -1551,7 +1551,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
49137 */
49138 usb_get_urb(urb);
49139 atomic_inc(&urb->use_count);
49140- atomic_inc(&urb->dev->urbnum);
49141+ atomic_inc_unchecked(&urb->dev->urbnum);
49142 usbmon_urb_submit(&hcd->self, urb);
49143
49144 /* NOTE requirements on root-hub callers (usbfs and the hub
49145@@ -1578,7 +1578,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
49146 urb->hcpriv = NULL;
49147 INIT_LIST_HEAD(&urb->urb_list);
49148 atomic_dec(&urb->use_count);
49149- atomic_dec(&urb->dev->urbnum);
49150+ atomic_dec_unchecked(&urb->dev->urbnum);
49151 if (atomic_read(&urb->reject))
49152 wake_up(&usb_kill_urb_queue);
49153 usb_put_urb(urb);
49154diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
49155index 558313d..8cadfa5 100644
49156--- a/drivers/usb/core/hub.c
49157+++ b/drivers/usb/core/hub.c
49158@@ -27,6 +27,7 @@
49159 #include <linux/freezer.h>
49160 #include <linux/random.h>
49161 #include <linux/pm_qos.h>
49162+#include <linux/grsecurity.h>
49163
49164 #include <asm/uaccess.h>
49165 #include <asm/byteorder.h>
49166@@ -4426,6 +4427,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
49167 goto done;
49168 return;
49169 }
49170+
49171+ if (gr_handle_new_usb())
49172+ goto done;
49173+
49174 if (hub_is_superspeed(hub->hdev))
49175 unit_load = 150;
49176 else
49177diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
49178index e7ee1e4..1dfc9ea4 100644
49179--- a/drivers/usb/core/message.c
49180+++ b/drivers/usb/core/message.c
49181@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
49182 * method can wait for it to complete. Since you don't have a handle on the
49183 * URB used, you can't cancel the request.
49184 */
49185-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
49186+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
49187 __u8 requesttype, __u16 value, __u16 index, void *data,
49188 __u16 size, int timeout)
49189 {
49190diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
49191index d9284b9..17023c7 100644
49192--- a/drivers/usb/core/sysfs.c
49193+++ b/drivers/usb/core/sysfs.c
49194@@ -239,7 +239,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
49195 struct usb_device *udev;
49196
49197 udev = to_usb_device(dev);
49198- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
49199+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
49200 }
49201 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
49202
49203diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
49204index 7dad603..350f7a9 100644
49205--- a/drivers/usb/core/usb.c
49206+++ b/drivers/usb/core/usb.c
49207@@ -422,7 +422,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
49208 set_dev_node(&dev->dev, dev_to_node(bus->controller));
49209 dev->state = USB_STATE_ATTACHED;
49210 dev->lpm_disable_count = 1;
49211- atomic_set(&dev->urbnum, 0);
49212+ atomic_set_unchecked(&dev->urbnum, 0);
49213
49214 INIT_LIST_HEAD(&dev->ep0.urb_list);
49215 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
49216diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
49217index f77083f..f3e2e34 100644
49218--- a/drivers/usb/dwc3/gadget.c
49219+++ b/drivers/usb/dwc3/gadget.c
49220@@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
49221 if (!usb_endpoint_xfer_isoc(desc))
49222 return 0;
49223
49224- memset(&trb_link, 0, sizeof(trb_link));
49225-
49226 /* Link TRB for ISOC. The HWO bit is never reset */
49227 trb_st_hw = &dep->trb_pool[0];
49228
49229diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
49230index 5e29dde..eca992f 100644
49231--- a/drivers/usb/early/ehci-dbgp.c
49232+++ b/drivers/usb/early/ehci-dbgp.c
49233@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
49234
49235 #ifdef CONFIG_KGDB
49236 static struct kgdb_io kgdbdbgp_io_ops;
49237-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
49238+static struct kgdb_io kgdbdbgp_io_ops_console;
49239+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
49240 #else
49241 #define dbgp_kgdb_mode (0)
49242 #endif
49243@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
49244 .write_char = kgdbdbgp_write_char,
49245 };
49246
49247+static struct kgdb_io kgdbdbgp_io_ops_console = {
49248+ .name = "kgdbdbgp",
49249+ .read_char = kgdbdbgp_read_char,
49250+ .write_char = kgdbdbgp_write_char,
49251+ .is_console = 1
49252+};
49253+
49254 static int kgdbdbgp_wait_time;
49255
49256 static int __init kgdbdbgp_parse_config(char *str)
49257@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
49258 ptr++;
49259 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
49260 }
49261- kgdb_register_io_module(&kgdbdbgp_io_ops);
49262- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
49263+ if (early_dbgp_console.index != -1)
49264+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
49265+ else
49266+ kgdb_register_io_module(&kgdbdbgp_io_ops);
49267
49268 return 0;
49269 }
49270diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
49271index b369292..9f3ba40 100644
49272--- a/drivers/usb/gadget/u_serial.c
49273+++ b/drivers/usb/gadget/u_serial.c
49274@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49275 spin_lock_irq(&port->port_lock);
49276
49277 /* already open? Great. */
49278- if (port->port.count) {
49279+ if (atomic_read(&port->port.count)) {
49280 status = 0;
49281- port->port.count++;
49282+ atomic_inc(&port->port.count);
49283
49284 /* currently opening/closing? wait ... */
49285 } else if (port->openclose) {
49286@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49287 tty->driver_data = port;
49288 port->port.tty = tty;
49289
49290- port->port.count = 1;
49291+ atomic_set(&port->port.count, 1);
49292 port->openclose = false;
49293
49294 /* if connected, start the I/O stream */
49295@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49296
49297 spin_lock_irq(&port->port_lock);
49298
49299- if (port->port.count != 1) {
49300- if (port->port.count == 0)
49301+ if (atomic_read(&port->port.count) != 1) {
49302+ if (atomic_read(&port->port.count) == 0)
49303 WARN_ON(1);
49304 else
49305- --port->port.count;
49306+ atomic_dec(&port->port.count);
49307 goto exit;
49308 }
49309
49310@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49311 * and sleep if necessary
49312 */
49313 port->openclose = true;
49314- port->port.count = 0;
49315+ atomic_set(&port->port.count, 0);
49316
49317 gser = port->port_usb;
49318 if (gser && gser->disconnect)
49319@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
49320 int cond;
49321
49322 spin_lock_irq(&port->port_lock);
49323- cond = (port->port.count == 0) && !port->openclose;
49324+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
49325 spin_unlock_irq(&port->port_lock);
49326 return cond;
49327 }
49328@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
49329 /* if it's already open, start I/O ... and notify the serial
49330 * protocol about open/close status (connect/disconnect).
49331 */
49332- if (port->port.count) {
49333+ if (atomic_read(&port->port.count)) {
49334 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
49335 gs_start_io(port);
49336 if (gser->connect)
49337@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
49338
49339 port->port_usb = NULL;
49340 gser->ioport = NULL;
49341- if (port->port.count > 0 || port->openclose) {
49342+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
49343 wake_up_interruptible(&port->drain_wait);
49344 if (port->port.tty)
49345 tty_hangup(port->port.tty);
49346@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
49347
49348 /* finally, free any unused/unusable I/O buffers */
49349 spin_lock_irqsave(&port->port_lock, flags);
49350- if (port->port.count == 0 && !port->openclose)
49351+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
49352 gs_buf_free(&port->port_write_buf);
49353 gs_free_requests(gser->out, &port->read_pool, NULL);
49354 gs_free_requests(gser->out, &port->read_queue, NULL);
49355diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
49356index ba6a5d6..f88f7f3 100644
49357--- a/drivers/usb/misc/appledisplay.c
49358+++ b/drivers/usb/misc/appledisplay.c
49359@@ -83,7 +83,7 @@ struct appledisplay {
49360 spinlock_t lock;
49361 };
49362
49363-static atomic_t count_displays = ATOMIC_INIT(0);
49364+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
49365 static struct workqueue_struct *wq;
49366
49367 static void appledisplay_complete(struct urb *urb)
49368@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
49369
49370 /* Register backlight device */
49371 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
49372- atomic_inc_return(&count_displays) - 1);
49373+ atomic_inc_return_unchecked(&count_displays) - 1);
49374 memset(&props, 0, sizeof(struct backlight_properties));
49375 props.type = BACKLIGHT_RAW;
49376 props.max_brightness = 0xff;
49377diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
49378index afb50ea..7b0b1cf 100644
49379--- a/drivers/usb/serial/console.c
49380+++ b/drivers/usb/serial/console.c
49381@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
49382
49383 info->port = port;
49384
49385- ++port->port.count;
49386+ atomic_inc(&port->port.count);
49387 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
49388 if (serial->type->set_termios) {
49389 /*
49390@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
49391 }
49392 /* Now that any required fake tty operations are completed restore
49393 * the tty port count */
49394- --port->port.count;
49395+ atomic_dec(&port->port.count);
49396 /* The console is special in terms of closing the device so
49397 * indicate this port is now acting as a system console. */
49398 port->port.console = 1;
49399@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
49400 free_tty:
49401 kfree(tty);
49402 reset_open_count:
49403- port->port.count = 0;
49404+ atomic_set(&port->port.count, 0);
49405 usb_autopm_put_interface(serial->interface);
49406 error_get_interface:
49407 usb_serial_put(serial);
49408diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
49409index 75f70f0..d467e1a 100644
49410--- a/drivers/usb/storage/usb.h
49411+++ b/drivers/usb/storage/usb.h
49412@@ -63,7 +63,7 @@ struct us_unusual_dev {
49413 __u8 useProtocol;
49414 __u8 useTransport;
49415 int (*initFunction)(struct us_data *);
49416-};
49417+} __do_const;
49418
49419
49420 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
49421diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
49422index d6bea3e..60b250e 100644
49423--- a/drivers/usb/wusbcore/wa-hc.h
49424+++ b/drivers/usb/wusbcore/wa-hc.h
49425@@ -192,7 +192,7 @@ struct wahc {
49426 struct list_head xfer_delayed_list;
49427 spinlock_t xfer_list_lock;
49428 struct work_struct xfer_work;
49429- atomic_t xfer_id_count;
49430+ atomic_unchecked_t xfer_id_count;
49431 };
49432
49433
49434@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
49435 INIT_LIST_HEAD(&wa->xfer_delayed_list);
49436 spin_lock_init(&wa->xfer_list_lock);
49437 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
49438- atomic_set(&wa->xfer_id_count, 1);
49439+ atomic_set_unchecked(&wa->xfer_id_count, 1);
49440 }
49441
49442 /**
49443diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
49444index d3493ca..0c33b7e 100644
49445--- a/drivers/usb/wusbcore/wa-xfer.c
49446+++ b/drivers/usb/wusbcore/wa-xfer.c
49447@@ -297,7 +297,7 @@ out:
49448 */
49449 static void wa_xfer_id_init(struct wa_xfer *xfer)
49450 {
49451- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
49452+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
49453 }
49454
49455 /*
49456diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
49457index 842f450..d1d7409 100644
49458--- a/drivers/vfio/vfio.c
49459+++ b/drivers/vfio/vfio.c
49460@@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
49461 return 0;
49462
49463 /* TODO Prevent device auto probing */
49464- WARN("Device %s added to live group %d!\n", dev_name(dev),
49465+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
49466 iommu_group_id(group->iommu_group));
49467
49468 return 0;
49469diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
49470index 5174eba..86e764a 100644
49471--- a/drivers/vhost/vringh.c
49472+++ b/drivers/vhost/vringh.c
49473@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
49474
49475 static inline int putu16_kern(u16 *p, u16 val)
49476 {
49477- ACCESS_ONCE(*p) = val;
49478+ ACCESS_ONCE_RW(*p) = val;
49479 return 0;
49480 }
49481
49482diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
49483index a4dfe8c..297ddd9 100644
49484--- a/drivers/video/aty/aty128fb.c
49485+++ b/drivers/video/aty/aty128fb.c
49486@@ -149,7 +149,7 @@ enum {
49487 };
49488
49489 /* Must match above enum */
49490-static char * const r128_family[] = {
49491+static const char * const r128_family[] = {
49492 "AGP",
49493 "PCI",
49494 "PRO AGP",
49495diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
49496index 9b0f12c..024673d 100644
49497--- a/drivers/video/aty/atyfb_base.c
49498+++ b/drivers/video/aty/atyfb_base.c
49499@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
49500 par->accel_flags = var->accel_flags; /* hack */
49501
49502 if (var->accel_flags) {
49503- info->fbops->fb_sync = atyfb_sync;
49504+ pax_open_kernel();
49505+ *(void **)&info->fbops->fb_sync = atyfb_sync;
49506+ pax_close_kernel();
49507 info->flags &= ~FBINFO_HWACCEL_DISABLED;
49508 } else {
49509- info->fbops->fb_sync = NULL;
49510+ pax_open_kernel();
49511+ *(void **)&info->fbops->fb_sync = NULL;
49512+ pax_close_kernel();
49513 info->flags |= FBINFO_HWACCEL_DISABLED;
49514 }
49515
49516diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
49517index 95ec042..e6affdd 100644
49518--- a/drivers/video/aty/mach64_cursor.c
49519+++ b/drivers/video/aty/mach64_cursor.c
49520@@ -7,6 +7,7 @@
49521 #include <linux/string.h>
49522
49523 #include <asm/io.h>
49524+#include <asm/pgtable.h>
49525
49526 #ifdef __sparc__
49527 #include <asm/fbio.h>
49528@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
49529 info->sprite.buf_align = 16; /* and 64 lines tall. */
49530 info->sprite.flags = FB_PIXMAP_IO;
49531
49532- info->fbops->fb_cursor = atyfb_cursor;
49533+ pax_open_kernel();
49534+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
49535+ pax_close_kernel();
49536
49537 return 0;
49538 }
49539diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
49540index bca6ccc..252107e 100644
49541--- a/drivers/video/backlight/kb3886_bl.c
49542+++ b/drivers/video/backlight/kb3886_bl.c
49543@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
49544 static unsigned long kb3886bl_flags;
49545 #define KB3886BL_SUSPENDED 0x01
49546
49547-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
49548+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
49549 {
49550 .ident = "Sahara Touch-iT",
49551 .matches = {
49552diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
49553index 900aa4e..6d49418 100644
49554--- a/drivers/video/fb_defio.c
49555+++ b/drivers/video/fb_defio.c
49556@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
49557
49558 BUG_ON(!fbdefio);
49559 mutex_init(&fbdefio->lock);
49560- info->fbops->fb_mmap = fb_deferred_io_mmap;
49561+ pax_open_kernel();
49562+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
49563+ pax_close_kernel();
49564 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
49565 INIT_LIST_HEAD(&fbdefio->pagelist);
49566 if (fbdefio->delay == 0) /* set a default of 1 s */
49567@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
49568 page->mapping = NULL;
49569 }
49570
49571- info->fbops->fb_mmap = NULL;
49572+ *(void **)&info->fbops->fb_mmap = NULL;
49573 mutex_destroy(&fbdefio->lock);
49574 }
49575 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
49576diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
49577index 5c3960d..15cf8fc 100644
49578--- a/drivers/video/fbcmap.c
49579+++ b/drivers/video/fbcmap.c
49580@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
49581 rc = -ENODEV;
49582 goto out;
49583 }
49584- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
49585- !info->fbops->fb_setcmap)) {
49586+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
49587 rc = -EINVAL;
49588 goto out1;
49589 }
49590diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
49591index 36e1fe2..c744820 100644
49592--- a/drivers/video/fbmem.c
49593+++ b/drivers/video/fbmem.c
49594@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49595 image->dx += image->width + 8;
49596 }
49597 } else if (rotate == FB_ROTATE_UD) {
49598- for (x = 0; x < num && image->dx >= 0; x++) {
49599+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
49600 info->fbops->fb_imageblit(info, image);
49601 image->dx -= image->width + 8;
49602 }
49603@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49604 image->dy += image->height + 8;
49605 }
49606 } else if (rotate == FB_ROTATE_CCW) {
49607- for (x = 0; x < num && image->dy >= 0; x++) {
49608+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
49609 info->fbops->fb_imageblit(info, image);
49610 image->dy -= image->height + 8;
49611 }
49612@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
49613 return -EFAULT;
49614 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
49615 return -EINVAL;
49616- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
49617+ if (con2fb.framebuffer >= FB_MAX)
49618 return -EINVAL;
49619 if (!registered_fb[con2fb.framebuffer])
49620 request_module("fb%d", con2fb.framebuffer);
49621diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
49622index d4d2c5f..ebbd113 100644
49623--- a/drivers/video/hyperv_fb.c
49624+++ b/drivers/video/hyperv_fb.c
49625@@ -233,7 +233,7 @@ static uint screen_fb_size;
49626 static inline int synthvid_send(struct hv_device *hdev,
49627 struct synthvid_msg *msg)
49628 {
49629- static atomic64_t request_id = ATOMIC64_INIT(0);
49630+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
49631 int ret;
49632
49633 msg->pipe_hdr.type = PIPE_MSG_DATA;
49634@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
49635
49636 ret = vmbus_sendpacket(hdev->channel, msg,
49637 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
49638- atomic64_inc_return(&request_id),
49639+ atomic64_inc_return_unchecked(&request_id),
49640 VM_PKT_DATA_INBAND, 0);
49641
49642 if (ret)
49643diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
49644index 7672d2e..b56437f 100644
49645--- a/drivers/video/i810/i810_accel.c
49646+++ b/drivers/video/i810/i810_accel.c
49647@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
49648 }
49649 }
49650 printk("ringbuffer lockup!!!\n");
49651+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
49652 i810_report_error(mmio);
49653 par->dev_flags |= LOCKUP;
49654 info->pixmap.scan_align = 1;
49655diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
49656index 285d552..eafa544 100644
49657--- a/drivers/video/logo/logo_linux_clut224.ppm
49658+++ b/drivers/video/logo/logo_linux_clut224.ppm
49659@@ -1,883 +1,1123 @@
49660 P3
49661 80 80
49662 255
49663-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49664-0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 33 49 54 59 85 92 73 97 106
49665-83 116 129 105 131 142 115 114 122 74 88 93 20 29 31 0 0 0 0 0 0 0 0 0
49666-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49667-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 10 10 10 10 10 10
49668-10 10 10 6 6 6 6 6 6 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49669-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49670-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49671-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49672-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49673-
49674-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49675-0 0 0 0 0 0 2 3 3 17 23 26 50 67 72 73 97 106 59 85 92 73 97 106
49676-105 131 142 124 127 131 105 131 142 105 131 142 53 75 83 6 8 8 0 0 0 0 0 0
49677-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49678-0 0 0 6 6 6 10 10 10 14 14 14 22 22 22 26 26 26 30 30 30 34 34 34
49679-30 30 30 30 30 30 26 26 26 18 18 18 14 14 14 10 10 10 6 6 6 0 0 0
49680-0 0 0 0 0 0 0 0 0 0 0 0 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-
49685-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0
49686-0 0 0 1 1 1 26 35 39 59 85 92 59 85 92 59 85 92 29 43 47 53 75 83
49687-108 122 132 132 98 104 108 122 132 105 131 142 101 101 101 43 45 48 6 8 8 0 0 0
49688-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49689-6 6 6 14 14 14 26 26 26 42 42 42 54 54 54 66 66 66 78 78 78 78 78 78
49690-78 78 78 74 74 74 66 66 66 54 54 54 42 42 42 26 26 26 18 18 18 10 10 10
49691-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
49696-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0
49697-11 15 17 27 40 45 59 85 92 59 85 92 27 40 45 31 45 49 73 97 106 93 121 133
49698-108 122 132 108 122 132 105 131 142 108 122 132 105 131 142 73 97 106 26 35 39 0 0 0
49699-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
49700-22 22 22 42 42 42 66 66 66 86 86 86 66 66 66 38 38 38 38 38 38 22 22 22
49701-26 26 26 34 34 34 54 54 54 66 66 66 86 86 86 70 70 70 46 46 46 26 26 26
49702-14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49703-0 0 0 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-
49707-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 7 12 13 21 31 35 42 59 64
49708-53 75 83 53 75 83 50 67 72 42 59 64 32 40 45 42 59 64 73 97 106 116 116 116
49709-132 98 104 116 116 116 108 122 132 117 104 110 105 131 142 83 116 129 50 67 72 7 12 13
49710-1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
49711-50 50 50 82 82 82 58 58 58 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
49712-2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 54 54 54 86 86 86 66 66 66
49713-38 38 38 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49714-0 0 0 0 0 0 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-
49718-0 0 0 1 1 1 6 8 8 15 22 25 26 35 39 36 54 60 53 75 83 59 85 92
49719-59 85 92 48 63 69 15 22 25 12 17 20 52 67 79 94 94 94 132 98 104 132 98 104
49720-117 104 110 108 122 132 108 122 132 115 114 122 105 131 142 77 105 114 59 85 92 36 54 60
49721-7 12 13 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 50 50 50
49722-78 78 78 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49723-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 70 70 70
49724-78 78 78 46 46 46 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49725-0 0 0 0 0 0 0 0 0 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-
49729-0 0 0 15 22 25 29 43 47 36 54 60 42 59 64 42 59 64 48 63 69 21 31 35
49730-6 8 8 29 43 47 36 50 56 43 45 48 79 78 84 132 98 104 165 78 79 132 98 104
49731-108 122 132 117 104 110 117 104 110 108 122 132 77 105 114 73 97 106 95 131 149 78 102 129
49732-36 50 56 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18 42 42 42 82 82 82
49733-26 26 26 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49734-2 2 6 2 2 6 2 2 6 14 14 14 46 46 46 34 34 34 6 6 6 2 2 6
49735-42 42 42 78 78 78 42 42 42 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
49736-0 0 0 0 0 0 0 0 0 0 0 0 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-
49740-27 40 45 53 75 83 48 63 69 24 31 37 6 8 12 0 0 0 18 25 28 26 35 39
49741-12 17 20 26 35 39 65 78 84 112 81 86 152 81 83 137 83 86 132 98 104 117 104 110
49742-117 104 110 132 98 104 132 98 104 115 114 122 73 97 106 53 75 83 95 131 149 93 124 152
49743-68 78 128 15 22 25 0 0 0 0 0 0 10 10 10 30 30 30 66 66 66 58 58 58
49744-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49745-2 2 6 2 2 6 2 2 6 26 26 26 86 86 86 101 101 101 46 46 46 10 10 10
49746-2 2 6 58 58 58 70 70 70 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
49747-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
49751-36 50 56 21 30 33 4 7 7 0 0 0 1 1 1 17 12 12 69 31 31 68 59 64
49752-57 59 63 21 31 35 32 40 45 86 73 69 152 81 83 152 81 83 117 104 110 132 98 104
49753-152 81 83 132 98 104 108 122 132 77 105 114 77 105 114 93 121 133 95 131 149 93 124 152
49754-95 131 149 53 75 83 11 15 17 0 0 0 14 14 14 42 42 42 86 86 86 10 10 10
49755-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49756-2 2 6 2 2 6 2 2 6 30 30 30 94 94 94 94 94 94 58 58 58 26 26 26
49757-2 2 6 6 6 6 78 78 78 54 54 54 22 22 22 6 6 6 0 0 0 0 0 0
49758-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
49762-17 23 26 2 3 3 0 0 0 17 12 12 69 31 31 123 55 55 123 55 55 152 81 83
49763-86 73 69 17 23 26 7 12 13 45 54 57 101 101 101 137 83 86 132 98 104 132 98 104
49764-137 83 86 117 104 110 77 105 114 42 59 64 50 67 72 78 102 129 91 117 157 91 117 157
49765-95 131 149 83 116 129 40 48 73 6 6 6 22 22 22 62 62 62 62 62 62 2 2 6
49766-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49767-2 2 6 2 2 6 2 2 6 26 26 26 54 54 54 38 38 38 18 18 18 10 10 10
49768-2 2 6 2 2 6 34 34 34 82 82 82 38 38 38 14 14 14 0 0 0 0 0 0
49769-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
49773-1 1 1 1 2 2 2 3 3 28 12 12 123 55 55 174 79 79 174 79 79 174 79 79
49774-152 81 83 68 59 64 26 35 39 27 40 45 79 78 84 137 83 86 165 78 79 137 83 86
49775-94 94 94 48 63 69 36 50 56 50 67 72 73 97 106 93 121 133 93 124 152 93 124 152
49776-95 131 149 91 118 149 78 102 129 27 40 45 30 30 30 78 78 78 30 30 30 2 2 6
49777-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49778-2 2 6 2 2 6 2 2 6 10 10 10 10 10 10 2 2 6 2 2 6 2 2 6
49779-2 2 6 2 2 6 2 2 6 78 78 78 50 50 50 18 18 18 6 6 6 0 0 0
49780-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
49784-4 5 3 24 53 24 19 31 15 8 7 3 90 61 47 165 78 79 174 79 79 174 79 79
49785-174 79 79 137 83 86 60 52 57 7 12 13 17 23 26 70 70 70 132 98 104 112 81 86
49786-79 78 84 31 45 49 15 22 25 53 75 83 91 118 149 86 106 160 91 117 157 93 124 152
49787-91 117 157 93 124 152 95 131 149 53 75 83 50 50 50 86 86 86 14 14 14 2 2 6
49788-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 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 54 54 54 66 66 66 26 26 26 6 6 6 0 0 0
49791-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
49795-19 31 15 34 76 34 34 76 34 19 31 15 28 12 12 123 55 55 174 79 79 174 79 79
49796-174 79 79 165 78 79 112 81 86 32 40 45 15 22 25 38 53 58 65 78 84 29 31 32
49797-21 30 33 42 59 64 60 80 103 78 102 129 87 112 149 84 96 162 91 117 157 93 124 152
49798-91 117 157 93 124 152 93 121 133 59 85 92 57 68 71 82 85 86 2 2 6 2 2 6
49799-2 2 6 6 6 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49800-2 2 6 2 2 6 2 2 6 6 6 6 14 14 14 10 10 10 2 2 6 2 2 6
49801-2 2 6 2 2 6 2 2 6 18 18 18 82 82 82 34 34 34 10 10 10 0 0 0
49802-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
49806-34 76 34 40 89 40 40 89 40 34 76 34 8 15 6 48 26 18 123 55 55 174 79 79
49807-174 79 79 174 79 79 137 83 86 68 59 64 32 40 45 21 30 33 31 45 49 21 31 35
49808-12 17 20 48 63 69 78 102 129 81 88 166 84 96 162 91 117 157 93 124 152 91 117 157
49809-93 124 152 95 131 149 83 116 129 59 85 92 57 68 71 86 86 86 2 2 6 2 2 6
49810-6 6 6 6 6 6 22 22 22 34 34 34 6 6 6 2 2 6 2 2 6 2 2 6
49811-2 2 6 2 2 6 18 18 18 34 34 34 10 10 10 50 50 50 22 22 22 2 2 6
49812-2 2 6 2 2 6 2 2 6 10 10 10 86 86 86 42 42 42 14 14 14 0 0 0
49813-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
49817-40 89 40 40 89 40 40 89 40 40 89 40 24 53 24 6 6 6 69 31 31 123 55 55
49818-123 55 55 90 61 47 69 31 31 36 32 33 21 31 35 7 12 13 18 25 28 48 63 69
49819-60 80 103 68 78 128 84 101 153 84 96 162 84 96 162 91 117 157 91 117 157 84 96 162
49820-91 117 157 73 97 106 48 63 69 50 67 72 57 59 63 86 86 86 2 2 6 2 2 6
49821-38 38 38 116 116 116 94 94 94 22 22 22 22 22 22 2 2 6 2 2 6 2 2 6
49822-14 14 14 86 86 86 124 131 137 170 170 170 151 151 151 38 38 38 26 26 26 6 6 6
49823-2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 46 46 46 14 14 14 0 0 0
49824-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
49828-34 76 34 40 89 40 40 89 40 40 89 40 34 76 34 19 31 15 17 12 12 48 26 18
49829-48 26 18 8 7 3 10 10 22 23 29 47 51 61 92 42 59 64 21 30 33 34 45 54
49830-68 78 128 81 88 166 81 82 173 86 106 160 86 106 160 84 96 162 86 106 160 87 112 149
49831-91 118 149 77 105 114 52 67 79 32 40 45 50 50 50 86 86 86 2 2 6 14 14 14
49832-124 131 137 198 198 198 195 195 195 116 116 116 10 10 10 2 2 6 2 2 6 6 6 6
49833-101 98 89 187 187 187 210 210 210 218 218 218 214 214 214 124 131 137 14 14 14 6 6 6
49834-2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 50 50 50 18 18 18 6 6 6
49835-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
49839-19 31 15 34 76 34 40 89 40 40 89 40 40 89 40 24 53 24 8 7 3 0 0 0
49840-6 8 12 28 32 52 51 61 92 54 54 122 74 77 160 68 78 128 26 35 39 6 8 8
49841-34 45 54 68 78 128 84 96 162 86 106 160 86 106 160 81 88 166 84 96 162 87 112 149
49842-73 97 106 36 50 56 33 49 54 18 18 18 46 46 46 86 86 86 2 2 6 54 54 54
49843-218 218 218 195 195 195 226 226 226 246 246 246 58 58 58 2 2 6 2 2 6 30 30 30
49844-210 210 210 253 253 253 170 170 170 124 127 131 221 221 221 234 234 234 74 74 74 2 2 6
49845-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 22 22 22 6 6 6
49846-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-
49850-4 5 3 24 53 24 40 89 40 40 89 40 34 76 34 12 22 15 4 5 3 4 5 3
49851-13 17 26 54 54 122 78 78 174 78 78 174 78 78 174 74 77 160 51 61 92 21 31 35
49852-26 35 39 53 75 83 84 101 153 81 82 173 81 88 166 84 101 153 60 80 103 60 80 103
49853-53 75 83 38 53 58 42 59 64 22 22 22 46 46 46 82 82 82 2 2 6 106 106 106
49854-170 170 170 26 26 26 86 86 86 226 226 226 124 127 131 10 10 10 14 14 14 46 46 46
49855-231 231 231 190 190 190 6 6 6 70 70 70 90 90 90 238 238 238 151 151 151 2 2 6
49856-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 22 22 22 6 6 6
49857-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-
49861-1 2 2 8 15 6 24 53 24 34 76 34 19 31 15 8 15 6 63 55 20 63 55 20
49862-18 18 18 40 48 73 74 77 160 78 78 174 78 78 174 81 82 173 74 77 160 52 67 79
49863-17 23 26 21 31 35 60 80 103 81 88 166 74 77 160 78 102 129 36 54 60 12 17 20
49864-42 59 64 48 63 69 21 31 35 18 18 18 42 42 42 86 86 86 6 6 6 116 116 116
49865-106 106 106 6 6 6 70 70 70 151 151 151 124 127 131 18 18 18 38 38 38 54 54 54
49866-221 221 221 106 106 106 2 2 6 14 14 14 46 46 46 190 190 190 198 198 198 2 2 6
49867-2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 6 6 6
49868-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-
49872-11 15 17 0 0 0 12 22 15 19 31 15 8 15 6 63 55 20 149 139 69 149 139 69
49873-63 55 20 10 10 22 54 54 122 78 78 174 78 78 174 78 78 174 81 82 173 68 78 128
49874-24 31 37 6 6 6 36 50 56 60 80 103 51 61 92 42 59 64 36 50 56 31 45 49
49875-29 43 47 27 40 45 6 8 8 14 14 14 42 42 42 94 94 94 14 14 14 101 101 101
49876-124 127 131 2 2 6 18 18 18 116 116 116 106 107 48 121 92 8 121 92 8 98 70 6
49877-170 170 170 106 106 106 2 2 6 2 2 6 2 2 6 195 195 195 195 195 195 6 6 6
49878-2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 6 6 6
49879-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-
49883-26 35 39 3 5 6 1 1 1 2 3 3 35 31 12 133 118 54 175 176 80 175 176 80
49884-133 118 54 35 31 12 23 29 47 54 54 122 78 78 174 78 78 174 74 77 160 68 78 128
49885-51 61 92 31 45 49 26 35 39 36 50 56 29 43 47 7 12 13 21 30 33 42 59 64
49886-18 25 28 7 12 13 1 1 1 10 10 10 38 38 38 90 90 90 14 14 14 58 58 58
49887-210 210 210 26 26 26 62 42 6 154 114 10 226 170 11 237 188 10 220 174 15 184 138 11
49888-220 174 15 174 140 55 35 31 12 2 2 6 70 70 70 246 246 246 124 131 137 2 2 6
49889-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 66 66 66 26 26 26 6 6 6
49890-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-
49894-27 40 45 17 23 26 2 3 3 1 1 1 56 77 35 165 152 80 175 176 80 175 176 80
49895-175 176 80 106 107 48 22 22 22 28 32 52 54 54 122 54 54 122 51 61 92 28 32 52
49896-20 27 34 31 45 49 11 15 17 7 12 13 36 50 56 31 45 49 29 43 47 36 50 56
49897-6 8 8 0 0 0 0 0 0 10 10 10 38 38 38 86 86 86 14 14 14 10 10 10
49898-195 195 195 198 179 130 192 133 9 220 174 15 239 182 13 237 188 10 232 195 16 239 207 25
49899-237 201 50 241 208 19 232 195 16 184 138 11 198 179 130 208 206 196 42 42 42 2 2 6
49900-2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 74 74 74 30 30 30 6 6 6
49901-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-
49905-15 22 25 26 35 39 15 22 25 0 0 0 35 31 12 133 118 54 175 176 80 175 176 80
49906-175 176 80 165 152 80 56 77 35 6 8 12 23 29 47 13 17 26 2 2 6 0 0 0
49907-1 2 2 26 35 39 26 35 39 26 35 39 42 59 64 42 59 64 20 29 31 6 8 8
49908-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 86 86 86 14 14 14 2 2 6
49909-121 92 8 192 133 9 219 162 10 239 182 13 237 188 10 232 195 16 241 208 19 237 201 50
49910-237 201 50 239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 121 92 8 2 2 6
49911-2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 82 82 82 34 34 34 10 10 10
49912-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-
49916-1 2 2 15 22 25 31 45 49 6 8 12 4 5 3 63 55 20 149 139 69 175 176 80
49917-175 176 80 175 176 80 106 107 48 20 16 6 1 1 1 0 0 0 2 3 3 11 15 17
49918-21 30 33 36 50 56 36 50 56 24 31 37 15 22 25 6 8 8 0 0 0 0 0 0
49919-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 82 82 82 30 30 30 62 42 6
49920-180 123 7 206 145 10 230 174 11 239 182 13 237 188 10 238 202 15 241 208 19 237 201 50
49921-239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 220 174 15 184 138 11 6 6 6
49922-2 2 6 2 2 6 2 2 6 2 2 6 26 26 26 94 94 94 42 42 42 14 14 14
49923-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-
49927-0 0 0 1 2 2 29 43 47 26 35 39 3 5 6 8 7 3 106 107 48 165 152 80
49928-175 176 80 149 139 69 63 55 20 4 5 3 2 3 3 12 17 20 26 35 39 26 35 39
49929-17 23 26 7 12 13 6 8 8 3 5 6 1 2 2 0 0 0 0 0 0 0 0 0
49930-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 78 78 78 50 50 50 104 69 6
49931-192 133 9 216 158 10 236 178 12 237 188 10 232 195 16 241 208 19 237 201 50 237 201 50
49932-241 208 19 241 208 19 241 208 19 204 160 10 200 144 11 216 158 10 156 118 10 2 2 6
49933-2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 90 90 90 54 54 54 18 18 18
49934-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-
49938-0 0 0 0 0 0 12 17 20 27 40 45 18 25 28 1 1 1 35 31 12 106 107 48
49939-149 139 69 56 77 35 8 7 3 1 2 2 12 17 20 26 35 39 21 31 35 11 15 17
49940-3 5 6 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49941-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 78 78 78 46 46 46 22 22 22
49942-137 92 6 204 160 10 239 182 13 237 188 10 238 202 15 241 208 19 241 208 19 241 208 19
49943-241 208 19 204 160 10 184 138 11 210 150 10 216 158 10 210 150 10 98 70 6 2 2 6
49944-6 6 6 54 54 54 14 14 14 2 2 6 2 2 6 62 62 62 74 74 74 30 30 30
49945-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49946-0 0 0 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-
49949-0 0 0 0 0 0 1 1 1 15 22 25 33 49 54 12 17 20 2 3 3 35 31 12
49950-56 77 35 20 16 6 1 1 1 18 25 28 21 31 35 11 15 17 1 1 1 0 0 0
49951-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49952-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 78 78 78 50 50 50 6 6 6
49953-88 55 22 139 102 15 190 146 13 230 187 11 239 207 25 232 195 16 220 174 15 190 146 13
49954-171 120 8 192 133 9 210 150 10 213 154 11 185 146 40 165 152 80 101 98 89 2 2 6
49955-2 2 6 78 78 78 116 116 116 58 58 58 2 2 6 22 22 22 90 90 90 46 46 46
49956-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49957-0 0 0 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-
49960-0 0 0 0 0 0 0 0 0 1 1 1 27 40 45 29 43 47 3 5 6 2 3 3
49961-8 7 3 1 1 1 17 23 26 31 45 49 15 22 25 0 0 0 0 0 0 0 0 0
49962-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49963-0 0 0 0 0 0 0 0 0 10 10 10 38 38 38 86 86 86 50 50 50 6 6 6
49964-124 127 131 168 158 138 156 107 11 171 120 8 204 160 10 184 138 11 197 138 11 200 144 11
49965-206 145 10 206 145 10 197 138 11 198 179 130 195 195 195 198 198 198 170 170 170 14 14 14
49966-2 2 6 22 22 22 116 116 116 116 116 116 22 22 22 2 2 6 74 74 74 70 70 70
49967-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49968-0 0 0 0 0 0 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-
49971-0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 31 45 49 26 35 39 3 5 6
49972-0 0 0 7 12 13 27 40 45 18 25 28 0 0 0 0 0 0 0 0 0 0 0 0
49973-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49974-0 0 0 0 0 0 6 6 6 18 18 18 50 50 50 101 101 101 26 26 26 10 10 10
49975-124 131 137 190 190 190 168 158 138 156 107 11 197 138 11 200 144 11 197 138 11 192 133 9
49976-180 123 7 185 146 40 198 179 130 187 187 187 202 202 202 221 221 221 214 214 214 66 66 66
49977-2 2 6 2 2 6 50 50 50 62 62 62 6 6 6 2 2 6 10 10 10 90 90 90
49978-50 50 50 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49979-0 0 0 0 0 0 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-
49982-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 15 22 25 36 54 60 18 25 28
49983-0 0 0 21 30 33 27 40 45 2 3 3 0 0 0 0 0 0 0 0 0 0 0 0
49984-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49985-0 0 0 0 0 0 10 10 10 34 34 34 74 74 74 74 74 74 2 2 6 6 6 6
49986-151 151 151 198 198 198 190 190 190 168 158 138 148 132 55 156 107 11 156 107 11 169 125 40
49987-168 158 138 187 187 187 190 190 190 210 210 210 246 246 246 253 253 253 253 253 253 180 180 180
49988-6 6 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62
49989-74 74 74 34 34 34 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49990-0 0 0 0 0 0 0 0 0 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-
49993-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 27 40 45 35 52 58
49994-18 25 28 35 52 58 17 23 26 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49995-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49996-0 0 0 10 10 10 22 22 22 54 54 54 94 94 94 18 18 18 2 2 6 46 46 46
49997-234 234 234 221 221 221 190 190 190 190 190 190 190 190 190 187 187 187 187 187 187 190 190 190
49998-190 190 190 195 195 195 214 214 214 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49999-82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 14 14 14
50000-86 86 86 54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50001-0 0 0 0 0 0 0 0 0 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-
50004-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 12 13 33 49 54
50005-52 72 81 36 54 60 6 8 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50006-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50007-6 6 6 18 18 18 46 46 46 90 90 90 46 46 46 18 18 18 6 6 6 180 180 180
50008-253 253 253 246 246 246 202 202 202 190 190 190 190 190 190 190 190 190 190 190 190 190 190 190
50009-202 202 202 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50010-202 202 202 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50011-42 42 42 86 86 86 42 42 42 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50012-0 0 0 0 0 0 0 0 0 0 0 0 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-
50015-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 17 20
50016-36 54 60 29 43 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50017-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50018-14 14 14 38 38 38 74 74 74 66 66 66 2 2 6 6 6 6 90 90 90 250 250 250
50019-253 253 253 253 253 253 238 238 238 198 198 198 190 190 190 190 190 190 195 195 195 221 221 221
50020-246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50021-253 253 253 82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50022-2 2 6 78 78 78 70 70 70 34 34 34 14 14 14 6 6 6 0 0 0 0 0 0
50023-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
50026-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50027-21 30 33 35 52 58 6 8 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50028-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50029-34 34 34 66 66 66 78 78 78 6 6 6 2 2 6 18 18 18 218 218 218 253 253 253
50030-253 253 253 253 253 253 253 253 253 246 246 246 226 226 226 231 231 231 246 246 246 253 253 253
50031-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50032-253 253 253 180 180 180 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50033-2 2 6 18 18 18 90 90 90 62 62 62 30 30 30 10 10 10 0 0 0 0 0 0
50034-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
50037-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50038-12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50039-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
50040-58 58 58 90 90 90 18 18 18 2 2 6 2 2 6 106 106 106 253 253 253 253 253 253
50041-253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 253 253 253 253 253 253 253 253 253
50042-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50043-253 253 253 231 231 231 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50044-2 2 6 2 2 6 18 18 18 94 94 94 54 54 54 26 26 26 10 10 10 0 0 0
50045-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
50048-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50049-0 0 0 21 30 33 35 52 58 6 8 12 0 0 0 0 0 0 0 0 0 0 0 0
50050-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 50 50 50
50051-90 90 90 26 26 26 2 2 6 2 2 6 14 14 14 195 195 195 250 250 250 253 253 253
50052-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50053-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50054-250 250 250 242 242 242 54 54 54 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50055-2 2 6 2 2 6 2 2 6 38 38 38 86 86 86 50 50 50 22 22 22 6 6 6
50056-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
50059-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50060-0 0 0 0 0 0 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0
50061-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 38 38 38 82 82 82
50062-34 34 34 2 2 6 2 2 6 2 2 6 42 42 42 195 195 195 246 246 246 253 253 253
50063-253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 242 242 242 250 250 250 253 253 253
50064-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 246 246 246 238 238 238
50065-226 226 226 231 231 231 101 101 101 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
50066-2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 82 82 82 42 42 42 14 14 14
50067-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-
50070-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50071-0 0 0 0 0 0 0 0 0 21 30 33 35 52 58 6 8 12 0 0 0 0 0 0
50072-0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26 62 62 62 66 66 66
50073-2 2 6 2 2 6 2 2 6 6 6 6 70 70 70 170 170 170 202 202 202 234 234 234
50074-246 246 246 250 250 250 250 250 250 238 238 238 226 226 226 231 231 231 238 238 238 250 250 250
50075-250 250 250 250 250 250 246 246 246 231 231 231 214 214 214 202 202 202 202 202 202 202 202 202
50076-198 198 198 202 202 202 180 180 180 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6
50077-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66 30 30 30
50078-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50079-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50080-
50081-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50082-0 0 0 0 0 0 0 0 0 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0
50083-0 0 0 0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 82 82 82 18 18 18
50084-2 2 6 2 2 6 2 2 6 10 10 10 94 94 94 180 180 180 218 218 218 242 242 242
50085-250 250 250 253 253 253 253 253 253 250 250 250 234 234 234 253 253 253 253 253 253 253 253 253
50086-253 253 253 253 253 253 253 253 253 246 246 246 238 238 238 226 226 226 210 210 210 202 202 202
50087-195 195 195 195 195 195 210 210 210 151 151 151 6 6 6 14 14 14 50 50 50 14 14 14
50088-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 86 86 86 46 46 46
50089-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50090-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50091-
50092-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50093-0 0 0 0 0 0 0 0 0 0 0 0 21 30 33 35 52 58 6 8 12 0 0 0
50094-0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 54 54 54 70 70 70 2 2 6
50095-2 2 6 10 10 10 2 2 6 22 22 22 170 170 170 231 231 231 250 250 250 253 253 253
50096-253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 253 253 253 253 253 253 253 253 253
50097-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 246 246 246
50098-231 231 231 202 202 202 198 198 198 226 226 226 94 94 94 2 2 6 6 6 6 38 38 38
50099-30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66
50100-26 26 26 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50101-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50102-
50103-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50104-0 0 0 0 0 0 0 0 0 0 0 0 6 8 8 33 49 54 29 43 47 6 8 12
50105-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 74 74 74 50 50 50 2 2 6
50106-26 26 26 26 26 26 2 2 6 106 106 106 238 238 238 253 253 253 253 253 253 253 253 253
50107-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50108-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50109-253 253 253 246 246 246 218 218 218 202 202 202 210 210 210 14 14 14 2 2 6 2 2 6
50110-30 30 30 22 22 22 2 2 6 2 2 6 2 2 6 2 2 6 18 18 18 86 86 86
50111-42 42 42 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50112-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50113-
50114-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50115-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 17 20 33 49 54 17 23 26
50116-0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 90 90 90 22 22 22 2 2 6
50117-42 42 42 2 2 6 18 18 18 218 218 218 253 253 253 253 253 253 253 253 253 253 253 253
50118-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 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 250 250 250 221 221 221 218 218 218 101 101 101 2 2 6 14 14 14
50121-18 18 18 38 38 38 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 78 78 78
50122-58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50123-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50124-
50125-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50126-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 22 25 36 54 60
50127-0 0 0 0 0 0 0 0 0 18 18 18 54 54 54 82 82 82 2 2 6 26 26 26
50128-22 22 22 2 2 6 124 127 131 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50129-253 253 253 253 253 253 253 253 253 253 253 253 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 250 250 250 238 238 238 198 198 198 6 6 6 38 38 38
50132-58 58 58 26 26 26 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6 46 46 46
50133-78 78 78 30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50134-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50135-
50136-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50137-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 21 30 33
50138-36 54 60 0 0 0 0 0 0 30 30 30 74 74 74 58 58 58 2 2 6 42 42 42
50139-2 2 6 22 22 22 231 231 231 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50140-253 253 253 253 253 253 253 253 253 250 250 250 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 246 246 246 46 46 46 38 38 38
50143-42 42 42 14 14 14 38 38 38 14 14 14 2 2 6 2 2 6 2 2 6 6 6 6
50144-86 86 86 46 46 46 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50145-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50146-
50147-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-36 54 60 0 0 0 0 0 0 42 42 42 90 90 90 18 18 18 18 18 18 26 26 26
50150-2 2 6 116 116 116 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50151-253 253 253 253 253 253 250 250 250 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253
50152-253 253 253 253 253 253 253 253 253 253 253 253 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 94 94 94 6 6 6
50154-2 2 6 2 2 6 10 10 10 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6
50155-74 74 74 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50156-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50157-
50158-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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 36 54 60 26 26 26 66 66 66 82 82 82 2 2 6 38 38 38 6 6 6
50161-14 14 14 210 210 210 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50162-253 253 253 253 253 253 246 246 246 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50163-253 253 253 253 253 253 253 253 253 253 253 253 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 151 151 151 2 2 6
50165-2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
50166-42 42 42 74 74 74 30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0
50167-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50168-
50169-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-6 6 6 36 54 60 21 30 33 90 90 90 26 26 26 6 6 6 42 42 42 2 2 6
50172-74 74 74 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50173-253 253 253 253 253 253 242 242 242 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50174-253 253 253 253 253 253 253 253 253 253 253 253 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 180 180 180 2 2 6
50176-2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
50177-10 10 10 86 86 86 38 38 38 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0
50178-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50179-
50180-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-10 10 10 26 26 26 36 54 60 82 82 82 2 2 6 22 22 22 18 18 18 2 2 6
50183-151 151 151 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50184-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50185-253 253 253 253 253 253 253 253 253 253 253 253 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 202 202 202 2 2 6
50187-2 2 6 2 2 6 2 2 6 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6
50188-6 6 6 86 86 86 46 46 46 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0
50189-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50190-
50191-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50192-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50193-18 18 18 46 46 46 86 86 86 36 54 60 2 2 6 34 34 34 10 10 10 6 6 6
50194-210 210 210 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50195-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50196-253 253 253 253 253 253 253 253 253 253 253 253 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 221 221 221 6 6 6
50198-2 2 6 2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
50199-2 2 6 82 82 82 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50200-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50201-
50202-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50203-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50204-26 26 26 66 66 66 62 62 62 2 2 6 2 2 6 38 38 38 10 10 10 26 26 26
50205-238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50206-253 253 253 253 253 253 231 231 231 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253
50207-253 253 253 253 253 253 253 253 253 253 253 253 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 231 231 231 6 6 6
50209-2 2 6 2 2 6 10 10 10 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
50210-2 2 6 66 66 66 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50211-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50212-
50213-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50214-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50215-38 38 38 78 78 78 6 6 6 2 2 6 2 2 6 46 46 46 14 14 14 42 42 42
50216-246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50217-253 253 253 253 253 253 231 231 231 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50218-253 253 253 253 253 253 253 253 253 253 253 253 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 234 234 234 10 10 10
50220-2 2 6 2 2 6 22 22 22 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6
50221-2 2 6 66 66 66 62 62 62 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50222-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50223-
50224-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50225-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50226-50 50 50 74 74 74 2 2 6 2 2 6 14 14 14 70 70 70 34 34 34 62 62 62
50227-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50228-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50229-253 253 253 253 253 253 253 253 253 253 253 253 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 234 234 234 14 14 14
50231-2 2 6 2 2 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50232-2 2 6 66 66 66 62 62 62 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50233-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50234-
50235-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50236-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50237-54 54 54 62 62 62 2 2 6 2 2 6 2 2 6 30 30 30 46 46 46 70 70 70
50238-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50239-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50240-253 253 253 253 253 253 253 253 253 253 253 253 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 226 226 226 10 10 10
50242-2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50243-2 2 6 66 66 66 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50244-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50245-
50246-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50247-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50248-58 58 58 62 62 62 2 2 6 2 2 6 2 2 6 2 2 6 30 30 30 78 78 78
50249-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50250-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50251-253 253 253 253 253 253 253 253 253 253 253 253 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 202 202 202 2 2 6
50253-22 22 22 34 34 34 20 16 6 22 22 22 26 26 26 18 18 18 6 6 6 2 2 6
50254-2 2 6 82 82 82 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50255-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50256-
50257-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50258-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 26 26 26
50259-62 62 62 106 106 106 63 55 20 184 138 11 204 160 10 121 92 8 6 6 6 62 62 62
50260-238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50261-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50262-253 253 253 253 253 253 253 253 253 253 253 253 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 151 151 151 18 18 18
50264-14 14 14 2 2 6 2 2 6 2 2 6 6 6 6 18 18 18 66 66 66 38 38 38
50265-6 6 6 94 94 94 50 50 50 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50266-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50267-
50268-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50269-0 0 0 0 0 0 0 0 0 6 6 6 10 10 10 10 10 10 18 18 18 38 38 38
50270-78 78 78 138 132 106 216 158 10 242 186 14 246 190 14 246 190 14 156 118 10 10 10 10
50271-90 90 90 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50272-253 253 253 253 253 253 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
50273-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50274-253 253 253 253 253 253 253 253 253 246 230 190 214 187 87 214 187 87 185 146 40 35 31 12
50275-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 46 46 46
50276-26 26 26 106 106 106 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50277-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50278-
50279-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50280-0 0 0 6 6 6 14 14 14 22 22 22 30 30 30 38 38 38 50 50 50 70 70 70
50281-106 106 106 185 146 40 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 154 114 10
50282-6 6 6 74 74 74 226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50283-253 253 253 253 253 253 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
50284-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50285-253 253 253 253 253 253 253 253 253 237 201 50 241 196 14 241 208 19 232 195 16 35 31 12
50286-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 30 30 30 26 26 26
50287-204 160 10 165 152 80 66 66 66 26 26 26 6 6 6 0 0 0 0 0 0 0 0 0
50288-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50289-
50290-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50291-6 6 6 18 18 18 38 38 38 58 58 58 78 78 78 86 86 86 101 101 101 124 127 131
50292-174 140 55 210 150 10 234 174 13 246 186 14 246 190 14 246 190 14 246 190 14 237 188 10
50293-98 70 6 2 2 6 46 46 46 198 198 198 253 253 253 253 253 253 253 253 253 253 253 253
50294-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50295-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50296-253 253 253 253 253 253 253 253 253 214 187 87 242 186 14 241 196 14 204 160 10 20 16 6
50297-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 121 92 8
50298-238 202 15 232 195 16 82 82 82 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
50299-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50300-
50301-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50302-14 14 14 38 38 38 70 70 70 148 132 55 185 146 40 200 144 11 197 138 11 197 138 11
50303-213 154 11 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50304-220 174 15 35 31 12 2 2 6 22 22 22 151 151 151 250 250 250 253 253 253 253 253 253
50305-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50306-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50307-253 253 253 250 250 250 242 242 242 214 187 87 239 182 13 237 188 10 213 154 11 35 31 12
50308-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 42 6 220 174 15
50309-237 188 10 237 188 10 113 101 86 42 42 42 14 14 14 0 0 0 0 0 0 0 0 0
50310-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50311-
50312-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50313-22 22 22 54 54 54 148 132 55 213 154 11 226 170 11 230 174 11 226 170 11 226 170 11
50314-236 178 12 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50315-241 196 14 184 138 11 10 10 10 2 2 6 6 6 6 116 116 116 242 242 242 253 253 253
50316-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 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 231 231 231 198 198 198 213 164 39 236 178 12 236 178 12 210 150 10 137 92 6
50319-20 16 6 2 2 6 2 2 6 2 2 6 6 6 6 62 42 6 200 144 11 236 178 12
50320-239 182 13 239 182 13 124 112 88 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0
50321-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50322-
50323-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50324-30 30 30 70 70 70 169 125 40 226 170 11 239 182 13 242 186 14 242 186 14 246 186 14
50325-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50326-246 190 14 232 195 16 98 70 6 2 2 6 2 2 6 2 2 6 66 66 66 221 221 221
50327-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 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 202 202 202 198 198 198 213 164 39 230 174 11 230 174 11 216 158 10 192 133 9
50330-163 110 8 120 80 7 98 70 6 120 80 7 167 114 7 197 138 11 226 170 11 239 182 13
50331-242 186 14 242 186 14 165 152 80 78 78 78 34 34 34 14 14 14 6 6 6 0 0 0
50332-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50333-
50334-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50335-30 30 30 78 78 78 185 146 40 226 170 11 239 182 13 246 190 14 246 190 14 246 190 14
50336-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50337-246 190 14 241 196 14 204 160 10 20 16 6 2 2 6 2 2 6 2 2 6 38 38 38
50338-218 218 218 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
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-250 250 250 202 202 202 198 198 198 213 164 39 226 170 11 236 178 12 224 166 10 210 150 10
50341-200 144 11 197 138 11 192 133 9 197 138 11 210 150 10 226 170 11 242 186 14 246 190 14
50342-246 190 14 246 186 14 220 174 15 124 112 88 62 62 62 30 30 30 14 14 14 6 6 6
50343-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50344-
50345-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50346-30 30 30 78 78 78 174 140 55 224 166 10 239 182 13 246 190 14 246 190 14 246 190 14
50347-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50348-246 190 14 246 190 14 241 196 14 139 102 15 2 2 6 2 2 6 2 2 6 2 2 6
50349-78 78 78 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50350-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50351-250 250 250 214 214 214 198 198 198 185 146 40 219 162 10 236 178 12 234 174 13 224 166 10
50352-216 158 10 213 154 11 213 154 11 216 158 10 226 170 11 239 182 13 246 190 14 246 190 14
50353-246 190 14 246 190 14 242 186 14 213 164 39 101 101 101 58 58 58 30 30 30 14 14 14
50354-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50355-
50356-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50357-30 30 30 74 74 74 174 140 55 216 158 10 236 178 12 246 190 14 246 190 14 246 190 14
50358-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50359-246 190 14 246 190 14 241 196 14 230 187 11 62 42 6 2 2 6 2 2 6 2 2 6
50360-22 22 22 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50361-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50362-253 253 253 226 226 226 187 187 187 169 125 40 216 158 10 236 178 12 239 182 13 236 178 12
50363-230 174 11 226 170 11 226 170 11 230 174 11 236 178 12 242 186 14 246 190 14 246 190 14
50364-246 190 14 246 190 14 246 186 14 239 182 13 213 164 39 106 106 106 66 66 66 34 34 34
50365-14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50366-
50367-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50368-26 26 26 70 70 70 149 139 69 213 154 11 236 178 12 246 190 14 246 190 14 246 190 14
50369-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50370-246 190 14 246 190 14 246 190 14 241 196 14 190 146 13 20 16 6 2 2 6 2 2 6
50371-46 46 46 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50372-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50373-253 253 253 221 221 221 86 86 86 156 107 11 216 158 10 236 178 12 242 186 14 246 186 14
50374-242 186 14 239 182 13 239 182 13 242 186 14 242 186 14 246 186 14 246 190 14 246 190 14
50375-246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 220 174 15 149 139 69 66 66 66
50376-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50377-
50378-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50379-26 26 26 70 70 70 149 139 69 210 150 10 236 178 12 246 190 14 246 190 14 246 190 14
50380-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50381-246 190 14 246 190 14 246 190 14 246 190 14 232 195 16 121 92 8 34 34 34 106 106 106
50382-221 221 221 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50383-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50384-242 242 242 82 82 82 20 16 6 163 110 8 216 158 10 236 178 12 242 186 14 246 190 14
50385-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50386-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 149 139 69
50387-46 46 46 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50388-
50389-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50390-30 30 30 78 78 78 149 139 69 210 150 10 236 178 12 246 186 14 246 190 14 246 190 14
50391-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50392-246 190 14 246 190 14 246 190 14 246 190 14 241 196 14 220 174 15 198 179 130 253 253 253
50393-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50394-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 218 218 218
50395-58 58 58 2 2 6 20 16 6 167 114 7 216 158 10 236 178 12 246 186 14 246 190 14
50396-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50397-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 242 186 14 185 146 40
50398-54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50399-
50400-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50401-38 38 38 86 86 86 169 125 40 213 154 11 236 178 12 246 186 14 246 190 14 246 190 14
50402-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50403-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 232 195 16 190 146 13 214 214 214
50404-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50405-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 170 170 170 26 26 26
50406-2 2 6 2 2 6 35 31 12 163 110 8 219 162 10 239 182 13 246 186 14 246 190 14
50407-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50408-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 224 166 10 149 139 69
50409-46 46 46 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50410-
50411-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50412-50 50 50 113 101 86 192 133 9 224 166 10 242 186 14 246 190 14 246 190 14 246 190 14
50413-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50414-246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 230 187 11 204 160 10 133 118 54
50415-226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50416-253 253 253 253 253 253 253 253 253 253 253 253 198 198 198 66 66 66 2 2 6 2 2 6
50417-2 2 6 2 2 6 62 42 6 156 107 11 219 162 10 239 182 13 246 186 14 246 190 14
50418-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50419-246 190 14 246 190 14 246 190 14 242 186 14 234 174 13 213 154 11 148 132 55 66 66 66
50420-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50421-
50422-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50423-58 58 58 148 132 55 206 145 10 234 174 13 242 186 14 246 186 14 246 190 14 246 190 14
50424-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50425-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 204 160 10 163 110 8
50426-62 42 6 124 131 137 218 218 218 250 250 250 253 253 253 253 253 253 253 253 253 250 250 250
50427-242 242 242 210 210 210 151 151 151 66 66 66 6 6 6 2 2 6 2 2 6 2 2 6
50428-2 2 6 2 2 6 62 42 6 163 110 8 216 158 10 236 178 12 246 190 14 246 190 14
50429-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50430-246 190 14 239 182 13 230 174 11 216 158 10 185 146 40 124 112 88 70 70 70 38 38 38
50431-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50432-
50433-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50434-62 62 62 169 125 40 206 145 10 224 166 10 236 178 12 239 182 13 242 186 14 242 186 14
50435-246 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50436-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 236 178 12 216 158 10 171 120 8
50437-85 57 6 2 2 6 6 6 6 30 30 30 54 54 54 62 62 62 50 50 50 38 38 38
50438-14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50439-2 2 6 6 6 6 85 57 6 167 114 7 213 154 11 236 178 12 246 190 14 246 190 14
50440-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 239 182 13 239 182 13
50441-230 174 11 210 150 10 174 140 55 124 112 88 82 82 82 54 54 54 34 34 34 18 18 18
50442-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50443-
50444-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50445-50 50 50 169 125 40 192 133 9 200 144 11 216 158 10 219 162 10 224 166 10 226 170 11
50446-230 174 11 236 178 12 239 182 13 239 182 13 242 186 14 246 186 14 246 190 14 246 190 14
50447-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 230 174 11 210 150 10 163 110 8
50448-104 69 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50449-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50450-2 2 6 6 6 6 85 57 6 167 114 7 206 145 10 230 174 11 242 186 14 246 190 14
50451-246 190 14 246 190 14 246 186 14 242 186 14 239 182 13 230 174 11 224 166 10 213 154 11
50452-169 125 40 124 112 88 86 86 86 58 58 58 38 38 38 22 22 22 10 10 10 6 6 6
50453-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50454-
50455-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50456-34 34 34 70 70 70 133 118 54 169 125 40 167 114 7 180 123 7 192 133 9 197 138 11
50457-200 144 11 206 145 10 213 154 11 219 162 10 224 166 10 230 174 11 239 182 13 242 186 14
50458-246 186 14 246 186 14 246 186 14 246 186 14 239 182 13 216 158 10 184 138 11 152 99 6
50459-104 69 6 20 16 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50460-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50461-2 2 6 6 6 6 85 57 6 152 99 6 192 133 9 219 162 10 236 178 12 239 182 13
50462-246 186 14 242 186 14 239 182 13 236 178 12 224 166 10 206 145 10 192 133 9 148 132 55
50463-94 94 94 62 62 62 42 42 42 22 22 22 14 14 14 6 6 6 0 0 0 0 0 0
50464-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50465-
50466-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50467-18 18 18 34 34 34 58 58 58 78 78 78 101 98 89 124 112 88 133 118 54 156 107 11
50468-163 110 8 167 114 7 171 120 8 180 123 7 184 138 11 197 138 11 210 150 10 219 162 10
50469-226 170 11 236 178 12 236 178 12 234 174 13 219 162 10 197 138 11 163 110 8 134 84 6
50470-85 57 6 10 10 10 2 2 6 2 2 6 18 18 18 38 38 38 38 38 38 38 38 38
50471-38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 26 26 26 2 2 6
50472-2 2 6 6 6 6 62 42 6 137 92 6 171 120 8 200 144 11 219 162 10 230 174 11
50473-234 174 13 230 174 11 219 162 10 210 150 10 192 133 9 163 110 8 124 112 88 82 82 82
50474-50 50 50 30 30 30 14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50475-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50476-
50477-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50478-6 6 6 14 14 14 22 22 22 34 34 34 42 42 42 58 58 58 74 74 74 86 86 86
50479-101 98 89 113 101 86 133 118 54 121 92 8 137 92 6 152 99 6 163 110 8 180 123 7
50480-184 138 11 197 138 11 206 145 10 200 144 11 180 123 7 156 107 11 134 84 6 104 69 6
50481-62 42 6 54 54 54 106 106 106 101 98 89 86 86 86 82 82 82 78 78 78 78 78 78
50482-78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 82 82 82 86 86 86 94 94 94
50483-106 106 106 101 101 101 90 61 47 120 80 7 156 107 11 180 123 7 192 133 9 200 144 11
50484-206 145 10 200 144 11 192 133 9 171 120 8 139 102 15 113 101 86 70 70 70 42 42 42
50485-22 22 22 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50486-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50487-
50488-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50489-0 0 0 0 0 0 6 6 6 10 10 10 14 14 14 22 22 22 30 30 30 38 38 38
50490-50 50 50 62 62 62 74 74 74 90 90 90 101 98 89 113 101 86 121 92 8 120 80 7
50491-137 92 6 152 99 6 152 99 6 152 99 6 134 84 6 120 80 7 98 70 6 88 55 22
50492-101 98 89 82 82 82 58 58 58 46 46 46 38 38 38 34 34 34 34 34 34 34 34 34
50493-34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 38 38 38 42 42 42
50494-54 54 54 82 82 82 94 86 71 85 57 6 134 84 6 156 107 11 167 114 7 171 120 8
50495-171 120 8 167 114 7 152 99 6 121 92 8 101 98 89 62 62 62 34 34 34 18 18 18
50496-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50497-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50498-
50499-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50500-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 10 10 10
50501-18 18 18 22 22 22 30 30 30 42 42 42 50 50 50 66 66 66 86 86 86 101 98 89
50502-94 86 71 98 70 6 104 69 6 104 69 6 104 69 6 85 57 6 88 55 22 90 90 90
50503-62 62 62 38 38 38 22 22 22 14 14 14 10 10 10 10 10 10 10 10 10 10 10 10
50504-10 10 10 10 10 10 6 6 6 10 10 10 10 10 10 10 10 10 10 10 10 14 14 14
50505-22 22 22 42 42 42 70 70 70 94 86 71 85 57 6 104 69 6 120 80 7 137 92 6
50506-134 84 6 120 80 7 94 86 71 86 86 86 58 58 58 30 30 30 14 14 14 6 6 6
50507-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50508-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50509-
50510-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 10 10 10 14 14 14 18 18 18 26 26 26 38 38 38 54 54 54
50513-70 70 70 86 86 86 94 86 71 94 86 71 94 86 71 86 86 86 74 74 74 50 50 50
50514-30 30 30 14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50515-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50516-6 6 6 18 18 18 34 34 34 58 58 58 82 82 82 94 86 71 94 86 71 94 86 71
50517-94 86 71 94 86 71 74 74 74 50 50 50 26 26 26 14 14 14 6 6 6 0 0 0
50518-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-
50521-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 6 6 6 14 14 14 18 18 18
50524-30 30 30 38 38 38 46 46 46 54 54 54 50 50 50 42 42 42 30 30 30 18 18 18
50525-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50526-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50527-0 0 0 6 6 6 14 14 14 26 26 26 38 38 38 50 50 50 58 58 58 58 58 58
50528-54 54 54 42 42 42 30 30 30 18 18 18 10 10 10 0 0 0 0 0 0 0 0 0
50529-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
50532-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
50535-6 6 6 10 10 10 14 14 14 18 18 18 18 18 18 14 14 14 10 10 10 6 6 6
50536-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50537-0 0 0 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 6 6 6 14 14 14 18 18 18 22 22 22 22 22 22
50539-18 18 18 14 14 14 10 10 10 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50540-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
50543+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50544+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50545+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50546+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50547+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50548+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50549+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50550+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50551+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50552+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50553+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50554+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 3 3 3 0 0 0 0 0 0
50632+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 1 1 1 0 0 0
50637+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50638+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
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 4 4 4 4 4 4 4 4 4
50644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50645+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
50646+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
50647+5 5 5 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 4 4 4 4 4 4
50649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50650+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
50651+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
50652+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
50653+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50654+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 4 4 4 4 4 4 4 4 4 4 4 4
50658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50659+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
50660+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
50661+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50664+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
50665+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
50666+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
50667+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
50668+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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50672+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
50673+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
50674+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
50675+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
50676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50677+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
50678+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
50679+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
50680+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
50681+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
50682+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 4 4 4 4 4 4 4 4 4 4 4 4
50685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50686+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
50687+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
50688+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
50689+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
50690+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
50691+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
50692+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
50693+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
50694+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
50695+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
50696+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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
50700+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
50701+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
50702+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
50703+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
50704+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
50705+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
50706+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
50707+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
50708+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
50709+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
50710+4 4 4 4 4 4
50711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50713+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
50714+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
50715+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
50716+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
50717+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
50718+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
50719+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
50720+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
50721+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
50722+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
50723+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
50724+4 4 4 4 4 4
50725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50727+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
50728+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
50729+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
50730+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
50731+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
50732+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
50733+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
50734+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
50735+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
50736+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
50737+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
50738+4 4 4 4 4 4
50739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50741+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
50742+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
50743+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
50744+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
50745+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
50746+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
50747+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
50748+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
50749+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
50750+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
50751+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50752+4 4 4 4 4 4
50753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50755+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
50756+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
50757+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
50758+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
50759+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
50760+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
50761+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
50762+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
50763+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
50764+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
50765+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
50766+4 4 4 4 4 4
50767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50768+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
50769+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
50770+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
50771+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
50772+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
50773+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
50774+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
50775+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
50776+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
50777+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
50778+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
50779+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
50780+4 4 4 4 4 4
50781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50782+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
50783+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
50784+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
50785+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
50786+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
50787+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
50788+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
50789+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
50790+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
50791+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
50792+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
50793+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
50794+0 0 0 4 4 4
50795+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
50796+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
50797+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
50798+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
50799+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
50800+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
50801+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
50802+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
50803+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
50804+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
50805+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
50806+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
50807+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
50808+2 0 0 0 0 0
50809+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
50810+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
50811+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
50812+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
50813+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
50814+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
50815+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
50816+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
50817+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
50818+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
50819+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
50820+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
50821+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
50822+37 38 37 0 0 0
50823+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
50824+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
50825+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
50826+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
50827+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
50828+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
50829+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
50830+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
50831+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
50832+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
50833+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
50834+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
50835+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
50836+85 115 134 4 0 0
50837+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
50838+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
50839+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
50840+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
50841+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
50842+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
50843+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
50844+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
50845+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
50846+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
50847+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
50848+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
50849+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
50850+60 73 81 4 0 0
50851+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
50852+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
50853+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
50854+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
50855+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
50856+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
50857+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
50858+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
50859+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
50860+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
50861+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
50862+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
50863+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
50864+16 19 21 4 0 0
50865+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
50866+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
50867+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
50868+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
50869+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
50870+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
50871+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
50872+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
50873+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
50874+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
50875+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
50876+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
50877+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
50878+4 0 0 4 3 3
50879+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
50880+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
50881+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
50882+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
50883+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
50884+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
50885+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
50886+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
50887+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
50888+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
50889+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
50890+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
50891+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
50892+3 2 2 4 4 4
50893+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
50894+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
50895+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
50896+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
50897+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
50898+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
50899+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50900+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
50901+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
50902+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
50903+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
50904+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
50905+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
50906+4 4 4 4 4 4
50907+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
50908+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
50909+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
50910+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
50911+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
50912+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
50913+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
50914+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
50915+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
50916+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
50917+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
50918+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
50919+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
50920+4 4 4 4 4 4
50921+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
50922+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
50923+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
50924+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
50925+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
50926+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
50927+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
50928+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
50929+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
50930+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
50931+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
50932+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
50933+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
50934+5 5 5 5 5 5
50935+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
50936+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
50937+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
50938+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
50939+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
50940+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50941+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
50942+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
50943+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
50944+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
50945+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
50946+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
50947+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
50948+5 5 5 4 4 4
50949+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
50950+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
50951+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
50952+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
50953+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50954+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
50955+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
50956+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
50957+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
50958+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
50959+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
50960+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
50961+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50962+4 4 4 4 4 4
50963+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
50964+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
50965+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
50966+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
50967+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
50968+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50969+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50970+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
50971+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
50972+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
50973+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
50974+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
50975+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50976+4 4 4 4 4 4
50977+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
50978+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
50979+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
50980+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
50981+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50982+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
50983+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
50984+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
50985+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
50986+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
50987+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
50988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50989+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50990+4 4 4 4 4 4
50991+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
50992+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
50993+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
50994+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
50995+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
50996+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50997+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50998+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
50999+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
51000+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
51001+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
51002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51004+4 4 4 4 4 4
51005+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
51006+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
51007+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
51008+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
51009+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51010+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
51011+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
51012+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
51013+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
51014+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
51015+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51018+4 4 4 4 4 4
51019+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
51020+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
51021+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
51022+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
51023+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51024+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
51025+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
51026+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
51027+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
51028+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
51029+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
51030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51032+4 4 4 4 4 4
51033+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
51034+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
51035+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
51036+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
51037+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
51038+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
51039+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
51040+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
51041+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
51042+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
51043+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
51044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51046+4 4 4 4 4 4
51047+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
51048+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
51049+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
51050+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
51051+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
51052+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
51053+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
51054+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
51055+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
51056+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
51057+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51060+4 4 4 4 4 4
51061+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
51062+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
51063+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
51064+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
51065+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51066+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
51067+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
51068+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
51069+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
51070+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
51071+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51074+4 4 4 4 4 4
51075+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
51076+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
51077+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
51078+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
51079+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51080+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
51081+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
51082+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
51083+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
51084+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
51085+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51088+4 4 4 4 4 4
51089+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
51090+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
51091+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
51092+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
51093+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51094+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
51095+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
51096+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
51097+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
51098+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51099+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51102+4 4 4 4 4 4
51103+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
51104+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
51105+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
51106+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
51107+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
51108+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
51109+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
51110+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
51111+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51112+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51113+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51115+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51116+4 4 4 4 4 4
51117+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
51118+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
51119+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
51120+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
51121+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51122+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
51123+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
51124+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
51125+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51126+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51127+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51129+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51130+4 4 4 4 4 4
51131+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
51132+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
51133+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
51134+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
51135+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
51136+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
51137+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
51138+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
51139+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51140+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51141+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51144+4 4 4 4 4 4
51145+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
51146+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
51147+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51148+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
51149+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
51150+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
51151+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
51152+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
51153+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
51154+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51155+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51158+4 4 4 4 4 4
51159+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
51160+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
51161+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
51162+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
51163+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
51164+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
51165+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
51166+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
51167+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51168+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51169+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51172+4 4 4 4 4 4
51173+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
51174+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
51175+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51176+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
51177+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
51178+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
51179+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
51180+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
51181+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
51182+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51183+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51186+4 4 4 4 4 4
51187+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
51188+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
51189+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
51190+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
51191+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
51192+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
51193+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
51194+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
51195+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51196+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51197+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51198+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51200+4 4 4 4 4 4
51201+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51202+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
51203+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51204+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
51205+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
51206+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
51207+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
51208+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
51209+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51210+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51211+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51214+4 4 4 4 4 4
51215+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51216+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
51217+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
51218+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
51219+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
51220+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
51221+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51222+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
51223+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51224+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51225+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51226+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51228+4 4 4 4 4 4
51229+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51230+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
51231+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
51232+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51233+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
51234+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
51235+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51236+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
51237+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51238+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51239+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51240+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51242+4 4 4 4 4 4
51243+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51244+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
51245+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
51246+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
51247+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
51248+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
51249+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
51250+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
51251+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
51252+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51253+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51254+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51255+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51256+4 4 4 4 4 4
51257+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51258+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
51259+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
51260+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
51261+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
51262+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
51263+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
51264+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
51265+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
51266+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51267+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51268+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51269+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51270+4 4 4 4 4 4
51271+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
51272+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
51273+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
51274+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
51275+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51276+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
51277+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
51278+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
51279+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
51280+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51281+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51282+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51283+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51284+4 4 4 4 4 4
51285+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51286+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
51287+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
51288+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
51289+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
51290+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
51291+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
51292+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
51293+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
51294+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51295+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51296+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51297+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51298+4 4 4 4 4 4
51299+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
51300+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
51301+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
51302+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
51303+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
51304+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
51305+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
51306+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
51307+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
51308+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
51309+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51310+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51311+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51312+4 4 4 4 4 4
51313+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
51314+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51315+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
51316+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
51317+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
51318+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
51319+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
51320+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
51321+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
51322+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
51323+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51324+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51325+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51326+4 4 4 4 4 4
51327+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
51328+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51329+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
51330+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
51331+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
51332+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
51333+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51334+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
51335+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
51336+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
51337+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51340+4 4 4 4 4 4
51341+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
51342+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
51343+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
51344+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
51345+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
51346+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
51347+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
51348+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
51349+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
51350+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
51351+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51352+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51354+4 4 4 4 4 4
51355+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
51356+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
51357+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51358+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
51359+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
51360+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
51361+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
51362+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
51363+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
51364+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
51367+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51368+4 4 4 4 4 4
51369+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51370+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
51371+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
51372+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
51373+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
51374+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
51375+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
51376+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
51377+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
51378+13 16 17 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
51381+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51382+4 4 4 4 4 4
51383+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
51384+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
51385+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
51386+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
51387+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
51388+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
51389+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
51390+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
51391+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
51392+4 0 0 4 0 0 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51395+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51396+4 4 4 4 4 4
51397+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
51398+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
51399+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
51400+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
51401+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
51402+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
51403+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
51404+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
51405+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
51406+4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51409+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51410+4 4 4 4 4 4
51411+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
51412+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51413+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
51414+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51415+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
51416+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
51417+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
51418+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
51419+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 4 4 4 4 4 4 4 4 4 4 4 4
51423+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51424+4 4 4 4 4 4
51425+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
51426+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
51427+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
51428+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
51429+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
51430+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
51431+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
51432+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
51433+4 0 0 4 0 0 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
51437+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51438+4 4 4 4 4 4
51439+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
51440+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
51441+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
51442+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
51443+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
51444+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
51445+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
51446+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
51447+4 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
51451+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51452+4 4 4 4 4 4
51453+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
51454+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
51455+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51456+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
51457+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
51458+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
51459+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
51460+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 4 4 4 4 4 4
51465+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51466+4 4 4 4 4 4
51467+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51468+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
51469+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
51470+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
51471+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
51472+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
51473+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
51474+6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
51479+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51480+4 4 4 4 4 4
51481+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51482+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
51483+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51484+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
51485+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
51486+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
51487+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
51488+4 0 0 4 3 3 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
51493+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51494+4 4 4 4 4 4
51495+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51496+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
51497+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
51498+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
51499+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
51500+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
51501+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
51502+6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 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 4 4 4
51509+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51510+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
51511+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
51512+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51513+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
51514+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
51515+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
51516+5 5 5 5 5 5 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 4 4 4 4 4 4 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
51523+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51524+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51525+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51526+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
51527+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
51528+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
51529+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
51530+4 3 3 5 5 5 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 4 4 4 4 4 4 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
51537+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51538+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51539+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51540+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51541+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
51542+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
51543+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 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
51551+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51552+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51553+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51554+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51555+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51556+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
51557+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 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
51565+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51566+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51567+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51568+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
51569+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51570+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51571+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
51581+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51582+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
51583+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
51584+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
51585+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4
51595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51597+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
51598+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51599+6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 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
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 4 4 4
51609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51611+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
51612+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
51613+4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51625+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
51626+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
51627+5 5 5 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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51639+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
51640+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4
51652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51653+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51654+5 5 5 4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 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
51663diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
51664index fe92eed..106e085 100644
51665--- a/drivers/video/mb862xx/mb862xxfb_accel.c
51666+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
51667@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
51668 struct mb862xxfb_par *par = info->par;
51669
51670 if (info->var.bits_per_pixel == 32) {
51671- info->fbops->fb_fillrect = cfb_fillrect;
51672- info->fbops->fb_copyarea = cfb_copyarea;
51673- info->fbops->fb_imageblit = cfb_imageblit;
51674+ pax_open_kernel();
51675+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
51676+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
51677+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
51678+ pax_close_kernel();
51679 } else {
51680 outreg(disp, GC_L0EM, 3);
51681- info->fbops->fb_fillrect = mb86290fb_fillrect;
51682- info->fbops->fb_copyarea = mb86290fb_copyarea;
51683- info->fbops->fb_imageblit = mb86290fb_imageblit;
51684+ pax_open_kernel();
51685+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
51686+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
51687+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
51688+ pax_close_kernel();
51689 }
51690 outreg(draw, GDC_REG_DRAW_BASE, 0);
51691 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
51692diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
51693index ff22871..b129bed 100644
51694--- a/drivers/video/nvidia/nvidia.c
51695+++ b/drivers/video/nvidia/nvidia.c
51696@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
51697 info->fix.line_length = (info->var.xres_virtual *
51698 info->var.bits_per_pixel) >> 3;
51699 if (info->var.accel_flags) {
51700- info->fbops->fb_imageblit = nvidiafb_imageblit;
51701- info->fbops->fb_fillrect = nvidiafb_fillrect;
51702- info->fbops->fb_copyarea = nvidiafb_copyarea;
51703- info->fbops->fb_sync = nvidiafb_sync;
51704+ pax_open_kernel();
51705+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
51706+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
51707+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
51708+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
51709+ pax_close_kernel();
51710 info->pixmap.scan_align = 4;
51711 info->flags &= ~FBINFO_HWACCEL_DISABLED;
51712 info->flags |= FBINFO_READS_FAST;
51713 NVResetGraphics(info);
51714 } else {
51715- info->fbops->fb_imageblit = cfb_imageblit;
51716- info->fbops->fb_fillrect = cfb_fillrect;
51717- info->fbops->fb_copyarea = cfb_copyarea;
51718- info->fbops->fb_sync = NULL;
51719+ pax_open_kernel();
51720+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
51721+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
51722+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
51723+ *(void **)&info->fbops->fb_sync = NULL;
51724+ pax_close_kernel();
51725 info->pixmap.scan_align = 1;
51726 info->flags |= FBINFO_HWACCEL_DISABLED;
51727 info->flags &= ~FBINFO_READS_FAST;
51728@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
51729 info->pixmap.size = 8 * 1024;
51730 info->pixmap.flags = FB_PIXMAP_SYSTEM;
51731
51732- if (!hwcur)
51733- info->fbops->fb_cursor = NULL;
51734+ if (!hwcur) {
51735+ pax_open_kernel();
51736+ *(void **)&info->fbops->fb_cursor = NULL;
51737+ pax_close_kernel();
51738+ }
51739
51740 info->var.accel_flags = (!noaccel);
51741
51742diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
51743index 05c2dc3..ea1f391 100644
51744--- a/drivers/video/s1d13xxxfb.c
51745+++ b/drivers/video/s1d13xxxfb.c
51746@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
51747
51748 switch(prod_id) {
51749 case S1D13506_PROD_ID: /* activate acceleration */
51750- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
51751- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
51752+ pax_open_kernel();
51753+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
51754+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
51755+ pax_close_kernel();
51756 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
51757 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
51758 break;
51759diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
51760index e188ada..aac63c8 100644
51761--- a/drivers/video/smscufx.c
51762+++ b/drivers/video/smscufx.c
51763@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
51764 fb_deferred_io_cleanup(info);
51765 kfree(info->fbdefio);
51766 info->fbdefio = NULL;
51767- info->fbops->fb_mmap = ufx_ops_mmap;
51768+ pax_open_kernel();
51769+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
51770+ pax_close_kernel();
51771 }
51772
51773 pr_debug("released /dev/fb%d user=%d count=%d",
51774diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
51775index d2e5bc3..4cb05d1 100644
51776--- a/drivers/video/udlfb.c
51777+++ b/drivers/video/udlfb.c
51778@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
51779 dlfb_urb_completion(urb);
51780
51781 error:
51782- atomic_add(bytes_sent, &dev->bytes_sent);
51783- atomic_add(bytes_identical, &dev->bytes_identical);
51784- atomic_add(width*height*2, &dev->bytes_rendered);
51785+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
51786+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
51787+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
51788 end_cycles = get_cycles();
51789- atomic_add(((unsigned int) ((end_cycles - start_cycles)
51790+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
51791 >> 10)), /* Kcycles */
51792 &dev->cpu_kcycles_used);
51793
51794@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
51795 dlfb_urb_completion(urb);
51796
51797 error:
51798- atomic_add(bytes_sent, &dev->bytes_sent);
51799- atomic_add(bytes_identical, &dev->bytes_identical);
51800- atomic_add(bytes_rendered, &dev->bytes_rendered);
51801+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
51802+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
51803+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
51804 end_cycles = get_cycles();
51805- atomic_add(((unsigned int) ((end_cycles - start_cycles)
51806+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
51807 >> 10)), /* Kcycles */
51808 &dev->cpu_kcycles_used);
51809 }
51810@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
51811 fb_deferred_io_cleanup(info);
51812 kfree(info->fbdefio);
51813 info->fbdefio = NULL;
51814- info->fbops->fb_mmap = dlfb_ops_mmap;
51815+ pax_open_kernel();
51816+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
51817+ pax_close_kernel();
51818 }
51819
51820 pr_warn("released /dev/fb%d user=%d count=%d\n",
51821@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
51822 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51823 struct dlfb_data *dev = fb_info->par;
51824 return snprintf(buf, PAGE_SIZE, "%u\n",
51825- atomic_read(&dev->bytes_rendered));
51826+ atomic_read_unchecked(&dev->bytes_rendered));
51827 }
51828
51829 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
51830@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
51831 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51832 struct dlfb_data *dev = fb_info->par;
51833 return snprintf(buf, PAGE_SIZE, "%u\n",
51834- atomic_read(&dev->bytes_identical));
51835+ atomic_read_unchecked(&dev->bytes_identical));
51836 }
51837
51838 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
51839@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
51840 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51841 struct dlfb_data *dev = fb_info->par;
51842 return snprintf(buf, PAGE_SIZE, "%u\n",
51843- atomic_read(&dev->bytes_sent));
51844+ atomic_read_unchecked(&dev->bytes_sent));
51845 }
51846
51847 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
51848@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
51849 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51850 struct dlfb_data *dev = fb_info->par;
51851 return snprintf(buf, PAGE_SIZE, "%u\n",
51852- atomic_read(&dev->cpu_kcycles_used));
51853+ atomic_read_unchecked(&dev->cpu_kcycles_used));
51854 }
51855
51856 static ssize_t edid_show(
51857@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
51858 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51859 struct dlfb_data *dev = fb_info->par;
51860
51861- atomic_set(&dev->bytes_rendered, 0);
51862- atomic_set(&dev->bytes_identical, 0);
51863- atomic_set(&dev->bytes_sent, 0);
51864- atomic_set(&dev->cpu_kcycles_used, 0);
51865+ atomic_set_unchecked(&dev->bytes_rendered, 0);
51866+ atomic_set_unchecked(&dev->bytes_identical, 0);
51867+ atomic_set_unchecked(&dev->bytes_sent, 0);
51868+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
51869
51870 return count;
51871 }
51872diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
51873index 7aec6f3..e3b2d55 100644
51874--- a/drivers/video/uvesafb.c
51875+++ b/drivers/video/uvesafb.c
51876@@ -19,6 +19,7 @@
51877 #include <linux/io.h>
51878 #include <linux/mutex.h>
51879 #include <linux/slab.h>
51880+#include <linux/moduleloader.h>
51881 #include <video/edid.h>
51882 #include <video/uvesafb.h>
51883 #ifdef CONFIG_X86
51884@@ -566,10 +567,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
51885 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
51886 par->pmi_setpal = par->ypan = 0;
51887 } else {
51888+
51889+#ifdef CONFIG_PAX_KERNEXEC
51890+#ifdef CONFIG_MODULES
51891+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
51892+#endif
51893+ if (!par->pmi_code) {
51894+ par->pmi_setpal = par->ypan = 0;
51895+ return 0;
51896+ }
51897+#endif
51898+
51899 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
51900 + task->t.regs.edi);
51901+
51902+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51903+ pax_open_kernel();
51904+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
51905+ pax_close_kernel();
51906+
51907+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
51908+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
51909+#else
51910 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
51911 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
51912+#endif
51913+
51914 printk(KERN_INFO "uvesafb: protected mode interface info at "
51915 "%04x:%04x\n",
51916 (u16)task->t.regs.es, (u16)task->t.regs.edi);
51917@@ -814,13 +837,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
51918 par->ypan = ypan;
51919
51920 if (par->pmi_setpal || par->ypan) {
51921+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
51922 if (__supported_pte_mask & _PAGE_NX) {
51923 par->pmi_setpal = par->ypan = 0;
51924 printk(KERN_WARNING "uvesafb: NX protection is active, "
51925 "better not use the PMI.\n");
51926- } else {
51927+ } else
51928+#endif
51929 uvesafb_vbe_getpmi(task, par);
51930- }
51931 }
51932 #else
51933 /* The protected mode interface is not available on non-x86. */
51934@@ -1454,8 +1478,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
51935 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
51936
51937 /* Disable blanking if the user requested so. */
51938- if (!blank)
51939- info->fbops->fb_blank = NULL;
51940+ if (!blank) {
51941+ pax_open_kernel();
51942+ *(void **)&info->fbops->fb_blank = NULL;
51943+ pax_close_kernel();
51944+ }
51945
51946 /*
51947 * Find out how much IO memory is required for the mode with
51948@@ -1531,8 +1558,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
51949 info->flags = FBINFO_FLAG_DEFAULT |
51950 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
51951
51952- if (!par->ypan)
51953- info->fbops->fb_pan_display = NULL;
51954+ if (!par->ypan) {
51955+ pax_open_kernel();
51956+ *(void **)&info->fbops->fb_pan_display = NULL;
51957+ pax_close_kernel();
51958+ }
51959 }
51960
51961 static void uvesafb_init_mtrr(struct fb_info *info)
51962@@ -1796,6 +1826,11 @@ out:
51963 if (par->vbe_modes)
51964 kfree(par->vbe_modes);
51965
51966+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51967+ if (par->pmi_code)
51968+ module_free_exec(NULL, par->pmi_code);
51969+#endif
51970+
51971 framebuffer_release(info);
51972 return err;
51973 }
51974@@ -1823,6 +1858,12 @@ static int uvesafb_remove(struct platform_device *dev)
51975 kfree(par->vbe_state_orig);
51976 if (par->vbe_state_saved)
51977 kfree(par->vbe_state_saved);
51978+
51979+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51980+ if (par->pmi_code)
51981+ module_free_exec(NULL, par->pmi_code);
51982+#endif
51983+
51984 }
51985
51986 framebuffer_release(info);
51987diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
51988index 501b340..d80aa17 100644
51989--- a/drivers/video/vesafb.c
51990+++ b/drivers/video/vesafb.c
51991@@ -9,6 +9,7 @@
51992 */
51993
51994 #include <linux/module.h>
51995+#include <linux/moduleloader.h>
51996 #include <linux/kernel.h>
51997 #include <linux/errno.h>
51998 #include <linux/string.h>
51999@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
52000 static int vram_total __initdata; /* Set total amount of memory */
52001 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
52002 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
52003-static void (*pmi_start)(void) __read_mostly;
52004-static void (*pmi_pal) (void) __read_mostly;
52005+static void (*pmi_start)(void) __read_only;
52006+static void (*pmi_pal) (void) __read_only;
52007 static int depth __read_mostly;
52008 static int vga_compat __read_mostly;
52009 /* --------------------------------------------------------------------- */
52010@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
52011 unsigned int size_vmode;
52012 unsigned int size_remap;
52013 unsigned int size_total;
52014+ void *pmi_code = NULL;
52015
52016 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
52017 return -ENODEV;
52018@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
52019 size_remap = size_total;
52020 vesafb_fix.smem_len = size_remap;
52021
52022-#ifndef __i386__
52023- screen_info.vesapm_seg = 0;
52024-#endif
52025-
52026 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
52027 printk(KERN_WARNING
52028 "vesafb: cannot reserve video memory at 0x%lx\n",
52029@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
52030 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
52031 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
52032
52033+#ifdef __i386__
52034+
52035+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52036+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
52037+ if (!pmi_code)
52038+#elif !defined(CONFIG_PAX_KERNEXEC)
52039+ if (0)
52040+#endif
52041+
52042+#endif
52043+ screen_info.vesapm_seg = 0;
52044+
52045 if (screen_info.vesapm_seg) {
52046- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
52047- screen_info.vesapm_seg,screen_info.vesapm_off);
52048+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
52049+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
52050 }
52051
52052 if (screen_info.vesapm_seg < 0xc000)
52053@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
52054
52055 if (ypan || pmi_setpal) {
52056 unsigned short *pmi_base;
52057+
52058 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
52059- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
52060- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
52061+
52062+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52063+ pax_open_kernel();
52064+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
52065+#else
52066+ pmi_code = pmi_base;
52067+#endif
52068+
52069+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
52070+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
52071+
52072+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52073+ pmi_start = ktva_ktla(pmi_start);
52074+ pmi_pal = ktva_ktla(pmi_pal);
52075+ pax_close_kernel();
52076+#endif
52077+
52078 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
52079 if (pmi_base[3]) {
52080 printk(KERN_INFO "vesafb: pmi: ports = ");
52081@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
52082 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
52083 (ypan ? FBINFO_HWACCEL_YPAN : 0);
52084
52085- if (!ypan)
52086- info->fbops->fb_pan_display = NULL;
52087+ if (!ypan) {
52088+ pax_open_kernel();
52089+ *(void **)&info->fbops->fb_pan_display = NULL;
52090+ pax_close_kernel();
52091+ }
52092
52093 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
52094 err = -ENOMEM;
52095@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
52096 info->node, info->fix.id);
52097 return 0;
52098 err:
52099+
52100+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52101+ module_free_exec(NULL, pmi_code);
52102+#endif
52103+
52104 if (info->screen_base)
52105 iounmap(info->screen_base);
52106 framebuffer_release(info);
52107diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
52108index 88714ae..16c2e11 100644
52109--- a/drivers/video/via/via_clock.h
52110+++ b/drivers/video/via/via_clock.h
52111@@ -56,7 +56,7 @@ struct via_clock {
52112
52113 void (*set_engine_pll_state)(u8 state);
52114 void (*set_engine_pll)(struct via_pll_config config);
52115-};
52116+} __no_const;
52117
52118
52119 static inline u32 get_pll_internal_frequency(u32 ref_freq,
52120diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
52121index fef20db..d28b1ab 100644
52122--- a/drivers/xen/xenfs/xenstored.c
52123+++ b/drivers/xen/xenfs/xenstored.c
52124@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
52125 static int xsd_kva_open(struct inode *inode, struct file *file)
52126 {
52127 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
52128+#ifdef CONFIG_GRKERNSEC_HIDESYM
52129+ NULL);
52130+#else
52131 xen_store_interface);
52132+#endif
52133+
52134 if (!file->private_data)
52135 return -ENOMEM;
52136 return 0;
52137diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
52138index 9ff073f..05cef23 100644
52139--- a/fs/9p/vfs_addr.c
52140+++ b/fs/9p/vfs_addr.c
52141@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
52142
52143 retval = v9fs_file_write_internal(inode,
52144 v9inode->writeback_fid,
52145- (__force const char __user *)buffer,
52146+ (const char __force_user *)buffer,
52147 len, &offset, 0);
52148 if (retval > 0)
52149 retval = 0;
52150diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
52151index 25b018e..b941525 100644
52152--- a/fs/9p/vfs_inode.c
52153+++ b/fs/9p/vfs_inode.c
52154@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
52155 void
52156 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52157 {
52158- char *s = nd_get_link(nd);
52159+ const char *s = nd_get_link(nd);
52160
52161 p9_debug(P9_DEBUG_VFS, " %s %s\n",
52162 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
52163diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
52164index 370b24c..ff0be7b 100644
52165--- a/fs/Kconfig.binfmt
52166+++ b/fs/Kconfig.binfmt
52167@@ -103,7 +103,7 @@ config HAVE_AOUT
52168
52169 config BINFMT_AOUT
52170 tristate "Kernel support for a.out and ECOFF binaries"
52171- depends on HAVE_AOUT
52172+ depends on HAVE_AOUT && BROKEN
52173 ---help---
52174 A.out (Assembler.OUTput) is a set of formats for libraries and
52175 executables used in the earliest versions of UNIX. Linux used
52176diff --git a/fs/afs/inode.c b/fs/afs/inode.c
52177index 789bc25..fafaeea 100644
52178--- a/fs/afs/inode.c
52179+++ b/fs/afs/inode.c
52180@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
52181 struct afs_vnode *vnode;
52182 struct super_block *sb;
52183 struct inode *inode;
52184- static atomic_t afs_autocell_ino;
52185+ static atomic_unchecked_t afs_autocell_ino;
52186
52187 _enter("{%x:%u},%*.*s,",
52188 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
52189@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
52190 data.fid.unique = 0;
52191 data.fid.vnode = 0;
52192
52193- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
52194+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
52195 afs_iget5_autocell_test, afs_iget5_set,
52196 &data);
52197 if (!inode) {
52198diff --git a/fs/aio.c b/fs/aio.c
52199index 9b5ca11..c530886 100644
52200--- a/fs/aio.c
52201+++ b/fs/aio.c
52202@@ -162,7 +162,7 @@ static int aio_setup_ring(struct kioctx *ctx)
52203 size += sizeof(struct io_event) * nr_events;
52204 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
52205
52206- if (nr_pages < 0)
52207+ if (nr_pages <= 0)
52208 return -EINVAL;
52209
52210 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
52211@@ -952,6 +952,7 @@ static ssize_t aio_rw_vect_retry(struct kiocb *iocb, int rw, aio_rw_op *rw_op)
52212 static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
52213 {
52214 ssize_t ret;
52215+ struct iovec iovstack;
52216
52217 kiocb->ki_nr_segs = kiocb->ki_nbytes;
52218
52219@@ -959,17 +960,22 @@ static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
52220 if (compat)
52221 ret = compat_rw_copy_check_uvector(rw,
52222 (struct compat_iovec __user *)kiocb->ki_buf,
52223- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
52224+ kiocb->ki_nr_segs, 1, &iovstack,
52225 &kiocb->ki_iovec);
52226 else
52227 #endif
52228 ret = rw_copy_check_uvector(rw,
52229 (struct iovec __user *)kiocb->ki_buf,
52230- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
52231+ kiocb->ki_nr_segs, 1, &iovstack,
52232 &kiocb->ki_iovec);
52233 if (ret < 0)
52234 return ret;
52235
52236+ if (kiocb->ki_iovec == &iovstack) {
52237+ kiocb->ki_inline_vec = iovstack;
52238+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
52239+ }
52240+
52241 /* ki_nbytes now reflect bytes instead of segs */
52242 kiocb->ki_nbytes = ret;
52243 return 0;
52244diff --git a/fs/attr.c b/fs/attr.c
52245index 1449adb..a2038c2 100644
52246--- a/fs/attr.c
52247+++ b/fs/attr.c
52248@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
52249 unsigned long limit;
52250
52251 limit = rlimit(RLIMIT_FSIZE);
52252+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
52253 if (limit != RLIM_INFINITY && offset > limit)
52254 goto out_sig;
52255 if (offset > inode->i_sb->s_maxbytes)
52256diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
52257index 3db70da..7aeec5b 100644
52258--- a/fs/autofs4/waitq.c
52259+++ b/fs/autofs4/waitq.c
52260@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
52261 {
52262 unsigned long sigpipe, flags;
52263 mm_segment_t fs;
52264- const char *data = (const char *)addr;
52265+ const char __user *data = (const char __force_user *)addr;
52266 ssize_t wr = 0;
52267
52268 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
52269@@ -346,6 +346,10 @@ static int validate_request(struct autofs_wait_queue **wait,
52270 return 1;
52271 }
52272
52273+#ifdef CONFIG_GRKERNSEC_HIDESYM
52274+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
52275+#endif
52276+
52277 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52278 enum autofs_notify notify)
52279 {
52280@@ -379,7 +383,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52281
52282 /* If this is a direct mount request create a dummy name */
52283 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
52284+#ifdef CONFIG_GRKERNSEC_HIDESYM
52285+ /* this name does get written to userland via autofs4_write() */
52286+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
52287+#else
52288 qstr.len = sprintf(name, "%p", dentry);
52289+#endif
52290 else {
52291 qstr.len = autofs4_getpath(sbi, dentry, &name);
52292 if (!qstr.len) {
52293diff --git a/fs/befs/endian.h b/fs/befs/endian.h
52294index 2722387..c8dd2a7 100644
52295--- a/fs/befs/endian.h
52296+++ b/fs/befs/endian.h
52297@@ -11,7 +11,7 @@
52298
52299 #include <asm/byteorder.h>
52300
52301-static inline u64
52302+static inline u64 __intentional_overflow(-1)
52303 fs64_to_cpu(const struct super_block *sb, fs64 n)
52304 {
52305 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52306@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
52307 return (__force fs64)cpu_to_be64(n);
52308 }
52309
52310-static inline u32
52311+static inline u32 __intentional_overflow(-1)
52312 fs32_to_cpu(const struct super_block *sb, fs32 n)
52313 {
52314 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52315diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
52316index e9c75e2..1baece1 100644
52317--- a/fs/befs/linuxvfs.c
52318+++ b/fs/befs/linuxvfs.c
52319@@ -514,7 +514,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52320 {
52321 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
52322 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
52323- char *link = nd_get_link(nd);
52324+ const char *link = nd_get_link(nd);
52325 if (!IS_ERR(link))
52326 kfree(link);
52327 }
52328diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
52329index 89dec7f..361b0d75 100644
52330--- a/fs/binfmt_aout.c
52331+++ b/fs/binfmt_aout.c
52332@@ -16,6 +16,7 @@
52333 #include <linux/string.h>
52334 #include <linux/fs.h>
52335 #include <linux/file.h>
52336+#include <linux/security.h>
52337 #include <linux/stat.h>
52338 #include <linux/fcntl.h>
52339 #include <linux/ptrace.h>
52340@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
52341 #endif
52342 # define START_STACK(u) ((void __user *)u.start_stack)
52343
52344+ memset(&dump, 0, sizeof(dump));
52345+
52346 fs = get_fs();
52347 set_fs(KERNEL_DS);
52348 has_dumped = 1;
52349@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
52350
52351 /* If the size of the dump file exceeds the rlimit, then see what would happen
52352 if we wrote the stack, but not the data area. */
52353+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
52354 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
52355 dump.u_dsize = 0;
52356
52357 /* Make sure we have enough room to write the stack and data areas. */
52358+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
52359 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
52360 dump.u_ssize = 0;
52361
52362@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
52363 rlim = rlimit(RLIMIT_DATA);
52364 if (rlim >= RLIM_INFINITY)
52365 rlim = ~0;
52366+
52367+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
52368 if (ex.a_data + ex.a_bss > rlim)
52369 return -ENOMEM;
52370
52371@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
52372
52373 install_exec_creds(bprm);
52374
52375+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52376+ current->mm->pax_flags = 0UL;
52377+#endif
52378+
52379+#ifdef CONFIG_PAX_PAGEEXEC
52380+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
52381+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
52382+
52383+#ifdef CONFIG_PAX_EMUTRAMP
52384+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
52385+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
52386+#endif
52387+
52388+#ifdef CONFIG_PAX_MPROTECT
52389+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
52390+ current->mm->pax_flags |= MF_PAX_MPROTECT;
52391+#endif
52392+
52393+ }
52394+#endif
52395+
52396 if (N_MAGIC(ex) == OMAGIC) {
52397 unsigned long text_addr, map_size;
52398 loff_t pos;
52399@@ -322,7 +350,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
52400 }
52401
52402 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
52403- PROT_READ | PROT_WRITE | PROT_EXEC,
52404+ PROT_READ | PROT_WRITE,
52405 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
52406 fd_offset + ex.a_text);
52407 if (error != N_DATADDR(ex)) {
52408diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
52409index 100edcc..ed95731 100644
52410--- a/fs/binfmt_elf.c
52411+++ b/fs/binfmt_elf.c
52412@@ -34,6 +34,7 @@
52413 #include <linux/utsname.h>
52414 #include <linux/coredump.h>
52415 #include <linux/sched.h>
52416+#include <linux/xattr.h>
52417 #include <asm/uaccess.h>
52418 #include <asm/param.h>
52419 #include <asm/page.h>
52420@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
52421 #define elf_core_dump NULL
52422 #endif
52423
52424+#ifdef CONFIG_PAX_MPROTECT
52425+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
52426+#endif
52427+
52428+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52429+static void elf_handle_mmap(struct file *file);
52430+#endif
52431+
52432 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
52433 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
52434 #else
52435@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
52436 .load_binary = load_elf_binary,
52437 .load_shlib = load_elf_library,
52438 .core_dump = elf_core_dump,
52439+
52440+#ifdef CONFIG_PAX_MPROTECT
52441+ .handle_mprotect= elf_handle_mprotect,
52442+#endif
52443+
52444+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52445+ .handle_mmap = elf_handle_mmap,
52446+#endif
52447+
52448 .min_coredump = ELF_EXEC_PAGESIZE,
52449 };
52450
52451@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
52452
52453 static int set_brk(unsigned long start, unsigned long end)
52454 {
52455+ unsigned long e = end;
52456+
52457 start = ELF_PAGEALIGN(start);
52458 end = ELF_PAGEALIGN(end);
52459 if (end > start) {
52460@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
52461 if (BAD_ADDR(addr))
52462 return addr;
52463 }
52464- current->mm->start_brk = current->mm->brk = end;
52465+ current->mm->start_brk = current->mm->brk = e;
52466 return 0;
52467 }
52468
52469@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52470 elf_addr_t __user *u_rand_bytes;
52471 const char *k_platform = ELF_PLATFORM;
52472 const char *k_base_platform = ELF_BASE_PLATFORM;
52473- unsigned char k_rand_bytes[16];
52474+ u32 k_rand_bytes[4];
52475 int items;
52476 elf_addr_t *elf_info;
52477 int ei_index = 0;
52478 const struct cred *cred = current_cred();
52479 struct vm_area_struct *vma;
52480+ unsigned long saved_auxv[AT_VECTOR_SIZE];
52481
52482 /*
52483 * In some cases (e.g. Hyper-Threading), we want to avoid L1
52484@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52485 * Generate 16 random bytes for userspace PRNG seeding.
52486 */
52487 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
52488- u_rand_bytes = (elf_addr_t __user *)
52489- STACK_ALLOC(p, sizeof(k_rand_bytes));
52490+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
52491+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
52492+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
52493+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
52494+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
52495+ u_rand_bytes = (elf_addr_t __user *) p;
52496 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
52497 return -EFAULT;
52498
52499@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52500 return -EFAULT;
52501 current->mm->env_end = p;
52502
52503+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
52504+
52505 /* Put the elf_info on the stack in the right place. */
52506 sp = (elf_addr_t __user *)envp + 1;
52507- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
52508+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
52509 return -EFAULT;
52510 return 0;
52511 }
52512@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
52513 an ELF header */
52514
52515 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52516- struct file *interpreter, unsigned long *interp_map_addr,
52517- unsigned long no_base)
52518+ struct file *interpreter, unsigned long no_base)
52519 {
52520 struct elf_phdr *elf_phdata;
52521 struct elf_phdr *eppnt;
52522- unsigned long load_addr = 0;
52523+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
52524 int load_addr_set = 0;
52525 unsigned long last_bss = 0, elf_bss = 0;
52526- unsigned long error = ~0UL;
52527+ unsigned long error = -EINVAL;
52528 unsigned long total_size;
52529 int retval, i, size;
52530
52531@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52532 goto out_close;
52533 }
52534
52535+#ifdef CONFIG_PAX_SEGMEXEC
52536+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
52537+ pax_task_size = SEGMEXEC_TASK_SIZE;
52538+#endif
52539+
52540 eppnt = elf_phdata;
52541 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
52542 if (eppnt->p_type == PT_LOAD) {
52543@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52544 map_addr = elf_map(interpreter, load_addr + vaddr,
52545 eppnt, elf_prot, elf_type, total_size);
52546 total_size = 0;
52547- if (!*interp_map_addr)
52548- *interp_map_addr = map_addr;
52549 error = map_addr;
52550 if (BAD_ADDR(map_addr))
52551 goto out_close;
52552@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52553 k = load_addr + eppnt->p_vaddr;
52554 if (BAD_ADDR(k) ||
52555 eppnt->p_filesz > eppnt->p_memsz ||
52556- eppnt->p_memsz > TASK_SIZE ||
52557- TASK_SIZE - eppnt->p_memsz < k) {
52558+ eppnt->p_memsz > pax_task_size ||
52559+ pax_task_size - eppnt->p_memsz < k) {
52560 error = -ENOMEM;
52561 goto out_close;
52562 }
52563@@ -538,6 +567,315 @@ out:
52564 return error;
52565 }
52566
52567+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52568+#ifdef CONFIG_PAX_SOFTMODE
52569+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
52570+{
52571+ unsigned long pax_flags = 0UL;
52572+
52573+#ifdef CONFIG_PAX_PAGEEXEC
52574+ if (elf_phdata->p_flags & PF_PAGEEXEC)
52575+ pax_flags |= MF_PAX_PAGEEXEC;
52576+#endif
52577+
52578+#ifdef CONFIG_PAX_SEGMEXEC
52579+ if (elf_phdata->p_flags & PF_SEGMEXEC)
52580+ pax_flags |= MF_PAX_SEGMEXEC;
52581+#endif
52582+
52583+#ifdef CONFIG_PAX_EMUTRAMP
52584+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52585+ pax_flags |= MF_PAX_EMUTRAMP;
52586+#endif
52587+
52588+#ifdef CONFIG_PAX_MPROTECT
52589+ if (elf_phdata->p_flags & PF_MPROTECT)
52590+ pax_flags |= MF_PAX_MPROTECT;
52591+#endif
52592+
52593+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52594+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
52595+ pax_flags |= MF_PAX_RANDMMAP;
52596+#endif
52597+
52598+ return pax_flags;
52599+}
52600+#endif
52601+
52602+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
52603+{
52604+ unsigned long pax_flags = 0UL;
52605+
52606+#ifdef CONFIG_PAX_PAGEEXEC
52607+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
52608+ pax_flags |= MF_PAX_PAGEEXEC;
52609+#endif
52610+
52611+#ifdef CONFIG_PAX_SEGMEXEC
52612+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
52613+ pax_flags |= MF_PAX_SEGMEXEC;
52614+#endif
52615+
52616+#ifdef CONFIG_PAX_EMUTRAMP
52617+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
52618+ pax_flags |= MF_PAX_EMUTRAMP;
52619+#endif
52620+
52621+#ifdef CONFIG_PAX_MPROTECT
52622+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
52623+ pax_flags |= MF_PAX_MPROTECT;
52624+#endif
52625+
52626+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52627+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
52628+ pax_flags |= MF_PAX_RANDMMAP;
52629+#endif
52630+
52631+ return pax_flags;
52632+}
52633+#endif
52634+
52635+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
52636+#ifdef CONFIG_PAX_SOFTMODE
52637+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
52638+{
52639+ unsigned long pax_flags = 0UL;
52640+
52641+#ifdef CONFIG_PAX_PAGEEXEC
52642+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
52643+ pax_flags |= MF_PAX_PAGEEXEC;
52644+#endif
52645+
52646+#ifdef CONFIG_PAX_SEGMEXEC
52647+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
52648+ pax_flags |= MF_PAX_SEGMEXEC;
52649+#endif
52650+
52651+#ifdef CONFIG_PAX_EMUTRAMP
52652+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52653+ pax_flags |= MF_PAX_EMUTRAMP;
52654+#endif
52655+
52656+#ifdef CONFIG_PAX_MPROTECT
52657+ if (pax_flags_softmode & MF_PAX_MPROTECT)
52658+ pax_flags |= MF_PAX_MPROTECT;
52659+#endif
52660+
52661+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52662+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
52663+ pax_flags |= MF_PAX_RANDMMAP;
52664+#endif
52665+
52666+ return pax_flags;
52667+}
52668+#endif
52669+
52670+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
52671+{
52672+ unsigned long pax_flags = 0UL;
52673+
52674+#ifdef CONFIG_PAX_PAGEEXEC
52675+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
52676+ pax_flags |= MF_PAX_PAGEEXEC;
52677+#endif
52678+
52679+#ifdef CONFIG_PAX_SEGMEXEC
52680+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
52681+ pax_flags |= MF_PAX_SEGMEXEC;
52682+#endif
52683+
52684+#ifdef CONFIG_PAX_EMUTRAMP
52685+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
52686+ pax_flags |= MF_PAX_EMUTRAMP;
52687+#endif
52688+
52689+#ifdef CONFIG_PAX_MPROTECT
52690+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
52691+ pax_flags |= MF_PAX_MPROTECT;
52692+#endif
52693+
52694+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52695+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
52696+ pax_flags |= MF_PAX_RANDMMAP;
52697+#endif
52698+
52699+ return pax_flags;
52700+}
52701+#endif
52702+
52703+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52704+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
52705+{
52706+ unsigned long pax_flags = 0UL;
52707+
52708+#ifdef CONFIG_PAX_EI_PAX
52709+
52710+#ifdef CONFIG_PAX_PAGEEXEC
52711+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
52712+ pax_flags |= MF_PAX_PAGEEXEC;
52713+#endif
52714+
52715+#ifdef CONFIG_PAX_SEGMEXEC
52716+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
52717+ pax_flags |= MF_PAX_SEGMEXEC;
52718+#endif
52719+
52720+#ifdef CONFIG_PAX_EMUTRAMP
52721+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
52722+ pax_flags |= MF_PAX_EMUTRAMP;
52723+#endif
52724+
52725+#ifdef CONFIG_PAX_MPROTECT
52726+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
52727+ pax_flags |= MF_PAX_MPROTECT;
52728+#endif
52729+
52730+#ifdef CONFIG_PAX_ASLR
52731+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
52732+ pax_flags |= MF_PAX_RANDMMAP;
52733+#endif
52734+
52735+#else
52736+
52737+#ifdef CONFIG_PAX_PAGEEXEC
52738+ pax_flags |= MF_PAX_PAGEEXEC;
52739+#endif
52740+
52741+#ifdef CONFIG_PAX_SEGMEXEC
52742+ pax_flags |= MF_PAX_SEGMEXEC;
52743+#endif
52744+
52745+#ifdef CONFIG_PAX_MPROTECT
52746+ pax_flags |= MF_PAX_MPROTECT;
52747+#endif
52748+
52749+#ifdef CONFIG_PAX_RANDMMAP
52750+ if (randomize_va_space)
52751+ pax_flags |= MF_PAX_RANDMMAP;
52752+#endif
52753+
52754+#endif
52755+
52756+ return pax_flags;
52757+}
52758+
52759+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
52760+{
52761+
52762+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52763+ unsigned long i;
52764+
52765+ for (i = 0UL; i < elf_ex->e_phnum; i++)
52766+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
52767+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
52768+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
52769+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
52770+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
52771+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
52772+ return ~0UL;
52773+
52774+#ifdef CONFIG_PAX_SOFTMODE
52775+ if (pax_softmode)
52776+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
52777+ else
52778+#endif
52779+
52780+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
52781+ break;
52782+ }
52783+#endif
52784+
52785+ return ~0UL;
52786+}
52787+
52788+static unsigned long pax_parse_xattr_pax(struct file * const file)
52789+{
52790+
52791+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
52792+ ssize_t xattr_size, i;
52793+ unsigned char xattr_value[sizeof("pemrs") - 1];
52794+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
52795+
52796+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
52797+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
52798+ return ~0UL;
52799+
52800+ for (i = 0; i < xattr_size; i++)
52801+ switch (xattr_value[i]) {
52802+ default:
52803+ return ~0UL;
52804+
52805+#define parse_flag(option1, option2, flag) \
52806+ case option1: \
52807+ if (pax_flags_hardmode & MF_PAX_##flag) \
52808+ return ~0UL; \
52809+ pax_flags_hardmode |= MF_PAX_##flag; \
52810+ break; \
52811+ case option2: \
52812+ if (pax_flags_softmode & MF_PAX_##flag) \
52813+ return ~0UL; \
52814+ pax_flags_softmode |= MF_PAX_##flag; \
52815+ break;
52816+
52817+ parse_flag('p', 'P', PAGEEXEC);
52818+ parse_flag('e', 'E', EMUTRAMP);
52819+ parse_flag('m', 'M', MPROTECT);
52820+ parse_flag('r', 'R', RANDMMAP);
52821+ parse_flag('s', 'S', SEGMEXEC);
52822+
52823+#undef parse_flag
52824+ }
52825+
52826+ if (pax_flags_hardmode & pax_flags_softmode)
52827+ return ~0UL;
52828+
52829+#ifdef CONFIG_PAX_SOFTMODE
52830+ if (pax_softmode)
52831+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
52832+ else
52833+#endif
52834+
52835+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
52836+#else
52837+ return ~0UL;
52838+#endif
52839+
52840+}
52841+
52842+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
52843+{
52844+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
52845+
52846+ pax_flags = pax_parse_ei_pax(elf_ex);
52847+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
52848+ xattr_pax_flags = pax_parse_xattr_pax(file);
52849+
52850+ if (pt_pax_flags == ~0UL)
52851+ pt_pax_flags = xattr_pax_flags;
52852+ else if (xattr_pax_flags == ~0UL)
52853+ xattr_pax_flags = pt_pax_flags;
52854+ if (pt_pax_flags != xattr_pax_flags)
52855+ return -EINVAL;
52856+ if (pt_pax_flags != ~0UL)
52857+ pax_flags = pt_pax_flags;
52858+
52859+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
52860+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52861+ if ((__supported_pte_mask & _PAGE_NX))
52862+ pax_flags &= ~MF_PAX_SEGMEXEC;
52863+ else
52864+ pax_flags &= ~MF_PAX_PAGEEXEC;
52865+ }
52866+#endif
52867+
52868+ if (0 > pax_check_flags(&pax_flags))
52869+ return -EINVAL;
52870+
52871+ current->mm->pax_flags = pax_flags;
52872+ return 0;
52873+}
52874+#endif
52875+
52876 /*
52877 * These are the functions used to load ELF style executables and shared
52878 * libraries. There is no binary dependent code anywhere else.
52879@@ -554,6 +892,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
52880 {
52881 unsigned int random_variable = 0;
52882
52883+#ifdef CONFIG_PAX_RANDUSTACK
52884+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
52885+ return stack_top - current->mm->delta_stack;
52886+#endif
52887+
52888 if ((current->flags & PF_RANDOMIZE) &&
52889 !(current->personality & ADDR_NO_RANDOMIZE)) {
52890 random_variable = get_random_int() & STACK_RND_MASK;
52891@@ -572,7 +915,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
52892 unsigned long load_addr = 0, load_bias = 0;
52893 int load_addr_set = 0;
52894 char * elf_interpreter = NULL;
52895- unsigned long error;
52896+ unsigned long error = 0;
52897 struct elf_phdr *elf_ppnt, *elf_phdata;
52898 unsigned long elf_bss, elf_brk;
52899 int retval, i;
52900@@ -582,12 +925,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
52901 unsigned long start_code, end_code, start_data, end_data;
52902 unsigned long reloc_func_desc __maybe_unused = 0;
52903 int executable_stack = EXSTACK_DEFAULT;
52904- unsigned long def_flags = 0;
52905 struct pt_regs *regs = current_pt_regs();
52906 struct {
52907 struct elfhdr elf_ex;
52908 struct elfhdr interp_elf_ex;
52909 } *loc;
52910+ unsigned long pax_task_size = TASK_SIZE;
52911
52912 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
52913 if (!loc) {
52914@@ -723,11 +1066,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
52915 goto out_free_dentry;
52916
52917 /* OK, This is the point of no return */
52918- current->mm->def_flags = def_flags;
52919+
52920+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52921+ current->mm->pax_flags = 0UL;
52922+#endif
52923+
52924+#ifdef CONFIG_PAX_DLRESOLVE
52925+ current->mm->call_dl_resolve = 0UL;
52926+#endif
52927+
52928+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
52929+ current->mm->call_syscall = 0UL;
52930+#endif
52931+
52932+#ifdef CONFIG_PAX_ASLR
52933+ current->mm->delta_mmap = 0UL;
52934+ current->mm->delta_stack = 0UL;
52935+#endif
52936+
52937+ current->mm->def_flags = 0;
52938+
52939+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52940+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
52941+ send_sig(SIGKILL, current, 0);
52942+ goto out_free_dentry;
52943+ }
52944+#endif
52945+
52946+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
52947+ pax_set_initial_flags(bprm);
52948+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
52949+ if (pax_set_initial_flags_func)
52950+ (pax_set_initial_flags_func)(bprm);
52951+#endif
52952+
52953+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52954+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
52955+ current->mm->context.user_cs_limit = PAGE_SIZE;
52956+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
52957+ }
52958+#endif
52959+
52960+#ifdef CONFIG_PAX_SEGMEXEC
52961+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
52962+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
52963+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
52964+ pax_task_size = SEGMEXEC_TASK_SIZE;
52965+ current->mm->def_flags |= VM_NOHUGEPAGE;
52966+ }
52967+#endif
52968+
52969+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
52970+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52971+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
52972+ put_cpu();
52973+ }
52974+#endif
52975
52976 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
52977 may depend on the personality. */
52978 SET_PERSONALITY(loc->elf_ex);
52979+
52980+#ifdef CONFIG_PAX_ASLR
52981+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
52982+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
52983+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
52984+ }
52985+#endif
52986+
52987+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
52988+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52989+ executable_stack = EXSTACK_DISABLE_X;
52990+ current->personality &= ~READ_IMPLIES_EXEC;
52991+ } else
52992+#endif
52993+
52994 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
52995 current->personality |= READ_IMPLIES_EXEC;
52996
52997@@ -817,6 +1230,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
52998 #else
52999 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
53000 #endif
53001+
53002+#ifdef CONFIG_PAX_RANDMMAP
53003+ /* PaX: randomize base address at the default exe base if requested */
53004+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
53005+#ifdef CONFIG_SPARC64
53006+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
53007+#else
53008+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
53009+#endif
53010+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
53011+ elf_flags |= MAP_FIXED;
53012+ }
53013+#endif
53014+
53015 }
53016
53017 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
53018@@ -849,9 +1276,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
53019 * allowed task size. Note that p_filesz must always be
53020 * <= p_memsz so it is only necessary to check p_memsz.
53021 */
53022- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
53023- elf_ppnt->p_memsz > TASK_SIZE ||
53024- TASK_SIZE - elf_ppnt->p_memsz < k) {
53025+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
53026+ elf_ppnt->p_memsz > pax_task_size ||
53027+ pax_task_size - elf_ppnt->p_memsz < k) {
53028 /* set_brk can never work. Avoid overflows. */
53029 send_sig(SIGKILL, current, 0);
53030 retval = -EINVAL;
53031@@ -890,17 +1317,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
53032 goto out_free_dentry;
53033 }
53034 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
53035- send_sig(SIGSEGV, current, 0);
53036- retval = -EFAULT; /* Nobody gets to see this, but.. */
53037- goto out_free_dentry;
53038+ /*
53039+ * This bss-zeroing can fail if the ELF
53040+ * file specifies odd protections. So
53041+ * we don't check the return value
53042+ */
53043 }
53044
53045+#ifdef CONFIG_PAX_RANDMMAP
53046+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
53047+ unsigned long start, size, flags;
53048+ vm_flags_t vm_flags;
53049+
53050+ start = ELF_PAGEALIGN(elf_brk);
53051+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
53052+ flags = MAP_FIXED | MAP_PRIVATE;
53053+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
53054+
53055+ down_write(&current->mm->mmap_sem);
53056+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
53057+ retval = -ENOMEM;
53058+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
53059+// if (current->personality & ADDR_NO_RANDOMIZE)
53060+// vm_flags |= VM_READ | VM_MAYREAD;
53061+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
53062+ retval = IS_ERR_VALUE(start) ? start : 0;
53063+ }
53064+ up_write(&current->mm->mmap_sem);
53065+ if (retval == 0)
53066+ retval = set_brk(start + size, start + size + PAGE_SIZE);
53067+ if (retval < 0) {
53068+ send_sig(SIGKILL, current, 0);
53069+ goto out_free_dentry;
53070+ }
53071+ }
53072+#endif
53073+
53074 if (elf_interpreter) {
53075- unsigned long interp_map_addr = 0;
53076-
53077 elf_entry = load_elf_interp(&loc->interp_elf_ex,
53078 interpreter,
53079- &interp_map_addr,
53080 load_bias);
53081 if (!IS_ERR((void *)elf_entry)) {
53082 /*
53083@@ -1122,7 +1577,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
53084 * Decide what to dump of a segment, part, all or none.
53085 */
53086 static unsigned long vma_dump_size(struct vm_area_struct *vma,
53087- unsigned long mm_flags)
53088+ unsigned long mm_flags, long signr)
53089 {
53090 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
53091
53092@@ -1160,7 +1615,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
53093 if (vma->vm_file == NULL)
53094 return 0;
53095
53096- if (FILTER(MAPPED_PRIVATE))
53097+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
53098 goto whole;
53099
53100 /*
53101@@ -1385,9 +1840,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
53102 {
53103 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
53104 int i = 0;
53105- do
53106+ do {
53107 i += 2;
53108- while (auxv[i - 2] != AT_NULL);
53109+ } while (auxv[i - 2] != AT_NULL);
53110 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
53111 }
53112
53113@@ -1396,7 +1851,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
53114 {
53115 mm_segment_t old_fs = get_fs();
53116 set_fs(KERNEL_DS);
53117- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
53118+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
53119 set_fs(old_fs);
53120 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
53121 }
53122@@ -2017,14 +2472,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
53123 }
53124
53125 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
53126- unsigned long mm_flags)
53127+ struct coredump_params *cprm)
53128 {
53129 struct vm_area_struct *vma;
53130 size_t size = 0;
53131
53132 for (vma = first_vma(current, gate_vma); vma != NULL;
53133 vma = next_vma(vma, gate_vma))
53134- size += vma_dump_size(vma, mm_flags);
53135+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53136 return size;
53137 }
53138
53139@@ -2117,7 +2572,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53140
53141 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
53142
53143- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
53144+ offset += elf_core_vma_data_size(gate_vma, cprm);
53145 offset += elf_core_extra_data_size();
53146 e_shoff = offset;
53147
53148@@ -2131,10 +2586,12 @@ static int elf_core_dump(struct coredump_params *cprm)
53149 offset = dataoff;
53150
53151 size += sizeof(*elf);
53152+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53153 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
53154 goto end_coredump;
53155
53156 size += sizeof(*phdr4note);
53157+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53158 if (size > cprm->limit
53159 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
53160 goto end_coredump;
53161@@ -2148,7 +2605,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53162 phdr.p_offset = offset;
53163 phdr.p_vaddr = vma->vm_start;
53164 phdr.p_paddr = 0;
53165- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
53166+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53167 phdr.p_memsz = vma->vm_end - vma->vm_start;
53168 offset += phdr.p_filesz;
53169 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
53170@@ -2159,6 +2616,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53171 phdr.p_align = ELF_EXEC_PAGESIZE;
53172
53173 size += sizeof(phdr);
53174+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53175 if (size > cprm->limit
53176 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
53177 goto end_coredump;
53178@@ -2183,7 +2641,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53179 unsigned long addr;
53180 unsigned long end;
53181
53182- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
53183+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53184
53185 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
53186 struct page *page;
53187@@ -2192,6 +2650,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53188 page = get_dump_page(addr);
53189 if (page) {
53190 void *kaddr = kmap(page);
53191+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
53192 stop = ((size += PAGE_SIZE) > cprm->limit) ||
53193 !dump_write(cprm->file, kaddr,
53194 PAGE_SIZE);
53195@@ -2209,6 +2668,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53196
53197 if (e_phnum == PN_XNUM) {
53198 size += sizeof(*shdr4extnum);
53199+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53200 if (size > cprm->limit
53201 || !dump_write(cprm->file, shdr4extnum,
53202 sizeof(*shdr4extnum)))
53203@@ -2229,6 +2689,167 @@ out:
53204
53205 #endif /* CONFIG_ELF_CORE */
53206
53207+#ifdef CONFIG_PAX_MPROTECT
53208+/* PaX: non-PIC ELF libraries need relocations on their executable segments
53209+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
53210+ * we'll remove VM_MAYWRITE for good on RELRO segments.
53211+ *
53212+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
53213+ * basis because we want to allow the common case and not the special ones.
53214+ */
53215+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
53216+{
53217+ struct elfhdr elf_h;
53218+ struct elf_phdr elf_p;
53219+ unsigned long i;
53220+ unsigned long oldflags;
53221+ bool is_textrel_rw, is_textrel_rx, is_relro;
53222+
53223+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
53224+ return;
53225+
53226+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
53227+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
53228+
53229+#ifdef CONFIG_PAX_ELFRELOCS
53230+ /* possible TEXTREL */
53231+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
53232+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
53233+#else
53234+ is_textrel_rw = false;
53235+ is_textrel_rx = false;
53236+#endif
53237+
53238+ /* possible RELRO */
53239+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
53240+
53241+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
53242+ return;
53243+
53244+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53245+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53246+
53247+#ifdef CONFIG_PAX_ETEXECRELOCS
53248+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53249+#else
53250+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
53251+#endif
53252+
53253+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53254+ !elf_check_arch(&elf_h) ||
53255+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53256+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53257+ return;
53258+
53259+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53260+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53261+ return;
53262+ switch (elf_p.p_type) {
53263+ case PT_DYNAMIC:
53264+ if (!is_textrel_rw && !is_textrel_rx)
53265+ continue;
53266+ i = 0UL;
53267+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
53268+ elf_dyn dyn;
53269+
53270+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
53271+ break;
53272+ if (dyn.d_tag == DT_NULL)
53273+ break;
53274+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
53275+ gr_log_textrel(vma);
53276+ if (is_textrel_rw)
53277+ vma->vm_flags |= VM_MAYWRITE;
53278+ else
53279+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
53280+ vma->vm_flags &= ~VM_MAYWRITE;
53281+ break;
53282+ }
53283+ i++;
53284+ }
53285+ is_textrel_rw = false;
53286+ is_textrel_rx = false;
53287+ continue;
53288+
53289+ case PT_GNU_RELRO:
53290+ if (!is_relro)
53291+ continue;
53292+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
53293+ vma->vm_flags &= ~VM_MAYWRITE;
53294+ is_relro = false;
53295+ continue;
53296+
53297+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53298+ case PT_PAX_FLAGS: {
53299+ const char *msg_mprotect = "", *msg_emutramp = "";
53300+ char *buffer_lib, *buffer_exe;
53301+
53302+ if (elf_p.p_flags & PF_NOMPROTECT)
53303+ msg_mprotect = "MPROTECT disabled";
53304+
53305+#ifdef CONFIG_PAX_EMUTRAMP
53306+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
53307+ msg_emutramp = "EMUTRAMP enabled";
53308+#endif
53309+
53310+ if (!msg_mprotect[0] && !msg_emutramp[0])
53311+ continue;
53312+
53313+ if (!printk_ratelimit())
53314+ continue;
53315+
53316+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
53317+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
53318+ if (buffer_lib && buffer_exe) {
53319+ char *path_lib, *path_exe;
53320+
53321+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
53322+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
53323+
53324+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
53325+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
53326+
53327+ }
53328+ free_page((unsigned long)buffer_exe);
53329+ free_page((unsigned long)buffer_lib);
53330+ continue;
53331+ }
53332+#endif
53333+
53334+ }
53335+ }
53336+}
53337+#endif
53338+
53339+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
53340+
53341+extern int grsec_enable_log_rwxmaps;
53342+
53343+static void elf_handle_mmap(struct file *file)
53344+{
53345+ struct elfhdr elf_h;
53346+ struct elf_phdr elf_p;
53347+ unsigned long i;
53348+
53349+ if (!grsec_enable_log_rwxmaps)
53350+ return;
53351+
53352+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53353+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53354+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
53355+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53356+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53357+ return;
53358+
53359+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53360+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53361+ return;
53362+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
53363+ gr_log_ptgnustack(file);
53364+ }
53365+}
53366+#endif
53367+
53368 static int __init init_elf_binfmt(void)
53369 {
53370 register_binfmt(&elf_format);
53371diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
53372index d50bbe5..af3b649 100644
53373--- a/fs/binfmt_flat.c
53374+++ b/fs/binfmt_flat.c
53375@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
53376 realdatastart = (unsigned long) -ENOMEM;
53377 printk("Unable to allocate RAM for process data, errno %d\n",
53378 (int)-realdatastart);
53379+ down_write(&current->mm->mmap_sem);
53380 vm_munmap(textpos, text_len);
53381+ up_write(&current->mm->mmap_sem);
53382 ret = realdatastart;
53383 goto err;
53384 }
53385@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53386 }
53387 if (IS_ERR_VALUE(result)) {
53388 printk("Unable to read data+bss, errno %d\n", (int)-result);
53389+ down_write(&current->mm->mmap_sem);
53390 vm_munmap(textpos, text_len);
53391 vm_munmap(realdatastart, len);
53392+ up_write(&current->mm->mmap_sem);
53393 ret = result;
53394 goto err;
53395 }
53396@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53397 }
53398 if (IS_ERR_VALUE(result)) {
53399 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
53400+ down_write(&current->mm->mmap_sem);
53401 vm_munmap(textpos, text_len + data_len + extra +
53402 MAX_SHARED_LIBS * sizeof(unsigned long));
53403+ up_write(&current->mm->mmap_sem);
53404 ret = result;
53405 goto err;
53406 }
53407diff --git a/fs/bio.c b/fs/bio.c
53408index c5eae72..599e3cf 100644
53409--- a/fs/bio.c
53410+++ b/fs/bio.c
53411@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
53412 /*
53413 * Overflow, abort
53414 */
53415- if (end < start)
53416+ if (end < start || end - start > INT_MAX - nr_pages)
53417 return ERR_PTR(-EINVAL);
53418
53419 nr_pages += end - start;
53420@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
53421 /*
53422 * Overflow, abort
53423 */
53424- if (end < start)
53425+ if (end < start || end - start > INT_MAX - nr_pages)
53426 return ERR_PTR(-EINVAL);
53427
53428 nr_pages += end - start;
53429@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
53430 const int read = bio_data_dir(bio) == READ;
53431 struct bio_map_data *bmd = bio->bi_private;
53432 int i;
53433- char *p = bmd->sgvecs[0].iov_base;
53434+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
53435
53436 bio_for_each_segment_all(bvec, bio, i) {
53437 char *addr = page_address(bvec->bv_page);
53438diff --git a/fs/block_dev.c b/fs/block_dev.c
53439index c7bda5c..2121e94 100644
53440--- a/fs/block_dev.c
53441+++ b/fs/block_dev.c
53442@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
53443 else if (bdev->bd_contains == bdev)
53444 return true; /* is a whole device which isn't held */
53445
53446- else if (whole->bd_holder == bd_may_claim)
53447+ else if (whole->bd_holder == (void *)bd_may_claim)
53448 return true; /* is a partition of a device that is being partitioned */
53449 else if (whole->bd_holder != NULL)
53450 return false; /* is a partition of a held device */
53451diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
53452index ed50460..fe84385 100644
53453--- a/fs/btrfs/ctree.c
53454+++ b/fs/btrfs/ctree.c
53455@@ -1076,9 +1076,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
53456 free_extent_buffer(buf);
53457 add_root_to_dirty_list(root);
53458 } else {
53459- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
53460- parent_start = parent->start;
53461- else
53462+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
53463+ if (parent)
53464+ parent_start = parent->start;
53465+ else
53466+ parent_start = 0;
53467+ } else
53468 parent_start = 0;
53469
53470 WARN_ON(trans->transid != btrfs_header_generation(parent));
53471diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
53472index 3755109..e3d457f 100644
53473--- a/fs/btrfs/delayed-inode.c
53474+++ b/fs/btrfs/delayed-inode.c
53475@@ -458,7 +458,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
53476
53477 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
53478 {
53479- int seq = atomic_inc_return(&delayed_root->items_seq);
53480+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
53481 if ((atomic_dec_return(&delayed_root->items) <
53482 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
53483 waitqueue_active(&delayed_root->wait))
53484@@ -1377,7 +1377,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
53485 static int refs_newer(struct btrfs_delayed_root *delayed_root,
53486 int seq, int count)
53487 {
53488- int val = atomic_read(&delayed_root->items_seq);
53489+ int val = atomic_read_unchecked(&delayed_root->items_seq);
53490
53491 if (val < seq || val >= seq + count)
53492 return 1;
53493@@ -1394,7 +1394,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
53494 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
53495 return;
53496
53497- seq = atomic_read(&delayed_root->items_seq);
53498+ seq = atomic_read_unchecked(&delayed_root->items_seq);
53499
53500 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
53501 int ret;
53502diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
53503index a4b38f9..f86a509 100644
53504--- a/fs/btrfs/delayed-inode.h
53505+++ b/fs/btrfs/delayed-inode.h
53506@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
53507 */
53508 struct list_head prepare_list;
53509 atomic_t items; /* for delayed items */
53510- atomic_t items_seq; /* for delayed items */
53511+ atomic_unchecked_t items_seq; /* for delayed items */
53512 int nodes; /* for delayed nodes */
53513 wait_queue_head_t wait;
53514 };
53515@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
53516 struct btrfs_delayed_root *delayed_root)
53517 {
53518 atomic_set(&delayed_root->items, 0);
53519- atomic_set(&delayed_root->items_seq, 0);
53520+ atomic_set_unchecked(&delayed_root->items_seq, 0);
53521 delayed_root->nodes = 0;
53522 spin_lock_init(&delayed_root->lock);
53523 init_waitqueue_head(&delayed_root->wait);
53524diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
53525index 238a055..1e33cd5 100644
53526--- a/fs/btrfs/ioctl.c
53527+++ b/fs/btrfs/ioctl.c
53528@@ -3097,9 +3097,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53529 for (i = 0; i < num_types; i++) {
53530 struct btrfs_space_info *tmp;
53531
53532+ /* Don't copy in more than we allocated */
53533 if (!slot_count)
53534 break;
53535
53536+ slot_count--;
53537+
53538 info = NULL;
53539 rcu_read_lock();
53540 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
53541@@ -3121,10 +3124,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53542 memcpy(dest, &space, sizeof(space));
53543 dest++;
53544 space_args.total_spaces++;
53545- slot_count--;
53546 }
53547- if (!slot_count)
53548- break;
53549 }
53550 up_read(&info->groups_sem);
53551 }
53552diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
53553index 8eb6191..eda91e2 100644
53554--- a/fs/btrfs/super.c
53555+++ b/fs/btrfs/super.c
53556@@ -264,7 +264,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
53557 function, line, errstr);
53558 return;
53559 }
53560- ACCESS_ONCE(trans->transaction->aborted) = errno;
53561+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
53562 /* Wake up anybody who may be waiting on this transaction */
53563 wake_up(&root->fs_info->transaction_wait);
53564 wake_up(&root->fs_info->transaction_blocked_wait);
53565diff --git a/fs/buffer.c b/fs/buffer.c
53566index 4d74335..b0df7f9 100644
53567--- a/fs/buffer.c
53568+++ b/fs/buffer.c
53569@@ -3416,7 +3416,7 @@ void __init buffer_init(void)
53570 bh_cachep = kmem_cache_create("buffer_head",
53571 sizeof(struct buffer_head), 0,
53572 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
53573- SLAB_MEM_SPREAD),
53574+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
53575 NULL);
53576
53577 /*
53578diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
53579index 622f469..e8d2d55 100644
53580--- a/fs/cachefiles/bind.c
53581+++ b/fs/cachefiles/bind.c
53582@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
53583 args);
53584
53585 /* start by checking things over */
53586- ASSERT(cache->fstop_percent >= 0 &&
53587- cache->fstop_percent < cache->fcull_percent &&
53588+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
53589 cache->fcull_percent < cache->frun_percent &&
53590 cache->frun_percent < 100);
53591
53592- ASSERT(cache->bstop_percent >= 0 &&
53593- cache->bstop_percent < cache->bcull_percent &&
53594+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
53595 cache->bcull_percent < cache->brun_percent &&
53596 cache->brun_percent < 100);
53597
53598diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
53599index 0a1467b..6a53245 100644
53600--- a/fs/cachefiles/daemon.c
53601+++ b/fs/cachefiles/daemon.c
53602@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
53603 if (n > buflen)
53604 return -EMSGSIZE;
53605
53606- if (copy_to_user(_buffer, buffer, n) != 0)
53607+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
53608 return -EFAULT;
53609
53610 return n;
53611@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
53612 if (test_bit(CACHEFILES_DEAD, &cache->flags))
53613 return -EIO;
53614
53615- if (datalen < 0 || datalen > PAGE_SIZE - 1)
53616+ if (datalen > PAGE_SIZE - 1)
53617 return -EOPNOTSUPP;
53618
53619 /* drag the command string into the kernel so we can parse it */
53620@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
53621 if (args[0] != '%' || args[1] != '\0')
53622 return -EINVAL;
53623
53624- if (fstop < 0 || fstop >= cache->fcull_percent)
53625+ if (fstop >= cache->fcull_percent)
53626 return cachefiles_daemon_range_error(cache, args);
53627
53628 cache->fstop_percent = fstop;
53629@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
53630 if (args[0] != '%' || args[1] != '\0')
53631 return -EINVAL;
53632
53633- if (bstop < 0 || bstop >= cache->bcull_percent)
53634+ if (bstop >= cache->bcull_percent)
53635 return cachefiles_daemon_range_error(cache, args);
53636
53637 cache->bstop_percent = bstop;
53638diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
53639index 4938251..7e01445 100644
53640--- a/fs/cachefiles/internal.h
53641+++ b/fs/cachefiles/internal.h
53642@@ -59,7 +59,7 @@ struct cachefiles_cache {
53643 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
53644 struct rb_root active_nodes; /* active nodes (can't be culled) */
53645 rwlock_t active_lock; /* lock for active_nodes */
53646- atomic_t gravecounter; /* graveyard uniquifier */
53647+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
53648 unsigned frun_percent; /* when to stop culling (% files) */
53649 unsigned fcull_percent; /* when to start culling (% files) */
53650 unsigned fstop_percent; /* when to stop allocating (% files) */
53651@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
53652 * proc.c
53653 */
53654 #ifdef CONFIG_CACHEFILES_HISTOGRAM
53655-extern atomic_t cachefiles_lookup_histogram[HZ];
53656-extern atomic_t cachefiles_mkdir_histogram[HZ];
53657-extern atomic_t cachefiles_create_histogram[HZ];
53658+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
53659+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
53660+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
53661
53662 extern int __init cachefiles_proc_init(void);
53663 extern void cachefiles_proc_cleanup(void);
53664 static inline
53665-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
53666+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
53667 {
53668 unsigned long jif = jiffies - start_jif;
53669 if (jif >= HZ)
53670 jif = HZ - 1;
53671- atomic_inc(&histogram[jif]);
53672+ atomic_inc_unchecked(&histogram[jif]);
53673 }
53674
53675 #else
53676diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
53677index 25badd1..d70d918 100644
53678--- a/fs/cachefiles/namei.c
53679+++ b/fs/cachefiles/namei.c
53680@@ -317,7 +317,7 @@ try_again:
53681 /* first step is to make up a grave dentry in the graveyard */
53682 sprintf(nbuffer, "%08x%08x",
53683 (uint32_t) get_seconds(),
53684- (uint32_t) atomic_inc_return(&cache->gravecounter));
53685+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
53686
53687 /* do the multiway lock magic */
53688 trap = lock_rename(cache->graveyard, dir);
53689diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
53690index eccd339..4c1d995 100644
53691--- a/fs/cachefiles/proc.c
53692+++ b/fs/cachefiles/proc.c
53693@@ -14,9 +14,9 @@
53694 #include <linux/seq_file.h>
53695 #include "internal.h"
53696
53697-atomic_t cachefiles_lookup_histogram[HZ];
53698-atomic_t cachefiles_mkdir_histogram[HZ];
53699-atomic_t cachefiles_create_histogram[HZ];
53700+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
53701+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
53702+atomic_unchecked_t cachefiles_create_histogram[HZ];
53703
53704 /*
53705 * display the latency histogram
53706@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
53707 return 0;
53708 default:
53709 index = (unsigned long) v - 3;
53710- x = atomic_read(&cachefiles_lookup_histogram[index]);
53711- y = atomic_read(&cachefiles_mkdir_histogram[index]);
53712- z = atomic_read(&cachefiles_create_histogram[index]);
53713+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
53714+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
53715+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
53716 if (x == 0 && y == 0 && z == 0)
53717 return 0;
53718
53719diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
53720index ebaff36..7e3ea26 100644
53721--- a/fs/cachefiles/rdwr.c
53722+++ b/fs/cachefiles/rdwr.c
53723@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
53724 old_fs = get_fs();
53725 set_fs(KERNEL_DS);
53726 ret = file->f_op->write(
53727- file, (const void __user *) data, len, &pos);
53728+ file, (const void __force_user *) data, len, &pos);
53729 set_fs(old_fs);
53730 kunmap(page);
53731 file_end_write(file);
53732diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
53733index a40ceda..f43d17c 100644
53734--- a/fs/ceph/dir.c
53735+++ b/fs/ceph/dir.c
53736@@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
53737 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
53738 struct ceph_mds_client *mdsc = fsc->mdsc;
53739 unsigned frag = fpos_frag(ctx->pos);
53740- int off = fpos_off(ctx->pos);
53741+ unsigned int off = fpos_off(ctx->pos);
53742 int err;
53743 u32 ftype;
53744 struct ceph_mds_reply_info_parsed *rinfo;
53745diff --git a/fs/ceph/super.c b/fs/ceph/super.c
53746index 6627b26..634ec4b 100644
53747--- a/fs/ceph/super.c
53748+++ b/fs/ceph/super.c
53749@@ -839,7 +839,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
53750 /*
53751 * construct our own bdi so we can control readahead, etc.
53752 */
53753-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
53754+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
53755
53756 static int ceph_register_bdi(struct super_block *sb,
53757 struct ceph_fs_client *fsc)
53758@@ -856,7 +856,7 @@ static int ceph_register_bdi(struct super_block *sb,
53759 default_backing_dev_info.ra_pages;
53760
53761 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
53762- atomic_long_inc_return(&bdi_seq));
53763+ atomic_long_inc_return_unchecked(&bdi_seq));
53764 if (!err)
53765 sb->s_bdi = &fsc->backing_dev_info;
53766 return err;
53767diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
53768index f3ac415..3d2420c 100644
53769--- a/fs/cifs/cifs_debug.c
53770+++ b/fs/cifs/cifs_debug.c
53771@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
53772
53773 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
53774 #ifdef CONFIG_CIFS_STATS2
53775- atomic_set(&totBufAllocCount, 0);
53776- atomic_set(&totSmBufAllocCount, 0);
53777+ atomic_set_unchecked(&totBufAllocCount, 0);
53778+ atomic_set_unchecked(&totSmBufAllocCount, 0);
53779 #endif /* CONFIG_CIFS_STATS2 */
53780 spin_lock(&cifs_tcp_ses_lock);
53781 list_for_each(tmp1, &cifs_tcp_ses_list) {
53782@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
53783 tcon = list_entry(tmp3,
53784 struct cifs_tcon,
53785 tcon_list);
53786- atomic_set(&tcon->num_smbs_sent, 0);
53787+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
53788 if (server->ops->clear_stats)
53789 server->ops->clear_stats(tcon);
53790 }
53791@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
53792 smBufAllocCount.counter, cifs_min_small);
53793 #ifdef CONFIG_CIFS_STATS2
53794 seq_printf(m, "Total Large %d Small %d Allocations\n",
53795- atomic_read(&totBufAllocCount),
53796- atomic_read(&totSmBufAllocCount));
53797+ atomic_read_unchecked(&totBufAllocCount),
53798+ atomic_read_unchecked(&totSmBufAllocCount));
53799 #endif /* CONFIG_CIFS_STATS2 */
53800
53801 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
53802@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
53803 if (tcon->need_reconnect)
53804 seq_puts(m, "\tDISCONNECTED ");
53805 seq_printf(m, "\nSMBs: %d",
53806- atomic_read(&tcon->num_smbs_sent));
53807+ atomic_read_unchecked(&tcon->num_smbs_sent));
53808 if (server->ops->print_stats)
53809 server->ops->print_stats(m, tcon);
53810 }
53811diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
53812index 85ea98d..b3ed4d6 100644
53813--- a/fs/cifs/cifsfs.c
53814+++ b/fs/cifs/cifsfs.c
53815@@ -1037,7 +1037,7 @@ cifs_init_request_bufs(void)
53816 */
53817 cifs_req_cachep = kmem_cache_create("cifs_request",
53818 CIFSMaxBufSize + max_hdr_size, 0,
53819- SLAB_HWCACHE_ALIGN, NULL);
53820+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
53821 if (cifs_req_cachep == NULL)
53822 return -ENOMEM;
53823
53824@@ -1064,7 +1064,7 @@ cifs_init_request_bufs(void)
53825 efficient to alloc 1 per page off the slab compared to 17K (5page)
53826 alloc of large cifs buffers even when page debugging is on */
53827 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
53828- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
53829+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
53830 NULL);
53831 if (cifs_sm_req_cachep == NULL) {
53832 mempool_destroy(cifs_req_poolp);
53833@@ -1149,8 +1149,8 @@ init_cifs(void)
53834 atomic_set(&bufAllocCount, 0);
53835 atomic_set(&smBufAllocCount, 0);
53836 #ifdef CONFIG_CIFS_STATS2
53837- atomic_set(&totBufAllocCount, 0);
53838- atomic_set(&totSmBufAllocCount, 0);
53839+ atomic_set_unchecked(&totBufAllocCount, 0);
53840+ atomic_set_unchecked(&totSmBufAllocCount, 0);
53841 #endif /* CONFIG_CIFS_STATS2 */
53842
53843 atomic_set(&midCount, 0);
53844diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
53845index 52ca861..47f309c 100644
53846--- a/fs/cifs/cifsglob.h
53847+++ b/fs/cifs/cifsglob.h
53848@@ -756,35 +756,35 @@ struct cifs_tcon {
53849 __u16 Flags; /* optional support bits */
53850 enum statusEnum tidStatus;
53851 #ifdef CONFIG_CIFS_STATS
53852- atomic_t num_smbs_sent;
53853+ atomic_unchecked_t num_smbs_sent;
53854 union {
53855 struct {
53856- atomic_t num_writes;
53857- atomic_t num_reads;
53858- atomic_t num_flushes;
53859- atomic_t num_oplock_brks;
53860- atomic_t num_opens;
53861- atomic_t num_closes;
53862- atomic_t num_deletes;
53863- atomic_t num_mkdirs;
53864- atomic_t num_posixopens;
53865- atomic_t num_posixmkdirs;
53866- atomic_t num_rmdirs;
53867- atomic_t num_renames;
53868- atomic_t num_t2renames;
53869- atomic_t num_ffirst;
53870- atomic_t num_fnext;
53871- atomic_t num_fclose;
53872- atomic_t num_hardlinks;
53873- atomic_t num_symlinks;
53874- atomic_t num_locks;
53875- atomic_t num_acl_get;
53876- atomic_t num_acl_set;
53877+ atomic_unchecked_t num_writes;
53878+ atomic_unchecked_t num_reads;
53879+ atomic_unchecked_t num_flushes;
53880+ atomic_unchecked_t num_oplock_brks;
53881+ atomic_unchecked_t num_opens;
53882+ atomic_unchecked_t num_closes;
53883+ atomic_unchecked_t num_deletes;
53884+ atomic_unchecked_t num_mkdirs;
53885+ atomic_unchecked_t num_posixopens;
53886+ atomic_unchecked_t num_posixmkdirs;
53887+ atomic_unchecked_t num_rmdirs;
53888+ atomic_unchecked_t num_renames;
53889+ atomic_unchecked_t num_t2renames;
53890+ atomic_unchecked_t num_ffirst;
53891+ atomic_unchecked_t num_fnext;
53892+ atomic_unchecked_t num_fclose;
53893+ atomic_unchecked_t num_hardlinks;
53894+ atomic_unchecked_t num_symlinks;
53895+ atomic_unchecked_t num_locks;
53896+ atomic_unchecked_t num_acl_get;
53897+ atomic_unchecked_t num_acl_set;
53898 } cifs_stats;
53899 #ifdef CONFIG_CIFS_SMB2
53900 struct {
53901- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
53902- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
53903+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
53904+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
53905 } smb2_stats;
53906 #endif /* CONFIG_CIFS_SMB2 */
53907 } stats;
53908@@ -1096,7 +1096,7 @@ convert_delimiter(char *path, char delim)
53909 }
53910
53911 #ifdef CONFIG_CIFS_STATS
53912-#define cifs_stats_inc atomic_inc
53913+#define cifs_stats_inc atomic_inc_unchecked
53914
53915 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
53916 unsigned int bytes)
53917@@ -1461,8 +1461,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
53918 /* Various Debug counters */
53919 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
53920 #ifdef CONFIG_CIFS_STATS2
53921-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
53922-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
53923+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
53924+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
53925 #endif
53926 GLOBAL_EXTERN atomic_t smBufAllocCount;
53927 GLOBAL_EXTERN atomic_t midCount;
53928diff --git a/fs/cifs/link.c b/fs/cifs/link.c
53929index 562044f..4af6a17 100644
53930--- a/fs/cifs/link.c
53931+++ b/fs/cifs/link.c
53932@@ -638,7 +638,7 @@ symlink_exit:
53933
53934 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
53935 {
53936- char *p = nd_get_link(nd);
53937+ const char *p = nd_get_link(nd);
53938 if (!IS_ERR(p))
53939 kfree(p);
53940 }
53941diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
53942index f7d4b22..1254377 100644
53943--- a/fs/cifs/misc.c
53944+++ b/fs/cifs/misc.c
53945@@ -169,7 +169,7 @@ cifs_buf_get(void)
53946 memset(ret_buf, 0, buf_size + 3);
53947 atomic_inc(&bufAllocCount);
53948 #ifdef CONFIG_CIFS_STATS2
53949- atomic_inc(&totBufAllocCount);
53950+ atomic_inc_unchecked(&totBufAllocCount);
53951 #endif /* CONFIG_CIFS_STATS2 */
53952 }
53953
53954@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
53955 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
53956 atomic_inc(&smBufAllocCount);
53957 #ifdef CONFIG_CIFS_STATS2
53958- atomic_inc(&totSmBufAllocCount);
53959+ atomic_inc_unchecked(&totSmBufAllocCount);
53960 #endif /* CONFIG_CIFS_STATS2 */
53961
53962 }
53963diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
53964index 6094397..51e576f 100644
53965--- a/fs/cifs/smb1ops.c
53966+++ b/fs/cifs/smb1ops.c
53967@@ -590,27 +590,27 @@ static void
53968 cifs_clear_stats(struct cifs_tcon *tcon)
53969 {
53970 #ifdef CONFIG_CIFS_STATS
53971- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
53972- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
53973- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
53974- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
53975- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
53976- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
53977- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
53978- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
53979- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
53980- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
53981- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
53982- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
53983- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
53984- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
53985- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
53986- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
53987- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
53988- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
53989- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
53990- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
53991- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
53992+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
53993+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
53994+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
53995+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
53996+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
53997+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
53998+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
53999+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
54000+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
54001+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
54002+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
54003+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
54004+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
54005+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
54006+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
54007+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
54008+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
54009+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
54010+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
54011+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
54012+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
54013 #endif
54014 }
54015
54016@@ -619,36 +619,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
54017 {
54018 #ifdef CONFIG_CIFS_STATS
54019 seq_printf(m, " Oplocks breaks: %d",
54020- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
54021+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
54022 seq_printf(m, "\nReads: %d Bytes: %llu",
54023- atomic_read(&tcon->stats.cifs_stats.num_reads),
54024+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
54025 (long long)(tcon->bytes_read));
54026 seq_printf(m, "\nWrites: %d Bytes: %llu",
54027- atomic_read(&tcon->stats.cifs_stats.num_writes),
54028+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
54029 (long long)(tcon->bytes_written));
54030 seq_printf(m, "\nFlushes: %d",
54031- atomic_read(&tcon->stats.cifs_stats.num_flushes));
54032+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
54033 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
54034- atomic_read(&tcon->stats.cifs_stats.num_locks),
54035- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
54036- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
54037+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
54038+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
54039+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
54040 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
54041- atomic_read(&tcon->stats.cifs_stats.num_opens),
54042- atomic_read(&tcon->stats.cifs_stats.num_closes),
54043- atomic_read(&tcon->stats.cifs_stats.num_deletes));
54044+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
54045+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
54046+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
54047 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
54048- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
54049- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
54050+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
54051+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
54052 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
54053- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
54054- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
54055+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
54056+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
54057 seq_printf(m, "\nRenames: %d T2 Renames %d",
54058- atomic_read(&tcon->stats.cifs_stats.num_renames),
54059- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
54060+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
54061+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
54062 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
54063- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
54064- atomic_read(&tcon->stats.cifs_stats.num_fnext),
54065- atomic_read(&tcon->stats.cifs_stats.num_fclose));
54066+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
54067+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
54068+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
54069 #endif
54070 }
54071
54072diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
54073index f259e6c..ca948ff 100644
54074--- a/fs/cifs/smb2ops.c
54075+++ b/fs/cifs/smb2ops.c
54076@@ -281,8 +281,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
54077 #ifdef CONFIG_CIFS_STATS
54078 int i;
54079 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
54080- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
54081- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
54082+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
54083+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
54084 }
54085 #endif
54086 }
54087@@ -310,65 +310,65 @@ static void
54088 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
54089 {
54090 #ifdef CONFIG_CIFS_STATS
54091- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
54092- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
54093+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
54094+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
54095 seq_printf(m, "\nNegotiates: %d sent %d failed",
54096- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
54097- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
54098+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
54099+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
54100 seq_printf(m, "\nSessionSetups: %d sent %d failed",
54101- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
54102- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
54103+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
54104+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
54105 seq_printf(m, "\nLogoffs: %d sent %d failed",
54106- atomic_read(&sent[SMB2_LOGOFF_HE]),
54107- atomic_read(&failed[SMB2_LOGOFF_HE]));
54108+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
54109+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
54110 seq_printf(m, "\nTreeConnects: %d sent %d failed",
54111- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
54112- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
54113+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
54114+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
54115 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
54116- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
54117- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
54118+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
54119+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
54120 seq_printf(m, "\nCreates: %d sent %d failed",
54121- atomic_read(&sent[SMB2_CREATE_HE]),
54122- atomic_read(&failed[SMB2_CREATE_HE]));
54123+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
54124+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
54125 seq_printf(m, "\nCloses: %d sent %d failed",
54126- atomic_read(&sent[SMB2_CLOSE_HE]),
54127- atomic_read(&failed[SMB2_CLOSE_HE]));
54128+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
54129+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
54130 seq_printf(m, "\nFlushes: %d sent %d failed",
54131- atomic_read(&sent[SMB2_FLUSH_HE]),
54132- atomic_read(&failed[SMB2_FLUSH_HE]));
54133+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
54134+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
54135 seq_printf(m, "\nReads: %d sent %d failed",
54136- atomic_read(&sent[SMB2_READ_HE]),
54137- atomic_read(&failed[SMB2_READ_HE]));
54138+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
54139+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
54140 seq_printf(m, "\nWrites: %d sent %d failed",
54141- atomic_read(&sent[SMB2_WRITE_HE]),
54142- atomic_read(&failed[SMB2_WRITE_HE]));
54143+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
54144+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
54145 seq_printf(m, "\nLocks: %d sent %d failed",
54146- atomic_read(&sent[SMB2_LOCK_HE]),
54147- atomic_read(&failed[SMB2_LOCK_HE]));
54148+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
54149+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
54150 seq_printf(m, "\nIOCTLs: %d sent %d failed",
54151- atomic_read(&sent[SMB2_IOCTL_HE]),
54152- atomic_read(&failed[SMB2_IOCTL_HE]));
54153+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
54154+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
54155 seq_printf(m, "\nCancels: %d sent %d failed",
54156- atomic_read(&sent[SMB2_CANCEL_HE]),
54157- atomic_read(&failed[SMB2_CANCEL_HE]));
54158+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
54159+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
54160 seq_printf(m, "\nEchos: %d sent %d failed",
54161- atomic_read(&sent[SMB2_ECHO_HE]),
54162- atomic_read(&failed[SMB2_ECHO_HE]));
54163+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
54164+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
54165 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
54166- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
54167- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
54168+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
54169+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
54170 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
54171- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
54172- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
54173+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
54174+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
54175 seq_printf(m, "\nQueryInfos: %d sent %d failed",
54176- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
54177- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
54178+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
54179+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
54180 seq_printf(m, "\nSetInfos: %d sent %d failed",
54181- atomic_read(&sent[SMB2_SET_INFO_HE]),
54182- atomic_read(&failed[SMB2_SET_INFO_HE]));
54183+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
54184+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
54185 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
54186- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
54187- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
54188+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
54189+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
54190 #endif
54191 }
54192
54193diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
54194index abc9c28..3fdae28 100644
54195--- a/fs/cifs/smb2pdu.c
54196+++ b/fs/cifs/smb2pdu.c
54197@@ -1946,8 +1946,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
54198 default:
54199 cifs_dbg(VFS, "info level %u isn't supported\n",
54200 srch_inf->info_level);
54201- rc = -EINVAL;
54202- goto qdir_exit;
54203+ return -EINVAL;
54204 }
54205
54206 req->FileIndex = cpu_to_le32(index);
54207diff --git a/fs/coda/cache.c b/fs/coda/cache.c
54208index 1da168c..8bc7ff6 100644
54209--- a/fs/coda/cache.c
54210+++ b/fs/coda/cache.c
54211@@ -24,7 +24,7 @@
54212 #include "coda_linux.h"
54213 #include "coda_cache.h"
54214
54215-static atomic_t permission_epoch = ATOMIC_INIT(0);
54216+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
54217
54218 /* replace or extend an acl cache hit */
54219 void coda_cache_enter(struct inode *inode, int mask)
54220@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
54221 struct coda_inode_info *cii = ITOC(inode);
54222
54223 spin_lock(&cii->c_lock);
54224- cii->c_cached_epoch = atomic_read(&permission_epoch);
54225+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
54226 if (!uid_eq(cii->c_uid, current_fsuid())) {
54227 cii->c_uid = current_fsuid();
54228 cii->c_cached_perm = mask;
54229@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
54230 {
54231 struct coda_inode_info *cii = ITOC(inode);
54232 spin_lock(&cii->c_lock);
54233- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
54234+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
54235 spin_unlock(&cii->c_lock);
54236 }
54237
54238 /* remove all acl caches */
54239 void coda_cache_clear_all(struct super_block *sb)
54240 {
54241- atomic_inc(&permission_epoch);
54242+ atomic_inc_unchecked(&permission_epoch);
54243 }
54244
54245
54246@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
54247 spin_lock(&cii->c_lock);
54248 hit = (mask & cii->c_cached_perm) == mask &&
54249 uid_eq(cii->c_uid, current_fsuid()) &&
54250- cii->c_cached_epoch == atomic_read(&permission_epoch);
54251+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
54252 spin_unlock(&cii->c_lock);
54253
54254 return hit;
54255diff --git a/fs/compat.c b/fs/compat.c
54256index 6af20de..fec3fbb 100644
54257--- a/fs/compat.c
54258+++ b/fs/compat.c
54259@@ -54,7 +54,7 @@
54260 #include <asm/ioctls.h>
54261 #include "internal.h"
54262
54263-int compat_log = 1;
54264+int compat_log = 0;
54265
54266 int compat_printk(const char *fmt, ...)
54267 {
54268@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
54269
54270 set_fs(KERNEL_DS);
54271 /* The __user pointer cast is valid because of the set_fs() */
54272- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
54273+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
54274 set_fs(oldfs);
54275 /* truncating is ok because it's a user address */
54276 if (!ret)
54277@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
54278 goto out;
54279
54280 ret = -EINVAL;
54281- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
54282+ if (nr_segs > UIO_MAXIOV)
54283 goto out;
54284 if (nr_segs > fast_segs) {
54285 ret = -ENOMEM;
54286@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
54287 struct compat_readdir_callback {
54288 struct dir_context ctx;
54289 struct compat_old_linux_dirent __user *dirent;
54290+ struct file * file;
54291 int result;
54292 };
54293
54294@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
54295 buf->result = -EOVERFLOW;
54296 return -EOVERFLOW;
54297 }
54298+
54299+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54300+ return 0;
54301+
54302 buf->result++;
54303 dirent = buf->dirent;
54304 if (!access_ok(VERIFY_WRITE, dirent,
54305@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
54306 if (!f.file)
54307 return -EBADF;
54308
54309+ buf.file = f.file;
54310 error = iterate_dir(f.file, &buf.ctx);
54311 if (buf.result)
54312 error = buf.result;
54313@@ -901,6 +907,7 @@ struct compat_getdents_callback {
54314 struct dir_context ctx;
54315 struct compat_linux_dirent __user *current_dir;
54316 struct compat_linux_dirent __user *previous;
54317+ struct file * file;
54318 int count;
54319 int error;
54320 };
54321@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
54322 buf->error = -EOVERFLOW;
54323 return -EOVERFLOW;
54324 }
54325+
54326+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54327+ return 0;
54328+
54329 dirent = buf->previous;
54330 if (dirent) {
54331 if (__put_user(offset, &dirent->d_off))
54332@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
54333 if (!f.file)
54334 return -EBADF;
54335
54336+ buf.file = f.file;
54337 error = iterate_dir(f.file, &buf.ctx);
54338 if (error >= 0)
54339 error = buf.error;
54340@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
54341 struct dir_context ctx;
54342 struct linux_dirent64 __user *current_dir;
54343 struct linux_dirent64 __user *previous;
54344+ struct file * file;
54345 int count;
54346 int error;
54347 };
54348@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
54349 buf->error = -EINVAL; /* only used if we fail.. */
54350 if (reclen > buf->count)
54351 return -EINVAL;
54352+
54353+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54354+ return 0;
54355+
54356 dirent = buf->previous;
54357
54358 if (dirent) {
54359@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
54360 if (!f.file)
54361 return -EBADF;
54362
54363+ buf.file = f.file;
54364 error = iterate_dir(f.file, &buf.ctx);
54365 if (error >= 0)
54366 error = buf.error;
54367diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
54368index a81147e..20bf2b5 100644
54369--- a/fs/compat_binfmt_elf.c
54370+++ b/fs/compat_binfmt_elf.c
54371@@ -30,11 +30,13 @@
54372 #undef elf_phdr
54373 #undef elf_shdr
54374 #undef elf_note
54375+#undef elf_dyn
54376 #undef elf_addr_t
54377 #define elfhdr elf32_hdr
54378 #define elf_phdr elf32_phdr
54379 #define elf_shdr elf32_shdr
54380 #define elf_note elf32_note
54381+#define elf_dyn Elf32_Dyn
54382 #define elf_addr_t Elf32_Addr
54383
54384 /*
54385diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
54386index 5d19acf..9ab093b 100644
54387--- a/fs/compat_ioctl.c
54388+++ b/fs/compat_ioctl.c
54389@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
54390 return -EFAULT;
54391 if (__get_user(udata, &ss32->iomem_base))
54392 return -EFAULT;
54393- ss.iomem_base = compat_ptr(udata);
54394+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
54395 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
54396 __get_user(ss.port_high, &ss32->port_high))
54397 return -EFAULT;
54398@@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
54399 for (i = 0; i < nmsgs; i++) {
54400 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
54401 return -EFAULT;
54402- if (get_user(datap, &umsgs[i].buf) ||
54403- put_user(compat_ptr(datap), &tmsgs[i].buf))
54404+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
54405+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
54406 return -EFAULT;
54407 }
54408 return sys_ioctl(fd, cmd, (unsigned long)tdata);
54409@@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
54410 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
54411 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
54412 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
54413- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54414+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54415 return -EFAULT;
54416
54417 return ioctl_preallocate(file, p);
54418@@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
54419 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
54420 {
54421 unsigned int a, b;
54422- a = *(unsigned int *)p;
54423- b = *(unsigned int *)q;
54424+ a = *(const unsigned int *)p;
54425+ b = *(const unsigned int *)q;
54426 if (a > b)
54427 return 1;
54428 if (a < b)
54429diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
54430index 277bd1b..f312c9e 100644
54431--- a/fs/configfs/dir.c
54432+++ b/fs/configfs/dir.c
54433@@ -1546,7 +1546,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54434 }
54435 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
54436 struct configfs_dirent *next;
54437- const char *name;
54438+ const unsigned char * name;
54439+ char d_name[sizeof(next->s_dentry->d_iname)];
54440 int len;
54441 struct inode *inode = NULL;
54442
54443@@ -1555,7 +1556,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54444 continue;
54445
54446 name = configfs_get_name(next);
54447- len = strlen(name);
54448+ if (next->s_dentry && name == next->s_dentry->d_iname) {
54449+ len = next->s_dentry->d_name.len;
54450+ memcpy(d_name, name, len);
54451+ name = d_name;
54452+ } else
54453+ len = strlen(name);
54454
54455 /*
54456 * We'll have a dentry and an inode for
54457diff --git a/fs/coredump.c b/fs/coredump.c
54458index 72f816d..1ba8eff 100644
54459--- a/fs/coredump.c
54460+++ b/fs/coredump.c
54461@@ -433,8 +433,8 @@ static void wait_for_dump_helpers(struct file *file)
54462 struct pipe_inode_info *pipe = file->private_data;
54463
54464 pipe_lock(pipe);
54465- pipe->readers++;
54466- pipe->writers--;
54467+ atomic_inc(&pipe->readers);
54468+ atomic_dec(&pipe->writers);
54469 wake_up_interruptible_sync(&pipe->wait);
54470 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54471 pipe_unlock(pipe);
54472@@ -443,11 +443,11 @@ static void wait_for_dump_helpers(struct file *file)
54473 * We actually want wait_event_freezable() but then we need
54474 * to clear TIF_SIGPENDING and improve dump_interrupted().
54475 */
54476- wait_event_interruptible(pipe->wait, pipe->readers == 1);
54477+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
54478
54479 pipe_lock(pipe);
54480- pipe->readers--;
54481- pipe->writers++;
54482+ atomic_dec(&pipe->readers);
54483+ atomic_inc(&pipe->writers);
54484 pipe_unlock(pipe);
54485 }
54486
54487@@ -494,7 +494,8 @@ void do_coredump(siginfo_t *siginfo)
54488 struct files_struct *displaced;
54489 bool need_nonrelative = false;
54490 bool core_dumped = false;
54491- static atomic_t core_dump_count = ATOMIC_INIT(0);
54492+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
54493+ long signr = siginfo->si_signo;
54494 struct coredump_params cprm = {
54495 .siginfo = siginfo,
54496 .regs = signal_pt_regs(),
54497@@ -507,7 +508,10 @@ void do_coredump(siginfo_t *siginfo)
54498 .mm_flags = mm->flags,
54499 };
54500
54501- audit_core_dumps(siginfo->si_signo);
54502+ audit_core_dumps(signr);
54503+
54504+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
54505+ gr_handle_brute_attach(cprm.mm_flags);
54506
54507 binfmt = mm->binfmt;
54508 if (!binfmt || !binfmt->core_dump)
54509@@ -531,7 +535,7 @@ void do_coredump(siginfo_t *siginfo)
54510 need_nonrelative = true;
54511 }
54512
54513- retval = coredump_wait(siginfo->si_signo, &core_state);
54514+ retval = coredump_wait(signr, &core_state);
54515 if (retval < 0)
54516 goto fail_creds;
54517
54518@@ -574,7 +578,7 @@ void do_coredump(siginfo_t *siginfo)
54519 }
54520 cprm.limit = RLIM_INFINITY;
54521
54522- dump_count = atomic_inc_return(&core_dump_count);
54523+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
54524 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
54525 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
54526 task_tgid_vnr(current), current->comm);
54527@@ -606,6 +610,8 @@ void do_coredump(siginfo_t *siginfo)
54528 } else {
54529 struct inode *inode;
54530
54531+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
54532+
54533 if (cprm.limit < binfmt->min_coredump)
54534 goto fail_unlock;
54535
54536@@ -664,7 +670,7 @@ close_fail:
54537 filp_close(cprm.file, NULL);
54538 fail_dropcount:
54539 if (ispipe)
54540- atomic_dec(&core_dump_count);
54541+ atomic_dec_unchecked(&core_dump_count);
54542 fail_unlock:
54543 kfree(cn.corename);
54544 coredump_finish(mm, core_dumped);
54545@@ -684,7 +690,7 @@ int dump_write(struct file *file, const void *addr, int nr)
54546 {
54547 return !dump_interrupted() &&
54548 access_ok(VERIFY_READ, addr, nr) &&
54549- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
54550+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
54551 }
54552 EXPORT_SYMBOL(dump_write);
54553
54554diff --git a/fs/dcache.c b/fs/dcache.c
54555index b949af8..5978926 100644
54556--- a/fs/dcache.c
54557+++ b/fs/dcache.c
54558@@ -3073,7 +3073,8 @@ void __init vfs_caches_init(unsigned long mempages)
54559 mempages -= reserve;
54560
54561 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
54562- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
54563+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
54564+ SLAB_NO_SANITIZE, NULL);
54565
54566 dcache_init();
54567 inode_init();
54568diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
54569index c7c83ff..bda9461 100644
54570--- a/fs/debugfs/inode.c
54571+++ b/fs/debugfs/inode.c
54572@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
54573 */
54574 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
54575 {
54576+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
54577+ return __create_file(name, S_IFDIR | S_IRWXU,
54578+#else
54579 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
54580+#endif
54581 parent, NULL, NULL);
54582 }
54583 EXPORT_SYMBOL_GPL(debugfs_create_dir);
54584diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
54585index 67e9b63..a9adb68 100644
54586--- a/fs/ecryptfs/inode.c
54587+++ b/fs/ecryptfs/inode.c
54588@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
54589 old_fs = get_fs();
54590 set_fs(get_ds());
54591 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
54592- (char __user *)lower_buf,
54593+ (char __force_user *)lower_buf,
54594 PATH_MAX);
54595 set_fs(old_fs);
54596 if (rc < 0)
54597@@ -706,7 +706,7 @@ out:
54598 static void
54599 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
54600 {
54601- char *buf = nd_get_link(nd);
54602+ const char *buf = nd_get_link(nd);
54603 if (!IS_ERR(buf)) {
54604 /* Free the char* */
54605 kfree(buf);
54606diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
54607index e4141f2..d8263e8 100644
54608--- a/fs/ecryptfs/miscdev.c
54609+++ b/fs/ecryptfs/miscdev.c
54610@@ -304,7 +304,7 @@ check_list:
54611 goto out_unlock_msg_ctx;
54612 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
54613 if (msg_ctx->msg) {
54614- if (copy_to_user(&buf[i], packet_length, packet_length_size))
54615+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
54616 goto out_unlock_msg_ctx;
54617 i += packet_length_size;
54618 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
54619diff --git a/fs/exec.c b/fs/exec.c
54620index fd774c7..1c6a7bf 100644
54621--- a/fs/exec.c
54622+++ b/fs/exec.c
54623@@ -55,8 +55,20 @@
54624 #include <linux/pipe_fs_i.h>
54625 #include <linux/oom.h>
54626 #include <linux/compat.h>
54627+#include <linux/random.h>
54628+#include <linux/seq_file.h>
54629+#include <linux/coredump.h>
54630+#include <linux/mman.h>
54631+
54632+#ifdef CONFIG_PAX_REFCOUNT
54633+#include <linux/kallsyms.h>
54634+#include <linux/kdebug.h>
54635+#endif
54636+
54637+#include <trace/events/fs.h>
54638
54639 #include <asm/uaccess.h>
54640+#include <asm/sections.h>
54641 #include <asm/mmu_context.h>
54642 #include <asm/tlb.h>
54643
54644@@ -66,17 +78,32 @@
54645
54646 #include <trace/events/sched.h>
54647
54648+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
54649+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
54650+{
54651+ 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");
54652+}
54653+#endif
54654+
54655+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
54656+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
54657+EXPORT_SYMBOL(pax_set_initial_flags_func);
54658+#endif
54659+
54660 int suid_dumpable = 0;
54661
54662 static LIST_HEAD(formats);
54663 static DEFINE_RWLOCK(binfmt_lock);
54664
54665+extern int gr_process_kernel_exec_ban(void);
54666+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
54667+
54668 void __register_binfmt(struct linux_binfmt * fmt, int insert)
54669 {
54670 BUG_ON(!fmt);
54671 write_lock(&binfmt_lock);
54672- insert ? list_add(&fmt->lh, &formats) :
54673- list_add_tail(&fmt->lh, &formats);
54674+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
54675+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
54676 write_unlock(&binfmt_lock);
54677 }
54678
54679@@ -85,7 +112,7 @@ EXPORT_SYMBOL(__register_binfmt);
54680 void unregister_binfmt(struct linux_binfmt * fmt)
54681 {
54682 write_lock(&binfmt_lock);
54683- list_del(&fmt->lh);
54684+ pax_list_del((struct list_head *)&fmt->lh);
54685 write_unlock(&binfmt_lock);
54686 }
54687
54688@@ -181,18 +208,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
54689 int write)
54690 {
54691 struct page *page;
54692- int ret;
54693
54694-#ifdef CONFIG_STACK_GROWSUP
54695- if (write) {
54696- ret = expand_downwards(bprm->vma, pos);
54697- if (ret < 0)
54698- return NULL;
54699- }
54700-#endif
54701- ret = get_user_pages(current, bprm->mm, pos,
54702- 1, write, 1, &page, NULL);
54703- if (ret <= 0)
54704+ if (0 > expand_downwards(bprm->vma, pos))
54705+ return NULL;
54706+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
54707 return NULL;
54708
54709 if (write) {
54710@@ -208,6 +227,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
54711 if (size <= ARG_MAX)
54712 return page;
54713
54714+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54715+ // only allow 512KB for argv+env on suid/sgid binaries
54716+ // to prevent easy ASLR exhaustion
54717+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
54718+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
54719+ (size > (512 * 1024))) {
54720+ put_page(page);
54721+ return NULL;
54722+ }
54723+#endif
54724+
54725 /*
54726 * Limit to 1/4-th the stack size for the argv+env strings.
54727 * This ensures that:
54728@@ -267,6 +297,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
54729 vma->vm_end = STACK_TOP_MAX;
54730 vma->vm_start = vma->vm_end - PAGE_SIZE;
54731 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
54732+
54733+#ifdef CONFIG_PAX_SEGMEXEC
54734+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
54735+#endif
54736+
54737 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
54738 INIT_LIST_HEAD(&vma->anon_vma_chain);
54739
54740@@ -277,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
54741 mm->stack_vm = mm->total_vm = 1;
54742 up_write(&mm->mmap_sem);
54743 bprm->p = vma->vm_end - sizeof(void *);
54744+
54745+#ifdef CONFIG_PAX_RANDUSTACK
54746+ if (randomize_va_space)
54747+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
54748+#endif
54749+
54750 return 0;
54751 err:
54752 up_write(&mm->mmap_sem);
54753@@ -397,7 +438,7 @@ struct user_arg_ptr {
54754 } ptr;
54755 };
54756
54757-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54758+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54759 {
54760 const char __user *native;
54761
54762@@ -406,14 +447,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54763 compat_uptr_t compat;
54764
54765 if (get_user(compat, argv.ptr.compat + nr))
54766- return ERR_PTR(-EFAULT);
54767+ return (const char __force_user *)ERR_PTR(-EFAULT);
54768
54769 return compat_ptr(compat);
54770 }
54771 #endif
54772
54773 if (get_user(native, argv.ptr.native + nr))
54774- return ERR_PTR(-EFAULT);
54775+ return (const char __force_user *)ERR_PTR(-EFAULT);
54776
54777 return native;
54778 }
54779@@ -432,7 +473,7 @@ static int count(struct user_arg_ptr argv, int max)
54780 if (!p)
54781 break;
54782
54783- if (IS_ERR(p))
54784+ if (IS_ERR((const char __force_kernel *)p))
54785 return -EFAULT;
54786
54787 if (i >= max)
54788@@ -467,7 +508,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
54789
54790 ret = -EFAULT;
54791 str = get_user_arg_ptr(argv, argc);
54792- if (IS_ERR(str))
54793+ if (IS_ERR((const char __force_kernel *)str))
54794 goto out;
54795
54796 len = strnlen_user(str, MAX_ARG_STRLEN);
54797@@ -549,7 +590,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
54798 int r;
54799 mm_segment_t oldfs = get_fs();
54800 struct user_arg_ptr argv = {
54801- .ptr.native = (const char __user *const __user *)__argv,
54802+ .ptr.native = (const char __force_user * const __force_user *)__argv,
54803 };
54804
54805 set_fs(KERNEL_DS);
54806@@ -584,7 +625,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
54807 unsigned long new_end = old_end - shift;
54808 struct mmu_gather tlb;
54809
54810- BUG_ON(new_start > new_end);
54811+ if (new_start >= new_end || new_start < mmap_min_addr)
54812+ return -ENOMEM;
54813
54814 /*
54815 * ensure there are no vmas between where we want to go
54816@@ -593,6 +635,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
54817 if (vma != find_vma(mm, new_start))
54818 return -EFAULT;
54819
54820+#ifdef CONFIG_PAX_SEGMEXEC
54821+ BUG_ON(pax_find_mirror_vma(vma));
54822+#endif
54823+
54824 /*
54825 * cover the whole range: [new_start, old_end)
54826 */
54827@@ -673,10 +719,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
54828 stack_top = arch_align_stack(stack_top);
54829 stack_top = PAGE_ALIGN(stack_top);
54830
54831- if (unlikely(stack_top < mmap_min_addr) ||
54832- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
54833- return -ENOMEM;
54834-
54835 stack_shift = vma->vm_end - stack_top;
54836
54837 bprm->p -= stack_shift;
54838@@ -688,8 +730,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
54839 bprm->exec -= stack_shift;
54840
54841 down_write(&mm->mmap_sem);
54842+
54843+ /* Move stack pages down in memory. */
54844+ if (stack_shift) {
54845+ ret = shift_arg_pages(vma, stack_shift);
54846+ if (ret)
54847+ goto out_unlock;
54848+ }
54849+
54850 vm_flags = VM_STACK_FLAGS;
54851
54852+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
54853+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
54854+ vm_flags &= ~VM_EXEC;
54855+
54856+#ifdef CONFIG_PAX_MPROTECT
54857+ if (mm->pax_flags & MF_PAX_MPROTECT)
54858+ vm_flags &= ~VM_MAYEXEC;
54859+#endif
54860+
54861+ }
54862+#endif
54863+
54864 /*
54865 * Adjust stack execute permissions; explicitly enable for
54866 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
54867@@ -708,13 +770,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
54868 goto out_unlock;
54869 BUG_ON(prev != vma);
54870
54871- /* Move stack pages down in memory. */
54872- if (stack_shift) {
54873- ret = shift_arg_pages(vma, stack_shift);
54874- if (ret)
54875- goto out_unlock;
54876- }
54877-
54878 /* mprotect_fixup is overkill to remove the temporary stack flags */
54879 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
54880
54881@@ -738,6 +793,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
54882 #endif
54883 current->mm->start_stack = bprm->p;
54884 ret = expand_stack(vma, stack_base);
54885+
54886+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
54887+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
54888+ unsigned long size;
54889+ vm_flags_t vm_flags;
54890+
54891+ size = STACK_TOP - vma->vm_end;
54892+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
54893+
54894+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
54895+
54896+#ifdef CONFIG_X86
54897+ if (!ret) {
54898+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
54899+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
54900+ }
54901+#endif
54902+
54903+ }
54904+#endif
54905+
54906 if (ret)
54907 ret = -EFAULT;
54908
54909@@ -774,6 +850,8 @@ struct file *open_exec(const char *name)
54910
54911 fsnotify_open(file);
54912
54913+ trace_open_exec(name);
54914+
54915 err = deny_write_access(file);
54916 if (err)
54917 goto exit;
54918@@ -797,7 +875,7 @@ int kernel_read(struct file *file, loff_t offset,
54919 old_fs = get_fs();
54920 set_fs(get_ds());
54921 /* The cast to a user pointer is valid due to the set_fs() */
54922- result = vfs_read(file, (void __user *)addr, count, &pos);
54923+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
54924 set_fs(old_fs);
54925 return result;
54926 }
54927@@ -1253,7 +1331,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
54928 }
54929 rcu_read_unlock();
54930
54931- if (p->fs->users > n_fs) {
54932+ if (atomic_read(&p->fs->users) > n_fs) {
54933 bprm->unsafe |= LSM_UNSAFE_SHARE;
54934 } else {
54935 res = -EAGAIN;
54936@@ -1453,6 +1531,31 @@ int search_binary_handler(struct linux_binprm *bprm)
54937
54938 EXPORT_SYMBOL(search_binary_handler);
54939
54940+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54941+static DEFINE_PER_CPU(u64, exec_counter);
54942+static int __init init_exec_counters(void)
54943+{
54944+ unsigned int cpu;
54945+
54946+ for_each_possible_cpu(cpu) {
54947+ per_cpu(exec_counter, cpu) = (u64)cpu;
54948+ }
54949+
54950+ return 0;
54951+}
54952+early_initcall(init_exec_counters);
54953+static inline void increment_exec_counter(void)
54954+{
54955+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
54956+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
54957+}
54958+#else
54959+static inline void increment_exec_counter(void) {}
54960+#endif
54961+
54962+extern void gr_handle_exec_args(struct linux_binprm *bprm,
54963+ struct user_arg_ptr argv);
54964+
54965 /*
54966 * sys_execve() executes a new program.
54967 */
54968@@ -1460,12 +1563,19 @@ static int do_execve_common(const char *filename,
54969 struct user_arg_ptr argv,
54970 struct user_arg_ptr envp)
54971 {
54972+#ifdef CONFIG_GRKERNSEC
54973+ struct file *old_exec_file;
54974+ struct acl_subject_label *old_acl;
54975+ struct rlimit old_rlim[RLIM_NLIMITS];
54976+#endif
54977 struct linux_binprm *bprm;
54978 struct file *file;
54979 struct files_struct *displaced;
54980 bool clear_in_exec;
54981 int retval;
54982
54983+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
54984+
54985 /*
54986 * We move the actual failure in case of RLIMIT_NPROC excess from
54987 * set*uid() to execve() because too many poorly written programs
54988@@ -1506,12 +1616,22 @@ static int do_execve_common(const char *filename,
54989 if (IS_ERR(file))
54990 goto out_unmark;
54991
54992+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
54993+ retval = -EPERM;
54994+ goto out_file;
54995+ }
54996+
54997 sched_exec();
54998
54999 bprm->file = file;
55000 bprm->filename = filename;
55001 bprm->interp = filename;
55002
55003+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
55004+ retval = -EACCES;
55005+ goto out_file;
55006+ }
55007+
55008 retval = bprm_mm_init(bprm);
55009 if (retval)
55010 goto out_file;
55011@@ -1528,24 +1648,70 @@ static int do_execve_common(const char *filename,
55012 if (retval < 0)
55013 goto out;
55014
55015+#ifdef CONFIG_GRKERNSEC
55016+ old_acl = current->acl;
55017+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
55018+ old_exec_file = current->exec_file;
55019+ get_file(file);
55020+ current->exec_file = file;
55021+#endif
55022+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55023+ /* limit suid stack to 8MB
55024+ * we saved the old limits above and will restore them if this exec fails
55025+ */
55026+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
55027+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
55028+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
55029+#endif
55030+
55031+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
55032+ retval = -EPERM;
55033+ goto out_fail;
55034+ }
55035+
55036+ if (!gr_tpe_allow(file)) {
55037+ retval = -EACCES;
55038+ goto out_fail;
55039+ }
55040+
55041+ if (gr_check_crash_exec(file)) {
55042+ retval = -EACCES;
55043+ goto out_fail;
55044+ }
55045+
55046+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
55047+ bprm->unsafe);
55048+ if (retval < 0)
55049+ goto out_fail;
55050+
55051 retval = copy_strings_kernel(1, &bprm->filename, bprm);
55052 if (retval < 0)
55053- goto out;
55054+ goto out_fail;
55055
55056 bprm->exec = bprm->p;
55057 retval = copy_strings(bprm->envc, envp, bprm);
55058 if (retval < 0)
55059- goto out;
55060+ goto out_fail;
55061
55062 retval = copy_strings(bprm->argc, argv, bprm);
55063 if (retval < 0)
55064- goto out;
55065+ goto out_fail;
55066+
55067+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
55068+
55069+ gr_handle_exec_args(bprm, argv);
55070
55071 retval = search_binary_handler(bprm);
55072 if (retval < 0)
55073- goto out;
55074+ goto out_fail;
55075+#ifdef CONFIG_GRKERNSEC
55076+ if (old_exec_file)
55077+ fput(old_exec_file);
55078+#endif
55079
55080 /* execve succeeded */
55081+
55082+ increment_exec_counter();
55083 current->fs->in_exec = 0;
55084 current->in_execve = 0;
55085 acct_update_integrals(current);
55086@@ -1554,6 +1720,14 @@ static int do_execve_common(const char *filename,
55087 put_files_struct(displaced);
55088 return retval;
55089
55090+out_fail:
55091+#ifdef CONFIG_GRKERNSEC
55092+ current->acl = old_acl;
55093+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
55094+ fput(current->exec_file);
55095+ current->exec_file = old_exec_file;
55096+#endif
55097+
55098 out:
55099 if (bprm->mm) {
55100 acct_arg_size(bprm, 0);
55101@@ -1702,3 +1876,287 @@ asmlinkage long compat_sys_execve(const char __user * filename,
55102 return error;
55103 }
55104 #endif
55105+
55106+int pax_check_flags(unsigned long *flags)
55107+{
55108+ int retval = 0;
55109+
55110+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
55111+ if (*flags & MF_PAX_SEGMEXEC)
55112+ {
55113+ *flags &= ~MF_PAX_SEGMEXEC;
55114+ retval = -EINVAL;
55115+ }
55116+#endif
55117+
55118+ if ((*flags & MF_PAX_PAGEEXEC)
55119+
55120+#ifdef CONFIG_PAX_PAGEEXEC
55121+ && (*flags & MF_PAX_SEGMEXEC)
55122+#endif
55123+
55124+ )
55125+ {
55126+ *flags &= ~MF_PAX_PAGEEXEC;
55127+ retval = -EINVAL;
55128+ }
55129+
55130+ if ((*flags & MF_PAX_MPROTECT)
55131+
55132+#ifdef CONFIG_PAX_MPROTECT
55133+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
55134+#endif
55135+
55136+ )
55137+ {
55138+ *flags &= ~MF_PAX_MPROTECT;
55139+ retval = -EINVAL;
55140+ }
55141+
55142+ if ((*flags & MF_PAX_EMUTRAMP)
55143+
55144+#ifdef CONFIG_PAX_EMUTRAMP
55145+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
55146+#endif
55147+
55148+ )
55149+ {
55150+ *flags &= ~MF_PAX_EMUTRAMP;
55151+ retval = -EINVAL;
55152+ }
55153+
55154+ return retval;
55155+}
55156+
55157+EXPORT_SYMBOL(pax_check_flags);
55158+
55159+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55160+char *pax_get_path(const struct path *path, char *buf, int buflen)
55161+{
55162+ char *pathname = d_path(path, buf, buflen);
55163+
55164+ if (IS_ERR(pathname))
55165+ goto toolong;
55166+
55167+ pathname = mangle_path(buf, pathname, "\t\n\\");
55168+ if (!pathname)
55169+ goto toolong;
55170+
55171+ *pathname = 0;
55172+ return buf;
55173+
55174+toolong:
55175+ return "<path too long>";
55176+}
55177+EXPORT_SYMBOL(pax_get_path);
55178+
55179+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
55180+{
55181+ struct task_struct *tsk = current;
55182+ struct mm_struct *mm = current->mm;
55183+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
55184+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
55185+ char *path_exec = NULL;
55186+ char *path_fault = NULL;
55187+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
55188+ siginfo_t info = { };
55189+
55190+ if (buffer_exec && buffer_fault) {
55191+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
55192+
55193+ down_read(&mm->mmap_sem);
55194+ vma = mm->mmap;
55195+ while (vma && (!vma_exec || !vma_fault)) {
55196+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
55197+ vma_exec = vma;
55198+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
55199+ vma_fault = vma;
55200+ vma = vma->vm_next;
55201+ }
55202+ if (vma_exec)
55203+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
55204+ if (vma_fault) {
55205+ start = vma_fault->vm_start;
55206+ end = vma_fault->vm_end;
55207+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
55208+ if (vma_fault->vm_file)
55209+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
55210+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
55211+ path_fault = "<heap>";
55212+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
55213+ path_fault = "<stack>";
55214+ else
55215+ path_fault = "<anonymous mapping>";
55216+ }
55217+ up_read(&mm->mmap_sem);
55218+ }
55219+ if (tsk->signal->curr_ip)
55220+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
55221+ else
55222+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
55223+ 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),
55224+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
55225+ free_page((unsigned long)buffer_exec);
55226+ free_page((unsigned long)buffer_fault);
55227+ pax_report_insns(regs, pc, sp);
55228+ info.si_signo = SIGKILL;
55229+ info.si_errno = 0;
55230+ info.si_code = SI_KERNEL;
55231+ info.si_pid = 0;
55232+ info.si_uid = 0;
55233+ do_coredump(&info);
55234+}
55235+#endif
55236+
55237+#ifdef CONFIG_PAX_REFCOUNT
55238+void pax_report_refcount_overflow(struct pt_regs *regs)
55239+{
55240+ if (current->signal->curr_ip)
55241+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
55242+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
55243+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55244+ else
55245+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
55246+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55247+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
55248+ preempt_disable();
55249+ show_regs(regs);
55250+ preempt_enable();
55251+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
55252+}
55253+#endif
55254+
55255+#ifdef CONFIG_PAX_USERCOPY
55256+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
55257+static noinline int check_stack_object(const void *obj, unsigned long len)
55258+{
55259+ const void * const stack = task_stack_page(current);
55260+ const void * const stackend = stack + THREAD_SIZE;
55261+
55262+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55263+ const void *frame = NULL;
55264+ const void *oldframe;
55265+#endif
55266+
55267+ if (obj + len < obj)
55268+ return -1;
55269+
55270+ if (obj + len <= stack || stackend <= obj)
55271+ return 0;
55272+
55273+ if (obj < stack || stackend < obj + len)
55274+ return -1;
55275+
55276+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55277+ oldframe = __builtin_frame_address(1);
55278+ if (oldframe)
55279+ frame = __builtin_frame_address(2);
55280+ /*
55281+ low ----------------------------------------------> high
55282+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
55283+ ^----------------^
55284+ allow copies only within here
55285+ */
55286+ while (stack <= frame && frame < stackend) {
55287+ /* if obj + len extends past the last frame, this
55288+ check won't pass and the next frame will be 0,
55289+ causing us to bail out and correctly report
55290+ the copy as invalid
55291+ */
55292+ if (obj + len <= frame)
55293+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
55294+ oldframe = frame;
55295+ frame = *(const void * const *)frame;
55296+ }
55297+ return -1;
55298+#else
55299+ return 1;
55300+#endif
55301+}
55302+
55303+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
55304+{
55305+ if (current->signal->curr_ip)
55306+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55307+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55308+ else
55309+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55310+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55311+ dump_stack();
55312+ gr_handle_kernel_exploit();
55313+ do_group_exit(SIGKILL);
55314+}
55315+#endif
55316+
55317+#ifdef CONFIG_PAX_USERCOPY
55318+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
55319+{
55320+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
55321+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
55322+#ifdef CONFIG_MODULES
55323+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
55324+#else
55325+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
55326+#endif
55327+
55328+#else
55329+ unsigned long textlow = (unsigned long)_stext;
55330+ unsigned long texthigh = (unsigned long)_etext;
55331+#endif
55332+
55333+ if (high <= textlow || low > texthigh)
55334+ return false;
55335+ else
55336+ return true;
55337+}
55338+#endif
55339+
55340+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
55341+{
55342+
55343+#ifdef CONFIG_PAX_USERCOPY
55344+ const char *type;
55345+
55346+ if (!n)
55347+ return;
55348+
55349+ type = check_heap_object(ptr, n);
55350+ if (!type) {
55351+ int ret = check_stack_object(ptr, n);
55352+ if (ret == 1 || ret == 2)
55353+ return;
55354+ if (ret == 0) {
55355+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
55356+ type = "<kernel text>";
55357+ else
55358+ return;
55359+ } else
55360+ type = "<process stack>";
55361+ }
55362+
55363+ pax_report_usercopy(ptr, n, to_user, type);
55364+#endif
55365+
55366+}
55367+EXPORT_SYMBOL(__check_object_size);
55368+
55369+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
55370+void pax_track_stack(void)
55371+{
55372+ unsigned long sp = (unsigned long)&sp;
55373+ if (sp < current_thread_info()->lowest_stack &&
55374+ sp > (unsigned long)task_stack_page(current))
55375+ current_thread_info()->lowest_stack = sp;
55376+}
55377+EXPORT_SYMBOL(pax_track_stack);
55378+#endif
55379+
55380+#ifdef CONFIG_PAX_SIZE_OVERFLOW
55381+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
55382+{
55383+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
55384+ dump_stack();
55385+ do_group_exit(SIGKILL);
55386+}
55387+EXPORT_SYMBOL(report_size_overflow);
55388+#endif
55389diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
55390index 9f9992b..8b59411 100644
55391--- a/fs/ext2/balloc.c
55392+++ b/fs/ext2/balloc.c
55393@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
55394
55395 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55396 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55397- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55398+ if (free_blocks < root_blocks + 1 &&
55399 !uid_eq(sbi->s_resuid, current_fsuid()) &&
55400 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55401- !in_group_p (sbi->s_resgid))) {
55402+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55403 return 0;
55404 }
55405 return 1;
55406diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
55407index 22548f5..41521d8 100644
55408--- a/fs/ext3/balloc.c
55409+++ b/fs/ext3/balloc.c
55410@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
55411
55412 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55413 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55414- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55415+ if (free_blocks < root_blocks + 1 &&
55416 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
55417 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55418- !in_group_p (sbi->s_resgid))) {
55419+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55420 return 0;
55421 }
55422 return 1;
55423diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
55424index ddd715e..c772f88 100644
55425--- a/fs/ext4/balloc.c
55426+++ b/fs/ext4/balloc.c
55427@@ -528,8 +528,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
55428 /* Hm, nope. Are (enough) root reserved clusters available? */
55429 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
55430 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
55431- capable(CAP_SYS_RESOURCE) ||
55432- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
55433+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
55434+ capable_nolog(CAP_SYS_RESOURCE)) {
55435
55436 if (free_clusters >= (nclusters + dirty_clusters +
55437 resv_clusters))
55438diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
55439index 0ab26fb..b6ecb39 100644
55440--- a/fs/ext4/ext4.h
55441+++ b/fs/ext4/ext4.h
55442@@ -1247,19 +1247,19 @@ struct ext4_sb_info {
55443 unsigned long s_mb_last_start;
55444
55445 /* stats for buddy allocator */
55446- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
55447- atomic_t s_bal_success; /* we found long enough chunks */
55448- atomic_t s_bal_allocated; /* in blocks */
55449- atomic_t s_bal_ex_scanned; /* total extents scanned */
55450- atomic_t s_bal_goals; /* goal hits */
55451- atomic_t s_bal_breaks; /* too long searches */
55452- atomic_t s_bal_2orders; /* 2^order hits */
55453+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
55454+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
55455+ atomic_unchecked_t s_bal_allocated; /* in blocks */
55456+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
55457+ atomic_unchecked_t s_bal_goals; /* goal hits */
55458+ atomic_unchecked_t s_bal_breaks; /* too long searches */
55459+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
55460 spinlock_t s_bal_lock;
55461 unsigned long s_mb_buddies_generated;
55462 unsigned long long s_mb_generation_time;
55463- atomic_t s_mb_lost_chunks;
55464- atomic_t s_mb_preallocated;
55465- atomic_t s_mb_discarded;
55466+ atomic_unchecked_t s_mb_lost_chunks;
55467+ atomic_unchecked_t s_mb_preallocated;
55468+ atomic_unchecked_t s_mb_discarded;
55469 atomic_t s_lock_busy;
55470
55471 /* locality groups */
55472diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
55473index 4bbbf13b..dcceaeb 100644
55474--- a/fs/ext4/mballoc.c
55475+++ b/fs/ext4/mballoc.c
55476@@ -1865,7 +1865,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
55477 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
55478
55479 if (EXT4_SB(sb)->s_mb_stats)
55480- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
55481+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
55482
55483 break;
55484 }
55485@@ -2171,7 +2171,7 @@ repeat:
55486 ac->ac_status = AC_STATUS_CONTINUE;
55487 ac->ac_flags |= EXT4_MB_HINT_FIRST;
55488 cr = 3;
55489- atomic_inc(&sbi->s_mb_lost_chunks);
55490+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
55491 goto repeat;
55492 }
55493 }
55494@@ -2679,25 +2679,25 @@ int ext4_mb_release(struct super_block *sb)
55495 if (sbi->s_mb_stats) {
55496 ext4_msg(sb, KERN_INFO,
55497 "mballoc: %u blocks %u reqs (%u success)",
55498- atomic_read(&sbi->s_bal_allocated),
55499- atomic_read(&sbi->s_bal_reqs),
55500- atomic_read(&sbi->s_bal_success));
55501+ atomic_read_unchecked(&sbi->s_bal_allocated),
55502+ atomic_read_unchecked(&sbi->s_bal_reqs),
55503+ atomic_read_unchecked(&sbi->s_bal_success));
55504 ext4_msg(sb, KERN_INFO,
55505 "mballoc: %u extents scanned, %u goal hits, "
55506 "%u 2^N hits, %u breaks, %u lost",
55507- atomic_read(&sbi->s_bal_ex_scanned),
55508- atomic_read(&sbi->s_bal_goals),
55509- atomic_read(&sbi->s_bal_2orders),
55510- atomic_read(&sbi->s_bal_breaks),
55511- atomic_read(&sbi->s_mb_lost_chunks));
55512+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
55513+ atomic_read_unchecked(&sbi->s_bal_goals),
55514+ atomic_read_unchecked(&sbi->s_bal_2orders),
55515+ atomic_read_unchecked(&sbi->s_bal_breaks),
55516+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
55517 ext4_msg(sb, KERN_INFO,
55518 "mballoc: %lu generated and it took %Lu",
55519 sbi->s_mb_buddies_generated,
55520 sbi->s_mb_generation_time);
55521 ext4_msg(sb, KERN_INFO,
55522 "mballoc: %u preallocated, %u discarded",
55523- atomic_read(&sbi->s_mb_preallocated),
55524- atomic_read(&sbi->s_mb_discarded));
55525+ atomic_read_unchecked(&sbi->s_mb_preallocated),
55526+ atomic_read_unchecked(&sbi->s_mb_discarded));
55527 }
55528
55529 free_percpu(sbi->s_locality_groups);
55530@@ -3151,16 +3151,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
55531 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
55532
55533 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
55534- atomic_inc(&sbi->s_bal_reqs);
55535- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55536+ atomic_inc_unchecked(&sbi->s_bal_reqs);
55537+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55538 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
55539- atomic_inc(&sbi->s_bal_success);
55540- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
55541+ atomic_inc_unchecked(&sbi->s_bal_success);
55542+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
55543 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
55544 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
55545- atomic_inc(&sbi->s_bal_goals);
55546+ atomic_inc_unchecked(&sbi->s_bal_goals);
55547 if (ac->ac_found > sbi->s_mb_max_to_scan)
55548- atomic_inc(&sbi->s_bal_breaks);
55549+ atomic_inc_unchecked(&sbi->s_bal_breaks);
55550 }
55551
55552 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
55553@@ -3560,7 +3560,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
55554 trace_ext4_mb_new_inode_pa(ac, pa);
55555
55556 ext4_mb_use_inode_pa(ac, pa);
55557- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
55558+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
55559
55560 ei = EXT4_I(ac->ac_inode);
55561 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
55562@@ -3620,7 +3620,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
55563 trace_ext4_mb_new_group_pa(ac, pa);
55564
55565 ext4_mb_use_group_pa(ac, pa);
55566- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
55567+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
55568
55569 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
55570 lg = ac->ac_lg;
55571@@ -3709,7 +3709,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
55572 * from the bitmap and continue.
55573 */
55574 }
55575- atomic_add(free, &sbi->s_mb_discarded);
55576+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
55577
55578 return err;
55579 }
55580@@ -3727,7 +3727,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
55581 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
55582 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
55583 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
55584- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
55585+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
55586 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
55587
55588 return 0;
55589diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
55590index 214461e..3614c89 100644
55591--- a/fs/ext4/mmp.c
55592+++ b/fs/ext4/mmp.c
55593@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
55594 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
55595 const char *function, unsigned int line, const char *msg)
55596 {
55597- __ext4_warning(sb, function, line, msg);
55598+ __ext4_warning(sb, function, line, "%s", msg);
55599 __ext4_warning(sb, function, line,
55600 "MMP failure info: last update time: %llu, last update "
55601 "node: %s, last update device: %s\n",
55602diff --git a/fs/ext4/super.c b/fs/ext4/super.c
55603index b59373b..f41c2b5 100644
55604--- a/fs/ext4/super.c
55605+++ b/fs/ext4/super.c
55606@@ -1254,7 +1254,7 @@ static ext4_fsblk_t get_sb_block(void **data)
55607 }
55608
55609 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
55610-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
55611+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
55612 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
55613
55614 #ifdef CONFIG_QUOTA
55615@@ -2394,7 +2394,7 @@ struct ext4_attr {
55616 int offset;
55617 int deprecated_val;
55618 } u;
55619-};
55620+} __do_const;
55621
55622 static int parse_strtoull(const char *buf,
55623 unsigned long long max, unsigned long long *value)
55624diff --git a/fs/fcntl.c b/fs/fcntl.c
55625index 65343c3..9969dcf 100644
55626--- a/fs/fcntl.c
55627+++ b/fs/fcntl.c
55628@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
55629 if (err)
55630 return err;
55631
55632+ if (gr_handle_chroot_fowner(pid, type))
55633+ return -ENOENT;
55634+ if (gr_check_protected_task_fowner(pid, type))
55635+ return -EACCES;
55636+
55637 f_modown(filp, pid, type, force);
55638 return 0;
55639 }
55640diff --git a/fs/fhandle.c b/fs/fhandle.c
55641index 999ff5c..41f4109 100644
55642--- a/fs/fhandle.c
55643+++ b/fs/fhandle.c
55644@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
55645 } else
55646 retval = 0;
55647 /* copy the mount id */
55648- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
55649- sizeof(*mnt_id)) ||
55650+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
55651 copy_to_user(ufh, handle,
55652 sizeof(struct file_handle) + handle_bytes))
55653 retval = -EFAULT;
55654diff --git a/fs/file.c b/fs/file.c
55655index 4a78f98..9447397 100644
55656--- a/fs/file.c
55657+++ b/fs/file.c
55658@@ -16,6 +16,7 @@
55659 #include <linux/slab.h>
55660 #include <linux/vmalloc.h>
55661 #include <linux/file.h>
55662+#include <linux/security.h>
55663 #include <linux/fdtable.h>
55664 #include <linux/bitops.h>
55665 #include <linux/interrupt.h>
55666@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
55667 if (!file)
55668 return __close_fd(files, fd);
55669
55670+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
55671 if (fd >= rlimit(RLIMIT_NOFILE))
55672 return -EBADF;
55673
55674@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
55675 if (unlikely(oldfd == newfd))
55676 return -EINVAL;
55677
55678+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
55679 if (newfd >= rlimit(RLIMIT_NOFILE))
55680 return -EBADF;
55681
55682@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
55683 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
55684 {
55685 int err;
55686+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
55687 if (from >= rlimit(RLIMIT_NOFILE))
55688 return -EINVAL;
55689 err = alloc_fd(from, flags);
55690diff --git a/fs/filesystems.c b/fs/filesystems.c
55691index 92567d9..fcd8cbf 100644
55692--- a/fs/filesystems.c
55693+++ b/fs/filesystems.c
55694@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
55695 int len = dot ? dot - name : strlen(name);
55696
55697 fs = __get_fs_type(name, len);
55698+#ifdef CONFIG_GRKERNSEC_MODHARDEN
55699+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
55700+#else
55701 if (!fs && (request_module("fs-%.*s", len, name) == 0))
55702+#endif
55703 fs = __get_fs_type(name, len);
55704
55705 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
55706diff --git a/fs/fs_struct.c b/fs/fs_struct.c
55707index d8ac61d..79a36f0 100644
55708--- a/fs/fs_struct.c
55709+++ b/fs/fs_struct.c
55710@@ -4,6 +4,7 @@
55711 #include <linux/path.h>
55712 #include <linux/slab.h>
55713 #include <linux/fs_struct.h>
55714+#include <linux/grsecurity.h>
55715 #include "internal.h"
55716
55717 /*
55718@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
55719 write_seqcount_begin(&fs->seq);
55720 old_root = fs->root;
55721 fs->root = *path;
55722+ gr_set_chroot_entries(current, path);
55723 write_seqcount_end(&fs->seq);
55724 spin_unlock(&fs->lock);
55725 if (old_root.dentry)
55726@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
55727 int hits = 0;
55728 spin_lock(&fs->lock);
55729 write_seqcount_begin(&fs->seq);
55730+ /* this root replacement is only done by pivot_root,
55731+ leave grsec's chroot tagging alone for this task
55732+ so that a pivoted root isn't treated as a chroot
55733+ */
55734 hits += replace_path(&fs->root, old_root, new_root);
55735 hits += replace_path(&fs->pwd, old_root, new_root);
55736 write_seqcount_end(&fs->seq);
55737@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
55738 task_lock(tsk);
55739 spin_lock(&fs->lock);
55740 tsk->fs = NULL;
55741- kill = !--fs->users;
55742+ gr_clear_chroot_entries(tsk);
55743+ kill = !atomic_dec_return(&fs->users);
55744 spin_unlock(&fs->lock);
55745 task_unlock(tsk);
55746 if (kill)
55747@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
55748 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
55749 /* We don't need to lock fs - think why ;-) */
55750 if (fs) {
55751- fs->users = 1;
55752+ atomic_set(&fs->users, 1);
55753 fs->in_exec = 0;
55754 spin_lock_init(&fs->lock);
55755 seqcount_init(&fs->seq);
55756@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
55757 spin_lock(&old->lock);
55758 fs->root = old->root;
55759 path_get(&fs->root);
55760+ /* instead of calling gr_set_chroot_entries here,
55761+ we call it from every caller of this function
55762+ */
55763 fs->pwd = old->pwd;
55764 path_get(&fs->pwd);
55765 spin_unlock(&old->lock);
55766@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
55767
55768 task_lock(current);
55769 spin_lock(&fs->lock);
55770- kill = !--fs->users;
55771+ kill = !atomic_dec_return(&fs->users);
55772 current->fs = new_fs;
55773+ gr_set_chroot_entries(current, &new_fs->root);
55774 spin_unlock(&fs->lock);
55775 task_unlock(current);
55776
55777@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
55778
55779 int current_umask(void)
55780 {
55781- return current->fs->umask;
55782+ return current->fs->umask | gr_acl_umask();
55783 }
55784 EXPORT_SYMBOL(current_umask);
55785
55786 /* to be mentioned only in INIT_TASK */
55787 struct fs_struct init_fs = {
55788- .users = 1,
55789+ .users = ATOMIC_INIT(1),
55790 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
55791 .seq = SEQCNT_ZERO,
55792 .umask = 0022,
55793diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
55794index 0e91a3c..6c6d2e0 100644
55795--- a/fs/fscache/cookie.c
55796+++ b/fs/fscache/cookie.c
55797@@ -19,7 +19,7 @@
55798
55799 struct kmem_cache *fscache_cookie_jar;
55800
55801-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
55802+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
55803
55804 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
55805 static int fscache_alloc_object(struct fscache_cache *cache,
55806@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
55807 parent ? (char *) parent->def->name : "<no-parent>",
55808 def->name, netfs_data);
55809
55810- fscache_stat(&fscache_n_acquires);
55811+ fscache_stat_unchecked(&fscache_n_acquires);
55812
55813 /* if there's no parent cookie, then we don't create one here either */
55814 if (!parent) {
55815- fscache_stat(&fscache_n_acquires_null);
55816+ fscache_stat_unchecked(&fscache_n_acquires_null);
55817 _leave(" [no parent]");
55818 return NULL;
55819 }
55820@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
55821 /* allocate and initialise a cookie */
55822 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
55823 if (!cookie) {
55824- fscache_stat(&fscache_n_acquires_oom);
55825+ fscache_stat_unchecked(&fscache_n_acquires_oom);
55826 _leave(" [ENOMEM]");
55827 return NULL;
55828 }
55829@@ -114,13 +114,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
55830
55831 switch (cookie->def->type) {
55832 case FSCACHE_COOKIE_TYPE_INDEX:
55833- fscache_stat(&fscache_n_cookie_index);
55834+ fscache_stat_unchecked(&fscache_n_cookie_index);
55835 break;
55836 case FSCACHE_COOKIE_TYPE_DATAFILE:
55837- fscache_stat(&fscache_n_cookie_data);
55838+ fscache_stat_unchecked(&fscache_n_cookie_data);
55839 break;
55840 default:
55841- fscache_stat(&fscache_n_cookie_special);
55842+ fscache_stat_unchecked(&fscache_n_cookie_special);
55843 break;
55844 }
55845
55846@@ -131,13 +131,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
55847 if (fscache_acquire_non_index_cookie(cookie) < 0) {
55848 atomic_dec(&parent->n_children);
55849 __fscache_cookie_put(cookie);
55850- fscache_stat(&fscache_n_acquires_nobufs);
55851+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
55852 _leave(" = NULL");
55853 return NULL;
55854 }
55855 }
55856
55857- fscache_stat(&fscache_n_acquires_ok);
55858+ fscache_stat_unchecked(&fscache_n_acquires_ok);
55859 _leave(" = %p", cookie);
55860 return cookie;
55861 }
55862@@ -173,7 +173,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
55863 cache = fscache_select_cache_for_object(cookie->parent);
55864 if (!cache) {
55865 up_read(&fscache_addremove_sem);
55866- fscache_stat(&fscache_n_acquires_no_cache);
55867+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
55868 _leave(" = -ENOMEDIUM [no cache]");
55869 return -ENOMEDIUM;
55870 }
55871@@ -259,14 +259,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
55872 object = cache->ops->alloc_object(cache, cookie);
55873 fscache_stat_d(&fscache_n_cop_alloc_object);
55874 if (IS_ERR(object)) {
55875- fscache_stat(&fscache_n_object_no_alloc);
55876+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
55877 ret = PTR_ERR(object);
55878 goto error;
55879 }
55880
55881- fscache_stat(&fscache_n_object_alloc);
55882+ fscache_stat_unchecked(&fscache_n_object_alloc);
55883
55884- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
55885+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
55886
55887 _debug("ALLOC OBJ%x: %s {%lx}",
55888 object->debug_id, cookie->def->name, object->events);
55889@@ -380,7 +380,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
55890
55891 _enter("{%s}", cookie->def->name);
55892
55893- fscache_stat(&fscache_n_invalidates);
55894+ fscache_stat_unchecked(&fscache_n_invalidates);
55895
55896 /* Only permit invalidation of data files. Invalidating an index will
55897 * require the caller to release all its attachments to the tree rooted
55898@@ -438,10 +438,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
55899 {
55900 struct fscache_object *object;
55901
55902- fscache_stat(&fscache_n_updates);
55903+ fscache_stat_unchecked(&fscache_n_updates);
55904
55905 if (!cookie) {
55906- fscache_stat(&fscache_n_updates_null);
55907+ fscache_stat_unchecked(&fscache_n_updates_null);
55908 _leave(" [no cookie]");
55909 return;
55910 }
55911@@ -473,12 +473,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
55912 {
55913 struct fscache_object *object;
55914
55915- fscache_stat(&fscache_n_relinquishes);
55916+ fscache_stat_unchecked(&fscache_n_relinquishes);
55917 if (retire)
55918- fscache_stat(&fscache_n_relinquishes_retire);
55919+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
55920
55921 if (!cookie) {
55922- fscache_stat(&fscache_n_relinquishes_null);
55923+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
55924 _leave(" [no cookie]");
55925 return;
55926 }
55927diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
55928index 12d505b..86473a3 100644
55929--- a/fs/fscache/internal.h
55930+++ b/fs/fscache/internal.h
55931@@ -147,101 +147,101 @@ extern void fscache_proc_cleanup(void);
55932 * stats.c
55933 */
55934 #ifdef CONFIG_FSCACHE_STATS
55935-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
55936-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
55937+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
55938+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
55939
55940-extern atomic_t fscache_n_op_pend;
55941-extern atomic_t fscache_n_op_run;
55942-extern atomic_t fscache_n_op_enqueue;
55943-extern atomic_t fscache_n_op_deferred_release;
55944-extern atomic_t fscache_n_op_release;
55945-extern atomic_t fscache_n_op_gc;
55946-extern atomic_t fscache_n_op_cancelled;
55947-extern atomic_t fscache_n_op_rejected;
55948+extern atomic_unchecked_t fscache_n_op_pend;
55949+extern atomic_unchecked_t fscache_n_op_run;
55950+extern atomic_unchecked_t fscache_n_op_enqueue;
55951+extern atomic_unchecked_t fscache_n_op_deferred_release;
55952+extern atomic_unchecked_t fscache_n_op_release;
55953+extern atomic_unchecked_t fscache_n_op_gc;
55954+extern atomic_unchecked_t fscache_n_op_cancelled;
55955+extern atomic_unchecked_t fscache_n_op_rejected;
55956
55957-extern atomic_t fscache_n_attr_changed;
55958-extern atomic_t fscache_n_attr_changed_ok;
55959-extern atomic_t fscache_n_attr_changed_nobufs;
55960-extern atomic_t fscache_n_attr_changed_nomem;
55961-extern atomic_t fscache_n_attr_changed_calls;
55962+extern atomic_unchecked_t fscache_n_attr_changed;
55963+extern atomic_unchecked_t fscache_n_attr_changed_ok;
55964+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
55965+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
55966+extern atomic_unchecked_t fscache_n_attr_changed_calls;
55967
55968-extern atomic_t fscache_n_allocs;
55969-extern atomic_t fscache_n_allocs_ok;
55970-extern atomic_t fscache_n_allocs_wait;
55971-extern atomic_t fscache_n_allocs_nobufs;
55972-extern atomic_t fscache_n_allocs_intr;
55973-extern atomic_t fscache_n_allocs_object_dead;
55974-extern atomic_t fscache_n_alloc_ops;
55975-extern atomic_t fscache_n_alloc_op_waits;
55976+extern atomic_unchecked_t fscache_n_allocs;
55977+extern atomic_unchecked_t fscache_n_allocs_ok;
55978+extern atomic_unchecked_t fscache_n_allocs_wait;
55979+extern atomic_unchecked_t fscache_n_allocs_nobufs;
55980+extern atomic_unchecked_t fscache_n_allocs_intr;
55981+extern atomic_unchecked_t fscache_n_allocs_object_dead;
55982+extern atomic_unchecked_t fscache_n_alloc_ops;
55983+extern atomic_unchecked_t fscache_n_alloc_op_waits;
55984
55985-extern atomic_t fscache_n_retrievals;
55986-extern atomic_t fscache_n_retrievals_ok;
55987-extern atomic_t fscache_n_retrievals_wait;
55988-extern atomic_t fscache_n_retrievals_nodata;
55989-extern atomic_t fscache_n_retrievals_nobufs;
55990-extern atomic_t fscache_n_retrievals_intr;
55991-extern atomic_t fscache_n_retrievals_nomem;
55992-extern atomic_t fscache_n_retrievals_object_dead;
55993-extern atomic_t fscache_n_retrieval_ops;
55994-extern atomic_t fscache_n_retrieval_op_waits;
55995+extern atomic_unchecked_t fscache_n_retrievals;
55996+extern atomic_unchecked_t fscache_n_retrievals_ok;
55997+extern atomic_unchecked_t fscache_n_retrievals_wait;
55998+extern atomic_unchecked_t fscache_n_retrievals_nodata;
55999+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
56000+extern atomic_unchecked_t fscache_n_retrievals_intr;
56001+extern atomic_unchecked_t fscache_n_retrievals_nomem;
56002+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
56003+extern atomic_unchecked_t fscache_n_retrieval_ops;
56004+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
56005
56006-extern atomic_t fscache_n_stores;
56007-extern atomic_t fscache_n_stores_ok;
56008-extern atomic_t fscache_n_stores_again;
56009-extern atomic_t fscache_n_stores_nobufs;
56010-extern atomic_t fscache_n_stores_oom;
56011-extern atomic_t fscache_n_store_ops;
56012-extern atomic_t fscache_n_store_calls;
56013-extern atomic_t fscache_n_store_pages;
56014-extern atomic_t fscache_n_store_radix_deletes;
56015-extern atomic_t fscache_n_store_pages_over_limit;
56016+extern atomic_unchecked_t fscache_n_stores;
56017+extern atomic_unchecked_t fscache_n_stores_ok;
56018+extern atomic_unchecked_t fscache_n_stores_again;
56019+extern atomic_unchecked_t fscache_n_stores_nobufs;
56020+extern atomic_unchecked_t fscache_n_stores_oom;
56021+extern atomic_unchecked_t fscache_n_store_ops;
56022+extern atomic_unchecked_t fscache_n_store_calls;
56023+extern atomic_unchecked_t fscache_n_store_pages;
56024+extern atomic_unchecked_t fscache_n_store_radix_deletes;
56025+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
56026
56027-extern atomic_t fscache_n_store_vmscan_not_storing;
56028-extern atomic_t fscache_n_store_vmscan_gone;
56029-extern atomic_t fscache_n_store_vmscan_busy;
56030-extern atomic_t fscache_n_store_vmscan_cancelled;
56031-extern atomic_t fscache_n_store_vmscan_wait;
56032+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
56033+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
56034+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
56035+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
56036+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
56037
56038-extern atomic_t fscache_n_marks;
56039-extern atomic_t fscache_n_uncaches;
56040+extern atomic_unchecked_t fscache_n_marks;
56041+extern atomic_unchecked_t fscache_n_uncaches;
56042
56043-extern atomic_t fscache_n_acquires;
56044-extern atomic_t fscache_n_acquires_null;
56045-extern atomic_t fscache_n_acquires_no_cache;
56046-extern atomic_t fscache_n_acquires_ok;
56047-extern atomic_t fscache_n_acquires_nobufs;
56048-extern atomic_t fscache_n_acquires_oom;
56049+extern atomic_unchecked_t fscache_n_acquires;
56050+extern atomic_unchecked_t fscache_n_acquires_null;
56051+extern atomic_unchecked_t fscache_n_acquires_no_cache;
56052+extern atomic_unchecked_t fscache_n_acquires_ok;
56053+extern atomic_unchecked_t fscache_n_acquires_nobufs;
56054+extern atomic_unchecked_t fscache_n_acquires_oom;
56055
56056-extern atomic_t fscache_n_invalidates;
56057-extern atomic_t fscache_n_invalidates_run;
56058+extern atomic_unchecked_t fscache_n_invalidates;
56059+extern atomic_unchecked_t fscache_n_invalidates_run;
56060
56061-extern atomic_t fscache_n_updates;
56062-extern atomic_t fscache_n_updates_null;
56063-extern atomic_t fscache_n_updates_run;
56064+extern atomic_unchecked_t fscache_n_updates;
56065+extern atomic_unchecked_t fscache_n_updates_null;
56066+extern atomic_unchecked_t fscache_n_updates_run;
56067
56068-extern atomic_t fscache_n_relinquishes;
56069-extern atomic_t fscache_n_relinquishes_null;
56070-extern atomic_t fscache_n_relinquishes_waitcrt;
56071-extern atomic_t fscache_n_relinquishes_retire;
56072+extern atomic_unchecked_t fscache_n_relinquishes;
56073+extern atomic_unchecked_t fscache_n_relinquishes_null;
56074+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
56075+extern atomic_unchecked_t fscache_n_relinquishes_retire;
56076
56077-extern atomic_t fscache_n_cookie_index;
56078-extern atomic_t fscache_n_cookie_data;
56079-extern atomic_t fscache_n_cookie_special;
56080+extern atomic_unchecked_t fscache_n_cookie_index;
56081+extern atomic_unchecked_t fscache_n_cookie_data;
56082+extern atomic_unchecked_t fscache_n_cookie_special;
56083
56084-extern atomic_t fscache_n_object_alloc;
56085-extern atomic_t fscache_n_object_no_alloc;
56086-extern atomic_t fscache_n_object_lookups;
56087-extern atomic_t fscache_n_object_lookups_negative;
56088-extern atomic_t fscache_n_object_lookups_positive;
56089-extern atomic_t fscache_n_object_lookups_timed_out;
56090-extern atomic_t fscache_n_object_created;
56091-extern atomic_t fscache_n_object_avail;
56092-extern atomic_t fscache_n_object_dead;
56093+extern atomic_unchecked_t fscache_n_object_alloc;
56094+extern atomic_unchecked_t fscache_n_object_no_alloc;
56095+extern atomic_unchecked_t fscache_n_object_lookups;
56096+extern atomic_unchecked_t fscache_n_object_lookups_negative;
56097+extern atomic_unchecked_t fscache_n_object_lookups_positive;
56098+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
56099+extern atomic_unchecked_t fscache_n_object_created;
56100+extern atomic_unchecked_t fscache_n_object_avail;
56101+extern atomic_unchecked_t fscache_n_object_dead;
56102
56103-extern atomic_t fscache_n_checkaux_none;
56104-extern atomic_t fscache_n_checkaux_okay;
56105-extern atomic_t fscache_n_checkaux_update;
56106-extern atomic_t fscache_n_checkaux_obsolete;
56107+extern atomic_unchecked_t fscache_n_checkaux_none;
56108+extern atomic_unchecked_t fscache_n_checkaux_okay;
56109+extern atomic_unchecked_t fscache_n_checkaux_update;
56110+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
56111
56112 extern atomic_t fscache_n_cop_alloc_object;
56113 extern atomic_t fscache_n_cop_lookup_object;
56114@@ -266,6 +266,11 @@ static inline void fscache_stat(atomic_t *stat)
56115 atomic_inc(stat);
56116 }
56117
56118+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
56119+{
56120+ atomic_inc_unchecked(stat);
56121+}
56122+
56123 static inline void fscache_stat_d(atomic_t *stat)
56124 {
56125 atomic_dec(stat);
56126@@ -278,6 +283,7 @@ extern const struct file_operations fscache_stats_fops;
56127
56128 #define __fscache_stat(stat) (NULL)
56129 #define fscache_stat(stat) do {} while (0)
56130+#define fscache_stat_unchecked(stat) do {} while (0)
56131 #define fscache_stat_d(stat) do {} while (0)
56132 #endif
56133
56134diff --git a/fs/fscache/object.c b/fs/fscache/object.c
56135index 86d75a6..5f3d7a0 100644
56136--- a/fs/fscache/object.c
56137+++ b/fs/fscache/object.c
56138@@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56139 _debug("LOOKUP \"%s\" in \"%s\"",
56140 cookie->def->name, object->cache->tag->name);
56141
56142- fscache_stat(&fscache_n_object_lookups);
56143+ fscache_stat_unchecked(&fscache_n_object_lookups);
56144 fscache_stat(&fscache_n_cop_lookup_object);
56145 ret = object->cache->ops->lookup_object(object);
56146 fscache_stat_d(&fscache_n_cop_lookup_object);
56147@@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56148 if (ret == -ETIMEDOUT) {
56149 /* probably stuck behind another object, so move this one to
56150 * the back of the queue */
56151- fscache_stat(&fscache_n_object_lookups_timed_out);
56152+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
56153 _leave(" [timeout]");
56154 return NO_TRANSIT;
56155 }
56156@@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
56157 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
56158
56159 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56160- fscache_stat(&fscache_n_object_lookups_negative);
56161+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
56162
56163 /* Allow write requests to begin stacking up and read requests to begin
56164 * returning ENODATA.
56165@@ -523,7 +523,7 @@ void fscache_obtained_object(struct fscache_object *object)
56166 /* if we were still looking up, then we must have a positive lookup
56167 * result, in which case there may be data available */
56168 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56169- fscache_stat(&fscache_n_object_lookups_positive);
56170+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
56171
56172 /* We do (presumably) have data */
56173 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
56174@@ -534,7 +534,7 @@ void fscache_obtained_object(struct fscache_object *object)
56175 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
56176 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
56177 } else {
56178- fscache_stat(&fscache_n_object_created);
56179+ fscache_stat_unchecked(&fscache_n_object_created);
56180 }
56181
56182 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
56183@@ -570,7 +570,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
56184 fscache_stat_d(&fscache_n_cop_lookup_complete);
56185
56186 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
56187- fscache_stat(&fscache_n_object_avail);
56188+ fscache_stat_unchecked(&fscache_n_object_avail);
56189
56190 _leave("");
56191 return transit_to(JUMPSTART_DEPS);
56192@@ -716,7 +716,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
56193
56194 /* this just shifts the object release to the work processor */
56195 fscache_put_object(object);
56196- fscache_stat(&fscache_n_object_dead);
56197+ fscache_stat_unchecked(&fscache_n_object_dead);
56198
56199 _leave("");
56200 return transit_to(OBJECT_DEAD);
56201@@ -881,7 +881,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56202 enum fscache_checkaux result;
56203
56204 if (!object->cookie->def->check_aux) {
56205- fscache_stat(&fscache_n_checkaux_none);
56206+ fscache_stat_unchecked(&fscache_n_checkaux_none);
56207 return FSCACHE_CHECKAUX_OKAY;
56208 }
56209
56210@@ -890,17 +890,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56211 switch (result) {
56212 /* entry okay as is */
56213 case FSCACHE_CHECKAUX_OKAY:
56214- fscache_stat(&fscache_n_checkaux_okay);
56215+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
56216 break;
56217
56218 /* entry requires update */
56219 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
56220- fscache_stat(&fscache_n_checkaux_update);
56221+ fscache_stat_unchecked(&fscache_n_checkaux_update);
56222 break;
56223
56224 /* entry requires deletion */
56225 case FSCACHE_CHECKAUX_OBSOLETE:
56226- fscache_stat(&fscache_n_checkaux_obsolete);
56227+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
56228 break;
56229
56230 default:
56231@@ -986,7 +986,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
56232 {
56233 const struct fscache_state *s;
56234
56235- fscache_stat(&fscache_n_invalidates_run);
56236+ fscache_stat_unchecked(&fscache_n_invalidates_run);
56237 fscache_stat(&fscache_n_cop_invalidate_object);
56238 s = _fscache_invalidate_object(object, event);
56239 fscache_stat_d(&fscache_n_cop_invalidate_object);
56240@@ -1001,7 +1001,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
56241 {
56242 _enter("{OBJ%x},%d", object->debug_id, event);
56243
56244- fscache_stat(&fscache_n_updates_run);
56245+ fscache_stat_unchecked(&fscache_n_updates_run);
56246 fscache_stat(&fscache_n_cop_update_object);
56247 object->cache->ops->update_object(object);
56248 fscache_stat_d(&fscache_n_cop_update_object);
56249diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
56250index 318071a..379938b 100644
56251--- a/fs/fscache/operation.c
56252+++ b/fs/fscache/operation.c
56253@@ -17,7 +17,7 @@
56254 #include <linux/slab.h>
56255 #include "internal.h"
56256
56257-atomic_t fscache_op_debug_id;
56258+atomic_unchecked_t fscache_op_debug_id;
56259 EXPORT_SYMBOL(fscache_op_debug_id);
56260
56261 /**
56262@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
56263 ASSERTCMP(atomic_read(&op->usage), >, 0);
56264 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
56265
56266- fscache_stat(&fscache_n_op_enqueue);
56267+ fscache_stat_unchecked(&fscache_n_op_enqueue);
56268 switch (op->flags & FSCACHE_OP_TYPE) {
56269 case FSCACHE_OP_ASYNC:
56270 _debug("queue async");
56271@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
56272 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
56273 if (op->processor)
56274 fscache_enqueue_operation(op);
56275- fscache_stat(&fscache_n_op_run);
56276+ fscache_stat_unchecked(&fscache_n_op_run);
56277 }
56278
56279 /*
56280@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56281 if (object->n_in_progress > 0) {
56282 atomic_inc(&op->usage);
56283 list_add_tail(&op->pend_link, &object->pending_ops);
56284- fscache_stat(&fscache_n_op_pend);
56285+ fscache_stat_unchecked(&fscache_n_op_pend);
56286 } else if (!list_empty(&object->pending_ops)) {
56287 atomic_inc(&op->usage);
56288 list_add_tail(&op->pend_link, &object->pending_ops);
56289- fscache_stat(&fscache_n_op_pend);
56290+ fscache_stat_unchecked(&fscache_n_op_pend);
56291 fscache_start_operations(object);
56292 } else {
56293 ASSERTCMP(object->n_in_progress, ==, 0);
56294@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56295 object->n_exclusive++; /* reads and writes must wait */
56296 atomic_inc(&op->usage);
56297 list_add_tail(&op->pend_link, &object->pending_ops);
56298- fscache_stat(&fscache_n_op_pend);
56299+ fscache_stat_unchecked(&fscache_n_op_pend);
56300 ret = 0;
56301 } else {
56302 /* If we're in any other state, there must have been an I/O
56303@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
56304 if (object->n_exclusive > 0) {
56305 atomic_inc(&op->usage);
56306 list_add_tail(&op->pend_link, &object->pending_ops);
56307- fscache_stat(&fscache_n_op_pend);
56308+ fscache_stat_unchecked(&fscache_n_op_pend);
56309 } else if (!list_empty(&object->pending_ops)) {
56310 atomic_inc(&op->usage);
56311 list_add_tail(&op->pend_link, &object->pending_ops);
56312- fscache_stat(&fscache_n_op_pend);
56313+ fscache_stat_unchecked(&fscache_n_op_pend);
56314 fscache_start_operations(object);
56315 } else {
56316 ASSERTCMP(object->n_exclusive, ==, 0);
56317@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
56318 object->n_ops++;
56319 atomic_inc(&op->usage);
56320 list_add_tail(&op->pend_link, &object->pending_ops);
56321- fscache_stat(&fscache_n_op_pend);
56322+ fscache_stat_unchecked(&fscache_n_op_pend);
56323 ret = 0;
56324 } else if (fscache_object_is_dying(object)) {
56325- fscache_stat(&fscache_n_op_rejected);
56326+ fscache_stat_unchecked(&fscache_n_op_rejected);
56327 op->state = FSCACHE_OP_ST_CANCELLED;
56328 ret = -ENOBUFS;
56329 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
56330@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
56331 ret = -EBUSY;
56332 if (op->state == FSCACHE_OP_ST_PENDING) {
56333 ASSERT(!list_empty(&op->pend_link));
56334- fscache_stat(&fscache_n_op_cancelled);
56335+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56336 list_del_init(&op->pend_link);
56337 if (do_cancel)
56338 do_cancel(op);
56339@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
56340 while (!list_empty(&object->pending_ops)) {
56341 op = list_entry(object->pending_ops.next,
56342 struct fscache_operation, pend_link);
56343- fscache_stat(&fscache_n_op_cancelled);
56344+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56345 list_del_init(&op->pend_link);
56346
56347 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
56348@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
56349 op->state, ==, FSCACHE_OP_ST_CANCELLED);
56350 op->state = FSCACHE_OP_ST_DEAD;
56351
56352- fscache_stat(&fscache_n_op_release);
56353+ fscache_stat_unchecked(&fscache_n_op_release);
56354
56355 if (op->release) {
56356 op->release(op);
56357@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
56358 * lock, and defer it otherwise */
56359 if (!spin_trylock(&object->lock)) {
56360 _debug("defer put");
56361- fscache_stat(&fscache_n_op_deferred_release);
56362+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
56363
56364 cache = object->cache;
56365 spin_lock(&cache->op_gc_list_lock);
56366@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
56367
56368 _debug("GC DEFERRED REL OBJ%x OP%x",
56369 object->debug_id, op->debug_id);
56370- fscache_stat(&fscache_n_op_gc);
56371+ fscache_stat_unchecked(&fscache_n_op_gc);
56372
56373 ASSERTCMP(atomic_read(&op->usage), ==, 0);
56374 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
56375diff --git a/fs/fscache/page.c b/fs/fscache/page.c
56376index d479ab3..727a7f2 100644
56377--- a/fs/fscache/page.c
56378+++ b/fs/fscache/page.c
56379@@ -61,7 +61,7 @@ try_again:
56380 val = radix_tree_lookup(&cookie->stores, page->index);
56381 if (!val) {
56382 rcu_read_unlock();
56383- fscache_stat(&fscache_n_store_vmscan_not_storing);
56384+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
56385 __fscache_uncache_page(cookie, page);
56386 return true;
56387 }
56388@@ -91,11 +91,11 @@ try_again:
56389 spin_unlock(&cookie->stores_lock);
56390
56391 if (xpage) {
56392- fscache_stat(&fscache_n_store_vmscan_cancelled);
56393- fscache_stat(&fscache_n_store_radix_deletes);
56394+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
56395+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56396 ASSERTCMP(xpage, ==, page);
56397 } else {
56398- fscache_stat(&fscache_n_store_vmscan_gone);
56399+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
56400 }
56401
56402 wake_up_bit(&cookie->flags, 0);
56403@@ -110,11 +110,11 @@ page_busy:
56404 * sleeping on memory allocation, so we may need to impose a timeout
56405 * too. */
56406 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
56407- fscache_stat(&fscache_n_store_vmscan_busy);
56408+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
56409 return false;
56410 }
56411
56412- fscache_stat(&fscache_n_store_vmscan_wait);
56413+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
56414 __fscache_wait_on_page_write(cookie, page);
56415 gfp &= ~__GFP_WAIT;
56416 goto try_again;
56417@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
56418 FSCACHE_COOKIE_STORING_TAG);
56419 if (!radix_tree_tag_get(&cookie->stores, page->index,
56420 FSCACHE_COOKIE_PENDING_TAG)) {
56421- fscache_stat(&fscache_n_store_radix_deletes);
56422+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56423 xpage = radix_tree_delete(&cookie->stores, page->index);
56424 }
56425 spin_unlock(&cookie->stores_lock);
56426@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
56427
56428 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
56429
56430- fscache_stat(&fscache_n_attr_changed_calls);
56431+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
56432
56433 if (fscache_object_is_active(object) &&
56434 fscache_use_cookie(object)) {
56435@@ -189,11 +189,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56436
56437 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56438
56439- fscache_stat(&fscache_n_attr_changed);
56440+ fscache_stat_unchecked(&fscache_n_attr_changed);
56441
56442 op = kzalloc(sizeof(*op), GFP_KERNEL);
56443 if (!op) {
56444- fscache_stat(&fscache_n_attr_changed_nomem);
56445+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
56446 _leave(" = -ENOMEM");
56447 return -ENOMEM;
56448 }
56449@@ -211,7 +211,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56450 if (fscache_submit_exclusive_op(object, op) < 0)
56451 goto nobufs;
56452 spin_unlock(&cookie->lock);
56453- fscache_stat(&fscache_n_attr_changed_ok);
56454+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
56455 fscache_put_operation(op);
56456 _leave(" = 0");
56457 return 0;
56458@@ -219,7 +219,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56459 nobufs:
56460 spin_unlock(&cookie->lock);
56461 kfree(op);
56462- fscache_stat(&fscache_n_attr_changed_nobufs);
56463+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
56464 _leave(" = %d", -ENOBUFS);
56465 return -ENOBUFS;
56466 }
56467@@ -258,7 +258,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
56468 /* allocate a retrieval operation and attempt to submit it */
56469 op = kzalloc(sizeof(*op), GFP_NOIO);
56470 if (!op) {
56471- fscache_stat(&fscache_n_retrievals_nomem);
56472+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56473 return NULL;
56474 }
56475
56476@@ -289,13 +289,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
56477 return 0;
56478 }
56479
56480- fscache_stat(&fscache_n_retrievals_wait);
56481+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
56482
56483 jif = jiffies;
56484 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
56485 fscache_wait_bit_interruptible,
56486 TASK_INTERRUPTIBLE) != 0) {
56487- fscache_stat(&fscache_n_retrievals_intr);
56488+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56489 _leave(" = -ERESTARTSYS");
56490 return -ERESTARTSYS;
56491 }
56492@@ -324,8 +324,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
56493 */
56494 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56495 struct fscache_retrieval *op,
56496- atomic_t *stat_op_waits,
56497- atomic_t *stat_object_dead)
56498+ atomic_unchecked_t *stat_op_waits,
56499+ atomic_unchecked_t *stat_object_dead)
56500 {
56501 int ret;
56502
56503@@ -333,7 +333,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56504 goto check_if_dead;
56505
56506 _debug(">>> WT");
56507- fscache_stat(stat_op_waits);
56508+ fscache_stat_unchecked(stat_op_waits);
56509 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
56510 fscache_wait_bit_interruptible,
56511 TASK_INTERRUPTIBLE) != 0) {
56512@@ -350,14 +350,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56513
56514 check_if_dead:
56515 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
56516- fscache_stat(stat_object_dead);
56517+ fscache_stat_unchecked(stat_object_dead);
56518 _leave(" = -ENOBUFS [cancelled]");
56519 return -ENOBUFS;
56520 }
56521 if (unlikely(fscache_object_is_dead(object))) {
56522 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
56523 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
56524- fscache_stat(stat_object_dead);
56525+ fscache_stat_unchecked(stat_object_dead);
56526 return -ENOBUFS;
56527 }
56528 return 0;
56529@@ -384,7 +384,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56530
56531 _enter("%p,%p,,,", cookie, page);
56532
56533- fscache_stat(&fscache_n_retrievals);
56534+ fscache_stat_unchecked(&fscache_n_retrievals);
56535
56536 if (hlist_empty(&cookie->backing_objects))
56537 goto nobufs;
56538@@ -424,7 +424,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56539 goto nobufs_unlock_dec;
56540 spin_unlock(&cookie->lock);
56541
56542- fscache_stat(&fscache_n_retrieval_ops);
56543+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
56544
56545 /* pin the netfs read context in case we need to do the actual netfs
56546 * read because we've encountered a cache read failure */
56547@@ -454,15 +454,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56548
56549 error:
56550 if (ret == -ENOMEM)
56551- fscache_stat(&fscache_n_retrievals_nomem);
56552+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56553 else if (ret == -ERESTARTSYS)
56554- fscache_stat(&fscache_n_retrievals_intr);
56555+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56556 else if (ret == -ENODATA)
56557- fscache_stat(&fscache_n_retrievals_nodata);
56558+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
56559 else if (ret < 0)
56560- fscache_stat(&fscache_n_retrievals_nobufs);
56561+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56562 else
56563- fscache_stat(&fscache_n_retrievals_ok);
56564+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
56565
56566 fscache_put_retrieval(op);
56567 _leave(" = %d", ret);
56568@@ -475,7 +475,7 @@ nobufs_unlock:
56569 atomic_dec(&cookie->n_active);
56570 kfree(op);
56571 nobufs:
56572- fscache_stat(&fscache_n_retrievals_nobufs);
56573+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56574 _leave(" = -ENOBUFS");
56575 return -ENOBUFS;
56576 }
56577@@ -513,7 +513,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56578
56579 _enter("%p,,%d,,,", cookie, *nr_pages);
56580
56581- fscache_stat(&fscache_n_retrievals);
56582+ fscache_stat_unchecked(&fscache_n_retrievals);
56583
56584 if (hlist_empty(&cookie->backing_objects))
56585 goto nobufs;
56586@@ -549,7 +549,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56587 goto nobufs_unlock_dec;
56588 spin_unlock(&cookie->lock);
56589
56590- fscache_stat(&fscache_n_retrieval_ops);
56591+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
56592
56593 /* pin the netfs read context in case we need to do the actual netfs
56594 * read because we've encountered a cache read failure */
56595@@ -579,15 +579,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56596
56597 error:
56598 if (ret == -ENOMEM)
56599- fscache_stat(&fscache_n_retrievals_nomem);
56600+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56601 else if (ret == -ERESTARTSYS)
56602- fscache_stat(&fscache_n_retrievals_intr);
56603+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56604 else if (ret == -ENODATA)
56605- fscache_stat(&fscache_n_retrievals_nodata);
56606+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
56607 else if (ret < 0)
56608- fscache_stat(&fscache_n_retrievals_nobufs);
56609+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56610 else
56611- fscache_stat(&fscache_n_retrievals_ok);
56612+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
56613
56614 fscache_put_retrieval(op);
56615 _leave(" = %d", ret);
56616@@ -600,7 +600,7 @@ nobufs_unlock:
56617 atomic_dec(&cookie->n_active);
56618 kfree(op);
56619 nobufs:
56620- fscache_stat(&fscache_n_retrievals_nobufs);
56621+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56622 _leave(" = -ENOBUFS");
56623 return -ENOBUFS;
56624 }
56625@@ -624,7 +624,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56626
56627 _enter("%p,%p,,,", cookie, page);
56628
56629- fscache_stat(&fscache_n_allocs);
56630+ fscache_stat_unchecked(&fscache_n_allocs);
56631
56632 if (hlist_empty(&cookie->backing_objects))
56633 goto nobufs;
56634@@ -656,7 +656,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56635 goto nobufs_unlock;
56636 spin_unlock(&cookie->lock);
56637
56638- fscache_stat(&fscache_n_alloc_ops);
56639+ fscache_stat_unchecked(&fscache_n_alloc_ops);
56640
56641 ret = fscache_wait_for_retrieval_activation(
56642 object, op,
56643@@ -672,11 +672,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56644
56645 error:
56646 if (ret == -ERESTARTSYS)
56647- fscache_stat(&fscache_n_allocs_intr);
56648+ fscache_stat_unchecked(&fscache_n_allocs_intr);
56649 else if (ret < 0)
56650- fscache_stat(&fscache_n_allocs_nobufs);
56651+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
56652 else
56653- fscache_stat(&fscache_n_allocs_ok);
56654+ fscache_stat_unchecked(&fscache_n_allocs_ok);
56655
56656 fscache_put_retrieval(op);
56657 _leave(" = %d", ret);
56658@@ -687,7 +687,7 @@ nobufs_unlock:
56659 atomic_dec(&cookie->n_active);
56660 kfree(op);
56661 nobufs:
56662- fscache_stat(&fscache_n_allocs_nobufs);
56663+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
56664 _leave(" = -ENOBUFS");
56665 return -ENOBUFS;
56666 }
56667@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56668
56669 spin_lock(&cookie->stores_lock);
56670
56671- fscache_stat(&fscache_n_store_calls);
56672+ fscache_stat_unchecked(&fscache_n_store_calls);
56673
56674 /* find a page to store */
56675 page = NULL;
56676@@ -758,7 +758,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56677 page = results[0];
56678 _debug("gang %d [%lx]", n, page->index);
56679 if (page->index > op->store_limit) {
56680- fscache_stat(&fscache_n_store_pages_over_limit);
56681+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
56682 goto superseded;
56683 }
56684
56685@@ -770,7 +770,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56686 spin_unlock(&cookie->stores_lock);
56687 spin_unlock(&object->lock);
56688
56689- fscache_stat(&fscache_n_store_pages);
56690+ fscache_stat_unchecked(&fscache_n_store_pages);
56691 fscache_stat(&fscache_n_cop_write_page);
56692 ret = object->cache->ops->write_page(op, page);
56693 fscache_stat_d(&fscache_n_cop_write_page);
56694@@ -873,7 +873,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56695 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56696 ASSERT(PageFsCache(page));
56697
56698- fscache_stat(&fscache_n_stores);
56699+ fscache_stat_unchecked(&fscache_n_stores);
56700
56701 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
56702 _leave(" = -ENOBUFS [invalidating]");
56703@@ -931,7 +931,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56704 spin_unlock(&cookie->stores_lock);
56705 spin_unlock(&object->lock);
56706
56707- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
56708+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
56709 op->store_limit = object->store_limit;
56710
56711 atomic_inc(&cookie->n_active);
56712@@ -940,8 +940,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56713
56714 spin_unlock(&cookie->lock);
56715 radix_tree_preload_end();
56716- fscache_stat(&fscache_n_store_ops);
56717- fscache_stat(&fscache_n_stores_ok);
56718+ fscache_stat_unchecked(&fscache_n_store_ops);
56719+ fscache_stat_unchecked(&fscache_n_stores_ok);
56720
56721 /* the work queue now carries its own ref on the object */
56722 fscache_put_operation(&op->op);
56723@@ -949,14 +949,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56724 return 0;
56725
56726 already_queued:
56727- fscache_stat(&fscache_n_stores_again);
56728+ fscache_stat_unchecked(&fscache_n_stores_again);
56729 already_pending:
56730 spin_unlock(&cookie->stores_lock);
56731 spin_unlock(&object->lock);
56732 spin_unlock(&cookie->lock);
56733 radix_tree_preload_end();
56734 kfree(op);
56735- fscache_stat(&fscache_n_stores_ok);
56736+ fscache_stat_unchecked(&fscache_n_stores_ok);
56737 _leave(" = 0");
56738 return 0;
56739
56740@@ -976,14 +976,14 @@ nobufs:
56741 spin_unlock(&cookie->lock);
56742 radix_tree_preload_end();
56743 kfree(op);
56744- fscache_stat(&fscache_n_stores_nobufs);
56745+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
56746 _leave(" = -ENOBUFS");
56747 return -ENOBUFS;
56748
56749 nomem_free:
56750 kfree(op);
56751 nomem:
56752- fscache_stat(&fscache_n_stores_oom);
56753+ fscache_stat_unchecked(&fscache_n_stores_oom);
56754 _leave(" = -ENOMEM");
56755 return -ENOMEM;
56756 }
56757@@ -1001,7 +1001,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
56758 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56759 ASSERTCMP(page, !=, NULL);
56760
56761- fscache_stat(&fscache_n_uncaches);
56762+ fscache_stat_unchecked(&fscache_n_uncaches);
56763
56764 /* cache withdrawal may beat us to it */
56765 if (!PageFsCache(page))
56766@@ -1052,7 +1052,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
56767 struct fscache_cookie *cookie = op->op.object->cookie;
56768
56769 #ifdef CONFIG_FSCACHE_STATS
56770- atomic_inc(&fscache_n_marks);
56771+ atomic_inc_unchecked(&fscache_n_marks);
56772 #endif
56773
56774 _debug("- mark %p{%lx}", page, page->index);
56775diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
56776index 40d13c7..ddf52b9 100644
56777--- a/fs/fscache/stats.c
56778+++ b/fs/fscache/stats.c
56779@@ -18,99 +18,99 @@
56780 /*
56781 * operation counters
56782 */
56783-atomic_t fscache_n_op_pend;
56784-atomic_t fscache_n_op_run;
56785-atomic_t fscache_n_op_enqueue;
56786-atomic_t fscache_n_op_requeue;
56787-atomic_t fscache_n_op_deferred_release;
56788-atomic_t fscache_n_op_release;
56789-atomic_t fscache_n_op_gc;
56790-atomic_t fscache_n_op_cancelled;
56791-atomic_t fscache_n_op_rejected;
56792+atomic_unchecked_t fscache_n_op_pend;
56793+atomic_unchecked_t fscache_n_op_run;
56794+atomic_unchecked_t fscache_n_op_enqueue;
56795+atomic_unchecked_t fscache_n_op_requeue;
56796+atomic_unchecked_t fscache_n_op_deferred_release;
56797+atomic_unchecked_t fscache_n_op_release;
56798+atomic_unchecked_t fscache_n_op_gc;
56799+atomic_unchecked_t fscache_n_op_cancelled;
56800+atomic_unchecked_t fscache_n_op_rejected;
56801
56802-atomic_t fscache_n_attr_changed;
56803-atomic_t fscache_n_attr_changed_ok;
56804-atomic_t fscache_n_attr_changed_nobufs;
56805-atomic_t fscache_n_attr_changed_nomem;
56806-atomic_t fscache_n_attr_changed_calls;
56807+atomic_unchecked_t fscache_n_attr_changed;
56808+atomic_unchecked_t fscache_n_attr_changed_ok;
56809+atomic_unchecked_t fscache_n_attr_changed_nobufs;
56810+atomic_unchecked_t fscache_n_attr_changed_nomem;
56811+atomic_unchecked_t fscache_n_attr_changed_calls;
56812
56813-atomic_t fscache_n_allocs;
56814-atomic_t fscache_n_allocs_ok;
56815-atomic_t fscache_n_allocs_wait;
56816-atomic_t fscache_n_allocs_nobufs;
56817-atomic_t fscache_n_allocs_intr;
56818-atomic_t fscache_n_allocs_object_dead;
56819-atomic_t fscache_n_alloc_ops;
56820-atomic_t fscache_n_alloc_op_waits;
56821+atomic_unchecked_t fscache_n_allocs;
56822+atomic_unchecked_t fscache_n_allocs_ok;
56823+atomic_unchecked_t fscache_n_allocs_wait;
56824+atomic_unchecked_t fscache_n_allocs_nobufs;
56825+atomic_unchecked_t fscache_n_allocs_intr;
56826+atomic_unchecked_t fscache_n_allocs_object_dead;
56827+atomic_unchecked_t fscache_n_alloc_ops;
56828+atomic_unchecked_t fscache_n_alloc_op_waits;
56829
56830-atomic_t fscache_n_retrievals;
56831-atomic_t fscache_n_retrievals_ok;
56832-atomic_t fscache_n_retrievals_wait;
56833-atomic_t fscache_n_retrievals_nodata;
56834-atomic_t fscache_n_retrievals_nobufs;
56835-atomic_t fscache_n_retrievals_intr;
56836-atomic_t fscache_n_retrievals_nomem;
56837-atomic_t fscache_n_retrievals_object_dead;
56838-atomic_t fscache_n_retrieval_ops;
56839-atomic_t fscache_n_retrieval_op_waits;
56840+atomic_unchecked_t fscache_n_retrievals;
56841+atomic_unchecked_t fscache_n_retrievals_ok;
56842+atomic_unchecked_t fscache_n_retrievals_wait;
56843+atomic_unchecked_t fscache_n_retrievals_nodata;
56844+atomic_unchecked_t fscache_n_retrievals_nobufs;
56845+atomic_unchecked_t fscache_n_retrievals_intr;
56846+atomic_unchecked_t fscache_n_retrievals_nomem;
56847+atomic_unchecked_t fscache_n_retrievals_object_dead;
56848+atomic_unchecked_t fscache_n_retrieval_ops;
56849+atomic_unchecked_t fscache_n_retrieval_op_waits;
56850
56851-atomic_t fscache_n_stores;
56852-atomic_t fscache_n_stores_ok;
56853-atomic_t fscache_n_stores_again;
56854-atomic_t fscache_n_stores_nobufs;
56855-atomic_t fscache_n_stores_oom;
56856-atomic_t fscache_n_store_ops;
56857-atomic_t fscache_n_store_calls;
56858-atomic_t fscache_n_store_pages;
56859-atomic_t fscache_n_store_radix_deletes;
56860-atomic_t fscache_n_store_pages_over_limit;
56861+atomic_unchecked_t fscache_n_stores;
56862+atomic_unchecked_t fscache_n_stores_ok;
56863+atomic_unchecked_t fscache_n_stores_again;
56864+atomic_unchecked_t fscache_n_stores_nobufs;
56865+atomic_unchecked_t fscache_n_stores_oom;
56866+atomic_unchecked_t fscache_n_store_ops;
56867+atomic_unchecked_t fscache_n_store_calls;
56868+atomic_unchecked_t fscache_n_store_pages;
56869+atomic_unchecked_t fscache_n_store_radix_deletes;
56870+atomic_unchecked_t fscache_n_store_pages_over_limit;
56871
56872-atomic_t fscache_n_store_vmscan_not_storing;
56873-atomic_t fscache_n_store_vmscan_gone;
56874-atomic_t fscache_n_store_vmscan_busy;
56875-atomic_t fscache_n_store_vmscan_cancelled;
56876-atomic_t fscache_n_store_vmscan_wait;
56877+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
56878+atomic_unchecked_t fscache_n_store_vmscan_gone;
56879+atomic_unchecked_t fscache_n_store_vmscan_busy;
56880+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
56881+atomic_unchecked_t fscache_n_store_vmscan_wait;
56882
56883-atomic_t fscache_n_marks;
56884-atomic_t fscache_n_uncaches;
56885+atomic_unchecked_t fscache_n_marks;
56886+atomic_unchecked_t fscache_n_uncaches;
56887
56888-atomic_t fscache_n_acquires;
56889-atomic_t fscache_n_acquires_null;
56890-atomic_t fscache_n_acquires_no_cache;
56891-atomic_t fscache_n_acquires_ok;
56892-atomic_t fscache_n_acquires_nobufs;
56893-atomic_t fscache_n_acquires_oom;
56894+atomic_unchecked_t fscache_n_acquires;
56895+atomic_unchecked_t fscache_n_acquires_null;
56896+atomic_unchecked_t fscache_n_acquires_no_cache;
56897+atomic_unchecked_t fscache_n_acquires_ok;
56898+atomic_unchecked_t fscache_n_acquires_nobufs;
56899+atomic_unchecked_t fscache_n_acquires_oom;
56900
56901-atomic_t fscache_n_invalidates;
56902-atomic_t fscache_n_invalidates_run;
56903+atomic_unchecked_t fscache_n_invalidates;
56904+atomic_unchecked_t fscache_n_invalidates_run;
56905
56906-atomic_t fscache_n_updates;
56907-atomic_t fscache_n_updates_null;
56908-atomic_t fscache_n_updates_run;
56909+atomic_unchecked_t fscache_n_updates;
56910+atomic_unchecked_t fscache_n_updates_null;
56911+atomic_unchecked_t fscache_n_updates_run;
56912
56913-atomic_t fscache_n_relinquishes;
56914-atomic_t fscache_n_relinquishes_null;
56915-atomic_t fscache_n_relinquishes_waitcrt;
56916-atomic_t fscache_n_relinquishes_retire;
56917+atomic_unchecked_t fscache_n_relinquishes;
56918+atomic_unchecked_t fscache_n_relinquishes_null;
56919+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
56920+atomic_unchecked_t fscache_n_relinquishes_retire;
56921
56922-atomic_t fscache_n_cookie_index;
56923-atomic_t fscache_n_cookie_data;
56924-atomic_t fscache_n_cookie_special;
56925+atomic_unchecked_t fscache_n_cookie_index;
56926+atomic_unchecked_t fscache_n_cookie_data;
56927+atomic_unchecked_t fscache_n_cookie_special;
56928
56929-atomic_t fscache_n_object_alloc;
56930-atomic_t fscache_n_object_no_alloc;
56931-atomic_t fscache_n_object_lookups;
56932-atomic_t fscache_n_object_lookups_negative;
56933-atomic_t fscache_n_object_lookups_positive;
56934-atomic_t fscache_n_object_lookups_timed_out;
56935-atomic_t fscache_n_object_created;
56936-atomic_t fscache_n_object_avail;
56937-atomic_t fscache_n_object_dead;
56938+atomic_unchecked_t fscache_n_object_alloc;
56939+atomic_unchecked_t fscache_n_object_no_alloc;
56940+atomic_unchecked_t fscache_n_object_lookups;
56941+atomic_unchecked_t fscache_n_object_lookups_negative;
56942+atomic_unchecked_t fscache_n_object_lookups_positive;
56943+atomic_unchecked_t fscache_n_object_lookups_timed_out;
56944+atomic_unchecked_t fscache_n_object_created;
56945+atomic_unchecked_t fscache_n_object_avail;
56946+atomic_unchecked_t fscache_n_object_dead;
56947
56948-atomic_t fscache_n_checkaux_none;
56949-atomic_t fscache_n_checkaux_okay;
56950-atomic_t fscache_n_checkaux_update;
56951-atomic_t fscache_n_checkaux_obsolete;
56952+atomic_unchecked_t fscache_n_checkaux_none;
56953+atomic_unchecked_t fscache_n_checkaux_okay;
56954+atomic_unchecked_t fscache_n_checkaux_update;
56955+atomic_unchecked_t fscache_n_checkaux_obsolete;
56956
56957 atomic_t fscache_n_cop_alloc_object;
56958 atomic_t fscache_n_cop_lookup_object;
56959@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
56960 seq_puts(m, "FS-Cache statistics\n");
56961
56962 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
56963- atomic_read(&fscache_n_cookie_index),
56964- atomic_read(&fscache_n_cookie_data),
56965- atomic_read(&fscache_n_cookie_special));
56966+ atomic_read_unchecked(&fscache_n_cookie_index),
56967+ atomic_read_unchecked(&fscache_n_cookie_data),
56968+ atomic_read_unchecked(&fscache_n_cookie_special));
56969
56970 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
56971- atomic_read(&fscache_n_object_alloc),
56972- atomic_read(&fscache_n_object_no_alloc),
56973- atomic_read(&fscache_n_object_avail),
56974- atomic_read(&fscache_n_object_dead));
56975+ atomic_read_unchecked(&fscache_n_object_alloc),
56976+ atomic_read_unchecked(&fscache_n_object_no_alloc),
56977+ atomic_read_unchecked(&fscache_n_object_avail),
56978+ atomic_read_unchecked(&fscache_n_object_dead));
56979 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
56980- atomic_read(&fscache_n_checkaux_none),
56981- atomic_read(&fscache_n_checkaux_okay),
56982- atomic_read(&fscache_n_checkaux_update),
56983- atomic_read(&fscache_n_checkaux_obsolete));
56984+ atomic_read_unchecked(&fscache_n_checkaux_none),
56985+ atomic_read_unchecked(&fscache_n_checkaux_okay),
56986+ atomic_read_unchecked(&fscache_n_checkaux_update),
56987+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
56988
56989 seq_printf(m, "Pages : mrk=%u unc=%u\n",
56990- atomic_read(&fscache_n_marks),
56991- atomic_read(&fscache_n_uncaches));
56992+ atomic_read_unchecked(&fscache_n_marks),
56993+ atomic_read_unchecked(&fscache_n_uncaches));
56994
56995 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
56996 " oom=%u\n",
56997- atomic_read(&fscache_n_acquires),
56998- atomic_read(&fscache_n_acquires_null),
56999- atomic_read(&fscache_n_acquires_no_cache),
57000- atomic_read(&fscache_n_acquires_ok),
57001- atomic_read(&fscache_n_acquires_nobufs),
57002- atomic_read(&fscache_n_acquires_oom));
57003+ atomic_read_unchecked(&fscache_n_acquires),
57004+ atomic_read_unchecked(&fscache_n_acquires_null),
57005+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
57006+ atomic_read_unchecked(&fscache_n_acquires_ok),
57007+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
57008+ atomic_read_unchecked(&fscache_n_acquires_oom));
57009
57010 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
57011- atomic_read(&fscache_n_object_lookups),
57012- atomic_read(&fscache_n_object_lookups_negative),
57013- atomic_read(&fscache_n_object_lookups_positive),
57014- atomic_read(&fscache_n_object_created),
57015- atomic_read(&fscache_n_object_lookups_timed_out));
57016+ atomic_read_unchecked(&fscache_n_object_lookups),
57017+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
57018+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
57019+ atomic_read_unchecked(&fscache_n_object_created),
57020+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
57021
57022 seq_printf(m, "Invals : n=%u run=%u\n",
57023- atomic_read(&fscache_n_invalidates),
57024- atomic_read(&fscache_n_invalidates_run));
57025+ atomic_read_unchecked(&fscache_n_invalidates),
57026+ atomic_read_unchecked(&fscache_n_invalidates_run));
57027
57028 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
57029- atomic_read(&fscache_n_updates),
57030- atomic_read(&fscache_n_updates_null),
57031- atomic_read(&fscache_n_updates_run));
57032+ atomic_read_unchecked(&fscache_n_updates),
57033+ atomic_read_unchecked(&fscache_n_updates_null),
57034+ atomic_read_unchecked(&fscache_n_updates_run));
57035
57036 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
57037- atomic_read(&fscache_n_relinquishes),
57038- atomic_read(&fscache_n_relinquishes_null),
57039- atomic_read(&fscache_n_relinquishes_waitcrt),
57040- atomic_read(&fscache_n_relinquishes_retire));
57041+ atomic_read_unchecked(&fscache_n_relinquishes),
57042+ atomic_read_unchecked(&fscache_n_relinquishes_null),
57043+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
57044+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
57045
57046 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
57047- atomic_read(&fscache_n_attr_changed),
57048- atomic_read(&fscache_n_attr_changed_ok),
57049- atomic_read(&fscache_n_attr_changed_nobufs),
57050- atomic_read(&fscache_n_attr_changed_nomem),
57051- atomic_read(&fscache_n_attr_changed_calls));
57052+ atomic_read_unchecked(&fscache_n_attr_changed),
57053+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
57054+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
57055+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
57056+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
57057
57058 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
57059- atomic_read(&fscache_n_allocs),
57060- atomic_read(&fscache_n_allocs_ok),
57061- atomic_read(&fscache_n_allocs_wait),
57062- atomic_read(&fscache_n_allocs_nobufs),
57063- atomic_read(&fscache_n_allocs_intr));
57064+ atomic_read_unchecked(&fscache_n_allocs),
57065+ atomic_read_unchecked(&fscache_n_allocs_ok),
57066+ atomic_read_unchecked(&fscache_n_allocs_wait),
57067+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
57068+ atomic_read_unchecked(&fscache_n_allocs_intr));
57069 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
57070- atomic_read(&fscache_n_alloc_ops),
57071- atomic_read(&fscache_n_alloc_op_waits),
57072- atomic_read(&fscache_n_allocs_object_dead));
57073+ atomic_read_unchecked(&fscache_n_alloc_ops),
57074+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
57075+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
57076
57077 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
57078 " int=%u oom=%u\n",
57079- atomic_read(&fscache_n_retrievals),
57080- atomic_read(&fscache_n_retrievals_ok),
57081- atomic_read(&fscache_n_retrievals_wait),
57082- atomic_read(&fscache_n_retrievals_nodata),
57083- atomic_read(&fscache_n_retrievals_nobufs),
57084- atomic_read(&fscache_n_retrievals_intr),
57085- atomic_read(&fscache_n_retrievals_nomem));
57086+ atomic_read_unchecked(&fscache_n_retrievals),
57087+ atomic_read_unchecked(&fscache_n_retrievals_ok),
57088+ atomic_read_unchecked(&fscache_n_retrievals_wait),
57089+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
57090+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
57091+ atomic_read_unchecked(&fscache_n_retrievals_intr),
57092+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
57093 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
57094- atomic_read(&fscache_n_retrieval_ops),
57095- atomic_read(&fscache_n_retrieval_op_waits),
57096- atomic_read(&fscache_n_retrievals_object_dead));
57097+ atomic_read_unchecked(&fscache_n_retrieval_ops),
57098+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
57099+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
57100
57101 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
57102- atomic_read(&fscache_n_stores),
57103- atomic_read(&fscache_n_stores_ok),
57104- atomic_read(&fscache_n_stores_again),
57105- atomic_read(&fscache_n_stores_nobufs),
57106- atomic_read(&fscache_n_stores_oom));
57107+ atomic_read_unchecked(&fscache_n_stores),
57108+ atomic_read_unchecked(&fscache_n_stores_ok),
57109+ atomic_read_unchecked(&fscache_n_stores_again),
57110+ atomic_read_unchecked(&fscache_n_stores_nobufs),
57111+ atomic_read_unchecked(&fscache_n_stores_oom));
57112 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
57113- atomic_read(&fscache_n_store_ops),
57114- atomic_read(&fscache_n_store_calls),
57115- atomic_read(&fscache_n_store_pages),
57116- atomic_read(&fscache_n_store_radix_deletes),
57117- atomic_read(&fscache_n_store_pages_over_limit));
57118+ atomic_read_unchecked(&fscache_n_store_ops),
57119+ atomic_read_unchecked(&fscache_n_store_calls),
57120+ atomic_read_unchecked(&fscache_n_store_pages),
57121+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
57122+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
57123
57124 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
57125- atomic_read(&fscache_n_store_vmscan_not_storing),
57126- atomic_read(&fscache_n_store_vmscan_gone),
57127- atomic_read(&fscache_n_store_vmscan_busy),
57128- atomic_read(&fscache_n_store_vmscan_cancelled),
57129- atomic_read(&fscache_n_store_vmscan_wait));
57130+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
57131+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
57132+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
57133+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
57134+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
57135
57136 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
57137- atomic_read(&fscache_n_op_pend),
57138- atomic_read(&fscache_n_op_run),
57139- atomic_read(&fscache_n_op_enqueue),
57140- atomic_read(&fscache_n_op_cancelled),
57141- atomic_read(&fscache_n_op_rejected));
57142+ atomic_read_unchecked(&fscache_n_op_pend),
57143+ atomic_read_unchecked(&fscache_n_op_run),
57144+ atomic_read_unchecked(&fscache_n_op_enqueue),
57145+ atomic_read_unchecked(&fscache_n_op_cancelled),
57146+ atomic_read_unchecked(&fscache_n_op_rejected));
57147 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
57148- atomic_read(&fscache_n_op_deferred_release),
57149- atomic_read(&fscache_n_op_release),
57150- atomic_read(&fscache_n_op_gc));
57151+ atomic_read_unchecked(&fscache_n_op_deferred_release),
57152+ atomic_read_unchecked(&fscache_n_op_release),
57153+ atomic_read_unchecked(&fscache_n_op_gc));
57154
57155 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
57156 atomic_read(&fscache_n_cop_alloc_object),
57157diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
57158index aef34b1..59bfd7b 100644
57159--- a/fs/fuse/cuse.c
57160+++ b/fs/fuse/cuse.c
57161@@ -600,10 +600,12 @@ static int __init cuse_init(void)
57162 INIT_LIST_HEAD(&cuse_conntbl[i]);
57163
57164 /* inherit and extend fuse_dev_operations */
57165- cuse_channel_fops = fuse_dev_operations;
57166- cuse_channel_fops.owner = THIS_MODULE;
57167- cuse_channel_fops.open = cuse_channel_open;
57168- cuse_channel_fops.release = cuse_channel_release;
57169+ pax_open_kernel();
57170+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
57171+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
57172+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
57173+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
57174+ pax_close_kernel();
57175
57176 cuse_class = class_create(THIS_MODULE, "cuse");
57177 if (IS_ERR(cuse_class))
57178diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
57179index 1d55f94..088da65 100644
57180--- a/fs/fuse/dev.c
57181+++ b/fs/fuse/dev.c
57182@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57183 ret = 0;
57184 pipe_lock(pipe);
57185
57186- if (!pipe->readers) {
57187+ if (!atomic_read(&pipe->readers)) {
57188 send_sig(SIGPIPE, current, 0);
57189 if (!ret)
57190 ret = -EPIPE;
57191@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57192 page_nr++;
57193 ret += buf->len;
57194
57195- if (pipe->files)
57196+ if (atomic_read(&pipe->files))
57197 do_wakeup = 1;
57198 }
57199
57200diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
57201index 72a5d5b..c991011 100644
57202--- a/fs/fuse/dir.c
57203+++ b/fs/fuse/dir.c
57204@@ -1433,7 +1433,7 @@ static char *read_link(struct dentry *dentry)
57205 return link;
57206 }
57207
57208-static void free_link(char *link)
57209+static void free_link(const char *link)
57210 {
57211 if (!IS_ERR(link))
57212 free_page((unsigned long) link);
57213diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
57214index 64915ee..6bed500 100644
57215--- a/fs/gfs2/inode.c
57216+++ b/fs/gfs2/inode.c
57217@@ -1506,7 +1506,7 @@ out:
57218
57219 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
57220 {
57221- char *s = nd_get_link(nd);
57222+ const char *s = nd_get_link(nd);
57223 if (!IS_ERR(s))
57224 kfree(s);
57225 }
57226diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
57227index d19b30a..ef89c36 100644
57228--- a/fs/hugetlbfs/inode.c
57229+++ b/fs/hugetlbfs/inode.c
57230@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57231 struct mm_struct *mm = current->mm;
57232 struct vm_area_struct *vma;
57233 struct hstate *h = hstate_file(file);
57234+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
57235 struct vm_unmapped_area_info info;
57236
57237 if (len & ~huge_page_mask(h))
57238@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57239 return addr;
57240 }
57241
57242+#ifdef CONFIG_PAX_RANDMMAP
57243+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
57244+#endif
57245+
57246 if (addr) {
57247 addr = ALIGN(addr, huge_page_size(h));
57248 vma = find_vma(mm, addr);
57249- if (TASK_SIZE - len >= addr &&
57250- (!vma || addr + len <= vma->vm_start))
57251+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
57252 return addr;
57253 }
57254
57255 info.flags = 0;
57256 info.length = len;
57257 info.low_limit = TASK_UNMAPPED_BASE;
57258+
57259+#ifdef CONFIG_PAX_RANDMMAP
57260+ if (mm->pax_flags & MF_PAX_RANDMMAP)
57261+ info.low_limit += mm->delta_mmap;
57262+#endif
57263+
57264 info.high_limit = TASK_SIZE;
57265 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
57266 info.align_offset = 0;
57267@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
57268 };
57269 MODULE_ALIAS_FS("hugetlbfs");
57270
57271-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57272+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57273
57274 static int can_do_hugetlb_shm(void)
57275 {
57276diff --git a/fs/inode.c b/fs/inode.c
57277index d6dfb09..602e77e 100644
57278--- a/fs/inode.c
57279+++ b/fs/inode.c
57280@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
57281
57282 #ifdef CONFIG_SMP
57283 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
57284- static atomic_t shared_last_ino;
57285- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
57286+ static atomic_unchecked_t shared_last_ino;
57287+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
57288
57289 res = next - LAST_INO_BATCH;
57290 }
57291diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
57292index 4a6cf28..d3a29d3 100644
57293--- a/fs/jffs2/erase.c
57294+++ b/fs/jffs2/erase.c
57295@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
57296 struct jffs2_unknown_node marker = {
57297 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
57298 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57299- .totlen = cpu_to_je32(c->cleanmarker_size)
57300+ .totlen = cpu_to_je32(c->cleanmarker_size),
57301+ .hdr_crc = cpu_to_je32(0)
57302 };
57303
57304 jffs2_prealloc_raw_node_refs(c, jeb, 1);
57305diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
57306index a6597d6..41b30ec 100644
57307--- a/fs/jffs2/wbuf.c
57308+++ b/fs/jffs2/wbuf.c
57309@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
57310 {
57311 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
57312 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57313- .totlen = constant_cpu_to_je32(8)
57314+ .totlen = constant_cpu_to_je32(8),
57315+ .hdr_crc = constant_cpu_to_je32(0)
57316 };
57317
57318 /*
57319diff --git a/fs/jfs/super.c b/fs/jfs/super.c
57320index 6669aa2..36b033d 100644
57321--- a/fs/jfs/super.c
57322+++ b/fs/jfs/super.c
57323@@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
57324
57325 jfs_inode_cachep =
57326 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
57327- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
57328+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
57329 init_once);
57330 if (jfs_inode_cachep == NULL)
57331 return -ENOMEM;
57332diff --git a/fs/libfs.c b/fs/libfs.c
57333index 3a3a9b5..3a9b074 100644
57334--- a/fs/libfs.c
57335+++ b/fs/libfs.c
57336@@ -150,6 +150,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57337
57338 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
57339 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
57340+ char d_name[sizeof(next->d_iname)];
57341+ const unsigned char *name;
57342+
57343 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
57344 if (!simple_positive(next)) {
57345 spin_unlock(&next->d_lock);
57346@@ -158,7 +161,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57347
57348 spin_unlock(&next->d_lock);
57349 spin_unlock(&dentry->d_lock);
57350- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
57351+ name = next->d_name.name;
57352+ if (name == next->d_iname) {
57353+ memcpy(d_name, name, next->d_name.len);
57354+ name = d_name;
57355+ }
57356+ if (!dir_emit(ctx, name, next->d_name.len,
57357 next->d_inode->i_ino, dt_type(next->d_inode)))
57358 return 0;
57359 spin_lock(&dentry->d_lock);
57360diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
57361index acd3947..1f896e2 100644
57362--- a/fs/lockd/clntproc.c
57363+++ b/fs/lockd/clntproc.c
57364@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
57365 /*
57366 * Cookie counter for NLM requests
57367 */
57368-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
57369+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
57370
57371 void nlmclnt_next_cookie(struct nlm_cookie *c)
57372 {
57373- u32 cookie = atomic_inc_return(&nlm_cookie);
57374+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
57375
57376 memcpy(c->data, &cookie, 4);
57377 c->len=4;
57378diff --git a/fs/locks.c b/fs/locks.c
57379index b27a300..4156d0b 100644
57380--- a/fs/locks.c
57381+++ b/fs/locks.c
57382@@ -2183,16 +2183,16 @@ void locks_remove_flock(struct file *filp)
57383 return;
57384
57385 if (filp->f_op && filp->f_op->flock) {
57386- struct file_lock fl = {
57387+ struct file_lock flock = {
57388 .fl_pid = current->tgid,
57389 .fl_file = filp,
57390 .fl_flags = FL_FLOCK,
57391 .fl_type = F_UNLCK,
57392 .fl_end = OFFSET_MAX,
57393 };
57394- filp->f_op->flock(filp, F_SETLKW, &fl);
57395- if (fl.fl_ops && fl.fl_ops->fl_release_private)
57396- fl.fl_ops->fl_release_private(&fl);
57397+ filp->f_op->flock(filp, F_SETLKW, &flock);
57398+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
57399+ flock.fl_ops->fl_release_private(&flock);
57400 }
57401
57402 spin_lock(&inode->i_lock);
57403diff --git a/fs/namei.c b/fs/namei.c
57404index 7720fbd..7934bb2 100644
57405--- a/fs/namei.c
57406+++ b/fs/namei.c
57407@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
57408 if (ret != -EACCES)
57409 return ret;
57410
57411+#ifdef CONFIG_GRKERNSEC
57412+ /* we'll block if we have to log due to a denied capability use */
57413+ if (mask & MAY_NOT_BLOCK)
57414+ return -ECHILD;
57415+#endif
57416+
57417 if (S_ISDIR(inode->i_mode)) {
57418 /* DACs are overridable for directories */
57419- if (inode_capable(inode, CAP_DAC_OVERRIDE))
57420- return 0;
57421 if (!(mask & MAY_WRITE))
57422- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57423+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57424+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57425 return 0;
57426+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
57427+ return 0;
57428 return -EACCES;
57429 }
57430 /*
57431+ * Searching includes executable on directories, else just read.
57432+ */
57433+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57434+ if (mask == MAY_READ)
57435+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57436+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57437+ return 0;
57438+
57439+ /*
57440 * Read/write DACs are always overridable.
57441 * Executable DACs are overridable when there is
57442 * at least one exec bit set.
57443@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
57444 if (inode_capable(inode, CAP_DAC_OVERRIDE))
57445 return 0;
57446
57447- /*
57448- * Searching includes executable on directories, else just read.
57449- */
57450- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57451- if (mask == MAY_READ)
57452- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57453- return 0;
57454-
57455 return -EACCES;
57456 }
57457
57458@@ -820,7 +828,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57459 {
57460 struct dentry *dentry = link->dentry;
57461 int error;
57462- char *s;
57463+ const char *s;
57464
57465 BUG_ON(nd->flags & LOOKUP_RCU);
57466
57467@@ -841,6 +849,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57468 if (error)
57469 goto out_put_nd_path;
57470
57471+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
57472+ dentry->d_inode, dentry, nd->path.mnt)) {
57473+ error = -EACCES;
57474+ goto out_put_nd_path;
57475+ }
57476+
57477 nd->last_type = LAST_BIND;
57478 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
57479 error = PTR_ERR(*p);
57480@@ -1588,6 +1602,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
57481 if (res)
57482 break;
57483 res = walk_component(nd, path, LOOKUP_FOLLOW);
57484+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
57485+ res = -EACCES;
57486 put_link(nd, &link, cookie);
57487 } while (res > 0);
57488
57489@@ -1686,7 +1702,7 @@ EXPORT_SYMBOL(full_name_hash);
57490 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
57491 {
57492 unsigned long a, b, adata, bdata, mask, hash, len;
57493- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
57494+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
57495
57496 hash = a = 0;
57497 len = -sizeof(unsigned long);
57498@@ -1967,6 +1983,8 @@ static int path_lookupat(int dfd, const char *name,
57499 if (err)
57500 break;
57501 err = lookup_last(nd, &path);
57502+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
57503+ err = -EACCES;
57504 put_link(nd, &link, cookie);
57505 }
57506 }
57507@@ -1974,6 +1992,13 @@ static int path_lookupat(int dfd, const char *name,
57508 if (!err)
57509 err = complete_walk(nd);
57510
57511+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
57512+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
57513+ path_put(&nd->path);
57514+ err = -ENOENT;
57515+ }
57516+ }
57517+
57518 if (!err && nd->flags & LOOKUP_DIRECTORY) {
57519 if (!can_lookup(nd->inode)) {
57520 path_put(&nd->path);
57521@@ -2001,8 +2026,15 @@ static int filename_lookup(int dfd, struct filename *name,
57522 retval = path_lookupat(dfd, name->name,
57523 flags | LOOKUP_REVAL, nd);
57524
57525- if (likely(!retval))
57526+ if (likely(!retval)) {
57527 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
57528+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
57529+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
57530+ path_put(&nd->path);
57531+ return -ENOENT;
57532+ }
57533+ }
57534+ }
57535 return retval;
57536 }
57537
57538@@ -2380,6 +2412,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
57539 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
57540 return -EPERM;
57541
57542+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
57543+ return -EPERM;
57544+ if (gr_handle_rawio(inode))
57545+ return -EPERM;
57546+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
57547+ return -EACCES;
57548+
57549 return 0;
57550 }
57551
57552@@ -2601,7 +2640,7 @@ looked_up:
57553 * cleared otherwise prior to returning.
57554 */
57555 static int lookup_open(struct nameidata *nd, struct path *path,
57556- struct file *file,
57557+ struct path *link, struct file *file,
57558 const struct open_flags *op,
57559 bool got_write, int *opened)
57560 {
57561@@ -2636,6 +2675,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
57562 /* Negative dentry, just create the file */
57563 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
57564 umode_t mode = op->mode;
57565+
57566+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
57567+ error = -EACCES;
57568+ goto out_dput;
57569+ }
57570+
57571+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
57572+ error = -EACCES;
57573+ goto out_dput;
57574+ }
57575+
57576 if (!IS_POSIXACL(dir->d_inode))
57577 mode &= ~current_umask();
57578 /*
57579@@ -2657,6 +2707,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
57580 nd->flags & LOOKUP_EXCL);
57581 if (error)
57582 goto out_dput;
57583+ else
57584+ gr_handle_create(dentry, nd->path.mnt);
57585 }
57586 out_no_open:
57587 path->dentry = dentry;
57588@@ -2671,7 +2723,7 @@ out_dput:
57589 /*
57590 * Handle the last step of open()
57591 */
57592-static int do_last(struct nameidata *nd, struct path *path,
57593+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
57594 struct file *file, const struct open_flags *op,
57595 int *opened, struct filename *name)
57596 {
57597@@ -2721,6 +2773,15 @@ static int do_last(struct nameidata *nd, struct path *path,
57598 if (error)
57599 return error;
57600
57601+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
57602+ error = -ENOENT;
57603+ goto out;
57604+ }
57605+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
57606+ error = -EACCES;
57607+ goto out;
57608+ }
57609+
57610 audit_inode(name, dir, LOOKUP_PARENT);
57611 error = -EISDIR;
57612 /* trailing slashes? */
57613@@ -2740,7 +2801,7 @@ retry_lookup:
57614 */
57615 }
57616 mutex_lock(&dir->d_inode->i_mutex);
57617- error = lookup_open(nd, path, file, op, got_write, opened);
57618+ error = lookup_open(nd, path, link, file, op, got_write, opened);
57619 mutex_unlock(&dir->d_inode->i_mutex);
57620
57621 if (error <= 0) {
57622@@ -2764,11 +2825,28 @@ retry_lookup:
57623 goto finish_open_created;
57624 }
57625
57626+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
57627+ error = -ENOENT;
57628+ goto exit_dput;
57629+ }
57630+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
57631+ error = -EACCES;
57632+ goto exit_dput;
57633+ }
57634+
57635 /*
57636 * create/update audit record if it already exists.
57637 */
57638- if (path->dentry->d_inode)
57639+ if (path->dentry->d_inode) {
57640+ /* only check if O_CREAT is specified, all other checks need to go
57641+ into may_open */
57642+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
57643+ error = -EACCES;
57644+ goto exit_dput;
57645+ }
57646+
57647 audit_inode(name, path->dentry, 0);
57648+ }
57649
57650 /*
57651 * If atomic_open() acquired write access it is dropped now due to
57652@@ -2809,6 +2887,11 @@ finish_lookup:
57653 }
57654 }
57655 BUG_ON(inode != path->dentry->d_inode);
57656+ /* if we're resolving a symlink to another symlink */
57657+ if (link && gr_handle_symlink_owner(link, inode)) {
57658+ error = -EACCES;
57659+ goto out;
57660+ }
57661 return 1;
57662 }
57663
57664@@ -2818,7 +2901,6 @@ finish_lookup:
57665 save_parent.dentry = nd->path.dentry;
57666 save_parent.mnt = mntget(path->mnt);
57667 nd->path.dentry = path->dentry;
57668-
57669 }
57670 nd->inode = inode;
57671 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
57672@@ -2828,7 +2910,18 @@ finish_open:
57673 path_put(&save_parent);
57674 return error;
57675 }
57676+
57677+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
57678+ error = -ENOENT;
57679+ goto out;
57680+ }
57681+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
57682+ error = -EACCES;
57683+ goto out;
57684+ }
57685+
57686 audit_inode(name, nd->path.dentry, 0);
57687+
57688 error = -EISDIR;
57689 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
57690 goto out;
57691@@ -2991,7 +3084,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
57692 if (unlikely(error))
57693 goto out;
57694
57695- error = do_last(nd, &path, file, op, &opened, pathname);
57696+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
57697 while (unlikely(error > 0)) { /* trailing symlink */
57698 struct path link = path;
57699 void *cookie;
57700@@ -3009,7 +3102,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
57701 error = follow_link(&link, nd, &cookie);
57702 if (unlikely(error))
57703 break;
57704- error = do_last(nd, &path, file, op, &opened, pathname);
57705+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
57706 put_link(nd, &link, cookie);
57707 }
57708 out:
57709@@ -3109,8 +3202,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
57710 goto unlock;
57711
57712 error = -EEXIST;
57713- if (dentry->d_inode)
57714+ if (dentry->d_inode) {
57715+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
57716+ error = -ENOENT;
57717+ }
57718 goto fail;
57719+ }
57720 /*
57721 * Special case - lookup gave negative, but... we had foo/bar/
57722 * From the vfs_mknod() POV we just have a negative dentry -
57723@@ -3162,6 +3259,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
57724 }
57725 EXPORT_SYMBOL(user_path_create);
57726
57727+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
57728+{
57729+ struct filename *tmp = getname(pathname);
57730+ struct dentry *res;
57731+ if (IS_ERR(tmp))
57732+ return ERR_CAST(tmp);
57733+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
57734+ if (IS_ERR(res))
57735+ putname(tmp);
57736+ else
57737+ *to = tmp;
57738+ return res;
57739+}
57740+
57741 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
57742 {
57743 int error = may_create(dir, dentry);
57744@@ -3224,6 +3335,17 @@ retry:
57745
57746 if (!IS_POSIXACL(path.dentry->d_inode))
57747 mode &= ~current_umask();
57748+
57749+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
57750+ error = -EPERM;
57751+ goto out;
57752+ }
57753+
57754+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
57755+ error = -EACCES;
57756+ goto out;
57757+ }
57758+
57759 error = security_path_mknod(&path, dentry, mode, dev);
57760 if (error)
57761 goto out;
57762@@ -3240,6 +3362,8 @@ retry:
57763 break;
57764 }
57765 out:
57766+ if (!error)
57767+ gr_handle_create(dentry, path.mnt);
57768 done_path_create(&path, dentry);
57769 if (retry_estale(error, lookup_flags)) {
57770 lookup_flags |= LOOKUP_REVAL;
57771@@ -3292,9 +3416,16 @@ retry:
57772
57773 if (!IS_POSIXACL(path.dentry->d_inode))
57774 mode &= ~current_umask();
57775+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
57776+ error = -EACCES;
57777+ goto out;
57778+ }
57779 error = security_path_mkdir(&path, dentry, mode);
57780 if (!error)
57781 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
57782+ if (!error)
57783+ gr_handle_create(dentry, path.mnt);
57784+out:
57785 done_path_create(&path, dentry);
57786 if (retry_estale(error, lookup_flags)) {
57787 lookup_flags |= LOOKUP_REVAL;
57788@@ -3375,6 +3506,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
57789 struct filename *name;
57790 struct dentry *dentry;
57791 struct nameidata nd;
57792+ ino_t saved_ino = 0;
57793+ dev_t saved_dev = 0;
57794 unsigned int lookup_flags = 0;
57795 retry:
57796 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
57797@@ -3407,10 +3540,21 @@ retry:
57798 error = -ENOENT;
57799 goto exit3;
57800 }
57801+
57802+ saved_ino = dentry->d_inode->i_ino;
57803+ saved_dev = gr_get_dev_from_dentry(dentry);
57804+
57805+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
57806+ error = -EACCES;
57807+ goto exit3;
57808+ }
57809+
57810 error = security_path_rmdir(&nd.path, dentry);
57811 if (error)
57812 goto exit3;
57813 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
57814+ if (!error && (saved_dev || saved_ino))
57815+ gr_handle_delete(saved_ino, saved_dev);
57816 exit3:
57817 dput(dentry);
57818 exit2:
57819@@ -3476,6 +3620,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
57820 struct dentry *dentry;
57821 struct nameidata nd;
57822 struct inode *inode = NULL;
57823+ ino_t saved_ino = 0;
57824+ dev_t saved_dev = 0;
57825 unsigned int lookup_flags = 0;
57826 retry:
57827 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
57828@@ -3502,10 +3648,22 @@ retry:
57829 if (!inode)
57830 goto slashes;
57831 ihold(inode);
57832+
57833+ if (inode->i_nlink <= 1) {
57834+ saved_ino = inode->i_ino;
57835+ saved_dev = gr_get_dev_from_dentry(dentry);
57836+ }
57837+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
57838+ error = -EACCES;
57839+ goto exit2;
57840+ }
57841+
57842 error = security_path_unlink(&nd.path, dentry);
57843 if (error)
57844 goto exit2;
57845 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
57846+ if (!error && (saved_ino || saved_dev))
57847+ gr_handle_delete(saved_ino, saved_dev);
57848 exit2:
57849 dput(dentry);
57850 }
57851@@ -3583,9 +3741,17 @@ retry:
57852 if (IS_ERR(dentry))
57853 goto out_putname;
57854
57855+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
57856+ error = -EACCES;
57857+ goto out;
57858+ }
57859+
57860 error = security_path_symlink(&path, dentry, from->name);
57861 if (!error)
57862 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
57863+ if (!error)
57864+ gr_handle_create(dentry, path.mnt);
57865+out:
57866 done_path_create(&path, dentry);
57867 if (retry_estale(error, lookup_flags)) {
57868 lookup_flags |= LOOKUP_REVAL;
57869@@ -3665,6 +3831,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
57870 {
57871 struct dentry *new_dentry;
57872 struct path old_path, new_path;
57873+ struct filename *to = NULL;
57874 int how = 0;
57875 int error;
57876
57877@@ -3688,7 +3855,7 @@ retry:
57878 if (error)
57879 return error;
57880
57881- new_dentry = user_path_create(newdfd, newname, &new_path,
57882+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
57883 (how & LOOKUP_REVAL));
57884 error = PTR_ERR(new_dentry);
57885 if (IS_ERR(new_dentry))
57886@@ -3700,11 +3867,28 @@ retry:
57887 error = may_linkat(&old_path);
57888 if (unlikely(error))
57889 goto out_dput;
57890+
57891+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
57892+ old_path.dentry->d_inode,
57893+ old_path.dentry->d_inode->i_mode, to)) {
57894+ error = -EACCES;
57895+ goto out_dput;
57896+ }
57897+
57898+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
57899+ old_path.dentry, old_path.mnt, to)) {
57900+ error = -EACCES;
57901+ goto out_dput;
57902+ }
57903+
57904 error = security_path_link(old_path.dentry, &new_path, new_dentry);
57905 if (error)
57906 goto out_dput;
57907 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
57908+ if (!error)
57909+ gr_handle_create(new_dentry, new_path.mnt);
57910 out_dput:
57911+ putname(to);
57912 done_path_create(&new_path, new_dentry);
57913 if (retry_estale(error, how)) {
57914 how |= LOOKUP_REVAL;
57915@@ -3950,12 +4134,21 @@ retry:
57916 if (new_dentry == trap)
57917 goto exit5;
57918
57919+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
57920+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
57921+ to);
57922+ if (error)
57923+ goto exit5;
57924+
57925 error = security_path_rename(&oldnd.path, old_dentry,
57926 &newnd.path, new_dentry);
57927 if (error)
57928 goto exit5;
57929 error = vfs_rename(old_dir->d_inode, old_dentry,
57930 new_dir->d_inode, new_dentry);
57931+ if (!error)
57932+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
57933+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
57934 exit5:
57935 dput(new_dentry);
57936 exit4:
57937@@ -3987,6 +4180,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
57938
57939 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
57940 {
57941+ char tmpbuf[64];
57942+ const char *newlink;
57943 int len;
57944
57945 len = PTR_ERR(link);
57946@@ -3996,7 +4191,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
57947 len = strlen(link);
57948 if (len > (unsigned) buflen)
57949 len = buflen;
57950- if (copy_to_user(buffer, link, len))
57951+
57952+ if (len < sizeof(tmpbuf)) {
57953+ memcpy(tmpbuf, link, len);
57954+ newlink = tmpbuf;
57955+ } else
57956+ newlink = link;
57957+
57958+ if (copy_to_user(buffer, newlink, len))
57959 len = -EFAULT;
57960 out:
57961 return len;
57962diff --git a/fs/namespace.c b/fs/namespace.c
57963index a45ba4f..b4c7d07 100644
57964--- a/fs/namespace.c
57965+++ b/fs/namespace.c
57966@@ -1265,6 +1265,9 @@ static int do_umount(struct mount *mnt, int flags)
57967 if (!(sb->s_flags & MS_RDONLY))
57968 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
57969 up_write(&sb->s_umount);
57970+
57971+ gr_log_remount(mnt->mnt_devname, retval);
57972+
57973 return retval;
57974 }
57975
57976@@ -1283,6 +1286,9 @@ static int do_umount(struct mount *mnt, int flags)
57977 }
57978 br_write_unlock(&vfsmount_lock);
57979 namespace_unlock();
57980+
57981+ gr_log_unmount(mnt->mnt_devname, retval);
57982+
57983 return retval;
57984 }
57985
57986@@ -1302,7 +1308,7 @@ static inline bool may_mount(void)
57987 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
57988 */
57989
57990-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
57991+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
57992 {
57993 struct path path;
57994 struct mount *mnt;
57995@@ -1342,7 +1348,7 @@ out:
57996 /*
57997 * The 2.0 compatible umount. No flags.
57998 */
57999-SYSCALL_DEFINE1(oldumount, char __user *, name)
58000+SYSCALL_DEFINE1(oldumount, const char __user *, name)
58001 {
58002 return sys_umount(name, 0);
58003 }
58004@@ -2313,6 +2319,16 @@ long do_mount(const char *dev_name, const char *dir_name,
58005 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
58006 MS_STRICTATIME);
58007
58008+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
58009+ retval = -EPERM;
58010+ goto dput_out;
58011+ }
58012+
58013+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
58014+ retval = -EPERM;
58015+ goto dput_out;
58016+ }
58017+
58018 if (flags & MS_REMOUNT)
58019 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
58020 data_page);
58021@@ -2327,6 +2343,9 @@ long do_mount(const char *dev_name, const char *dir_name,
58022 dev_name, data_page);
58023 dput_out:
58024 path_put(&path);
58025+
58026+ gr_log_mount(dev_name, dir_name, retval);
58027+
58028 return retval;
58029 }
58030
58031@@ -2344,7 +2363,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
58032 * number incrementing at 10Ghz will take 12,427 years to wrap which
58033 * is effectively never, so we can ignore the possibility.
58034 */
58035-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
58036+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
58037
58038 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58039 {
58040@@ -2359,7 +2378,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58041 kfree(new_ns);
58042 return ERR_PTR(ret);
58043 }
58044- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
58045+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
58046 atomic_set(&new_ns->count, 1);
58047 new_ns->root = NULL;
58048 INIT_LIST_HEAD(&new_ns->list);
58049@@ -2373,7 +2392,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58050 * Allocate a new namespace structure and populate it with contents
58051 * copied from the namespace of the passed in task structure.
58052 */
58053-static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
58054+static __latent_entropy struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
58055 struct user_namespace *user_ns, struct fs_struct *fs)
58056 {
58057 struct mnt_namespace *new_ns;
58058@@ -2500,8 +2519,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
58059 }
58060 EXPORT_SYMBOL(mount_subtree);
58061
58062-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
58063- char __user *, type, unsigned long, flags, void __user *, data)
58064+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
58065+ const char __user *, type, unsigned long, flags, void __user *, data)
58066 {
58067 int ret;
58068 char *kernel_type;
58069@@ -2614,6 +2633,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
58070 if (error)
58071 goto out2;
58072
58073+ if (gr_handle_chroot_pivot()) {
58074+ error = -EPERM;
58075+ goto out2;
58076+ }
58077+
58078 get_fs_root(current->fs, &root);
58079 old_mp = lock_mount(&old);
58080 error = PTR_ERR(old_mp);
58081@@ -2864,7 +2888,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
58082 !nsown_capable(CAP_SYS_ADMIN))
58083 return -EPERM;
58084
58085- if (fs->users != 1)
58086+ if (atomic_read(&fs->users) != 1)
58087 return -EINVAL;
58088
58089 get_mnt_ns(mnt_ns);
58090diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
58091index f4ccfe6..a5cf064 100644
58092--- a/fs/nfs/callback_xdr.c
58093+++ b/fs/nfs/callback_xdr.c
58094@@ -51,7 +51,7 @@ struct callback_op {
58095 callback_decode_arg_t decode_args;
58096 callback_encode_res_t encode_res;
58097 long res_maxsize;
58098-};
58099+} __do_const;
58100
58101 static struct callback_op callback_ops[];
58102
58103diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
58104index 941246f..17d8724 100644
58105--- a/fs/nfs/inode.c
58106+++ b/fs/nfs/inode.c
58107@@ -1138,16 +1138,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
58108 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
58109 }
58110
58111-static atomic_long_t nfs_attr_generation_counter;
58112+static atomic_long_unchecked_t nfs_attr_generation_counter;
58113
58114 static unsigned long nfs_read_attr_generation_counter(void)
58115 {
58116- return atomic_long_read(&nfs_attr_generation_counter);
58117+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
58118 }
58119
58120 unsigned long nfs_inc_attr_generation_counter(void)
58121 {
58122- return atomic_long_inc_return(&nfs_attr_generation_counter);
58123+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
58124 }
58125
58126 void nfs_fattr_init(struct nfs_fattr *fattr)
58127diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
58128index 419572f..5414a23 100644
58129--- a/fs/nfsd/nfs4proc.c
58130+++ b/fs/nfsd/nfs4proc.c
58131@@ -1168,7 +1168,7 @@ struct nfsd4_operation {
58132 nfsd4op_rsize op_rsize_bop;
58133 stateid_getter op_get_currentstateid;
58134 stateid_setter op_set_currentstateid;
58135-};
58136+} __do_const;
58137
58138 static struct nfsd4_operation nfsd4_ops[];
58139
58140diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
58141index c2a4701..fd80e29 100644
58142--- a/fs/nfsd/nfs4xdr.c
58143+++ b/fs/nfsd/nfs4xdr.c
58144@@ -1498,7 +1498,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
58145
58146 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
58147
58148-static nfsd4_dec nfsd4_dec_ops[] = {
58149+static const nfsd4_dec nfsd4_dec_ops[] = {
58150 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58151 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58152 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58153@@ -1538,7 +1538,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
58154 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
58155 };
58156
58157-static nfsd4_dec nfsd41_dec_ops[] = {
58158+static const nfsd4_dec nfsd41_dec_ops[] = {
58159 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58160 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58161 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58162@@ -1600,7 +1600,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
58163 };
58164
58165 struct nfsd4_minorversion_ops {
58166- nfsd4_dec *decoders;
58167+ const nfsd4_dec *decoders;
58168 int nops;
58169 };
58170
58171diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
58172index e76244e..9fe8f2f1 100644
58173--- a/fs/nfsd/nfscache.c
58174+++ b/fs/nfsd/nfscache.c
58175@@ -526,14 +526,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
58176 {
58177 struct svc_cacherep *rp = rqstp->rq_cacherep;
58178 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
58179- int len;
58180+ long len;
58181 size_t bufsize = 0;
58182
58183 if (!rp)
58184 return;
58185
58186- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
58187- len >>= 2;
58188+ if (statp) {
58189+ len = (char*)statp - (char*)resv->iov_base;
58190+ len = resv->iov_len - len;
58191+ len >>= 2;
58192+ }
58193
58194 /* Don't cache excessive amounts of data and XDR failures */
58195 if (!statp || len > (256 >> 2)) {
58196diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
58197index c827acb..b253b77 100644
58198--- a/fs/nfsd/vfs.c
58199+++ b/fs/nfsd/vfs.c
58200@@ -968,7 +968,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58201 } else {
58202 oldfs = get_fs();
58203 set_fs(KERNEL_DS);
58204- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
58205+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
58206 set_fs(oldfs);
58207 }
58208
58209@@ -1055,7 +1055,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58210
58211 /* Write the data. */
58212 oldfs = get_fs(); set_fs(KERNEL_DS);
58213- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
58214+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
58215 set_fs(oldfs);
58216 if (host_err < 0)
58217 goto out_nfserr;
58218@@ -1601,7 +1601,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
58219 */
58220
58221 oldfs = get_fs(); set_fs(KERNEL_DS);
58222- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
58223+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
58224 set_fs(oldfs);
58225
58226 if (host_err < 0)
58227diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
58228index fea6bd5..8ee9d81 100644
58229--- a/fs/nls/nls_base.c
58230+++ b/fs/nls/nls_base.c
58231@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
58232
58233 int register_nls(struct nls_table * nls)
58234 {
58235- struct nls_table ** tmp = &tables;
58236+ struct nls_table *tmp = tables;
58237
58238 if (nls->next)
58239 return -EBUSY;
58240
58241 spin_lock(&nls_lock);
58242- while (*tmp) {
58243- if (nls == *tmp) {
58244+ while (tmp) {
58245+ if (nls == tmp) {
58246 spin_unlock(&nls_lock);
58247 return -EBUSY;
58248 }
58249- tmp = &(*tmp)->next;
58250+ tmp = tmp->next;
58251 }
58252- nls->next = tables;
58253+ pax_open_kernel();
58254+ *(struct nls_table **)&nls->next = tables;
58255+ pax_close_kernel();
58256 tables = nls;
58257 spin_unlock(&nls_lock);
58258 return 0;
58259@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
58260
58261 int unregister_nls(struct nls_table * nls)
58262 {
58263- struct nls_table ** tmp = &tables;
58264+ struct nls_table * const * tmp = &tables;
58265
58266 spin_lock(&nls_lock);
58267 while (*tmp) {
58268 if (nls == *tmp) {
58269- *tmp = nls->next;
58270+ pax_open_kernel();
58271+ *(struct nls_table **)tmp = nls->next;
58272+ pax_close_kernel();
58273 spin_unlock(&nls_lock);
58274 return 0;
58275 }
58276diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
58277index 7424929..35f6be5 100644
58278--- a/fs/nls/nls_euc-jp.c
58279+++ b/fs/nls/nls_euc-jp.c
58280@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
58281 p_nls = load_nls("cp932");
58282
58283 if (p_nls) {
58284- table.charset2upper = p_nls->charset2upper;
58285- table.charset2lower = p_nls->charset2lower;
58286+ pax_open_kernel();
58287+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58288+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58289+ pax_close_kernel();
58290 return register_nls(&table);
58291 }
58292
58293diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
58294index e7bc1d7..06bd4bb 100644
58295--- a/fs/nls/nls_koi8-ru.c
58296+++ b/fs/nls/nls_koi8-ru.c
58297@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
58298 p_nls = load_nls("koi8-u");
58299
58300 if (p_nls) {
58301- table.charset2upper = p_nls->charset2upper;
58302- table.charset2lower = p_nls->charset2lower;
58303+ pax_open_kernel();
58304+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58305+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58306+ pax_close_kernel();
58307 return register_nls(&table);
58308 }
58309
58310diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
58311index e44cb64..4807084 100644
58312--- a/fs/notify/fanotify/fanotify_user.c
58313+++ b/fs/notify/fanotify/fanotify_user.c
58314@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
58315
58316 fd = fanotify_event_metadata.fd;
58317 ret = -EFAULT;
58318- if (copy_to_user(buf, &fanotify_event_metadata,
58319- fanotify_event_metadata.event_len))
58320+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
58321+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
58322 goto out_close_fd;
58323
58324 ret = prepare_for_access_response(group, event, fd);
58325diff --git a/fs/notify/notification.c b/fs/notify/notification.c
58326index 7b51b05..5ea5ef6 100644
58327--- a/fs/notify/notification.c
58328+++ b/fs/notify/notification.c
58329@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
58330 * get set to 0 so it will never get 'freed'
58331 */
58332 static struct fsnotify_event *q_overflow_event;
58333-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58334+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58335
58336 /**
58337 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
58338@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58339 */
58340 u32 fsnotify_get_cookie(void)
58341 {
58342- return atomic_inc_return(&fsnotify_sync_cookie);
58343+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
58344 }
58345 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
58346
58347diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
58348index 9e38daf..5727cae 100644
58349--- a/fs/ntfs/dir.c
58350+++ b/fs/ntfs/dir.c
58351@@ -1310,7 +1310,7 @@ find_next_index_buffer:
58352 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
58353 ~(s64)(ndir->itype.index.block_size - 1)));
58354 /* Bounds checks. */
58355- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58356+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58357 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
58358 "inode 0x%lx or driver bug.", vdir->i_ino);
58359 goto err_out;
58360diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
58361index c5670b8..2b43d9b 100644
58362--- a/fs/ntfs/file.c
58363+++ b/fs/ntfs/file.c
58364@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
58365 char *addr;
58366 size_t total = 0;
58367 unsigned len;
58368- int left;
58369+ unsigned left;
58370
58371 do {
58372 len = PAGE_CACHE_SIZE - ofs;
58373@@ -2241,6 +2241,6 @@ const struct inode_operations ntfs_file_inode_ops = {
58374 #endif /* NTFS_RW */
58375 };
58376
58377-const struct file_operations ntfs_empty_file_ops = {};
58378+const struct file_operations ntfs_empty_file_ops __read_only;
58379
58380-const struct inode_operations ntfs_empty_inode_ops = {};
58381+const struct inode_operations ntfs_empty_inode_ops __read_only;
58382diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
58383index 82650d5..db37dcf 100644
58384--- a/fs/ntfs/super.c
58385+++ b/fs/ntfs/super.c
58386@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58387 if (!silent)
58388 ntfs_error(sb, "Primary boot sector is invalid.");
58389 } else if (!silent)
58390- ntfs_error(sb, read_err_str, "primary");
58391+ ntfs_error(sb, read_err_str, "%s", "primary");
58392 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
58393 if (bh_primary)
58394 brelse(bh_primary);
58395@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58396 goto hotfix_primary_boot_sector;
58397 brelse(bh_backup);
58398 } else if (!silent)
58399- ntfs_error(sb, read_err_str, "backup");
58400+ ntfs_error(sb, read_err_str, "%s", "backup");
58401 /* Try to read NT3.51- backup boot sector. */
58402 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
58403 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
58404@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58405 "sector.");
58406 brelse(bh_backup);
58407 } else if (!silent)
58408- ntfs_error(sb, read_err_str, "backup");
58409+ ntfs_error(sb, read_err_str, "%s", "backup");
58410 /* We failed. Cleanup and return. */
58411 if (bh_primary)
58412 brelse(bh_primary);
58413diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
58414index aebeacd..0dcdd26 100644
58415--- a/fs/ocfs2/localalloc.c
58416+++ b/fs/ocfs2/localalloc.c
58417@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
58418 goto bail;
58419 }
58420
58421- atomic_inc(&osb->alloc_stats.moves);
58422+ atomic_inc_unchecked(&osb->alloc_stats.moves);
58423
58424 bail:
58425 if (handle)
58426diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
58427index 3a90347..c40bef8 100644
58428--- a/fs/ocfs2/ocfs2.h
58429+++ b/fs/ocfs2/ocfs2.h
58430@@ -235,11 +235,11 @@ enum ocfs2_vol_state
58431
58432 struct ocfs2_alloc_stats
58433 {
58434- atomic_t moves;
58435- atomic_t local_data;
58436- atomic_t bitmap_data;
58437- atomic_t bg_allocs;
58438- atomic_t bg_extends;
58439+ atomic_unchecked_t moves;
58440+ atomic_unchecked_t local_data;
58441+ atomic_unchecked_t bitmap_data;
58442+ atomic_unchecked_t bg_allocs;
58443+ atomic_unchecked_t bg_extends;
58444 };
58445
58446 enum ocfs2_local_alloc_state
58447diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
58448index 5397c07..54afc55 100644
58449--- a/fs/ocfs2/suballoc.c
58450+++ b/fs/ocfs2/suballoc.c
58451@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
58452 mlog_errno(status);
58453 goto bail;
58454 }
58455- atomic_inc(&osb->alloc_stats.bg_extends);
58456+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
58457
58458 /* You should never ask for this much metadata */
58459 BUG_ON(bits_wanted >
58460@@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
58461 mlog_errno(status);
58462 goto bail;
58463 }
58464- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58465+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58466
58467 *suballoc_loc = res.sr_bg_blkno;
58468 *suballoc_bit_start = res.sr_bit_offset;
58469@@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
58470 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
58471 res->sr_bits);
58472
58473- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58474+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58475
58476 BUG_ON(res->sr_bits != 1);
58477
58478@@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
58479 mlog_errno(status);
58480 goto bail;
58481 }
58482- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58483+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58484
58485 BUG_ON(res.sr_bits != 1);
58486
58487@@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
58488 cluster_start,
58489 num_clusters);
58490 if (!status)
58491- atomic_inc(&osb->alloc_stats.local_data);
58492+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
58493 } else {
58494 if (min_clusters > (osb->bitmap_cpg - 1)) {
58495 /* The only paths asking for contiguousness
58496@@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
58497 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
58498 res.sr_bg_blkno,
58499 res.sr_bit_offset);
58500- atomic_inc(&osb->alloc_stats.bitmap_data);
58501+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
58502 *num_clusters = res.sr_bits;
58503 }
58504 }
58505diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
58506index 121da2d..a0232bc 100644
58507--- a/fs/ocfs2/super.c
58508+++ b/fs/ocfs2/super.c
58509@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
58510 "%10s => GlobalAllocs: %d LocalAllocs: %d "
58511 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
58512 "Stats",
58513- atomic_read(&osb->alloc_stats.bitmap_data),
58514- atomic_read(&osb->alloc_stats.local_data),
58515- atomic_read(&osb->alloc_stats.bg_allocs),
58516- atomic_read(&osb->alloc_stats.moves),
58517- atomic_read(&osb->alloc_stats.bg_extends));
58518+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
58519+ atomic_read_unchecked(&osb->alloc_stats.local_data),
58520+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
58521+ atomic_read_unchecked(&osb->alloc_stats.moves),
58522+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
58523
58524 out += snprintf(buf + out, len - out,
58525 "%10s => State: %u Descriptor: %llu Size: %u bits "
58526@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
58527 spin_lock_init(&osb->osb_xattr_lock);
58528 ocfs2_init_steal_slots(osb);
58529
58530- atomic_set(&osb->alloc_stats.moves, 0);
58531- atomic_set(&osb->alloc_stats.local_data, 0);
58532- atomic_set(&osb->alloc_stats.bitmap_data, 0);
58533- atomic_set(&osb->alloc_stats.bg_allocs, 0);
58534- atomic_set(&osb->alloc_stats.bg_extends, 0);
58535+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
58536+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
58537+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
58538+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
58539+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
58540
58541 /* Copy the blockcheck stats from the superblock probe */
58542 osb->osb_ecc_stats = *stats;
58543diff --git a/fs/open.c b/fs/open.c
58544index 7931f76..7b03f3b 100644
58545--- a/fs/open.c
58546+++ b/fs/open.c
58547@@ -32,6 +32,8 @@
58548 #include <linux/dnotify.h>
58549 #include <linux/compat.h>
58550
58551+#define CREATE_TRACE_POINTS
58552+#include <trace/events/fs.h>
58553 #include "internal.h"
58554
58555 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
58556@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
58557 error = locks_verify_truncate(inode, NULL, length);
58558 if (!error)
58559 error = security_path_truncate(path);
58560+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
58561+ error = -EACCES;
58562 if (!error)
58563 error = do_truncate(path->dentry, length, 0, NULL);
58564
58565@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
58566 error = locks_verify_truncate(inode, f.file, length);
58567 if (!error)
58568 error = security_path_truncate(&f.file->f_path);
58569+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
58570+ error = -EACCES;
58571 if (!error)
58572 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
58573 sb_end_write(inode->i_sb);
58574@@ -360,6 +366,9 @@ retry:
58575 if (__mnt_is_readonly(path.mnt))
58576 res = -EROFS;
58577
58578+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
58579+ res = -EACCES;
58580+
58581 out_path_release:
58582 path_put(&path);
58583 if (retry_estale(res, lookup_flags)) {
58584@@ -391,6 +400,8 @@ retry:
58585 if (error)
58586 goto dput_and_out;
58587
58588+ gr_log_chdir(path.dentry, path.mnt);
58589+
58590 set_fs_pwd(current->fs, &path);
58591
58592 dput_and_out:
58593@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
58594 goto out_putf;
58595
58596 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
58597+
58598+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
58599+ error = -EPERM;
58600+
58601+ if (!error)
58602+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
58603+
58604 if (!error)
58605 set_fs_pwd(current->fs, &f.file->f_path);
58606 out_putf:
58607@@ -449,7 +467,13 @@ retry:
58608 if (error)
58609 goto dput_and_out;
58610
58611+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
58612+ goto dput_and_out;
58613+
58614 set_fs_root(current->fs, &path);
58615+
58616+ gr_handle_chroot_chdir(&path);
58617+
58618 error = 0;
58619 dput_and_out:
58620 path_put(&path);
58621@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
58622 if (error)
58623 return error;
58624 mutex_lock(&inode->i_mutex);
58625+
58626+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
58627+ error = -EACCES;
58628+ goto out_unlock;
58629+ }
58630+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
58631+ error = -EACCES;
58632+ goto out_unlock;
58633+ }
58634+
58635 error = security_path_chmod(path, mode);
58636 if (error)
58637 goto out_unlock;
58638@@ -531,6 +565,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
58639 uid = make_kuid(current_user_ns(), user);
58640 gid = make_kgid(current_user_ns(), group);
58641
58642+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
58643+ return -EACCES;
58644+
58645 newattrs.ia_valid = ATTR_CTIME;
58646 if (user != (uid_t) -1) {
58647 if (!uid_valid(uid))
58648@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
58649 } else {
58650 fsnotify_open(f);
58651 fd_install(fd, f);
58652+ trace_do_sys_open(tmp->name, flags, mode);
58653 }
58654 }
58655 putname(tmp);
58656diff --git a/fs/pipe.c b/fs/pipe.c
58657index d2c45e1..009fe1c 100644
58658--- a/fs/pipe.c
58659+++ b/fs/pipe.c
58660@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
58661
58662 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
58663 {
58664- if (pipe->files)
58665+ if (atomic_read(&pipe->files))
58666 mutex_lock_nested(&pipe->mutex, subclass);
58667 }
58668
58669@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
58670
58671 void pipe_unlock(struct pipe_inode_info *pipe)
58672 {
58673- if (pipe->files)
58674+ if (atomic_read(&pipe->files))
58675 mutex_unlock(&pipe->mutex);
58676 }
58677 EXPORT_SYMBOL(pipe_unlock);
58678@@ -449,9 +449,9 @@ redo:
58679 }
58680 if (bufs) /* More to do? */
58681 continue;
58682- if (!pipe->writers)
58683+ if (!atomic_read(&pipe->writers))
58684 break;
58685- if (!pipe->waiting_writers) {
58686+ if (!atomic_read(&pipe->waiting_writers)) {
58687 /* syscall merging: Usually we must not sleep
58688 * if O_NONBLOCK is set, or if we got some data.
58689 * But if a writer sleeps in kernel space, then
58690@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
58691 ret = 0;
58692 __pipe_lock(pipe);
58693
58694- if (!pipe->readers) {
58695+ if (!atomic_read(&pipe->readers)) {
58696 send_sig(SIGPIPE, current, 0);
58697 ret = -EPIPE;
58698 goto out;
58699@@ -562,7 +562,7 @@ redo1:
58700 for (;;) {
58701 int bufs;
58702
58703- if (!pipe->readers) {
58704+ if (!atomic_read(&pipe->readers)) {
58705 send_sig(SIGPIPE, current, 0);
58706 if (!ret)
58707 ret = -EPIPE;
58708@@ -653,9 +653,9 @@ redo2:
58709 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58710 do_wakeup = 0;
58711 }
58712- pipe->waiting_writers++;
58713+ atomic_inc(&pipe->waiting_writers);
58714 pipe_wait(pipe);
58715- pipe->waiting_writers--;
58716+ atomic_dec(&pipe->waiting_writers);
58717 }
58718 out:
58719 __pipe_unlock(pipe);
58720@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
58721 mask = 0;
58722 if (filp->f_mode & FMODE_READ) {
58723 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
58724- if (!pipe->writers && filp->f_version != pipe->w_counter)
58725+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
58726 mask |= POLLHUP;
58727 }
58728
58729@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
58730 * Most Unices do not set POLLERR for FIFOs but on Linux they
58731 * behave exactly like pipes for poll().
58732 */
58733- if (!pipe->readers)
58734+ if (!atomic_read(&pipe->readers))
58735 mask |= POLLERR;
58736 }
58737
58738@@ -734,17 +734,17 @@ pipe_release(struct inode *inode, struct file *file)
58739
58740 __pipe_lock(pipe);
58741 if (file->f_mode & FMODE_READ)
58742- pipe->readers--;
58743+ atomic_dec(&pipe->readers);
58744 if (file->f_mode & FMODE_WRITE)
58745- pipe->writers--;
58746+ atomic_dec(&pipe->writers);
58747
58748- if (pipe->readers || pipe->writers) {
58749+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
58750 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
58751 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58752 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
58753 }
58754 spin_lock(&inode->i_lock);
58755- if (!--pipe->files) {
58756+ if (atomic_dec_and_test(&pipe->files)) {
58757 inode->i_pipe = NULL;
58758 kill = 1;
58759 }
58760@@ -811,7 +811,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
58761 kfree(pipe);
58762 }
58763
58764-static struct vfsmount *pipe_mnt __read_mostly;
58765+struct vfsmount *pipe_mnt __read_mostly;
58766
58767 /*
58768 * pipefs_dname() is called from d_path().
58769@@ -841,8 +841,9 @@ static struct inode * get_pipe_inode(void)
58770 goto fail_iput;
58771
58772 inode->i_pipe = pipe;
58773- pipe->files = 2;
58774- pipe->readers = pipe->writers = 1;
58775+ atomic_set(&pipe->files, 2);
58776+ atomic_set(&pipe->readers, 1);
58777+ atomic_set(&pipe->writers, 1);
58778 inode->i_fop = &pipefifo_fops;
58779
58780 /*
58781@@ -1022,17 +1023,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
58782 spin_lock(&inode->i_lock);
58783 if (inode->i_pipe) {
58784 pipe = inode->i_pipe;
58785- pipe->files++;
58786+ atomic_inc(&pipe->files);
58787 spin_unlock(&inode->i_lock);
58788 } else {
58789 spin_unlock(&inode->i_lock);
58790 pipe = alloc_pipe_info();
58791 if (!pipe)
58792 return -ENOMEM;
58793- pipe->files = 1;
58794+ atomic_set(&pipe->files, 1);
58795 spin_lock(&inode->i_lock);
58796 if (unlikely(inode->i_pipe)) {
58797- inode->i_pipe->files++;
58798+ atomic_inc(&inode->i_pipe->files);
58799 spin_unlock(&inode->i_lock);
58800 free_pipe_info(pipe);
58801 pipe = inode->i_pipe;
58802@@ -1057,10 +1058,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
58803 * opened, even when there is no process writing the FIFO.
58804 */
58805 pipe->r_counter++;
58806- if (pipe->readers++ == 0)
58807+ if (atomic_inc_return(&pipe->readers) == 1)
58808 wake_up_partner(pipe);
58809
58810- if (!is_pipe && !pipe->writers) {
58811+ if (!is_pipe && !atomic_read(&pipe->writers)) {
58812 if ((filp->f_flags & O_NONBLOCK)) {
58813 /* suppress POLLHUP until we have
58814 * seen a writer */
58815@@ -1079,14 +1080,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
58816 * errno=ENXIO when there is no process reading the FIFO.
58817 */
58818 ret = -ENXIO;
58819- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
58820+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
58821 goto err;
58822
58823 pipe->w_counter++;
58824- if (!pipe->writers++)
58825+ if (atomic_inc_return(&pipe->writers) == 1)
58826 wake_up_partner(pipe);
58827
58828- if (!is_pipe && !pipe->readers) {
58829+ if (!is_pipe && !atomic_read(&pipe->readers)) {
58830 if (wait_for_partner(pipe, &pipe->r_counter))
58831 goto err_wr;
58832 }
58833@@ -1100,11 +1101,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
58834 * the process can at least talk to itself.
58835 */
58836
58837- pipe->readers++;
58838- pipe->writers++;
58839+ atomic_inc(&pipe->readers);
58840+ atomic_inc(&pipe->writers);
58841 pipe->r_counter++;
58842 pipe->w_counter++;
58843- if (pipe->readers == 1 || pipe->writers == 1)
58844+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
58845 wake_up_partner(pipe);
58846 break;
58847
58848@@ -1118,20 +1119,20 @@ static int fifo_open(struct inode *inode, struct file *filp)
58849 return 0;
58850
58851 err_rd:
58852- if (!--pipe->readers)
58853+ if (atomic_dec_and_test(&pipe->readers))
58854 wake_up_interruptible(&pipe->wait);
58855 ret = -ERESTARTSYS;
58856 goto err;
58857
58858 err_wr:
58859- if (!--pipe->writers)
58860+ if (atomic_dec_and_test(&pipe->writers))
58861 wake_up_interruptible(&pipe->wait);
58862 ret = -ERESTARTSYS;
58863 goto err;
58864
58865 err:
58866 spin_lock(&inode->i_lock);
58867- if (!--pipe->files) {
58868+ if (atomic_dec_and_test(&pipe->files)) {
58869 inode->i_pipe = NULL;
58870 kill = 1;
58871 }
58872diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
58873index 15af622..0e9f4467 100644
58874--- a/fs/proc/Kconfig
58875+++ b/fs/proc/Kconfig
58876@@ -30,12 +30,12 @@ config PROC_FS
58877
58878 config PROC_KCORE
58879 bool "/proc/kcore support" if !ARM
58880- depends on PROC_FS && MMU
58881+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
58882
58883 config PROC_VMCORE
58884 bool "/proc/vmcore support"
58885- depends on PROC_FS && CRASH_DUMP
58886- default y
58887+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
58888+ default n
58889 help
58890 Exports the dump image of crashed kernel in ELF format.
58891
58892@@ -59,8 +59,8 @@ config PROC_SYSCTL
58893 limited in memory.
58894
58895 config PROC_PAGE_MONITOR
58896- default y
58897- depends on PROC_FS && MMU
58898+ default n
58899+ depends on PROC_FS && MMU && !GRKERNSEC
58900 bool "Enable /proc page monitoring" if EXPERT
58901 help
58902 Various /proc files exist to monitor process memory utilization:
58903diff --git a/fs/proc/array.c b/fs/proc/array.c
58904index cbd0f1b..adec3f0 100644
58905--- a/fs/proc/array.c
58906+++ b/fs/proc/array.c
58907@@ -60,6 +60,7 @@
58908 #include <linux/tty.h>
58909 #include <linux/string.h>
58910 #include <linux/mman.h>
58911+#include <linux/grsecurity.h>
58912 #include <linux/proc_fs.h>
58913 #include <linux/ioport.h>
58914 #include <linux/uaccess.h>
58915@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
58916 seq_putc(m, '\n');
58917 }
58918
58919+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58920+static inline void task_pax(struct seq_file *m, struct task_struct *p)
58921+{
58922+ if (p->mm)
58923+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
58924+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
58925+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
58926+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
58927+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
58928+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
58929+ else
58930+ seq_printf(m, "PaX:\t-----\n");
58931+}
58932+#endif
58933+
58934 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
58935 struct pid *pid, struct task_struct *task)
58936 {
58937@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
58938 task_cpus_allowed(m, task);
58939 cpuset_task_status_allowed(m, task);
58940 task_context_switch_counts(m, task);
58941+
58942+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58943+ task_pax(m, task);
58944+#endif
58945+
58946+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
58947+ task_grsec_rbac(m, task);
58948+#endif
58949+
58950 return 0;
58951 }
58952
58953+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58954+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
58955+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
58956+ _mm->pax_flags & MF_PAX_SEGMEXEC))
58957+#endif
58958+
58959 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58960 struct pid *pid, struct task_struct *task, int whole)
58961 {
58962@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58963 char tcomm[sizeof(task->comm)];
58964 unsigned long flags;
58965
58966+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58967+ if (current->exec_id != m->exec_id) {
58968+ gr_log_badprocpid("stat");
58969+ return 0;
58970+ }
58971+#endif
58972+
58973 state = *get_task_state(task);
58974 vsize = eip = esp = 0;
58975 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
58976@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58977 gtime = task_gtime(task);
58978 }
58979
58980+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58981+ if (PAX_RAND_FLAGS(mm)) {
58982+ eip = 0;
58983+ esp = 0;
58984+ wchan = 0;
58985+ }
58986+#endif
58987+#ifdef CONFIG_GRKERNSEC_HIDESYM
58988+ wchan = 0;
58989+ eip =0;
58990+ esp =0;
58991+#endif
58992+
58993 /* scale priority and nice values from timeslices to -20..20 */
58994 /* to make it look like a "normal" Unix priority/nice value */
58995 priority = task_prio(task);
58996@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58997 seq_put_decimal_ull(m, ' ', vsize);
58998 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
58999 seq_put_decimal_ull(m, ' ', rsslim);
59000+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59001+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
59002+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
59003+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
59004+#else
59005 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
59006 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
59007 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
59008+#endif
59009 seq_put_decimal_ull(m, ' ', esp);
59010 seq_put_decimal_ull(m, ' ', eip);
59011 /* The signal information here is obsolete.
59012@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59013 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
59014 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
59015
59016- if (mm && permitted) {
59017+ if (mm && permitted
59018+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59019+ && !PAX_RAND_FLAGS(mm)
59020+#endif
59021+ ) {
59022 seq_put_decimal_ull(m, ' ', mm->start_data);
59023 seq_put_decimal_ull(m, ' ', mm->end_data);
59024 seq_put_decimal_ull(m, ' ', mm->start_brk);
59025@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
59026 struct pid *pid, struct task_struct *task)
59027 {
59028 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
59029- struct mm_struct *mm = get_task_mm(task);
59030+ struct mm_struct *mm;
59031
59032+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59033+ if (current->exec_id != m->exec_id) {
59034+ gr_log_badprocpid("statm");
59035+ return 0;
59036+ }
59037+#endif
59038+ mm = get_task_mm(task);
59039 if (mm) {
59040 size = task_statm(mm, &shared, &text, &data, &resident);
59041 mmput(mm);
59042@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
59043 return 0;
59044 }
59045
59046+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59047+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
59048+{
59049+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
59050+}
59051+#endif
59052+
59053 #ifdef CONFIG_CHECKPOINT_RESTORE
59054 static struct pid *
59055 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
59056diff --git a/fs/proc/base.c b/fs/proc/base.c
59057index 1485e38..8ad4236 100644
59058--- a/fs/proc/base.c
59059+++ b/fs/proc/base.c
59060@@ -113,6 +113,14 @@ struct pid_entry {
59061 union proc_op op;
59062 };
59063
59064+struct getdents_callback {
59065+ struct linux_dirent __user * current_dir;
59066+ struct linux_dirent __user * previous;
59067+ struct file * file;
59068+ int count;
59069+ int error;
59070+};
59071+
59072 #define NOD(NAME, MODE, IOP, FOP, OP) { \
59073 .name = (NAME), \
59074 .len = sizeof(NAME) - 1, \
59075@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
59076 if (!mm->arg_end)
59077 goto out_mm; /* Shh! No looking before we're done */
59078
59079+ if (gr_acl_handle_procpidmem(task))
59080+ goto out_mm;
59081+
59082 len = mm->arg_end - mm->arg_start;
59083
59084 if (len > PAGE_SIZE)
59085@@ -237,12 +248,28 @@ out:
59086 return res;
59087 }
59088
59089+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59090+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59091+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59092+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59093+#endif
59094+
59095 static int proc_pid_auxv(struct task_struct *task, char *buffer)
59096 {
59097 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
59098 int res = PTR_ERR(mm);
59099 if (mm && !IS_ERR(mm)) {
59100 unsigned int nwords = 0;
59101+
59102+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59103+ /* allow if we're currently ptracing this task */
59104+ if (PAX_RAND_FLAGS(mm) &&
59105+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
59106+ mmput(mm);
59107+ return 0;
59108+ }
59109+#endif
59110+
59111 do {
59112 nwords += 2;
59113 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
59114@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
59115 }
59116
59117
59118-#ifdef CONFIG_KALLSYMS
59119+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59120 /*
59121 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
59122 * Returns the resolved symbol. If that fails, simply return the address.
59123@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
59124 mutex_unlock(&task->signal->cred_guard_mutex);
59125 }
59126
59127-#ifdef CONFIG_STACKTRACE
59128+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59129
59130 #define MAX_STACK_TRACE_DEPTH 64
59131
59132@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
59133 return count;
59134 }
59135
59136-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59137+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59138 static int proc_pid_syscall(struct task_struct *task, char *buffer)
59139 {
59140 long nr;
59141@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
59142 /************************************************************************/
59143
59144 /* permission checks */
59145-static int proc_fd_access_allowed(struct inode *inode)
59146+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
59147 {
59148 struct task_struct *task;
59149 int allowed = 0;
59150@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
59151 */
59152 task = get_proc_task(inode);
59153 if (task) {
59154- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59155+ if (log)
59156+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59157+ else
59158+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
59159 put_task_struct(task);
59160 }
59161 return allowed;
59162@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
59163 struct task_struct *task,
59164 int hide_pid_min)
59165 {
59166+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59167+ return false;
59168+
59169+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59170+ rcu_read_lock();
59171+ {
59172+ const struct cred *tmpcred = current_cred();
59173+ const struct cred *cred = __task_cred(task);
59174+
59175+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
59176+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59177+ || in_group_p(grsec_proc_gid)
59178+#endif
59179+ ) {
59180+ rcu_read_unlock();
59181+ return true;
59182+ }
59183+ }
59184+ rcu_read_unlock();
59185+
59186+ if (!pid->hide_pid)
59187+ return false;
59188+#endif
59189+
59190 if (pid->hide_pid < hide_pid_min)
59191 return true;
59192 if (in_group_p(pid->pid_gid))
59193 return true;
59194+
59195 return ptrace_may_access(task, PTRACE_MODE_READ);
59196 }
59197
59198@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
59199 put_task_struct(task);
59200
59201 if (!has_perms) {
59202+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59203+ {
59204+#else
59205 if (pid->hide_pid == 2) {
59206+#endif
59207 /*
59208 * Let's make getdents(), stat(), and open()
59209 * consistent with each other. If a process
59210@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59211 if (!task)
59212 return -ESRCH;
59213
59214+ if (gr_acl_handle_procpidmem(task)) {
59215+ put_task_struct(task);
59216+ return -EPERM;
59217+ }
59218+
59219 mm = mm_access(task, mode);
59220 put_task_struct(task);
59221
59222@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59223
59224 file->private_data = mm;
59225
59226+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59227+ file->f_version = current->exec_id;
59228+#endif
59229+
59230 return 0;
59231 }
59232
59233@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59234 ssize_t copied;
59235 char *page;
59236
59237+#ifdef CONFIG_GRKERNSEC
59238+ if (write)
59239+ return -EPERM;
59240+#endif
59241+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59242+ if (file->f_version != current->exec_id) {
59243+ gr_log_badprocpid("mem");
59244+ return 0;
59245+ }
59246+#endif
59247+
59248 if (!mm)
59249 return 0;
59250
59251@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59252 goto free;
59253
59254 while (count > 0) {
59255- int this_len = min_t(int, count, PAGE_SIZE);
59256+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
59257
59258 if (write && copy_from_user(page, buf, this_len)) {
59259 copied = -EFAULT;
59260@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59261 if (!mm)
59262 return 0;
59263
59264+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59265+ if (file->f_version != current->exec_id) {
59266+ gr_log_badprocpid("environ");
59267+ return 0;
59268+ }
59269+#endif
59270+
59271 page = (char *)__get_free_page(GFP_TEMPORARY);
59272 if (!page)
59273 return -ENOMEM;
59274@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59275 goto free;
59276 while (count > 0) {
59277 size_t this_len, max_len;
59278- int retval;
59279+ ssize_t retval;
59280
59281 if (src >= (mm->env_end - mm->env_start))
59282 break;
59283@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
59284 int error = -EACCES;
59285
59286 /* Are we allowed to snoop on the tasks file descriptors? */
59287- if (!proc_fd_access_allowed(inode))
59288+ if (!proc_fd_access_allowed(inode, 0))
59289 goto out;
59290
59291 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59292@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
59293 struct path path;
59294
59295 /* Are we allowed to snoop on the tasks file descriptors? */
59296- if (!proc_fd_access_allowed(inode))
59297- goto out;
59298+ /* logging this is needed for learning on chromium to work properly,
59299+ but we don't want to flood the logs from 'ps' which does a readlink
59300+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
59301+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
59302+ */
59303+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
59304+ if (!proc_fd_access_allowed(inode,0))
59305+ goto out;
59306+ } else {
59307+ if (!proc_fd_access_allowed(inode,1))
59308+ goto out;
59309+ }
59310
59311 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59312 if (error)
59313@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
59314 rcu_read_lock();
59315 cred = __task_cred(task);
59316 inode->i_uid = cred->euid;
59317+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59318+ inode->i_gid = grsec_proc_gid;
59319+#else
59320 inode->i_gid = cred->egid;
59321+#endif
59322 rcu_read_unlock();
59323 }
59324 security_task_to_inode(task, inode);
59325@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
59326 return -ENOENT;
59327 }
59328 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59329+#ifdef CONFIG_GRKERNSEC_PROC_USER
59330+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59331+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59332+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59333+#endif
59334 task_dumpable(task)) {
59335 cred = __task_cred(task);
59336 stat->uid = cred->euid;
59337+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59338+ stat->gid = grsec_proc_gid;
59339+#else
59340 stat->gid = cred->egid;
59341+#endif
59342 }
59343 }
59344 rcu_read_unlock();
59345@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
59346
59347 if (task) {
59348 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59349+#ifdef CONFIG_GRKERNSEC_PROC_USER
59350+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59351+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59352+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59353+#endif
59354 task_dumpable(task)) {
59355 rcu_read_lock();
59356 cred = __task_cred(task);
59357 inode->i_uid = cred->euid;
59358+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59359+ inode->i_gid = grsec_proc_gid;
59360+#else
59361 inode->i_gid = cred->egid;
59362+#endif
59363 rcu_read_unlock();
59364 } else {
59365 inode->i_uid = GLOBAL_ROOT_UID;
59366@@ -2166,6 +2284,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
59367 if (!task)
59368 goto out_no_task;
59369
59370+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59371+ goto out;
59372+
59373 /*
59374 * Yes, it does not scale. And it should not. Don't add
59375 * new entries into /proc/<tgid>/ without very good reasons.
59376@@ -2196,6 +2317,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
59377 if (!task)
59378 return -ENOENT;
59379
59380+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59381+ goto out;
59382+
59383 if (!dir_emit_dots(file, ctx))
59384 goto out;
59385
59386@@ -2585,7 +2709,7 @@ static const struct pid_entry tgid_base_stuff[] = {
59387 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
59388 #endif
59389 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59390-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59391+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59392 INF("syscall", S_IRUGO, proc_pid_syscall),
59393 #endif
59394 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59395@@ -2610,10 +2734,10 @@ static const struct pid_entry tgid_base_stuff[] = {
59396 #ifdef CONFIG_SECURITY
59397 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59398 #endif
59399-#ifdef CONFIG_KALLSYMS
59400+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59401 INF("wchan", S_IRUGO, proc_pid_wchan),
59402 #endif
59403-#ifdef CONFIG_STACKTRACE
59404+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59405 ONE("stack", S_IRUGO, proc_pid_stack),
59406 #endif
59407 #ifdef CONFIG_SCHEDSTATS
59408@@ -2647,6 +2771,9 @@ static const struct pid_entry tgid_base_stuff[] = {
59409 #ifdef CONFIG_HARDWALL
59410 INF("hardwall", S_IRUGO, proc_pid_hardwall),
59411 #endif
59412+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59413+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
59414+#endif
59415 #ifdef CONFIG_USER_NS
59416 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
59417 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
59418@@ -2777,7 +2904,14 @@ static int proc_pid_instantiate(struct inode *dir,
59419 if (!inode)
59420 goto out;
59421
59422+#ifdef CONFIG_GRKERNSEC_PROC_USER
59423+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
59424+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59425+ inode->i_gid = grsec_proc_gid;
59426+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
59427+#else
59428 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
59429+#endif
59430 inode->i_op = &proc_tgid_base_inode_operations;
59431 inode->i_fop = &proc_tgid_base_operations;
59432 inode->i_flags|=S_IMMUTABLE;
59433@@ -2815,7 +2949,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
59434 if (!task)
59435 goto out;
59436
59437+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59438+ goto out_put_task;
59439+
59440 result = proc_pid_instantiate(dir, dentry, task, NULL);
59441+out_put_task:
59442 put_task_struct(task);
59443 out:
59444 return ERR_PTR(result);
59445@@ -2921,7 +3059,7 @@ static const struct pid_entry tid_base_stuff[] = {
59446 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
59447 #endif
59448 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59449-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59450+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59451 INF("syscall", S_IRUGO, proc_pid_syscall),
59452 #endif
59453 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59454@@ -2948,10 +3086,10 @@ static const struct pid_entry tid_base_stuff[] = {
59455 #ifdef CONFIG_SECURITY
59456 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59457 #endif
59458-#ifdef CONFIG_KALLSYMS
59459+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59460 INF("wchan", S_IRUGO, proc_pid_wchan),
59461 #endif
59462-#ifdef CONFIG_STACKTRACE
59463+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59464 ONE("stack", S_IRUGO, proc_pid_stack),
59465 #endif
59466 #ifdef CONFIG_SCHEDSTATS
59467diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
59468index 82676e3..5f8518a 100644
59469--- a/fs/proc/cmdline.c
59470+++ b/fs/proc/cmdline.c
59471@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
59472
59473 static int __init proc_cmdline_init(void)
59474 {
59475+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59476+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
59477+#else
59478 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
59479+#endif
59480 return 0;
59481 }
59482 module_init(proc_cmdline_init);
59483diff --git a/fs/proc/devices.c b/fs/proc/devices.c
59484index b143471..bb105e5 100644
59485--- a/fs/proc/devices.c
59486+++ b/fs/proc/devices.c
59487@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
59488
59489 static int __init proc_devices_init(void)
59490 {
59491+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59492+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
59493+#else
59494 proc_create("devices", 0, NULL, &proc_devinfo_operations);
59495+#endif
59496 return 0;
59497 }
59498 module_init(proc_devices_init);
59499diff --git a/fs/proc/fd.c b/fs/proc/fd.c
59500index 0ff80f9..a1d7500 100644
59501--- a/fs/proc/fd.c
59502+++ b/fs/proc/fd.c
59503@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
59504 if (!task)
59505 return -ENOENT;
59506
59507- files = get_files_struct(task);
59508+ if (!gr_acl_handle_procpidmem(task))
59509+ files = get_files_struct(task);
59510 put_task_struct(task);
59511
59512 if (files) {
59513@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
59514 */
59515 int proc_fd_permission(struct inode *inode, int mask)
59516 {
59517+ struct task_struct *task;
59518 int rv = generic_permission(inode, mask);
59519- if (rv == 0)
59520- return 0;
59521+
59522 if (task_pid(current) == proc_pid(inode))
59523 rv = 0;
59524+
59525+ task = get_proc_task(inode);
59526+ if (task == NULL)
59527+ return rv;
59528+
59529+ if (gr_acl_handle_procpidmem(task))
59530+ rv = -EACCES;
59531+
59532+ put_task_struct(task);
59533+
59534 return rv;
59535 }
59536
59537diff --git a/fs/proc/inode.c b/fs/proc/inode.c
59538index 073aea6..0630370 100644
59539--- a/fs/proc/inode.c
59540+++ b/fs/proc/inode.c
59541@@ -23,11 +23,17 @@
59542 #include <linux/slab.h>
59543 #include <linux/mount.h>
59544 #include <linux/magic.h>
59545+#include <linux/grsecurity.h>
59546
59547 #include <asm/uaccess.h>
59548
59549 #include "internal.h"
59550
59551+#ifdef CONFIG_PROC_SYSCTL
59552+extern const struct inode_operations proc_sys_inode_operations;
59553+extern const struct inode_operations proc_sys_dir_operations;
59554+#endif
59555+
59556 static void proc_evict_inode(struct inode *inode)
59557 {
59558 struct proc_dir_entry *de;
59559@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
59560 ns = PROC_I(inode)->ns.ns;
59561 if (ns_ops && ns)
59562 ns_ops->put(ns);
59563+
59564+#ifdef CONFIG_PROC_SYSCTL
59565+ if (inode->i_op == &proc_sys_inode_operations ||
59566+ inode->i_op == &proc_sys_dir_operations)
59567+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
59568+#endif
59569+
59570 }
59571
59572 static struct kmem_cache * proc_inode_cachep;
59573@@ -385,7 +398,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
59574 if (de->mode) {
59575 inode->i_mode = de->mode;
59576 inode->i_uid = de->uid;
59577+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59578+ inode->i_gid = grsec_proc_gid;
59579+#else
59580 inode->i_gid = de->gid;
59581+#endif
59582 }
59583 if (de->size)
59584 inode->i_size = de->size;
59585diff --git a/fs/proc/internal.h b/fs/proc/internal.h
59586index 651d09a..60c73ae 100644
59587--- a/fs/proc/internal.h
59588+++ b/fs/proc/internal.h
59589@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
59590 struct pid *, struct task_struct *);
59591 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
59592 struct pid *, struct task_struct *);
59593+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59594+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
59595+#endif
59596
59597 /*
59598 * base.c
59599diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
59600index 06ea155..9a798c7 100644
59601--- a/fs/proc/kcore.c
59602+++ b/fs/proc/kcore.c
59603@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59604 * the addresses in the elf_phdr on our list.
59605 */
59606 start = kc_offset_to_vaddr(*fpos - elf_buflen);
59607- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
59608+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
59609+ if (tsz > buflen)
59610 tsz = buflen;
59611-
59612+
59613 while (buflen) {
59614 struct kcore_list *m;
59615
59616@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59617 kfree(elf_buf);
59618 } else {
59619 if (kern_addr_valid(start)) {
59620- unsigned long n;
59621+ char *elf_buf;
59622+ mm_segment_t oldfs;
59623
59624- n = copy_to_user(buffer, (char *)start, tsz);
59625- /*
59626- * We cannot distinguish between fault on source
59627- * and fault on destination. When this happens
59628- * we clear too and hope it will trigger the
59629- * EFAULT again.
59630- */
59631- if (n) {
59632- if (clear_user(buffer + tsz - n,
59633- n))
59634+ elf_buf = kmalloc(tsz, GFP_KERNEL);
59635+ if (!elf_buf)
59636+ return -ENOMEM;
59637+ oldfs = get_fs();
59638+ set_fs(KERNEL_DS);
59639+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
59640+ set_fs(oldfs);
59641+ if (copy_to_user(buffer, elf_buf, tsz)) {
59642+ kfree(elf_buf);
59643 return -EFAULT;
59644+ }
59645 }
59646+ set_fs(oldfs);
59647+ kfree(elf_buf);
59648 } else {
59649 if (clear_user(buffer, tsz))
59650 return -EFAULT;
59651@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59652
59653 static int open_kcore(struct inode *inode, struct file *filp)
59654 {
59655+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
59656+ return -EPERM;
59657+#endif
59658 if (!capable(CAP_SYS_RAWIO))
59659 return -EPERM;
59660 if (kcore_need_update)
59661diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
59662index 5aa847a..f77c8d4 100644
59663--- a/fs/proc/meminfo.c
59664+++ b/fs/proc/meminfo.c
59665@@ -159,7 +159,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
59666 vmi.used >> 10,
59667 vmi.largest_chunk >> 10
59668 #ifdef CONFIG_MEMORY_FAILURE
59669- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
59670+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
59671 #endif
59672 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
59673 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
59674diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
59675index ccfd99b..1b7e255 100644
59676--- a/fs/proc/nommu.c
59677+++ b/fs/proc/nommu.c
59678@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
59679 if (len < 1)
59680 len = 1;
59681 seq_printf(m, "%*c", len, ' ');
59682- seq_path(m, &file->f_path, "");
59683+ seq_path(m, &file->f_path, "\n\\");
59684 }
59685
59686 seq_putc(m, '\n');
59687diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
59688index 4677bb7..408e936 100644
59689--- a/fs/proc/proc_net.c
59690+++ b/fs/proc/proc_net.c
59691@@ -23,6 +23,7 @@
59692 #include <linux/nsproxy.h>
59693 #include <net/net_namespace.h>
59694 #include <linux/seq_file.h>
59695+#include <linux/grsecurity.h>
59696
59697 #include "internal.h"
59698
59699@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
59700 struct task_struct *task;
59701 struct nsproxy *ns;
59702 struct net *net = NULL;
59703+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59704+ const struct cred *cred = current_cred();
59705+#endif
59706+
59707+#ifdef CONFIG_GRKERNSEC_PROC_USER
59708+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
59709+ return net;
59710+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59711+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
59712+ return net;
59713+#endif
59714
59715 rcu_read_lock();
59716 task = pid_task(proc_pid(dir), PIDTYPE_PID);
59717diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
59718index 7129046..f2779c6 100644
59719--- a/fs/proc/proc_sysctl.c
59720+++ b/fs/proc/proc_sysctl.c
59721@@ -13,11 +13,15 @@
59722 #include <linux/module.h>
59723 #include "internal.h"
59724
59725+extern int gr_handle_chroot_sysctl(const int op);
59726+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
59727+ const int op);
59728+
59729 static const struct dentry_operations proc_sys_dentry_operations;
59730 static const struct file_operations proc_sys_file_operations;
59731-static const struct inode_operations proc_sys_inode_operations;
59732+const struct inode_operations proc_sys_inode_operations;
59733 static const struct file_operations proc_sys_dir_file_operations;
59734-static const struct inode_operations proc_sys_dir_operations;
59735+const struct inode_operations proc_sys_dir_operations;
59736
59737 void proc_sys_poll_notify(struct ctl_table_poll *poll)
59738 {
59739@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
59740
59741 err = NULL;
59742 d_set_d_op(dentry, &proc_sys_dentry_operations);
59743+
59744+ gr_handle_proc_create(dentry, inode);
59745+
59746 d_add(dentry, inode);
59747
59748 out:
59749@@ -482,6 +489,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59750 struct inode *inode = file_inode(filp);
59751 struct ctl_table_header *head = grab_header(inode);
59752 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
59753+ int op = write ? MAY_WRITE : MAY_READ;
59754 ssize_t error;
59755 size_t res;
59756
59757@@ -493,7 +501,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59758 * and won't be until we finish.
59759 */
59760 error = -EPERM;
59761- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
59762+ if (sysctl_perm(head, table, op))
59763 goto out;
59764
59765 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
59766@@ -501,6 +509,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59767 if (!table->proc_handler)
59768 goto out;
59769
59770+#ifdef CONFIG_GRKERNSEC
59771+ error = -EPERM;
59772+ if (gr_handle_chroot_sysctl(op))
59773+ goto out;
59774+ dget(filp->f_path.dentry);
59775+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
59776+ dput(filp->f_path.dentry);
59777+ goto out;
59778+ }
59779+ dput(filp->f_path.dentry);
59780+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
59781+ goto out;
59782+ if (write && !capable(CAP_SYS_ADMIN))
59783+ goto out;
59784+#endif
59785+
59786 /* careful: calling conventions are nasty here */
59787 res = count;
59788 error = table->proc_handler(table, write, buf, &res, ppos);
59789@@ -598,6 +622,9 @@ static bool proc_sys_fill_cache(struct file *file,
59790 return false;
59791 } else {
59792 d_set_d_op(child, &proc_sys_dentry_operations);
59793+
59794+ gr_handle_proc_create(child, inode);
59795+
59796 d_add(child, inode);
59797 }
59798 } else {
59799@@ -641,6 +668,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
59800 if ((*pos)++ < ctx->pos)
59801 return true;
59802
59803+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
59804+ return 0;
59805+
59806 if (unlikely(S_ISLNK(table->mode)))
59807 res = proc_sys_link_fill_cache(file, ctx, head, table);
59808 else
59809@@ -734,6 +764,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
59810 if (IS_ERR(head))
59811 return PTR_ERR(head);
59812
59813+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
59814+ return -ENOENT;
59815+
59816 generic_fillattr(inode, stat);
59817 if (table)
59818 stat->mode = (stat->mode & S_IFMT) | table->mode;
59819@@ -756,13 +789,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
59820 .llseek = generic_file_llseek,
59821 };
59822
59823-static const struct inode_operations proc_sys_inode_operations = {
59824+const struct inode_operations proc_sys_inode_operations = {
59825 .permission = proc_sys_permission,
59826 .setattr = proc_sys_setattr,
59827 .getattr = proc_sys_getattr,
59828 };
59829
59830-static const struct inode_operations proc_sys_dir_operations = {
59831+const struct inode_operations proc_sys_dir_operations = {
59832 .lookup = proc_sys_lookup,
59833 .permission = proc_sys_permission,
59834 .setattr = proc_sys_setattr,
59835@@ -839,7 +872,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
59836 static struct ctl_dir *new_dir(struct ctl_table_set *set,
59837 const char *name, int namelen)
59838 {
59839- struct ctl_table *table;
59840+ ctl_table_no_const *table;
59841 struct ctl_dir *new;
59842 struct ctl_node *node;
59843 char *new_name;
59844@@ -851,7 +884,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
59845 return NULL;
59846
59847 node = (struct ctl_node *)(new + 1);
59848- table = (struct ctl_table *)(node + 1);
59849+ table = (ctl_table_no_const *)(node + 1);
59850 new_name = (char *)(table + 2);
59851 memcpy(new_name, name, namelen);
59852 new_name[namelen] = '\0';
59853@@ -1020,7 +1053,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
59854 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
59855 struct ctl_table_root *link_root)
59856 {
59857- struct ctl_table *link_table, *entry, *link;
59858+ ctl_table_no_const *link_table, *link;
59859+ struct ctl_table *entry;
59860 struct ctl_table_header *links;
59861 struct ctl_node *node;
59862 char *link_name;
59863@@ -1043,7 +1077,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
59864 return NULL;
59865
59866 node = (struct ctl_node *)(links + 1);
59867- link_table = (struct ctl_table *)(node + nr_entries);
59868+ link_table = (ctl_table_no_const *)(node + nr_entries);
59869 link_name = (char *)&link_table[nr_entries + 1];
59870
59871 for (link = link_table, entry = table; entry->procname; link++, entry++) {
59872@@ -1291,8 +1325,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59873 struct ctl_table_header ***subheader, struct ctl_table_set *set,
59874 struct ctl_table *table)
59875 {
59876- struct ctl_table *ctl_table_arg = NULL;
59877- struct ctl_table *entry, *files;
59878+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
59879+ struct ctl_table *entry;
59880 int nr_files = 0;
59881 int nr_dirs = 0;
59882 int err = -ENOMEM;
59883@@ -1304,10 +1338,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59884 nr_files++;
59885 }
59886
59887- files = table;
59888 /* If there are mixed files and directories we need a new table */
59889 if (nr_dirs && nr_files) {
59890- struct ctl_table *new;
59891+ ctl_table_no_const *new;
59892 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
59893 GFP_KERNEL);
59894 if (!files)
59895@@ -1325,7 +1358,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59896 /* Register everything except a directory full of subdirectories */
59897 if (nr_files || !nr_dirs) {
59898 struct ctl_table_header *header;
59899- header = __register_sysctl_table(set, path, files);
59900+ header = __register_sysctl_table(set, path, files ? files : table);
59901 if (!header) {
59902 kfree(ctl_table_arg);
59903 goto out;
59904diff --git a/fs/proc/root.c b/fs/proc/root.c
59905index e0a790d..21e095e 100644
59906--- a/fs/proc/root.c
59907+++ b/fs/proc/root.c
59908@@ -182,7 +182,15 @@ void __init proc_root_init(void)
59909 #ifdef CONFIG_PROC_DEVICETREE
59910 proc_device_tree_init();
59911 #endif
59912+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59913+#ifdef CONFIG_GRKERNSEC_PROC_USER
59914+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
59915+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59916+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
59917+#endif
59918+#else
59919 proc_mkdir("bus", NULL);
59920+#endif
59921 proc_sys_init();
59922 }
59923
59924diff --git a/fs/proc/self.c b/fs/proc/self.c
59925index 6b6a993..807cccc 100644
59926--- a/fs/proc/self.c
59927+++ b/fs/proc/self.c
59928@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
59929 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
59930 void *cookie)
59931 {
59932- char *s = nd_get_link(nd);
59933+ const char *s = nd_get_link(nd);
59934 if (!IS_ERR(s))
59935 kfree(s);
59936 }
59937diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
59938index 107d026..c715aeb 100644
59939--- a/fs/proc/task_mmu.c
59940+++ b/fs/proc/task_mmu.c
59941@@ -12,12 +12,19 @@
59942 #include <linux/swap.h>
59943 #include <linux/swapops.h>
59944 #include <linux/mmu_notifier.h>
59945+#include <linux/grsecurity.h>
59946
59947 #include <asm/elf.h>
59948 #include <asm/uaccess.h>
59949 #include <asm/tlbflush.h>
59950 #include "internal.h"
59951
59952+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59953+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59954+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59955+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59956+#endif
59957+
59958 void task_mem(struct seq_file *m, struct mm_struct *mm)
59959 {
59960 unsigned long data, text, lib, swap;
59961@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
59962 "VmExe:\t%8lu kB\n"
59963 "VmLib:\t%8lu kB\n"
59964 "VmPTE:\t%8lu kB\n"
59965- "VmSwap:\t%8lu kB\n",
59966- hiwater_vm << (PAGE_SHIFT-10),
59967+ "VmSwap:\t%8lu kB\n"
59968+
59969+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59970+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
59971+#endif
59972+
59973+ ,hiwater_vm << (PAGE_SHIFT-10),
59974 total_vm << (PAGE_SHIFT-10),
59975 mm->locked_vm << (PAGE_SHIFT-10),
59976 mm->pinned_vm << (PAGE_SHIFT-10),
59977@@ -63,7 +75,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
59978 data << (PAGE_SHIFT-10),
59979 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
59980 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
59981- swap << (PAGE_SHIFT-10));
59982+ swap << (PAGE_SHIFT-10)
59983+
59984+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59985+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59986+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
59987+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
59988+#else
59989+ , mm->context.user_cs_base
59990+ , mm->context.user_cs_limit
59991+#endif
59992+#endif
59993+
59994+ );
59995 }
59996
59997 unsigned long task_vsize(struct mm_struct *mm)
59998@@ -278,13 +302,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59999 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
60000 }
60001
60002- /* We don't show the stack guard page in /proc/maps */
60003+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60004+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
60005+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
60006+#else
60007 start = vma->vm_start;
60008- if (stack_guard_page_start(vma, start))
60009- start += PAGE_SIZE;
60010 end = vma->vm_end;
60011- if (stack_guard_page_end(vma, end))
60012- end -= PAGE_SIZE;
60013+#endif
60014
60015 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
60016 start,
60017@@ -293,7 +317,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60018 flags & VM_WRITE ? 'w' : '-',
60019 flags & VM_EXEC ? 'x' : '-',
60020 flags & VM_MAYSHARE ? 's' : 'p',
60021+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60022+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
60023+#else
60024 pgoff,
60025+#endif
60026 MAJOR(dev), MINOR(dev), ino, &len);
60027
60028 /*
60029@@ -302,7 +330,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60030 */
60031 if (file) {
60032 pad_len_spaces(m, len);
60033- seq_path(m, &file->f_path, "\n");
60034+ seq_path(m, &file->f_path, "\n\\");
60035 goto done;
60036 }
60037
60038@@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60039 * Thread stack in /proc/PID/task/TID/maps or
60040 * the main process stack.
60041 */
60042- if (!is_pid || (vma->vm_start <= mm->start_stack &&
60043- vma->vm_end >= mm->start_stack)) {
60044+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
60045+ (vma->vm_start <= mm->start_stack &&
60046+ vma->vm_end >= mm->start_stack)) {
60047 name = "[stack]";
60048 } else {
60049 /* Thread stack in /proc/PID/maps */
60050@@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
60051 struct proc_maps_private *priv = m->private;
60052 struct task_struct *task = priv->task;
60053
60054+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60055+ if (current->exec_id != m->exec_id) {
60056+ gr_log_badprocpid("maps");
60057+ return 0;
60058+ }
60059+#endif
60060+
60061 show_map_vma(m, vma, is_pid);
60062
60063 if (m->count < m->size) /* vma is copied successfully */
60064@@ -590,12 +626,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
60065 .private = &mss,
60066 };
60067
60068+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60069+ if (current->exec_id != m->exec_id) {
60070+ gr_log_badprocpid("smaps");
60071+ return 0;
60072+ }
60073+#endif
60074 memset(&mss, 0, sizeof mss);
60075- mss.vma = vma;
60076- /* mmap_sem is held in m_start */
60077- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
60078- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
60079-
60080+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60081+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
60082+#endif
60083+ mss.vma = vma;
60084+ /* mmap_sem is held in m_start */
60085+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
60086+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
60087+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60088+ }
60089+#endif
60090 show_map_vma(m, vma, is_pid);
60091
60092 seq_printf(m,
60093@@ -613,7 +660,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
60094 "KernelPageSize: %8lu kB\n"
60095 "MMUPageSize: %8lu kB\n"
60096 "Locked: %8lu kB\n",
60097+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60098+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
60099+#else
60100 (vma->vm_end - vma->vm_start) >> 10,
60101+#endif
60102 mss.resident >> 10,
60103 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
60104 mss.shared_clean >> 10,
60105@@ -1362,6 +1413,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60106 int n;
60107 char buffer[50];
60108
60109+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60110+ if (current->exec_id != m->exec_id) {
60111+ gr_log_badprocpid("numa_maps");
60112+ return 0;
60113+ }
60114+#endif
60115+
60116 if (!mm)
60117 return 0;
60118
60119@@ -1379,11 +1437,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60120 mpol_to_str(buffer, sizeof(buffer), pol);
60121 mpol_cond_put(pol);
60122
60123+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60124+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
60125+#else
60126 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
60127+#endif
60128
60129 if (file) {
60130 seq_printf(m, " file=");
60131- seq_path(m, &file->f_path, "\n\t= ");
60132+ seq_path(m, &file->f_path, "\n\t\\= ");
60133 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
60134 seq_printf(m, " heap");
60135 } else {
60136diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
60137index 56123a6..5a2f6ec 100644
60138--- a/fs/proc/task_nommu.c
60139+++ b/fs/proc/task_nommu.c
60140@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
60141 else
60142 bytes += kobjsize(mm);
60143
60144- if (current->fs && current->fs->users > 1)
60145+ if (current->fs && atomic_read(&current->fs->users) > 1)
60146 sbytes += kobjsize(current->fs);
60147 else
60148 bytes += kobjsize(current->fs);
60149@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
60150
60151 if (file) {
60152 pad_len_spaces(m, len);
60153- seq_path(m, &file->f_path, "");
60154+ seq_path(m, &file->f_path, "\n\\");
60155 } else if (mm) {
60156 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
60157
60158diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
60159index a1a16eb..6be46ed 100644
60160--- a/fs/proc/vmcore.c
60161+++ b/fs/proc/vmcore.c
60162@@ -104,9 +104,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
60163 nr_bytes = count;
60164
60165 /* If pfn is not ram, return zeros for sparse dump files */
60166- if (pfn_is_ram(pfn) == 0)
60167- memset(buf, 0, nr_bytes);
60168- else {
60169+ if (pfn_is_ram(pfn) == 0) {
60170+ if (userbuf) {
60171+ if (clear_user((char __force_user *)buf, nr_bytes))
60172+ return -EFAULT;
60173+ } else
60174+ memset(buf, 0, nr_bytes);
60175+ } else {
60176 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
60177 offset, userbuf);
60178 if (tmp < 0)
60179@@ -178,7 +182,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
60180 if (*fpos < m->offset + m->size) {
60181 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
60182 start = m->paddr + *fpos - m->offset;
60183- tmp = read_from_oldmem(buffer, tsz, &start, 1);
60184+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
60185 if (tmp < 0)
60186 return tmp;
60187 buflen -= tsz;
60188diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
60189index b00fcc9..e0c6381 100644
60190--- a/fs/qnx6/qnx6.h
60191+++ b/fs/qnx6/qnx6.h
60192@@ -74,7 +74,7 @@ enum {
60193 BYTESEX_BE,
60194 };
60195
60196-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60197+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60198 {
60199 if (sbi->s_bytesex == BYTESEX_LE)
60200 return le64_to_cpu((__force __le64)n);
60201@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
60202 return (__force __fs64)cpu_to_be64(n);
60203 }
60204
60205-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60206+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60207 {
60208 if (sbi->s_bytesex == BYTESEX_LE)
60209 return le32_to_cpu((__force __le32)n);
60210diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
60211index 16e8abb..2dcf914 100644
60212--- a/fs/quota/netlink.c
60213+++ b/fs/quota/netlink.c
60214@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
60215 void quota_send_warning(struct kqid qid, dev_t dev,
60216 const char warntype)
60217 {
60218- static atomic_t seq;
60219+ static atomic_unchecked_t seq;
60220 struct sk_buff *skb;
60221 void *msg_head;
60222 int ret;
60223@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
60224 "VFS: Not enough memory to send quota warning.\n");
60225 return;
60226 }
60227- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
60228+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
60229 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
60230 if (!msg_head) {
60231 printk(KERN_ERR
60232diff --git a/fs/read_write.c b/fs/read_write.c
60233index 122a384..0b7ecf2 100644
60234--- a/fs/read_write.c
60235+++ b/fs/read_write.c
60236@@ -440,7 +440,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
60237
60238 old_fs = get_fs();
60239 set_fs(get_ds());
60240- p = (__force const char __user *)buf;
60241+ p = (const char __force_user *)buf;
60242 if (count > MAX_RW_COUNT)
60243 count = MAX_RW_COUNT;
60244 if (file->f_op->write)
60245diff --git a/fs/readdir.c b/fs/readdir.c
60246index 93d71e5..6a14be8 100644
60247--- a/fs/readdir.c
60248+++ b/fs/readdir.c
60249@@ -17,6 +17,7 @@
60250 #include <linux/security.h>
60251 #include <linux/syscalls.h>
60252 #include <linux/unistd.h>
60253+#include <linux/namei.h>
60254
60255 #include <asm/uaccess.h>
60256
60257@@ -69,6 +70,7 @@ struct old_linux_dirent {
60258 struct readdir_callback {
60259 struct dir_context ctx;
60260 struct old_linux_dirent __user * dirent;
60261+ struct file * file;
60262 int result;
60263 };
60264
60265@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
60266 buf->result = -EOVERFLOW;
60267 return -EOVERFLOW;
60268 }
60269+
60270+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60271+ return 0;
60272+
60273 buf->result++;
60274 dirent = buf->dirent;
60275 if (!access_ok(VERIFY_WRITE, dirent,
60276@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60277 if (!f.file)
60278 return -EBADF;
60279
60280+ buf.file = f.file;
60281 error = iterate_dir(f.file, &buf.ctx);
60282 if (buf.result)
60283 error = buf.result;
60284@@ -142,6 +149,7 @@ struct getdents_callback {
60285 struct dir_context ctx;
60286 struct linux_dirent __user * current_dir;
60287 struct linux_dirent __user * previous;
60288+ struct file * file;
60289 int count;
60290 int error;
60291 };
60292@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
60293 buf->error = -EOVERFLOW;
60294 return -EOVERFLOW;
60295 }
60296+
60297+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60298+ return 0;
60299+
60300 dirent = buf->previous;
60301 if (dirent) {
60302 if (__put_user(offset, &dirent->d_off))
60303@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
60304 if (!f.file)
60305 return -EBADF;
60306
60307+ buf.file = f.file;
60308 error = iterate_dir(f.file, &buf.ctx);
60309 if (error >= 0)
60310 error = buf.error;
60311@@ -226,6 +239,7 @@ struct getdents_callback64 {
60312 struct dir_context ctx;
60313 struct linux_dirent64 __user * current_dir;
60314 struct linux_dirent64 __user * previous;
60315+ struct file *file;
60316 int count;
60317 int error;
60318 };
60319@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
60320 buf->error = -EINVAL; /* only used if we fail.. */
60321 if (reclen > buf->count)
60322 return -EINVAL;
60323+
60324+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60325+ return 0;
60326+
60327 dirent = buf->previous;
60328 if (dirent) {
60329 if (__put_user(offset, &dirent->d_off))
60330@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60331 if (!f.file)
60332 return -EBADF;
60333
60334+ buf.file = f.file;
60335 error = iterate_dir(f.file, &buf.ctx);
60336 if (error >= 0)
60337 error = buf.error;
60338diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
60339index 2b7882b..1c5ef48 100644
60340--- a/fs/reiserfs/do_balan.c
60341+++ b/fs/reiserfs/do_balan.c
60342@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
60343 return;
60344 }
60345
60346- atomic_inc(&(fs_generation(tb->tb_sb)));
60347+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
60348 do_balance_starts(tb);
60349
60350 /* balance leaf returns 0 except if combining L R and S into
60351diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
60352index a958444..42b2323 100644
60353--- a/fs/reiserfs/procfs.c
60354+++ b/fs/reiserfs/procfs.c
60355@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
60356 "SMALL_TAILS " : "NO_TAILS ",
60357 replay_only(sb) ? "REPLAY_ONLY " : "",
60358 convert_reiserfs(sb) ? "CONV " : "",
60359- atomic_read(&r->s_generation_counter),
60360+ atomic_read_unchecked(&r->s_generation_counter),
60361 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
60362 SF(s_do_balance), SF(s_unneeded_left_neighbor),
60363 SF(s_good_search_by_key_reada), SF(s_bmaps),
60364diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
60365index 3df5ce6..8c0f4b0 100644
60366--- a/fs/reiserfs/reiserfs.h
60367+++ b/fs/reiserfs/reiserfs.h
60368@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
60369 /* Comment? -Hans */
60370 wait_queue_head_t s_wait;
60371 /* To be obsoleted soon by per buffer seals.. -Hans */
60372- atomic_t s_generation_counter; // increased by one every time the
60373+ atomic_unchecked_t s_generation_counter; // increased by one every time the
60374 // tree gets re-balanced
60375 unsigned long s_properties; /* File system properties. Currently holds
60376 on-disk FS format */
60377@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
60378 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
60379
60380 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
60381-#define get_generation(s) atomic_read (&fs_generation(s))
60382+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
60383 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
60384 #define __fs_changed(gen,s) (gen != get_generation (s))
60385 #define fs_changed(gen,s) \
60386diff --git a/fs/select.c b/fs/select.c
60387index 35d4adc7..d6c60db 100644
60388--- a/fs/select.c
60389+++ b/fs/select.c
60390@@ -20,6 +20,7 @@
60391 #include <linux/export.h>
60392 #include <linux/slab.h>
60393 #include <linux/poll.h>
60394+#include <linux/security.h>
60395 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
60396 #include <linux/file.h>
60397 #include <linux/fdtable.h>
60398@@ -881,6 +882,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
60399 struct poll_list *walk = head;
60400 unsigned long todo = nfds;
60401
60402+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
60403 if (nfds > rlimit(RLIMIT_NOFILE))
60404 return -EINVAL;
60405
60406diff --git a/fs/seq_file.c b/fs/seq_file.c
60407index 3135c25..d0395dd 100644
60408--- a/fs/seq_file.c
60409+++ b/fs/seq_file.c
60410@@ -10,6 +10,7 @@
60411 #include <linux/seq_file.h>
60412 #include <linux/slab.h>
60413 #include <linux/cred.h>
60414+#include <linux/sched.h>
60415
60416 #include <asm/uaccess.h>
60417 #include <asm/page.h>
60418@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
60419 #ifdef CONFIG_USER_NS
60420 p->user_ns = file->f_cred->user_ns;
60421 #endif
60422+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60423+ p->exec_id = current->exec_id;
60424+#endif
60425
60426 /*
60427 * Wrappers around seq_open(e.g. swaps_open) need to be
60428@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60429 return 0;
60430 }
60431 if (!m->buf) {
60432- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60433+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60434 if (!m->buf)
60435 return -ENOMEM;
60436 }
60437@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60438 Eoverflow:
60439 m->op->stop(m, p);
60440 kfree(m->buf);
60441- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60442+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60443 return !m->buf ? -ENOMEM : -EAGAIN;
60444 }
60445
60446@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60447
60448 /* grab buffer if we didn't have one */
60449 if (!m->buf) {
60450- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60451+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60452 if (!m->buf)
60453 goto Enomem;
60454 }
60455@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60456 goto Fill;
60457 m->op->stop(m, p);
60458 kfree(m->buf);
60459- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60460+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60461 if (!m->buf)
60462 goto Enomem;
60463 m->count = 0;
60464@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
60465 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
60466 void *data)
60467 {
60468- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
60469+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
60470 int res = -ENOMEM;
60471
60472 if (op) {
60473diff --git a/fs/splice.c b/fs/splice.c
60474index 3b7ee65..87fc2e4 100644
60475--- a/fs/splice.c
60476+++ b/fs/splice.c
60477@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60478 pipe_lock(pipe);
60479
60480 for (;;) {
60481- if (!pipe->readers) {
60482+ if (!atomic_read(&pipe->readers)) {
60483 send_sig(SIGPIPE, current, 0);
60484 if (!ret)
60485 ret = -EPIPE;
60486@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60487 page_nr++;
60488 ret += buf->len;
60489
60490- if (pipe->files)
60491+ if (atomic_read(&pipe->files))
60492 do_wakeup = 1;
60493
60494 if (!--spd->nr_pages)
60495@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60496 do_wakeup = 0;
60497 }
60498
60499- pipe->waiting_writers++;
60500+ atomic_inc(&pipe->waiting_writers);
60501 pipe_wait(pipe);
60502- pipe->waiting_writers--;
60503+ atomic_dec(&pipe->waiting_writers);
60504 }
60505
60506 pipe_unlock(pipe);
60507@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
60508 old_fs = get_fs();
60509 set_fs(get_ds());
60510 /* The cast to a user pointer is valid due to the set_fs() */
60511- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
60512+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
60513 set_fs(old_fs);
60514
60515 return res;
60516@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
60517 old_fs = get_fs();
60518 set_fs(get_ds());
60519 /* The cast to a user pointer is valid due to the set_fs() */
60520- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
60521+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
60522 set_fs(old_fs);
60523
60524 return res;
60525@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
60526 goto err;
60527
60528 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
60529- vec[i].iov_base = (void __user *) page_address(page);
60530+ vec[i].iov_base = (void __force_user *) page_address(page);
60531 vec[i].iov_len = this_len;
60532 spd.pages[i] = page;
60533 spd.nr_pages++;
60534@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
60535 ops->release(pipe, buf);
60536 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
60537 pipe->nrbufs--;
60538- if (pipe->files)
60539+ if (atomic_read(&pipe->files))
60540 sd->need_wakeup = true;
60541 }
60542
60543@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
60544 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
60545 {
60546 while (!pipe->nrbufs) {
60547- if (!pipe->writers)
60548+ if (!atomic_read(&pipe->writers))
60549 return 0;
60550
60551- if (!pipe->waiting_writers && sd->num_spliced)
60552+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
60553 return 0;
60554
60555 if (sd->flags & SPLICE_F_NONBLOCK)
60556@@ -1179,7 +1179,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
60557 * out of the pipe right after the splice_to_pipe(). So set
60558 * PIPE_READERS appropriately.
60559 */
60560- pipe->readers = 1;
60561+ atomic_set(&pipe->readers, 1);
60562
60563 current->splice_pipe = pipe;
60564 }
60565@@ -1475,6 +1475,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
60566
60567 partial[buffers].offset = off;
60568 partial[buffers].len = plen;
60569+ partial[buffers].private = 0;
60570
60571 off = 0;
60572 len -= plen;
60573@@ -1777,9 +1778,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60574 ret = -ERESTARTSYS;
60575 break;
60576 }
60577- if (!pipe->writers)
60578+ if (!atomic_read(&pipe->writers))
60579 break;
60580- if (!pipe->waiting_writers) {
60581+ if (!atomic_read(&pipe->waiting_writers)) {
60582 if (flags & SPLICE_F_NONBLOCK) {
60583 ret = -EAGAIN;
60584 break;
60585@@ -1811,7 +1812,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60586 pipe_lock(pipe);
60587
60588 while (pipe->nrbufs >= pipe->buffers) {
60589- if (!pipe->readers) {
60590+ if (!atomic_read(&pipe->readers)) {
60591 send_sig(SIGPIPE, current, 0);
60592 ret = -EPIPE;
60593 break;
60594@@ -1824,9 +1825,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60595 ret = -ERESTARTSYS;
60596 break;
60597 }
60598- pipe->waiting_writers++;
60599+ atomic_inc(&pipe->waiting_writers);
60600 pipe_wait(pipe);
60601- pipe->waiting_writers--;
60602+ atomic_dec(&pipe->waiting_writers);
60603 }
60604
60605 pipe_unlock(pipe);
60606@@ -1862,14 +1863,14 @@ retry:
60607 pipe_double_lock(ipipe, opipe);
60608
60609 do {
60610- if (!opipe->readers) {
60611+ if (!atomic_read(&opipe->readers)) {
60612 send_sig(SIGPIPE, current, 0);
60613 if (!ret)
60614 ret = -EPIPE;
60615 break;
60616 }
60617
60618- if (!ipipe->nrbufs && !ipipe->writers)
60619+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
60620 break;
60621
60622 /*
60623@@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60624 pipe_double_lock(ipipe, opipe);
60625
60626 do {
60627- if (!opipe->readers) {
60628+ if (!atomic_read(&opipe->readers)) {
60629 send_sig(SIGPIPE, current, 0);
60630 if (!ret)
60631 ret = -EPIPE;
60632@@ -2011,7 +2012,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60633 * return EAGAIN if we have the potential of some data in the
60634 * future, otherwise just return 0
60635 */
60636- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
60637+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
60638 ret = -EAGAIN;
60639
60640 pipe_unlock(ipipe);
60641diff --git a/fs/stat.c b/fs/stat.c
60642index 04ce1ac..a13dd1e 100644
60643--- a/fs/stat.c
60644+++ b/fs/stat.c
60645@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
60646 stat->gid = inode->i_gid;
60647 stat->rdev = inode->i_rdev;
60648 stat->size = i_size_read(inode);
60649- stat->atime = inode->i_atime;
60650- stat->mtime = inode->i_mtime;
60651+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60652+ stat->atime = inode->i_ctime;
60653+ stat->mtime = inode->i_ctime;
60654+ } else {
60655+ stat->atime = inode->i_atime;
60656+ stat->mtime = inode->i_mtime;
60657+ }
60658 stat->ctime = inode->i_ctime;
60659 stat->blksize = (1 << inode->i_blkbits);
60660 stat->blocks = inode->i_blocks;
60661@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
60662 if (retval)
60663 return retval;
60664
60665- if (inode->i_op->getattr)
60666- return inode->i_op->getattr(path->mnt, path->dentry, stat);
60667+ if (inode->i_op->getattr) {
60668+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
60669+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60670+ stat->atime = stat->ctime;
60671+ stat->mtime = stat->ctime;
60672+ }
60673+ return retval;
60674+ }
60675
60676 generic_fillattr(inode, stat);
60677 return 0;
60678diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
60679index 15c68f9..36a8b3e 100644
60680--- a/fs/sysfs/bin.c
60681+++ b/fs/sysfs/bin.c
60682@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
60683 return ret;
60684 }
60685
60686-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
60687- void *buf, int len, int write)
60688+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
60689+ void *buf, size_t len, int write)
60690 {
60691 struct file *file = vma->vm_file;
60692 struct bin_buffer *bb = file->private_data;
60693 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
60694- int ret;
60695+ ssize_t ret;
60696
60697 if (!bb->vm_ops)
60698 return -EINVAL;
60699diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
60700index e068e74..92edeb8 100644
60701--- a/fs/sysfs/dir.c
60702+++ b/fs/sysfs/dir.c
60703@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
60704 *
60705 * Returns 31 bit hash of ns + name (so it fits in an off_t )
60706 */
60707-static unsigned int sysfs_name_hash(const void *ns, const char *name)
60708+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
60709 {
60710 unsigned long hash = init_name_hash();
60711 unsigned int len = strlen(name);
60712@@ -679,6 +679,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
60713 struct sysfs_dirent *sd;
60714 int rc;
60715
60716+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60717+ const char *parent_name = parent_sd->s_name;
60718+
60719+ mode = S_IFDIR | S_IRWXU;
60720+
60721+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
60722+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
60723+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
60724+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
60725+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
60726+#endif
60727+
60728 /* allocate */
60729 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
60730 if (!sd)
60731diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
60732index d2bb7ed..fe8c331 100644
60733--- a/fs/sysfs/file.c
60734+++ b/fs/sysfs/file.c
60735@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
60736
60737 struct sysfs_open_dirent {
60738 atomic_t refcnt;
60739- atomic_t event;
60740+ atomic_unchecked_t event;
60741 wait_queue_head_t poll;
60742 struct list_head buffers; /* goes through sysfs_buffer.list */
60743 };
60744@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
60745 if (!sysfs_get_active(attr_sd))
60746 return -ENODEV;
60747
60748- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
60749+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
60750 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
60751
60752 sysfs_put_active(attr_sd);
60753@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
60754 return -ENOMEM;
60755
60756 atomic_set(&new_od->refcnt, 0);
60757- atomic_set(&new_od->event, 1);
60758+ atomic_set_unchecked(&new_od->event, 1);
60759 init_waitqueue_head(&new_od->poll);
60760 INIT_LIST_HEAD(&new_od->buffers);
60761 goto retry;
60762@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
60763
60764 sysfs_put_active(attr_sd);
60765
60766- if (buffer->event != atomic_read(&od->event))
60767+ if (buffer->event != atomic_read_unchecked(&od->event))
60768 goto trigger;
60769
60770 return DEFAULT_POLLMASK;
60771@@ -452,7 +452,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
60772 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
60773 od = sd->s_attr.open;
60774 if (od) {
60775- atomic_inc(&od->event);
60776+ atomic_inc_unchecked(&od->event);
60777 wake_up_interruptible(&od->poll);
60778 }
60779 }
60780diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
60781index 8c940df..25b733e 100644
60782--- a/fs/sysfs/symlink.c
60783+++ b/fs/sysfs/symlink.c
60784@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
60785
60786 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
60787 {
60788- char *page = nd_get_link(nd);
60789+ const char *page = nd_get_link(nd);
60790 if (!IS_ERR(page))
60791 free_page((unsigned long)page);
60792 }
60793diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
60794index 69d4889..a810bd4 100644
60795--- a/fs/sysv/sysv.h
60796+++ b/fs/sysv/sysv.h
60797@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
60798 #endif
60799 }
60800
60801-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60802+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60803 {
60804 if (sbi->s_bytesex == BYTESEX_PDP)
60805 return PDP_swab((__force __u32)n);
60806diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
60807index e18b988..f1d4ad0f 100644
60808--- a/fs/ubifs/io.c
60809+++ b/fs/ubifs/io.c
60810@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
60811 return err;
60812 }
60813
60814-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60815+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60816 {
60817 int err;
60818
60819diff --git a/fs/udf/misc.c b/fs/udf/misc.c
60820index c175b4d..8f36a16 100644
60821--- a/fs/udf/misc.c
60822+++ b/fs/udf/misc.c
60823@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
60824
60825 u8 udf_tag_checksum(const struct tag *t)
60826 {
60827- u8 *data = (u8 *)t;
60828+ const u8 *data = (const u8 *)t;
60829 u8 checksum = 0;
60830 int i;
60831 for (i = 0; i < sizeof(struct tag); ++i)
60832diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
60833index 8d974c4..b82f6ec 100644
60834--- a/fs/ufs/swab.h
60835+++ b/fs/ufs/swab.h
60836@@ -22,7 +22,7 @@ enum {
60837 BYTESEX_BE
60838 };
60839
60840-static inline u64
60841+static inline u64 __intentional_overflow(-1)
60842 fs64_to_cpu(struct super_block *sbp, __fs64 n)
60843 {
60844 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60845@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
60846 return (__force __fs64)cpu_to_be64(n);
60847 }
60848
60849-static inline u32
60850+static inline u32 __intentional_overflow(-1)
60851 fs32_to_cpu(struct super_block *sbp, __fs32 n)
60852 {
60853 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60854diff --git a/fs/utimes.c b/fs/utimes.c
60855index f4fb7ec..3fe03c0 100644
60856--- a/fs/utimes.c
60857+++ b/fs/utimes.c
60858@@ -1,6 +1,7 @@
60859 #include <linux/compiler.h>
60860 #include <linux/file.h>
60861 #include <linux/fs.h>
60862+#include <linux/security.h>
60863 #include <linux/linkage.h>
60864 #include <linux/mount.h>
60865 #include <linux/namei.h>
60866@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
60867 goto mnt_drop_write_and_out;
60868 }
60869 }
60870+
60871+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
60872+ error = -EACCES;
60873+ goto mnt_drop_write_and_out;
60874+ }
60875+
60876 mutex_lock(&inode->i_mutex);
60877 error = notify_change(path->dentry, &newattrs);
60878 mutex_unlock(&inode->i_mutex);
60879diff --git a/fs/xattr.c b/fs/xattr.c
60880index 3377dff..4d074d9 100644
60881--- a/fs/xattr.c
60882+++ b/fs/xattr.c
60883@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
60884 return rc;
60885 }
60886
60887+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
60888+ssize_t
60889+pax_getxattr(struct dentry *dentry, void *value, size_t size)
60890+{
60891+ struct inode *inode = dentry->d_inode;
60892+ ssize_t error;
60893+
60894+ error = inode_permission(inode, MAY_EXEC);
60895+ if (error)
60896+ return error;
60897+
60898+ if (inode->i_op->getxattr)
60899+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
60900+ else
60901+ error = -EOPNOTSUPP;
60902+
60903+ return error;
60904+}
60905+EXPORT_SYMBOL(pax_getxattr);
60906+#endif
60907+
60908 ssize_t
60909 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
60910 {
60911@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
60912 * Extended attribute SET operations
60913 */
60914 static long
60915-setxattr(struct dentry *d, const char __user *name, const void __user *value,
60916+setxattr(struct path *path, const char __user *name, const void __user *value,
60917 size_t size, int flags)
60918 {
60919 int error;
60920@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
60921 posix_acl_fix_xattr_from_user(kvalue, size);
60922 }
60923
60924- error = vfs_setxattr(d, kname, kvalue, size, flags);
60925+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
60926+ error = -EACCES;
60927+ goto out;
60928+ }
60929+
60930+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
60931 out:
60932 if (vvalue)
60933 vfree(vvalue);
60934@@ -377,7 +403,7 @@ retry:
60935 return error;
60936 error = mnt_want_write(path.mnt);
60937 if (!error) {
60938- error = setxattr(path.dentry, name, value, size, flags);
60939+ error = setxattr(&path, name, value, size, flags);
60940 mnt_drop_write(path.mnt);
60941 }
60942 path_put(&path);
60943@@ -401,7 +427,7 @@ retry:
60944 return error;
60945 error = mnt_want_write(path.mnt);
60946 if (!error) {
60947- error = setxattr(path.dentry, name, value, size, flags);
60948+ error = setxattr(&path, name, value, size, flags);
60949 mnt_drop_write(path.mnt);
60950 }
60951 path_put(&path);
60952@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
60953 const void __user *,value, size_t, size, int, flags)
60954 {
60955 struct fd f = fdget(fd);
60956- struct dentry *dentry;
60957 int error = -EBADF;
60958
60959 if (!f.file)
60960 return error;
60961- dentry = f.file->f_path.dentry;
60962- audit_inode(NULL, dentry, 0);
60963+ audit_inode(NULL, f.file->f_path.dentry, 0);
60964 error = mnt_want_write_file(f.file);
60965 if (!error) {
60966- error = setxattr(dentry, name, value, size, flags);
60967+ error = setxattr(&f.file->f_path, name, value, size, flags);
60968 mnt_drop_write_file(f.file);
60969 }
60970 fdput(f);
60971diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
60972index 9fbea87..6b19972 100644
60973--- a/fs/xattr_acl.c
60974+++ b/fs/xattr_acl.c
60975@@ -76,8 +76,8 @@ struct posix_acl *
60976 posix_acl_from_xattr(struct user_namespace *user_ns,
60977 const void *value, size_t size)
60978 {
60979- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
60980- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
60981+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
60982+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
60983 int count;
60984 struct posix_acl *acl;
60985 struct posix_acl_entry *acl_e;
60986diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
60987index 05c698c..6b918af 100644
60988--- a/fs/xfs/xfs_bmap.c
60989+++ b/fs/xfs/xfs_bmap.c
60990@@ -765,7 +765,7 @@ xfs_bmap_validate_ret(
60991
60992 #else
60993 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
60994-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
60995+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
60996 #endif /* DEBUG */
60997
60998 /*
60999diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
61000index 97676a3..399a75d 100644
61001--- a/fs/xfs/xfs_dir2_sf.c
61002+++ b/fs/xfs/xfs_dir2_sf.c
61003@@ -848,7 +848,12 @@ xfs_dir2_sf_getdents(
61004
61005 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
61006 ctx->pos = off & 0x7fffffff;
61007- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
61008+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
61009+ char name[sfep->namelen];
61010+ memcpy(name, sfep->name, sfep->namelen);
61011+ if (!dir_emit(ctx, name, sfep->namelen, ino, DT_UNKNOWN))
61012+ return 0;
61013+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
61014 ino, DT_UNKNOWN))
61015 return 0;
61016 sfep = xfs_dir2_sf_nextentry(sfp, sfep);
61017diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
61018index 6e2bca5..6ce80d3 100644
61019--- a/fs/xfs/xfs_ioctl.c
61020+++ b/fs/xfs/xfs_ioctl.c
61021@@ -127,7 +127,7 @@ xfs_find_handle(
61022 }
61023
61024 error = -EFAULT;
61025- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
61026+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
61027 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
61028 goto out_put;
61029
61030diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
61031index 96dda62..d6c6a52 100644
61032--- a/fs/xfs/xfs_iops.c
61033+++ b/fs/xfs/xfs_iops.c
61034@@ -395,7 +395,7 @@ xfs_vn_put_link(
61035 struct nameidata *nd,
61036 void *p)
61037 {
61038- char *s = nd_get_link(nd);
61039+ const char *s = nd_get_link(nd);
61040
61041 if (!IS_ERR(s))
61042 kfree(s);
61043diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
61044new file mode 100644
61045index 0000000..0fd7c82
61046--- /dev/null
61047+++ b/grsecurity/Kconfig
61048@@ -0,0 +1,1080 @@
61049+#
61050+# grecurity configuration
61051+#
61052+menu "Memory Protections"
61053+depends on GRKERNSEC
61054+
61055+config GRKERNSEC_KMEM
61056+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
61057+ default y if GRKERNSEC_CONFIG_AUTO
61058+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
61059+ help
61060+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
61061+ be written to or read from to modify or leak the contents of the running
61062+ kernel. /dev/port will also not be allowed to be opened and support
61063+ for /dev/cpu/*/msr will be removed. If you have module
61064+ support disabled, enabling this will close up five ways that are
61065+ currently used to insert malicious code into the running kernel.
61066+
61067+ Even with all these features enabled, we still highly recommend that
61068+ you use the RBAC system, as it is still possible for an attacker to
61069+ modify the running kernel through privileged I/O granted by ioperm/iopl.
61070+
61071+ If you are not using XFree86, you may be able to stop this additional
61072+ case by enabling the 'Disable privileged I/O' option. Though nothing
61073+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
61074+ but only to video memory, which is the only writing we allow in this
61075+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
61076+ not be allowed to mprotect it with PROT_WRITE later.
61077+ Enabling this feature will prevent the "cpupower" and "powertop" tools
61078+ from working.
61079+
61080+ It is highly recommended that you say Y here if you meet all the
61081+ conditions above.
61082+
61083+config GRKERNSEC_VM86
61084+ bool "Restrict VM86 mode"
61085+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61086+ depends on X86_32
61087+
61088+ help
61089+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
61090+ make use of a special execution mode on 32bit x86 processors called
61091+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
61092+ video cards and will still work with this option enabled. The purpose
61093+ of the option is to prevent exploitation of emulation errors in
61094+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
61095+ Nearly all users should be able to enable this option.
61096+
61097+config GRKERNSEC_IO
61098+ bool "Disable privileged I/O"
61099+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61100+ depends on X86
61101+ select RTC_CLASS
61102+ select RTC_INTF_DEV
61103+ select RTC_DRV_CMOS
61104+
61105+ help
61106+ If you say Y here, all ioperm and iopl calls will return an error.
61107+ Ioperm and iopl can be used to modify the running kernel.
61108+ Unfortunately, some programs need this access to operate properly,
61109+ the most notable of which are XFree86 and hwclock. hwclock can be
61110+ remedied by having RTC support in the kernel, so real-time
61111+ clock support is enabled if this option is enabled, to ensure
61112+ that hwclock operates correctly. XFree86 still will not
61113+ operate correctly with this option enabled, so DO NOT CHOOSE Y
61114+ IF YOU USE XFree86. If you use XFree86 and you still want to
61115+ protect your kernel against modification, use the RBAC system.
61116+
61117+config GRKERNSEC_JIT_HARDEN
61118+ bool "Harden BPF JIT against spray attacks"
61119+ default y if GRKERNSEC_CONFIG_AUTO
61120+ depends on BPF_JIT
61121+ help
61122+ If you say Y here, the native code generated by the kernel's Berkeley
61123+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
61124+ attacks that attempt to fit attacker-beneficial instructions in
61125+ 32bit immediate fields of JIT-generated native instructions. The
61126+ attacker will generally aim to cause an unintended instruction sequence
61127+ of JIT-generated native code to execute by jumping into the middle of
61128+ a generated instruction. This feature effectively randomizes the 32bit
61129+ immediate constants present in the generated code to thwart such attacks.
61130+
61131+ If you're using KERNEXEC, it's recommended that you enable this option
61132+ to supplement the hardening of the kernel.
61133+
61134+config GRKERNSEC_PERF_HARDEN
61135+ bool "Disable unprivileged PERF_EVENTS usage by default"
61136+ default y if GRKERNSEC_CONFIG_AUTO
61137+ depends on PERF_EVENTS
61138+ help
61139+ If you say Y here, the range of acceptable values for the
61140+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
61141+ default to a new value: 3. When the sysctl is set to this value, no
61142+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
61143+
61144+ Though PERF_EVENTS can be used legitimately for performance monitoring
61145+ and low-level application profiling, it is forced on regardless of
61146+ configuration, has been at fault for several vulnerabilities, and
61147+ creates new opportunities for side channels and other information leaks.
61148+
61149+ This feature puts PERF_EVENTS into a secure default state and permits
61150+ the administrator to change out of it temporarily if unprivileged
61151+ application profiling is needed.
61152+
61153+config GRKERNSEC_RAND_THREADSTACK
61154+ bool "Insert random gaps between thread stacks"
61155+ default y if GRKERNSEC_CONFIG_AUTO
61156+ depends on PAX_RANDMMAP && !PPC
61157+ help
61158+ If you say Y here, a random-sized gap will be enforced between allocated
61159+ thread stacks. Glibc's NPTL and other threading libraries that
61160+ pass MAP_STACK to the kernel for thread stack allocation are supported.
61161+ The implementation currently provides 8 bits of entropy for the gap.
61162+
61163+ Many distributions do not compile threaded remote services with the
61164+ -fstack-check argument to GCC, causing the variable-sized stack-based
61165+ allocator, alloca(), to not probe the stack on allocation. This
61166+ permits an unbounded alloca() to skip over any guard page and potentially
61167+ modify another thread's stack reliably. An enforced random gap
61168+ reduces the reliability of such an attack and increases the chance
61169+ that such a read/write to another thread's stack instead lands in
61170+ an unmapped area, causing a crash and triggering grsecurity's
61171+ anti-bruteforcing logic.
61172+
61173+config GRKERNSEC_PROC_MEMMAP
61174+ bool "Harden ASLR against information leaks and entropy reduction"
61175+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
61176+ depends on PAX_NOEXEC || PAX_ASLR
61177+ help
61178+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
61179+ give no information about the addresses of its mappings if
61180+ PaX features that rely on random addresses are enabled on the task.
61181+ In addition to sanitizing this information and disabling other
61182+ dangerous sources of information, this option causes reads of sensitive
61183+ /proc/<pid> entries where the file descriptor was opened in a different
61184+ task than the one performing the read. Such attempts are logged.
61185+ This option also limits argv/env strings for suid/sgid binaries
61186+ to 512KB to prevent a complete exhaustion of the stack entropy provided
61187+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
61188+ binaries to prevent alternative mmap layouts from being abused.
61189+
61190+ If you use PaX it is essential that you say Y here as it closes up
61191+ several holes that make full ASLR useless locally.
61192+
61193+config GRKERNSEC_BRUTE
61194+ bool "Deter exploit bruteforcing"
61195+ default y if GRKERNSEC_CONFIG_AUTO
61196+ help
61197+ If you say Y here, attempts to bruteforce exploits against forking
61198+ daemons such as apache or sshd, as well as against suid/sgid binaries
61199+ will be deterred. When a child of a forking daemon is killed by PaX
61200+ or crashes due to an illegal instruction or other suspicious signal,
61201+ the parent process will be delayed 30 seconds upon every subsequent
61202+ fork until the administrator is able to assess the situation and
61203+ restart the daemon.
61204+ In the suid/sgid case, the attempt is logged, the user has all their
61205+ existing instances of the suid/sgid binary terminated and will
61206+ be unable to execute any suid/sgid binaries for 15 minutes.
61207+
61208+ It is recommended that you also enable signal logging in the auditing
61209+ section so that logs are generated when a process triggers a suspicious
61210+ signal.
61211+ If the sysctl option is enabled, a sysctl option with name
61212+ "deter_bruteforce" is created.
61213+
61214+
61215+config GRKERNSEC_MODHARDEN
61216+ bool "Harden module auto-loading"
61217+ default y if GRKERNSEC_CONFIG_AUTO
61218+ depends on MODULES
61219+ help
61220+ If you say Y here, module auto-loading in response to use of some
61221+ feature implemented by an unloaded module will be restricted to
61222+ root users. Enabling this option helps defend against attacks
61223+ by unprivileged users who abuse the auto-loading behavior to
61224+ cause a vulnerable module to load that is then exploited.
61225+
61226+ If this option prevents a legitimate use of auto-loading for a
61227+ non-root user, the administrator can execute modprobe manually
61228+ with the exact name of the module mentioned in the alert log.
61229+ Alternatively, the administrator can add the module to the list
61230+ of modules loaded at boot by modifying init scripts.
61231+
61232+ Modification of init scripts will most likely be needed on
61233+ Ubuntu servers with encrypted home directory support enabled,
61234+ as the first non-root user logging in will cause the ecb(aes),
61235+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
61236+
61237+config GRKERNSEC_HIDESYM
61238+ bool "Hide kernel symbols"
61239+ default y if GRKERNSEC_CONFIG_AUTO
61240+ select PAX_USERCOPY_SLABS
61241+ help
61242+ If you say Y here, getting information on loaded modules, and
61243+ displaying all kernel symbols through a syscall will be restricted
61244+ to users with CAP_SYS_MODULE. For software compatibility reasons,
61245+ /proc/kallsyms will be restricted to the root user. The RBAC
61246+ system can hide that entry even from root.
61247+
61248+ This option also prevents leaking of kernel addresses through
61249+ several /proc entries.
61250+
61251+ Note that this option is only effective provided the following
61252+ conditions are met:
61253+ 1) The kernel using grsecurity is not precompiled by some distribution
61254+ 2) You have also enabled GRKERNSEC_DMESG
61255+ 3) You are using the RBAC system and hiding other files such as your
61256+ kernel image and System.map. Alternatively, enabling this option
61257+ causes the permissions on /boot, /lib/modules, and the kernel
61258+ source directory to change at compile time to prevent
61259+ reading by non-root users.
61260+ If the above conditions are met, this option will aid in providing a
61261+ useful protection against local kernel exploitation of overflows
61262+ and arbitrary read/write vulnerabilities.
61263+
61264+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
61265+ in addition to this feature.
61266+
61267+config GRKERNSEC_KERN_LOCKOUT
61268+ bool "Active kernel exploit response"
61269+ default y if GRKERNSEC_CONFIG_AUTO
61270+ depends on X86 || ARM || PPC || SPARC
61271+ help
61272+ If you say Y here, when a PaX alert is triggered due to suspicious
61273+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
61274+ or an OOPS occurs due to bad memory accesses, instead of just
61275+ terminating the offending process (and potentially allowing
61276+ a subsequent exploit from the same user), we will take one of two
61277+ actions:
61278+ If the user was root, we will panic the system
61279+ If the user was non-root, we will log the attempt, terminate
61280+ all processes owned by the user, then prevent them from creating
61281+ any new processes until the system is restarted
61282+ This deters repeated kernel exploitation/bruteforcing attempts
61283+ and is useful for later forensics.
61284+
61285+endmenu
61286+menu "Role Based Access Control Options"
61287+depends on GRKERNSEC
61288+
61289+config GRKERNSEC_RBAC_DEBUG
61290+ bool
61291+
61292+config GRKERNSEC_NO_RBAC
61293+ bool "Disable RBAC system"
61294+ help
61295+ If you say Y here, the /dev/grsec device will be removed from the kernel,
61296+ preventing the RBAC system from being enabled. You should only say Y
61297+ here if you have no intention of using the RBAC system, so as to prevent
61298+ an attacker with root access from misusing the RBAC system to hide files
61299+ and processes when loadable module support and /dev/[k]mem have been
61300+ locked down.
61301+
61302+config GRKERNSEC_ACL_HIDEKERN
61303+ bool "Hide kernel processes"
61304+ help
61305+ If you say Y here, all kernel threads will be hidden to all
61306+ processes but those whose subject has the "view hidden processes"
61307+ flag.
61308+
61309+config GRKERNSEC_ACL_MAXTRIES
61310+ int "Maximum tries before password lockout"
61311+ default 3
61312+ help
61313+ This option enforces the maximum number of times a user can attempt
61314+ to authorize themselves with the grsecurity RBAC system before being
61315+ denied the ability to attempt authorization again for a specified time.
61316+ The lower the number, the harder it will be to brute-force a password.
61317+
61318+config GRKERNSEC_ACL_TIMEOUT
61319+ int "Time to wait after max password tries, in seconds"
61320+ default 30
61321+ help
61322+ This option specifies the time the user must wait after attempting to
61323+ authorize to the RBAC system with the maximum number of invalid
61324+ passwords. The higher the number, the harder it will be to brute-force
61325+ a password.
61326+
61327+endmenu
61328+menu "Filesystem Protections"
61329+depends on GRKERNSEC
61330+
61331+config GRKERNSEC_PROC
61332+ bool "Proc restrictions"
61333+ default y if GRKERNSEC_CONFIG_AUTO
61334+ help
61335+ If you say Y here, the permissions of the /proc filesystem
61336+ will be altered to enhance system security and privacy. You MUST
61337+ choose either a user only restriction or a user and group restriction.
61338+ Depending upon the option you choose, you can either restrict users to
61339+ see only the processes they themselves run, or choose a group that can
61340+ view all processes and files normally restricted to root if you choose
61341+ the "restrict to user only" option. NOTE: If you're running identd or
61342+ ntpd as a non-root user, you will have to run it as the group you
61343+ specify here.
61344+
61345+config GRKERNSEC_PROC_USER
61346+ bool "Restrict /proc to user only"
61347+ depends on GRKERNSEC_PROC
61348+ help
61349+ If you say Y here, non-root users will only be able to view their own
61350+ processes, and restricts them from viewing network-related information,
61351+ and viewing kernel symbol and module information.
61352+
61353+config GRKERNSEC_PROC_USERGROUP
61354+ bool "Allow special group"
61355+ default y if GRKERNSEC_CONFIG_AUTO
61356+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
61357+ help
61358+ If you say Y here, you will be able to select a group that will be
61359+ able to view all processes and network-related information. If you've
61360+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
61361+ remain hidden. This option is useful if you want to run identd as
61362+ a non-root user. The group you select may also be chosen at boot time
61363+ via "grsec_proc_gid=" on the kernel commandline.
61364+
61365+config GRKERNSEC_PROC_GID
61366+ int "GID for special group"
61367+ depends on GRKERNSEC_PROC_USERGROUP
61368+ default 1001
61369+
61370+config GRKERNSEC_PROC_ADD
61371+ bool "Additional restrictions"
61372+ default y if GRKERNSEC_CONFIG_AUTO
61373+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
61374+ help
61375+ If you say Y here, additional restrictions will be placed on
61376+ /proc that keep normal users from viewing device information and
61377+ slabinfo information that could be useful for exploits.
61378+
61379+config GRKERNSEC_LINK
61380+ bool "Linking restrictions"
61381+ default y if GRKERNSEC_CONFIG_AUTO
61382+ help
61383+ If you say Y here, /tmp race exploits will be prevented, since users
61384+ will no longer be able to follow symlinks owned by other users in
61385+ world-writable +t directories (e.g. /tmp), unless the owner of the
61386+ symlink is the owner of the directory. users will also not be
61387+ able to hardlink to files they do not own. If the sysctl option is
61388+ enabled, a sysctl option with name "linking_restrictions" is created.
61389+
61390+config GRKERNSEC_SYMLINKOWN
61391+ bool "Kernel-enforced SymlinksIfOwnerMatch"
61392+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61393+ help
61394+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
61395+ that prevents it from being used as a security feature. As Apache
61396+ verifies the symlink by performing a stat() against the target of
61397+ the symlink before it is followed, an attacker can setup a symlink
61398+ to point to a same-owned file, then replace the symlink with one
61399+ that targets another user's file just after Apache "validates" the
61400+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
61401+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
61402+ will be in place for the group you specify. If the sysctl option
61403+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
61404+ created.
61405+
61406+config GRKERNSEC_SYMLINKOWN_GID
61407+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
61408+ depends on GRKERNSEC_SYMLINKOWN
61409+ default 1006
61410+ help
61411+ Setting this GID determines what group kernel-enforced
61412+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
61413+ is enabled, a sysctl option with name "symlinkown_gid" is created.
61414+
61415+config GRKERNSEC_FIFO
61416+ bool "FIFO restrictions"
61417+ default y if GRKERNSEC_CONFIG_AUTO
61418+ help
61419+ If you say Y here, users will not be able to write to FIFOs they don't
61420+ own in world-writable +t directories (e.g. /tmp), unless the owner of
61421+ the FIFO is the same owner of the directory it's held in. If the sysctl
61422+ option is enabled, a sysctl option with name "fifo_restrictions" is
61423+ created.
61424+
61425+config GRKERNSEC_SYSFS_RESTRICT
61426+ bool "Sysfs/debugfs restriction"
61427+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61428+ depends on SYSFS
61429+ help
61430+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
61431+ any filesystem normally mounted under it (e.g. debugfs) will be
61432+ mostly accessible only by root. These filesystems generally provide access
61433+ to hardware and debug information that isn't appropriate for unprivileged
61434+ users of the system. Sysfs and debugfs have also become a large source
61435+ of new vulnerabilities, ranging from infoleaks to local compromise.
61436+ There has been very little oversight with an eye toward security involved
61437+ in adding new exporters of information to these filesystems, so their
61438+ use is discouraged.
61439+ For reasons of compatibility, a few directories have been whitelisted
61440+ for access by non-root users:
61441+ /sys/fs/selinux
61442+ /sys/fs/fuse
61443+ /sys/devices/system/cpu
61444+
61445+config GRKERNSEC_ROFS
61446+ bool "Runtime read-only mount protection"
61447+ depends on SYSCTL
61448+ help
61449+ If you say Y here, a sysctl option with name "romount_protect" will
61450+ be created. By setting this option to 1 at runtime, filesystems
61451+ will be protected in the following ways:
61452+ * No new writable mounts will be allowed
61453+ * Existing read-only mounts won't be able to be remounted read/write
61454+ * Write operations will be denied on all block devices
61455+ This option acts independently of grsec_lock: once it is set to 1,
61456+ it cannot be turned off. Therefore, please be mindful of the resulting
61457+ behavior if this option is enabled in an init script on a read-only
61458+ filesystem. This feature is mainly intended for secure embedded systems.
61459+
61460+config GRKERNSEC_DEVICE_SIDECHANNEL
61461+ bool "Eliminate stat/notify-based device sidechannels"
61462+ default y if GRKERNSEC_CONFIG_AUTO
61463+ help
61464+ If you say Y here, timing analyses on block or character
61465+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
61466+ will be thwarted for unprivileged users. If a process without
61467+ CAP_MKNOD stats such a device, the last access and last modify times
61468+ will match the device's create time. No access or modify events
61469+ will be triggered through inotify/dnotify/fanotify for such devices.
61470+ This feature will prevent attacks that may at a minimum
61471+ allow an attacker to determine the administrator's password length.
61472+
61473+config GRKERNSEC_CHROOT
61474+ bool "Chroot jail restrictions"
61475+ default y if GRKERNSEC_CONFIG_AUTO
61476+ help
61477+ If you say Y here, you will be able to choose several options that will
61478+ make breaking out of a chrooted jail much more difficult. If you
61479+ encounter no software incompatibilities with the following options, it
61480+ is recommended that you enable each one.
61481+
61482+config GRKERNSEC_CHROOT_MOUNT
61483+ bool "Deny mounts"
61484+ default y if GRKERNSEC_CONFIG_AUTO
61485+ depends on GRKERNSEC_CHROOT
61486+ help
61487+ If you say Y here, processes inside a chroot will not be able to
61488+ mount or remount filesystems. If the sysctl option is enabled, a
61489+ sysctl option with name "chroot_deny_mount" is created.
61490+
61491+config GRKERNSEC_CHROOT_DOUBLE
61492+ bool "Deny double-chroots"
61493+ default y if GRKERNSEC_CONFIG_AUTO
61494+ depends on GRKERNSEC_CHROOT
61495+ help
61496+ If you say Y here, processes inside a chroot will not be able to chroot
61497+ again outside the chroot. This is a widely used method of breaking
61498+ out of a chroot jail and should not be allowed. If the sysctl
61499+ option is enabled, a sysctl option with name
61500+ "chroot_deny_chroot" is created.
61501+
61502+config GRKERNSEC_CHROOT_PIVOT
61503+ bool "Deny pivot_root in chroot"
61504+ default y if GRKERNSEC_CONFIG_AUTO
61505+ depends on GRKERNSEC_CHROOT
61506+ help
61507+ If you say Y here, processes inside a chroot will not be able to use
61508+ a function called pivot_root() that was introduced in Linux 2.3.41. It
61509+ works similar to chroot in that it changes the root filesystem. This
61510+ function could be misused in a chrooted process to attempt to break out
61511+ of the chroot, and therefore should not be allowed. If the sysctl
61512+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
61513+ created.
61514+
61515+config GRKERNSEC_CHROOT_CHDIR
61516+ bool "Enforce chdir(\"/\") on all chroots"
61517+ default y if GRKERNSEC_CONFIG_AUTO
61518+ depends on GRKERNSEC_CHROOT
61519+ help
61520+ If you say Y here, the current working directory of all newly-chrooted
61521+ applications will be set to the the root directory of the chroot.
61522+ The man page on chroot(2) states:
61523+ Note that this call does not change the current working
61524+ directory, so that `.' can be outside the tree rooted at
61525+ `/'. In particular, the super-user can escape from a
61526+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
61527+
61528+ It is recommended that you say Y here, since it's not known to break
61529+ any software. If the sysctl option is enabled, a sysctl option with
61530+ name "chroot_enforce_chdir" is created.
61531+
61532+config GRKERNSEC_CHROOT_CHMOD
61533+ bool "Deny (f)chmod +s"
61534+ default y if GRKERNSEC_CONFIG_AUTO
61535+ depends on GRKERNSEC_CHROOT
61536+ help
61537+ If you say Y here, processes inside a chroot will not be able to chmod
61538+ or fchmod files to make them have suid or sgid bits. This protects
61539+ against another published method of breaking a chroot. If the sysctl
61540+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
61541+ created.
61542+
61543+config GRKERNSEC_CHROOT_FCHDIR
61544+ bool "Deny fchdir out of chroot"
61545+ default y if GRKERNSEC_CONFIG_AUTO
61546+ depends on GRKERNSEC_CHROOT
61547+ help
61548+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
61549+ to a file descriptor of the chrooting process that points to a directory
61550+ outside the filesystem will be stopped. If the sysctl option
61551+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
61552+
61553+config GRKERNSEC_CHROOT_MKNOD
61554+ bool "Deny mknod"
61555+ default y if GRKERNSEC_CONFIG_AUTO
61556+ depends on GRKERNSEC_CHROOT
61557+ help
61558+ If you say Y here, processes inside a chroot will not be allowed to
61559+ mknod. The problem with using mknod inside a chroot is that it
61560+ would allow an attacker to create a device entry that is the same
61561+ as one on the physical root of your system, which could range from
61562+ anything from the console device to a device for your harddrive (which
61563+ they could then use to wipe the drive or steal data). It is recommended
61564+ that you say Y here, unless you run into software incompatibilities.
61565+ If the sysctl option is enabled, a sysctl option with name
61566+ "chroot_deny_mknod" is created.
61567+
61568+config GRKERNSEC_CHROOT_SHMAT
61569+ bool "Deny shmat() out of chroot"
61570+ default y if GRKERNSEC_CONFIG_AUTO
61571+ depends on GRKERNSEC_CHROOT
61572+ help
61573+ If you say Y here, processes inside a chroot will not be able to attach
61574+ to shared memory segments that were created outside of the chroot jail.
61575+ It is recommended that you say Y here. If the sysctl option is enabled,
61576+ a sysctl option with name "chroot_deny_shmat" is created.
61577+
61578+config GRKERNSEC_CHROOT_UNIX
61579+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
61580+ default y if GRKERNSEC_CONFIG_AUTO
61581+ depends on GRKERNSEC_CHROOT
61582+ help
61583+ If you say Y here, processes inside a chroot will not be able to
61584+ connect to abstract (meaning not belonging to a filesystem) Unix
61585+ domain sockets that were bound outside of a chroot. It is recommended
61586+ that you say Y here. If the sysctl option is enabled, a sysctl option
61587+ with name "chroot_deny_unix" is created.
61588+
61589+config GRKERNSEC_CHROOT_FINDTASK
61590+ bool "Protect outside processes"
61591+ default y if GRKERNSEC_CONFIG_AUTO
61592+ depends on GRKERNSEC_CHROOT
61593+ help
61594+ If you say Y here, processes inside a chroot will not be able to
61595+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
61596+ getsid, or view any process outside of the chroot. If the sysctl
61597+ option is enabled, a sysctl option with name "chroot_findtask" is
61598+ created.
61599+
61600+config GRKERNSEC_CHROOT_NICE
61601+ bool "Restrict priority changes"
61602+ default y if GRKERNSEC_CONFIG_AUTO
61603+ depends on GRKERNSEC_CHROOT
61604+ help
61605+ If you say Y here, processes inside a chroot will not be able to raise
61606+ the priority of processes in the chroot, or alter the priority of
61607+ processes outside the chroot. This provides more security than simply
61608+ removing CAP_SYS_NICE from the process' capability set. If the
61609+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
61610+ is created.
61611+
61612+config GRKERNSEC_CHROOT_SYSCTL
61613+ bool "Deny sysctl writes"
61614+ default y if GRKERNSEC_CONFIG_AUTO
61615+ depends on GRKERNSEC_CHROOT
61616+ help
61617+ If you say Y here, an attacker in a chroot will not be able to
61618+ write to sysctl entries, either by sysctl(2) or through a /proc
61619+ interface. It is strongly recommended that you say Y here. If the
61620+ sysctl option is enabled, a sysctl option with name
61621+ "chroot_deny_sysctl" is created.
61622+
61623+config GRKERNSEC_CHROOT_CAPS
61624+ bool "Capability restrictions"
61625+ default y if GRKERNSEC_CONFIG_AUTO
61626+ depends on GRKERNSEC_CHROOT
61627+ help
61628+ If you say Y here, the capabilities on all processes within a
61629+ chroot jail will be lowered to stop module insertion, raw i/o,
61630+ system and net admin tasks, rebooting the system, modifying immutable
61631+ files, modifying IPC owned by another, and changing the system time.
61632+ This is left an option because it can break some apps. Disable this
61633+ if your chrooted apps are having problems performing those kinds of
61634+ tasks. If the sysctl option is enabled, a sysctl option with
61635+ name "chroot_caps" is created.
61636+
61637+config GRKERNSEC_CHROOT_INITRD
61638+ bool "Exempt initrd tasks from restrictions"
61639+ default y if GRKERNSEC_CONFIG_AUTO
61640+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
61641+ help
61642+ If you say Y here, tasks started prior to init will be exempted from
61643+ grsecurity's chroot restrictions. This option is mainly meant to
61644+ resolve Plymouth's performing privileged operations unnecessarily
61645+ in a chroot.
61646+
61647+endmenu
61648+menu "Kernel Auditing"
61649+depends on GRKERNSEC
61650+
61651+config GRKERNSEC_AUDIT_GROUP
61652+ bool "Single group for auditing"
61653+ help
61654+ If you say Y here, the exec and chdir logging features will only operate
61655+ on a group you specify. This option is recommended if you only want to
61656+ watch certain users instead of having a large amount of logs from the
61657+ entire system. If the sysctl option is enabled, a sysctl option with
61658+ name "audit_group" is created.
61659+
61660+config GRKERNSEC_AUDIT_GID
61661+ int "GID for auditing"
61662+ depends on GRKERNSEC_AUDIT_GROUP
61663+ default 1007
61664+
61665+config GRKERNSEC_EXECLOG
61666+ bool "Exec logging"
61667+ help
61668+ If you say Y here, all execve() calls will be logged (since the
61669+ other exec*() calls are frontends to execve(), all execution
61670+ will be logged). Useful for shell-servers that like to keep track
61671+ of their users. If the sysctl option is enabled, a sysctl option with
61672+ name "exec_logging" is created.
61673+ WARNING: This option when enabled will produce a LOT of logs, especially
61674+ on an active system.
61675+
61676+config GRKERNSEC_RESLOG
61677+ bool "Resource logging"
61678+ default y if GRKERNSEC_CONFIG_AUTO
61679+ help
61680+ If you say Y here, all attempts to overstep resource limits will
61681+ be logged with the resource name, the requested size, and the current
61682+ limit. It is highly recommended that you say Y here. If the sysctl
61683+ option is enabled, a sysctl option with name "resource_logging" is
61684+ created. If the RBAC system is enabled, the sysctl value is ignored.
61685+
61686+config GRKERNSEC_CHROOT_EXECLOG
61687+ bool "Log execs within chroot"
61688+ help
61689+ If you say Y here, all executions inside a chroot jail will be logged
61690+ to syslog. This can cause a large amount of logs if certain
61691+ applications (eg. djb's daemontools) are installed on the system, and
61692+ is therefore left as an option. If the sysctl option is enabled, a
61693+ sysctl option with name "chroot_execlog" is created.
61694+
61695+config GRKERNSEC_AUDIT_PTRACE
61696+ bool "Ptrace logging"
61697+ help
61698+ If you say Y here, all attempts to attach to a process via ptrace
61699+ will be logged. If the sysctl option is enabled, a sysctl option
61700+ with name "audit_ptrace" is created.
61701+
61702+config GRKERNSEC_AUDIT_CHDIR
61703+ bool "Chdir logging"
61704+ help
61705+ If you say Y here, all chdir() calls will be logged. If the sysctl
61706+ option is enabled, a sysctl option with name "audit_chdir" is created.
61707+
61708+config GRKERNSEC_AUDIT_MOUNT
61709+ bool "(Un)Mount logging"
61710+ help
61711+ If you say Y here, all mounts and unmounts will be logged. If the
61712+ sysctl option is enabled, a sysctl option with name "audit_mount" is
61713+ created.
61714+
61715+config GRKERNSEC_SIGNAL
61716+ bool "Signal logging"
61717+ default y if GRKERNSEC_CONFIG_AUTO
61718+ help
61719+ If you say Y here, certain important signals will be logged, such as
61720+ SIGSEGV, which will as a result inform you of when a error in a program
61721+ occurred, which in some cases could mean a possible exploit attempt.
61722+ If the sysctl option is enabled, a sysctl option with name
61723+ "signal_logging" is created.
61724+
61725+config GRKERNSEC_FORKFAIL
61726+ bool "Fork failure logging"
61727+ help
61728+ If you say Y here, all failed fork() attempts will be logged.
61729+ This could suggest a fork bomb, or someone attempting to overstep
61730+ their process limit. If the sysctl option is enabled, a sysctl option
61731+ with name "forkfail_logging" is created.
61732+
61733+config GRKERNSEC_TIME
61734+ bool "Time change logging"
61735+ default y if GRKERNSEC_CONFIG_AUTO
61736+ help
61737+ If you say Y here, any changes of the system clock will be logged.
61738+ If the sysctl option is enabled, a sysctl option with name
61739+ "timechange_logging" is created.
61740+
61741+config GRKERNSEC_PROC_IPADDR
61742+ bool "/proc/<pid>/ipaddr support"
61743+ default y if GRKERNSEC_CONFIG_AUTO
61744+ help
61745+ If you say Y here, a new entry will be added to each /proc/<pid>
61746+ directory that contains the IP address of the person using the task.
61747+ The IP is carried across local TCP and AF_UNIX stream sockets.
61748+ This information can be useful for IDS/IPSes to perform remote response
61749+ to a local attack. The entry is readable by only the owner of the
61750+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
61751+ the RBAC system), and thus does not create privacy concerns.
61752+
61753+config GRKERNSEC_RWXMAP_LOG
61754+ bool 'Denied RWX mmap/mprotect logging'
61755+ default y if GRKERNSEC_CONFIG_AUTO
61756+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
61757+ help
61758+ If you say Y here, calls to mmap() and mprotect() with explicit
61759+ usage of PROT_WRITE and PROT_EXEC together will be logged when
61760+ denied by the PAX_MPROTECT feature. This feature will also
61761+ log other problematic scenarios that can occur when PAX_MPROTECT
61762+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
61763+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
61764+ is created.
61765+
61766+endmenu
61767+
61768+menu "Executable Protections"
61769+depends on GRKERNSEC
61770+
61771+config GRKERNSEC_DMESG
61772+ bool "Dmesg(8) restriction"
61773+ default y if GRKERNSEC_CONFIG_AUTO
61774+ help
61775+ If you say Y here, non-root users will not be able to use dmesg(8)
61776+ to view the contents of the kernel's circular log buffer.
61777+ The kernel's log buffer often contains kernel addresses and other
61778+ identifying information useful to an attacker in fingerprinting a
61779+ system for a targeted exploit.
61780+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
61781+ created.
61782+
61783+config GRKERNSEC_HARDEN_PTRACE
61784+ bool "Deter ptrace-based process snooping"
61785+ default y if GRKERNSEC_CONFIG_AUTO
61786+ help
61787+ If you say Y here, TTY sniffers and other malicious monitoring
61788+ programs implemented through ptrace will be defeated. If you
61789+ have been using the RBAC system, this option has already been
61790+ enabled for several years for all users, with the ability to make
61791+ fine-grained exceptions.
61792+
61793+ This option only affects the ability of non-root users to ptrace
61794+ processes that are not a descendent of the ptracing process.
61795+ This means that strace ./binary and gdb ./binary will still work,
61796+ but attaching to arbitrary processes will not. If the sysctl
61797+ option is enabled, a sysctl option with name "harden_ptrace" is
61798+ created.
61799+
61800+config GRKERNSEC_PTRACE_READEXEC
61801+ bool "Require read access to ptrace sensitive binaries"
61802+ default y if GRKERNSEC_CONFIG_AUTO
61803+ help
61804+ If you say Y here, unprivileged users will not be able to ptrace unreadable
61805+ binaries. This option is useful in environments that
61806+ remove the read bits (e.g. file mode 4711) from suid binaries to
61807+ prevent infoleaking of their contents. This option adds
61808+ consistency to the use of that file mode, as the binary could normally
61809+ be read out when run without privileges while ptracing.
61810+
61811+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
61812+ is created.
61813+
61814+config GRKERNSEC_SETXID
61815+ bool "Enforce consistent multithreaded privileges"
61816+ default y if GRKERNSEC_CONFIG_AUTO
61817+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
61818+ help
61819+ If you say Y here, a change from a root uid to a non-root uid
61820+ in a multithreaded application will cause the resulting uids,
61821+ gids, supplementary groups, and capabilities in that thread
61822+ to be propagated to the other threads of the process. In most
61823+ cases this is unnecessary, as glibc will emulate this behavior
61824+ on behalf of the application. Other libcs do not act in the
61825+ same way, allowing the other threads of the process to continue
61826+ running with root privileges. If the sysctl option is enabled,
61827+ a sysctl option with name "consistent_setxid" is created.
61828+
61829+config GRKERNSEC_TPE
61830+ bool "Trusted Path Execution (TPE)"
61831+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61832+ help
61833+ If you say Y here, you will be able to choose a gid to add to the
61834+ supplementary groups of users you want to mark as "untrusted."
61835+ These users will not be able to execute any files that are not in
61836+ root-owned directories writable only by root. If the sysctl option
61837+ is enabled, a sysctl option with name "tpe" is created.
61838+
61839+config GRKERNSEC_TPE_ALL
61840+ bool "Partially restrict all non-root users"
61841+ depends on GRKERNSEC_TPE
61842+ help
61843+ If you say Y here, all non-root users will be covered under
61844+ a weaker TPE restriction. This is separate from, and in addition to,
61845+ the main TPE options that you have selected elsewhere. Thus, if a
61846+ "trusted" GID is chosen, this restriction applies to even that GID.
61847+ Under this restriction, all non-root users will only be allowed to
61848+ execute files in directories they own that are not group or
61849+ world-writable, or in directories owned by root and writable only by
61850+ root. If the sysctl option is enabled, a sysctl option with name
61851+ "tpe_restrict_all" is created.
61852+
61853+config GRKERNSEC_TPE_INVERT
61854+ bool "Invert GID option"
61855+ depends on GRKERNSEC_TPE
61856+ help
61857+ If you say Y here, the group you specify in the TPE configuration will
61858+ decide what group TPE restrictions will be *disabled* for. This
61859+ option is useful if you want TPE restrictions to be applied to most
61860+ users on the system. If the sysctl option is enabled, a sysctl option
61861+ with name "tpe_invert" is created. Unlike other sysctl options, this
61862+ entry will default to on for backward-compatibility.
61863+
61864+config GRKERNSEC_TPE_GID
61865+ int
61866+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
61867+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
61868+
61869+config GRKERNSEC_TPE_UNTRUSTED_GID
61870+ int "GID for TPE-untrusted users"
61871+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
61872+ default 1005
61873+ help
61874+ Setting this GID determines what group TPE restrictions will be
61875+ *enabled* for. If the sysctl option is enabled, a sysctl option
61876+ with name "tpe_gid" is created.
61877+
61878+config GRKERNSEC_TPE_TRUSTED_GID
61879+ int "GID for TPE-trusted users"
61880+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
61881+ default 1005
61882+ help
61883+ Setting this GID determines what group TPE restrictions will be
61884+ *disabled* for. If the sysctl option is enabled, a sysctl option
61885+ with name "tpe_gid" is created.
61886+
61887+endmenu
61888+menu "Network Protections"
61889+depends on GRKERNSEC
61890+
61891+config GRKERNSEC_RANDNET
61892+ bool "Larger entropy pools"
61893+ default y if GRKERNSEC_CONFIG_AUTO
61894+ help
61895+ If you say Y here, the entropy pools used for many features of Linux
61896+ and grsecurity will be doubled in size. Since several grsecurity
61897+ features use additional randomness, it is recommended that you say Y
61898+ here. Saying Y here has a similar effect as modifying
61899+ /proc/sys/kernel/random/poolsize.
61900+
61901+config GRKERNSEC_BLACKHOLE
61902+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
61903+ default y if GRKERNSEC_CONFIG_AUTO
61904+ depends on NET
61905+ help
61906+ If you say Y here, neither TCP resets nor ICMP
61907+ destination-unreachable packets will be sent in response to packets
61908+ sent to ports for which no associated listening process exists.
61909+ This feature supports both IPV4 and IPV6 and exempts the
61910+ loopback interface from blackholing. Enabling this feature
61911+ makes a host more resilient to DoS attacks and reduces network
61912+ visibility against scanners.
61913+
61914+ The blackhole feature as-implemented is equivalent to the FreeBSD
61915+ blackhole feature, as it prevents RST responses to all packets, not
61916+ just SYNs. Under most application behavior this causes no
61917+ problems, but applications (like haproxy) may not close certain
61918+ connections in a way that cleanly terminates them on the remote
61919+ end, leaving the remote host in LAST_ACK state. Because of this
61920+ side-effect and to prevent intentional LAST_ACK DoSes, this
61921+ feature also adds automatic mitigation against such attacks.
61922+ The mitigation drastically reduces the amount of time a socket
61923+ can spend in LAST_ACK state. If you're using haproxy and not
61924+ all servers it connects to have this option enabled, consider
61925+ disabling this feature on the haproxy host.
61926+
61927+ If the sysctl option is enabled, two sysctl options with names
61928+ "ip_blackhole" and "lastack_retries" will be created.
61929+ While "ip_blackhole" takes the standard zero/non-zero on/off
61930+ toggle, "lastack_retries" uses the same kinds of values as
61931+ "tcp_retries1" and "tcp_retries2". The default value of 4
61932+ prevents a socket from lasting more than 45 seconds in LAST_ACK
61933+ state.
61934+
61935+config GRKERNSEC_NO_SIMULT_CONNECT
61936+ bool "Disable TCP Simultaneous Connect"
61937+ default y if GRKERNSEC_CONFIG_AUTO
61938+ depends on NET
61939+ help
61940+ If you say Y here, a feature by Willy Tarreau will be enabled that
61941+ removes a weakness in Linux's strict implementation of TCP that
61942+ allows two clients to connect to each other without either entering
61943+ a listening state. The weakness allows an attacker to easily prevent
61944+ a client from connecting to a known server provided the source port
61945+ for the connection is guessed correctly.
61946+
61947+ As the weakness could be used to prevent an antivirus or IPS from
61948+ fetching updates, or prevent an SSL gateway from fetching a CRL,
61949+ it should be eliminated by enabling this option. Though Linux is
61950+ one of few operating systems supporting simultaneous connect, it
61951+ has no legitimate use in practice and is rarely supported by firewalls.
61952+
61953+config GRKERNSEC_SOCKET
61954+ bool "Socket restrictions"
61955+ depends on NET
61956+ help
61957+ If you say Y here, you will be able to choose from several options.
61958+ If you assign a GID on your system and add it to the supplementary
61959+ groups of users you want to restrict socket access to, this patch
61960+ will perform up to three things, based on the option(s) you choose.
61961+
61962+config GRKERNSEC_SOCKET_ALL
61963+ bool "Deny any sockets to group"
61964+ depends on GRKERNSEC_SOCKET
61965+ help
61966+ If you say Y here, you will be able to choose a GID of whose users will
61967+ be unable to connect to other hosts from your machine or run server
61968+ applications from your machine. If the sysctl option is enabled, a
61969+ sysctl option with name "socket_all" is created.
61970+
61971+config GRKERNSEC_SOCKET_ALL_GID
61972+ int "GID to deny all sockets for"
61973+ depends on GRKERNSEC_SOCKET_ALL
61974+ default 1004
61975+ help
61976+ Here you can choose the GID to disable socket access for. Remember to
61977+ add the users you want socket access disabled for to the GID
61978+ specified here. If the sysctl option is enabled, a sysctl option
61979+ with name "socket_all_gid" is created.
61980+
61981+config GRKERNSEC_SOCKET_CLIENT
61982+ bool "Deny client sockets to group"
61983+ depends on GRKERNSEC_SOCKET
61984+ help
61985+ If you say Y here, you will be able to choose a GID of whose users will
61986+ be unable to connect to other hosts from your machine, but will be
61987+ able to run servers. If this option is enabled, all users in the group
61988+ you specify will have to use passive mode when initiating ftp transfers
61989+ from the shell on your machine. If the sysctl option is enabled, a
61990+ sysctl option with name "socket_client" is created.
61991+
61992+config GRKERNSEC_SOCKET_CLIENT_GID
61993+ int "GID to deny client sockets for"
61994+ depends on GRKERNSEC_SOCKET_CLIENT
61995+ default 1003
61996+ help
61997+ Here you can choose the GID to disable client socket access for.
61998+ Remember to add the users you want client socket access disabled for to
61999+ the GID specified here. If the sysctl option is enabled, a sysctl
62000+ option with name "socket_client_gid" is created.
62001+
62002+config GRKERNSEC_SOCKET_SERVER
62003+ bool "Deny server sockets to group"
62004+ depends on GRKERNSEC_SOCKET
62005+ help
62006+ If you say Y here, you will be able to choose a GID of whose users will
62007+ be unable to run server applications from your machine. If the sysctl
62008+ option is enabled, a sysctl option with name "socket_server" is created.
62009+
62010+config GRKERNSEC_SOCKET_SERVER_GID
62011+ int "GID to deny server sockets for"
62012+ depends on GRKERNSEC_SOCKET_SERVER
62013+ default 1002
62014+ help
62015+ Here you can choose the GID to disable server socket access for.
62016+ Remember to add the users you want server socket access disabled for to
62017+ the GID specified here. If the sysctl option is enabled, a sysctl
62018+ option with name "socket_server_gid" is created.
62019+
62020+endmenu
62021+
62022+menu "Physical Protections"
62023+depends on GRKERNSEC
62024+
62025+config GRKERNSEC_DENYUSB
62026+ bool "Deny new USB connections after toggle"
62027+ default y if GRKERNSEC_CONFIG_AUTO
62028+ depends on SYSCTL && USB_SUPPORT
62029+ help
62030+ If you say Y here, a new sysctl option with name "deny_new_usb"
62031+ will be created. Setting its value to 1 will prevent any new
62032+ USB devices from being recognized by the OS. Any attempted USB
62033+ device insertion will be logged. This option is intended to be
62034+ used against custom USB devices designed to exploit vulnerabilities
62035+ in various USB device drivers.
62036+
62037+ For greatest effectiveness, this sysctl should be set after any
62038+ relevant init scripts. This option is safe to enable in distros
62039+ as each user can choose whether or not to toggle the sysctl.
62040+
62041+config GRKERNSEC_DENYUSB_FORCE
62042+ bool "Reject all USB devices not connected at boot"
62043+ select USB
62044+ depends on GRKERNSEC_DENYUSB
62045+ help
62046+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
62047+ that doesn't involve a sysctl entry. This option should only be
62048+ enabled if you're sure you want to deny all new USB connections
62049+ at runtime and don't want to modify init scripts. This should not
62050+ be enabled by distros. It forces the core USB code to be built
62051+ into the kernel image so that all devices connected at boot time
62052+ can be recognized and new USB device connections can be prevented
62053+ prior to init running.
62054+
62055+endmenu
62056+
62057+menu "Sysctl Support"
62058+depends on GRKERNSEC && SYSCTL
62059+
62060+config GRKERNSEC_SYSCTL
62061+ bool "Sysctl support"
62062+ default y if GRKERNSEC_CONFIG_AUTO
62063+ help
62064+ If you say Y here, you will be able to change the options that
62065+ grsecurity runs with at bootup, without having to recompile your
62066+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
62067+ to enable (1) or disable (0) various features. All the sysctl entries
62068+ are mutable until the "grsec_lock" entry is set to a non-zero value.
62069+ All features enabled in the kernel configuration are disabled at boot
62070+ if you do not say Y to the "Turn on features by default" option.
62071+ All options should be set at startup, and the grsec_lock entry should
62072+ be set to a non-zero value after all the options are set.
62073+ *THIS IS EXTREMELY IMPORTANT*
62074+
62075+config GRKERNSEC_SYSCTL_DISTRO
62076+ bool "Extra sysctl support for distro makers (READ HELP)"
62077+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
62078+ help
62079+ If you say Y here, additional sysctl options will be created
62080+ for features that affect processes running as root. Therefore,
62081+ it is critical when using this option that the grsec_lock entry be
62082+ enabled after boot. Only distros with prebuilt kernel packages
62083+ with this option enabled that can ensure grsec_lock is enabled
62084+ after boot should use this option.
62085+ *Failure to set grsec_lock after boot makes all grsec features
62086+ this option covers useless*
62087+
62088+ Currently this option creates the following sysctl entries:
62089+ "Disable Privileged I/O": "disable_priv_io"
62090+
62091+config GRKERNSEC_SYSCTL_ON
62092+ bool "Turn on features by default"
62093+ default y if GRKERNSEC_CONFIG_AUTO
62094+ depends on GRKERNSEC_SYSCTL
62095+ help
62096+ If you say Y here, instead of having all features enabled in the
62097+ kernel configuration disabled at boot time, the features will be
62098+ enabled at boot time. It is recommended you say Y here unless
62099+ there is some reason you would want all sysctl-tunable features to
62100+ be disabled by default. As mentioned elsewhere, it is important
62101+ to enable the grsec_lock entry once you have finished modifying
62102+ the sysctl entries.
62103+
62104+endmenu
62105+menu "Logging Options"
62106+depends on GRKERNSEC
62107+
62108+config GRKERNSEC_FLOODTIME
62109+ int "Seconds in between log messages (minimum)"
62110+ default 10
62111+ help
62112+ This option allows you to enforce the number of seconds between
62113+ grsecurity log messages. The default should be suitable for most
62114+ people, however, if you choose to change it, choose a value small enough
62115+ to allow informative logs to be produced, but large enough to
62116+ prevent flooding.
62117+
62118+config GRKERNSEC_FLOODBURST
62119+ int "Number of messages in a burst (maximum)"
62120+ default 6
62121+ help
62122+ This option allows you to choose the maximum number of messages allowed
62123+ within the flood time interval you chose in a separate option. The
62124+ default should be suitable for most people, however if you find that
62125+ many of your logs are being interpreted as flooding, you may want to
62126+ raise this value.
62127+
62128+endmenu
62129diff --git a/grsecurity/Makefile b/grsecurity/Makefile
62130new file mode 100644
62131index 0000000..b0b77d5
62132--- /dev/null
62133+++ b/grsecurity/Makefile
62134@@ -0,0 +1,43 @@
62135+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
62136+# during 2001-2009 it has been completely redesigned by Brad Spengler
62137+# into an RBAC system
62138+#
62139+# All code in this directory and various hooks inserted throughout the kernel
62140+# are copyright Brad Spengler - Open Source Security, Inc., and released
62141+# under the GPL v2 or higher
62142+
62143+KBUILD_CFLAGS += -Werror
62144+
62145+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
62146+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
62147+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
62148+ grsec_usb.o
62149+
62150+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
62151+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
62152+ gracl_learn.o grsec_log.o
62153+ifdef CONFIG_COMPAT
62154+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
62155+endif
62156+
62157+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
62158+
62159+ifdef CONFIG_NET
62160+obj-y += grsec_sock.o
62161+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
62162+endif
62163+
62164+ifndef CONFIG_GRKERNSEC
62165+obj-y += grsec_disabled.o
62166+endif
62167+
62168+ifdef CONFIG_GRKERNSEC_HIDESYM
62169+extra-y := grsec_hidesym.o
62170+$(obj)/grsec_hidesym.o:
62171+ @-chmod -f 500 /boot
62172+ @-chmod -f 500 /lib/modules
62173+ @-chmod -f 500 /lib64/modules
62174+ @-chmod -f 500 /lib32/modules
62175+ @-chmod -f 700 .
62176+ @echo ' grsec: protected kernel image paths'
62177+endif
62178diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
62179new file mode 100644
62180index 0000000..c0793fd
62181--- /dev/null
62182+++ b/grsecurity/gracl.c
62183@@ -0,0 +1,4178 @@
62184+#include <linux/kernel.h>
62185+#include <linux/module.h>
62186+#include <linux/sched.h>
62187+#include <linux/mm.h>
62188+#include <linux/file.h>
62189+#include <linux/fs.h>
62190+#include <linux/namei.h>
62191+#include <linux/mount.h>
62192+#include <linux/tty.h>
62193+#include <linux/proc_fs.h>
62194+#include <linux/lglock.h>
62195+#include <linux/slab.h>
62196+#include <linux/vmalloc.h>
62197+#include <linux/types.h>
62198+#include <linux/sysctl.h>
62199+#include <linux/netdevice.h>
62200+#include <linux/ptrace.h>
62201+#include <linux/gracl.h>
62202+#include <linux/gralloc.h>
62203+#include <linux/security.h>
62204+#include <linux/grinternal.h>
62205+#include <linux/pid_namespace.h>
62206+#include <linux/stop_machine.h>
62207+#include <linux/fdtable.h>
62208+#include <linux/percpu.h>
62209+#include <linux/lglock.h>
62210+#include <linux/hugetlb.h>
62211+#include <linux/posix-timers.h>
62212+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62213+#include <linux/magic.h>
62214+#include <linux/pagemap.h>
62215+#include "../fs/btrfs/async-thread.h"
62216+#include "../fs/btrfs/ctree.h"
62217+#include "../fs/btrfs/btrfs_inode.h"
62218+#endif
62219+#include "../fs/mount.h"
62220+
62221+#include <asm/uaccess.h>
62222+#include <asm/errno.h>
62223+#include <asm/mman.h>
62224+
62225+extern struct lglock vfsmount_lock;
62226+
62227+static struct acl_role_db acl_role_set;
62228+static struct name_db name_set;
62229+static struct inodev_db inodev_set;
62230+
62231+/* for keeping track of userspace pointers used for subjects, so we
62232+ can share references in the kernel as well
62233+*/
62234+
62235+static struct path real_root;
62236+
62237+static struct acl_subj_map_db subj_map_set;
62238+
62239+static struct acl_role_label *default_role;
62240+
62241+static struct acl_role_label *role_list;
62242+
62243+static u16 acl_sp_role_value;
62244+
62245+extern char *gr_shared_page[4];
62246+static DEFINE_MUTEX(gr_dev_mutex);
62247+DEFINE_RWLOCK(gr_inode_lock);
62248+
62249+struct gr_arg *gr_usermode;
62250+
62251+static unsigned int gr_status __read_only = GR_STATUS_INIT;
62252+
62253+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
62254+extern void gr_clear_learn_entries(void);
62255+
62256+unsigned char *gr_system_salt;
62257+unsigned char *gr_system_sum;
62258+
62259+static struct sprole_pw **acl_special_roles = NULL;
62260+static __u16 num_sprole_pws = 0;
62261+
62262+static struct acl_role_label *kernel_role = NULL;
62263+
62264+static unsigned int gr_auth_attempts = 0;
62265+static unsigned long gr_auth_expires = 0UL;
62266+
62267+#ifdef CONFIG_NET
62268+extern struct vfsmount *sock_mnt;
62269+#endif
62270+
62271+extern struct vfsmount *pipe_mnt;
62272+extern struct vfsmount *shm_mnt;
62273+
62274+#ifdef CONFIG_HUGETLBFS
62275+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
62276+#endif
62277+
62278+static struct acl_object_label *fakefs_obj_rw;
62279+static struct acl_object_label *fakefs_obj_rwx;
62280+
62281+extern int gr_init_uidset(void);
62282+extern void gr_free_uidset(void);
62283+extern void gr_remove_uid(uid_t uid);
62284+extern int gr_find_uid(uid_t uid);
62285+
62286+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
62287+{
62288+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
62289+ return -EFAULT;
62290+
62291+ return 0;
62292+}
62293+
62294+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
62295+{
62296+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
62297+ return -EFAULT;
62298+
62299+ return 0;
62300+}
62301+
62302+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
62303+{
62304+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
62305+ return -EFAULT;
62306+
62307+ return 0;
62308+}
62309+
62310+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
62311+{
62312+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
62313+ return -EFAULT;
62314+
62315+ return 0;
62316+}
62317+
62318+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
62319+{
62320+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
62321+ return -EFAULT;
62322+
62323+ return 0;
62324+}
62325+
62326+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
62327+{
62328+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
62329+ return -EFAULT;
62330+
62331+ return 0;
62332+}
62333+
62334+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
62335+{
62336+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
62337+ return -EFAULT;
62338+
62339+ return 0;
62340+}
62341+
62342+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
62343+{
62344+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
62345+ return -EFAULT;
62346+
62347+ return 0;
62348+}
62349+
62350+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
62351+{
62352+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
62353+ return -EFAULT;
62354+
62355+ return 0;
62356+}
62357+
62358+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
62359+{
62360+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
62361+ return -EFAULT;
62362+
62363+ if ((uwrap->version != GRSECURITY_VERSION) || (uwrap->size != sizeof(struct gr_arg)))
62364+ return -EINVAL;
62365+
62366+ return 0;
62367+}
62368+
62369+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
62370+{
62371+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
62372+ return -EFAULT;
62373+
62374+ return 0;
62375+}
62376+
62377+static size_t get_gr_arg_wrapper_size_normal(void)
62378+{
62379+ return sizeof(struct gr_arg_wrapper);
62380+}
62381+
62382+#ifdef CONFIG_COMPAT
62383+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
62384+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
62385+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
62386+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
62387+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
62388+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
62389+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
62390+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
62391+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
62392+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
62393+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
62394+extern size_t get_gr_arg_wrapper_size_compat(void);
62395+
62396+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
62397+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
62398+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
62399+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
62400+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
62401+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
62402+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
62403+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
62404+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
62405+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
62406+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
62407+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
62408+
62409+#else
62410+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
62411+#define copy_gr_arg copy_gr_arg_normal
62412+#define copy_gr_hash_struct copy_gr_hash_struct_normal
62413+#define copy_acl_object_label copy_acl_object_label_normal
62414+#define copy_acl_subject_label copy_acl_subject_label_normal
62415+#define copy_acl_role_label copy_acl_role_label_normal
62416+#define copy_acl_ip_label copy_acl_ip_label_normal
62417+#define copy_pointer_from_array copy_pointer_from_array_normal
62418+#define copy_sprole_pw copy_sprole_pw_normal
62419+#define copy_role_transition copy_role_transition_normal
62420+#define copy_role_allowed_ip copy_role_allowed_ip_normal
62421+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
62422+#endif
62423+
62424+__inline__ int
62425+gr_acl_is_enabled(void)
62426+{
62427+ return (gr_status & GR_READY);
62428+}
62429+
62430+static inline dev_t __get_dev(const struct dentry *dentry)
62431+{
62432+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62433+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
62434+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
62435+ else
62436+#endif
62437+ return dentry->d_sb->s_dev;
62438+}
62439+
62440+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
62441+{
62442+ return __get_dev(dentry);
62443+}
62444+
62445+static char gr_task_roletype_to_char(struct task_struct *task)
62446+{
62447+ switch (task->role->roletype &
62448+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
62449+ GR_ROLE_SPECIAL)) {
62450+ case GR_ROLE_DEFAULT:
62451+ return 'D';
62452+ case GR_ROLE_USER:
62453+ return 'U';
62454+ case GR_ROLE_GROUP:
62455+ return 'G';
62456+ case GR_ROLE_SPECIAL:
62457+ return 'S';
62458+ }
62459+
62460+ return 'X';
62461+}
62462+
62463+char gr_roletype_to_char(void)
62464+{
62465+ return gr_task_roletype_to_char(current);
62466+}
62467+
62468+__inline__ int
62469+gr_acl_tpe_check(void)
62470+{
62471+ if (unlikely(!(gr_status & GR_READY)))
62472+ return 0;
62473+ if (current->role->roletype & GR_ROLE_TPE)
62474+ return 1;
62475+ else
62476+ return 0;
62477+}
62478+
62479+int
62480+gr_handle_rawio(const struct inode *inode)
62481+{
62482+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62483+ if (inode && S_ISBLK(inode->i_mode) &&
62484+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
62485+ !capable(CAP_SYS_RAWIO))
62486+ return 1;
62487+#endif
62488+ return 0;
62489+}
62490+
62491+static int
62492+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
62493+{
62494+ if (likely(lena != lenb))
62495+ return 0;
62496+
62497+ return !memcmp(a, b, lena);
62498+}
62499+
62500+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
62501+{
62502+ *buflen -= namelen;
62503+ if (*buflen < 0)
62504+ return -ENAMETOOLONG;
62505+ *buffer -= namelen;
62506+ memcpy(*buffer, str, namelen);
62507+ return 0;
62508+}
62509+
62510+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
62511+{
62512+ return prepend(buffer, buflen, name->name, name->len);
62513+}
62514+
62515+static int prepend_path(const struct path *path, struct path *root,
62516+ char **buffer, int *buflen)
62517+{
62518+ struct dentry *dentry = path->dentry;
62519+ struct vfsmount *vfsmnt = path->mnt;
62520+ struct mount *mnt = real_mount(vfsmnt);
62521+ bool slash = false;
62522+ int error = 0;
62523+
62524+ while (dentry != root->dentry || vfsmnt != root->mnt) {
62525+ struct dentry * parent;
62526+
62527+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
62528+ /* Global root? */
62529+ if (!mnt_has_parent(mnt)) {
62530+ goto out;
62531+ }
62532+ dentry = mnt->mnt_mountpoint;
62533+ mnt = mnt->mnt_parent;
62534+ vfsmnt = &mnt->mnt;
62535+ continue;
62536+ }
62537+ parent = dentry->d_parent;
62538+ prefetch(parent);
62539+ spin_lock(&dentry->d_lock);
62540+ error = prepend_name(buffer, buflen, &dentry->d_name);
62541+ spin_unlock(&dentry->d_lock);
62542+ if (!error)
62543+ error = prepend(buffer, buflen, "/", 1);
62544+ if (error)
62545+ break;
62546+
62547+ slash = true;
62548+ dentry = parent;
62549+ }
62550+
62551+out:
62552+ if (!error && !slash)
62553+ error = prepend(buffer, buflen, "/", 1);
62554+
62555+ return error;
62556+}
62557+
62558+/* this must be called with vfsmount_lock and rename_lock held */
62559+
62560+static char *__our_d_path(const struct path *path, struct path *root,
62561+ char *buf, int buflen)
62562+{
62563+ char *res = buf + buflen;
62564+ int error;
62565+
62566+ prepend(&res, &buflen, "\0", 1);
62567+ error = prepend_path(path, root, &res, &buflen);
62568+ if (error)
62569+ return ERR_PTR(error);
62570+
62571+ return res;
62572+}
62573+
62574+static char *
62575+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
62576+{
62577+ char *retval;
62578+
62579+ retval = __our_d_path(path, root, buf, buflen);
62580+ if (unlikely(IS_ERR(retval)))
62581+ retval = strcpy(buf, "<path too long>");
62582+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
62583+ retval[1] = '\0';
62584+
62585+ return retval;
62586+}
62587+
62588+static char *
62589+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62590+ char *buf, int buflen)
62591+{
62592+ struct path path;
62593+ char *res;
62594+
62595+ path.dentry = (struct dentry *)dentry;
62596+ path.mnt = (struct vfsmount *)vfsmnt;
62597+
62598+ /* we can use real_root.dentry, real_root.mnt, because this is only called
62599+ by the RBAC system */
62600+ res = gen_full_path(&path, &real_root, buf, buflen);
62601+
62602+ return res;
62603+}
62604+
62605+static char *
62606+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62607+ char *buf, int buflen)
62608+{
62609+ char *res;
62610+ struct path path;
62611+ struct path root;
62612+ struct task_struct *reaper = init_pid_ns.child_reaper;
62613+
62614+ path.dentry = (struct dentry *)dentry;
62615+ path.mnt = (struct vfsmount *)vfsmnt;
62616+
62617+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
62618+ get_fs_root(reaper->fs, &root);
62619+
62620+ br_read_lock(&vfsmount_lock);
62621+ write_seqlock(&rename_lock);
62622+ res = gen_full_path(&path, &root, buf, buflen);
62623+ write_sequnlock(&rename_lock);
62624+ br_read_unlock(&vfsmount_lock);
62625+
62626+ path_put(&root);
62627+ return res;
62628+}
62629+
62630+static char *
62631+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62632+{
62633+ char *ret;
62634+ br_read_lock(&vfsmount_lock);
62635+ write_seqlock(&rename_lock);
62636+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62637+ PAGE_SIZE);
62638+ write_sequnlock(&rename_lock);
62639+ br_read_unlock(&vfsmount_lock);
62640+ return ret;
62641+}
62642+
62643+static char *
62644+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62645+{
62646+ char *ret;
62647+ char *buf;
62648+ int buflen;
62649+
62650+ br_read_lock(&vfsmount_lock);
62651+ write_seqlock(&rename_lock);
62652+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
62653+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
62654+ buflen = (int)(ret - buf);
62655+ if (buflen >= 5)
62656+ prepend(&ret, &buflen, "/proc", 5);
62657+ else
62658+ ret = strcpy(buf, "<path too long>");
62659+ write_sequnlock(&rename_lock);
62660+ br_read_unlock(&vfsmount_lock);
62661+ return ret;
62662+}
62663+
62664+char *
62665+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
62666+{
62667+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62668+ PAGE_SIZE);
62669+}
62670+
62671+char *
62672+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
62673+{
62674+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62675+ PAGE_SIZE);
62676+}
62677+
62678+char *
62679+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
62680+{
62681+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
62682+ PAGE_SIZE);
62683+}
62684+
62685+char *
62686+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
62687+{
62688+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
62689+ PAGE_SIZE);
62690+}
62691+
62692+char *
62693+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
62694+{
62695+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
62696+ PAGE_SIZE);
62697+}
62698+
62699+__inline__ __u32
62700+to_gr_audit(const __u32 reqmode)
62701+{
62702+ /* masks off auditable permission flags, then shifts them to create
62703+ auditing flags, and adds the special case of append auditing if
62704+ we're requesting write */
62705+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
62706+}
62707+
62708+struct acl_subject_label *
62709+lookup_subject_map(const struct acl_subject_label *userp)
62710+{
62711+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
62712+ struct subject_map *match;
62713+
62714+ match = subj_map_set.s_hash[index];
62715+
62716+ while (match && match->user != userp)
62717+ match = match->next;
62718+
62719+ if (match != NULL)
62720+ return match->kernel;
62721+ else
62722+ return NULL;
62723+}
62724+
62725+static void
62726+insert_subj_map_entry(struct subject_map *subjmap)
62727+{
62728+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
62729+ struct subject_map **curr;
62730+
62731+ subjmap->prev = NULL;
62732+
62733+ curr = &subj_map_set.s_hash[index];
62734+ if (*curr != NULL)
62735+ (*curr)->prev = subjmap;
62736+
62737+ subjmap->next = *curr;
62738+ *curr = subjmap;
62739+
62740+ return;
62741+}
62742+
62743+static struct acl_role_label *
62744+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
62745+ const gid_t gid)
62746+{
62747+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
62748+ struct acl_role_label *match;
62749+ struct role_allowed_ip *ipp;
62750+ unsigned int x;
62751+ u32 curr_ip = task->signal->curr_ip;
62752+
62753+ task->signal->saved_ip = curr_ip;
62754+
62755+ match = acl_role_set.r_hash[index];
62756+
62757+ while (match) {
62758+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
62759+ for (x = 0; x < match->domain_child_num; x++) {
62760+ if (match->domain_children[x] == uid)
62761+ goto found;
62762+ }
62763+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
62764+ break;
62765+ match = match->next;
62766+ }
62767+found:
62768+ if (match == NULL) {
62769+ try_group:
62770+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
62771+ match = acl_role_set.r_hash[index];
62772+
62773+ while (match) {
62774+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
62775+ for (x = 0; x < match->domain_child_num; x++) {
62776+ if (match->domain_children[x] == gid)
62777+ goto found2;
62778+ }
62779+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
62780+ break;
62781+ match = match->next;
62782+ }
62783+found2:
62784+ if (match == NULL)
62785+ match = default_role;
62786+ if (match->allowed_ips == NULL)
62787+ return match;
62788+ else {
62789+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62790+ if (likely
62791+ ((ntohl(curr_ip) & ipp->netmask) ==
62792+ (ntohl(ipp->addr) & ipp->netmask)))
62793+ return match;
62794+ }
62795+ match = default_role;
62796+ }
62797+ } else if (match->allowed_ips == NULL) {
62798+ return match;
62799+ } else {
62800+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62801+ if (likely
62802+ ((ntohl(curr_ip) & ipp->netmask) ==
62803+ (ntohl(ipp->addr) & ipp->netmask)))
62804+ return match;
62805+ }
62806+ goto try_group;
62807+ }
62808+
62809+ return match;
62810+}
62811+
62812+struct acl_subject_label *
62813+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
62814+ const struct acl_role_label *role)
62815+{
62816+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62817+ struct acl_subject_label *match;
62818+
62819+ match = role->subj_hash[index];
62820+
62821+ while (match && (match->inode != ino || match->device != dev ||
62822+ (match->mode & GR_DELETED))) {
62823+ match = match->next;
62824+ }
62825+
62826+ if (match && !(match->mode & GR_DELETED))
62827+ return match;
62828+ else
62829+ return NULL;
62830+}
62831+
62832+struct acl_subject_label *
62833+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
62834+ const struct acl_role_label *role)
62835+{
62836+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62837+ struct acl_subject_label *match;
62838+
62839+ match = role->subj_hash[index];
62840+
62841+ while (match && (match->inode != ino || match->device != dev ||
62842+ !(match->mode & GR_DELETED))) {
62843+ match = match->next;
62844+ }
62845+
62846+ if (match && (match->mode & GR_DELETED))
62847+ return match;
62848+ else
62849+ return NULL;
62850+}
62851+
62852+static struct acl_object_label *
62853+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
62854+ const struct acl_subject_label *subj)
62855+{
62856+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
62857+ struct acl_object_label *match;
62858+
62859+ match = subj->obj_hash[index];
62860+
62861+ while (match && (match->inode != ino || match->device != dev ||
62862+ (match->mode & GR_DELETED))) {
62863+ match = match->next;
62864+ }
62865+
62866+ if (match && !(match->mode & GR_DELETED))
62867+ return match;
62868+ else
62869+ return NULL;
62870+}
62871+
62872+static struct acl_object_label *
62873+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
62874+ const struct acl_subject_label *subj)
62875+{
62876+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
62877+ struct acl_object_label *match;
62878+
62879+ match = subj->obj_hash[index];
62880+
62881+ while (match && (match->inode != ino || match->device != dev ||
62882+ !(match->mode & GR_DELETED))) {
62883+ match = match->next;
62884+ }
62885+
62886+ if (match && (match->mode & GR_DELETED))
62887+ return match;
62888+
62889+ match = subj->obj_hash[index];
62890+
62891+ while (match && (match->inode != ino || match->device != dev ||
62892+ (match->mode & GR_DELETED))) {
62893+ match = match->next;
62894+ }
62895+
62896+ if (match && !(match->mode & GR_DELETED))
62897+ return match;
62898+ else
62899+ return NULL;
62900+}
62901+
62902+static struct name_entry *
62903+lookup_name_entry(const char *name)
62904+{
62905+ unsigned int len = strlen(name);
62906+ unsigned int key = full_name_hash(name, len);
62907+ unsigned int index = key % name_set.n_size;
62908+ struct name_entry *match;
62909+
62910+ match = name_set.n_hash[index];
62911+
62912+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
62913+ match = match->next;
62914+
62915+ return match;
62916+}
62917+
62918+static struct name_entry *
62919+lookup_name_entry_create(const char *name)
62920+{
62921+ unsigned int len = strlen(name);
62922+ unsigned int key = full_name_hash(name, len);
62923+ unsigned int index = key % name_set.n_size;
62924+ struct name_entry *match;
62925+
62926+ match = name_set.n_hash[index];
62927+
62928+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
62929+ !match->deleted))
62930+ match = match->next;
62931+
62932+ if (match && match->deleted)
62933+ return match;
62934+
62935+ match = name_set.n_hash[index];
62936+
62937+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
62938+ match->deleted))
62939+ match = match->next;
62940+
62941+ if (match && !match->deleted)
62942+ return match;
62943+ else
62944+ return NULL;
62945+}
62946+
62947+static struct inodev_entry *
62948+lookup_inodev_entry(const ino_t ino, const dev_t dev)
62949+{
62950+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
62951+ struct inodev_entry *match;
62952+
62953+ match = inodev_set.i_hash[index];
62954+
62955+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
62956+ match = match->next;
62957+
62958+ return match;
62959+}
62960+
62961+static void
62962+insert_inodev_entry(struct inodev_entry *entry)
62963+{
62964+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
62965+ inodev_set.i_size);
62966+ struct inodev_entry **curr;
62967+
62968+ entry->prev = NULL;
62969+
62970+ curr = &inodev_set.i_hash[index];
62971+ if (*curr != NULL)
62972+ (*curr)->prev = entry;
62973+
62974+ entry->next = *curr;
62975+ *curr = entry;
62976+
62977+ return;
62978+}
62979+
62980+static void
62981+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
62982+{
62983+ unsigned int index =
62984+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
62985+ struct acl_role_label **curr;
62986+ struct acl_role_label *tmp, *tmp2;
62987+
62988+ curr = &acl_role_set.r_hash[index];
62989+
62990+ /* simple case, slot is empty, just set it to our role */
62991+ if (*curr == NULL) {
62992+ *curr = role;
62993+ } else {
62994+ /* example:
62995+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
62996+ 2 -> 3
62997+ */
62998+ /* first check to see if we can already be reached via this slot */
62999+ tmp = *curr;
63000+ while (tmp && tmp != role)
63001+ tmp = tmp->next;
63002+ if (tmp == role) {
63003+ /* we don't need to add ourselves to this slot's chain */
63004+ return;
63005+ }
63006+ /* we need to add ourselves to this chain, two cases */
63007+ if (role->next == NULL) {
63008+ /* simple case, append the current chain to our role */
63009+ role->next = *curr;
63010+ *curr = role;
63011+ } else {
63012+ /* 1 -> 2 -> 3 -> 4
63013+ 2 -> 3 -> 4
63014+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
63015+ */
63016+ /* trickier case: walk our role's chain until we find
63017+ the role for the start of the current slot's chain */
63018+ tmp = role;
63019+ tmp2 = *curr;
63020+ while (tmp->next && tmp->next != tmp2)
63021+ tmp = tmp->next;
63022+ if (tmp->next == tmp2) {
63023+ /* from example above, we found 3, so just
63024+ replace this slot's chain with ours */
63025+ *curr = role;
63026+ } else {
63027+ /* we didn't find a subset of our role's chain
63028+ in the current slot's chain, so append their
63029+ chain to ours, and set us as the first role in
63030+ the slot's chain
63031+
63032+ we could fold this case with the case above,
63033+ but making it explicit for clarity
63034+ */
63035+ tmp->next = tmp2;
63036+ *curr = role;
63037+ }
63038+ }
63039+ }
63040+
63041+ return;
63042+}
63043+
63044+static void
63045+insert_acl_role_label(struct acl_role_label *role)
63046+{
63047+ int i;
63048+
63049+ if (role_list == NULL) {
63050+ role_list = role;
63051+ role->prev = NULL;
63052+ } else {
63053+ role->prev = role_list;
63054+ role_list = role;
63055+ }
63056+
63057+ /* used for hash chains */
63058+ role->next = NULL;
63059+
63060+ if (role->roletype & GR_ROLE_DOMAIN) {
63061+ for (i = 0; i < role->domain_child_num; i++)
63062+ __insert_acl_role_label(role, role->domain_children[i]);
63063+ } else
63064+ __insert_acl_role_label(role, role->uidgid);
63065+}
63066+
63067+static int
63068+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
63069+{
63070+ struct name_entry **curr, *nentry;
63071+ struct inodev_entry *ientry;
63072+ unsigned int len = strlen(name);
63073+ unsigned int key = full_name_hash(name, len);
63074+ unsigned int index = key % name_set.n_size;
63075+
63076+ curr = &name_set.n_hash[index];
63077+
63078+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
63079+ curr = &((*curr)->next);
63080+
63081+ if (*curr != NULL)
63082+ return 1;
63083+
63084+ nentry = acl_alloc(sizeof (struct name_entry));
63085+ if (nentry == NULL)
63086+ return 0;
63087+ ientry = acl_alloc(sizeof (struct inodev_entry));
63088+ if (ientry == NULL)
63089+ return 0;
63090+ ientry->nentry = nentry;
63091+
63092+ nentry->key = key;
63093+ nentry->name = name;
63094+ nentry->inode = inode;
63095+ nentry->device = device;
63096+ nentry->len = len;
63097+ nentry->deleted = deleted;
63098+
63099+ nentry->prev = NULL;
63100+ curr = &name_set.n_hash[index];
63101+ if (*curr != NULL)
63102+ (*curr)->prev = nentry;
63103+ nentry->next = *curr;
63104+ *curr = nentry;
63105+
63106+ /* insert us into the table searchable by inode/dev */
63107+ insert_inodev_entry(ientry);
63108+
63109+ return 1;
63110+}
63111+
63112+static void
63113+insert_acl_obj_label(struct acl_object_label *obj,
63114+ struct acl_subject_label *subj)
63115+{
63116+ unsigned int index =
63117+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
63118+ struct acl_object_label **curr;
63119+
63120+
63121+ obj->prev = NULL;
63122+
63123+ curr = &subj->obj_hash[index];
63124+ if (*curr != NULL)
63125+ (*curr)->prev = obj;
63126+
63127+ obj->next = *curr;
63128+ *curr = obj;
63129+
63130+ return;
63131+}
63132+
63133+static void
63134+insert_acl_subj_label(struct acl_subject_label *obj,
63135+ struct acl_role_label *role)
63136+{
63137+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
63138+ struct acl_subject_label **curr;
63139+
63140+ obj->prev = NULL;
63141+
63142+ curr = &role->subj_hash[index];
63143+ if (*curr != NULL)
63144+ (*curr)->prev = obj;
63145+
63146+ obj->next = *curr;
63147+ *curr = obj;
63148+
63149+ return;
63150+}
63151+
63152+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
63153+
63154+static void *
63155+create_table(__u32 * len, int elementsize)
63156+{
63157+ unsigned int table_sizes[] = {
63158+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
63159+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
63160+ 4194301, 8388593, 16777213, 33554393, 67108859
63161+ };
63162+ void *newtable = NULL;
63163+ unsigned int pwr = 0;
63164+
63165+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
63166+ table_sizes[pwr] <= *len)
63167+ pwr++;
63168+
63169+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
63170+ return newtable;
63171+
63172+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
63173+ newtable =
63174+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
63175+ else
63176+ newtable = vmalloc(table_sizes[pwr] * elementsize);
63177+
63178+ *len = table_sizes[pwr];
63179+
63180+ return newtable;
63181+}
63182+
63183+static int
63184+init_variables(const struct gr_arg *arg)
63185+{
63186+ struct task_struct *reaper = init_pid_ns.child_reaper;
63187+ unsigned int stacksize;
63188+
63189+ subj_map_set.s_size = arg->role_db.num_subjects;
63190+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
63191+ name_set.n_size = arg->role_db.num_objects;
63192+ inodev_set.i_size = arg->role_db.num_objects;
63193+
63194+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
63195+ !name_set.n_size || !inodev_set.i_size)
63196+ return 1;
63197+
63198+ if (!gr_init_uidset())
63199+ return 1;
63200+
63201+ /* set up the stack that holds allocation info */
63202+
63203+ stacksize = arg->role_db.num_pointers + 5;
63204+
63205+ if (!acl_alloc_stack_init(stacksize))
63206+ return 1;
63207+
63208+ /* grab reference for the real root dentry and vfsmount */
63209+ get_fs_root(reaper->fs, &real_root);
63210+
63211+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63212+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
63213+#endif
63214+
63215+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
63216+ if (fakefs_obj_rw == NULL)
63217+ return 1;
63218+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
63219+
63220+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
63221+ if (fakefs_obj_rwx == NULL)
63222+ return 1;
63223+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
63224+
63225+ subj_map_set.s_hash =
63226+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
63227+ acl_role_set.r_hash =
63228+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
63229+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
63230+ inodev_set.i_hash =
63231+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
63232+
63233+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
63234+ !name_set.n_hash || !inodev_set.i_hash)
63235+ return 1;
63236+
63237+ memset(subj_map_set.s_hash, 0,
63238+ sizeof(struct subject_map *) * subj_map_set.s_size);
63239+ memset(acl_role_set.r_hash, 0,
63240+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
63241+ memset(name_set.n_hash, 0,
63242+ sizeof (struct name_entry *) * name_set.n_size);
63243+ memset(inodev_set.i_hash, 0,
63244+ sizeof (struct inodev_entry *) * inodev_set.i_size);
63245+
63246+ return 0;
63247+}
63248+
63249+/* free information not needed after startup
63250+ currently contains user->kernel pointer mappings for subjects
63251+*/
63252+
63253+static void
63254+free_init_variables(void)
63255+{
63256+ __u32 i;
63257+
63258+ if (subj_map_set.s_hash) {
63259+ for (i = 0; i < subj_map_set.s_size; i++) {
63260+ if (subj_map_set.s_hash[i]) {
63261+ kfree(subj_map_set.s_hash[i]);
63262+ subj_map_set.s_hash[i] = NULL;
63263+ }
63264+ }
63265+
63266+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
63267+ PAGE_SIZE)
63268+ kfree(subj_map_set.s_hash);
63269+ else
63270+ vfree(subj_map_set.s_hash);
63271+ }
63272+
63273+ return;
63274+}
63275+
63276+static void
63277+free_variables(void)
63278+{
63279+ struct acl_subject_label *s;
63280+ struct acl_role_label *r;
63281+ struct task_struct *task, *task2;
63282+ unsigned int x;
63283+
63284+ gr_clear_learn_entries();
63285+
63286+ read_lock(&tasklist_lock);
63287+ do_each_thread(task2, task) {
63288+ task->acl_sp_role = 0;
63289+ task->acl_role_id = 0;
63290+ task->acl = NULL;
63291+ task->role = NULL;
63292+ } while_each_thread(task2, task);
63293+ read_unlock(&tasklist_lock);
63294+
63295+ /* release the reference to the real root dentry and vfsmount */
63296+ path_put(&real_root);
63297+ memset(&real_root, 0, sizeof(real_root));
63298+
63299+ /* free all object hash tables */
63300+
63301+ FOR_EACH_ROLE_START(r)
63302+ if (r->subj_hash == NULL)
63303+ goto next_role;
63304+ FOR_EACH_SUBJECT_START(r, s, x)
63305+ if (s->obj_hash == NULL)
63306+ break;
63307+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
63308+ kfree(s->obj_hash);
63309+ else
63310+ vfree(s->obj_hash);
63311+ FOR_EACH_SUBJECT_END(s, x)
63312+ FOR_EACH_NESTED_SUBJECT_START(r, s)
63313+ if (s->obj_hash == NULL)
63314+ break;
63315+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
63316+ kfree(s->obj_hash);
63317+ else
63318+ vfree(s->obj_hash);
63319+ FOR_EACH_NESTED_SUBJECT_END(s)
63320+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
63321+ kfree(r->subj_hash);
63322+ else
63323+ vfree(r->subj_hash);
63324+ r->subj_hash = NULL;
63325+next_role:
63326+ FOR_EACH_ROLE_END(r)
63327+
63328+ acl_free_all();
63329+
63330+ if (acl_role_set.r_hash) {
63331+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
63332+ PAGE_SIZE)
63333+ kfree(acl_role_set.r_hash);
63334+ else
63335+ vfree(acl_role_set.r_hash);
63336+ }
63337+ if (name_set.n_hash) {
63338+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
63339+ PAGE_SIZE)
63340+ kfree(name_set.n_hash);
63341+ else
63342+ vfree(name_set.n_hash);
63343+ }
63344+
63345+ if (inodev_set.i_hash) {
63346+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
63347+ PAGE_SIZE)
63348+ kfree(inodev_set.i_hash);
63349+ else
63350+ vfree(inodev_set.i_hash);
63351+ }
63352+
63353+ gr_free_uidset();
63354+
63355+ memset(&name_set, 0, sizeof (struct name_db));
63356+ memset(&inodev_set, 0, sizeof (struct inodev_db));
63357+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
63358+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
63359+
63360+ default_role = NULL;
63361+ kernel_role = NULL;
63362+ role_list = NULL;
63363+
63364+ return;
63365+}
63366+
63367+static struct acl_subject_label *
63368+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
63369+
63370+static int alloc_and_copy_string(char **name, unsigned int maxlen)
63371+{
63372+ unsigned int len = strnlen_user(*name, maxlen);
63373+ char *tmp;
63374+
63375+ if (!len || len >= maxlen)
63376+ return -EINVAL;
63377+
63378+ if ((tmp = (char *) acl_alloc(len)) == NULL)
63379+ return -ENOMEM;
63380+
63381+ if (copy_from_user(tmp, *name, len))
63382+ return -EFAULT;
63383+
63384+ tmp[len-1] = '\0';
63385+ *name = tmp;
63386+
63387+ return 0;
63388+}
63389+
63390+static int
63391+copy_user_glob(struct acl_object_label *obj)
63392+{
63393+ struct acl_object_label *g_tmp, **guser;
63394+ int error;
63395+
63396+ if (obj->globbed == NULL)
63397+ return 0;
63398+
63399+ guser = &obj->globbed;
63400+ while (*guser) {
63401+ g_tmp = (struct acl_object_label *)
63402+ acl_alloc(sizeof (struct acl_object_label));
63403+ if (g_tmp == NULL)
63404+ return -ENOMEM;
63405+
63406+ if (copy_acl_object_label(g_tmp, *guser))
63407+ return -EFAULT;
63408+
63409+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
63410+ if (error)
63411+ return error;
63412+
63413+ *guser = g_tmp;
63414+ guser = &(g_tmp->next);
63415+ }
63416+
63417+ return 0;
63418+}
63419+
63420+static int
63421+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
63422+ struct acl_role_label *role)
63423+{
63424+ struct acl_object_label *o_tmp;
63425+ int ret;
63426+
63427+ while (userp) {
63428+ if ((o_tmp = (struct acl_object_label *)
63429+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
63430+ return -ENOMEM;
63431+
63432+ if (copy_acl_object_label(o_tmp, userp))
63433+ return -EFAULT;
63434+
63435+ userp = o_tmp->prev;
63436+
63437+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
63438+ if (ret)
63439+ return ret;
63440+
63441+ insert_acl_obj_label(o_tmp, subj);
63442+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
63443+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
63444+ return -ENOMEM;
63445+
63446+ ret = copy_user_glob(o_tmp);
63447+ if (ret)
63448+ return ret;
63449+
63450+ if (o_tmp->nested) {
63451+ int already_copied;
63452+
63453+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
63454+ if (IS_ERR(o_tmp->nested))
63455+ return PTR_ERR(o_tmp->nested);
63456+
63457+ /* insert into nested subject list if we haven't copied this one yet
63458+ to prevent duplicate entries */
63459+ if (!already_copied) {
63460+ o_tmp->nested->next = role->hash->first;
63461+ role->hash->first = o_tmp->nested;
63462+ }
63463+ }
63464+ }
63465+
63466+ return 0;
63467+}
63468+
63469+static __u32
63470+count_user_subjs(struct acl_subject_label *userp)
63471+{
63472+ struct acl_subject_label s_tmp;
63473+ __u32 num = 0;
63474+
63475+ while (userp) {
63476+ if (copy_acl_subject_label(&s_tmp, userp))
63477+ break;
63478+
63479+ userp = s_tmp.prev;
63480+ }
63481+
63482+ return num;
63483+}
63484+
63485+static int
63486+copy_user_allowedips(struct acl_role_label *rolep)
63487+{
63488+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
63489+
63490+ ruserip = rolep->allowed_ips;
63491+
63492+ while (ruserip) {
63493+ rlast = rtmp;
63494+
63495+ if ((rtmp = (struct role_allowed_ip *)
63496+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
63497+ return -ENOMEM;
63498+
63499+ if (copy_role_allowed_ip(rtmp, ruserip))
63500+ return -EFAULT;
63501+
63502+ ruserip = rtmp->prev;
63503+
63504+ if (!rlast) {
63505+ rtmp->prev = NULL;
63506+ rolep->allowed_ips = rtmp;
63507+ } else {
63508+ rlast->next = rtmp;
63509+ rtmp->prev = rlast;
63510+ }
63511+
63512+ if (!ruserip)
63513+ rtmp->next = NULL;
63514+ }
63515+
63516+ return 0;
63517+}
63518+
63519+static int
63520+copy_user_transitions(struct acl_role_label *rolep)
63521+{
63522+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
63523+ int error;
63524+
63525+ rusertp = rolep->transitions;
63526+
63527+ while (rusertp) {
63528+ rlast = rtmp;
63529+
63530+ if ((rtmp = (struct role_transition *)
63531+ acl_alloc(sizeof (struct role_transition))) == NULL)
63532+ return -ENOMEM;
63533+
63534+ if (copy_role_transition(rtmp, rusertp))
63535+ return -EFAULT;
63536+
63537+ rusertp = rtmp->prev;
63538+
63539+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
63540+ if (error)
63541+ return error;
63542+
63543+ if (!rlast) {
63544+ rtmp->prev = NULL;
63545+ rolep->transitions = rtmp;
63546+ } else {
63547+ rlast->next = rtmp;
63548+ rtmp->prev = rlast;
63549+ }
63550+
63551+ if (!rusertp)
63552+ rtmp->next = NULL;
63553+ }
63554+
63555+ return 0;
63556+}
63557+
63558+static __u32 count_user_objs(const struct acl_object_label __user *userp)
63559+{
63560+ struct acl_object_label o_tmp;
63561+ __u32 num = 0;
63562+
63563+ while (userp) {
63564+ if (copy_acl_object_label(&o_tmp, userp))
63565+ break;
63566+
63567+ userp = o_tmp.prev;
63568+ num++;
63569+ }
63570+
63571+ return num;
63572+}
63573+
63574+static struct acl_subject_label *
63575+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
63576+{
63577+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
63578+ __u32 num_objs;
63579+ struct acl_ip_label **i_tmp, *i_utmp2;
63580+ struct gr_hash_struct ghash;
63581+ struct subject_map *subjmap;
63582+ unsigned int i_num;
63583+ int err;
63584+
63585+ if (already_copied != NULL)
63586+ *already_copied = 0;
63587+
63588+ s_tmp = lookup_subject_map(userp);
63589+
63590+ /* we've already copied this subject into the kernel, just return
63591+ the reference to it, and don't copy it over again
63592+ */
63593+ if (s_tmp) {
63594+ if (already_copied != NULL)
63595+ *already_copied = 1;
63596+ return(s_tmp);
63597+ }
63598+
63599+ if ((s_tmp = (struct acl_subject_label *)
63600+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
63601+ return ERR_PTR(-ENOMEM);
63602+
63603+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
63604+ if (subjmap == NULL)
63605+ return ERR_PTR(-ENOMEM);
63606+
63607+ subjmap->user = userp;
63608+ subjmap->kernel = s_tmp;
63609+ insert_subj_map_entry(subjmap);
63610+
63611+ if (copy_acl_subject_label(s_tmp, userp))
63612+ return ERR_PTR(-EFAULT);
63613+
63614+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
63615+ if (err)
63616+ return ERR_PTR(err);
63617+
63618+ if (!strcmp(s_tmp->filename, "/"))
63619+ role->root_label = s_tmp;
63620+
63621+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
63622+ return ERR_PTR(-EFAULT);
63623+
63624+ /* copy user and group transition tables */
63625+
63626+ if (s_tmp->user_trans_num) {
63627+ uid_t *uidlist;
63628+
63629+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
63630+ if (uidlist == NULL)
63631+ return ERR_PTR(-ENOMEM);
63632+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
63633+ return ERR_PTR(-EFAULT);
63634+
63635+ s_tmp->user_transitions = uidlist;
63636+ }
63637+
63638+ if (s_tmp->group_trans_num) {
63639+ gid_t *gidlist;
63640+
63641+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
63642+ if (gidlist == NULL)
63643+ return ERR_PTR(-ENOMEM);
63644+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
63645+ return ERR_PTR(-EFAULT);
63646+
63647+ s_tmp->group_transitions = gidlist;
63648+ }
63649+
63650+ /* set up object hash table */
63651+ num_objs = count_user_objs(ghash.first);
63652+
63653+ s_tmp->obj_hash_size = num_objs;
63654+ s_tmp->obj_hash =
63655+ (struct acl_object_label **)
63656+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
63657+
63658+ if (!s_tmp->obj_hash)
63659+ return ERR_PTR(-ENOMEM);
63660+
63661+ memset(s_tmp->obj_hash, 0,
63662+ s_tmp->obj_hash_size *
63663+ sizeof (struct acl_object_label *));
63664+
63665+ /* add in objects */
63666+ err = copy_user_objs(ghash.first, s_tmp, role);
63667+
63668+ if (err)
63669+ return ERR_PTR(err);
63670+
63671+ /* set pointer for parent subject */
63672+ if (s_tmp->parent_subject) {
63673+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
63674+
63675+ if (IS_ERR(s_tmp2))
63676+ return s_tmp2;
63677+
63678+ s_tmp->parent_subject = s_tmp2;
63679+ }
63680+
63681+ /* add in ip acls */
63682+
63683+ if (!s_tmp->ip_num) {
63684+ s_tmp->ips = NULL;
63685+ goto insert;
63686+ }
63687+
63688+ i_tmp =
63689+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
63690+ sizeof (struct acl_ip_label *));
63691+
63692+ if (!i_tmp)
63693+ return ERR_PTR(-ENOMEM);
63694+
63695+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
63696+ *(i_tmp + i_num) =
63697+ (struct acl_ip_label *)
63698+ acl_alloc(sizeof (struct acl_ip_label));
63699+ if (!*(i_tmp + i_num))
63700+ return ERR_PTR(-ENOMEM);
63701+
63702+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
63703+ return ERR_PTR(-EFAULT);
63704+
63705+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
63706+ return ERR_PTR(-EFAULT);
63707+
63708+ if ((*(i_tmp + i_num))->iface == NULL)
63709+ continue;
63710+
63711+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
63712+ if (err)
63713+ return ERR_PTR(err);
63714+ }
63715+
63716+ s_tmp->ips = i_tmp;
63717+
63718+insert:
63719+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
63720+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
63721+ return ERR_PTR(-ENOMEM);
63722+
63723+ return s_tmp;
63724+}
63725+
63726+static int
63727+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
63728+{
63729+ struct acl_subject_label s_pre;
63730+ struct acl_subject_label * ret;
63731+ int err;
63732+
63733+ while (userp) {
63734+ if (copy_acl_subject_label(&s_pre, userp))
63735+ return -EFAULT;
63736+
63737+ ret = do_copy_user_subj(userp, role, NULL);
63738+
63739+ err = PTR_ERR(ret);
63740+ if (IS_ERR(ret))
63741+ return err;
63742+
63743+ insert_acl_subj_label(ret, role);
63744+
63745+ userp = s_pre.prev;
63746+ }
63747+
63748+ return 0;
63749+}
63750+
63751+static int
63752+copy_user_acl(struct gr_arg *arg)
63753+{
63754+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
63755+ struct acl_subject_label *subj_list;
63756+ struct sprole_pw *sptmp;
63757+ struct gr_hash_struct *ghash;
63758+ uid_t *domainlist;
63759+ unsigned int r_num;
63760+ int err = 0;
63761+ __u16 i;
63762+ __u32 num_subjs;
63763+
63764+ /* we need a default and kernel role */
63765+ if (arg->role_db.num_roles < 2)
63766+ return -EINVAL;
63767+
63768+ /* copy special role authentication info from userspace */
63769+
63770+ num_sprole_pws = arg->num_sprole_pws;
63771+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
63772+
63773+ if (!acl_special_roles && num_sprole_pws)
63774+ return -ENOMEM;
63775+
63776+ for (i = 0; i < num_sprole_pws; i++) {
63777+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
63778+ if (!sptmp)
63779+ return -ENOMEM;
63780+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
63781+ return -EFAULT;
63782+
63783+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
63784+ if (err)
63785+ return err;
63786+
63787+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63788+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
63789+#endif
63790+
63791+ acl_special_roles[i] = sptmp;
63792+ }
63793+
63794+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
63795+
63796+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
63797+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
63798+
63799+ if (!r_tmp)
63800+ return -ENOMEM;
63801+
63802+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
63803+ return -EFAULT;
63804+
63805+ if (copy_acl_role_label(r_tmp, r_utmp2))
63806+ return -EFAULT;
63807+
63808+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
63809+ if (err)
63810+ return err;
63811+
63812+ if (!strcmp(r_tmp->rolename, "default")
63813+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
63814+ default_role = r_tmp;
63815+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
63816+ kernel_role = r_tmp;
63817+ }
63818+
63819+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
63820+ return -ENOMEM;
63821+
63822+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
63823+ return -EFAULT;
63824+
63825+ r_tmp->hash = ghash;
63826+
63827+ num_subjs = count_user_subjs(r_tmp->hash->first);
63828+
63829+ r_tmp->subj_hash_size = num_subjs;
63830+ r_tmp->subj_hash =
63831+ (struct acl_subject_label **)
63832+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
63833+
63834+ if (!r_tmp->subj_hash)
63835+ return -ENOMEM;
63836+
63837+ err = copy_user_allowedips(r_tmp);
63838+ if (err)
63839+ return err;
63840+
63841+ /* copy domain info */
63842+ if (r_tmp->domain_children != NULL) {
63843+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
63844+ if (domainlist == NULL)
63845+ return -ENOMEM;
63846+
63847+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
63848+ return -EFAULT;
63849+
63850+ r_tmp->domain_children = domainlist;
63851+ }
63852+
63853+ err = copy_user_transitions(r_tmp);
63854+ if (err)
63855+ return err;
63856+
63857+ memset(r_tmp->subj_hash, 0,
63858+ r_tmp->subj_hash_size *
63859+ sizeof (struct acl_subject_label *));
63860+
63861+ /* acquire the list of subjects, then NULL out
63862+ the list prior to parsing the subjects for this role,
63863+ as during this parsing the list is replaced with a list
63864+ of *nested* subjects for the role
63865+ */
63866+ subj_list = r_tmp->hash->first;
63867+
63868+ /* set nested subject list to null */
63869+ r_tmp->hash->first = NULL;
63870+
63871+ err = copy_user_subjs(subj_list, r_tmp);
63872+
63873+ if (err)
63874+ return err;
63875+
63876+ insert_acl_role_label(r_tmp);
63877+ }
63878+
63879+ if (default_role == NULL || kernel_role == NULL)
63880+ return -EINVAL;
63881+
63882+ return err;
63883+}
63884+
63885+static int
63886+gracl_init(struct gr_arg *args)
63887+{
63888+ int error = 0;
63889+
63890+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
63891+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
63892+
63893+ if (init_variables(args)) {
63894+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
63895+ error = -ENOMEM;
63896+ free_variables();
63897+ goto out;
63898+ }
63899+
63900+ error = copy_user_acl(args);
63901+ free_init_variables();
63902+ if (error) {
63903+ free_variables();
63904+ goto out;
63905+ }
63906+
63907+ if ((error = gr_set_acls(0))) {
63908+ free_variables();
63909+ goto out;
63910+ }
63911+
63912+ pax_open_kernel();
63913+ gr_status |= GR_READY;
63914+ pax_close_kernel();
63915+
63916+ out:
63917+ return error;
63918+}
63919+
63920+/* derived from glibc fnmatch() 0: match, 1: no match*/
63921+
63922+static int
63923+glob_match(const char *p, const char *n)
63924+{
63925+ char c;
63926+
63927+ while ((c = *p++) != '\0') {
63928+ switch (c) {
63929+ case '?':
63930+ if (*n == '\0')
63931+ return 1;
63932+ else if (*n == '/')
63933+ return 1;
63934+ break;
63935+ case '\\':
63936+ if (*n != c)
63937+ return 1;
63938+ break;
63939+ case '*':
63940+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
63941+ if (*n == '/')
63942+ return 1;
63943+ else if (c == '?') {
63944+ if (*n == '\0')
63945+ return 1;
63946+ else
63947+ ++n;
63948+ }
63949+ }
63950+ if (c == '\0') {
63951+ return 0;
63952+ } else {
63953+ const char *endp;
63954+
63955+ if ((endp = strchr(n, '/')) == NULL)
63956+ endp = n + strlen(n);
63957+
63958+ if (c == '[') {
63959+ for (--p; n < endp; ++n)
63960+ if (!glob_match(p, n))
63961+ return 0;
63962+ } else if (c == '/') {
63963+ while (*n != '\0' && *n != '/')
63964+ ++n;
63965+ if (*n == '/' && !glob_match(p, n + 1))
63966+ return 0;
63967+ } else {
63968+ for (--p; n < endp; ++n)
63969+ if (*n == c && !glob_match(p, n))
63970+ return 0;
63971+ }
63972+
63973+ return 1;
63974+ }
63975+ case '[':
63976+ {
63977+ int not;
63978+ char cold;
63979+
63980+ if (*n == '\0' || *n == '/')
63981+ return 1;
63982+
63983+ not = (*p == '!' || *p == '^');
63984+ if (not)
63985+ ++p;
63986+
63987+ c = *p++;
63988+ for (;;) {
63989+ unsigned char fn = (unsigned char)*n;
63990+
63991+ if (c == '\0')
63992+ return 1;
63993+ else {
63994+ if (c == fn)
63995+ goto matched;
63996+ cold = c;
63997+ c = *p++;
63998+
63999+ if (c == '-' && *p != ']') {
64000+ unsigned char cend = *p++;
64001+
64002+ if (cend == '\0')
64003+ return 1;
64004+
64005+ if (cold <= fn && fn <= cend)
64006+ goto matched;
64007+
64008+ c = *p++;
64009+ }
64010+ }
64011+
64012+ if (c == ']')
64013+ break;
64014+ }
64015+ if (!not)
64016+ return 1;
64017+ break;
64018+ matched:
64019+ while (c != ']') {
64020+ if (c == '\0')
64021+ return 1;
64022+
64023+ c = *p++;
64024+ }
64025+ if (not)
64026+ return 1;
64027+ }
64028+ break;
64029+ default:
64030+ if (c != *n)
64031+ return 1;
64032+ }
64033+
64034+ ++n;
64035+ }
64036+
64037+ if (*n == '\0')
64038+ return 0;
64039+
64040+ if (*n == '/')
64041+ return 0;
64042+
64043+ return 1;
64044+}
64045+
64046+static struct acl_object_label *
64047+chk_glob_label(struct acl_object_label *globbed,
64048+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
64049+{
64050+ struct acl_object_label *tmp;
64051+
64052+ if (*path == NULL)
64053+ *path = gr_to_filename_nolock(dentry, mnt);
64054+
64055+ tmp = globbed;
64056+
64057+ while (tmp) {
64058+ if (!glob_match(tmp->filename, *path))
64059+ return tmp;
64060+ tmp = tmp->next;
64061+ }
64062+
64063+ return NULL;
64064+}
64065+
64066+static struct acl_object_label *
64067+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
64068+ const ino_t curr_ino, const dev_t curr_dev,
64069+ const struct acl_subject_label *subj, char **path, const int checkglob)
64070+{
64071+ struct acl_subject_label *tmpsubj;
64072+ struct acl_object_label *retval;
64073+ struct acl_object_label *retval2;
64074+
64075+ tmpsubj = (struct acl_subject_label *) subj;
64076+ read_lock(&gr_inode_lock);
64077+ do {
64078+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
64079+ if (retval) {
64080+ if (checkglob && retval->globbed) {
64081+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
64082+ if (retval2)
64083+ retval = retval2;
64084+ }
64085+ break;
64086+ }
64087+ } while ((tmpsubj = tmpsubj->parent_subject));
64088+ read_unlock(&gr_inode_lock);
64089+
64090+ return retval;
64091+}
64092+
64093+static __inline__ struct acl_object_label *
64094+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
64095+ struct dentry *curr_dentry,
64096+ const struct acl_subject_label *subj, char **path, const int checkglob)
64097+{
64098+ int newglob = checkglob;
64099+ ino_t inode;
64100+ dev_t device;
64101+
64102+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
64103+ as we don't want a / * rule to match instead of the / object
64104+ don't do this for create lookups that call this function though, since they're looking up
64105+ on the parent and thus need globbing checks on all paths
64106+ */
64107+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
64108+ newglob = GR_NO_GLOB;
64109+
64110+ spin_lock(&curr_dentry->d_lock);
64111+ inode = curr_dentry->d_inode->i_ino;
64112+ device = __get_dev(curr_dentry);
64113+ spin_unlock(&curr_dentry->d_lock);
64114+
64115+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
64116+}
64117+
64118+#ifdef CONFIG_HUGETLBFS
64119+static inline bool
64120+is_hugetlbfs_mnt(const struct vfsmount *mnt)
64121+{
64122+ int i;
64123+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
64124+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
64125+ return true;
64126+ }
64127+
64128+ return false;
64129+}
64130+#endif
64131+
64132+static struct acl_object_label *
64133+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64134+ const struct acl_subject_label *subj, char *path, const int checkglob)
64135+{
64136+ struct dentry *dentry = (struct dentry *) l_dentry;
64137+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64138+ struct mount *real_mnt = real_mount(mnt);
64139+ struct acl_object_label *retval;
64140+ struct dentry *parent;
64141+
64142+ br_read_lock(&vfsmount_lock);
64143+ write_seqlock(&rename_lock);
64144+
64145+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
64146+#ifdef CONFIG_NET
64147+ mnt == sock_mnt ||
64148+#endif
64149+#ifdef CONFIG_HUGETLBFS
64150+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
64151+#endif
64152+ /* ignore Eric Biederman */
64153+ IS_PRIVATE(l_dentry->d_inode))) {
64154+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
64155+ goto out;
64156+ }
64157+
64158+ for (;;) {
64159+ if (dentry == real_root.dentry && mnt == real_root.mnt)
64160+ break;
64161+
64162+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64163+ if (!mnt_has_parent(real_mnt))
64164+ break;
64165+
64166+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64167+ if (retval != NULL)
64168+ goto out;
64169+
64170+ dentry = real_mnt->mnt_mountpoint;
64171+ real_mnt = real_mnt->mnt_parent;
64172+ mnt = &real_mnt->mnt;
64173+ continue;
64174+ }
64175+
64176+ parent = dentry->d_parent;
64177+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64178+ if (retval != NULL)
64179+ goto out;
64180+
64181+ dentry = parent;
64182+ }
64183+
64184+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64185+
64186+ /* real_root is pinned so we don't have to hold a reference */
64187+ if (retval == NULL)
64188+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
64189+out:
64190+ write_sequnlock(&rename_lock);
64191+ br_read_unlock(&vfsmount_lock);
64192+
64193+ BUG_ON(retval == NULL);
64194+
64195+ return retval;
64196+}
64197+
64198+static __inline__ struct acl_object_label *
64199+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64200+ const struct acl_subject_label *subj)
64201+{
64202+ char *path = NULL;
64203+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
64204+}
64205+
64206+static __inline__ struct acl_object_label *
64207+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64208+ const struct acl_subject_label *subj)
64209+{
64210+ char *path = NULL;
64211+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
64212+}
64213+
64214+static __inline__ struct acl_object_label *
64215+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64216+ const struct acl_subject_label *subj, char *path)
64217+{
64218+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
64219+}
64220+
64221+static struct acl_subject_label *
64222+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64223+ const struct acl_role_label *role)
64224+{
64225+ struct dentry *dentry = (struct dentry *) l_dentry;
64226+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64227+ struct mount *real_mnt = real_mount(mnt);
64228+ struct acl_subject_label *retval;
64229+ struct dentry *parent;
64230+
64231+ br_read_lock(&vfsmount_lock);
64232+ write_seqlock(&rename_lock);
64233+
64234+ for (;;) {
64235+ if (dentry == real_root.dentry && mnt == real_root.mnt)
64236+ break;
64237+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64238+ if (!mnt_has_parent(real_mnt))
64239+ break;
64240+
64241+ spin_lock(&dentry->d_lock);
64242+ read_lock(&gr_inode_lock);
64243+ retval =
64244+ lookup_acl_subj_label(dentry->d_inode->i_ino,
64245+ __get_dev(dentry), role);
64246+ read_unlock(&gr_inode_lock);
64247+ spin_unlock(&dentry->d_lock);
64248+ if (retval != NULL)
64249+ goto out;
64250+
64251+ dentry = real_mnt->mnt_mountpoint;
64252+ real_mnt = real_mnt->mnt_parent;
64253+ mnt = &real_mnt->mnt;
64254+ continue;
64255+ }
64256+
64257+ spin_lock(&dentry->d_lock);
64258+ read_lock(&gr_inode_lock);
64259+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64260+ __get_dev(dentry), role);
64261+ read_unlock(&gr_inode_lock);
64262+ parent = dentry->d_parent;
64263+ spin_unlock(&dentry->d_lock);
64264+
64265+ if (retval != NULL)
64266+ goto out;
64267+
64268+ dentry = parent;
64269+ }
64270+
64271+ spin_lock(&dentry->d_lock);
64272+ read_lock(&gr_inode_lock);
64273+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64274+ __get_dev(dentry), role);
64275+ read_unlock(&gr_inode_lock);
64276+ spin_unlock(&dentry->d_lock);
64277+
64278+ if (unlikely(retval == NULL)) {
64279+ /* real_root is pinned, we don't need to hold a reference */
64280+ read_lock(&gr_inode_lock);
64281+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
64282+ __get_dev(real_root.dentry), role);
64283+ read_unlock(&gr_inode_lock);
64284+ }
64285+out:
64286+ write_sequnlock(&rename_lock);
64287+ br_read_unlock(&vfsmount_lock);
64288+
64289+ BUG_ON(retval == NULL);
64290+
64291+ return retval;
64292+}
64293+
64294+static void
64295+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
64296+{
64297+ struct task_struct *task = current;
64298+ const struct cred *cred = current_cred();
64299+
64300+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
64301+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64302+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64303+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
64304+
64305+ return;
64306+}
64307+
64308+static void
64309+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
64310+{
64311+ struct task_struct *task = current;
64312+ const struct cred *cred = current_cred();
64313+
64314+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64315+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64316+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64317+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
64318+
64319+ return;
64320+}
64321+
64322+static void
64323+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
64324+{
64325+ struct task_struct *task = current;
64326+ const struct cred *cred = current_cred();
64327+
64328+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64329+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64330+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64331+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
64332+
64333+ return;
64334+}
64335+
64336+__u32
64337+gr_search_file(const struct dentry * dentry, const __u32 mode,
64338+ const struct vfsmount * mnt)
64339+{
64340+ __u32 retval = mode;
64341+ struct acl_subject_label *curracl;
64342+ struct acl_object_label *currobj;
64343+
64344+ if (unlikely(!(gr_status & GR_READY)))
64345+ return (mode & ~GR_AUDITS);
64346+
64347+ curracl = current->acl;
64348+
64349+ currobj = chk_obj_label(dentry, mnt, curracl);
64350+ retval = currobj->mode & mode;
64351+
64352+ /* if we're opening a specified transfer file for writing
64353+ (e.g. /dev/initctl), then transfer our role to init
64354+ */
64355+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
64356+ current->role->roletype & GR_ROLE_PERSIST)) {
64357+ struct task_struct *task = init_pid_ns.child_reaper;
64358+
64359+ if (task->role != current->role) {
64360+ task->acl_sp_role = 0;
64361+ task->acl_role_id = current->acl_role_id;
64362+ task->role = current->role;
64363+ rcu_read_lock();
64364+ read_lock(&grsec_exec_file_lock);
64365+ gr_apply_subject_to_task(task);
64366+ read_unlock(&grsec_exec_file_lock);
64367+ rcu_read_unlock();
64368+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
64369+ }
64370+ }
64371+
64372+ if (unlikely
64373+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
64374+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
64375+ __u32 new_mode = mode;
64376+
64377+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64378+
64379+ retval = new_mode;
64380+
64381+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
64382+ new_mode |= GR_INHERIT;
64383+
64384+ if (!(mode & GR_NOLEARN))
64385+ gr_log_learn(dentry, mnt, new_mode);
64386+ }
64387+
64388+ return retval;
64389+}
64390+
64391+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
64392+ const struct dentry *parent,
64393+ const struct vfsmount *mnt)
64394+{
64395+ struct name_entry *match;
64396+ struct acl_object_label *matchpo;
64397+ struct acl_subject_label *curracl;
64398+ char *path;
64399+
64400+ if (unlikely(!(gr_status & GR_READY)))
64401+ return NULL;
64402+
64403+ preempt_disable();
64404+ path = gr_to_filename_rbac(new_dentry, mnt);
64405+ match = lookup_name_entry_create(path);
64406+
64407+ curracl = current->acl;
64408+
64409+ if (match) {
64410+ read_lock(&gr_inode_lock);
64411+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
64412+ read_unlock(&gr_inode_lock);
64413+
64414+ if (matchpo) {
64415+ preempt_enable();
64416+ return matchpo;
64417+ }
64418+ }
64419+
64420+ // lookup parent
64421+
64422+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
64423+
64424+ preempt_enable();
64425+ return matchpo;
64426+}
64427+
64428+__u32
64429+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
64430+ const struct vfsmount * mnt, const __u32 mode)
64431+{
64432+ struct acl_object_label *matchpo;
64433+ __u32 retval;
64434+
64435+ if (unlikely(!(gr_status & GR_READY)))
64436+ return (mode & ~GR_AUDITS);
64437+
64438+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
64439+
64440+ retval = matchpo->mode & mode;
64441+
64442+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
64443+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64444+ __u32 new_mode = mode;
64445+
64446+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64447+
64448+ gr_log_learn(new_dentry, mnt, new_mode);
64449+ return new_mode;
64450+ }
64451+
64452+ return retval;
64453+}
64454+
64455+__u32
64456+gr_check_link(const struct dentry * new_dentry,
64457+ const struct dentry * parent_dentry,
64458+ const struct vfsmount * parent_mnt,
64459+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
64460+{
64461+ struct acl_object_label *obj;
64462+ __u32 oldmode, newmode;
64463+ __u32 needmode;
64464+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
64465+ GR_DELETE | GR_INHERIT;
64466+
64467+ if (unlikely(!(gr_status & GR_READY)))
64468+ return (GR_CREATE | GR_LINK);
64469+
64470+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
64471+ oldmode = obj->mode;
64472+
64473+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
64474+ newmode = obj->mode;
64475+
64476+ needmode = newmode & checkmodes;
64477+
64478+ // old name for hardlink must have at least the permissions of the new name
64479+ if ((oldmode & needmode) != needmode)
64480+ goto bad;
64481+
64482+ // if old name had restrictions/auditing, make sure the new name does as well
64483+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
64484+
64485+ // don't allow hardlinking of suid/sgid/fcapped files without permission
64486+ if (is_privileged_binary(old_dentry))
64487+ needmode |= GR_SETID;
64488+
64489+ if ((newmode & needmode) != needmode)
64490+ goto bad;
64491+
64492+ // enforce minimum permissions
64493+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
64494+ return newmode;
64495+bad:
64496+ needmode = oldmode;
64497+ if (is_privileged_binary(old_dentry))
64498+ needmode |= GR_SETID;
64499+
64500+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
64501+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
64502+ return (GR_CREATE | GR_LINK);
64503+ } else if (newmode & GR_SUPPRESS)
64504+ return GR_SUPPRESS;
64505+ else
64506+ return 0;
64507+}
64508+
64509+int
64510+gr_check_hidden_task(const struct task_struct *task)
64511+{
64512+ if (unlikely(!(gr_status & GR_READY)))
64513+ return 0;
64514+
64515+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
64516+ return 1;
64517+
64518+ return 0;
64519+}
64520+
64521+int
64522+gr_check_protected_task(const struct task_struct *task)
64523+{
64524+ if (unlikely(!(gr_status & GR_READY) || !task))
64525+ return 0;
64526+
64527+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64528+ task->acl != current->acl)
64529+ return 1;
64530+
64531+ return 0;
64532+}
64533+
64534+int
64535+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64536+{
64537+ struct task_struct *p;
64538+ int ret = 0;
64539+
64540+ if (unlikely(!(gr_status & GR_READY) || !pid))
64541+ return ret;
64542+
64543+ read_lock(&tasklist_lock);
64544+ do_each_pid_task(pid, type, p) {
64545+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64546+ p->acl != current->acl) {
64547+ ret = 1;
64548+ goto out;
64549+ }
64550+ } while_each_pid_task(pid, type, p);
64551+out:
64552+ read_unlock(&tasklist_lock);
64553+
64554+ return ret;
64555+}
64556+
64557+void
64558+gr_copy_label(struct task_struct *tsk)
64559+{
64560+ tsk->signal->used_accept = 0;
64561+ tsk->acl_sp_role = 0;
64562+ tsk->acl_role_id = current->acl_role_id;
64563+ tsk->acl = current->acl;
64564+ tsk->role = current->role;
64565+ tsk->signal->curr_ip = current->signal->curr_ip;
64566+ tsk->signal->saved_ip = current->signal->saved_ip;
64567+ if (current->exec_file)
64568+ get_file(current->exec_file);
64569+ tsk->exec_file = current->exec_file;
64570+ tsk->is_writable = current->is_writable;
64571+ if (unlikely(current->signal->used_accept)) {
64572+ current->signal->curr_ip = 0;
64573+ current->signal->saved_ip = 0;
64574+ }
64575+
64576+ return;
64577+}
64578+
64579+static void
64580+gr_set_proc_res(struct task_struct *task)
64581+{
64582+ struct acl_subject_label *proc;
64583+ unsigned short i;
64584+
64585+ proc = task->acl;
64586+
64587+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
64588+ return;
64589+
64590+ for (i = 0; i < RLIM_NLIMITS; i++) {
64591+ if (!(proc->resmask & (1U << i)))
64592+ continue;
64593+
64594+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
64595+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
64596+
64597+ if (i == RLIMIT_CPU)
64598+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
64599+ }
64600+
64601+ return;
64602+}
64603+
64604+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
64605+
64606+int
64607+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64608+{
64609+ unsigned int i;
64610+ __u16 num;
64611+ uid_t *uidlist;
64612+ uid_t curuid;
64613+ int realok = 0;
64614+ int effectiveok = 0;
64615+ int fsok = 0;
64616+ uid_t globalreal, globaleffective, globalfs;
64617+
64618+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
64619+ struct user_struct *user;
64620+
64621+ if (!uid_valid(real))
64622+ goto skipit;
64623+
64624+ /* find user based on global namespace */
64625+
64626+ globalreal = GR_GLOBAL_UID(real);
64627+
64628+ user = find_user(make_kuid(&init_user_ns, globalreal));
64629+ if (user == NULL)
64630+ goto skipit;
64631+
64632+ if (gr_process_kernel_setuid_ban(user)) {
64633+ /* for find_user */
64634+ free_uid(user);
64635+ return 1;
64636+ }
64637+
64638+ /* for find_user */
64639+ free_uid(user);
64640+
64641+skipit:
64642+#endif
64643+
64644+ if (unlikely(!(gr_status & GR_READY)))
64645+ return 0;
64646+
64647+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64648+ gr_log_learn_uid_change(real, effective, fs);
64649+
64650+ num = current->acl->user_trans_num;
64651+ uidlist = current->acl->user_transitions;
64652+
64653+ if (uidlist == NULL)
64654+ return 0;
64655+
64656+ if (!uid_valid(real)) {
64657+ realok = 1;
64658+ globalreal = (uid_t)-1;
64659+ } else {
64660+ globalreal = GR_GLOBAL_UID(real);
64661+ }
64662+ if (!uid_valid(effective)) {
64663+ effectiveok = 1;
64664+ globaleffective = (uid_t)-1;
64665+ } else {
64666+ globaleffective = GR_GLOBAL_UID(effective);
64667+ }
64668+ if (!uid_valid(fs)) {
64669+ fsok = 1;
64670+ globalfs = (uid_t)-1;
64671+ } else {
64672+ globalfs = GR_GLOBAL_UID(fs);
64673+ }
64674+
64675+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
64676+ for (i = 0; i < num; i++) {
64677+ curuid = uidlist[i];
64678+ if (globalreal == curuid)
64679+ realok = 1;
64680+ if (globaleffective == curuid)
64681+ effectiveok = 1;
64682+ if (globalfs == curuid)
64683+ fsok = 1;
64684+ }
64685+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
64686+ for (i = 0; i < num; i++) {
64687+ curuid = uidlist[i];
64688+ if (globalreal == curuid)
64689+ break;
64690+ if (globaleffective == curuid)
64691+ break;
64692+ if (globalfs == curuid)
64693+ break;
64694+ }
64695+ /* not in deny list */
64696+ if (i == num) {
64697+ realok = 1;
64698+ effectiveok = 1;
64699+ fsok = 1;
64700+ }
64701+ }
64702+
64703+ if (realok && effectiveok && fsok)
64704+ return 0;
64705+ else {
64706+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64707+ return 1;
64708+ }
64709+}
64710+
64711+int
64712+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64713+{
64714+ unsigned int i;
64715+ __u16 num;
64716+ gid_t *gidlist;
64717+ gid_t curgid;
64718+ int realok = 0;
64719+ int effectiveok = 0;
64720+ int fsok = 0;
64721+ gid_t globalreal, globaleffective, globalfs;
64722+
64723+ if (unlikely(!(gr_status & GR_READY)))
64724+ return 0;
64725+
64726+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64727+ gr_log_learn_gid_change(real, effective, fs);
64728+
64729+ num = current->acl->group_trans_num;
64730+ gidlist = current->acl->group_transitions;
64731+
64732+ if (gidlist == NULL)
64733+ return 0;
64734+
64735+ if (!gid_valid(real)) {
64736+ realok = 1;
64737+ globalreal = (gid_t)-1;
64738+ } else {
64739+ globalreal = GR_GLOBAL_GID(real);
64740+ }
64741+ if (!gid_valid(effective)) {
64742+ effectiveok = 1;
64743+ globaleffective = (gid_t)-1;
64744+ } else {
64745+ globaleffective = GR_GLOBAL_GID(effective);
64746+ }
64747+ if (!gid_valid(fs)) {
64748+ fsok = 1;
64749+ globalfs = (gid_t)-1;
64750+ } else {
64751+ globalfs = GR_GLOBAL_GID(fs);
64752+ }
64753+
64754+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
64755+ for (i = 0; i < num; i++) {
64756+ curgid = gidlist[i];
64757+ if (globalreal == curgid)
64758+ realok = 1;
64759+ if (globaleffective == curgid)
64760+ effectiveok = 1;
64761+ if (globalfs == curgid)
64762+ fsok = 1;
64763+ }
64764+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
64765+ for (i = 0; i < num; i++) {
64766+ curgid = gidlist[i];
64767+ if (globalreal == curgid)
64768+ break;
64769+ if (globaleffective == curgid)
64770+ break;
64771+ if (globalfs == curgid)
64772+ break;
64773+ }
64774+ /* not in deny list */
64775+ if (i == num) {
64776+ realok = 1;
64777+ effectiveok = 1;
64778+ fsok = 1;
64779+ }
64780+ }
64781+
64782+ if (realok && effectiveok && fsok)
64783+ return 0;
64784+ else {
64785+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64786+ return 1;
64787+ }
64788+}
64789+
64790+extern int gr_acl_is_capable(const int cap);
64791+
64792+void
64793+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
64794+{
64795+ struct acl_role_label *role = task->role;
64796+ struct acl_subject_label *subj = NULL;
64797+ struct acl_object_label *obj;
64798+ struct file *filp;
64799+ uid_t uid;
64800+ gid_t gid;
64801+
64802+ if (unlikely(!(gr_status & GR_READY)))
64803+ return;
64804+
64805+ uid = GR_GLOBAL_UID(kuid);
64806+ gid = GR_GLOBAL_GID(kgid);
64807+
64808+ filp = task->exec_file;
64809+
64810+ /* kernel process, we'll give them the kernel role */
64811+ if (unlikely(!filp)) {
64812+ task->role = kernel_role;
64813+ task->acl = kernel_role->root_label;
64814+ return;
64815+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
64816+ role = lookup_acl_role_label(task, uid, gid);
64817+
64818+ /* don't change the role if we're not a privileged process */
64819+ if (role && task->role != role &&
64820+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
64821+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
64822+ return;
64823+
64824+ /* perform subject lookup in possibly new role
64825+ we can use this result below in the case where role == task->role
64826+ */
64827+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
64828+
64829+ /* if we changed uid/gid, but result in the same role
64830+ and are using inheritance, don't lose the inherited subject
64831+ if current subject is other than what normal lookup
64832+ would result in, we arrived via inheritance, don't
64833+ lose subject
64834+ */
64835+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
64836+ (subj == task->acl)))
64837+ task->acl = subj;
64838+
64839+ task->role = role;
64840+
64841+ task->is_writable = 0;
64842+
64843+ /* ignore additional mmap checks for processes that are writable
64844+ by the default ACL */
64845+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
64846+ if (unlikely(obj->mode & GR_WRITE))
64847+ task->is_writable = 1;
64848+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
64849+ if (unlikely(obj->mode & GR_WRITE))
64850+ task->is_writable = 1;
64851+
64852+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64853+ 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);
64854+#endif
64855+
64856+ gr_set_proc_res(task);
64857+
64858+ return;
64859+}
64860+
64861+int
64862+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64863+ const int unsafe_flags)
64864+{
64865+ struct task_struct *task = current;
64866+ struct acl_subject_label *newacl;
64867+ struct acl_object_label *obj;
64868+ __u32 retmode;
64869+
64870+ if (unlikely(!(gr_status & GR_READY)))
64871+ return 0;
64872+
64873+ newacl = chk_subj_label(dentry, mnt, task->role);
64874+
64875+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
64876+ did an exec
64877+ */
64878+ rcu_read_lock();
64879+ read_lock(&tasklist_lock);
64880+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
64881+ (task->parent->acl->mode & GR_POVERRIDE))) {
64882+ read_unlock(&tasklist_lock);
64883+ rcu_read_unlock();
64884+ goto skip_check;
64885+ }
64886+ read_unlock(&tasklist_lock);
64887+ rcu_read_unlock();
64888+
64889+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
64890+ !(task->role->roletype & GR_ROLE_GOD) &&
64891+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
64892+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64893+ if (unsafe_flags & LSM_UNSAFE_SHARE)
64894+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
64895+ else
64896+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
64897+ return -EACCES;
64898+ }
64899+
64900+skip_check:
64901+
64902+ obj = chk_obj_label(dentry, mnt, task->acl);
64903+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
64904+
64905+ if (!(task->acl->mode & GR_INHERITLEARN) &&
64906+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
64907+ if (obj->nested)
64908+ task->acl = obj->nested;
64909+ else
64910+ task->acl = newacl;
64911+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
64912+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
64913+
64914+ task->is_writable = 0;
64915+
64916+ /* ignore additional mmap checks for processes that are writable
64917+ by the default ACL */
64918+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
64919+ if (unlikely(obj->mode & GR_WRITE))
64920+ task->is_writable = 1;
64921+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
64922+ if (unlikely(obj->mode & GR_WRITE))
64923+ task->is_writable = 1;
64924+
64925+ gr_set_proc_res(task);
64926+
64927+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64928+ 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);
64929+#endif
64930+ return 0;
64931+}
64932+
64933+/* always called with valid inodev ptr */
64934+static void
64935+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
64936+{
64937+ struct acl_object_label *matchpo;
64938+ struct acl_subject_label *matchps;
64939+ struct acl_subject_label *subj;
64940+ struct acl_role_label *role;
64941+ unsigned int x;
64942+
64943+ FOR_EACH_ROLE_START(role)
64944+ FOR_EACH_SUBJECT_START(role, subj, x)
64945+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64946+ matchpo->mode |= GR_DELETED;
64947+ FOR_EACH_SUBJECT_END(subj,x)
64948+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
64949+ /* nested subjects aren't in the role's subj_hash table */
64950+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64951+ matchpo->mode |= GR_DELETED;
64952+ FOR_EACH_NESTED_SUBJECT_END(subj)
64953+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
64954+ matchps->mode |= GR_DELETED;
64955+ FOR_EACH_ROLE_END(role)
64956+
64957+ inodev->nentry->deleted = 1;
64958+
64959+ return;
64960+}
64961+
64962+void
64963+gr_handle_delete(const ino_t ino, const dev_t dev)
64964+{
64965+ struct inodev_entry *inodev;
64966+
64967+ if (unlikely(!(gr_status & GR_READY)))
64968+ return;
64969+
64970+ write_lock(&gr_inode_lock);
64971+ inodev = lookup_inodev_entry(ino, dev);
64972+ if (inodev != NULL)
64973+ do_handle_delete(inodev, ino, dev);
64974+ write_unlock(&gr_inode_lock);
64975+
64976+ return;
64977+}
64978+
64979+static void
64980+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
64981+ const ino_t newinode, const dev_t newdevice,
64982+ struct acl_subject_label *subj)
64983+{
64984+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
64985+ struct acl_object_label *match;
64986+
64987+ match = subj->obj_hash[index];
64988+
64989+ while (match && (match->inode != oldinode ||
64990+ match->device != olddevice ||
64991+ !(match->mode & GR_DELETED)))
64992+ match = match->next;
64993+
64994+ if (match && (match->inode == oldinode)
64995+ && (match->device == olddevice)
64996+ && (match->mode & GR_DELETED)) {
64997+ if (match->prev == NULL) {
64998+ subj->obj_hash[index] = match->next;
64999+ if (match->next != NULL)
65000+ match->next->prev = NULL;
65001+ } else {
65002+ match->prev->next = match->next;
65003+ if (match->next != NULL)
65004+ match->next->prev = match->prev;
65005+ }
65006+ match->prev = NULL;
65007+ match->next = NULL;
65008+ match->inode = newinode;
65009+ match->device = newdevice;
65010+ match->mode &= ~GR_DELETED;
65011+
65012+ insert_acl_obj_label(match, subj);
65013+ }
65014+
65015+ return;
65016+}
65017+
65018+static void
65019+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
65020+ const ino_t newinode, const dev_t newdevice,
65021+ struct acl_role_label *role)
65022+{
65023+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
65024+ struct acl_subject_label *match;
65025+
65026+ match = role->subj_hash[index];
65027+
65028+ while (match && (match->inode != oldinode ||
65029+ match->device != olddevice ||
65030+ !(match->mode & GR_DELETED)))
65031+ match = match->next;
65032+
65033+ if (match && (match->inode == oldinode)
65034+ && (match->device == olddevice)
65035+ && (match->mode & GR_DELETED)) {
65036+ if (match->prev == NULL) {
65037+ role->subj_hash[index] = match->next;
65038+ if (match->next != NULL)
65039+ match->next->prev = NULL;
65040+ } else {
65041+ match->prev->next = match->next;
65042+ if (match->next != NULL)
65043+ match->next->prev = match->prev;
65044+ }
65045+ match->prev = NULL;
65046+ match->next = NULL;
65047+ match->inode = newinode;
65048+ match->device = newdevice;
65049+ match->mode &= ~GR_DELETED;
65050+
65051+ insert_acl_subj_label(match, role);
65052+ }
65053+
65054+ return;
65055+}
65056+
65057+static void
65058+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
65059+ const ino_t newinode, const dev_t newdevice)
65060+{
65061+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
65062+ struct inodev_entry *match;
65063+
65064+ match = inodev_set.i_hash[index];
65065+
65066+ while (match && (match->nentry->inode != oldinode ||
65067+ match->nentry->device != olddevice || !match->nentry->deleted))
65068+ match = match->next;
65069+
65070+ if (match && (match->nentry->inode == oldinode)
65071+ && (match->nentry->device == olddevice) &&
65072+ match->nentry->deleted) {
65073+ if (match->prev == NULL) {
65074+ inodev_set.i_hash[index] = match->next;
65075+ if (match->next != NULL)
65076+ match->next->prev = NULL;
65077+ } else {
65078+ match->prev->next = match->next;
65079+ if (match->next != NULL)
65080+ match->next->prev = match->prev;
65081+ }
65082+ match->prev = NULL;
65083+ match->next = NULL;
65084+ match->nentry->inode = newinode;
65085+ match->nentry->device = newdevice;
65086+ match->nentry->deleted = 0;
65087+
65088+ insert_inodev_entry(match);
65089+ }
65090+
65091+ return;
65092+}
65093+
65094+static void
65095+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
65096+{
65097+ struct acl_subject_label *subj;
65098+ struct acl_role_label *role;
65099+ unsigned int x;
65100+
65101+ FOR_EACH_ROLE_START(role)
65102+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
65103+
65104+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
65105+ if ((subj->inode == ino) && (subj->device == dev)) {
65106+ subj->inode = ino;
65107+ subj->device = dev;
65108+ }
65109+ /* nested subjects aren't in the role's subj_hash table */
65110+ update_acl_obj_label(matchn->inode, matchn->device,
65111+ ino, dev, subj);
65112+ FOR_EACH_NESTED_SUBJECT_END(subj)
65113+ FOR_EACH_SUBJECT_START(role, subj, x)
65114+ update_acl_obj_label(matchn->inode, matchn->device,
65115+ ino, dev, subj);
65116+ FOR_EACH_SUBJECT_END(subj,x)
65117+ FOR_EACH_ROLE_END(role)
65118+
65119+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
65120+
65121+ return;
65122+}
65123+
65124+static void
65125+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
65126+ const struct vfsmount *mnt)
65127+{
65128+ ino_t ino = dentry->d_inode->i_ino;
65129+ dev_t dev = __get_dev(dentry);
65130+
65131+ __do_handle_create(matchn, ino, dev);
65132+
65133+ return;
65134+}
65135+
65136+void
65137+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
65138+{
65139+ struct name_entry *matchn;
65140+
65141+ if (unlikely(!(gr_status & GR_READY)))
65142+ return;
65143+
65144+ preempt_disable();
65145+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
65146+
65147+ if (unlikely((unsigned long)matchn)) {
65148+ write_lock(&gr_inode_lock);
65149+ do_handle_create(matchn, dentry, mnt);
65150+ write_unlock(&gr_inode_lock);
65151+ }
65152+ preempt_enable();
65153+
65154+ return;
65155+}
65156+
65157+void
65158+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
65159+{
65160+ struct name_entry *matchn;
65161+
65162+ if (unlikely(!(gr_status & GR_READY)))
65163+ return;
65164+
65165+ preempt_disable();
65166+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
65167+
65168+ if (unlikely((unsigned long)matchn)) {
65169+ write_lock(&gr_inode_lock);
65170+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
65171+ write_unlock(&gr_inode_lock);
65172+ }
65173+ preempt_enable();
65174+
65175+ return;
65176+}
65177+
65178+void
65179+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
65180+ struct dentry *old_dentry,
65181+ struct dentry *new_dentry,
65182+ struct vfsmount *mnt, const __u8 replace)
65183+{
65184+ struct name_entry *matchn;
65185+ struct inodev_entry *inodev;
65186+ struct inode *inode = new_dentry->d_inode;
65187+ ino_t old_ino = old_dentry->d_inode->i_ino;
65188+ dev_t old_dev = __get_dev(old_dentry);
65189+
65190+ /* vfs_rename swaps the name and parent link for old_dentry and
65191+ new_dentry
65192+ at this point, old_dentry has the new name, parent link, and inode
65193+ for the renamed file
65194+ if a file is being replaced by a rename, new_dentry has the inode
65195+ and name for the replaced file
65196+ */
65197+
65198+ if (unlikely(!(gr_status & GR_READY)))
65199+ return;
65200+
65201+ preempt_disable();
65202+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
65203+
65204+ /* we wouldn't have to check d_inode if it weren't for
65205+ NFS silly-renaming
65206+ */
65207+
65208+ write_lock(&gr_inode_lock);
65209+ if (unlikely(replace && inode)) {
65210+ ino_t new_ino = inode->i_ino;
65211+ dev_t new_dev = __get_dev(new_dentry);
65212+
65213+ inodev = lookup_inodev_entry(new_ino, new_dev);
65214+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
65215+ do_handle_delete(inodev, new_ino, new_dev);
65216+ }
65217+
65218+ inodev = lookup_inodev_entry(old_ino, old_dev);
65219+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
65220+ do_handle_delete(inodev, old_ino, old_dev);
65221+
65222+ if (unlikely((unsigned long)matchn))
65223+ do_handle_create(matchn, old_dentry, mnt);
65224+
65225+ write_unlock(&gr_inode_lock);
65226+ preempt_enable();
65227+
65228+ return;
65229+}
65230+
65231+static int
65232+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
65233+ unsigned char **sum)
65234+{
65235+ struct acl_role_label *r;
65236+ struct role_allowed_ip *ipp;
65237+ struct role_transition *trans;
65238+ unsigned int i;
65239+ int found = 0;
65240+ u32 curr_ip = current->signal->curr_ip;
65241+
65242+ current->signal->saved_ip = curr_ip;
65243+
65244+ /* check transition table */
65245+
65246+ for (trans = current->role->transitions; trans; trans = trans->next) {
65247+ if (!strcmp(rolename, trans->rolename)) {
65248+ found = 1;
65249+ break;
65250+ }
65251+ }
65252+
65253+ if (!found)
65254+ return 0;
65255+
65256+ /* handle special roles that do not require authentication
65257+ and check ip */
65258+
65259+ FOR_EACH_ROLE_START(r)
65260+ if (!strcmp(rolename, r->rolename) &&
65261+ (r->roletype & GR_ROLE_SPECIAL)) {
65262+ found = 0;
65263+ if (r->allowed_ips != NULL) {
65264+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
65265+ if ((ntohl(curr_ip) & ipp->netmask) ==
65266+ (ntohl(ipp->addr) & ipp->netmask))
65267+ found = 1;
65268+ }
65269+ } else
65270+ found = 2;
65271+ if (!found)
65272+ return 0;
65273+
65274+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
65275+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
65276+ *salt = NULL;
65277+ *sum = NULL;
65278+ return 1;
65279+ }
65280+ }
65281+ FOR_EACH_ROLE_END(r)
65282+
65283+ for (i = 0; i < num_sprole_pws; i++) {
65284+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
65285+ *salt = acl_special_roles[i]->salt;
65286+ *sum = acl_special_roles[i]->sum;
65287+ return 1;
65288+ }
65289+ }
65290+
65291+ return 0;
65292+}
65293+
65294+static void
65295+assign_special_role(char *rolename)
65296+{
65297+ struct acl_object_label *obj;
65298+ struct acl_role_label *r;
65299+ struct acl_role_label *assigned = NULL;
65300+ struct task_struct *tsk;
65301+ struct file *filp;
65302+
65303+ FOR_EACH_ROLE_START(r)
65304+ if (!strcmp(rolename, r->rolename) &&
65305+ (r->roletype & GR_ROLE_SPECIAL)) {
65306+ assigned = r;
65307+ break;
65308+ }
65309+ FOR_EACH_ROLE_END(r)
65310+
65311+ if (!assigned)
65312+ return;
65313+
65314+ read_lock(&tasklist_lock);
65315+ read_lock(&grsec_exec_file_lock);
65316+
65317+ tsk = current->real_parent;
65318+ if (tsk == NULL)
65319+ goto out_unlock;
65320+
65321+ filp = tsk->exec_file;
65322+ if (filp == NULL)
65323+ goto out_unlock;
65324+
65325+ tsk->is_writable = 0;
65326+
65327+ tsk->acl_sp_role = 1;
65328+ tsk->acl_role_id = ++acl_sp_role_value;
65329+ tsk->role = assigned;
65330+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
65331+
65332+ /* ignore additional mmap checks for processes that are writable
65333+ by the default ACL */
65334+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65335+ if (unlikely(obj->mode & GR_WRITE))
65336+ tsk->is_writable = 1;
65337+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
65338+ if (unlikely(obj->mode & GR_WRITE))
65339+ tsk->is_writable = 1;
65340+
65341+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65342+ 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));
65343+#endif
65344+
65345+out_unlock:
65346+ read_unlock(&grsec_exec_file_lock);
65347+ read_unlock(&tasklist_lock);
65348+ return;
65349+}
65350+
65351+int gr_check_secure_terminal(struct task_struct *task)
65352+{
65353+ struct task_struct *p, *p2, *p3;
65354+ struct files_struct *files;
65355+ struct fdtable *fdt;
65356+ struct file *our_file = NULL, *file;
65357+ int i;
65358+
65359+ if (task->signal->tty == NULL)
65360+ return 1;
65361+
65362+ files = get_files_struct(task);
65363+ if (files != NULL) {
65364+ rcu_read_lock();
65365+ fdt = files_fdtable(files);
65366+ for (i=0; i < fdt->max_fds; i++) {
65367+ file = fcheck_files(files, i);
65368+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
65369+ get_file(file);
65370+ our_file = file;
65371+ }
65372+ }
65373+ rcu_read_unlock();
65374+ put_files_struct(files);
65375+ }
65376+
65377+ if (our_file == NULL)
65378+ return 1;
65379+
65380+ read_lock(&tasklist_lock);
65381+ do_each_thread(p2, p) {
65382+ files = get_files_struct(p);
65383+ if (files == NULL ||
65384+ (p->signal && p->signal->tty == task->signal->tty)) {
65385+ if (files != NULL)
65386+ put_files_struct(files);
65387+ continue;
65388+ }
65389+ rcu_read_lock();
65390+ fdt = files_fdtable(files);
65391+ for (i=0; i < fdt->max_fds; i++) {
65392+ file = fcheck_files(files, i);
65393+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
65394+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
65395+ p3 = task;
65396+ while (task_pid_nr(p3) > 0) {
65397+ if (p3 == p)
65398+ break;
65399+ p3 = p3->real_parent;
65400+ }
65401+ if (p3 == p)
65402+ break;
65403+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
65404+ gr_handle_alertkill(p);
65405+ rcu_read_unlock();
65406+ put_files_struct(files);
65407+ read_unlock(&tasklist_lock);
65408+ fput(our_file);
65409+ return 0;
65410+ }
65411+ }
65412+ rcu_read_unlock();
65413+ put_files_struct(files);
65414+ } while_each_thread(p2, p);
65415+ read_unlock(&tasklist_lock);
65416+
65417+ fput(our_file);
65418+ return 1;
65419+}
65420+
65421+static int gr_rbac_disable(void *unused)
65422+{
65423+ pax_open_kernel();
65424+ gr_status &= ~GR_READY;
65425+ pax_close_kernel();
65426+
65427+ return 0;
65428+}
65429+
65430+ssize_t
65431+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
65432+{
65433+ struct gr_arg_wrapper uwrap;
65434+ unsigned char *sprole_salt = NULL;
65435+ unsigned char *sprole_sum = NULL;
65436+ int error = 0;
65437+ int error2 = 0;
65438+ size_t req_count = 0;
65439+
65440+ mutex_lock(&gr_dev_mutex);
65441+
65442+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
65443+ error = -EPERM;
65444+ goto out;
65445+ }
65446+
65447+#ifdef CONFIG_COMPAT
65448+ pax_open_kernel();
65449+ if (is_compat_task()) {
65450+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
65451+ copy_gr_arg = &copy_gr_arg_compat;
65452+ copy_acl_object_label = &copy_acl_object_label_compat;
65453+ copy_acl_subject_label = &copy_acl_subject_label_compat;
65454+ copy_acl_role_label = &copy_acl_role_label_compat;
65455+ copy_acl_ip_label = &copy_acl_ip_label_compat;
65456+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
65457+ copy_role_transition = &copy_role_transition_compat;
65458+ copy_sprole_pw = &copy_sprole_pw_compat;
65459+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
65460+ copy_pointer_from_array = &copy_pointer_from_array_compat;
65461+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
65462+ } else {
65463+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
65464+ copy_gr_arg = &copy_gr_arg_normal;
65465+ copy_acl_object_label = &copy_acl_object_label_normal;
65466+ copy_acl_subject_label = &copy_acl_subject_label_normal;
65467+ copy_acl_role_label = &copy_acl_role_label_normal;
65468+ copy_acl_ip_label = &copy_acl_ip_label_normal;
65469+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
65470+ copy_role_transition = &copy_role_transition_normal;
65471+ copy_sprole_pw = &copy_sprole_pw_normal;
65472+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
65473+ copy_pointer_from_array = &copy_pointer_from_array_normal;
65474+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
65475+ }
65476+ pax_close_kernel();
65477+#endif
65478+
65479+ req_count = get_gr_arg_wrapper_size();
65480+
65481+ if (count != req_count) {
65482+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
65483+ error = -EINVAL;
65484+ goto out;
65485+ }
65486+
65487+
65488+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
65489+ gr_auth_expires = 0;
65490+ gr_auth_attempts = 0;
65491+ }
65492+
65493+ error = copy_gr_arg_wrapper(buf, &uwrap);
65494+ if (error)
65495+ goto out;
65496+
65497+ error = copy_gr_arg(uwrap.arg, gr_usermode);
65498+ if (error)
65499+ goto out;
65500+
65501+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65502+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65503+ time_after(gr_auth_expires, get_seconds())) {
65504+ error = -EBUSY;
65505+ goto out;
65506+ }
65507+
65508+ /* if non-root trying to do anything other than use a special role,
65509+ do not attempt authentication, do not count towards authentication
65510+ locking
65511+ */
65512+
65513+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
65514+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65515+ gr_is_global_nonroot(current_uid())) {
65516+ error = -EPERM;
65517+ goto out;
65518+ }
65519+
65520+ /* ensure pw and special role name are null terminated */
65521+
65522+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
65523+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
65524+
65525+ /* Okay.
65526+ * We have our enough of the argument structure..(we have yet
65527+ * to copy_from_user the tables themselves) . Copy the tables
65528+ * only if we need them, i.e. for loading operations. */
65529+
65530+ switch (gr_usermode->mode) {
65531+ case GR_STATUS:
65532+ if (gr_status & GR_READY) {
65533+ error = 1;
65534+ if (!gr_check_secure_terminal(current))
65535+ error = 3;
65536+ } else
65537+ error = 2;
65538+ goto out;
65539+ case GR_SHUTDOWN:
65540+ if ((gr_status & GR_READY)
65541+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65542+ stop_machine(gr_rbac_disable, NULL, NULL);
65543+ free_variables();
65544+ memset(gr_usermode, 0, sizeof (struct gr_arg));
65545+ memset(gr_system_salt, 0, GR_SALT_LEN);
65546+ memset(gr_system_sum, 0, GR_SHA_LEN);
65547+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
65548+ } else if (gr_status & GR_READY) {
65549+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
65550+ error = -EPERM;
65551+ } else {
65552+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
65553+ error = -EAGAIN;
65554+ }
65555+ break;
65556+ case GR_ENABLE:
65557+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
65558+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
65559+ else {
65560+ if (gr_status & GR_READY)
65561+ error = -EAGAIN;
65562+ else
65563+ error = error2;
65564+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
65565+ }
65566+ break;
65567+ case GR_RELOAD:
65568+ if (!(gr_status & GR_READY)) {
65569+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
65570+ error = -EAGAIN;
65571+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65572+ stop_machine(gr_rbac_disable, NULL, NULL);
65573+ free_variables();
65574+ error2 = gracl_init(gr_usermode);
65575+ if (!error2)
65576+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
65577+ else {
65578+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65579+ error = error2;
65580+ }
65581+ } else {
65582+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65583+ error = -EPERM;
65584+ }
65585+ break;
65586+ case GR_SEGVMOD:
65587+ if (unlikely(!(gr_status & GR_READY))) {
65588+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
65589+ error = -EAGAIN;
65590+ break;
65591+ }
65592+
65593+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65594+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
65595+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
65596+ struct acl_subject_label *segvacl;
65597+ segvacl =
65598+ lookup_acl_subj_label(gr_usermode->segv_inode,
65599+ gr_usermode->segv_device,
65600+ current->role);
65601+ if (segvacl) {
65602+ segvacl->crashes = 0;
65603+ segvacl->expires = 0;
65604+ }
65605+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
65606+ gr_remove_uid(gr_usermode->segv_uid);
65607+ }
65608+ } else {
65609+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
65610+ error = -EPERM;
65611+ }
65612+ break;
65613+ case GR_SPROLE:
65614+ case GR_SPROLEPAM:
65615+ if (unlikely(!(gr_status & GR_READY))) {
65616+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
65617+ error = -EAGAIN;
65618+ break;
65619+ }
65620+
65621+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
65622+ current->role->expires = 0;
65623+ current->role->auth_attempts = 0;
65624+ }
65625+
65626+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65627+ time_after(current->role->expires, get_seconds())) {
65628+ error = -EBUSY;
65629+ goto out;
65630+ }
65631+
65632+ if (lookup_special_role_auth
65633+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
65634+ && ((!sprole_salt && !sprole_sum)
65635+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
65636+ char *p = "";
65637+ assign_special_role(gr_usermode->sp_role);
65638+ read_lock(&tasklist_lock);
65639+ if (current->real_parent)
65640+ p = current->real_parent->role->rolename;
65641+ read_unlock(&tasklist_lock);
65642+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
65643+ p, acl_sp_role_value);
65644+ } else {
65645+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
65646+ error = -EPERM;
65647+ if(!(current->role->auth_attempts++))
65648+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65649+
65650+ goto out;
65651+ }
65652+ break;
65653+ case GR_UNSPROLE:
65654+ if (unlikely(!(gr_status & GR_READY))) {
65655+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
65656+ error = -EAGAIN;
65657+ break;
65658+ }
65659+
65660+ if (current->role->roletype & GR_ROLE_SPECIAL) {
65661+ char *p = "";
65662+ int i = 0;
65663+
65664+ read_lock(&tasklist_lock);
65665+ if (current->real_parent) {
65666+ p = current->real_parent->role->rolename;
65667+ i = current->real_parent->acl_role_id;
65668+ }
65669+ read_unlock(&tasklist_lock);
65670+
65671+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
65672+ gr_set_acls(1);
65673+ } else {
65674+ error = -EPERM;
65675+ goto out;
65676+ }
65677+ break;
65678+ default:
65679+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
65680+ error = -EINVAL;
65681+ break;
65682+ }
65683+
65684+ if (error != -EPERM)
65685+ goto out;
65686+
65687+ if(!(gr_auth_attempts++))
65688+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65689+
65690+ out:
65691+ mutex_unlock(&gr_dev_mutex);
65692+
65693+ if (!error)
65694+ error = req_count;
65695+
65696+ return error;
65697+}
65698+
65699+/* must be called with
65700+ rcu_read_lock();
65701+ read_lock(&tasklist_lock);
65702+ read_lock(&grsec_exec_file_lock);
65703+*/
65704+int gr_apply_subject_to_task(struct task_struct *task)
65705+{
65706+ struct acl_object_label *obj;
65707+ char *tmpname;
65708+ struct acl_subject_label *tmpsubj;
65709+ struct file *filp;
65710+ struct name_entry *nmatch;
65711+
65712+ filp = task->exec_file;
65713+ if (filp == NULL)
65714+ return 0;
65715+
65716+ /* the following is to apply the correct subject
65717+ on binaries running when the RBAC system
65718+ is enabled, when the binaries have been
65719+ replaced or deleted since their execution
65720+ -----
65721+ when the RBAC system starts, the inode/dev
65722+ from exec_file will be one the RBAC system
65723+ is unaware of. It only knows the inode/dev
65724+ of the present file on disk, or the absence
65725+ of it.
65726+ */
65727+ preempt_disable();
65728+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
65729+
65730+ nmatch = lookup_name_entry(tmpname);
65731+ preempt_enable();
65732+ tmpsubj = NULL;
65733+ if (nmatch) {
65734+ if (nmatch->deleted)
65735+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
65736+ else
65737+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
65738+ if (tmpsubj != NULL)
65739+ task->acl = tmpsubj;
65740+ }
65741+ if (tmpsubj == NULL)
65742+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
65743+ task->role);
65744+ if (task->acl) {
65745+ task->is_writable = 0;
65746+ /* ignore additional mmap checks for processes that are writable
65747+ by the default ACL */
65748+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65749+ if (unlikely(obj->mode & GR_WRITE))
65750+ task->is_writable = 1;
65751+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
65752+ if (unlikely(obj->mode & GR_WRITE))
65753+ task->is_writable = 1;
65754+
65755+ gr_set_proc_res(task);
65756+
65757+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65758+ 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);
65759+#endif
65760+ } else {
65761+ return 1;
65762+ }
65763+
65764+ return 0;
65765+}
65766+
65767+int
65768+gr_set_acls(const int type)
65769+{
65770+ struct task_struct *task, *task2;
65771+ struct acl_role_label *role = current->role;
65772+ __u16 acl_role_id = current->acl_role_id;
65773+ const struct cred *cred;
65774+ int ret;
65775+
65776+ rcu_read_lock();
65777+ read_lock(&tasklist_lock);
65778+ read_lock(&grsec_exec_file_lock);
65779+ do_each_thread(task2, task) {
65780+ /* check to see if we're called from the exit handler,
65781+ if so, only replace ACLs that have inherited the admin
65782+ ACL */
65783+
65784+ if (type && (task->role != role ||
65785+ task->acl_role_id != acl_role_id))
65786+ continue;
65787+
65788+ task->acl_role_id = 0;
65789+ task->acl_sp_role = 0;
65790+
65791+ if (task->exec_file) {
65792+ cred = __task_cred(task);
65793+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
65794+ ret = gr_apply_subject_to_task(task);
65795+ if (ret) {
65796+ read_unlock(&grsec_exec_file_lock);
65797+ read_unlock(&tasklist_lock);
65798+ rcu_read_unlock();
65799+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
65800+ return ret;
65801+ }
65802+ } else {
65803+ // it's a kernel process
65804+ task->role = kernel_role;
65805+ task->acl = kernel_role->root_label;
65806+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
65807+ task->acl->mode &= ~GR_PROCFIND;
65808+#endif
65809+ }
65810+ } while_each_thread(task2, task);
65811+ read_unlock(&grsec_exec_file_lock);
65812+ read_unlock(&tasklist_lock);
65813+ rcu_read_unlock();
65814+
65815+ return 0;
65816+}
65817+
65818+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
65819+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
65820+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
65821+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
65822+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
65823+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
65824+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
65825+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
65826+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
65827+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
65828+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
65829+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
65830+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
65831+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
65832+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
65833+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
65834+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
65835+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
65836+};
65837+
65838+void
65839+gr_learn_resource(const struct task_struct *task,
65840+ const int res, const unsigned long wanted, const int gt)
65841+{
65842+ struct acl_subject_label *acl;
65843+ const struct cred *cred;
65844+
65845+ if (unlikely((gr_status & GR_READY) &&
65846+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
65847+ goto skip_reslog;
65848+
65849+ gr_log_resource(task, res, wanted, gt);
65850+skip_reslog:
65851+
65852+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
65853+ return;
65854+
65855+ acl = task->acl;
65856+
65857+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
65858+ !(acl->resmask & (1U << (unsigned short) res))))
65859+ return;
65860+
65861+ if (wanted >= acl->res[res].rlim_cur) {
65862+ unsigned long res_add;
65863+
65864+ res_add = wanted + res_learn_bumps[res];
65865+
65866+ acl->res[res].rlim_cur = res_add;
65867+
65868+ if (wanted > acl->res[res].rlim_max)
65869+ acl->res[res].rlim_max = res_add;
65870+
65871+ /* only log the subject filename, since resource logging is supported for
65872+ single-subject learning only */
65873+ rcu_read_lock();
65874+ cred = __task_cred(task);
65875+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
65876+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
65877+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
65878+ "", (unsigned long) res, &task->signal->saved_ip);
65879+ rcu_read_unlock();
65880+ }
65881+
65882+ return;
65883+}
65884+EXPORT_SYMBOL(gr_learn_resource);
65885+#endif
65886+
65887+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
65888+void
65889+pax_set_initial_flags(struct linux_binprm *bprm)
65890+{
65891+ struct task_struct *task = current;
65892+ struct acl_subject_label *proc;
65893+ unsigned long flags;
65894+
65895+ if (unlikely(!(gr_status & GR_READY)))
65896+ return;
65897+
65898+ flags = pax_get_flags(task);
65899+
65900+ proc = task->acl;
65901+
65902+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
65903+ flags &= ~MF_PAX_PAGEEXEC;
65904+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
65905+ flags &= ~MF_PAX_SEGMEXEC;
65906+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
65907+ flags &= ~MF_PAX_RANDMMAP;
65908+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
65909+ flags &= ~MF_PAX_EMUTRAMP;
65910+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
65911+ flags &= ~MF_PAX_MPROTECT;
65912+
65913+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
65914+ flags |= MF_PAX_PAGEEXEC;
65915+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
65916+ flags |= MF_PAX_SEGMEXEC;
65917+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
65918+ flags |= MF_PAX_RANDMMAP;
65919+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
65920+ flags |= MF_PAX_EMUTRAMP;
65921+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
65922+ flags |= MF_PAX_MPROTECT;
65923+
65924+ pax_set_flags(task, flags);
65925+
65926+ return;
65927+}
65928+#endif
65929+
65930+int
65931+gr_handle_proc_ptrace(struct task_struct *task)
65932+{
65933+ struct file *filp;
65934+ struct task_struct *tmp = task;
65935+ struct task_struct *curtemp = current;
65936+ __u32 retmode;
65937+
65938+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65939+ if (unlikely(!(gr_status & GR_READY)))
65940+ return 0;
65941+#endif
65942+
65943+ read_lock(&tasklist_lock);
65944+ read_lock(&grsec_exec_file_lock);
65945+ filp = task->exec_file;
65946+
65947+ while (task_pid_nr(tmp) > 0) {
65948+ if (tmp == curtemp)
65949+ break;
65950+ tmp = tmp->real_parent;
65951+ }
65952+
65953+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65954+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
65955+ read_unlock(&grsec_exec_file_lock);
65956+ read_unlock(&tasklist_lock);
65957+ return 1;
65958+ }
65959+
65960+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65961+ if (!(gr_status & GR_READY)) {
65962+ read_unlock(&grsec_exec_file_lock);
65963+ read_unlock(&tasklist_lock);
65964+ return 0;
65965+ }
65966+#endif
65967+
65968+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
65969+ read_unlock(&grsec_exec_file_lock);
65970+ read_unlock(&tasklist_lock);
65971+
65972+ if (retmode & GR_NOPTRACE)
65973+ return 1;
65974+
65975+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
65976+ && (current->acl != task->acl || (current->acl != current->role->root_label
65977+ && task_pid_nr(current) != task_pid_nr(task))))
65978+ return 1;
65979+
65980+ return 0;
65981+}
65982+
65983+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
65984+{
65985+ if (unlikely(!(gr_status & GR_READY)))
65986+ return;
65987+
65988+ if (!(current->role->roletype & GR_ROLE_GOD))
65989+ return;
65990+
65991+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
65992+ p->role->rolename, gr_task_roletype_to_char(p),
65993+ p->acl->filename);
65994+}
65995+
65996+int
65997+gr_handle_ptrace(struct task_struct *task, const long request)
65998+{
65999+ struct task_struct *tmp = task;
66000+ struct task_struct *curtemp = current;
66001+ __u32 retmode;
66002+
66003+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
66004+ if (unlikely(!(gr_status & GR_READY)))
66005+ return 0;
66006+#endif
66007+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
66008+ read_lock(&tasklist_lock);
66009+ while (task_pid_nr(tmp) > 0) {
66010+ if (tmp == curtemp)
66011+ break;
66012+ tmp = tmp->real_parent;
66013+ }
66014+
66015+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
66016+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
66017+ read_unlock(&tasklist_lock);
66018+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
66019+ return 1;
66020+ }
66021+ read_unlock(&tasklist_lock);
66022+ }
66023+
66024+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
66025+ if (!(gr_status & GR_READY))
66026+ return 0;
66027+#endif
66028+
66029+ read_lock(&grsec_exec_file_lock);
66030+ if (unlikely(!task->exec_file)) {
66031+ read_unlock(&grsec_exec_file_lock);
66032+ return 0;
66033+ }
66034+
66035+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
66036+ read_unlock(&grsec_exec_file_lock);
66037+
66038+ if (retmode & GR_NOPTRACE) {
66039+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
66040+ return 1;
66041+ }
66042+
66043+ if (retmode & GR_PTRACERD) {
66044+ switch (request) {
66045+ case PTRACE_SEIZE:
66046+ case PTRACE_POKETEXT:
66047+ case PTRACE_POKEDATA:
66048+ case PTRACE_POKEUSR:
66049+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
66050+ case PTRACE_SETREGS:
66051+ case PTRACE_SETFPREGS:
66052+#endif
66053+#ifdef CONFIG_X86
66054+ case PTRACE_SETFPXREGS:
66055+#endif
66056+#ifdef CONFIG_ALTIVEC
66057+ case PTRACE_SETVRREGS:
66058+#endif
66059+ return 1;
66060+ default:
66061+ return 0;
66062+ }
66063+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
66064+ !(current->role->roletype & GR_ROLE_GOD) &&
66065+ (current->acl != task->acl)) {
66066+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
66067+ return 1;
66068+ }
66069+
66070+ return 0;
66071+}
66072+
66073+static int is_writable_mmap(const struct file *filp)
66074+{
66075+ struct task_struct *task = current;
66076+ struct acl_object_label *obj, *obj2;
66077+
66078+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
66079+ !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))) {
66080+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
66081+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
66082+ task->role->root_label);
66083+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
66084+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
66085+ return 1;
66086+ }
66087+ }
66088+ return 0;
66089+}
66090+
66091+int
66092+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
66093+{
66094+ __u32 mode;
66095+
66096+ if (unlikely(!file || !(prot & PROT_EXEC)))
66097+ return 1;
66098+
66099+ if (is_writable_mmap(file))
66100+ return 0;
66101+
66102+ mode =
66103+ gr_search_file(file->f_path.dentry,
66104+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66105+ file->f_path.mnt);
66106+
66107+ if (!gr_tpe_allow(file))
66108+ return 0;
66109+
66110+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66111+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66112+ return 0;
66113+ } else if (unlikely(!(mode & GR_EXEC))) {
66114+ return 0;
66115+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66116+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66117+ return 1;
66118+ }
66119+
66120+ return 1;
66121+}
66122+
66123+int
66124+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
66125+{
66126+ __u32 mode;
66127+
66128+ if (unlikely(!file || !(prot & PROT_EXEC)))
66129+ return 1;
66130+
66131+ if (is_writable_mmap(file))
66132+ return 0;
66133+
66134+ mode =
66135+ gr_search_file(file->f_path.dentry,
66136+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66137+ file->f_path.mnt);
66138+
66139+ if (!gr_tpe_allow(file))
66140+ return 0;
66141+
66142+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66143+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66144+ return 0;
66145+ } else if (unlikely(!(mode & GR_EXEC))) {
66146+ return 0;
66147+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66148+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66149+ return 1;
66150+ }
66151+
66152+ return 1;
66153+}
66154+
66155+void
66156+gr_acl_handle_psacct(struct task_struct *task, const long code)
66157+{
66158+ unsigned long runtime;
66159+ unsigned long cputime;
66160+ unsigned int wday, cday;
66161+ __u8 whr, chr;
66162+ __u8 wmin, cmin;
66163+ __u8 wsec, csec;
66164+ struct timespec timeval;
66165+
66166+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
66167+ !(task->acl->mode & GR_PROCACCT)))
66168+ return;
66169+
66170+ do_posix_clock_monotonic_gettime(&timeval);
66171+ runtime = timeval.tv_sec - task->start_time.tv_sec;
66172+ wday = runtime / (3600 * 24);
66173+ runtime -= wday * (3600 * 24);
66174+ whr = runtime / 3600;
66175+ runtime -= whr * 3600;
66176+ wmin = runtime / 60;
66177+ runtime -= wmin * 60;
66178+ wsec = runtime;
66179+
66180+ cputime = (task->utime + task->stime) / HZ;
66181+ cday = cputime / (3600 * 24);
66182+ cputime -= cday * (3600 * 24);
66183+ chr = cputime / 3600;
66184+ cputime -= chr * 3600;
66185+ cmin = cputime / 60;
66186+ cputime -= cmin * 60;
66187+ csec = cputime;
66188+
66189+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
66190+
66191+ return;
66192+}
66193+
66194+void gr_set_kernel_label(struct task_struct *task)
66195+{
66196+ if (gr_status & GR_READY) {
66197+ task->role = kernel_role;
66198+ task->acl = kernel_role->root_label;
66199+ }
66200+ return;
66201+}
66202+
66203+#ifdef CONFIG_TASKSTATS
66204+int gr_is_taskstats_denied(int pid)
66205+{
66206+ struct task_struct *task;
66207+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66208+ const struct cred *cred;
66209+#endif
66210+ int ret = 0;
66211+
66212+ /* restrict taskstats viewing to un-chrooted root users
66213+ who have the 'view' subject flag if the RBAC system is enabled
66214+ */
66215+
66216+ rcu_read_lock();
66217+ read_lock(&tasklist_lock);
66218+ task = find_task_by_vpid(pid);
66219+ if (task) {
66220+#ifdef CONFIG_GRKERNSEC_CHROOT
66221+ if (proc_is_chrooted(task))
66222+ ret = -EACCES;
66223+#endif
66224+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66225+ cred = __task_cred(task);
66226+#ifdef CONFIG_GRKERNSEC_PROC_USER
66227+ if (gr_is_global_nonroot(cred->uid))
66228+ ret = -EACCES;
66229+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66230+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
66231+ ret = -EACCES;
66232+#endif
66233+#endif
66234+ if (gr_status & GR_READY) {
66235+ if (!(task->acl->mode & GR_VIEW))
66236+ ret = -EACCES;
66237+ }
66238+ } else
66239+ ret = -ENOENT;
66240+
66241+ read_unlock(&tasklist_lock);
66242+ rcu_read_unlock();
66243+
66244+ return ret;
66245+}
66246+#endif
66247+
66248+/* AUXV entries are filled via a descendant of search_binary_handler
66249+ after we've already applied the subject for the target
66250+*/
66251+int gr_acl_enable_at_secure(void)
66252+{
66253+ if (unlikely(!(gr_status & GR_READY)))
66254+ return 0;
66255+
66256+ if (current->acl->mode & GR_ATSECURE)
66257+ return 1;
66258+
66259+ return 0;
66260+}
66261+
66262+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
66263+{
66264+ struct task_struct *task = current;
66265+ struct dentry *dentry = file->f_path.dentry;
66266+ struct vfsmount *mnt = file->f_path.mnt;
66267+ struct acl_object_label *obj, *tmp;
66268+ struct acl_subject_label *subj;
66269+ unsigned int bufsize;
66270+ int is_not_root;
66271+ char *path;
66272+ dev_t dev = __get_dev(dentry);
66273+
66274+ if (unlikely(!(gr_status & GR_READY)))
66275+ return 1;
66276+
66277+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66278+ return 1;
66279+
66280+ /* ignore Eric Biederman */
66281+ if (IS_PRIVATE(dentry->d_inode))
66282+ return 1;
66283+
66284+ subj = task->acl;
66285+ read_lock(&gr_inode_lock);
66286+ do {
66287+ obj = lookup_acl_obj_label(ino, dev, subj);
66288+ if (obj != NULL) {
66289+ read_unlock(&gr_inode_lock);
66290+ return (obj->mode & GR_FIND) ? 1 : 0;
66291+ }
66292+ } while ((subj = subj->parent_subject));
66293+ read_unlock(&gr_inode_lock);
66294+
66295+ /* this is purely an optimization since we're looking for an object
66296+ for the directory we're doing a readdir on
66297+ if it's possible for any globbed object to match the entry we're
66298+ filling into the directory, then the object we find here will be
66299+ an anchor point with attached globbed objects
66300+ */
66301+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
66302+ if (obj->globbed == NULL)
66303+ return (obj->mode & GR_FIND) ? 1 : 0;
66304+
66305+ is_not_root = ((obj->filename[0] == '/') &&
66306+ (obj->filename[1] == '\0')) ? 0 : 1;
66307+ bufsize = PAGE_SIZE - namelen - is_not_root;
66308+
66309+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
66310+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
66311+ return 1;
66312+
66313+ preempt_disable();
66314+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66315+ bufsize);
66316+
66317+ bufsize = strlen(path);
66318+
66319+ /* if base is "/", don't append an additional slash */
66320+ if (is_not_root)
66321+ *(path + bufsize) = '/';
66322+ memcpy(path + bufsize + is_not_root, name, namelen);
66323+ *(path + bufsize + namelen + is_not_root) = '\0';
66324+
66325+ tmp = obj->globbed;
66326+ while (tmp) {
66327+ if (!glob_match(tmp->filename, path)) {
66328+ preempt_enable();
66329+ return (tmp->mode & GR_FIND) ? 1 : 0;
66330+ }
66331+ tmp = tmp->next;
66332+ }
66333+ preempt_enable();
66334+ return (obj->mode & GR_FIND) ? 1 : 0;
66335+}
66336+
66337+void gr_put_exec_file(struct task_struct *task)
66338+{
66339+ struct file *filp;
66340+
66341+ write_lock(&grsec_exec_file_lock);
66342+ filp = task->exec_file;
66343+ task->exec_file = NULL;
66344+ write_unlock(&grsec_exec_file_lock);
66345+
66346+ if (filp)
66347+ fput(filp);
66348+
66349+ return;
66350+}
66351+
66352+
66353+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
66354+EXPORT_SYMBOL(gr_acl_is_enabled);
66355+#endif
66356+EXPORT_SYMBOL(gr_set_kernel_label);
66357+#ifdef CONFIG_SECURITY
66358+EXPORT_SYMBOL(gr_check_user_change);
66359+EXPORT_SYMBOL(gr_check_group_change);
66360+#endif
66361+
66362diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
66363new file mode 100644
66364index 0000000..34fefda
66365--- /dev/null
66366+++ b/grsecurity/gracl_alloc.c
66367@@ -0,0 +1,105 @@
66368+#include <linux/kernel.h>
66369+#include <linux/mm.h>
66370+#include <linux/slab.h>
66371+#include <linux/vmalloc.h>
66372+#include <linux/gracl.h>
66373+#include <linux/grsecurity.h>
66374+
66375+static unsigned long alloc_stack_next = 1;
66376+static unsigned long alloc_stack_size = 1;
66377+static void **alloc_stack;
66378+
66379+static __inline__ int
66380+alloc_pop(void)
66381+{
66382+ if (alloc_stack_next == 1)
66383+ return 0;
66384+
66385+ kfree(alloc_stack[alloc_stack_next - 2]);
66386+
66387+ alloc_stack_next--;
66388+
66389+ return 1;
66390+}
66391+
66392+static __inline__ int
66393+alloc_push(void *buf)
66394+{
66395+ if (alloc_stack_next >= alloc_stack_size)
66396+ return 1;
66397+
66398+ alloc_stack[alloc_stack_next - 1] = buf;
66399+
66400+ alloc_stack_next++;
66401+
66402+ return 0;
66403+}
66404+
66405+void *
66406+acl_alloc(unsigned long len)
66407+{
66408+ void *ret = NULL;
66409+
66410+ if (!len || len > PAGE_SIZE)
66411+ goto out;
66412+
66413+ ret = kmalloc(len, GFP_KERNEL);
66414+
66415+ if (ret) {
66416+ if (alloc_push(ret)) {
66417+ kfree(ret);
66418+ ret = NULL;
66419+ }
66420+ }
66421+
66422+out:
66423+ return ret;
66424+}
66425+
66426+void *
66427+acl_alloc_num(unsigned long num, unsigned long len)
66428+{
66429+ if (!len || (num > (PAGE_SIZE / len)))
66430+ return NULL;
66431+
66432+ return acl_alloc(num * len);
66433+}
66434+
66435+void
66436+acl_free_all(void)
66437+{
66438+ if (gr_acl_is_enabled() || !alloc_stack)
66439+ return;
66440+
66441+ while (alloc_pop()) ;
66442+
66443+ if (alloc_stack) {
66444+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
66445+ kfree(alloc_stack);
66446+ else
66447+ vfree(alloc_stack);
66448+ }
66449+
66450+ alloc_stack = NULL;
66451+ alloc_stack_size = 1;
66452+ alloc_stack_next = 1;
66453+
66454+ return;
66455+}
66456+
66457+int
66458+acl_alloc_stack_init(unsigned long size)
66459+{
66460+ if ((size * sizeof (void *)) <= PAGE_SIZE)
66461+ alloc_stack =
66462+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
66463+ else
66464+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
66465+
66466+ alloc_stack_size = size;
66467+
66468+ if (!alloc_stack)
66469+ return 0;
66470+ else
66471+ return 1;
66472+}
66473diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
66474new file mode 100644
66475index 0000000..bdd51ea
66476--- /dev/null
66477+++ b/grsecurity/gracl_cap.c
66478@@ -0,0 +1,110 @@
66479+#include <linux/kernel.h>
66480+#include <linux/module.h>
66481+#include <linux/sched.h>
66482+#include <linux/gracl.h>
66483+#include <linux/grsecurity.h>
66484+#include <linux/grinternal.h>
66485+
66486+extern const char *captab_log[];
66487+extern int captab_log_entries;
66488+
66489+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
66490+{
66491+ struct acl_subject_label *curracl;
66492+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66493+ kernel_cap_t cap_audit = __cap_empty_set;
66494+
66495+ if (!gr_acl_is_enabled())
66496+ return 1;
66497+
66498+ curracl = task->acl;
66499+
66500+ cap_drop = curracl->cap_lower;
66501+ cap_mask = curracl->cap_mask;
66502+ cap_audit = curracl->cap_invert_audit;
66503+
66504+ while ((curracl = curracl->parent_subject)) {
66505+ /* if the cap isn't specified in the current computed mask but is specified in the
66506+ current level subject, and is lowered in the current level subject, then add
66507+ it to the set of dropped capabilities
66508+ otherwise, add the current level subject's mask to the current computed mask
66509+ */
66510+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66511+ cap_raise(cap_mask, cap);
66512+ if (cap_raised(curracl->cap_lower, cap))
66513+ cap_raise(cap_drop, cap);
66514+ if (cap_raised(curracl->cap_invert_audit, cap))
66515+ cap_raise(cap_audit, cap);
66516+ }
66517+ }
66518+
66519+ if (!cap_raised(cap_drop, cap)) {
66520+ if (cap_raised(cap_audit, cap))
66521+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
66522+ return 1;
66523+ }
66524+
66525+ curracl = task->acl;
66526+
66527+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
66528+ && cap_raised(cred->cap_effective, cap)) {
66529+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
66530+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
66531+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
66532+ gr_to_filename(task->exec_file->f_path.dentry,
66533+ task->exec_file->f_path.mnt) : curracl->filename,
66534+ curracl->filename, 0UL,
66535+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
66536+ return 1;
66537+ }
66538+
66539+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
66540+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
66541+
66542+ return 0;
66543+}
66544+
66545+int
66546+gr_acl_is_capable(const int cap)
66547+{
66548+ return gr_task_acl_is_capable(current, current_cred(), cap);
66549+}
66550+
66551+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
66552+{
66553+ struct acl_subject_label *curracl;
66554+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66555+
66556+ if (!gr_acl_is_enabled())
66557+ return 1;
66558+
66559+ curracl = task->acl;
66560+
66561+ cap_drop = curracl->cap_lower;
66562+ cap_mask = curracl->cap_mask;
66563+
66564+ while ((curracl = curracl->parent_subject)) {
66565+ /* if the cap isn't specified in the current computed mask but is specified in the
66566+ current level subject, and is lowered in the current level subject, then add
66567+ it to the set of dropped capabilities
66568+ otherwise, add the current level subject's mask to the current computed mask
66569+ */
66570+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66571+ cap_raise(cap_mask, cap);
66572+ if (cap_raised(curracl->cap_lower, cap))
66573+ cap_raise(cap_drop, cap);
66574+ }
66575+ }
66576+
66577+ if (!cap_raised(cap_drop, cap))
66578+ return 1;
66579+
66580+ return 0;
66581+}
66582+
66583+int
66584+gr_acl_is_capable_nolog(const int cap)
66585+{
66586+ return gr_task_acl_is_capable_nolog(current, cap);
66587+}
66588+
66589diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
66590new file mode 100644
66591index 0000000..a43dd06
66592--- /dev/null
66593+++ b/grsecurity/gracl_compat.c
66594@@ -0,0 +1,269 @@
66595+#include <linux/kernel.h>
66596+#include <linux/gracl.h>
66597+#include <linux/compat.h>
66598+#include <linux/gracl_compat.h>
66599+
66600+#include <asm/uaccess.h>
66601+
66602+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
66603+{
66604+ struct gr_arg_wrapper_compat uwrapcompat;
66605+
66606+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
66607+ return -EFAULT;
66608+
66609+ if ((uwrapcompat.version != GRSECURITY_VERSION) ||
66610+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
66611+ return -EINVAL;
66612+
66613+ uwrap->arg = compat_ptr(uwrapcompat.arg);
66614+ uwrap->version = uwrapcompat.version;
66615+ uwrap->size = sizeof(struct gr_arg);
66616+
66617+ return 0;
66618+}
66619+
66620+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
66621+{
66622+ struct gr_arg_compat argcompat;
66623+
66624+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
66625+ return -EFAULT;
66626+
66627+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
66628+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
66629+ arg->role_db.num_roles = argcompat.role_db.num_roles;
66630+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
66631+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
66632+ arg->role_db.num_objects = argcompat.role_db.num_objects;
66633+
66634+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
66635+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
66636+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
66637+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
66638+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
66639+ arg->segv_device = argcompat.segv_device;
66640+ arg->segv_inode = argcompat.segv_inode;
66641+ arg->segv_uid = argcompat.segv_uid;
66642+ arg->num_sprole_pws = argcompat.num_sprole_pws;
66643+ arg->mode = argcompat.mode;
66644+
66645+ return 0;
66646+}
66647+
66648+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
66649+{
66650+ struct acl_object_label_compat objcompat;
66651+
66652+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
66653+ return -EFAULT;
66654+
66655+ obj->filename = compat_ptr(objcompat.filename);
66656+ obj->inode = objcompat.inode;
66657+ obj->device = objcompat.device;
66658+ obj->mode = objcompat.mode;
66659+
66660+ obj->nested = compat_ptr(objcompat.nested);
66661+ obj->globbed = compat_ptr(objcompat.globbed);
66662+
66663+ obj->prev = compat_ptr(objcompat.prev);
66664+ obj->next = compat_ptr(objcompat.next);
66665+
66666+ return 0;
66667+}
66668+
66669+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
66670+{
66671+ unsigned int i;
66672+ struct acl_subject_label_compat subjcompat;
66673+
66674+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
66675+ return -EFAULT;
66676+
66677+ subj->filename = compat_ptr(subjcompat.filename);
66678+ subj->inode = subjcompat.inode;
66679+ subj->device = subjcompat.device;
66680+ subj->mode = subjcompat.mode;
66681+ subj->cap_mask = subjcompat.cap_mask;
66682+ subj->cap_lower = subjcompat.cap_lower;
66683+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
66684+
66685+ for (i = 0; i < GR_NLIMITS; i++) {
66686+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
66687+ subj->res[i].rlim_cur = RLIM_INFINITY;
66688+ else
66689+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
66690+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
66691+ subj->res[i].rlim_max = RLIM_INFINITY;
66692+ else
66693+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
66694+ }
66695+ subj->resmask = subjcompat.resmask;
66696+
66697+ subj->user_trans_type = subjcompat.user_trans_type;
66698+ subj->group_trans_type = subjcompat.group_trans_type;
66699+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
66700+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
66701+ subj->user_trans_num = subjcompat.user_trans_num;
66702+ subj->group_trans_num = subjcompat.group_trans_num;
66703+
66704+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
66705+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
66706+ subj->ip_type = subjcompat.ip_type;
66707+ subj->ips = compat_ptr(subjcompat.ips);
66708+ subj->ip_num = subjcompat.ip_num;
66709+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
66710+
66711+ subj->crashes = subjcompat.crashes;
66712+ subj->expires = subjcompat.expires;
66713+
66714+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
66715+ subj->hash = compat_ptr(subjcompat.hash);
66716+ subj->prev = compat_ptr(subjcompat.prev);
66717+ subj->next = compat_ptr(subjcompat.next);
66718+
66719+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
66720+ subj->obj_hash_size = subjcompat.obj_hash_size;
66721+ subj->pax_flags = subjcompat.pax_flags;
66722+
66723+ return 0;
66724+}
66725+
66726+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
66727+{
66728+ struct acl_role_label_compat rolecompat;
66729+
66730+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
66731+ return -EFAULT;
66732+
66733+ role->rolename = compat_ptr(rolecompat.rolename);
66734+ role->uidgid = rolecompat.uidgid;
66735+ role->roletype = rolecompat.roletype;
66736+
66737+ role->auth_attempts = rolecompat.auth_attempts;
66738+ role->expires = rolecompat.expires;
66739+
66740+ role->root_label = compat_ptr(rolecompat.root_label);
66741+ role->hash = compat_ptr(rolecompat.hash);
66742+
66743+ role->prev = compat_ptr(rolecompat.prev);
66744+ role->next = compat_ptr(rolecompat.next);
66745+
66746+ role->transitions = compat_ptr(rolecompat.transitions);
66747+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
66748+ role->domain_children = compat_ptr(rolecompat.domain_children);
66749+ role->domain_child_num = rolecompat.domain_child_num;
66750+
66751+ role->umask = rolecompat.umask;
66752+
66753+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
66754+ role->subj_hash_size = rolecompat.subj_hash_size;
66755+
66756+ return 0;
66757+}
66758+
66759+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
66760+{
66761+ struct role_allowed_ip_compat roleip_compat;
66762+
66763+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
66764+ return -EFAULT;
66765+
66766+ roleip->addr = roleip_compat.addr;
66767+ roleip->netmask = roleip_compat.netmask;
66768+
66769+ roleip->prev = compat_ptr(roleip_compat.prev);
66770+ roleip->next = compat_ptr(roleip_compat.next);
66771+
66772+ return 0;
66773+}
66774+
66775+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
66776+{
66777+ struct role_transition_compat trans_compat;
66778+
66779+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
66780+ return -EFAULT;
66781+
66782+ trans->rolename = compat_ptr(trans_compat.rolename);
66783+
66784+ trans->prev = compat_ptr(trans_compat.prev);
66785+ trans->next = compat_ptr(trans_compat.next);
66786+
66787+ return 0;
66788+
66789+}
66790+
66791+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
66792+{
66793+ struct gr_hash_struct_compat hash_compat;
66794+
66795+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
66796+ return -EFAULT;
66797+
66798+ hash->table = compat_ptr(hash_compat.table);
66799+ hash->nametable = compat_ptr(hash_compat.nametable);
66800+ hash->first = compat_ptr(hash_compat.first);
66801+
66802+ hash->table_size = hash_compat.table_size;
66803+ hash->used_size = hash_compat.used_size;
66804+
66805+ hash->type = hash_compat.type;
66806+
66807+ return 0;
66808+}
66809+
66810+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
66811+{
66812+ compat_uptr_t ptrcompat;
66813+
66814+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
66815+ return -EFAULT;
66816+
66817+ *(void **)ptr = compat_ptr(ptrcompat);
66818+
66819+ return 0;
66820+}
66821+
66822+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
66823+{
66824+ struct acl_ip_label_compat ip_compat;
66825+
66826+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
66827+ return -EFAULT;
66828+
66829+ ip->iface = compat_ptr(ip_compat.iface);
66830+ ip->addr = ip_compat.addr;
66831+ ip->netmask = ip_compat.netmask;
66832+ ip->low = ip_compat.low;
66833+ ip->high = ip_compat.high;
66834+ ip->mode = ip_compat.mode;
66835+ ip->type = ip_compat.type;
66836+
66837+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
66838+
66839+ ip->prev = compat_ptr(ip_compat.prev);
66840+ ip->next = compat_ptr(ip_compat.next);
66841+
66842+ return 0;
66843+}
66844+
66845+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
66846+{
66847+ struct sprole_pw_compat pw_compat;
66848+
66849+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
66850+ return -EFAULT;
66851+
66852+ pw->rolename = compat_ptr(pw_compat.rolename);
66853+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
66854+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
66855+
66856+ return 0;
66857+}
66858+
66859+size_t get_gr_arg_wrapper_size_compat(void)
66860+{
66861+ return sizeof(struct gr_arg_wrapper_compat);
66862+}
66863+
66864diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
66865new file mode 100644
66866index 0000000..a340c17
66867--- /dev/null
66868+++ b/grsecurity/gracl_fs.c
66869@@ -0,0 +1,431 @@
66870+#include <linux/kernel.h>
66871+#include <linux/sched.h>
66872+#include <linux/types.h>
66873+#include <linux/fs.h>
66874+#include <linux/file.h>
66875+#include <linux/stat.h>
66876+#include <linux/grsecurity.h>
66877+#include <linux/grinternal.h>
66878+#include <linux/gracl.h>
66879+
66880+umode_t
66881+gr_acl_umask(void)
66882+{
66883+ if (unlikely(!gr_acl_is_enabled()))
66884+ return 0;
66885+
66886+ return current->role->umask;
66887+}
66888+
66889+__u32
66890+gr_acl_handle_hidden_file(const struct dentry * dentry,
66891+ const struct vfsmount * mnt)
66892+{
66893+ __u32 mode;
66894+
66895+ if (unlikely(!dentry->d_inode))
66896+ return GR_FIND;
66897+
66898+ mode =
66899+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
66900+
66901+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
66902+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66903+ return mode;
66904+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
66905+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66906+ return 0;
66907+ } else if (unlikely(!(mode & GR_FIND)))
66908+ return 0;
66909+
66910+ return GR_FIND;
66911+}
66912+
66913+__u32
66914+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
66915+ int acc_mode)
66916+{
66917+ __u32 reqmode = GR_FIND;
66918+ __u32 mode;
66919+
66920+ if (unlikely(!dentry->d_inode))
66921+ return reqmode;
66922+
66923+ if (acc_mode & MAY_APPEND)
66924+ reqmode |= GR_APPEND;
66925+ else if (acc_mode & MAY_WRITE)
66926+ reqmode |= GR_WRITE;
66927+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
66928+ reqmode |= GR_READ;
66929+
66930+ mode =
66931+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66932+ mnt);
66933+
66934+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66935+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66936+ reqmode & GR_READ ? " reading" : "",
66937+ reqmode & GR_WRITE ? " writing" : reqmode &
66938+ GR_APPEND ? " appending" : "");
66939+ return reqmode;
66940+ } else
66941+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66942+ {
66943+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66944+ reqmode & GR_READ ? " reading" : "",
66945+ reqmode & GR_WRITE ? " writing" : reqmode &
66946+ GR_APPEND ? " appending" : "");
66947+ return 0;
66948+ } else if (unlikely((mode & reqmode) != reqmode))
66949+ return 0;
66950+
66951+ return reqmode;
66952+}
66953+
66954+__u32
66955+gr_acl_handle_creat(const struct dentry * dentry,
66956+ const struct dentry * p_dentry,
66957+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
66958+ const int imode)
66959+{
66960+ __u32 reqmode = GR_WRITE | GR_CREATE;
66961+ __u32 mode;
66962+
66963+ if (acc_mode & MAY_APPEND)
66964+ reqmode |= GR_APPEND;
66965+ // if a directory was required or the directory already exists, then
66966+ // don't count this open as a read
66967+ if ((acc_mode & MAY_READ) &&
66968+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
66969+ reqmode |= GR_READ;
66970+ if ((open_flags & O_CREAT) &&
66971+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
66972+ reqmode |= GR_SETID;
66973+
66974+ mode =
66975+ gr_check_create(dentry, p_dentry, p_mnt,
66976+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
66977+
66978+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66979+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66980+ reqmode & GR_READ ? " reading" : "",
66981+ reqmode & GR_WRITE ? " writing" : reqmode &
66982+ GR_APPEND ? " appending" : "");
66983+ return reqmode;
66984+ } else
66985+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66986+ {
66987+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66988+ reqmode & GR_READ ? " reading" : "",
66989+ reqmode & GR_WRITE ? " writing" : reqmode &
66990+ GR_APPEND ? " appending" : "");
66991+ return 0;
66992+ } else if (unlikely((mode & reqmode) != reqmode))
66993+ return 0;
66994+
66995+ return reqmode;
66996+}
66997+
66998+__u32
66999+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
67000+ const int fmode)
67001+{
67002+ __u32 mode, reqmode = GR_FIND;
67003+
67004+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
67005+ reqmode |= GR_EXEC;
67006+ if (fmode & S_IWOTH)
67007+ reqmode |= GR_WRITE;
67008+ if (fmode & S_IROTH)
67009+ reqmode |= GR_READ;
67010+
67011+ mode =
67012+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
67013+ mnt);
67014+
67015+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
67016+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
67017+ reqmode & GR_READ ? " reading" : "",
67018+ reqmode & GR_WRITE ? " writing" : "",
67019+ reqmode & GR_EXEC ? " executing" : "");
67020+ return reqmode;
67021+ } else
67022+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
67023+ {
67024+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
67025+ reqmode & GR_READ ? " reading" : "",
67026+ reqmode & GR_WRITE ? " writing" : "",
67027+ reqmode & GR_EXEC ? " executing" : "");
67028+ return 0;
67029+ } else if (unlikely((mode & reqmode) != reqmode))
67030+ return 0;
67031+
67032+ return reqmode;
67033+}
67034+
67035+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
67036+{
67037+ __u32 mode;
67038+
67039+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
67040+
67041+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
67042+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
67043+ return mode;
67044+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
67045+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
67046+ return 0;
67047+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
67048+ return 0;
67049+
67050+ return (reqmode);
67051+}
67052+
67053+__u32
67054+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
67055+{
67056+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
67057+}
67058+
67059+__u32
67060+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
67061+{
67062+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
67063+}
67064+
67065+__u32
67066+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
67067+{
67068+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
67069+}
67070+
67071+__u32
67072+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
67073+{
67074+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
67075+}
67076+
67077+__u32
67078+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
67079+ umode_t *modeptr)
67080+{
67081+ umode_t mode;
67082+
67083+ *modeptr &= ~gr_acl_umask();
67084+ mode = *modeptr;
67085+
67086+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
67087+ return 1;
67088+
67089+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
67090+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
67091+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
67092+ GR_CHMOD_ACL_MSG);
67093+ } else {
67094+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
67095+ }
67096+}
67097+
67098+__u32
67099+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
67100+{
67101+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
67102+}
67103+
67104+__u32
67105+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
67106+{
67107+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
67108+}
67109+
67110+__u32
67111+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
67112+{
67113+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
67114+}
67115+
67116+__u32
67117+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
67118+{
67119+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
67120+ GR_UNIXCONNECT_ACL_MSG);
67121+}
67122+
67123+/* hardlinks require at minimum create and link permission,
67124+ any additional privilege required is based on the
67125+ privilege of the file being linked to
67126+*/
67127+__u32
67128+gr_acl_handle_link(const struct dentry * new_dentry,
67129+ const struct dentry * parent_dentry,
67130+ const struct vfsmount * parent_mnt,
67131+ const struct dentry * old_dentry,
67132+ const struct vfsmount * old_mnt, const struct filename *to)
67133+{
67134+ __u32 mode;
67135+ __u32 needmode = GR_CREATE | GR_LINK;
67136+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
67137+
67138+ mode =
67139+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
67140+ old_mnt);
67141+
67142+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
67143+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67144+ return mode;
67145+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67146+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67147+ return 0;
67148+ } else if (unlikely((mode & needmode) != needmode))
67149+ return 0;
67150+
67151+ return 1;
67152+}
67153+
67154+__u32
67155+gr_acl_handle_symlink(const struct dentry * new_dentry,
67156+ const struct dentry * parent_dentry,
67157+ const struct vfsmount * parent_mnt, const struct filename *from)
67158+{
67159+ __u32 needmode = GR_WRITE | GR_CREATE;
67160+ __u32 mode;
67161+
67162+ mode =
67163+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
67164+ GR_CREATE | GR_AUDIT_CREATE |
67165+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
67166+
67167+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
67168+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67169+ return mode;
67170+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67171+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67172+ return 0;
67173+ } else if (unlikely((mode & needmode) != needmode))
67174+ return 0;
67175+
67176+ return (GR_WRITE | GR_CREATE);
67177+}
67178+
67179+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)
67180+{
67181+ __u32 mode;
67182+
67183+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
67184+
67185+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
67186+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
67187+ return mode;
67188+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
67189+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
67190+ return 0;
67191+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
67192+ return 0;
67193+
67194+ return (reqmode);
67195+}
67196+
67197+__u32
67198+gr_acl_handle_mknod(const struct dentry * new_dentry,
67199+ const struct dentry * parent_dentry,
67200+ const struct vfsmount * parent_mnt,
67201+ const int mode)
67202+{
67203+ __u32 reqmode = GR_WRITE | GR_CREATE;
67204+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
67205+ reqmode |= GR_SETID;
67206+
67207+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67208+ reqmode, GR_MKNOD_ACL_MSG);
67209+}
67210+
67211+__u32
67212+gr_acl_handle_mkdir(const struct dentry *new_dentry,
67213+ const struct dentry *parent_dentry,
67214+ const struct vfsmount *parent_mnt)
67215+{
67216+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67217+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
67218+}
67219+
67220+#define RENAME_CHECK_SUCCESS(old, new) \
67221+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
67222+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
67223+
67224+int
67225+gr_acl_handle_rename(struct dentry *new_dentry,
67226+ struct dentry *parent_dentry,
67227+ const struct vfsmount *parent_mnt,
67228+ struct dentry *old_dentry,
67229+ struct inode *old_parent_inode,
67230+ struct vfsmount *old_mnt, const struct filename *newname)
67231+{
67232+ __u32 comp1, comp2;
67233+ int error = 0;
67234+
67235+ if (unlikely(!gr_acl_is_enabled()))
67236+ return 0;
67237+
67238+ if (!new_dentry->d_inode) {
67239+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
67240+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
67241+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
67242+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
67243+ GR_DELETE | GR_AUDIT_DELETE |
67244+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67245+ GR_SUPPRESS, old_mnt);
67246+ } else {
67247+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
67248+ GR_CREATE | GR_DELETE |
67249+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
67250+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67251+ GR_SUPPRESS, parent_mnt);
67252+ comp2 =
67253+ gr_search_file(old_dentry,
67254+ GR_READ | GR_WRITE | GR_AUDIT_READ |
67255+ GR_DELETE | GR_AUDIT_DELETE |
67256+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
67257+ }
67258+
67259+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
67260+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
67261+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67262+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
67263+ && !(comp2 & GR_SUPPRESS)) {
67264+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67265+ error = -EACCES;
67266+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
67267+ error = -EACCES;
67268+
67269+ return error;
67270+}
67271+
67272+void
67273+gr_acl_handle_exit(void)
67274+{
67275+ u16 id;
67276+ char *rolename;
67277+
67278+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
67279+ !(current->role->roletype & GR_ROLE_PERSIST))) {
67280+ id = current->acl_role_id;
67281+ rolename = current->role->rolename;
67282+ gr_set_acls(1);
67283+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
67284+ }
67285+
67286+ gr_put_exec_file(current);
67287+ return;
67288+}
67289+
67290+int
67291+gr_acl_handle_procpidmem(const struct task_struct *task)
67292+{
67293+ if (unlikely(!gr_acl_is_enabled()))
67294+ return 0;
67295+
67296+ if (task != current && task->acl->mode & GR_PROTPROCFD)
67297+ return -EACCES;
67298+
67299+ return 0;
67300+}
67301diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
67302new file mode 100644
67303index 0000000..8132048
67304--- /dev/null
67305+++ b/grsecurity/gracl_ip.c
67306@@ -0,0 +1,387 @@
67307+#include <linux/kernel.h>
67308+#include <asm/uaccess.h>
67309+#include <asm/errno.h>
67310+#include <net/sock.h>
67311+#include <linux/file.h>
67312+#include <linux/fs.h>
67313+#include <linux/net.h>
67314+#include <linux/in.h>
67315+#include <linux/skbuff.h>
67316+#include <linux/ip.h>
67317+#include <linux/udp.h>
67318+#include <linux/types.h>
67319+#include <linux/sched.h>
67320+#include <linux/netdevice.h>
67321+#include <linux/inetdevice.h>
67322+#include <linux/gracl.h>
67323+#include <linux/grsecurity.h>
67324+#include <linux/grinternal.h>
67325+
67326+#define GR_BIND 0x01
67327+#define GR_CONNECT 0x02
67328+#define GR_INVERT 0x04
67329+#define GR_BINDOVERRIDE 0x08
67330+#define GR_CONNECTOVERRIDE 0x10
67331+#define GR_SOCK_FAMILY 0x20
67332+
67333+static const char * gr_protocols[IPPROTO_MAX] = {
67334+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
67335+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
67336+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
67337+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
67338+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
67339+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
67340+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
67341+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
67342+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
67343+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
67344+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
67345+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
67346+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
67347+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
67348+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
67349+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
67350+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
67351+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
67352+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
67353+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
67354+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
67355+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
67356+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
67357+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
67358+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
67359+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
67360+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
67361+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
67362+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
67363+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
67364+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
67365+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
67366+ };
67367+
67368+static const char * gr_socktypes[SOCK_MAX] = {
67369+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
67370+ "unknown:7", "unknown:8", "unknown:9", "packet"
67371+ };
67372+
67373+static const char * gr_sockfamilies[AF_MAX+1] = {
67374+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
67375+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
67376+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
67377+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
67378+ };
67379+
67380+const char *
67381+gr_proto_to_name(unsigned char proto)
67382+{
67383+ return gr_protocols[proto];
67384+}
67385+
67386+const char *
67387+gr_socktype_to_name(unsigned char type)
67388+{
67389+ return gr_socktypes[type];
67390+}
67391+
67392+const char *
67393+gr_sockfamily_to_name(unsigned char family)
67394+{
67395+ return gr_sockfamilies[family];
67396+}
67397+
67398+int
67399+gr_search_socket(const int domain, const int type, const int protocol)
67400+{
67401+ struct acl_subject_label *curr;
67402+ const struct cred *cred = current_cred();
67403+
67404+ if (unlikely(!gr_acl_is_enabled()))
67405+ goto exit;
67406+
67407+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
67408+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
67409+ goto exit; // let the kernel handle it
67410+
67411+ curr = current->acl;
67412+
67413+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
67414+ /* the family is allowed, if this is PF_INET allow it only if
67415+ the extra sock type/protocol checks pass */
67416+ if (domain == PF_INET)
67417+ goto inet_check;
67418+ goto exit;
67419+ } else {
67420+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67421+ __u32 fakeip = 0;
67422+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67423+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67424+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67425+ gr_to_filename(current->exec_file->f_path.dentry,
67426+ current->exec_file->f_path.mnt) :
67427+ curr->filename, curr->filename,
67428+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
67429+ &current->signal->saved_ip);
67430+ goto exit;
67431+ }
67432+ goto exit_fail;
67433+ }
67434+
67435+inet_check:
67436+ /* the rest of this checking is for IPv4 only */
67437+ if (!curr->ips)
67438+ goto exit;
67439+
67440+ if ((curr->ip_type & (1U << type)) &&
67441+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
67442+ goto exit;
67443+
67444+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67445+ /* we don't place acls on raw sockets , and sometimes
67446+ dgram/ip sockets are opened for ioctl and not
67447+ bind/connect, so we'll fake a bind learn log */
67448+ if (type == SOCK_RAW || type == SOCK_PACKET) {
67449+ __u32 fakeip = 0;
67450+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67451+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67452+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67453+ gr_to_filename(current->exec_file->f_path.dentry,
67454+ current->exec_file->f_path.mnt) :
67455+ curr->filename, curr->filename,
67456+ &fakeip, 0, type,
67457+ protocol, GR_CONNECT, &current->signal->saved_ip);
67458+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
67459+ __u32 fakeip = 0;
67460+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67461+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67462+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67463+ gr_to_filename(current->exec_file->f_path.dentry,
67464+ current->exec_file->f_path.mnt) :
67465+ curr->filename, curr->filename,
67466+ &fakeip, 0, type,
67467+ protocol, GR_BIND, &current->signal->saved_ip);
67468+ }
67469+ /* we'll log when they use connect or bind */
67470+ goto exit;
67471+ }
67472+
67473+exit_fail:
67474+ if (domain == PF_INET)
67475+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
67476+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
67477+ else
67478+#ifndef CONFIG_IPV6
67479+ if (domain != PF_INET6)
67480+#endif
67481+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
67482+ gr_socktype_to_name(type), protocol);
67483+
67484+ return 0;
67485+exit:
67486+ return 1;
67487+}
67488+
67489+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)
67490+{
67491+ if ((ip->mode & mode) &&
67492+ (ip_port >= ip->low) &&
67493+ (ip_port <= ip->high) &&
67494+ ((ntohl(ip_addr) & our_netmask) ==
67495+ (ntohl(our_addr) & our_netmask))
67496+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
67497+ && (ip->type & (1U << type))) {
67498+ if (ip->mode & GR_INVERT)
67499+ return 2; // specifically denied
67500+ else
67501+ return 1; // allowed
67502+ }
67503+
67504+ return 0; // not specifically allowed, may continue parsing
67505+}
67506+
67507+static int
67508+gr_search_connectbind(const int full_mode, struct sock *sk,
67509+ struct sockaddr_in *addr, const int type)
67510+{
67511+ char iface[IFNAMSIZ] = {0};
67512+ struct acl_subject_label *curr;
67513+ struct acl_ip_label *ip;
67514+ struct inet_sock *isk;
67515+ struct net_device *dev;
67516+ struct in_device *idev;
67517+ unsigned long i;
67518+ int ret;
67519+ int mode = full_mode & (GR_BIND | GR_CONNECT);
67520+ __u32 ip_addr = 0;
67521+ __u32 our_addr;
67522+ __u32 our_netmask;
67523+ char *p;
67524+ __u16 ip_port = 0;
67525+ const struct cred *cred = current_cred();
67526+
67527+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
67528+ return 0;
67529+
67530+ curr = current->acl;
67531+ isk = inet_sk(sk);
67532+
67533+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
67534+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
67535+ addr->sin_addr.s_addr = curr->inaddr_any_override;
67536+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
67537+ struct sockaddr_in saddr;
67538+ int err;
67539+
67540+ saddr.sin_family = AF_INET;
67541+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
67542+ saddr.sin_port = isk->inet_sport;
67543+
67544+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67545+ if (err)
67546+ return err;
67547+
67548+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67549+ if (err)
67550+ return err;
67551+ }
67552+
67553+ if (!curr->ips)
67554+ return 0;
67555+
67556+ ip_addr = addr->sin_addr.s_addr;
67557+ ip_port = ntohs(addr->sin_port);
67558+
67559+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67560+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67561+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67562+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67563+ gr_to_filename(current->exec_file->f_path.dentry,
67564+ current->exec_file->f_path.mnt) :
67565+ curr->filename, curr->filename,
67566+ &ip_addr, ip_port, type,
67567+ sk->sk_protocol, mode, &current->signal->saved_ip);
67568+ return 0;
67569+ }
67570+
67571+ for (i = 0; i < curr->ip_num; i++) {
67572+ ip = *(curr->ips + i);
67573+ if (ip->iface != NULL) {
67574+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
67575+ p = strchr(iface, ':');
67576+ if (p != NULL)
67577+ *p = '\0';
67578+ dev = dev_get_by_name(sock_net(sk), iface);
67579+ if (dev == NULL)
67580+ continue;
67581+ idev = in_dev_get(dev);
67582+ if (idev == NULL) {
67583+ dev_put(dev);
67584+ continue;
67585+ }
67586+ rcu_read_lock();
67587+ for_ifa(idev) {
67588+ if (!strcmp(ip->iface, ifa->ifa_label)) {
67589+ our_addr = ifa->ifa_address;
67590+ our_netmask = 0xffffffff;
67591+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67592+ if (ret == 1) {
67593+ rcu_read_unlock();
67594+ in_dev_put(idev);
67595+ dev_put(dev);
67596+ return 0;
67597+ } else if (ret == 2) {
67598+ rcu_read_unlock();
67599+ in_dev_put(idev);
67600+ dev_put(dev);
67601+ goto denied;
67602+ }
67603+ }
67604+ } endfor_ifa(idev);
67605+ rcu_read_unlock();
67606+ in_dev_put(idev);
67607+ dev_put(dev);
67608+ } else {
67609+ our_addr = ip->addr;
67610+ our_netmask = ip->netmask;
67611+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67612+ if (ret == 1)
67613+ return 0;
67614+ else if (ret == 2)
67615+ goto denied;
67616+ }
67617+ }
67618+
67619+denied:
67620+ if (mode == GR_BIND)
67621+ 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));
67622+ else if (mode == GR_CONNECT)
67623+ 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));
67624+
67625+ return -EACCES;
67626+}
67627+
67628+int
67629+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
67630+{
67631+ /* always allow disconnection of dgram sockets with connect */
67632+ if (addr->sin_family == AF_UNSPEC)
67633+ return 0;
67634+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
67635+}
67636+
67637+int
67638+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
67639+{
67640+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
67641+}
67642+
67643+int gr_search_listen(struct socket *sock)
67644+{
67645+ struct sock *sk = sock->sk;
67646+ struct sockaddr_in addr;
67647+
67648+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67649+ addr.sin_port = inet_sk(sk)->inet_sport;
67650+
67651+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67652+}
67653+
67654+int gr_search_accept(struct socket *sock)
67655+{
67656+ struct sock *sk = sock->sk;
67657+ struct sockaddr_in addr;
67658+
67659+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67660+ addr.sin_port = inet_sk(sk)->inet_sport;
67661+
67662+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67663+}
67664+
67665+int
67666+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
67667+{
67668+ if (addr)
67669+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
67670+ else {
67671+ struct sockaddr_in sin;
67672+ const struct inet_sock *inet = inet_sk(sk);
67673+
67674+ sin.sin_addr.s_addr = inet->inet_daddr;
67675+ sin.sin_port = inet->inet_dport;
67676+
67677+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67678+ }
67679+}
67680+
67681+int
67682+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
67683+{
67684+ struct sockaddr_in sin;
67685+
67686+ if (unlikely(skb->len < sizeof (struct udphdr)))
67687+ return 0; // skip this packet
67688+
67689+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
67690+ sin.sin_port = udp_hdr(skb)->source;
67691+
67692+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67693+}
67694diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
67695new file mode 100644
67696index 0000000..25f54ef
67697--- /dev/null
67698+++ b/grsecurity/gracl_learn.c
67699@@ -0,0 +1,207 @@
67700+#include <linux/kernel.h>
67701+#include <linux/mm.h>
67702+#include <linux/sched.h>
67703+#include <linux/poll.h>
67704+#include <linux/string.h>
67705+#include <linux/file.h>
67706+#include <linux/types.h>
67707+#include <linux/vmalloc.h>
67708+#include <linux/grinternal.h>
67709+
67710+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
67711+ size_t count, loff_t *ppos);
67712+extern int gr_acl_is_enabled(void);
67713+
67714+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
67715+static int gr_learn_attached;
67716+
67717+/* use a 512k buffer */
67718+#define LEARN_BUFFER_SIZE (512 * 1024)
67719+
67720+static DEFINE_SPINLOCK(gr_learn_lock);
67721+static DEFINE_MUTEX(gr_learn_user_mutex);
67722+
67723+/* we need to maintain two buffers, so that the kernel context of grlearn
67724+ uses a semaphore around the userspace copying, and the other kernel contexts
67725+ use a spinlock when copying into the buffer, since they cannot sleep
67726+*/
67727+static char *learn_buffer;
67728+static char *learn_buffer_user;
67729+static int learn_buffer_len;
67730+static int learn_buffer_user_len;
67731+
67732+static ssize_t
67733+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
67734+{
67735+ DECLARE_WAITQUEUE(wait, current);
67736+ ssize_t retval = 0;
67737+
67738+ add_wait_queue(&learn_wait, &wait);
67739+ set_current_state(TASK_INTERRUPTIBLE);
67740+ do {
67741+ mutex_lock(&gr_learn_user_mutex);
67742+ spin_lock(&gr_learn_lock);
67743+ if (learn_buffer_len)
67744+ break;
67745+ spin_unlock(&gr_learn_lock);
67746+ mutex_unlock(&gr_learn_user_mutex);
67747+ if (file->f_flags & O_NONBLOCK) {
67748+ retval = -EAGAIN;
67749+ goto out;
67750+ }
67751+ if (signal_pending(current)) {
67752+ retval = -ERESTARTSYS;
67753+ goto out;
67754+ }
67755+
67756+ schedule();
67757+ } while (1);
67758+
67759+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
67760+ learn_buffer_user_len = learn_buffer_len;
67761+ retval = learn_buffer_len;
67762+ learn_buffer_len = 0;
67763+
67764+ spin_unlock(&gr_learn_lock);
67765+
67766+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
67767+ retval = -EFAULT;
67768+
67769+ mutex_unlock(&gr_learn_user_mutex);
67770+out:
67771+ set_current_state(TASK_RUNNING);
67772+ remove_wait_queue(&learn_wait, &wait);
67773+ return retval;
67774+}
67775+
67776+static unsigned int
67777+poll_learn(struct file * file, poll_table * wait)
67778+{
67779+ poll_wait(file, &learn_wait, wait);
67780+
67781+ if (learn_buffer_len)
67782+ return (POLLIN | POLLRDNORM);
67783+
67784+ return 0;
67785+}
67786+
67787+void
67788+gr_clear_learn_entries(void)
67789+{
67790+ char *tmp;
67791+
67792+ mutex_lock(&gr_learn_user_mutex);
67793+ spin_lock(&gr_learn_lock);
67794+ tmp = learn_buffer;
67795+ learn_buffer = NULL;
67796+ spin_unlock(&gr_learn_lock);
67797+ if (tmp)
67798+ vfree(tmp);
67799+ if (learn_buffer_user != NULL) {
67800+ vfree(learn_buffer_user);
67801+ learn_buffer_user = NULL;
67802+ }
67803+ learn_buffer_len = 0;
67804+ mutex_unlock(&gr_learn_user_mutex);
67805+
67806+ return;
67807+}
67808+
67809+void
67810+gr_add_learn_entry(const char *fmt, ...)
67811+{
67812+ va_list args;
67813+ unsigned int len;
67814+
67815+ if (!gr_learn_attached)
67816+ return;
67817+
67818+ spin_lock(&gr_learn_lock);
67819+
67820+ /* leave a gap at the end so we know when it's "full" but don't have to
67821+ compute the exact length of the string we're trying to append
67822+ */
67823+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
67824+ spin_unlock(&gr_learn_lock);
67825+ wake_up_interruptible(&learn_wait);
67826+ return;
67827+ }
67828+ if (learn_buffer == NULL) {
67829+ spin_unlock(&gr_learn_lock);
67830+ return;
67831+ }
67832+
67833+ va_start(args, fmt);
67834+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
67835+ va_end(args);
67836+
67837+ learn_buffer_len += len + 1;
67838+
67839+ spin_unlock(&gr_learn_lock);
67840+ wake_up_interruptible(&learn_wait);
67841+
67842+ return;
67843+}
67844+
67845+static int
67846+open_learn(struct inode *inode, struct file *file)
67847+{
67848+ if (file->f_mode & FMODE_READ && gr_learn_attached)
67849+ return -EBUSY;
67850+ if (file->f_mode & FMODE_READ) {
67851+ int retval = 0;
67852+ mutex_lock(&gr_learn_user_mutex);
67853+ if (learn_buffer == NULL)
67854+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
67855+ if (learn_buffer_user == NULL)
67856+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
67857+ if (learn_buffer == NULL) {
67858+ retval = -ENOMEM;
67859+ goto out_error;
67860+ }
67861+ if (learn_buffer_user == NULL) {
67862+ retval = -ENOMEM;
67863+ goto out_error;
67864+ }
67865+ learn_buffer_len = 0;
67866+ learn_buffer_user_len = 0;
67867+ gr_learn_attached = 1;
67868+out_error:
67869+ mutex_unlock(&gr_learn_user_mutex);
67870+ return retval;
67871+ }
67872+ return 0;
67873+}
67874+
67875+static int
67876+close_learn(struct inode *inode, struct file *file)
67877+{
67878+ if (file->f_mode & FMODE_READ) {
67879+ char *tmp = NULL;
67880+ mutex_lock(&gr_learn_user_mutex);
67881+ spin_lock(&gr_learn_lock);
67882+ tmp = learn_buffer;
67883+ learn_buffer = NULL;
67884+ spin_unlock(&gr_learn_lock);
67885+ if (tmp)
67886+ vfree(tmp);
67887+ if (learn_buffer_user != NULL) {
67888+ vfree(learn_buffer_user);
67889+ learn_buffer_user = NULL;
67890+ }
67891+ learn_buffer_len = 0;
67892+ learn_buffer_user_len = 0;
67893+ gr_learn_attached = 0;
67894+ mutex_unlock(&gr_learn_user_mutex);
67895+ }
67896+
67897+ return 0;
67898+}
67899+
67900+const struct file_operations grsec_fops = {
67901+ .read = read_learn,
67902+ .write = write_grsec_handler,
67903+ .open = open_learn,
67904+ .release = close_learn,
67905+ .poll = poll_learn,
67906+};
67907diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
67908new file mode 100644
67909index 0000000..39645c9
67910--- /dev/null
67911+++ b/grsecurity/gracl_res.c
67912@@ -0,0 +1,68 @@
67913+#include <linux/kernel.h>
67914+#include <linux/sched.h>
67915+#include <linux/gracl.h>
67916+#include <linux/grinternal.h>
67917+
67918+static const char *restab_log[] = {
67919+ [RLIMIT_CPU] = "RLIMIT_CPU",
67920+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
67921+ [RLIMIT_DATA] = "RLIMIT_DATA",
67922+ [RLIMIT_STACK] = "RLIMIT_STACK",
67923+ [RLIMIT_CORE] = "RLIMIT_CORE",
67924+ [RLIMIT_RSS] = "RLIMIT_RSS",
67925+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
67926+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
67927+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
67928+ [RLIMIT_AS] = "RLIMIT_AS",
67929+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
67930+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
67931+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
67932+ [RLIMIT_NICE] = "RLIMIT_NICE",
67933+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
67934+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
67935+ [GR_CRASH_RES] = "RLIMIT_CRASH"
67936+};
67937+
67938+void
67939+gr_log_resource(const struct task_struct *task,
67940+ const int res, const unsigned long wanted, const int gt)
67941+{
67942+ const struct cred *cred;
67943+ unsigned long rlim;
67944+
67945+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
67946+ return;
67947+
67948+ // not yet supported resource
67949+ if (unlikely(!restab_log[res]))
67950+ return;
67951+
67952+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
67953+ rlim = task_rlimit_max(task, res);
67954+ else
67955+ rlim = task_rlimit(task, res);
67956+
67957+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
67958+ return;
67959+
67960+ rcu_read_lock();
67961+ cred = __task_cred(task);
67962+
67963+ if (res == RLIMIT_NPROC &&
67964+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
67965+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
67966+ goto out_rcu_unlock;
67967+ else if (res == RLIMIT_MEMLOCK &&
67968+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
67969+ goto out_rcu_unlock;
67970+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
67971+ goto out_rcu_unlock;
67972+ rcu_read_unlock();
67973+
67974+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
67975+
67976+ return;
67977+out_rcu_unlock:
67978+ rcu_read_unlock();
67979+ return;
67980+}
67981diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
67982new file mode 100644
67983index 0000000..3c38bfe
67984--- /dev/null
67985+++ b/grsecurity/gracl_segv.c
67986@@ -0,0 +1,305 @@
67987+#include <linux/kernel.h>
67988+#include <linux/mm.h>
67989+#include <asm/uaccess.h>
67990+#include <asm/errno.h>
67991+#include <asm/mman.h>
67992+#include <net/sock.h>
67993+#include <linux/file.h>
67994+#include <linux/fs.h>
67995+#include <linux/net.h>
67996+#include <linux/in.h>
67997+#include <linux/slab.h>
67998+#include <linux/types.h>
67999+#include <linux/sched.h>
68000+#include <linux/timer.h>
68001+#include <linux/gracl.h>
68002+#include <linux/grsecurity.h>
68003+#include <linux/grinternal.h>
68004+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
68005+#include <linux/magic.h>
68006+#include <linux/pagemap.h>
68007+#include "../fs/btrfs/async-thread.h"
68008+#include "../fs/btrfs/ctree.h"
68009+#include "../fs/btrfs/btrfs_inode.h"
68010+#endif
68011+
68012+static struct crash_uid *uid_set;
68013+static unsigned short uid_used;
68014+static DEFINE_SPINLOCK(gr_uid_lock);
68015+extern rwlock_t gr_inode_lock;
68016+extern struct acl_subject_label *
68017+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
68018+ struct acl_role_label *role);
68019+
68020+static inline dev_t __get_dev(const struct dentry *dentry)
68021+{
68022+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
68023+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
68024+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
68025+ else
68026+#endif
68027+ return dentry->d_sb->s_dev;
68028+}
68029+
68030+int
68031+gr_init_uidset(void)
68032+{
68033+ uid_set =
68034+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
68035+ uid_used = 0;
68036+
68037+ return uid_set ? 1 : 0;
68038+}
68039+
68040+void
68041+gr_free_uidset(void)
68042+{
68043+ if (uid_set)
68044+ kfree(uid_set);
68045+
68046+ return;
68047+}
68048+
68049+int
68050+gr_find_uid(const uid_t uid)
68051+{
68052+ struct crash_uid *tmp = uid_set;
68053+ uid_t buid;
68054+ int low = 0, high = uid_used - 1, mid;
68055+
68056+ while (high >= low) {
68057+ mid = (low + high) >> 1;
68058+ buid = tmp[mid].uid;
68059+ if (buid == uid)
68060+ return mid;
68061+ if (buid > uid)
68062+ high = mid - 1;
68063+ if (buid < uid)
68064+ low = mid + 1;
68065+ }
68066+
68067+ return -1;
68068+}
68069+
68070+static __inline__ void
68071+gr_insertsort(void)
68072+{
68073+ unsigned short i, j;
68074+ struct crash_uid index;
68075+
68076+ for (i = 1; i < uid_used; i++) {
68077+ index = uid_set[i];
68078+ j = i;
68079+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
68080+ uid_set[j] = uid_set[j - 1];
68081+ j--;
68082+ }
68083+ uid_set[j] = index;
68084+ }
68085+
68086+ return;
68087+}
68088+
68089+static __inline__ void
68090+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
68091+{
68092+ int loc;
68093+ uid_t uid = GR_GLOBAL_UID(kuid);
68094+
68095+ if (uid_used == GR_UIDTABLE_MAX)
68096+ return;
68097+
68098+ loc = gr_find_uid(uid);
68099+
68100+ if (loc >= 0) {
68101+ uid_set[loc].expires = expires;
68102+ return;
68103+ }
68104+
68105+ uid_set[uid_used].uid = uid;
68106+ uid_set[uid_used].expires = expires;
68107+ uid_used++;
68108+
68109+ gr_insertsort();
68110+
68111+ return;
68112+}
68113+
68114+void
68115+gr_remove_uid(const unsigned short loc)
68116+{
68117+ unsigned short i;
68118+
68119+ for (i = loc + 1; i < uid_used; i++)
68120+ uid_set[i - 1] = uid_set[i];
68121+
68122+ uid_used--;
68123+
68124+ return;
68125+}
68126+
68127+int
68128+gr_check_crash_uid(const kuid_t kuid)
68129+{
68130+ int loc;
68131+ int ret = 0;
68132+ uid_t uid;
68133+
68134+ if (unlikely(!gr_acl_is_enabled()))
68135+ return 0;
68136+
68137+ uid = GR_GLOBAL_UID(kuid);
68138+
68139+ spin_lock(&gr_uid_lock);
68140+ loc = gr_find_uid(uid);
68141+
68142+ if (loc < 0)
68143+ goto out_unlock;
68144+
68145+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
68146+ gr_remove_uid(loc);
68147+ else
68148+ ret = 1;
68149+
68150+out_unlock:
68151+ spin_unlock(&gr_uid_lock);
68152+ return ret;
68153+}
68154+
68155+static __inline__ int
68156+proc_is_setxid(const struct cred *cred)
68157+{
68158+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
68159+ !uid_eq(cred->uid, cred->fsuid))
68160+ return 1;
68161+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
68162+ !gid_eq(cred->gid, cred->fsgid))
68163+ return 1;
68164+
68165+ return 0;
68166+}
68167+
68168+extern int gr_fake_force_sig(int sig, struct task_struct *t);
68169+
68170+void
68171+gr_handle_crash(struct task_struct *task, const int sig)
68172+{
68173+ struct acl_subject_label *curr;
68174+ struct task_struct *tsk, *tsk2;
68175+ const struct cred *cred;
68176+ const struct cred *cred2;
68177+
68178+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
68179+ return;
68180+
68181+ if (unlikely(!gr_acl_is_enabled()))
68182+ return;
68183+
68184+ curr = task->acl;
68185+
68186+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
68187+ return;
68188+
68189+ if (time_before_eq(curr->expires, get_seconds())) {
68190+ curr->expires = 0;
68191+ curr->crashes = 0;
68192+ }
68193+
68194+ curr->crashes++;
68195+
68196+ if (!curr->expires)
68197+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
68198+
68199+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
68200+ time_after(curr->expires, get_seconds())) {
68201+ rcu_read_lock();
68202+ cred = __task_cred(task);
68203+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
68204+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
68205+ spin_lock(&gr_uid_lock);
68206+ gr_insert_uid(cred->uid, curr->expires);
68207+ spin_unlock(&gr_uid_lock);
68208+ curr->expires = 0;
68209+ curr->crashes = 0;
68210+ read_lock(&tasklist_lock);
68211+ do_each_thread(tsk2, tsk) {
68212+ cred2 = __task_cred(tsk);
68213+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
68214+ gr_fake_force_sig(SIGKILL, tsk);
68215+ } while_each_thread(tsk2, tsk);
68216+ read_unlock(&tasklist_lock);
68217+ } else {
68218+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
68219+ read_lock(&tasklist_lock);
68220+ read_lock(&grsec_exec_file_lock);
68221+ do_each_thread(tsk2, tsk) {
68222+ if (likely(tsk != task)) {
68223+ // if this thread has the same subject as the one that triggered
68224+ // RES_CRASH and it's the same binary, kill it
68225+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
68226+ gr_fake_force_sig(SIGKILL, tsk);
68227+ }
68228+ } while_each_thread(tsk2, tsk);
68229+ read_unlock(&grsec_exec_file_lock);
68230+ read_unlock(&tasklist_lock);
68231+ }
68232+ rcu_read_unlock();
68233+ }
68234+
68235+ return;
68236+}
68237+
68238+int
68239+gr_check_crash_exec(const struct file *filp)
68240+{
68241+ struct acl_subject_label *curr;
68242+
68243+ if (unlikely(!gr_acl_is_enabled()))
68244+ return 0;
68245+
68246+ read_lock(&gr_inode_lock);
68247+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
68248+ __get_dev(filp->f_path.dentry),
68249+ current->role);
68250+ read_unlock(&gr_inode_lock);
68251+
68252+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
68253+ (!curr->crashes && !curr->expires))
68254+ return 0;
68255+
68256+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
68257+ time_after(curr->expires, get_seconds()))
68258+ return 1;
68259+ else if (time_before_eq(curr->expires, get_seconds())) {
68260+ curr->crashes = 0;
68261+ curr->expires = 0;
68262+ }
68263+
68264+ return 0;
68265+}
68266+
68267+void
68268+gr_handle_alertkill(struct task_struct *task)
68269+{
68270+ struct acl_subject_label *curracl;
68271+ __u32 curr_ip;
68272+ struct task_struct *p, *p2;
68273+
68274+ if (unlikely(!gr_acl_is_enabled()))
68275+ return;
68276+
68277+ curracl = task->acl;
68278+ curr_ip = task->signal->curr_ip;
68279+
68280+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
68281+ read_lock(&tasklist_lock);
68282+ do_each_thread(p2, p) {
68283+ if (p->signal->curr_ip == curr_ip)
68284+ gr_fake_force_sig(SIGKILL, p);
68285+ } while_each_thread(p2, p);
68286+ read_unlock(&tasklist_lock);
68287+ } else if (curracl->mode & GR_KILLPROC)
68288+ gr_fake_force_sig(SIGKILL, task);
68289+
68290+ return;
68291+}
68292diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
68293new file mode 100644
68294index 0000000..98011b0
68295--- /dev/null
68296+++ b/grsecurity/gracl_shm.c
68297@@ -0,0 +1,40 @@
68298+#include <linux/kernel.h>
68299+#include <linux/mm.h>
68300+#include <linux/sched.h>
68301+#include <linux/file.h>
68302+#include <linux/ipc.h>
68303+#include <linux/gracl.h>
68304+#include <linux/grsecurity.h>
68305+#include <linux/grinternal.h>
68306+
68307+int
68308+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68309+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
68310+{
68311+ struct task_struct *task;
68312+
68313+ if (!gr_acl_is_enabled())
68314+ return 1;
68315+
68316+ rcu_read_lock();
68317+ read_lock(&tasklist_lock);
68318+
68319+ task = find_task_by_vpid(shm_cprid);
68320+
68321+ if (unlikely(!task))
68322+ task = find_task_by_vpid(shm_lapid);
68323+
68324+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
68325+ (task_pid_nr(task) == shm_lapid)) &&
68326+ (task->acl->mode & GR_PROTSHM) &&
68327+ (task->acl != current->acl))) {
68328+ read_unlock(&tasklist_lock);
68329+ rcu_read_unlock();
68330+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
68331+ return 0;
68332+ }
68333+ read_unlock(&tasklist_lock);
68334+ rcu_read_unlock();
68335+
68336+ return 1;
68337+}
68338diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
68339new file mode 100644
68340index 0000000..bc0be01
68341--- /dev/null
68342+++ b/grsecurity/grsec_chdir.c
68343@@ -0,0 +1,19 @@
68344+#include <linux/kernel.h>
68345+#include <linux/sched.h>
68346+#include <linux/fs.h>
68347+#include <linux/file.h>
68348+#include <linux/grsecurity.h>
68349+#include <linux/grinternal.h>
68350+
68351+void
68352+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
68353+{
68354+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
68355+ if ((grsec_enable_chdir && grsec_enable_group &&
68356+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
68357+ !grsec_enable_group)) {
68358+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
68359+ }
68360+#endif
68361+ return;
68362+}
68363diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
68364new file mode 100644
68365index 0000000..bd6e105
68366--- /dev/null
68367+++ b/grsecurity/grsec_chroot.c
68368@@ -0,0 +1,370 @@
68369+#include <linux/kernel.h>
68370+#include <linux/module.h>
68371+#include <linux/sched.h>
68372+#include <linux/file.h>
68373+#include <linux/fs.h>
68374+#include <linux/mount.h>
68375+#include <linux/types.h>
68376+#include "../fs/mount.h"
68377+#include <linux/grsecurity.h>
68378+#include <linux/grinternal.h>
68379+
68380+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68381+static int gr_init_ran;
68382+#endif
68383+
68384+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
68385+{
68386+#ifdef CONFIG_GRKERNSEC
68387+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
68388+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
68389+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68390+ && gr_init_ran
68391+#endif
68392+ )
68393+ task->gr_is_chrooted = 1;
68394+ else {
68395+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68396+ if (task_pid_nr(task) == 1 && !gr_init_ran)
68397+ gr_init_ran = 1;
68398+#endif
68399+ task->gr_is_chrooted = 0;
68400+ }
68401+
68402+ task->gr_chroot_dentry = path->dentry;
68403+#endif
68404+ return;
68405+}
68406+
68407+void gr_clear_chroot_entries(struct task_struct *task)
68408+{
68409+#ifdef CONFIG_GRKERNSEC
68410+ task->gr_is_chrooted = 0;
68411+ task->gr_chroot_dentry = NULL;
68412+#endif
68413+ return;
68414+}
68415+
68416+int
68417+gr_handle_chroot_unix(const pid_t pid)
68418+{
68419+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
68420+ struct task_struct *p;
68421+
68422+ if (unlikely(!grsec_enable_chroot_unix))
68423+ return 1;
68424+
68425+ if (likely(!proc_is_chrooted(current)))
68426+ return 1;
68427+
68428+ rcu_read_lock();
68429+ read_lock(&tasklist_lock);
68430+ p = find_task_by_vpid_unrestricted(pid);
68431+ if (unlikely(p && !have_same_root(current, p))) {
68432+ read_unlock(&tasklist_lock);
68433+ rcu_read_unlock();
68434+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
68435+ return 0;
68436+ }
68437+ read_unlock(&tasklist_lock);
68438+ rcu_read_unlock();
68439+#endif
68440+ return 1;
68441+}
68442+
68443+int
68444+gr_handle_chroot_nice(void)
68445+{
68446+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68447+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
68448+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
68449+ return -EPERM;
68450+ }
68451+#endif
68452+ return 0;
68453+}
68454+
68455+int
68456+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
68457+{
68458+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68459+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
68460+ && proc_is_chrooted(current)) {
68461+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
68462+ return -EACCES;
68463+ }
68464+#endif
68465+ return 0;
68466+}
68467+
68468+int
68469+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
68470+{
68471+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68472+ struct task_struct *p;
68473+ int ret = 0;
68474+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
68475+ return ret;
68476+
68477+ read_lock(&tasklist_lock);
68478+ do_each_pid_task(pid, type, p) {
68479+ if (!have_same_root(current, p)) {
68480+ ret = 1;
68481+ goto out;
68482+ }
68483+ } while_each_pid_task(pid, type, p);
68484+out:
68485+ read_unlock(&tasklist_lock);
68486+ return ret;
68487+#endif
68488+ return 0;
68489+}
68490+
68491+int
68492+gr_pid_is_chrooted(struct task_struct *p)
68493+{
68494+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68495+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
68496+ return 0;
68497+
68498+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
68499+ !have_same_root(current, p)) {
68500+ return 1;
68501+ }
68502+#endif
68503+ return 0;
68504+}
68505+
68506+EXPORT_SYMBOL(gr_pid_is_chrooted);
68507+
68508+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
68509+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
68510+{
68511+ struct path path, currentroot;
68512+ int ret = 0;
68513+
68514+ path.dentry = (struct dentry *)u_dentry;
68515+ path.mnt = (struct vfsmount *)u_mnt;
68516+ get_fs_root(current->fs, &currentroot);
68517+ if (path_is_under(&path, &currentroot))
68518+ ret = 1;
68519+ path_put(&currentroot);
68520+
68521+ return ret;
68522+}
68523+#endif
68524+
68525+int
68526+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
68527+{
68528+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
68529+ if (!grsec_enable_chroot_fchdir)
68530+ return 1;
68531+
68532+ if (!proc_is_chrooted(current))
68533+ return 1;
68534+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
68535+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
68536+ return 0;
68537+ }
68538+#endif
68539+ return 1;
68540+}
68541+
68542+int
68543+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68544+ const time_t shm_createtime)
68545+{
68546+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
68547+ struct task_struct *p;
68548+ time_t starttime;
68549+
68550+ if (unlikely(!grsec_enable_chroot_shmat))
68551+ return 1;
68552+
68553+ if (likely(!proc_is_chrooted(current)))
68554+ return 1;
68555+
68556+ rcu_read_lock();
68557+ read_lock(&tasklist_lock);
68558+
68559+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
68560+ starttime = p->start_time.tv_sec;
68561+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
68562+ if (have_same_root(current, p)) {
68563+ goto allow;
68564+ } else {
68565+ read_unlock(&tasklist_lock);
68566+ rcu_read_unlock();
68567+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68568+ return 0;
68569+ }
68570+ }
68571+ /* creator exited, pid reuse, fall through to next check */
68572+ }
68573+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
68574+ if (unlikely(!have_same_root(current, p))) {
68575+ read_unlock(&tasklist_lock);
68576+ rcu_read_unlock();
68577+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68578+ return 0;
68579+ }
68580+ }
68581+
68582+allow:
68583+ read_unlock(&tasklist_lock);
68584+ rcu_read_unlock();
68585+#endif
68586+ return 1;
68587+}
68588+
68589+void
68590+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
68591+{
68592+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
68593+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
68594+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
68595+#endif
68596+ return;
68597+}
68598+
68599+int
68600+gr_handle_chroot_mknod(const struct dentry *dentry,
68601+ const struct vfsmount *mnt, const int mode)
68602+{
68603+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
68604+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
68605+ proc_is_chrooted(current)) {
68606+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
68607+ return -EPERM;
68608+ }
68609+#endif
68610+ return 0;
68611+}
68612+
68613+int
68614+gr_handle_chroot_mount(const struct dentry *dentry,
68615+ const struct vfsmount *mnt, const char *dev_name)
68616+{
68617+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
68618+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
68619+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
68620+ return -EPERM;
68621+ }
68622+#endif
68623+ return 0;
68624+}
68625+
68626+int
68627+gr_handle_chroot_pivot(void)
68628+{
68629+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
68630+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
68631+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
68632+ return -EPERM;
68633+ }
68634+#endif
68635+ return 0;
68636+}
68637+
68638+int
68639+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
68640+{
68641+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
68642+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
68643+ !gr_is_outside_chroot(dentry, mnt)) {
68644+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
68645+ return -EPERM;
68646+ }
68647+#endif
68648+ return 0;
68649+}
68650+
68651+extern const char *captab_log[];
68652+extern int captab_log_entries;
68653+
68654+int
68655+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
68656+{
68657+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68658+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68659+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68660+ if (cap_raised(chroot_caps, cap)) {
68661+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
68662+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
68663+ }
68664+ return 0;
68665+ }
68666+ }
68667+#endif
68668+ return 1;
68669+}
68670+
68671+int
68672+gr_chroot_is_capable(const int cap)
68673+{
68674+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68675+ return gr_task_chroot_is_capable(current, current_cred(), cap);
68676+#endif
68677+ return 1;
68678+}
68679+
68680+int
68681+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
68682+{
68683+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68684+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68685+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68686+ if (cap_raised(chroot_caps, cap)) {
68687+ return 0;
68688+ }
68689+ }
68690+#endif
68691+ return 1;
68692+}
68693+
68694+int
68695+gr_chroot_is_capable_nolog(const int cap)
68696+{
68697+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68698+ return gr_task_chroot_is_capable_nolog(current, cap);
68699+#endif
68700+ return 1;
68701+}
68702+
68703+int
68704+gr_handle_chroot_sysctl(const int op)
68705+{
68706+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
68707+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
68708+ proc_is_chrooted(current))
68709+ return -EACCES;
68710+#endif
68711+ return 0;
68712+}
68713+
68714+void
68715+gr_handle_chroot_chdir(const struct path *path)
68716+{
68717+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
68718+ if (grsec_enable_chroot_chdir)
68719+ set_fs_pwd(current->fs, path);
68720+#endif
68721+ return;
68722+}
68723+
68724+int
68725+gr_handle_chroot_chmod(const struct dentry *dentry,
68726+ const struct vfsmount *mnt, const int mode)
68727+{
68728+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
68729+ /* allow chmod +s on directories, but not files */
68730+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
68731+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
68732+ proc_is_chrooted(current)) {
68733+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
68734+ return -EPERM;
68735+ }
68736+#endif
68737+ return 0;
68738+}
68739diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
68740new file mode 100644
68741index 0000000..ce65ceb
68742--- /dev/null
68743+++ b/grsecurity/grsec_disabled.c
68744@@ -0,0 +1,434 @@
68745+#include <linux/kernel.h>
68746+#include <linux/module.h>
68747+#include <linux/sched.h>
68748+#include <linux/file.h>
68749+#include <linux/fs.h>
68750+#include <linux/kdev_t.h>
68751+#include <linux/net.h>
68752+#include <linux/in.h>
68753+#include <linux/ip.h>
68754+#include <linux/skbuff.h>
68755+#include <linux/sysctl.h>
68756+
68757+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
68758+void
68759+pax_set_initial_flags(struct linux_binprm *bprm)
68760+{
68761+ return;
68762+}
68763+#endif
68764+
68765+#ifdef CONFIG_SYSCTL
68766+__u32
68767+gr_handle_sysctl(const struct ctl_table * table, const int op)
68768+{
68769+ return 0;
68770+}
68771+#endif
68772+
68773+#ifdef CONFIG_TASKSTATS
68774+int gr_is_taskstats_denied(int pid)
68775+{
68776+ return 0;
68777+}
68778+#endif
68779+
68780+int
68781+gr_acl_is_enabled(void)
68782+{
68783+ return 0;
68784+}
68785+
68786+void
68787+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68788+{
68789+ return;
68790+}
68791+
68792+int
68793+gr_handle_rawio(const struct inode *inode)
68794+{
68795+ return 0;
68796+}
68797+
68798+void
68799+gr_acl_handle_psacct(struct task_struct *task, const long code)
68800+{
68801+ return;
68802+}
68803+
68804+int
68805+gr_handle_ptrace(struct task_struct *task, const long request)
68806+{
68807+ return 0;
68808+}
68809+
68810+int
68811+gr_handle_proc_ptrace(struct task_struct *task)
68812+{
68813+ return 0;
68814+}
68815+
68816+int
68817+gr_set_acls(const int type)
68818+{
68819+ return 0;
68820+}
68821+
68822+int
68823+gr_check_hidden_task(const struct task_struct *tsk)
68824+{
68825+ return 0;
68826+}
68827+
68828+int
68829+gr_check_protected_task(const struct task_struct *task)
68830+{
68831+ return 0;
68832+}
68833+
68834+int
68835+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68836+{
68837+ return 0;
68838+}
68839+
68840+void
68841+gr_copy_label(struct task_struct *tsk)
68842+{
68843+ return;
68844+}
68845+
68846+void
68847+gr_set_pax_flags(struct task_struct *task)
68848+{
68849+ return;
68850+}
68851+
68852+int
68853+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68854+ const int unsafe_share)
68855+{
68856+ return 0;
68857+}
68858+
68859+void
68860+gr_handle_delete(const ino_t ino, const dev_t dev)
68861+{
68862+ return;
68863+}
68864+
68865+void
68866+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68867+{
68868+ return;
68869+}
68870+
68871+void
68872+gr_handle_crash(struct task_struct *task, const int sig)
68873+{
68874+ return;
68875+}
68876+
68877+int
68878+gr_check_crash_exec(const struct file *filp)
68879+{
68880+ return 0;
68881+}
68882+
68883+int
68884+gr_check_crash_uid(const kuid_t uid)
68885+{
68886+ return 0;
68887+}
68888+
68889+void
68890+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68891+ struct dentry *old_dentry,
68892+ struct dentry *new_dentry,
68893+ struct vfsmount *mnt, const __u8 replace)
68894+{
68895+ return;
68896+}
68897+
68898+int
68899+gr_search_socket(const int family, const int type, const int protocol)
68900+{
68901+ return 1;
68902+}
68903+
68904+int
68905+gr_search_connectbind(const int mode, const struct socket *sock,
68906+ const struct sockaddr_in *addr)
68907+{
68908+ return 0;
68909+}
68910+
68911+void
68912+gr_handle_alertkill(struct task_struct *task)
68913+{
68914+ return;
68915+}
68916+
68917+__u32
68918+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
68919+{
68920+ return 1;
68921+}
68922+
68923+__u32
68924+gr_acl_handle_hidden_file(const struct dentry * dentry,
68925+ const struct vfsmount * mnt)
68926+{
68927+ return 1;
68928+}
68929+
68930+__u32
68931+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
68932+ int acc_mode)
68933+{
68934+ return 1;
68935+}
68936+
68937+__u32
68938+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
68939+{
68940+ return 1;
68941+}
68942+
68943+__u32
68944+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
68945+{
68946+ return 1;
68947+}
68948+
68949+int
68950+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
68951+ unsigned int *vm_flags)
68952+{
68953+ return 1;
68954+}
68955+
68956+__u32
68957+gr_acl_handle_truncate(const struct dentry * dentry,
68958+ const struct vfsmount * mnt)
68959+{
68960+ return 1;
68961+}
68962+
68963+__u32
68964+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
68965+{
68966+ return 1;
68967+}
68968+
68969+__u32
68970+gr_acl_handle_access(const struct dentry * dentry,
68971+ const struct vfsmount * mnt, const int fmode)
68972+{
68973+ return 1;
68974+}
68975+
68976+__u32
68977+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
68978+ umode_t *mode)
68979+{
68980+ return 1;
68981+}
68982+
68983+__u32
68984+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
68985+{
68986+ return 1;
68987+}
68988+
68989+__u32
68990+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
68991+{
68992+ return 1;
68993+}
68994+
68995+void
68996+grsecurity_init(void)
68997+{
68998+ return;
68999+}
69000+
69001+umode_t gr_acl_umask(void)
69002+{
69003+ return 0;
69004+}
69005+
69006+__u32
69007+gr_acl_handle_mknod(const struct dentry * new_dentry,
69008+ const struct dentry * parent_dentry,
69009+ const struct vfsmount * parent_mnt,
69010+ const int mode)
69011+{
69012+ return 1;
69013+}
69014+
69015+__u32
69016+gr_acl_handle_mkdir(const struct dentry * new_dentry,
69017+ const struct dentry * parent_dentry,
69018+ const struct vfsmount * parent_mnt)
69019+{
69020+ return 1;
69021+}
69022+
69023+__u32
69024+gr_acl_handle_symlink(const struct dentry * new_dentry,
69025+ const struct dentry * parent_dentry,
69026+ const struct vfsmount * parent_mnt, const struct filename *from)
69027+{
69028+ return 1;
69029+}
69030+
69031+__u32
69032+gr_acl_handle_link(const struct dentry * new_dentry,
69033+ const struct dentry * parent_dentry,
69034+ const struct vfsmount * parent_mnt,
69035+ const struct dentry * old_dentry,
69036+ const struct vfsmount * old_mnt, const struct filename *to)
69037+{
69038+ return 1;
69039+}
69040+
69041+int
69042+gr_acl_handle_rename(const struct dentry *new_dentry,
69043+ const struct dentry *parent_dentry,
69044+ const struct vfsmount *parent_mnt,
69045+ const struct dentry *old_dentry,
69046+ const struct inode *old_parent_inode,
69047+ const struct vfsmount *old_mnt, const struct filename *newname)
69048+{
69049+ return 0;
69050+}
69051+
69052+int
69053+gr_acl_handle_filldir(const struct file *file, const char *name,
69054+ const int namelen, const ino_t ino)
69055+{
69056+ return 1;
69057+}
69058+
69059+int
69060+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69061+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
69062+{
69063+ return 1;
69064+}
69065+
69066+int
69067+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
69068+{
69069+ return 0;
69070+}
69071+
69072+int
69073+gr_search_accept(const struct socket *sock)
69074+{
69075+ return 0;
69076+}
69077+
69078+int
69079+gr_search_listen(const struct socket *sock)
69080+{
69081+ return 0;
69082+}
69083+
69084+int
69085+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
69086+{
69087+ return 0;
69088+}
69089+
69090+__u32
69091+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
69092+{
69093+ return 1;
69094+}
69095+
69096+__u32
69097+gr_acl_handle_creat(const struct dentry * dentry,
69098+ const struct dentry * p_dentry,
69099+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
69100+ const int imode)
69101+{
69102+ return 1;
69103+}
69104+
69105+void
69106+gr_acl_handle_exit(void)
69107+{
69108+ return;
69109+}
69110+
69111+int
69112+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69113+{
69114+ return 1;
69115+}
69116+
69117+void
69118+gr_set_role_label(const kuid_t uid, const kgid_t gid)
69119+{
69120+ return;
69121+}
69122+
69123+int
69124+gr_acl_handle_procpidmem(const struct task_struct *task)
69125+{
69126+ return 0;
69127+}
69128+
69129+int
69130+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
69131+{
69132+ return 0;
69133+}
69134+
69135+int
69136+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
69137+{
69138+ return 0;
69139+}
69140+
69141+void
69142+gr_set_kernel_label(struct task_struct *task)
69143+{
69144+ return;
69145+}
69146+
69147+int
69148+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
69149+{
69150+ return 0;
69151+}
69152+
69153+int
69154+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
69155+{
69156+ return 0;
69157+}
69158+
69159+int gr_acl_enable_at_secure(void)
69160+{
69161+ return 0;
69162+}
69163+
69164+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69165+{
69166+ return dentry->d_sb->s_dev;
69167+}
69168+
69169+void gr_put_exec_file(struct task_struct *task)
69170+{
69171+ return;
69172+}
69173+
69174+EXPORT_SYMBOL(gr_set_kernel_label);
69175+#ifdef CONFIG_SECURITY
69176+EXPORT_SYMBOL(gr_check_user_change);
69177+EXPORT_SYMBOL(gr_check_group_change);
69178+#endif
69179diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
69180new file mode 100644
69181index 0000000..387032b
69182--- /dev/null
69183+++ b/grsecurity/grsec_exec.c
69184@@ -0,0 +1,187 @@
69185+#include <linux/kernel.h>
69186+#include <linux/sched.h>
69187+#include <linux/file.h>
69188+#include <linux/binfmts.h>
69189+#include <linux/fs.h>
69190+#include <linux/types.h>
69191+#include <linux/grdefs.h>
69192+#include <linux/grsecurity.h>
69193+#include <linux/grinternal.h>
69194+#include <linux/capability.h>
69195+#include <linux/module.h>
69196+#include <linux/compat.h>
69197+
69198+#include <asm/uaccess.h>
69199+
69200+#ifdef CONFIG_GRKERNSEC_EXECLOG
69201+static char gr_exec_arg_buf[132];
69202+static DEFINE_MUTEX(gr_exec_arg_mutex);
69203+#endif
69204+
69205+struct user_arg_ptr {
69206+#ifdef CONFIG_COMPAT
69207+ bool is_compat;
69208+#endif
69209+ union {
69210+ const char __user *const __user *native;
69211+#ifdef CONFIG_COMPAT
69212+ const compat_uptr_t __user *compat;
69213+#endif
69214+ } ptr;
69215+};
69216+
69217+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
69218+
69219+void
69220+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
69221+{
69222+#ifdef CONFIG_GRKERNSEC_EXECLOG
69223+ char *grarg = gr_exec_arg_buf;
69224+ unsigned int i, x, execlen = 0;
69225+ char c;
69226+
69227+ if (!((grsec_enable_execlog && grsec_enable_group &&
69228+ in_group_p(grsec_audit_gid))
69229+ || (grsec_enable_execlog && !grsec_enable_group)))
69230+ return;
69231+
69232+ mutex_lock(&gr_exec_arg_mutex);
69233+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
69234+
69235+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
69236+ const char __user *p;
69237+ unsigned int len;
69238+
69239+ p = get_user_arg_ptr(argv, i);
69240+ if (IS_ERR(p))
69241+ goto log;
69242+
69243+ len = strnlen_user(p, 128 - execlen);
69244+ if (len > 128 - execlen)
69245+ len = 128 - execlen;
69246+ else if (len > 0)
69247+ len--;
69248+ if (copy_from_user(grarg + execlen, p, len))
69249+ goto log;
69250+
69251+ /* rewrite unprintable characters */
69252+ for (x = 0; x < len; x++) {
69253+ c = *(grarg + execlen + x);
69254+ if (c < 32 || c > 126)
69255+ *(grarg + execlen + x) = ' ';
69256+ }
69257+
69258+ execlen += len;
69259+ *(grarg + execlen) = ' ';
69260+ *(grarg + execlen + 1) = '\0';
69261+ execlen++;
69262+ }
69263+
69264+ log:
69265+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
69266+ bprm->file->f_path.mnt, grarg);
69267+ mutex_unlock(&gr_exec_arg_mutex);
69268+#endif
69269+ return;
69270+}
69271+
69272+#ifdef CONFIG_GRKERNSEC
69273+extern int gr_acl_is_capable(const int cap);
69274+extern int gr_acl_is_capable_nolog(const int cap);
69275+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69276+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
69277+extern int gr_chroot_is_capable(const int cap);
69278+extern int gr_chroot_is_capable_nolog(const int cap);
69279+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69280+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
69281+#endif
69282+
69283+const char *captab_log[] = {
69284+ "CAP_CHOWN",
69285+ "CAP_DAC_OVERRIDE",
69286+ "CAP_DAC_READ_SEARCH",
69287+ "CAP_FOWNER",
69288+ "CAP_FSETID",
69289+ "CAP_KILL",
69290+ "CAP_SETGID",
69291+ "CAP_SETUID",
69292+ "CAP_SETPCAP",
69293+ "CAP_LINUX_IMMUTABLE",
69294+ "CAP_NET_BIND_SERVICE",
69295+ "CAP_NET_BROADCAST",
69296+ "CAP_NET_ADMIN",
69297+ "CAP_NET_RAW",
69298+ "CAP_IPC_LOCK",
69299+ "CAP_IPC_OWNER",
69300+ "CAP_SYS_MODULE",
69301+ "CAP_SYS_RAWIO",
69302+ "CAP_SYS_CHROOT",
69303+ "CAP_SYS_PTRACE",
69304+ "CAP_SYS_PACCT",
69305+ "CAP_SYS_ADMIN",
69306+ "CAP_SYS_BOOT",
69307+ "CAP_SYS_NICE",
69308+ "CAP_SYS_RESOURCE",
69309+ "CAP_SYS_TIME",
69310+ "CAP_SYS_TTY_CONFIG",
69311+ "CAP_MKNOD",
69312+ "CAP_LEASE",
69313+ "CAP_AUDIT_WRITE",
69314+ "CAP_AUDIT_CONTROL",
69315+ "CAP_SETFCAP",
69316+ "CAP_MAC_OVERRIDE",
69317+ "CAP_MAC_ADMIN",
69318+ "CAP_SYSLOG",
69319+ "CAP_WAKE_ALARM"
69320+};
69321+
69322+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
69323+
69324+int gr_is_capable(const int cap)
69325+{
69326+#ifdef CONFIG_GRKERNSEC
69327+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
69328+ return 1;
69329+ return 0;
69330+#else
69331+ return 1;
69332+#endif
69333+}
69334+
69335+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69336+{
69337+#ifdef CONFIG_GRKERNSEC
69338+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
69339+ return 1;
69340+ return 0;
69341+#else
69342+ return 1;
69343+#endif
69344+}
69345+
69346+int gr_is_capable_nolog(const int cap)
69347+{
69348+#ifdef CONFIG_GRKERNSEC
69349+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
69350+ return 1;
69351+ return 0;
69352+#else
69353+ return 1;
69354+#endif
69355+}
69356+
69357+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
69358+{
69359+#ifdef CONFIG_GRKERNSEC
69360+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
69361+ return 1;
69362+ return 0;
69363+#else
69364+ return 1;
69365+#endif
69366+}
69367+
69368+EXPORT_SYMBOL(gr_is_capable);
69369+EXPORT_SYMBOL(gr_is_capable_nolog);
69370+EXPORT_SYMBOL(gr_task_is_capable);
69371+EXPORT_SYMBOL(gr_task_is_capable_nolog);
69372diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
69373new file mode 100644
69374index 0000000..06cc6ea
69375--- /dev/null
69376+++ b/grsecurity/grsec_fifo.c
69377@@ -0,0 +1,24 @@
69378+#include <linux/kernel.h>
69379+#include <linux/sched.h>
69380+#include <linux/fs.h>
69381+#include <linux/file.h>
69382+#include <linux/grinternal.h>
69383+
69384+int
69385+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
69386+ const struct dentry *dir, const int flag, const int acc_mode)
69387+{
69388+#ifdef CONFIG_GRKERNSEC_FIFO
69389+ const struct cred *cred = current_cred();
69390+
69391+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
69392+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
69393+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
69394+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
69395+ if (!inode_permission(dentry->d_inode, acc_mode))
69396+ 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));
69397+ return -EACCES;
69398+ }
69399+#endif
69400+ return 0;
69401+}
69402diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
69403new file mode 100644
69404index 0000000..8ca18bf
69405--- /dev/null
69406+++ b/grsecurity/grsec_fork.c
69407@@ -0,0 +1,23 @@
69408+#include <linux/kernel.h>
69409+#include <linux/sched.h>
69410+#include <linux/grsecurity.h>
69411+#include <linux/grinternal.h>
69412+#include <linux/errno.h>
69413+
69414+void
69415+gr_log_forkfail(const int retval)
69416+{
69417+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69418+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
69419+ switch (retval) {
69420+ case -EAGAIN:
69421+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
69422+ break;
69423+ case -ENOMEM:
69424+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
69425+ break;
69426+ }
69427+ }
69428+#endif
69429+ return;
69430+}
69431diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
69432new file mode 100644
69433index 0000000..99a0cb9
69434--- /dev/null
69435+++ b/grsecurity/grsec_init.c
69436@@ -0,0 +1,283 @@
69437+#include <linux/kernel.h>
69438+#include <linux/sched.h>
69439+#include <linux/mm.h>
69440+#include <linux/gracl.h>
69441+#include <linux/slab.h>
69442+#include <linux/vmalloc.h>
69443+#include <linux/percpu.h>
69444+#include <linux/module.h>
69445+
69446+int grsec_enable_ptrace_readexec;
69447+int grsec_enable_setxid;
69448+int grsec_enable_symlinkown;
69449+kgid_t grsec_symlinkown_gid;
69450+int grsec_enable_brute;
69451+int grsec_enable_link;
69452+int grsec_enable_dmesg;
69453+int grsec_enable_harden_ptrace;
69454+int grsec_enable_fifo;
69455+int grsec_enable_execlog;
69456+int grsec_enable_signal;
69457+int grsec_enable_forkfail;
69458+int grsec_enable_audit_ptrace;
69459+int grsec_enable_time;
69460+int grsec_enable_group;
69461+kgid_t grsec_audit_gid;
69462+int grsec_enable_chdir;
69463+int grsec_enable_mount;
69464+int grsec_enable_rofs;
69465+int grsec_deny_new_usb;
69466+int grsec_enable_chroot_findtask;
69467+int grsec_enable_chroot_mount;
69468+int grsec_enable_chroot_shmat;
69469+int grsec_enable_chroot_fchdir;
69470+int grsec_enable_chroot_double;
69471+int grsec_enable_chroot_pivot;
69472+int grsec_enable_chroot_chdir;
69473+int grsec_enable_chroot_chmod;
69474+int grsec_enable_chroot_mknod;
69475+int grsec_enable_chroot_nice;
69476+int grsec_enable_chroot_execlog;
69477+int grsec_enable_chroot_caps;
69478+int grsec_enable_chroot_sysctl;
69479+int grsec_enable_chroot_unix;
69480+int grsec_enable_tpe;
69481+kgid_t grsec_tpe_gid;
69482+int grsec_enable_blackhole;
69483+#ifdef CONFIG_IPV6_MODULE
69484+EXPORT_SYMBOL(grsec_enable_blackhole);
69485+#endif
69486+int grsec_lastack_retries;
69487+int grsec_enable_tpe_all;
69488+int grsec_enable_tpe_invert;
69489+int grsec_enable_socket_all;
69490+kgid_t grsec_socket_all_gid;
69491+int grsec_enable_socket_client;
69492+kgid_t grsec_socket_client_gid;
69493+int grsec_enable_socket_server;
69494+kgid_t grsec_socket_server_gid;
69495+int grsec_resource_logging;
69496+int grsec_disable_privio;
69497+int grsec_enable_log_rwxmaps;
69498+int grsec_lock;
69499+
69500+DEFINE_SPINLOCK(grsec_alert_lock);
69501+unsigned long grsec_alert_wtime = 0;
69502+unsigned long grsec_alert_fyet = 0;
69503+
69504+DEFINE_SPINLOCK(grsec_audit_lock);
69505+
69506+DEFINE_RWLOCK(grsec_exec_file_lock);
69507+
69508+char *gr_shared_page[4];
69509+
69510+char *gr_alert_log_fmt;
69511+char *gr_audit_log_fmt;
69512+char *gr_alert_log_buf;
69513+char *gr_audit_log_buf;
69514+
69515+extern struct gr_arg *gr_usermode;
69516+extern unsigned char *gr_system_salt;
69517+extern unsigned char *gr_system_sum;
69518+
69519+void __init
69520+grsecurity_init(void)
69521+{
69522+ int j;
69523+ /* create the per-cpu shared pages */
69524+
69525+#ifdef CONFIG_X86
69526+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
69527+#endif
69528+
69529+ for (j = 0; j < 4; j++) {
69530+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
69531+ if (gr_shared_page[j] == NULL) {
69532+ panic("Unable to allocate grsecurity shared page");
69533+ return;
69534+ }
69535+ }
69536+
69537+ /* allocate log buffers */
69538+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
69539+ if (!gr_alert_log_fmt) {
69540+ panic("Unable to allocate grsecurity alert log format buffer");
69541+ return;
69542+ }
69543+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
69544+ if (!gr_audit_log_fmt) {
69545+ panic("Unable to allocate grsecurity audit log format buffer");
69546+ return;
69547+ }
69548+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69549+ if (!gr_alert_log_buf) {
69550+ panic("Unable to allocate grsecurity alert log buffer");
69551+ return;
69552+ }
69553+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69554+ if (!gr_audit_log_buf) {
69555+ panic("Unable to allocate grsecurity audit log buffer");
69556+ return;
69557+ }
69558+
69559+ /* allocate memory for authentication structure */
69560+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
69561+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
69562+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
69563+
69564+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
69565+ panic("Unable to allocate grsecurity authentication structure");
69566+ return;
69567+ }
69568+
69569+
69570+#ifdef CONFIG_GRKERNSEC_IO
69571+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
69572+ grsec_disable_privio = 1;
69573+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69574+ grsec_disable_privio = 1;
69575+#else
69576+ grsec_disable_privio = 0;
69577+#endif
69578+#endif
69579+
69580+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
69581+ /* for backward compatibility, tpe_invert always defaults to on if
69582+ enabled in the kernel
69583+ */
69584+ grsec_enable_tpe_invert = 1;
69585+#endif
69586+
69587+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69588+#ifndef CONFIG_GRKERNSEC_SYSCTL
69589+ grsec_lock = 1;
69590+#endif
69591+
69592+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
69593+ grsec_enable_log_rwxmaps = 1;
69594+#endif
69595+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
69596+ grsec_enable_group = 1;
69597+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
69598+#endif
69599+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
69600+ grsec_enable_ptrace_readexec = 1;
69601+#endif
69602+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
69603+ grsec_enable_chdir = 1;
69604+#endif
69605+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69606+ grsec_enable_harden_ptrace = 1;
69607+#endif
69608+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
69609+ grsec_enable_mount = 1;
69610+#endif
69611+#ifdef CONFIG_GRKERNSEC_LINK
69612+ grsec_enable_link = 1;
69613+#endif
69614+#ifdef CONFIG_GRKERNSEC_BRUTE
69615+ grsec_enable_brute = 1;
69616+#endif
69617+#ifdef CONFIG_GRKERNSEC_DMESG
69618+ grsec_enable_dmesg = 1;
69619+#endif
69620+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
69621+ grsec_enable_blackhole = 1;
69622+ grsec_lastack_retries = 4;
69623+#endif
69624+#ifdef CONFIG_GRKERNSEC_FIFO
69625+ grsec_enable_fifo = 1;
69626+#endif
69627+#ifdef CONFIG_GRKERNSEC_EXECLOG
69628+ grsec_enable_execlog = 1;
69629+#endif
69630+#ifdef CONFIG_GRKERNSEC_SETXID
69631+ grsec_enable_setxid = 1;
69632+#endif
69633+#ifdef CONFIG_GRKERNSEC_SIGNAL
69634+ grsec_enable_signal = 1;
69635+#endif
69636+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69637+ grsec_enable_forkfail = 1;
69638+#endif
69639+#ifdef CONFIG_GRKERNSEC_TIME
69640+ grsec_enable_time = 1;
69641+#endif
69642+#ifdef CONFIG_GRKERNSEC_RESLOG
69643+ grsec_resource_logging = 1;
69644+#endif
69645+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69646+ grsec_enable_chroot_findtask = 1;
69647+#endif
69648+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
69649+ grsec_enable_chroot_unix = 1;
69650+#endif
69651+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
69652+ grsec_enable_chroot_mount = 1;
69653+#endif
69654+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
69655+ grsec_enable_chroot_fchdir = 1;
69656+#endif
69657+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
69658+ grsec_enable_chroot_shmat = 1;
69659+#endif
69660+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
69661+ grsec_enable_audit_ptrace = 1;
69662+#endif
69663+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
69664+ grsec_enable_chroot_double = 1;
69665+#endif
69666+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
69667+ grsec_enable_chroot_pivot = 1;
69668+#endif
69669+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
69670+ grsec_enable_chroot_chdir = 1;
69671+#endif
69672+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
69673+ grsec_enable_chroot_chmod = 1;
69674+#endif
69675+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
69676+ grsec_enable_chroot_mknod = 1;
69677+#endif
69678+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
69679+ grsec_enable_chroot_nice = 1;
69680+#endif
69681+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
69682+ grsec_enable_chroot_execlog = 1;
69683+#endif
69684+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69685+ grsec_enable_chroot_caps = 1;
69686+#endif
69687+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
69688+ grsec_enable_chroot_sysctl = 1;
69689+#endif
69690+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69691+ grsec_enable_symlinkown = 1;
69692+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
69693+#endif
69694+#ifdef CONFIG_GRKERNSEC_TPE
69695+ grsec_enable_tpe = 1;
69696+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
69697+#ifdef CONFIG_GRKERNSEC_TPE_ALL
69698+ grsec_enable_tpe_all = 1;
69699+#endif
69700+#endif
69701+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
69702+ grsec_enable_socket_all = 1;
69703+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
69704+#endif
69705+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
69706+ grsec_enable_socket_client = 1;
69707+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
69708+#endif
69709+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
69710+ grsec_enable_socket_server = 1;
69711+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
69712+#endif
69713+#endif
69714+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
69715+ grsec_deny_new_usb = 1;
69716+#endif
69717+
69718+ return;
69719+}
69720diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
69721new file mode 100644
69722index 0000000..5e05e20
69723--- /dev/null
69724+++ b/grsecurity/grsec_link.c
69725@@ -0,0 +1,58 @@
69726+#include <linux/kernel.h>
69727+#include <linux/sched.h>
69728+#include <linux/fs.h>
69729+#include <linux/file.h>
69730+#include <linux/grinternal.h>
69731+
69732+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
69733+{
69734+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69735+ const struct inode *link_inode = link->dentry->d_inode;
69736+
69737+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
69738+ /* ignore root-owned links, e.g. /proc/self */
69739+ gr_is_global_nonroot(link_inode->i_uid) && target &&
69740+ !uid_eq(link_inode->i_uid, target->i_uid)) {
69741+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
69742+ return 1;
69743+ }
69744+#endif
69745+ return 0;
69746+}
69747+
69748+int
69749+gr_handle_follow_link(const struct inode *parent,
69750+ const struct inode *inode,
69751+ const struct dentry *dentry, const struct vfsmount *mnt)
69752+{
69753+#ifdef CONFIG_GRKERNSEC_LINK
69754+ const struct cred *cred = current_cred();
69755+
69756+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
69757+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
69758+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
69759+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
69760+ return -EACCES;
69761+ }
69762+#endif
69763+ return 0;
69764+}
69765+
69766+int
69767+gr_handle_hardlink(const struct dentry *dentry,
69768+ const struct vfsmount *mnt,
69769+ struct inode *inode, const int mode, const struct filename *to)
69770+{
69771+#ifdef CONFIG_GRKERNSEC_LINK
69772+ const struct cred *cred = current_cred();
69773+
69774+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
69775+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
69776+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
69777+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
69778+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
69779+ return -EPERM;
69780+ }
69781+#endif
69782+ return 0;
69783+}
69784diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
69785new file mode 100644
69786index 0000000..dbe0a6b
69787--- /dev/null
69788+++ b/grsecurity/grsec_log.c
69789@@ -0,0 +1,341 @@
69790+#include <linux/kernel.h>
69791+#include <linux/sched.h>
69792+#include <linux/file.h>
69793+#include <linux/tty.h>
69794+#include <linux/fs.h>
69795+#include <linux/mm.h>
69796+#include <linux/grinternal.h>
69797+
69798+#ifdef CONFIG_TREE_PREEMPT_RCU
69799+#define DISABLE_PREEMPT() preempt_disable()
69800+#define ENABLE_PREEMPT() preempt_enable()
69801+#else
69802+#define DISABLE_PREEMPT()
69803+#define ENABLE_PREEMPT()
69804+#endif
69805+
69806+#define BEGIN_LOCKS(x) \
69807+ DISABLE_PREEMPT(); \
69808+ rcu_read_lock(); \
69809+ read_lock(&tasklist_lock); \
69810+ read_lock(&grsec_exec_file_lock); \
69811+ if (x != GR_DO_AUDIT) \
69812+ spin_lock(&grsec_alert_lock); \
69813+ else \
69814+ spin_lock(&grsec_audit_lock)
69815+
69816+#define END_LOCKS(x) \
69817+ if (x != GR_DO_AUDIT) \
69818+ spin_unlock(&grsec_alert_lock); \
69819+ else \
69820+ spin_unlock(&grsec_audit_lock); \
69821+ read_unlock(&grsec_exec_file_lock); \
69822+ read_unlock(&tasklist_lock); \
69823+ rcu_read_unlock(); \
69824+ ENABLE_PREEMPT(); \
69825+ if (x == GR_DONT_AUDIT) \
69826+ gr_handle_alertkill(current)
69827+
69828+enum {
69829+ FLOODING,
69830+ NO_FLOODING
69831+};
69832+
69833+extern char *gr_alert_log_fmt;
69834+extern char *gr_audit_log_fmt;
69835+extern char *gr_alert_log_buf;
69836+extern char *gr_audit_log_buf;
69837+
69838+static int gr_log_start(int audit)
69839+{
69840+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
69841+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
69842+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69843+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
69844+ unsigned long curr_secs = get_seconds();
69845+
69846+ if (audit == GR_DO_AUDIT)
69847+ goto set_fmt;
69848+
69849+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
69850+ grsec_alert_wtime = curr_secs;
69851+ grsec_alert_fyet = 0;
69852+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
69853+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
69854+ grsec_alert_fyet++;
69855+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
69856+ grsec_alert_wtime = curr_secs;
69857+ grsec_alert_fyet++;
69858+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
69859+ return FLOODING;
69860+ }
69861+ else return FLOODING;
69862+
69863+set_fmt:
69864+#endif
69865+ memset(buf, 0, PAGE_SIZE);
69866+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
69867+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
69868+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
69869+ } else if (current->signal->curr_ip) {
69870+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
69871+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
69872+ } else if (gr_acl_is_enabled()) {
69873+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
69874+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
69875+ } else {
69876+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
69877+ strcpy(buf, fmt);
69878+ }
69879+
69880+ return NO_FLOODING;
69881+}
69882+
69883+static void gr_log_middle(int audit, const char *msg, va_list ap)
69884+ __attribute__ ((format (printf, 2, 0)));
69885+
69886+static void gr_log_middle(int audit, const char *msg, va_list ap)
69887+{
69888+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69889+ unsigned int len = strlen(buf);
69890+
69891+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
69892+
69893+ return;
69894+}
69895+
69896+static void gr_log_middle_varargs(int audit, const char *msg, ...)
69897+ __attribute__ ((format (printf, 2, 3)));
69898+
69899+static void gr_log_middle_varargs(int audit, const char *msg, ...)
69900+{
69901+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69902+ unsigned int len = strlen(buf);
69903+ va_list ap;
69904+
69905+ va_start(ap, msg);
69906+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
69907+ va_end(ap);
69908+
69909+ return;
69910+}
69911+
69912+static void gr_log_end(int audit, int append_default)
69913+{
69914+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69915+ if (append_default) {
69916+ struct task_struct *task = current;
69917+ struct task_struct *parent = task->real_parent;
69918+ const struct cred *cred = __task_cred(task);
69919+ const struct cred *pcred = __task_cred(parent);
69920+ unsigned int len = strlen(buf);
69921+
69922+ 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));
69923+ }
69924+
69925+ printk("%s\n", buf);
69926+
69927+ return;
69928+}
69929+
69930+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
69931+{
69932+ int logtype;
69933+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
69934+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
69935+ void *voidptr = NULL;
69936+ int num1 = 0, num2 = 0;
69937+ unsigned long ulong1 = 0, ulong2 = 0;
69938+ struct dentry *dentry = NULL;
69939+ struct vfsmount *mnt = NULL;
69940+ struct file *file = NULL;
69941+ struct task_struct *task = NULL;
69942+ struct vm_area_struct *vma = NULL;
69943+ const struct cred *cred, *pcred;
69944+ va_list ap;
69945+
69946+ BEGIN_LOCKS(audit);
69947+ logtype = gr_log_start(audit);
69948+ if (logtype == FLOODING) {
69949+ END_LOCKS(audit);
69950+ return;
69951+ }
69952+ va_start(ap, argtypes);
69953+ switch (argtypes) {
69954+ case GR_TTYSNIFF:
69955+ task = va_arg(ap, struct task_struct *);
69956+ 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));
69957+ break;
69958+ case GR_SYSCTL_HIDDEN:
69959+ str1 = va_arg(ap, char *);
69960+ gr_log_middle_varargs(audit, msg, result, str1);
69961+ break;
69962+ case GR_RBAC:
69963+ dentry = va_arg(ap, struct dentry *);
69964+ mnt = va_arg(ap, struct vfsmount *);
69965+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
69966+ break;
69967+ case GR_RBAC_STR:
69968+ dentry = va_arg(ap, struct dentry *);
69969+ mnt = va_arg(ap, struct vfsmount *);
69970+ str1 = va_arg(ap, char *);
69971+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
69972+ break;
69973+ case GR_STR_RBAC:
69974+ str1 = va_arg(ap, char *);
69975+ dentry = va_arg(ap, struct dentry *);
69976+ mnt = va_arg(ap, struct vfsmount *);
69977+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
69978+ break;
69979+ case GR_RBAC_MODE2:
69980+ dentry = va_arg(ap, struct dentry *);
69981+ mnt = va_arg(ap, struct vfsmount *);
69982+ str1 = va_arg(ap, char *);
69983+ str2 = va_arg(ap, char *);
69984+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
69985+ break;
69986+ case GR_RBAC_MODE3:
69987+ dentry = va_arg(ap, struct dentry *);
69988+ mnt = va_arg(ap, struct vfsmount *);
69989+ str1 = va_arg(ap, char *);
69990+ str2 = va_arg(ap, char *);
69991+ str3 = va_arg(ap, char *);
69992+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
69993+ break;
69994+ case GR_FILENAME:
69995+ dentry = va_arg(ap, struct dentry *);
69996+ mnt = va_arg(ap, struct vfsmount *);
69997+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
69998+ break;
69999+ case GR_STR_FILENAME:
70000+ str1 = va_arg(ap, char *);
70001+ dentry = va_arg(ap, struct dentry *);
70002+ mnt = va_arg(ap, struct vfsmount *);
70003+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
70004+ break;
70005+ case GR_FILENAME_STR:
70006+ dentry = va_arg(ap, struct dentry *);
70007+ mnt = va_arg(ap, struct vfsmount *);
70008+ str1 = va_arg(ap, char *);
70009+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
70010+ break;
70011+ case GR_FILENAME_TWO_INT:
70012+ dentry = va_arg(ap, struct dentry *);
70013+ mnt = va_arg(ap, struct vfsmount *);
70014+ num1 = va_arg(ap, int);
70015+ num2 = va_arg(ap, int);
70016+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
70017+ break;
70018+ case GR_FILENAME_TWO_INT_STR:
70019+ dentry = va_arg(ap, struct dentry *);
70020+ mnt = va_arg(ap, struct vfsmount *);
70021+ num1 = va_arg(ap, int);
70022+ num2 = va_arg(ap, int);
70023+ str1 = va_arg(ap, char *);
70024+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
70025+ break;
70026+ case GR_TEXTREL:
70027+ file = va_arg(ap, struct file *);
70028+ ulong1 = va_arg(ap, unsigned long);
70029+ ulong2 = va_arg(ap, unsigned long);
70030+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
70031+ break;
70032+ case GR_PTRACE:
70033+ task = va_arg(ap, struct task_struct *);
70034+ 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));
70035+ break;
70036+ case GR_RESOURCE:
70037+ task = va_arg(ap, struct task_struct *);
70038+ cred = __task_cred(task);
70039+ pcred = __task_cred(task->real_parent);
70040+ ulong1 = va_arg(ap, unsigned long);
70041+ str1 = va_arg(ap, char *);
70042+ ulong2 = va_arg(ap, unsigned long);
70043+ 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));
70044+ break;
70045+ case GR_CAP:
70046+ task = va_arg(ap, struct task_struct *);
70047+ cred = __task_cred(task);
70048+ pcred = __task_cred(task->real_parent);
70049+ str1 = va_arg(ap, char *);
70050+ 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));
70051+ break;
70052+ case GR_SIG:
70053+ str1 = va_arg(ap, char *);
70054+ voidptr = va_arg(ap, void *);
70055+ gr_log_middle_varargs(audit, msg, str1, voidptr);
70056+ break;
70057+ case GR_SIG2:
70058+ task = va_arg(ap, struct task_struct *);
70059+ cred = __task_cred(task);
70060+ pcred = __task_cred(task->real_parent);
70061+ num1 = va_arg(ap, int);
70062+ 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));
70063+ break;
70064+ case GR_CRASH1:
70065+ task = va_arg(ap, struct task_struct *);
70066+ cred = __task_cred(task);
70067+ pcred = __task_cred(task->real_parent);
70068+ ulong1 = va_arg(ap, unsigned long);
70069+ 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);
70070+ break;
70071+ case GR_CRASH2:
70072+ task = va_arg(ap, struct task_struct *);
70073+ cred = __task_cred(task);
70074+ pcred = __task_cred(task->real_parent);
70075+ ulong1 = va_arg(ap, unsigned long);
70076+ 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);
70077+ break;
70078+ case GR_RWXMAP:
70079+ file = va_arg(ap, struct file *);
70080+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
70081+ break;
70082+ case GR_RWXMAPVMA:
70083+ vma = va_arg(ap, struct vm_area_struct *);
70084+ if (vma->vm_file)
70085+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
70086+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
70087+ str1 = "<stack>";
70088+ else if (vma->vm_start <= current->mm->brk &&
70089+ vma->vm_end >= current->mm->start_brk)
70090+ str1 = "<heap>";
70091+ else
70092+ str1 = "<anonymous mapping>";
70093+ gr_log_middle_varargs(audit, msg, str1);
70094+ break;
70095+ case GR_PSACCT:
70096+ {
70097+ unsigned int wday, cday;
70098+ __u8 whr, chr;
70099+ __u8 wmin, cmin;
70100+ __u8 wsec, csec;
70101+ char cur_tty[64] = { 0 };
70102+ char parent_tty[64] = { 0 };
70103+
70104+ task = va_arg(ap, struct task_struct *);
70105+ wday = va_arg(ap, unsigned int);
70106+ cday = va_arg(ap, unsigned int);
70107+ whr = va_arg(ap, int);
70108+ chr = va_arg(ap, int);
70109+ wmin = va_arg(ap, int);
70110+ cmin = va_arg(ap, int);
70111+ wsec = va_arg(ap, int);
70112+ csec = va_arg(ap, int);
70113+ ulong1 = va_arg(ap, unsigned long);
70114+ cred = __task_cred(task);
70115+ pcred = __task_cred(task->real_parent);
70116+
70117+ 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));
70118+ }
70119+ break;
70120+ default:
70121+ gr_log_middle(audit, msg, ap);
70122+ }
70123+ va_end(ap);
70124+ // these don't need DEFAULTSECARGS printed on the end
70125+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
70126+ gr_log_end(audit, 0);
70127+ else
70128+ gr_log_end(audit, 1);
70129+ END_LOCKS(audit);
70130+}
70131diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
70132new file mode 100644
70133index 0000000..f536303
70134--- /dev/null
70135+++ b/grsecurity/grsec_mem.c
70136@@ -0,0 +1,40 @@
70137+#include <linux/kernel.h>
70138+#include <linux/sched.h>
70139+#include <linux/mm.h>
70140+#include <linux/mman.h>
70141+#include <linux/grinternal.h>
70142+
70143+void
70144+gr_handle_ioperm(void)
70145+{
70146+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
70147+ return;
70148+}
70149+
70150+void
70151+gr_handle_iopl(void)
70152+{
70153+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
70154+ return;
70155+}
70156+
70157+void
70158+gr_handle_mem_readwrite(u64 from, u64 to)
70159+{
70160+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
70161+ return;
70162+}
70163+
70164+void
70165+gr_handle_vm86(void)
70166+{
70167+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
70168+ return;
70169+}
70170+
70171+void
70172+gr_log_badprocpid(const char *entry)
70173+{
70174+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
70175+ return;
70176+}
70177diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
70178new file mode 100644
70179index 0000000..2131422
70180--- /dev/null
70181+++ b/grsecurity/grsec_mount.c
70182@@ -0,0 +1,62 @@
70183+#include <linux/kernel.h>
70184+#include <linux/sched.h>
70185+#include <linux/mount.h>
70186+#include <linux/grsecurity.h>
70187+#include <linux/grinternal.h>
70188+
70189+void
70190+gr_log_remount(const char *devname, const int retval)
70191+{
70192+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70193+ if (grsec_enable_mount && (retval >= 0))
70194+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
70195+#endif
70196+ return;
70197+}
70198+
70199+void
70200+gr_log_unmount(const char *devname, const int retval)
70201+{
70202+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70203+ if (grsec_enable_mount && (retval >= 0))
70204+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
70205+#endif
70206+ return;
70207+}
70208+
70209+void
70210+gr_log_mount(const char *from, const char *to, const int retval)
70211+{
70212+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70213+ if (grsec_enable_mount && (retval >= 0))
70214+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
70215+#endif
70216+ return;
70217+}
70218+
70219+int
70220+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
70221+{
70222+#ifdef CONFIG_GRKERNSEC_ROFS
70223+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
70224+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
70225+ return -EPERM;
70226+ } else
70227+ return 0;
70228+#endif
70229+ return 0;
70230+}
70231+
70232+int
70233+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
70234+{
70235+#ifdef CONFIG_GRKERNSEC_ROFS
70236+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
70237+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
70238+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
70239+ return -EPERM;
70240+ } else
70241+ return 0;
70242+#endif
70243+ return 0;
70244+}
70245diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
70246new file mode 100644
70247index 0000000..6ee9d50
70248--- /dev/null
70249+++ b/grsecurity/grsec_pax.c
70250@@ -0,0 +1,45 @@
70251+#include <linux/kernel.h>
70252+#include <linux/sched.h>
70253+#include <linux/mm.h>
70254+#include <linux/file.h>
70255+#include <linux/grinternal.h>
70256+#include <linux/grsecurity.h>
70257+
70258+void
70259+gr_log_textrel(struct vm_area_struct * vma)
70260+{
70261+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70262+ if (grsec_enable_log_rwxmaps)
70263+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
70264+#endif
70265+ return;
70266+}
70267+
70268+void gr_log_ptgnustack(struct file *file)
70269+{
70270+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70271+ if (grsec_enable_log_rwxmaps)
70272+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
70273+#endif
70274+ return;
70275+}
70276+
70277+void
70278+gr_log_rwxmmap(struct file *file)
70279+{
70280+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70281+ if (grsec_enable_log_rwxmaps)
70282+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
70283+#endif
70284+ return;
70285+}
70286+
70287+void
70288+gr_log_rwxmprotect(struct vm_area_struct *vma)
70289+{
70290+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70291+ if (grsec_enable_log_rwxmaps)
70292+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
70293+#endif
70294+ return;
70295+}
70296diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
70297new file mode 100644
70298index 0000000..f7f29aa
70299--- /dev/null
70300+++ b/grsecurity/grsec_ptrace.c
70301@@ -0,0 +1,30 @@
70302+#include <linux/kernel.h>
70303+#include <linux/sched.h>
70304+#include <linux/grinternal.h>
70305+#include <linux/security.h>
70306+
70307+void
70308+gr_audit_ptrace(struct task_struct *task)
70309+{
70310+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
70311+ if (grsec_enable_audit_ptrace)
70312+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
70313+#endif
70314+ return;
70315+}
70316+
70317+int
70318+gr_ptrace_readexec(struct file *file, int unsafe_flags)
70319+{
70320+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70321+ const struct dentry *dentry = file->f_path.dentry;
70322+ const struct vfsmount *mnt = file->f_path.mnt;
70323+
70324+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
70325+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
70326+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
70327+ return -EACCES;
70328+ }
70329+#endif
70330+ return 0;
70331+}
70332diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
70333new file mode 100644
70334index 0000000..4e29cc7
70335--- /dev/null
70336+++ b/grsecurity/grsec_sig.c
70337@@ -0,0 +1,246 @@
70338+#include <linux/kernel.h>
70339+#include <linux/sched.h>
70340+#include <linux/fs.h>
70341+#include <linux/delay.h>
70342+#include <linux/grsecurity.h>
70343+#include <linux/grinternal.h>
70344+#include <linux/hardirq.h>
70345+
70346+char *signames[] = {
70347+ [SIGSEGV] = "Segmentation fault",
70348+ [SIGILL] = "Illegal instruction",
70349+ [SIGABRT] = "Abort",
70350+ [SIGBUS] = "Invalid alignment/Bus error"
70351+};
70352+
70353+void
70354+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
70355+{
70356+#ifdef CONFIG_GRKERNSEC_SIGNAL
70357+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
70358+ (sig == SIGABRT) || (sig == SIGBUS))) {
70359+ if (task_pid_nr(t) == task_pid_nr(current)) {
70360+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
70361+ } else {
70362+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
70363+ }
70364+ }
70365+#endif
70366+ return;
70367+}
70368+
70369+int
70370+gr_handle_signal(const struct task_struct *p, const int sig)
70371+{
70372+#ifdef CONFIG_GRKERNSEC
70373+ /* ignore the 0 signal for protected task checks */
70374+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
70375+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
70376+ return -EPERM;
70377+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
70378+ return -EPERM;
70379+ }
70380+#endif
70381+ return 0;
70382+}
70383+
70384+#ifdef CONFIG_GRKERNSEC
70385+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
70386+
70387+int gr_fake_force_sig(int sig, struct task_struct *t)
70388+{
70389+ unsigned long int flags;
70390+ int ret, blocked, ignored;
70391+ struct k_sigaction *action;
70392+
70393+ spin_lock_irqsave(&t->sighand->siglock, flags);
70394+ action = &t->sighand->action[sig-1];
70395+ ignored = action->sa.sa_handler == SIG_IGN;
70396+ blocked = sigismember(&t->blocked, sig);
70397+ if (blocked || ignored) {
70398+ action->sa.sa_handler = SIG_DFL;
70399+ if (blocked) {
70400+ sigdelset(&t->blocked, sig);
70401+ recalc_sigpending_and_wake(t);
70402+ }
70403+ }
70404+ if (action->sa.sa_handler == SIG_DFL)
70405+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
70406+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
70407+
70408+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
70409+
70410+ return ret;
70411+}
70412+#endif
70413+
70414+#ifdef CONFIG_GRKERNSEC_BRUTE
70415+#define GR_USER_BAN_TIME (15 * 60)
70416+#define GR_DAEMON_BRUTE_TIME (30 * 60)
70417+
70418+static int __get_dumpable(unsigned long mm_flags)
70419+{
70420+ int ret;
70421+
70422+ ret = mm_flags & MMF_DUMPABLE_MASK;
70423+ return (ret >= 2) ? 2 : ret;
70424+}
70425+#endif
70426+
70427+void gr_handle_brute_attach(unsigned long mm_flags)
70428+{
70429+#ifdef CONFIG_GRKERNSEC_BRUTE
70430+ struct task_struct *p = current;
70431+ kuid_t uid = GLOBAL_ROOT_UID;
70432+ int daemon = 0;
70433+
70434+ if (!grsec_enable_brute)
70435+ return;
70436+
70437+ rcu_read_lock();
70438+ read_lock(&tasklist_lock);
70439+ read_lock(&grsec_exec_file_lock);
70440+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
70441+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
70442+ p->real_parent->brute = 1;
70443+ daemon = 1;
70444+ } else {
70445+ const struct cred *cred = __task_cred(p), *cred2;
70446+ struct task_struct *tsk, *tsk2;
70447+
70448+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
70449+ struct user_struct *user;
70450+
70451+ uid = cred->uid;
70452+
70453+ /* this is put upon execution past expiration */
70454+ user = find_user(uid);
70455+ if (user == NULL)
70456+ goto unlock;
70457+ user->suid_banned = 1;
70458+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
70459+ if (user->suid_ban_expires == ~0UL)
70460+ user->suid_ban_expires--;
70461+
70462+ /* only kill other threads of the same binary, from the same user */
70463+ do_each_thread(tsk2, tsk) {
70464+ cred2 = __task_cred(tsk);
70465+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
70466+ gr_fake_force_sig(SIGKILL, tsk);
70467+ } while_each_thread(tsk2, tsk);
70468+ }
70469+ }
70470+unlock:
70471+ read_unlock(&grsec_exec_file_lock);
70472+ read_unlock(&tasklist_lock);
70473+ rcu_read_unlock();
70474+
70475+ if (gr_is_global_nonroot(uid))
70476+ 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);
70477+ else if (daemon)
70478+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
70479+
70480+#endif
70481+ return;
70482+}
70483+
70484+void gr_handle_brute_check(void)
70485+{
70486+#ifdef CONFIG_GRKERNSEC_BRUTE
70487+ struct task_struct *p = current;
70488+
70489+ if (unlikely(p->brute)) {
70490+ if (!grsec_enable_brute)
70491+ p->brute = 0;
70492+ else if (time_before(get_seconds(), p->brute_expires))
70493+ msleep(30 * 1000);
70494+ }
70495+#endif
70496+ return;
70497+}
70498+
70499+void gr_handle_kernel_exploit(void)
70500+{
70501+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70502+ const struct cred *cred;
70503+ struct task_struct *tsk, *tsk2;
70504+ struct user_struct *user;
70505+ kuid_t uid;
70506+
70507+ if (in_irq() || in_serving_softirq() || in_nmi())
70508+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
70509+
70510+ uid = current_uid();
70511+
70512+ if (gr_is_global_root(uid))
70513+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
70514+ else {
70515+ /* kill all the processes of this user, hold a reference
70516+ to their creds struct, and prevent them from creating
70517+ another process until system reset
70518+ */
70519+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
70520+ GR_GLOBAL_UID(uid));
70521+ /* we intentionally leak this ref */
70522+ user = get_uid(current->cred->user);
70523+ if (user)
70524+ user->kernel_banned = 1;
70525+
70526+ /* kill all processes of this user */
70527+ read_lock(&tasklist_lock);
70528+ do_each_thread(tsk2, tsk) {
70529+ cred = __task_cred(tsk);
70530+ if (uid_eq(cred->uid, uid))
70531+ gr_fake_force_sig(SIGKILL, tsk);
70532+ } while_each_thread(tsk2, tsk);
70533+ read_unlock(&tasklist_lock);
70534+ }
70535+#endif
70536+}
70537+
70538+#ifdef CONFIG_GRKERNSEC_BRUTE
70539+static bool suid_ban_expired(struct user_struct *user)
70540+{
70541+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
70542+ user->suid_banned = 0;
70543+ user->suid_ban_expires = 0;
70544+ free_uid(user);
70545+ return true;
70546+ }
70547+
70548+ return false;
70549+}
70550+#endif
70551+
70552+int gr_process_kernel_exec_ban(void)
70553+{
70554+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70555+ if (unlikely(current->cred->user->kernel_banned))
70556+ return -EPERM;
70557+#endif
70558+ return 0;
70559+}
70560+
70561+int gr_process_kernel_setuid_ban(struct user_struct *user)
70562+{
70563+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70564+ if (unlikely(user->kernel_banned))
70565+ gr_fake_force_sig(SIGKILL, current);
70566+#endif
70567+ return 0;
70568+}
70569+
70570+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
70571+{
70572+#ifdef CONFIG_GRKERNSEC_BRUTE
70573+ struct user_struct *user = current->cred->user;
70574+ if (unlikely(user->suid_banned)) {
70575+ if (suid_ban_expired(user))
70576+ return 0;
70577+ /* disallow execution of suid binaries only */
70578+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
70579+ return -EPERM;
70580+ }
70581+#endif
70582+ return 0;
70583+}
70584diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
70585new file mode 100644
70586index 0000000..4030d57
70587--- /dev/null
70588+++ b/grsecurity/grsec_sock.c
70589@@ -0,0 +1,244 @@
70590+#include <linux/kernel.h>
70591+#include <linux/module.h>
70592+#include <linux/sched.h>
70593+#include <linux/file.h>
70594+#include <linux/net.h>
70595+#include <linux/in.h>
70596+#include <linux/ip.h>
70597+#include <net/sock.h>
70598+#include <net/inet_sock.h>
70599+#include <linux/grsecurity.h>
70600+#include <linux/grinternal.h>
70601+#include <linux/gracl.h>
70602+
70603+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
70604+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
70605+
70606+EXPORT_SYMBOL(gr_search_udp_recvmsg);
70607+EXPORT_SYMBOL(gr_search_udp_sendmsg);
70608+
70609+#ifdef CONFIG_UNIX_MODULE
70610+EXPORT_SYMBOL(gr_acl_handle_unix);
70611+EXPORT_SYMBOL(gr_acl_handle_mknod);
70612+EXPORT_SYMBOL(gr_handle_chroot_unix);
70613+EXPORT_SYMBOL(gr_handle_create);
70614+#endif
70615+
70616+#ifdef CONFIG_GRKERNSEC
70617+#define gr_conn_table_size 32749
70618+struct conn_table_entry {
70619+ struct conn_table_entry *next;
70620+ struct signal_struct *sig;
70621+};
70622+
70623+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
70624+DEFINE_SPINLOCK(gr_conn_table_lock);
70625+
70626+extern const char * gr_socktype_to_name(unsigned char type);
70627+extern const char * gr_proto_to_name(unsigned char proto);
70628+extern const char * gr_sockfamily_to_name(unsigned char family);
70629+
70630+static __inline__ int
70631+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
70632+{
70633+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
70634+}
70635+
70636+static __inline__ int
70637+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
70638+ __u16 sport, __u16 dport)
70639+{
70640+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
70641+ sig->gr_sport == sport && sig->gr_dport == dport))
70642+ return 1;
70643+ else
70644+ return 0;
70645+}
70646+
70647+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
70648+{
70649+ struct conn_table_entry **match;
70650+ unsigned int index;
70651+
70652+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70653+ sig->gr_sport, sig->gr_dport,
70654+ gr_conn_table_size);
70655+
70656+ newent->sig = sig;
70657+
70658+ match = &gr_conn_table[index];
70659+ newent->next = *match;
70660+ *match = newent;
70661+
70662+ return;
70663+}
70664+
70665+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
70666+{
70667+ struct conn_table_entry *match, *last = NULL;
70668+ unsigned int index;
70669+
70670+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70671+ sig->gr_sport, sig->gr_dport,
70672+ gr_conn_table_size);
70673+
70674+ match = gr_conn_table[index];
70675+ while (match && !conn_match(match->sig,
70676+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
70677+ sig->gr_dport)) {
70678+ last = match;
70679+ match = match->next;
70680+ }
70681+
70682+ if (match) {
70683+ if (last)
70684+ last->next = match->next;
70685+ else
70686+ gr_conn_table[index] = NULL;
70687+ kfree(match);
70688+ }
70689+
70690+ return;
70691+}
70692+
70693+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
70694+ __u16 sport, __u16 dport)
70695+{
70696+ struct conn_table_entry *match;
70697+ unsigned int index;
70698+
70699+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
70700+
70701+ match = gr_conn_table[index];
70702+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
70703+ match = match->next;
70704+
70705+ if (match)
70706+ return match->sig;
70707+ else
70708+ return NULL;
70709+}
70710+
70711+#endif
70712+
70713+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
70714+{
70715+#ifdef CONFIG_GRKERNSEC
70716+ struct signal_struct *sig = task->signal;
70717+ struct conn_table_entry *newent;
70718+
70719+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
70720+ if (newent == NULL)
70721+ return;
70722+ /* no bh lock needed since we are called with bh disabled */
70723+ spin_lock(&gr_conn_table_lock);
70724+ gr_del_task_from_ip_table_nolock(sig);
70725+ sig->gr_saddr = inet->inet_rcv_saddr;
70726+ sig->gr_daddr = inet->inet_daddr;
70727+ sig->gr_sport = inet->inet_sport;
70728+ sig->gr_dport = inet->inet_dport;
70729+ gr_add_to_task_ip_table_nolock(sig, newent);
70730+ spin_unlock(&gr_conn_table_lock);
70731+#endif
70732+ return;
70733+}
70734+
70735+void gr_del_task_from_ip_table(struct task_struct *task)
70736+{
70737+#ifdef CONFIG_GRKERNSEC
70738+ spin_lock_bh(&gr_conn_table_lock);
70739+ gr_del_task_from_ip_table_nolock(task->signal);
70740+ spin_unlock_bh(&gr_conn_table_lock);
70741+#endif
70742+ return;
70743+}
70744+
70745+void
70746+gr_attach_curr_ip(const struct sock *sk)
70747+{
70748+#ifdef CONFIG_GRKERNSEC
70749+ struct signal_struct *p, *set;
70750+ const struct inet_sock *inet = inet_sk(sk);
70751+
70752+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
70753+ return;
70754+
70755+ set = current->signal;
70756+
70757+ spin_lock_bh(&gr_conn_table_lock);
70758+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
70759+ inet->inet_dport, inet->inet_sport);
70760+ if (unlikely(p != NULL)) {
70761+ set->curr_ip = p->curr_ip;
70762+ set->used_accept = 1;
70763+ gr_del_task_from_ip_table_nolock(p);
70764+ spin_unlock_bh(&gr_conn_table_lock);
70765+ return;
70766+ }
70767+ spin_unlock_bh(&gr_conn_table_lock);
70768+
70769+ set->curr_ip = inet->inet_daddr;
70770+ set->used_accept = 1;
70771+#endif
70772+ return;
70773+}
70774+
70775+int
70776+gr_handle_sock_all(const int family, const int type, const int protocol)
70777+{
70778+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
70779+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
70780+ (family != AF_UNIX)) {
70781+ if (family == AF_INET)
70782+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
70783+ else
70784+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
70785+ return -EACCES;
70786+ }
70787+#endif
70788+ return 0;
70789+}
70790+
70791+int
70792+gr_handle_sock_server(const struct sockaddr *sck)
70793+{
70794+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70795+ if (grsec_enable_socket_server &&
70796+ in_group_p(grsec_socket_server_gid) &&
70797+ sck && (sck->sa_family != AF_UNIX) &&
70798+ (sck->sa_family != AF_LOCAL)) {
70799+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70800+ return -EACCES;
70801+ }
70802+#endif
70803+ return 0;
70804+}
70805+
70806+int
70807+gr_handle_sock_server_other(const struct sock *sck)
70808+{
70809+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70810+ if (grsec_enable_socket_server &&
70811+ in_group_p(grsec_socket_server_gid) &&
70812+ sck && (sck->sk_family != AF_UNIX) &&
70813+ (sck->sk_family != AF_LOCAL)) {
70814+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70815+ return -EACCES;
70816+ }
70817+#endif
70818+ return 0;
70819+}
70820+
70821+int
70822+gr_handle_sock_client(const struct sockaddr *sck)
70823+{
70824+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
70825+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
70826+ sck && (sck->sa_family != AF_UNIX) &&
70827+ (sck->sa_family != AF_LOCAL)) {
70828+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
70829+ return -EACCES;
70830+ }
70831+#endif
70832+ return 0;
70833+}
70834diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
70835new file mode 100644
70836index 0000000..a147ae7
70837--- /dev/null
70838+++ b/grsecurity/grsec_sysctl.c
70839@@ -0,0 +1,470 @@
70840+#include <linux/kernel.h>
70841+#include <linux/sched.h>
70842+#include <linux/sysctl.h>
70843+#include <linux/grsecurity.h>
70844+#include <linux/grinternal.h>
70845+
70846+int
70847+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
70848+{
70849+#ifdef CONFIG_GRKERNSEC_SYSCTL
70850+ if (dirname == NULL || name == NULL)
70851+ return 0;
70852+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
70853+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
70854+ return -EACCES;
70855+ }
70856+#endif
70857+ return 0;
70858+}
70859+
70860+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
70861+static int __maybe_unused __read_only one = 1;
70862+#endif
70863+
70864+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
70865+ defined(CONFIG_GRKERNSEC_DENYUSB)
70866+struct ctl_table grsecurity_table[] = {
70867+#ifdef CONFIG_GRKERNSEC_SYSCTL
70868+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
70869+#ifdef CONFIG_GRKERNSEC_IO
70870+ {
70871+ .procname = "disable_priv_io",
70872+ .data = &grsec_disable_privio,
70873+ .maxlen = sizeof(int),
70874+ .mode = 0600,
70875+ .proc_handler = &proc_dointvec,
70876+ },
70877+#endif
70878+#endif
70879+#ifdef CONFIG_GRKERNSEC_LINK
70880+ {
70881+ .procname = "linking_restrictions",
70882+ .data = &grsec_enable_link,
70883+ .maxlen = sizeof(int),
70884+ .mode = 0600,
70885+ .proc_handler = &proc_dointvec,
70886+ },
70887+#endif
70888+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
70889+ {
70890+ .procname = "enforce_symlinksifowner",
70891+ .data = &grsec_enable_symlinkown,
70892+ .maxlen = sizeof(int),
70893+ .mode = 0600,
70894+ .proc_handler = &proc_dointvec,
70895+ },
70896+ {
70897+ .procname = "symlinkown_gid",
70898+ .data = &grsec_symlinkown_gid,
70899+ .maxlen = sizeof(int),
70900+ .mode = 0600,
70901+ .proc_handler = &proc_dointvec,
70902+ },
70903+#endif
70904+#ifdef CONFIG_GRKERNSEC_BRUTE
70905+ {
70906+ .procname = "deter_bruteforce",
70907+ .data = &grsec_enable_brute,
70908+ .maxlen = sizeof(int),
70909+ .mode = 0600,
70910+ .proc_handler = &proc_dointvec,
70911+ },
70912+#endif
70913+#ifdef CONFIG_GRKERNSEC_FIFO
70914+ {
70915+ .procname = "fifo_restrictions",
70916+ .data = &grsec_enable_fifo,
70917+ .maxlen = sizeof(int),
70918+ .mode = 0600,
70919+ .proc_handler = &proc_dointvec,
70920+ },
70921+#endif
70922+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70923+ {
70924+ .procname = "ptrace_readexec",
70925+ .data = &grsec_enable_ptrace_readexec,
70926+ .maxlen = sizeof(int),
70927+ .mode = 0600,
70928+ .proc_handler = &proc_dointvec,
70929+ },
70930+#endif
70931+#ifdef CONFIG_GRKERNSEC_SETXID
70932+ {
70933+ .procname = "consistent_setxid",
70934+ .data = &grsec_enable_setxid,
70935+ .maxlen = sizeof(int),
70936+ .mode = 0600,
70937+ .proc_handler = &proc_dointvec,
70938+ },
70939+#endif
70940+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
70941+ {
70942+ .procname = "ip_blackhole",
70943+ .data = &grsec_enable_blackhole,
70944+ .maxlen = sizeof(int),
70945+ .mode = 0600,
70946+ .proc_handler = &proc_dointvec,
70947+ },
70948+ {
70949+ .procname = "lastack_retries",
70950+ .data = &grsec_lastack_retries,
70951+ .maxlen = sizeof(int),
70952+ .mode = 0600,
70953+ .proc_handler = &proc_dointvec,
70954+ },
70955+#endif
70956+#ifdef CONFIG_GRKERNSEC_EXECLOG
70957+ {
70958+ .procname = "exec_logging",
70959+ .data = &grsec_enable_execlog,
70960+ .maxlen = sizeof(int),
70961+ .mode = 0600,
70962+ .proc_handler = &proc_dointvec,
70963+ },
70964+#endif
70965+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70966+ {
70967+ .procname = "rwxmap_logging",
70968+ .data = &grsec_enable_log_rwxmaps,
70969+ .maxlen = sizeof(int),
70970+ .mode = 0600,
70971+ .proc_handler = &proc_dointvec,
70972+ },
70973+#endif
70974+#ifdef CONFIG_GRKERNSEC_SIGNAL
70975+ {
70976+ .procname = "signal_logging",
70977+ .data = &grsec_enable_signal,
70978+ .maxlen = sizeof(int),
70979+ .mode = 0600,
70980+ .proc_handler = &proc_dointvec,
70981+ },
70982+#endif
70983+#ifdef CONFIG_GRKERNSEC_FORKFAIL
70984+ {
70985+ .procname = "forkfail_logging",
70986+ .data = &grsec_enable_forkfail,
70987+ .maxlen = sizeof(int),
70988+ .mode = 0600,
70989+ .proc_handler = &proc_dointvec,
70990+ },
70991+#endif
70992+#ifdef CONFIG_GRKERNSEC_TIME
70993+ {
70994+ .procname = "timechange_logging",
70995+ .data = &grsec_enable_time,
70996+ .maxlen = sizeof(int),
70997+ .mode = 0600,
70998+ .proc_handler = &proc_dointvec,
70999+ },
71000+#endif
71001+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
71002+ {
71003+ .procname = "chroot_deny_shmat",
71004+ .data = &grsec_enable_chroot_shmat,
71005+ .maxlen = sizeof(int),
71006+ .mode = 0600,
71007+ .proc_handler = &proc_dointvec,
71008+ },
71009+#endif
71010+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
71011+ {
71012+ .procname = "chroot_deny_unix",
71013+ .data = &grsec_enable_chroot_unix,
71014+ .maxlen = sizeof(int),
71015+ .mode = 0600,
71016+ .proc_handler = &proc_dointvec,
71017+ },
71018+#endif
71019+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
71020+ {
71021+ .procname = "chroot_deny_mount",
71022+ .data = &grsec_enable_chroot_mount,
71023+ .maxlen = sizeof(int),
71024+ .mode = 0600,
71025+ .proc_handler = &proc_dointvec,
71026+ },
71027+#endif
71028+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
71029+ {
71030+ .procname = "chroot_deny_fchdir",
71031+ .data = &grsec_enable_chroot_fchdir,
71032+ .maxlen = sizeof(int),
71033+ .mode = 0600,
71034+ .proc_handler = &proc_dointvec,
71035+ },
71036+#endif
71037+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
71038+ {
71039+ .procname = "chroot_deny_chroot",
71040+ .data = &grsec_enable_chroot_double,
71041+ .maxlen = sizeof(int),
71042+ .mode = 0600,
71043+ .proc_handler = &proc_dointvec,
71044+ },
71045+#endif
71046+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
71047+ {
71048+ .procname = "chroot_deny_pivot",
71049+ .data = &grsec_enable_chroot_pivot,
71050+ .maxlen = sizeof(int),
71051+ .mode = 0600,
71052+ .proc_handler = &proc_dointvec,
71053+ },
71054+#endif
71055+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
71056+ {
71057+ .procname = "chroot_enforce_chdir",
71058+ .data = &grsec_enable_chroot_chdir,
71059+ .maxlen = sizeof(int),
71060+ .mode = 0600,
71061+ .proc_handler = &proc_dointvec,
71062+ },
71063+#endif
71064+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
71065+ {
71066+ .procname = "chroot_deny_chmod",
71067+ .data = &grsec_enable_chroot_chmod,
71068+ .maxlen = sizeof(int),
71069+ .mode = 0600,
71070+ .proc_handler = &proc_dointvec,
71071+ },
71072+#endif
71073+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
71074+ {
71075+ .procname = "chroot_deny_mknod",
71076+ .data = &grsec_enable_chroot_mknod,
71077+ .maxlen = sizeof(int),
71078+ .mode = 0600,
71079+ .proc_handler = &proc_dointvec,
71080+ },
71081+#endif
71082+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
71083+ {
71084+ .procname = "chroot_restrict_nice",
71085+ .data = &grsec_enable_chroot_nice,
71086+ .maxlen = sizeof(int),
71087+ .mode = 0600,
71088+ .proc_handler = &proc_dointvec,
71089+ },
71090+#endif
71091+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
71092+ {
71093+ .procname = "chroot_execlog",
71094+ .data = &grsec_enable_chroot_execlog,
71095+ .maxlen = sizeof(int),
71096+ .mode = 0600,
71097+ .proc_handler = &proc_dointvec,
71098+ },
71099+#endif
71100+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
71101+ {
71102+ .procname = "chroot_caps",
71103+ .data = &grsec_enable_chroot_caps,
71104+ .maxlen = sizeof(int),
71105+ .mode = 0600,
71106+ .proc_handler = &proc_dointvec,
71107+ },
71108+#endif
71109+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
71110+ {
71111+ .procname = "chroot_deny_sysctl",
71112+ .data = &grsec_enable_chroot_sysctl,
71113+ .maxlen = sizeof(int),
71114+ .mode = 0600,
71115+ .proc_handler = &proc_dointvec,
71116+ },
71117+#endif
71118+#ifdef CONFIG_GRKERNSEC_TPE
71119+ {
71120+ .procname = "tpe",
71121+ .data = &grsec_enable_tpe,
71122+ .maxlen = sizeof(int),
71123+ .mode = 0600,
71124+ .proc_handler = &proc_dointvec,
71125+ },
71126+ {
71127+ .procname = "tpe_gid",
71128+ .data = &grsec_tpe_gid,
71129+ .maxlen = sizeof(int),
71130+ .mode = 0600,
71131+ .proc_handler = &proc_dointvec,
71132+ },
71133+#endif
71134+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71135+ {
71136+ .procname = "tpe_invert",
71137+ .data = &grsec_enable_tpe_invert,
71138+ .maxlen = sizeof(int),
71139+ .mode = 0600,
71140+ .proc_handler = &proc_dointvec,
71141+ },
71142+#endif
71143+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71144+ {
71145+ .procname = "tpe_restrict_all",
71146+ .data = &grsec_enable_tpe_all,
71147+ .maxlen = sizeof(int),
71148+ .mode = 0600,
71149+ .proc_handler = &proc_dointvec,
71150+ },
71151+#endif
71152+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
71153+ {
71154+ .procname = "socket_all",
71155+ .data = &grsec_enable_socket_all,
71156+ .maxlen = sizeof(int),
71157+ .mode = 0600,
71158+ .proc_handler = &proc_dointvec,
71159+ },
71160+ {
71161+ .procname = "socket_all_gid",
71162+ .data = &grsec_socket_all_gid,
71163+ .maxlen = sizeof(int),
71164+ .mode = 0600,
71165+ .proc_handler = &proc_dointvec,
71166+ },
71167+#endif
71168+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
71169+ {
71170+ .procname = "socket_client",
71171+ .data = &grsec_enable_socket_client,
71172+ .maxlen = sizeof(int),
71173+ .mode = 0600,
71174+ .proc_handler = &proc_dointvec,
71175+ },
71176+ {
71177+ .procname = "socket_client_gid",
71178+ .data = &grsec_socket_client_gid,
71179+ .maxlen = sizeof(int),
71180+ .mode = 0600,
71181+ .proc_handler = &proc_dointvec,
71182+ },
71183+#endif
71184+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
71185+ {
71186+ .procname = "socket_server",
71187+ .data = &grsec_enable_socket_server,
71188+ .maxlen = sizeof(int),
71189+ .mode = 0600,
71190+ .proc_handler = &proc_dointvec,
71191+ },
71192+ {
71193+ .procname = "socket_server_gid",
71194+ .data = &grsec_socket_server_gid,
71195+ .maxlen = sizeof(int),
71196+ .mode = 0600,
71197+ .proc_handler = &proc_dointvec,
71198+ },
71199+#endif
71200+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
71201+ {
71202+ .procname = "audit_group",
71203+ .data = &grsec_enable_group,
71204+ .maxlen = sizeof(int),
71205+ .mode = 0600,
71206+ .proc_handler = &proc_dointvec,
71207+ },
71208+ {
71209+ .procname = "audit_gid",
71210+ .data = &grsec_audit_gid,
71211+ .maxlen = sizeof(int),
71212+ .mode = 0600,
71213+ .proc_handler = &proc_dointvec,
71214+ },
71215+#endif
71216+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
71217+ {
71218+ .procname = "audit_chdir",
71219+ .data = &grsec_enable_chdir,
71220+ .maxlen = sizeof(int),
71221+ .mode = 0600,
71222+ .proc_handler = &proc_dointvec,
71223+ },
71224+#endif
71225+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71226+ {
71227+ .procname = "audit_mount",
71228+ .data = &grsec_enable_mount,
71229+ .maxlen = sizeof(int),
71230+ .mode = 0600,
71231+ .proc_handler = &proc_dointvec,
71232+ },
71233+#endif
71234+#ifdef CONFIG_GRKERNSEC_DMESG
71235+ {
71236+ .procname = "dmesg",
71237+ .data = &grsec_enable_dmesg,
71238+ .maxlen = sizeof(int),
71239+ .mode = 0600,
71240+ .proc_handler = &proc_dointvec,
71241+ },
71242+#endif
71243+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71244+ {
71245+ .procname = "chroot_findtask",
71246+ .data = &grsec_enable_chroot_findtask,
71247+ .maxlen = sizeof(int),
71248+ .mode = 0600,
71249+ .proc_handler = &proc_dointvec,
71250+ },
71251+#endif
71252+#ifdef CONFIG_GRKERNSEC_RESLOG
71253+ {
71254+ .procname = "resource_logging",
71255+ .data = &grsec_resource_logging,
71256+ .maxlen = sizeof(int),
71257+ .mode = 0600,
71258+ .proc_handler = &proc_dointvec,
71259+ },
71260+#endif
71261+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
71262+ {
71263+ .procname = "audit_ptrace",
71264+ .data = &grsec_enable_audit_ptrace,
71265+ .maxlen = sizeof(int),
71266+ .mode = 0600,
71267+ .proc_handler = &proc_dointvec,
71268+ },
71269+#endif
71270+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71271+ {
71272+ .procname = "harden_ptrace",
71273+ .data = &grsec_enable_harden_ptrace,
71274+ .maxlen = sizeof(int),
71275+ .mode = 0600,
71276+ .proc_handler = &proc_dointvec,
71277+ },
71278+#endif
71279+ {
71280+ .procname = "grsec_lock",
71281+ .data = &grsec_lock,
71282+ .maxlen = sizeof(int),
71283+ .mode = 0600,
71284+ .proc_handler = &proc_dointvec,
71285+ },
71286+#endif
71287+#ifdef CONFIG_GRKERNSEC_ROFS
71288+ {
71289+ .procname = "romount_protect",
71290+ .data = &grsec_enable_rofs,
71291+ .maxlen = sizeof(int),
71292+ .mode = 0600,
71293+ .proc_handler = &proc_dointvec_minmax,
71294+ .extra1 = &one,
71295+ .extra2 = &one,
71296+ },
71297+#endif
71298+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
71299+ {
71300+ .procname = "deny_new_usb",
71301+ .data = &grsec_deny_new_usb,
71302+ .maxlen = sizeof(int),
71303+ .mode = 0600,
71304+ .proc_handler = &proc_dointvec,
71305+ },
71306+#endif
71307+ { }
71308+};
71309+#endif
71310diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
71311new file mode 100644
71312index 0000000..0dc13c3
71313--- /dev/null
71314+++ b/grsecurity/grsec_time.c
71315@@ -0,0 +1,16 @@
71316+#include <linux/kernel.h>
71317+#include <linux/sched.h>
71318+#include <linux/grinternal.h>
71319+#include <linux/module.h>
71320+
71321+void
71322+gr_log_timechange(void)
71323+{
71324+#ifdef CONFIG_GRKERNSEC_TIME
71325+ if (grsec_enable_time)
71326+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
71327+#endif
71328+ return;
71329+}
71330+
71331+EXPORT_SYMBOL(gr_log_timechange);
71332diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
71333new file mode 100644
71334index 0000000..ee57dcf
71335--- /dev/null
71336+++ b/grsecurity/grsec_tpe.c
71337@@ -0,0 +1,73 @@
71338+#include <linux/kernel.h>
71339+#include <linux/sched.h>
71340+#include <linux/file.h>
71341+#include <linux/fs.h>
71342+#include <linux/grinternal.h>
71343+
71344+extern int gr_acl_tpe_check(void);
71345+
71346+int
71347+gr_tpe_allow(const struct file *file)
71348+{
71349+#ifdef CONFIG_GRKERNSEC
71350+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
71351+ const struct cred *cred = current_cred();
71352+ char *msg = NULL;
71353+ char *msg2 = NULL;
71354+
71355+ // never restrict root
71356+ if (gr_is_global_root(cred->uid))
71357+ return 1;
71358+
71359+ if (grsec_enable_tpe) {
71360+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71361+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
71362+ msg = "not being in trusted group";
71363+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
71364+ msg = "being in untrusted group";
71365+#else
71366+ if (in_group_p(grsec_tpe_gid))
71367+ msg = "being in untrusted group";
71368+#endif
71369+ }
71370+ if (!msg && gr_acl_tpe_check())
71371+ msg = "being in untrusted role";
71372+
71373+ // not in any affected group/role
71374+ if (!msg)
71375+ goto next_check;
71376+
71377+ if (gr_is_global_nonroot(inode->i_uid))
71378+ msg2 = "file in non-root-owned directory";
71379+ else if (inode->i_mode & S_IWOTH)
71380+ msg2 = "file in world-writable directory";
71381+ else if (inode->i_mode & S_IWGRP)
71382+ msg2 = "file in group-writable directory";
71383+
71384+ if (msg && msg2) {
71385+ char fullmsg[70] = {0};
71386+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
71387+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
71388+ return 0;
71389+ }
71390+ msg = NULL;
71391+next_check:
71392+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71393+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
71394+ return 1;
71395+
71396+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
71397+ msg = "directory not owned by user";
71398+ else if (inode->i_mode & S_IWOTH)
71399+ msg = "file in world-writable directory";
71400+ else if (inode->i_mode & S_IWGRP)
71401+ msg = "file in group-writable directory";
71402+
71403+ if (msg) {
71404+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
71405+ return 0;
71406+ }
71407+#endif
71408+#endif
71409+ return 1;
71410+}
71411diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
71412new file mode 100644
71413index 0000000..ae02d8e
71414--- /dev/null
71415+++ b/grsecurity/grsec_usb.c
71416@@ -0,0 +1,15 @@
71417+#include <linux/kernel.h>
71418+#include <linux/grinternal.h>
71419+#include <linux/module.h>
71420+
71421+int gr_handle_new_usb(void)
71422+{
71423+#ifdef CONFIG_GRKERNSEC_DENYUSB
71424+ if (grsec_deny_new_usb) {
71425+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
71426+ return 1;
71427+ }
71428+#endif
71429+ return 0;
71430+}
71431+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
71432diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
71433new file mode 100644
71434index 0000000..9f7b1ac
71435--- /dev/null
71436+++ b/grsecurity/grsum.c
71437@@ -0,0 +1,61 @@
71438+#include <linux/err.h>
71439+#include <linux/kernel.h>
71440+#include <linux/sched.h>
71441+#include <linux/mm.h>
71442+#include <linux/scatterlist.h>
71443+#include <linux/crypto.h>
71444+#include <linux/gracl.h>
71445+
71446+
71447+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
71448+#error "crypto and sha256 must be built into the kernel"
71449+#endif
71450+
71451+int
71452+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
71453+{
71454+ char *p;
71455+ struct crypto_hash *tfm;
71456+ struct hash_desc desc;
71457+ struct scatterlist sg;
71458+ unsigned char temp_sum[GR_SHA_LEN];
71459+ volatile int retval = 0;
71460+ volatile int dummy = 0;
71461+ unsigned int i;
71462+
71463+ sg_init_table(&sg, 1);
71464+
71465+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
71466+ if (IS_ERR(tfm)) {
71467+ /* should never happen, since sha256 should be built in */
71468+ return 1;
71469+ }
71470+
71471+ desc.tfm = tfm;
71472+ desc.flags = 0;
71473+
71474+ crypto_hash_init(&desc);
71475+
71476+ p = salt;
71477+ sg_set_buf(&sg, p, GR_SALT_LEN);
71478+ crypto_hash_update(&desc, &sg, sg.length);
71479+
71480+ p = entry->pw;
71481+ sg_set_buf(&sg, p, strlen(p));
71482+
71483+ crypto_hash_update(&desc, &sg, sg.length);
71484+
71485+ crypto_hash_final(&desc, temp_sum);
71486+
71487+ memset(entry->pw, 0, GR_PW_LEN);
71488+
71489+ for (i = 0; i < GR_SHA_LEN; i++)
71490+ if (sum[i] != temp_sum[i])
71491+ retval = 1;
71492+ else
71493+ dummy = 1; // waste a cycle
71494+
71495+ crypto_free_hash(tfm);
71496+
71497+ return retval;
71498+}
71499diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
71500index 77ff547..181834f 100644
71501--- a/include/asm-generic/4level-fixup.h
71502+++ b/include/asm-generic/4level-fixup.h
71503@@ -13,8 +13,10 @@
71504 #define pmd_alloc(mm, pud, address) \
71505 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
71506 NULL: pmd_offset(pud, address))
71507+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
71508
71509 #define pud_alloc(mm, pgd, address) (pgd)
71510+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
71511 #define pud_offset(pgd, start) (pgd)
71512 #define pud_none(pud) 0
71513 #define pud_bad(pud) 0
71514diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
71515index b7babf0..04ad282 100644
71516--- a/include/asm-generic/atomic-long.h
71517+++ b/include/asm-generic/atomic-long.h
71518@@ -22,6 +22,12 @@
71519
71520 typedef atomic64_t atomic_long_t;
71521
71522+#ifdef CONFIG_PAX_REFCOUNT
71523+typedef atomic64_unchecked_t atomic_long_unchecked_t;
71524+#else
71525+typedef atomic64_t atomic_long_unchecked_t;
71526+#endif
71527+
71528 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
71529
71530 static inline long atomic_long_read(atomic_long_t *l)
71531@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71532 return (long)atomic64_read(v);
71533 }
71534
71535+#ifdef CONFIG_PAX_REFCOUNT
71536+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71537+{
71538+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71539+
71540+ return (long)atomic64_read_unchecked(v);
71541+}
71542+#endif
71543+
71544 static inline void atomic_long_set(atomic_long_t *l, long i)
71545 {
71546 atomic64_t *v = (atomic64_t *)l;
71547@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71548 atomic64_set(v, i);
71549 }
71550
71551+#ifdef CONFIG_PAX_REFCOUNT
71552+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71553+{
71554+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71555+
71556+ atomic64_set_unchecked(v, i);
71557+}
71558+#endif
71559+
71560 static inline void atomic_long_inc(atomic_long_t *l)
71561 {
71562 atomic64_t *v = (atomic64_t *)l;
71563@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71564 atomic64_inc(v);
71565 }
71566
71567+#ifdef CONFIG_PAX_REFCOUNT
71568+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71569+{
71570+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71571+
71572+ atomic64_inc_unchecked(v);
71573+}
71574+#endif
71575+
71576 static inline void atomic_long_dec(atomic_long_t *l)
71577 {
71578 atomic64_t *v = (atomic64_t *)l;
71579@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71580 atomic64_dec(v);
71581 }
71582
71583+#ifdef CONFIG_PAX_REFCOUNT
71584+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71585+{
71586+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71587+
71588+ atomic64_dec_unchecked(v);
71589+}
71590+#endif
71591+
71592 static inline void atomic_long_add(long i, atomic_long_t *l)
71593 {
71594 atomic64_t *v = (atomic64_t *)l;
71595@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71596 atomic64_add(i, v);
71597 }
71598
71599+#ifdef CONFIG_PAX_REFCOUNT
71600+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71601+{
71602+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71603+
71604+ atomic64_add_unchecked(i, v);
71605+}
71606+#endif
71607+
71608 static inline void atomic_long_sub(long i, atomic_long_t *l)
71609 {
71610 atomic64_t *v = (atomic64_t *)l;
71611@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71612 atomic64_sub(i, v);
71613 }
71614
71615+#ifdef CONFIG_PAX_REFCOUNT
71616+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71617+{
71618+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71619+
71620+ atomic64_sub_unchecked(i, v);
71621+}
71622+#endif
71623+
71624 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71625 {
71626 atomic64_t *v = (atomic64_t *)l;
71627@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71628 return (long)atomic64_add_return(i, v);
71629 }
71630
71631+#ifdef CONFIG_PAX_REFCOUNT
71632+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71633+{
71634+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71635+
71636+ return (long)atomic64_add_return_unchecked(i, v);
71637+}
71638+#endif
71639+
71640 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71641 {
71642 atomic64_t *v = (atomic64_t *)l;
71643@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71644 return (long)atomic64_inc_return(v);
71645 }
71646
71647+#ifdef CONFIG_PAX_REFCOUNT
71648+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71649+{
71650+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71651+
71652+ return (long)atomic64_inc_return_unchecked(v);
71653+}
71654+#endif
71655+
71656 static inline long atomic_long_dec_return(atomic_long_t *l)
71657 {
71658 atomic64_t *v = (atomic64_t *)l;
71659@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71660
71661 typedef atomic_t atomic_long_t;
71662
71663+#ifdef CONFIG_PAX_REFCOUNT
71664+typedef atomic_unchecked_t atomic_long_unchecked_t;
71665+#else
71666+typedef atomic_t atomic_long_unchecked_t;
71667+#endif
71668+
71669 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
71670 static inline long atomic_long_read(atomic_long_t *l)
71671 {
71672@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71673 return (long)atomic_read(v);
71674 }
71675
71676+#ifdef CONFIG_PAX_REFCOUNT
71677+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71678+{
71679+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71680+
71681+ return (long)atomic_read_unchecked(v);
71682+}
71683+#endif
71684+
71685 static inline void atomic_long_set(atomic_long_t *l, long i)
71686 {
71687 atomic_t *v = (atomic_t *)l;
71688@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71689 atomic_set(v, i);
71690 }
71691
71692+#ifdef CONFIG_PAX_REFCOUNT
71693+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71694+{
71695+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71696+
71697+ atomic_set_unchecked(v, i);
71698+}
71699+#endif
71700+
71701 static inline void atomic_long_inc(atomic_long_t *l)
71702 {
71703 atomic_t *v = (atomic_t *)l;
71704@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71705 atomic_inc(v);
71706 }
71707
71708+#ifdef CONFIG_PAX_REFCOUNT
71709+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71710+{
71711+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71712+
71713+ atomic_inc_unchecked(v);
71714+}
71715+#endif
71716+
71717 static inline void atomic_long_dec(atomic_long_t *l)
71718 {
71719 atomic_t *v = (atomic_t *)l;
71720@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71721 atomic_dec(v);
71722 }
71723
71724+#ifdef CONFIG_PAX_REFCOUNT
71725+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71726+{
71727+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71728+
71729+ atomic_dec_unchecked(v);
71730+}
71731+#endif
71732+
71733 static inline void atomic_long_add(long i, atomic_long_t *l)
71734 {
71735 atomic_t *v = (atomic_t *)l;
71736@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71737 atomic_add(i, v);
71738 }
71739
71740+#ifdef CONFIG_PAX_REFCOUNT
71741+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71742+{
71743+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71744+
71745+ atomic_add_unchecked(i, v);
71746+}
71747+#endif
71748+
71749 static inline void atomic_long_sub(long i, atomic_long_t *l)
71750 {
71751 atomic_t *v = (atomic_t *)l;
71752@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71753 atomic_sub(i, v);
71754 }
71755
71756+#ifdef CONFIG_PAX_REFCOUNT
71757+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71758+{
71759+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71760+
71761+ atomic_sub_unchecked(i, v);
71762+}
71763+#endif
71764+
71765 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71766 {
71767 atomic_t *v = (atomic_t *)l;
71768@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71769 return (long)atomic_add_return(i, v);
71770 }
71771
71772+#ifdef CONFIG_PAX_REFCOUNT
71773+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71774+{
71775+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71776+
71777+ return (long)atomic_add_return_unchecked(i, v);
71778+}
71779+
71780+#endif
71781+
71782 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71783 {
71784 atomic_t *v = (atomic_t *)l;
71785@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71786 return (long)atomic_inc_return(v);
71787 }
71788
71789+#ifdef CONFIG_PAX_REFCOUNT
71790+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71791+{
71792+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71793+
71794+ return (long)atomic_inc_return_unchecked(v);
71795+}
71796+#endif
71797+
71798 static inline long atomic_long_dec_return(atomic_long_t *l)
71799 {
71800 atomic_t *v = (atomic_t *)l;
71801@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71802
71803 #endif /* BITS_PER_LONG == 64 */
71804
71805+#ifdef CONFIG_PAX_REFCOUNT
71806+static inline void pax_refcount_needs_these_functions(void)
71807+{
71808+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
71809+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
71810+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
71811+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
71812+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
71813+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
71814+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
71815+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
71816+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
71817+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
71818+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
71819+#ifdef CONFIG_X86
71820+ atomic_clear_mask_unchecked(0, NULL);
71821+ atomic_set_mask_unchecked(0, NULL);
71822+#endif
71823+
71824+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
71825+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
71826+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
71827+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
71828+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
71829+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
71830+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
71831+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
71832+}
71833+#else
71834+#define atomic_read_unchecked(v) atomic_read(v)
71835+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
71836+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
71837+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
71838+#define atomic_inc_unchecked(v) atomic_inc(v)
71839+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
71840+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
71841+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
71842+#define atomic_dec_unchecked(v) atomic_dec(v)
71843+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
71844+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
71845+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
71846+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
71847+
71848+#define atomic_long_read_unchecked(v) atomic_long_read(v)
71849+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
71850+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
71851+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
71852+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
71853+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
71854+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
71855+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
71856+#endif
71857+
71858 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
71859diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
71860index 33bd2de..f31bff97 100644
71861--- a/include/asm-generic/atomic.h
71862+++ b/include/asm-generic/atomic.h
71863@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
71864 * Atomically clears the bits set in @mask from @v
71865 */
71866 #ifndef atomic_clear_mask
71867-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
71868+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
71869 {
71870 unsigned long flags;
71871
71872diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
71873index b18ce4f..2ee2843 100644
71874--- a/include/asm-generic/atomic64.h
71875+++ b/include/asm-generic/atomic64.h
71876@@ -16,6 +16,8 @@ typedef struct {
71877 long long counter;
71878 } atomic64_t;
71879
71880+typedef atomic64_t atomic64_unchecked_t;
71881+
71882 #define ATOMIC64_INIT(i) { (i) }
71883
71884 extern long long atomic64_read(const atomic64_t *v);
71885@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
71886 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
71887 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
71888
71889+#define atomic64_read_unchecked(v) atomic64_read(v)
71890+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
71891+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
71892+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
71893+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
71894+#define atomic64_inc_unchecked(v) atomic64_inc(v)
71895+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
71896+#define atomic64_dec_unchecked(v) atomic64_dec(v)
71897+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
71898+
71899 #endif /* _ASM_GENERIC_ATOMIC64_H */
71900diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
71901index 1bfcfe5..e04c5c9 100644
71902--- a/include/asm-generic/cache.h
71903+++ b/include/asm-generic/cache.h
71904@@ -6,7 +6,7 @@
71905 * cache lines need to provide their own cache.h.
71906 */
71907
71908-#define L1_CACHE_SHIFT 5
71909-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
71910+#define L1_CACHE_SHIFT 5UL
71911+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
71912
71913 #endif /* __ASM_GENERIC_CACHE_H */
71914diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
71915index 0d68a1e..b74a761 100644
71916--- a/include/asm-generic/emergency-restart.h
71917+++ b/include/asm-generic/emergency-restart.h
71918@@ -1,7 +1,7 @@
71919 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
71920 #define _ASM_GENERIC_EMERGENCY_RESTART_H
71921
71922-static inline void machine_emergency_restart(void)
71923+static inline __noreturn void machine_emergency_restart(void)
71924 {
71925 machine_restart(NULL);
71926 }
71927diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
71928index 90f99c7..00ce236 100644
71929--- a/include/asm-generic/kmap_types.h
71930+++ b/include/asm-generic/kmap_types.h
71931@@ -2,9 +2,9 @@
71932 #define _ASM_GENERIC_KMAP_TYPES_H
71933
71934 #ifdef __WITH_KM_FENCE
71935-# define KM_TYPE_NR 41
71936+# define KM_TYPE_NR 42
71937 #else
71938-# define KM_TYPE_NR 20
71939+# define KM_TYPE_NR 21
71940 #endif
71941
71942 #endif
71943diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
71944index 9ceb03b..62b0b8f 100644
71945--- a/include/asm-generic/local.h
71946+++ b/include/asm-generic/local.h
71947@@ -23,24 +23,37 @@ typedef struct
71948 atomic_long_t a;
71949 } local_t;
71950
71951+typedef struct {
71952+ atomic_long_unchecked_t a;
71953+} local_unchecked_t;
71954+
71955 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
71956
71957 #define local_read(l) atomic_long_read(&(l)->a)
71958+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
71959 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
71960+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
71961 #define local_inc(l) atomic_long_inc(&(l)->a)
71962+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
71963 #define local_dec(l) atomic_long_dec(&(l)->a)
71964+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
71965 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
71966+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
71967 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
71968+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
71969
71970 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
71971 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
71972 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
71973 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
71974 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
71975+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
71976 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
71977 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
71978+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
71979
71980 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
71981+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
71982 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
71983 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
71984 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
71985diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
71986index 725612b..9cc513a 100644
71987--- a/include/asm-generic/pgtable-nopmd.h
71988+++ b/include/asm-generic/pgtable-nopmd.h
71989@@ -1,14 +1,19 @@
71990 #ifndef _PGTABLE_NOPMD_H
71991 #define _PGTABLE_NOPMD_H
71992
71993-#ifndef __ASSEMBLY__
71994-
71995 #include <asm-generic/pgtable-nopud.h>
71996
71997-struct mm_struct;
71998-
71999 #define __PAGETABLE_PMD_FOLDED
72000
72001+#define PMD_SHIFT PUD_SHIFT
72002+#define PTRS_PER_PMD 1
72003+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
72004+#define PMD_MASK (~(PMD_SIZE-1))
72005+
72006+#ifndef __ASSEMBLY__
72007+
72008+struct mm_struct;
72009+
72010 /*
72011 * Having the pmd type consist of a pud gets the size right, and allows
72012 * us to conceptually access the pud entry that this pmd is folded into
72013@@ -16,11 +21,6 @@ struct mm_struct;
72014 */
72015 typedef struct { pud_t pud; } pmd_t;
72016
72017-#define PMD_SHIFT PUD_SHIFT
72018-#define PTRS_PER_PMD 1
72019-#define PMD_SIZE (1UL << PMD_SHIFT)
72020-#define PMD_MASK (~(PMD_SIZE-1))
72021-
72022 /*
72023 * The "pud_xxx()" functions here are trivial for a folded two-level
72024 * setup: the pmd is never bad, and a pmd always exists (as it's folded
72025diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
72026index 810431d..0ec4804f 100644
72027--- a/include/asm-generic/pgtable-nopud.h
72028+++ b/include/asm-generic/pgtable-nopud.h
72029@@ -1,10 +1,15 @@
72030 #ifndef _PGTABLE_NOPUD_H
72031 #define _PGTABLE_NOPUD_H
72032
72033-#ifndef __ASSEMBLY__
72034-
72035 #define __PAGETABLE_PUD_FOLDED
72036
72037+#define PUD_SHIFT PGDIR_SHIFT
72038+#define PTRS_PER_PUD 1
72039+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
72040+#define PUD_MASK (~(PUD_SIZE-1))
72041+
72042+#ifndef __ASSEMBLY__
72043+
72044 /*
72045 * Having the pud type consist of a pgd gets the size right, and allows
72046 * us to conceptually access the pgd entry that this pud is folded into
72047@@ -12,11 +17,6 @@
72048 */
72049 typedef struct { pgd_t pgd; } pud_t;
72050
72051-#define PUD_SHIFT PGDIR_SHIFT
72052-#define PTRS_PER_PUD 1
72053-#define PUD_SIZE (1UL << PUD_SHIFT)
72054-#define PUD_MASK (~(PUD_SIZE-1))
72055-
72056 /*
72057 * The "pgd_xxx()" functions here are trivial for a folded two-level
72058 * setup: the pud is never bad, and a pud always exists (as it's folded
72059@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
72060 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
72061
72062 #define pgd_populate(mm, pgd, pud) do { } while (0)
72063+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
72064 /*
72065 * (puds are folded into pgds so this doesn't get actually called,
72066 * but the define is needed for a generic inline function.)
72067diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
72068index 0807ddf..cd67747 100644
72069--- a/include/asm-generic/pgtable.h
72070+++ b/include/asm-generic/pgtable.h
72071@@ -741,6 +741,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
72072 }
72073 #endif /* CONFIG_NUMA_BALANCING */
72074
72075+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
72076+#ifdef CONFIG_PAX_KERNEXEC
72077+#error KERNEXEC requires pax_open_kernel
72078+#else
72079+static inline unsigned long pax_open_kernel(void) { return 0; }
72080+#endif
72081+#endif
72082+
72083+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
72084+#ifdef CONFIG_PAX_KERNEXEC
72085+#error KERNEXEC requires pax_close_kernel
72086+#else
72087+static inline unsigned long pax_close_kernel(void) { return 0; }
72088+#endif
72089+#endif
72090+
72091 #endif /* CONFIG_MMU */
72092
72093 #endif /* !__ASSEMBLY__ */
72094diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
72095index dc1269c..48a4f51 100644
72096--- a/include/asm-generic/uaccess.h
72097+++ b/include/asm-generic/uaccess.h
72098@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
72099 return __clear_user(to, n);
72100 }
72101
72102+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
72103+#ifdef CONFIG_PAX_MEMORY_UDEREF
72104+#error UDEREF requires pax_open_userland
72105+#else
72106+static inline unsigned long pax_open_userland(void) { return 0; }
72107+#endif
72108+#endif
72109+
72110+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
72111+#ifdef CONFIG_PAX_MEMORY_UDEREF
72112+#error UDEREF requires pax_close_userland
72113+#else
72114+static inline unsigned long pax_close_userland(void) { return 0; }
72115+#endif
72116+#endif
72117+
72118 #endif /* __ASM_GENERIC_UACCESS_H */
72119diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
72120index 69732d2..cbe16d9 100644
72121--- a/include/asm-generic/vmlinux.lds.h
72122+++ b/include/asm-generic/vmlinux.lds.h
72123@@ -227,6 +227,7 @@
72124 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
72125 VMLINUX_SYMBOL(__start_rodata) = .; \
72126 *(.rodata) *(.rodata.*) \
72127+ *(.data..read_only) \
72128 *(__vermagic) /* Kernel version magic */ \
72129 . = ALIGN(8); \
72130 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
72131@@ -710,17 +711,18 @@
72132 * section in the linker script will go there too. @phdr should have
72133 * a leading colon.
72134 *
72135- * Note that this macros defines __per_cpu_load as an absolute symbol.
72136+ * Note that this macros defines per_cpu_load as an absolute symbol.
72137 * If there is no need to put the percpu section at a predetermined
72138 * address, use PERCPU_SECTION.
72139 */
72140 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
72141- VMLINUX_SYMBOL(__per_cpu_load) = .; \
72142- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
72143+ per_cpu_load = .; \
72144+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
72145 - LOAD_OFFSET) { \
72146+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
72147 PERCPU_INPUT(cacheline) \
72148 } phdr \
72149- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
72150+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
72151
72152 /**
72153 * PERCPU_SECTION - define output section for percpu area, simple version
72154diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
72155index 418d270..bfd2794 100644
72156--- a/include/crypto/algapi.h
72157+++ b/include/crypto/algapi.h
72158@@ -34,7 +34,7 @@ struct crypto_type {
72159 unsigned int maskclear;
72160 unsigned int maskset;
72161 unsigned int tfmsize;
72162-};
72163+} __do_const;
72164
72165 struct crypto_instance {
72166 struct crypto_alg alg;
72167diff --git a/include/drm/drmP.h b/include/drm/drmP.h
72168index 12083dc..39740ec 100644
72169--- a/include/drm/drmP.h
72170+++ b/include/drm/drmP.h
72171@@ -69,6 +69,7 @@
72172 #include <linux/workqueue.h>
72173 #include <linux/poll.h>
72174 #include <asm/pgalloc.h>
72175+#include <asm/local.h>
72176 #include <drm/drm.h>
72177 #include <drm/drm_sarea.h>
72178
72179@@ -293,10 +294,12 @@ do { \
72180 * \param cmd command.
72181 * \param arg argument.
72182 */
72183-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
72184+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
72185+ struct drm_file *file_priv);
72186+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
72187 struct drm_file *file_priv);
72188
72189-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
72190+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
72191 unsigned long arg);
72192
72193 #define DRM_IOCTL_NR(n) _IOC_NR(n)
72194@@ -311,10 +314,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
72195 struct drm_ioctl_desc {
72196 unsigned int cmd;
72197 int flags;
72198- drm_ioctl_t *func;
72199+ drm_ioctl_t func;
72200 unsigned int cmd_drv;
72201 const char *name;
72202-};
72203+} __do_const;
72204
72205 /**
72206 * Creates a driver or general drm_ioctl_desc array entry for the given
72207@@ -1015,7 +1018,7 @@ struct drm_info_list {
72208 int (*show)(struct seq_file*, void*); /** show callback */
72209 u32 driver_features; /**< Required driver features for this entry */
72210 void *data;
72211-};
72212+} __do_const;
72213
72214 /**
72215 * debugfs node structure. This structure represents a debugfs file.
72216@@ -1088,7 +1091,7 @@ struct drm_device {
72217
72218 /** \name Usage Counters */
72219 /*@{ */
72220- int open_count; /**< Outstanding files open */
72221+ local_t open_count; /**< Outstanding files open */
72222 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
72223 atomic_t vma_count; /**< Outstanding vma areas open */
72224 int buf_use; /**< Buffers in use -- cannot alloc */
72225@@ -1099,7 +1102,7 @@ struct drm_device {
72226 /*@{ */
72227 unsigned long counters;
72228 enum drm_stat_type types[15];
72229- atomic_t counts[15];
72230+ atomic_unchecked_t counts[15];
72231 /*@} */
72232
72233 struct list_head filelist;
72234diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
72235index f43d556..94d9343 100644
72236--- a/include/drm/drm_crtc_helper.h
72237+++ b/include/drm/drm_crtc_helper.h
72238@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
72239 struct drm_connector *connector);
72240 /* disable encoder when not in use - more explicit than dpms off */
72241 void (*disable)(struct drm_encoder *encoder);
72242-};
72243+} __no_const;
72244
72245 /**
72246 * drm_connector_helper_funcs - helper operations for connectors
72247diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
72248index 72dcbe8..8db58d7 100644
72249--- a/include/drm/ttm/ttm_memory.h
72250+++ b/include/drm/ttm/ttm_memory.h
72251@@ -48,7 +48,7 @@
72252
72253 struct ttm_mem_shrink {
72254 int (*do_shrink) (struct ttm_mem_shrink *);
72255-};
72256+} __no_const;
72257
72258 /**
72259 * struct ttm_mem_global - Global memory accounting structure.
72260diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
72261index 4b840e8..155d235 100644
72262--- a/include/keys/asymmetric-subtype.h
72263+++ b/include/keys/asymmetric-subtype.h
72264@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
72265 /* Verify the signature on a key of this subtype (optional) */
72266 int (*verify_signature)(const struct key *key,
72267 const struct public_key_signature *sig);
72268-};
72269+} __do_const;
72270
72271 /**
72272 * asymmetric_key_subtype - Get the subtype from an asymmetric key
72273diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
72274index c1da539..1dcec55 100644
72275--- a/include/linux/atmdev.h
72276+++ b/include/linux/atmdev.h
72277@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
72278 #endif
72279
72280 struct k_atm_aal_stats {
72281-#define __HANDLE_ITEM(i) atomic_t i
72282+#define __HANDLE_ITEM(i) atomic_unchecked_t i
72283 __AAL_STAT_ITEMS
72284 #undef __HANDLE_ITEM
72285 };
72286@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
72287 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
72288 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
72289 struct module *owner;
72290-};
72291+} __do_const ;
72292
72293 struct atmphy_ops {
72294 int (*start)(struct atm_dev *dev);
72295diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
72296index 70cf138..0418ee2 100644
72297--- a/include/linux/binfmts.h
72298+++ b/include/linux/binfmts.h
72299@@ -73,8 +73,10 @@ struct linux_binfmt {
72300 int (*load_binary)(struct linux_binprm *);
72301 int (*load_shlib)(struct file *);
72302 int (*core_dump)(struct coredump_params *cprm);
72303+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
72304+ void (*handle_mmap)(struct file *);
72305 unsigned long min_coredump; /* minimal dump size */
72306-};
72307+} __do_const;
72308
72309 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
72310
72311diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
72312index 2fdb4a4..54aad7e 100644
72313--- a/include/linux/blkdev.h
72314+++ b/include/linux/blkdev.h
72315@@ -1526,7 +1526,7 @@ struct block_device_operations {
72316 /* this callback is with swap_lock and sometimes page table lock held */
72317 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
72318 struct module *owner;
72319-};
72320+} __do_const;
72321
72322 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
72323 unsigned long);
72324diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
72325index 7c2e030..b72475d 100644
72326--- a/include/linux/blktrace_api.h
72327+++ b/include/linux/blktrace_api.h
72328@@ -23,7 +23,7 @@ struct blk_trace {
72329 struct dentry *dir;
72330 struct dentry *dropped_file;
72331 struct dentry *msg_file;
72332- atomic_t dropped;
72333+ atomic_unchecked_t dropped;
72334 };
72335
72336 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
72337diff --git a/include/linux/cache.h b/include/linux/cache.h
72338index 4c57065..4307975 100644
72339--- a/include/linux/cache.h
72340+++ b/include/linux/cache.h
72341@@ -16,6 +16,10 @@
72342 #define __read_mostly
72343 #endif
72344
72345+#ifndef __read_only
72346+#define __read_only __read_mostly
72347+#endif
72348+
72349 #ifndef ____cacheline_aligned
72350 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
72351 #endif
72352diff --git a/include/linux/capability.h b/include/linux/capability.h
72353index d9a4f7f4..19f77d6 100644
72354--- a/include/linux/capability.h
72355+++ b/include/linux/capability.h
72356@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
72357 extern bool nsown_capable(int cap);
72358 extern bool inode_capable(const struct inode *inode, int cap);
72359 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
72360+extern bool capable_nolog(int cap);
72361+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
72362+extern bool inode_capable_nolog(const struct inode *inode, int cap);
72363
72364 /* audit system wants to get cap info from files as well */
72365 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
72366
72367+extern int is_privileged_binary(const struct dentry *dentry);
72368+
72369 #endif /* !_LINUX_CAPABILITY_H */
72370diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
72371index 8609d57..86e4d79 100644
72372--- a/include/linux/cdrom.h
72373+++ b/include/linux/cdrom.h
72374@@ -87,7 +87,6 @@ struct cdrom_device_ops {
72375
72376 /* driver specifications */
72377 const int capability; /* capability flags */
72378- int n_minors; /* number of active minor devices */
72379 /* handle uniform packets for scsi type devices (scsi,atapi) */
72380 int (*generic_packet) (struct cdrom_device_info *,
72381 struct packet_command *);
72382diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
72383index 4ce9056..86caac6 100644
72384--- a/include/linux/cleancache.h
72385+++ b/include/linux/cleancache.h
72386@@ -31,7 +31,7 @@ struct cleancache_ops {
72387 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
72388 void (*invalidate_inode)(int, struct cleancache_filekey);
72389 void (*invalidate_fs)(int);
72390-};
72391+} __no_const;
72392
72393 extern struct cleancache_ops *
72394 cleancache_register_ops(struct cleancache_ops *ops);
72395diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
72396index 1ec14a7..d0654a2 100644
72397--- a/include/linux/clk-provider.h
72398+++ b/include/linux/clk-provider.h
72399@@ -132,6 +132,7 @@ struct clk_ops {
72400 unsigned long);
72401 void (*init)(struct clk_hw *hw);
72402 };
72403+typedef struct clk_ops __no_const clk_ops_no_const;
72404
72405 /**
72406 * struct clk_init_data - holds init data that's common to all clocks and is
72407diff --git a/include/linux/compat.h b/include/linux/compat.h
72408index 7f0c1dd..206ac34 100644
72409--- a/include/linux/compat.h
72410+++ b/include/linux/compat.h
72411@@ -312,7 +312,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
72412 compat_size_t __user *len_ptr);
72413
72414 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
72415-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
72416+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
72417 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
72418 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
72419 compat_ssize_t msgsz, int msgflg);
72420@@ -419,7 +419,7 @@ extern int compat_ptrace_request(struct task_struct *child,
72421 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
72422 compat_ulong_t addr, compat_ulong_t data);
72423 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
72424- compat_long_t addr, compat_long_t data);
72425+ compat_ulong_t addr, compat_ulong_t data);
72426
72427 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
72428 /*
72429@@ -669,6 +669,7 @@ asmlinkage long compat_sys_sigaltstack(const compat_stack_t __user *uss_ptr,
72430
72431 int compat_restore_altstack(const compat_stack_t __user *uss);
72432 int __compat_save_altstack(compat_stack_t __user *, unsigned long);
72433+void __compat_save_altstack_ex(compat_stack_t __user *, unsigned long);
72434
72435 asmlinkage long compat_sys_sched_rr_get_interval(compat_pid_t pid,
72436 struct compat_timespec __user *interval);
72437diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
72438index 842de22..7f3a41f 100644
72439--- a/include/linux/compiler-gcc4.h
72440+++ b/include/linux/compiler-gcc4.h
72441@@ -39,9 +39,29 @@
72442 # define __compiletime_warning(message) __attribute__((warning(message)))
72443 # define __compiletime_error(message) __attribute__((error(message)))
72444 #endif /* __CHECKER__ */
72445+
72446+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
72447+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
72448+#define __bos0(ptr) __bos((ptr), 0)
72449+#define __bos1(ptr) __bos((ptr), 1)
72450 #endif /* GCC_VERSION >= 40300 */
72451
72452 #if GCC_VERSION >= 40500
72453+
72454+#ifdef CONSTIFY_PLUGIN
72455+#define __no_const __attribute__((no_const))
72456+#define __do_const __attribute__((do_const))
72457+#endif
72458+
72459+#ifdef SIZE_OVERFLOW_PLUGIN
72460+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
72461+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
72462+#endif
72463+
72464+#ifdef LATENT_ENTROPY_PLUGIN
72465+#define __latent_entropy __attribute__((latent_entropy))
72466+#endif
72467+
72468 /*
72469 * Mark a position in code as unreachable. This can be used to
72470 * suppress control flow warnings after asm blocks that transfer
72471diff --git a/include/linux/compiler.h b/include/linux/compiler.h
72472index 92669cd..1771a15 100644
72473--- a/include/linux/compiler.h
72474+++ b/include/linux/compiler.h
72475@@ -5,11 +5,14 @@
72476
72477 #ifdef __CHECKER__
72478 # define __user __attribute__((noderef, address_space(1)))
72479+# define __force_user __force __user
72480 # define __kernel __attribute__((address_space(0)))
72481+# define __force_kernel __force __kernel
72482 # define __safe __attribute__((safe))
72483 # define __force __attribute__((force))
72484 # define __nocast __attribute__((nocast))
72485 # define __iomem __attribute__((noderef, address_space(2)))
72486+# define __force_iomem __force __iomem
72487 # define __must_hold(x) __attribute__((context(x,1,1)))
72488 # define __acquires(x) __attribute__((context(x,0,1)))
72489 # define __releases(x) __attribute__((context(x,1,0)))
72490@@ -17,20 +20,37 @@
72491 # define __release(x) __context__(x,-1)
72492 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
72493 # define __percpu __attribute__((noderef, address_space(3)))
72494+# define __force_percpu __force __percpu
72495 #ifdef CONFIG_SPARSE_RCU_POINTER
72496 # define __rcu __attribute__((noderef, address_space(4)))
72497+# define __force_rcu __force __rcu
72498 #else
72499 # define __rcu
72500+# define __force_rcu
72501 #endif
72502 extern void __chk_user_ptr(const volatile void __user *);
72503 extern void __chk_io_ptr(const volatile void __iomem *);
72504 #else
72505-# define __user
72506-# define __kernel
72507+# ifdef CHECKER_PLUGIN
72508+//# define __user
72509+//# define __force_user
72510+//# define __kernel
72511+//# define __force_kernel
72512+# else
72513+# ifdef STRUCTLEAK_PLUGIN
72514+# define __user __attribute__((user))
72515+# else
72516+# define __user
72517+# endif
72518+# define __force_user
72519+# define __kernel
72520+# define __force_kernel
72521+# endif
72522 # define __safe
72523 # define __force
72524 # define __nocast
72525 # define __iomem
72526+# define __force_iomem
72527 # define __chk_user_ptr(x) (void)0
72528 # define __chk_io_ptr(x) (void)0
72529 # define __builtin_warning(x, y...) (1)
72530@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
72531 # define __release(x) (void)0
72532 # define __cond_lock(x,c) (c)
72533 # define __percpu
72534+# define __force_percpu
72535 # define __rcu
72536+# define __force_rcu
72537 #endif
72538
72539 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
72540@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72541 # define __attribute_const__ /* unimplemented */
72542 #endif
72543
72544+#ifndef __no_const
72545+# define __no_const
72546+#endif
72547+
72548+#ifndef __do_const
72549+# define __do_const
72550+#endif
72551+
72552+#ifndef __size_overflow
72553+# define __size_overflow(...)
72554+#endif
72555+
72556+#ifndef __intentional_overflow
72557+# define __intentional_overflow(...)
72558+#endif
72559+
72560+#ifndef __latent_entropy
72561+# define __latent_entropy
72562+#endif
72563+
72564 /*
72565 * Tell gcc if a function is cold. The compiler will assume any path
72566 * directly leading to the call is unlikely.
72567@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72568 #define __cold
72569 #endif
72570
72571+#ifndef __alloc_size
72572+#define __alloc_size(...)
72573+#endif
72574+
72575+#ifndef __bos
72576+#define __bos(ptr, arg)
72577+#endif
72578+
72579+#ifndef __bos0
72580+#define __bos0(ptr)
72581+#endif
72582+
72583+#ifndef __bos1
72584+#define __bos1(ptr)
72585+#endif
72586+
72587 /* Simple shorthand for a section definition */
72588 #ifndef __section
72589 # define __section(S) __attribute__ ((__section__(#S)))
72590@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72591 * use is to mediate communication between process-level code and irq/NMI
72592 * handlers, all running on the same CPU.
72593 */
72594-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
72595+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
72596+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
72597
72598 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
72599 #ifdef CONFIG_KPROBES
72600diff --git a/include/linux/completion.h b/include/linux/completion.h
72601index 3cd574d..adce5fa 100644
72602--- a/include/linux/completion.h
72603+++ b/include/linux/completion.h
72604@@ -79,15 +79,15 @@ static inline void init_completion(struct completion *x)
72605 extern void wait_for_completion(struct completion *);
72606 extern void wait_for_completion_io(struct completion *);
72607 extern int wait_for_completion_interruptible(struct completion *x);
72608-extern int wait_for_completion_killable(struct completion *x);
72609+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
72610 extern unsigned long wait_for_completion_timeout(struct completion *x,
72611 unsigned long timeout);
72612 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
72613 unsigned long timeout);
72614 extern long wait_for_completion_interruptible_timeout(
72615- struct completion *x, unsigned long timeout);
72616+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72617 extern long wait_for_completion_killable_timeout(
72618- struct completion *x, unsigned long timeout);
72619+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72620 extern bool try_wait_for_completion(struct completion *x);
72621 extern bool completion_done(struct completion *x);
72622
72623diff --git a/include/linux/configfs.h b/include/linux/configfs.h
72624index 34025df..d94bbbc 100644
72625--- a/include/linux/configfs.h
72626+++ b/include/linux/configfs.h
72627@@ -125,7 +125,7 @@ struct configfs_attribute {
72628 const char *ca_name;
72629 struct module *ca_owner;
72630 umode_t ca_mode;
72631-};
72632+} __do_const;
72633
72634 /*
72635 * Users often need to create attribute structures for their configurable
72636diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
72637index 90d5a15..950cb80 100644
72638--- a/include/linux/cpufreq.h
72639+++ b/include/linux/cpufreq.h
72640@@ -266,7 +266,7 @@ struct cpufreq_driver {
72641 int (*suspend) (struct cpufreq_policy *policy);
72642 int (*resume) (struct cpufreq_policy *policy);
72643 struct freq_attr **attr;
72644-};
72645+} __do_const;
72646
72647 /* flags */
72648
72649@@ -325,6 +325,7 @@ struct global_attr {
72650 ssize_t (*store)(struct kobject *a, struct attribute *b,
72651 const char *c, size_t count);
72652 };
72653+typedef struct global_attr __no_const global_attr_no_const;
72654
72655 #define define_one_global_ro(_name) \
72656 static struct global_attr _name = \
72657diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
72658index 0bc4b74..973b368 100644
72659--- a/include/linux/cpuidle.h
72660+++ b/include/linux/cpuidle.h
72661@@ -52,7 +52,8 @@ struct cpuidle_state {
72662 int index);
72663
72664 int (*enter_dead) (struct cpuidle_device *dev, int index);
72665-};
72666+} __do_const;
72667+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
72668
72669 /* Idle State Flags */
72670 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
72671@@ -191,7 +192,7 @@ struct cpuidle_governor {
72672 void (*reflect) (struct cpuidle_device *dev, int index);
72673
72674 struct module *owner;
72675-};
72676+} __do_const;
72677
72678 #ifdef CONFIG_CPU_IDLE
72679
72680diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
72681index d08e4d2..95fad61 100644
72682--- a/include/linux/cpumask.h
72683+++ b/include/linux/cpumask.h
72684@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72685 }
72686
72687 /* Valid inputs for n are -1 and 0. */
72688-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72689+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72690 {
72691 return n+1;
72692 }
72693
72694-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72695+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72696 {
72697 return n+1;
72698 }
72699
72700-static inline unsigned int cpumask_next_and(int n,
72701+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
72702 const struct cpumask *srcp,
72703 const struct cpumask *andp)
72704 {
72705@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72706 *
72707 * Returns >= nr_cpu_ids if no further cpus set.
72708 */
72709-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72710+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72711 {
72712 /* -1 is a legal arg here. */
72713 if (n != -1)
72714@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72715 *
72716 * Returns >= nr_cpu_ids if no further cpus unset.
72717 */
72718-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72719+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72720 {
72721 /* -1 is a legal arg here. */
72722 if (n != -1)
72723@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72724 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
72725 }
72726
72727-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
72728+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
72729 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
72730
72731 /**
72732diff --git a/include/linux/cred.h b/include/linux/cred.h
72733index 04421e8..6bce4ef 100644
72734--- a/include/linux/cred.h
72735+++ b/include/linux/cred.h
72736@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
72737 static inline void validate_process_creds(void)
72738 {
72739 }
72740+static inline void validate_task_creds(struct task_struct *task)
72741+{
72742+}
72743 #endif
72744
72745 /**
72746diff --git a/include/linux/crypto.h b/include/linux/crypto.h
72747index b92eadf..b4ecdc1 100644
72748--- a/include/linux/crypto.h
72749+++ b/include/linux/crypto.h
72750@@ -373,7 +373,7 @@ struct cipher_tfm {
72751 const u8 *key, unsigned int keylen);
72752 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72753 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72754-};
72755+} __no_const;
72756
72757 struct hash_tfm {
72758 int (*init)(struct hash_desc *desc);
72759@@ -394,13 +394,13 @@ struct compress_tfm {
72760 int (*cot_decompress)(struct crypto_tfm *tfm,
72761 const u8 *src, unsigned int slen,
72762 u8 *dst, unsigned int *dlen);
72763-};
72764+} __no_const;
72765
72766 struct rng_tfm {
72767 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
72768 unsigned int dlen);
72769 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
72770-};
72771+} __no_const;
72772
72773 #define crt_ablkcipher crt_u.ablkcipher
72774 #define crt_aead crt_u.aead
72775diff --git a/include/linux/ctype.h b/include/linux/ctype.h
72776index 653589e..4ef254a 100644
72777--- a/include/linux/ctype.h
72778+++ b/include/linux/ctype.h
72779@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
72780 * Fast implementation of tolower() for internal usage. Do not use in your
72781 * code.
72782 */
72783-static inline char _tolower(const char c)
72784+static inline unsigned char _tolower(const unsigned char c)
72785 {
72786 return c | 0x20;
72787 }
72788diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
72789index 7925bf0..d5143d2 100644
72790--- a/include/linux/decompress/mm.h
72791+++ b/include/linux/decompress/mm.h
72792@@ -77,7 +77,7 @@ static void free(void *where)
72793 * warnings when not needed (indeed large_malloc / large_free are not
72794 * needed by inflate */
72795
72796-#define malloc(a) kmalloc(a, GFP_KERNEL)
72797+#define malloc(a) kmalloc((a), GFP_KERNEL)
72798 #define free(a) kfree(a)
72799
72800 #define large_malloc(a) vmalloc(a)
72801diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
72802index 5f1ab92..39c35ae 100644
72803--- a/include/linux/devfreq.h
72804+++ b/include/linux/devfreq.h
72805@@ -114,7 +114,7 @@ struct devfreq_governor {
72806 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
72807 int (*event_handler)(struct devfreq *devfreq,
72808 unsigned int event, void *data);
72809-};
72810+} __do_const;
72811
72812 /**
72813 * struct devfreq - Device devfreq structure
72814diff --git a/include/linux/device.h b/include/linux/device.h
72815index 22b546a..a573dc9 100644
72816--- a/include/linux/device.h
72817+++ b/include/linux/device.h
72818@@ -305,7 +305,7 @@ struct subsys_interface {
72819 struct list_head node;
72820 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
72821 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
72822-};
72823+} __do_const;
72824
72825 int subsys_interface_register(struct subsys_interface *sif);
72826 void subsys_interface_unregister(struct subsys_interface *sif);
72827@@ -493,7 +493,7 @@ struct device_type {
72828 void (*release)(struct device *dev);
72829
72830 const struct dev_pm_ops *pm;
72831-};
72832+} __do_const;
72833
72834 /* interface for exporting device attributes */
72835 struct device_attribute {
72836@@ -503,11 +503,12 @@ struct device_attribute {
72837 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
72838 const char *buf, size_t count);
72839 };
72840+typedef struct device_attribute __no_const device_attribute_no_const;
72841
72842 struct dev_ext_attribute {
72843 struct device_attribute attr;
72844 void *var;
72845-};
72846+} __do_const;
72847
72848 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
72849 char *buf);
72850diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
72851index 94af418..b1ca7a2 100644
72852--- a/include/linux/dma-mapping.h
72853+++ b/include/linux/dma-mapping.h
72854@@ -54,7 +54,7 @@ struct dma_map_ops {
72855 u64 (*get_required_mask)(struct device *dev);
72856 #endif
72857 int is_phys;
72858-};
72859+} __do_const;
72860
72861 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
72862
72863diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
72864index cb286b1..923d066 100644
72865--- a/include/linux/dmaengine.h
72866+++ b/include/linux/dmaengine.h
72867@@ -1030,9 +1030,9 @@ struct dma_pinned_list {
72868 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
72869 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
72870
72871-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
72872+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
72873 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
72874-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
72875+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
72876 struct dma_pinned_list *pinned_list, struct page *page,
72877 unsigned int offset, size_t len);
72878
72879diff --git a/include/linux/efi.h b/include/linux/efi.h
72880index 5f8f176..62a0556 100644
72881--- a/include/linux/efi.h
72882+++ b/include/linux/efi.h
72883@@ -745,6 +745,7 @@ struct efivar_operations {
72884 efi_set_variable_t *set_variable;
72885 efi_query_variable_store_t *query_variable_store;
72886 };
72887+typedef struct efivar_operations __no_const efivar_operations_no_const;
72888
72889 struct efivars {
72890 /*
72891diff --git a/include/linux/elf.h b/include/linux/elf.h
72892index 40a3c0e..4c45a38 100644
72893--- a/include/linux/elf.h
72894+++ b/include/linux/elf.h
72895@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
72896 #define elf_note elf32_note
72897 #define elf_addr_t Elf32_Off
72898 #define Elf_Half Elf32_Half
72899+#define elf_dyn Elf32_Dyn
72900
72901 #else
72902
72903@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
72904 #define elf_note elf64_note
72905 #define elf_addr_t Elf64_Off
72906 #define Elf_Half Elf64_Half
72907+#define elf_dyn Elf64_Dyn
72908
72909 #endif
72910
72911diff --git a/include/linux/err.h b/include/linux/err.h
72912index 221fcfb..f29e5e2 100644
72913--- a/include/linux/err.h
72914+++ b/include/linux/err.h
72915@@ -19,12 +19,12 @@
72916
72917 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
72918
72919-static inline void * __must_check ERR_PTR(long error)
72920+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
72921 {
72922 return (void *) error;
72923 }
72924
72925-static inline long __must_check PTR_ERR(__force const void *ptr)
72926+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
72927 {
72928 return (long) ptr;
72929 }
72930diff --git a/include/linux/extcon.h b/include/linux/extcon.h
72931index fcb51c8..bdafcf6 100644
72932--- a/include/linux/extcon.h
72933+++ b/include/linux/extcon.h
72934@@ -134,7 +134,7 @@ struct extcon_dev {
72935 /* /sys/class/extcon/.../mutually_exclusive/... */
72936 struct attribute_group attr_g_muex;
72937 struct attribute **attrs_muex;
72938- struct device_attribute *d_attrs_muex;
72939+ device_attribute_no_const *d_attrs_muex;
72940 };
72941
72942 /**
72943diff --git a/include/linux/fb.h b/include/linux/fb.h
72944index ffac70a..ca3e711 100644
72945--- a/include/linux/fb.h
72946+++ b/include/linux/fb.h
72947@@ -304,7 +304,7 @@ struct fb_ops {
72948 /* called at KDB enter and leave time to prepare the console */
72949 int (*fb_debug_enter)(struct fb_info *info);
72950 int (*fb_debug_leave)(struct fb_info *info);
72951-};
72952+} __do_const;
72953
72954 #ifdef CONFIG_FB_TILEBLITTING
72955 #define FB_TILE_CURSOR_NONE 0
72956diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
72957index 085197b..0fa6f0b 100644
72958--- a/include/linux/fdtable.h
72959+++ b/include/linux/fdtable.h
72960@@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
72961 void put_files_struct(struct files_struct *fs);
72962 void reset_files_struct(struct files_struct *);
72963 int unshare_files(struct files_struct **);
72964-struct files_struct *dup_fd(struct files_struct *, int *);
72965+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
72966 void do_close_on_exec(struct files_struct *);
72967 int iterate_fd(struct files_struct *, unsigned,
72968 int (*)(const void *, struct file *, unsigned),
72969diff --git a/include/linux/filter.h b/include/linux/filter.h
72970index a6ac848..a104a76 100644
72971--- a/include/linux/filter.h
72972+++ b/include/linux/filter.h
72973@@ -20,6 +20,7 @@ struct compat_sock_fprog {
72974
72975 struct sk_buff;
72976 struct sock;
72977+struct bpf_jit_work;
72978
72979 struct sk_filter
72980 {
72981@@ -27,6 +28,9 @@ struct sk_filter
72982 unsigned int len; /* Number of filter blocks */
72983 unsigned int (*bpf_func)(const struct sk_buff *skb,
72984 const struct sock_filter *filter);
72985+#ifdef CONFIG_BPF_JIT
72986+ struct bpf_jit_work *work;
72987+#endif
72988 struct rcu_head rcu;
72989 struct sock_filter insns[0];
72990 };
72991diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
72992index 8293262..2b3b8bd 100644
72993--- a/include/linux/frontswap.h
72994+++ b/include/linux/frontswap.h
72995@@ -11,7 +11,7 @@ struct frontswap_ops {
72996 int (*load)(unsigned, pgoff_t, struct page *);
72997 void (*invalidate_page)(unsigned, pgoff_t);
72998 void (*invalidate_area)(unsigned);
72999-};
73000+} __no_const;
73001
73002 extern bool frontswap_enabled;
73003 extern struct frontswap_ops *
73004diff --git a/include/linux/fs.h b/include/linux/fs.h
73005index 9818747..788bfbd 100644
73006--- a/include/linux/fs.h
73007+++ b/include/linux/fs.h
73008@@ -1554,7 +1554,8 @@ struct file_operations {
73009 long (*fallocate)(struct file *file, int mode, loff_t offset,
73010 loff_t len);
73011 int (*show_fdinfo)(struct seq_file *m, struct file *f);
73012-};
73013+} __do_const;
73014+typedef struct file_operations __no_const file_operations_no_const;
73015
73016 struct inode_operations {
73017 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
73018@@ -2740,4 +2741,14 @@ static inline bool dir_relax(struct inode *inode)
73019 return !IS_DEADDIR(inode);
73020 }
73021
73022+static inline bool is_sidechannel_device(const struct inode *inode)
73023+{
73024+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
73025+ umode_t mode = inode->i_mode;
73026+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
73027+#else
73028+ return false;
73029+#endif
73030+}
73031+
73032 #endif /* _LINUX_FS_H */
73033diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
73034index 2b93a9a..855d94a 100644
73035--- a/include/linux/fs_struct.h
73036+++ b/include/linux/fs_struct.h
73037@@ -6,7 +6,7 @@
73038 #include <linux/seqlock.h>
73039
73040 struct fs_struct {
73041- int users;
73042+ atomic_t users;
73043 spinlock_t lock;
73044 seqcount_t seq;
73045 int umask;
73046diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
73047index a9ff9a3..1ba1788 100644
73048--- a/include/linux/fscache-cache.h
73049+++ b/include/linux/fscache-cache.h
73050@@ -113,7 +113,7 @@ struct fscache_operation {
73051 fscache_operation_release_t release;
73052 };
73053
73054-extern atomic_t fscache_op_debug_id;
73055+extern atomic_unchecked_t fscache_op_debug_id;
73056 extern void fscache_op_work_func(struct work_struct *work);
73057
73058 extern void fscache_enqueue_operation(struct fscache_operation *);
73059@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
73060 INIT_WORK(&op->work, fscache_op_work_func);
73061 atomic_set(&op->usage, 1);
73062 op->state = FSCACHE_OP_ST_INITIALISED;
73063- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
73064+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
73065 op->processor = processor;
73066 op->release = release;
73067 INIT_LIST_HEAD(&op->pend_link);
73068diff --git a/include/linux/fscache.h b/include/linux/fscache.h
73069index 7a08623..4c07b0f 100644
73070--- a/include/linux/fscache.h
73071+++ b/include/linux/fscache.h
73072@@ -152,7 +152,7 @@ struct fscache_cookie_def {
73073 * - this is mandatory for any object that may have data
73074 */
73075 void (*now_uncached)(void *cookie_netfs_data);
73076-};
73077+} __do_const;
73078
73079 /*
73080 * fscache cached network filesystem type
73081diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
73082index 1c804b0..1432c2b 100644
73083--- a/include/linux/fsnotify.h
73084+++ b/include/linux/fsnotify.h
73085@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
73086 struct inode *inode = file_inode(file);
73087 __u32 mask = FS_ACCESS;
73088
73089+ if (is_sidechannel_device(inode))
73090+ return;
73091+
73092 if (S_ISDIR(inode->i_mode))
73093 mask |= FS_ISDIR;
73094
73095@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
73096 struct inode *inode = file_inode(file);
73097 __u32 mask = FS_MODIFY;
73098
73099+ if (is_sidechannel_device(inode))
73100+ return;
73101+
73102 if (S_ISDIR(inode->i_mode))
73103 mask |= FS_ISDIR;
73104
73105@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
73106 */
73107 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
73108 {
73109- return kstrdup(name, GFP_KERNEL);
73110+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
73111 }
73112
73113 /*
73114diff --git a/include/linux/genhd.h b/include/linux/genhd.h
73115index 9f3c275..911b591 100644
73116--- a/include/linux/genhd.h
73117+++ b/include/linux/genhd.h
73118@@ -194,7 +194,7 @@ struct gendisk {
73119 struct kobject *slave_dir;
73120
73121 struct timer_rand_state *random;
73122- atomic_t sync_io; /* RAID */
73123+ atomic_unchecked_t sync_io; /* RAID */
73124 struct disk_events *ev;
73125 #ifdef CONFIG_BLK_DEV_INTEGRITY
73126 struct blk_integrity *integrity;
73127diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
73128index 023bc34..b02b46a 100644
73129--- a/include/linux/genl_magic_func.h
73130+++ b/include/linux/genl_magic_func.h
73131@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
73132 },
73133
73134 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
73135-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
73136+static struct genl_ops ZZZ_genl_ops[] = {
73137 #include GENL_MAGIC_INCLUDE_FILE
73138 };
73139
73140diff --git a/include/linux/gfp.h b/include/linux/gfp.h
73141index 9b4dd49..61fd41d 100644
73142--- a/include/linux/gfp.h
73143+++ b/include/linux/gfp.h
73144@@ -35,6 +35,13 @@ struct vm_area_struct;
73145 #define ___GFP_NO_KSWAPD 0x400000u
73146 #define ___GFP_OTHER_NODE 0x800000u
73147 #define ___GFP_WRITE 0x1000000u
73148+
73149+#ifdef CONFIG_PAX_USERCOPY_SLABS
73150+#define ___GFP_USERCOPY 0x2000000u
73151+#else
73152+#define ___GFP_USERCOPY 0
73153+#endif
73154+
73155 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
73156
73157 /*
73158@@ -92,6 +99,7 @@ struct vm_area_struct;
73159 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
73160 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
73161 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
73162+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
73163
73164 /*
73165 * This may seem redundant, but it's a way of annotating false positives vs.
73166@@ -99,7 +107,7 @@ struct vm_area_struct;
73167 */
73168 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
73169
73170-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
73171+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
73172 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
73173
73174 /* This equals 0, but use constants in case they ever change */
73175@@ -153,6 +161,8 @@ struct vm_area_struct;
73176 /* 4GB DMA on some platforms */
73177 #define GFP_DMA32 __GFP_DMA32
73178
73179+#define GFP_USERCOPY __GFP_USERCOPY
73180+
73181 /* Convert GFP flags to their corresponding migrate type */
73182 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
73183 {
73184diff --git a/include/linux/gracl.h b/include/linux/gracl.h
73185new file mode 100644
73186index 0000000..ebe6d72
73187--- /dev/null
73188+++ b/include/linux/gracl.h
73189@@ -0,0 +1,319 @@
73190+#ifndef GR_ACL_H
73191+#define GR_ACL_H
73192+
73193+#include <linux/grdefs.h>
73194+#include <linux/resource.h>
73195+#include <linux/capability.h>
73196+#include <linux/dcache.h>
73197+#include <asm/resource.h>
73198+
73199+/* Major status information */
73200+
73201+#define GR_VERSION "grsecurity 2.9.1"
73202+#define GRSECURITY_VERSION 0x2901
73203+
73204+enum {
73205+ GR_SHUTDOWN = 0,
73206+ GR_ENABLE = 1,
73207+ GR_SPROLE = 2,
73208+ GR_RELOAD = 3,
73209+ GR_SEGVMOD = 4,
73210+ GR_STATUS = 5,
73211+ GR_UNSPROLE = 6,
73212+ GR_PASSSET = 7,
73213+ GR_SPROLEPAM = 8,
73214+};
73215+
73216+/* Password setup definitions
73217+ * kernel/grhash.c */
73218+enum {
73219+ GR_PW_LEN = 128,
73220+ GR_SALT_LEN = 16,
73221+ GR_SHA_LEN = 32,
73222+};
73223+
73224+enum {
73225+ GR_SPROLE_LEN = 64,
73226+};
73227+
73228+enum {
73229+ GR_NO_GLOB = 0,
73230+ GR_REG_GLOB,
73231+ GR_CREATE_GLOB
73232+};
73233+
73234+#define GR_NLIMITS 32
73235+
73236+/* Begin Data Structures */
73237+
73238+struct sprole_pw {
73239+ unsigned char *rolename;
73240+ unsigned char salt[GR_SALT_LEN];
73241+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
73242+};
73243+
73244+struct name_entry {
73245+ __u32 key;
73246+ ino_t inode;
73247+ dev_t device;
73248+ char *name;
73249+ __u16 len;
73250+ __u8 deleted;
73251+ struct name_entry *prev;
73252+ struct name_entry *next;
73253+};
73254+
73255+struct inodev_entry {
73256+ struct name_entry *nentry;
73257+ struct inodev_entry *prev;
73258+ struct inodev_entry *next;
73259+};
73260+
73261+struct acl_role_db {
73262+ struct acl_role_label **r_hash;
73263+ __u32 r_size;
73264+};
73265+
73266+struct inodev_db {
73267+ struct inodev_entry **i_hash;
73268+ __u32 i_size;
73269+};
73270+
73271+struct name_db {
73272+ struct name_entry **n_hash;
73273+ __u32 n_size;
73274+};
73275+
73276+struct crash_uid {
73277+ uid_t uid;
73278+ unsigned long expires;
73279+};
73280+
73281+struct gr_hash_struct {
73282+ void **table;
73283+ void **nametable;
73284+ void *first;
73285+ __u32 table_size;
73286+ __u32 used_size;
73287+ int type;
73288+};
73289+
73290+/* Userspace Grsecurity ACL data structures */
73291+
73292+struct acl_subject_label {
73293+ char *filename;
73294+ ino_t inode;
73295+ dev_t device;
73296+ __u32 mode;
73297+ kernel_cap_t cap_mask;
73298+ kernel_cap_t cap_lower;
73299+ kernel_cap_t cap_invert_audit;
73300+
73301+ struct rlimit res[GR_NLIMITS];
73302+ __u32 resmask;
73303+
73304+ __u8 user_trans_type;
73305+ __u8 group_trans_type;
73306+ uid_t *user_transitions;
73307+ gid_t *group_transitions;
73308+ __u16 user_trans_num;
73309+ __u16 group_trans_num;
73310+
73311+ __u32 sock_families[2];
73312+ __u32 ip_proto[8];
73313+ __u32 ip_type;
73314+ struct acl_ip_label **ips;
73315+ __u32 ip_num;
73316+ __u32 inaddr_any_override;
73317+
73318+ __u32 crashes;
73319+ unsigned long expires;
73320+
73321+ struct acl_subject_label *parent_subject;
73322+ struct gr_hash_struct *hash;
73323+ struct acl_subject_label *prev;
73324+ struct acl_subject_label *next;
73325+
73326+ struct acl_object_label **obj_hash;
73327+ __u32 obj_hash_size;
73328+ __u16 pax_flags;
73329+};
73330+
73331+struct role_allowed_ip {
73332+ __u32 addr;
73333+ __u32 netmask;
73334+
73335+ struct role_allowed_ip *prev;
73336+ struct role_allowed_ip *next;
73337+};
73338+
73339+struct role_transition {
73340+ char *rolename;
73341+
73342+ struct role_transition *prev;
73343+ struct role_transition *next;
73344+};
73345+
73346+struct acl_role_label {
73347+ char *rolename;
73348+ uid_t uidgid;
73349+ __u16 roletype;
73350+
73351+ __u16 auth_attempts;
73352+ unsigned long expires;
73353+
73354+ struct acl_subject_label *root_label;
73355+ struct gr_hash_struct *hash;
73356+
73357+ struct acl_role_label *prev;
73358+ struct acl_role_label *next;
73359+
73360+ struct role_transition *transitions;
73361+ struct role_allowed_ip *allowed_ips;
73362+ uid_t *domain_children;
73363+ __u16 domain_child_num;
73364+
73365+ umode_t umask;
73366+
73367+ struct acl_subject_label **subj_hash;
73368+ __u32 subj_hash_size;
73369+};
73370+
73371+struct user_acl_role_db {
73372+ struct acl_role_label **r_table;
73373+ __u32 num_pointers; /* Number of allocations to track */
73374+ __u32 num_roles; /* Number of roles */
73375+ __u32 num_domain_children; /* Number of domain children */
73376+ __u32 num_subjects; /* Number of subjects */
73377+ __u32 num_objects; /* Number of objects */
73378+};
73379+
73380+struct acl_object_label {
73381+ char *filename;
73382+ ino_t inode;
73383+ dev_t device;
73384+ __u32 mode;
73385+
73386+ struct acl_subject_label *nested;
73387+ struct acl_object_label *globbed;
73388+
73389+ /* next two structures not used */
73390+
73391+ struct acl_object_label *prev;
73392+ struct acl_object_label *next;
73393+};
73394+
73395+struct acl_ip_label {
73396+ char *iface;
73397+ __u32 addr;
73398+ __u32 netmask;
73399+ __u16 low, high;
73400+ __u8 mode;
73401+ __u32 type;
73402+ __u32 proto[8];
73403+
73404+ /* next two structures not used */
73405+
73406+ struct acl_ip_label *prev;
73407+ struct acl_ip_label *next;
73408+};
73409+
73410+struct gr_arg {
73411+ struct user_acl_role_db role_db;
73412+ unsigned char pw[GR_PW_LEN];
73413+ unsigned char salt[GR_SALT_LEN];
73414+ unsigned char sum[GR_SHA_LEN];
73415+ unsigned char sp_role[GR_SPROLE_LEN];
73416+ struct sprole_pw *sprole_pws;
73417+ dev_t segv_device;
73418+ ino_t segv_inode;
73419+ uid_t segv_uid;
73420+ __u16 num_sprole_pws;
73421+ __u16 mode;
73422+};
73423+
73424+struct gr_arg_wrapper {
73425+ struct gr_arg *arg;
73426+ __u32 version;
73427+ __u32 size;
73428+};
73429+
73430+struct subject_map {
73431+ struct acl_subject_label *user;
73432+ struct acl_subject_label *kernel;
73433+ struct subject_map *prev;
73434+ struct subject_map *next;
73435+};
73436+
73437+struct acl_subj_map_db {
73438+ struct subject_map **s_hash;
73439+ __u32 s_size;
73440+};
73441+
73442+/* End Data Structures Section */
73443+
73444+/* Hash functions generated by empirical testing by Brad Spengler
73445+ Makes good use of the low bits of the inode. Generally 0-1 times
73446+ in loop for successful match. 0-3 for unsuccessful match.
73447+ Shift/add algorithm with modulus of table size and an XOR*/
73448+
73449+static __inline__ unsigned int
73450+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
73451+{
73452+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
73453+}
73454+
73455+ static __inline__ unsigned int
73456+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
73457+{
73458+ return ((const unsigned long)userp % sz);
73459+}
73460+
73461+static __inline__ unsigned int
73462+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
73463+{
73464+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
73465+}
73466+
73467+static __inline__ unsigned int
73468+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
73469+{
73470+ return full_name_hash((const unsigned char *)name, len) % sz;
73471+}
73472+
73473+#define FOR_EACH_ROLE_START(role) \
73474+ role = role_list; \
73475+ while (role) {
73476+
73477+#define FOR_EACH_ROLE_END(role) \
73478+ role = role->prev; \
73479+ }
73480+
73481+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
73482+ subj = NULL; \
73483+ iter = 0; \
73484+ while (iter < role->subj_hash_size) { \
73485+ if (subj == NULL) \
73486+ subj = role->subj_hash[iter]; \
73487+ if (subj == NULL) { \
73488+ iter++; \
73489+ continue; \
73490+ }
73491+
73492+#define FOR_EACH_SUBJECT_END(subj,iter) \
73493+ subj = subj->next; \
73494+ if (subj == NULL) \
73495+ iter++; \
73496+ }
73497+
73498+
73499+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
73500+ subj = role->hash->first; \
73501+ while (subj != NULL) {
73502+
73503+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
73504+ subj = subj->next; \
73505+ }
73506+
73507+#endif
73508+
73509diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
73510new file mode 100644
73511index 0000000..33ebd1f
73512--- /dev/null
73513+++ b/include/linux/gracl_compat.h
73514@@ -0,0 +1,156 @@
73515+#ifndef GR_ACL_COMPAT_H
73516+#define GR_ACL_COMPAT_H
73517+
73518+#include <linux/resource.h>
73519+#include <asm/resource.h>
73520+
73521+struct sprole_pw_compat {
73522+ compat_uptr_t rolename;
73523+ unsigned char salt[GR_SALT_LEN];
73524+ unsigned char sum[GR_SHA_LEN];
73525+};
73526+
73527+struct gr_hash_struct_compat {
73528+ compat_uptr_t table;
73529+ compat_uptr_t nametable;
73530+ compat_uptr_t first;
73531+ __u32 table_size;
73532+ __u32 used_size;
73533+ int type;
73534+};
73535+
73536+struct acl_subject_label_compat {
73537+ compat_uptr_t filename;
73538+ compat_ino_t inode;
73539+ __u32 device;
73540+ __u32 mode;
73541+ kernel_cap_t cap_mask;
73542+ kernel_cap_t cap_lower;
73543+ kernel_cap_t cap_invert_audit;
73544+
73545+ struct compat_rlimit res[GR_NLIMITS];
73546+ __u32 resmask;
73547+
73548+ __u8 user_trans_type;
73549+ __u8 group_trans_type;
73550+ compat_uptr_t user_transitions;
73551+ compat_uptr_t group_transitions;
73552+ __u16 user_trans_num;
73553+ __u16 group_trans_num;
73554+
73555+ __u32 sock_families[2];
73556+ __u32 ip_proto[8];
73557+ __u32 ip_type;
73558+ compat_uptr_t ips;
73559+ __u32 ip_num;
73560+ __u32 inaddr_any_override;
73561+
73562+ __u32 crashes;
73563+ compat_ulong_t expires;
73564+
73565+ compat_uptr_t parent_subject;
73566+ compat_uptr_t hash;
73567+ compat_uptr_t prev;
73568+ compat_uptr_t next;
73569+
73570+ compat_uptr_t obj_hash;
73571+ __u32 obj_hash_size;
73572+ __u16 pax_flags;
73573+};
73574+
73575+struct role_allowed_ip_compat {
73576+ __u32 addr;
73577+ __u32 netmask;
73578+
73579+ compat_uptr_t prev;
73580+ compat_uptr_t next;
73581+};
73582+
73583+struct role_transition_compat {
73584+ compat_uptr_t rolename;
73585+
73586+ compat_uptr_t prev;
73587+ compat_uptr_t next;
73588+};
73589+
73590+struct acl_role_label_compat {
73591+ compat_uptr_t rolename;
73592+ uid_t uidgid;
73593+ __u16 roletype;
73594+
73595+ __u16 auth_attempts;
73596+ compat_ulong_t expires;
73597+
73598+ compat_uptr_t root_label;
73599+ compat_uptr_t hash;
73600+
73601+ compat_uptr_t prev;
73602+ compat_uptr_t next;
73603+
73604+ compat_uptr_t transitions;
73605+ compat_uptr_t allowed_ips;
73606+ compat_uptr_t domain_children;
73607+ __u16 domain_child_num;
73608+
73609+ umode_t umask;
73610+
73611+ compat_uptr_t subj_hash;
73612+ __u32 subj_hash_size;
73613+};
73614+
73615+struct user_acl_role_db_compat {
73616+ compat_uptr_t r_table;
73617+ __u32 num_pointers;
73618+ __u32 num_roles;
73619+ __u32 num_domain_children;
73620+ __u32 num_subjects;
73621+ __u32 num_objects;
73622+};
73623+
73624+struct acl_object_label_compat {
73625+ compat_uptr_t filename;
73626+ compat_ino_t inode;
73627+ __u32 device;
73628+ __u32 mode;
73629+
73630+ compat_uptr_t nested;
73631+ compat_uptr_t globbed;
73632+
73633+ compat_uptr_t prev;
73634+ compat_uptr_t next;
73635+};
73636+
73637+struct acl_ip_label_compat {
73638+ compat_uptr_t iface;
73639+ __u32 addr;
73640+ __u32 netmask;
73641+ __u16 low, high;
73642+ __u8 mode;
73643+ __u32 type;
73644+ __u32 proto[8];
73645+
73646+ compat_uptr_t prev;
73647+ compat_uptr_t next;
73648+};
73649+
73650+struct gr_arg_compat {
73651+ struct user_acl_role_db_compat role_db;
73652+ unsigned char pw[GR_PW_LEN];
73653+ unsigned char salt[GR_SALT_LEN];
73654+ unsigned char sum[GR_SHA_LEN];
73655+ unsigned char sp_role[GR_SPROLE_LEN];
73656+ compat_uptr_t sprole_pws;
73657+ __u32 segv_device;
73658+ compat_ino_t segv_inode;
73659+ uid_t segv_uid;
73660+ __u16 num_sprole_pws;
73661+ __u16 mode;
73662+};
73663+
73664+struct gr_arg_wrapper_compat {
73665+ compat_uptr_t arg;
73666+ __u32 version;
73667+ __u32 size;
73668+};
73669+
73670+#endif
73671diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
73672new file mode 100644
73673index 0000000..323ecf2
73674--- /dev/null
73675+++ b/include/linux/gralloc.h
73676@@ -0,0 +1,9 @@
73677+#ifndef __GRALLOC_H
73678+#define __GRALLOC_H
73679+
73680+void acl_free_all(void);
73681+int acl_alloc_stack_init(unsigned long size);
73682+void *acl_alloc(unsigned long len);
73683+void *acl_alloc_num(unsigned long num, unsigned long len);
73684+
73685+#endif
73686diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
73687new file mode 100644
73688index 0000000..be66033
73689--- /dev/null
73690+++ b/include/linux/grdefs.h
73691@@ -0,0 +1,140 @@
73692+#ifndef GRDEFS_H
73693+#define GRDEFS_H
73694+
73695+/* Begin grsecurity status declarations */
73696+
73697+enum {
73698+ GR_READY = 0x01,
73699+ GR_STATUS_INIT = 0x00 // disabled state
73700+};
73701+
73702+/* Begin ACL declarations */
73703+
73704+/* Role flags */
73705+
73706+enum {
73707+ GR_ROLE_USER = 0x0001,
73708+ GR_ROLE_GROUP = 0x0002,
73709+ GR_ROLE_DEFAULT = 0x0004,
73710+ GR_ROLE_SPECIAL = 0x0008,
73711+ GR_ROLE_AUTH = 0x0010,
73712+ GR_ROLE_NOPW = 0x0020,
73713+ GR_ROLE_GOD = 0x0040,
73714+ GR_ROLE_LEARN = 0x0080,
73715+ GR_ROLE_TPE = 0x0100,
73716+ GR_ROLE_DOMAIN = 0x0200,
73717+ GR_ROLE_PAM = 0x0400,
73718+ GR_ROLE_PERSIST = 0x0800
73719+};
73720+
73721+/* ACL Subject and Object mode flags */
73722+enum {
73723+ GR_DELETED = 0x80000000
73724+};
73725+
73726+/* ACL Object-only mode flags */
73727+enum {
73728+ GR_READ = 0x00000001,
73729+ GR_APPEND = 0x00000002,
73730+ GR_WRITE = 0x00000004,
73731+ GR_EXEC = 0x00000008,
73732+ GR_FIND = 0x00000010,
73733+ GR_INHERIT = 0x00000020,
73734+ GR_SETID = 0x00000040,
73735+ GR_CREATE = 0x00000080,
73736+ GR_DELETE = 0x00000100,
73737+ GR_LINK = 0x00000200,
73738+ GR_AUDIT_READ = 0x00000400,
73739+ GR_AUDIT_APPEND = 0x00000800,
73740+ GR_AUDIT_WRITE = 0x00001000,
73741+ GR_AUDIT_EXEC = 0x00002000,
73742+ GR_AUDIT_FIND = 0x00004000,
73743+ GR_AUDIT_INHERIT= 0x00008000,
73744+ GR_AUDIT_SETID = 0x00010000,
73745+ GR_AUDIT_CREATE = 0x00020000,
73746+ GR_AUDIT_DELETE = 0x00040000,
73747+ GR_AUDIT_LINK = 0x00080000,
73748+ GR_PTRACERD = 0x00100000,
73749+ GR_NOPTRACE = 0x00200000,
73750+ GR_SUPPRESS = 0x00400000,
73751+ GR_NOLEARN = 0x00800000,
73752+ GR_INIT_TRANSFER= 0x01000000
73753+};
73754+
73755+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
73756+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
73757+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
73758+
73759+/* ACL subject-only mode flags */
73760+enum {
73761+ GR_KILL = 0x00000001,
73762+ GR_VIEW = 0x00000002,
73763+ GR_PROTECTED = 0x00000004,
73764+ GR_LEARN = 0x00000008,
73765+ GR_OVERRIDE = 0x00000010,
73766+ /* just a placeholder, this mode is only used in userspace */
73767+ GR_DUMMY = 0x00000020,
73768+ GR_PROTSHM = 0x00000040,
73769+ GR_KILLPROC = 0x00000080,
73770+ GR_KILLIPPROC = 0x00000100,
73771+ /* just a placeholder, this mode is only used in userspace */
73772+ GR_NOTROJAN = 0x00000200,
73773+ GR_PROTPROCFD = 0x00000400,
73774+ GR_PROCACCT = 0x00000800,
73775+ GR_RELAXPTRACE = 0x00001000,
73776+ //GR_NESTED = 0x00002000,
73777+ GR_INHERITLEARN = 0x00004000,
73778+ GR_PROCFIND = 0x00008000,
73779+ GR_POVERRIDE = 0x00010000,
73780+ GR_KERNELAUTH = 0x00020000,
73781+ GR_ATSECURE = 0x00040000,
73782+ GR_SHMEXEC = 0x00080000
73783+};
73784+
73785+enum {
73786+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
73787+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
73788+ GR_PAX_ENABLE_MPROTECT = 0x0004,
73789+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
73790+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
73791+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
73792+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
73793+ GR_PAX_DISABLE_MPROTECT = 0x0400,
73794+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
73795+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
73796+};
73797+
73798+enum {
73799+ GR_ID_USER = 0x01,
73800+ GR_ID_GROUP = 0x02,
73801+};
73802+
73803+enum {
73804+ GR_ID_ALLOW = 0x01,
73805+ GR_ID_DENY = 0x02,
73806+};
73807+
73808+#define GR_CRASH_RES 31
73809+#define GR_UIDTABLE_MAX 500
73810+
73811+/* begin resource learning section */
73812+enum {
73813+ GR_RLIM_CPU_BUMP = 60,
73814+ GR_RLIM_FSIZE_BUMP = 50000,
73815+ GR_RLIM_DATA_BUMP = 10000,
73816+ GR_RLIM_STACK_BUMP = 1000,
73817+ GR_RLIM_CORE_BUMP = 10000,
73818+ GR_RLIM_RSS_BUMP = 500000,
73819+ GR_RLIM_NPROC_BUMP = 1,
73820+ GR_RLIM_NOFILE_BUMP = 5,
73821+ GR_RLIM_MEMLOCK_BUMP = 50000,
73822+ GR_RLIM_AS_BUMP = 500000,
73823+ GR_RLIM_LOCKS_BUMP = 2,
73824+ GR_RLIM_SIGPENDING_BUMP = 5,
73825+ GR_RLIM_MSGQUEUE_BUMP = 10000,
73826+ GR_RLIM_NICE_BUMP = 1,
73827+ GR_RLIM_RTPRIO_BUMP = 1,
73828+ GR_RLIM_RTTIME_BUMP = 1000000
73829+};
73830+
73831+#endif
73832diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
73833new file mode 100644
73834index 0000000..e337683
73835--- /dev/null
73836+++ b/include/linux/grinternal.h
73837@@ -0,0 +1,229 @@
73838+#ifndef __GRINTERNAL_H
73839+#define __GRINTERNAL_H
73840+
73841+#ifdef CONFIG_GRKERNSEC
73842+
73843+#include <linux/fs.h>
73844+#include <linux/mnt_namespace.h>
73845+#include <linux/nsproxy.h>
73846+#include <linux/gracl.h>
73847+#include <linux/grdefs.h>
73848+#include <linux/grmsg.h>
73849+
73850+void gr_add_learn_entry(const char *fmt, ...)
73851+ __attribute__ ((format (printf, 1, 2)));
73852+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
73853+ const struct vfsmount *mnt);
73854+__u32 gr_check_create(const struct dentry *new_dentry,
73855+ const struct dentry *parent,
73856+ const struct vfsmount *mnt, const __u32 mode);
73857+int gr_check_protected_task(const struct task_struct *task);
73858+__u32 to_gr_audit(const __u32 reqmode);
73859+int gr_set_acls(const int type);
73860+int gr_apply_subject_to_task(struct task_struct *task);
73861+int gr_acl_is_enabled(void);
73862+char gr_roletype_to_char(void);
73863+
73864+void gr_handle_alertkill(struct task_struct *task);
73865+char *gr_to_filename(const struct dentry *dentry,
73866+ const struct vfsmount *mnt);
73867+char *gr_to_filename1(const struct dentry *dentry,
73868+ const struct vfsmount *mnt);
73869+char *gr_to_filename2(const struct dentry *dentry,
73870+ const struct vfsmount *mnt);
73871+char *gr_to_filename3(const struct dentry *dentry,
73872+ const struct vfsmount *mnt);
73873+
73874+extern int grsec_enable_ptrace_readexec;
73875+extern int grsec_enable_harden_ptrace;
73876+extern int grsec_enable_link;
73877+extern int grsec_enable_fifo;
73878+extern int grsec_enable_execve;
73879+extern int grsec_enable_shm;
73880+extern int grsec_enable_execlog;
73881+extern int grsec_enable_signal;
73882+extern int grsec_enable_audit_ptrace;
73883+extern int grsec_enable_forkfail;
73884+extern int grsec_enable_time;
73885+extern int grsec_enable_rofs;
73886+extern int grsec_deny_new_usb;
73887+extern int grsec_enable_chroot_shmat;
73888+extern int grsec_enable_chroot_mount;
73889+extern int grsec_enable_chroot_double;
73890+extern int grsec_enable_chroot_pivot;
73891+extern int grsec_enable_chroot_chdir;
73892+extern int grsec_enable_chroot_chmod;
73893+extern int grsec_enable_chroot_mknod;
73894+extern int grsec_enable_chroot_fchdir;
73895+extern int grsec_enable_chroot_nice;
73896+extern int grsec_enable_chroot_execlog;
73897+extern int grsec_enable_chroot_caps;
73898+extern int grsec_enable_chroot_sysctl;
73899+extern int grsec_enable_chroot_unix;
73900+extern int grsec_enable_symlinkown;
73901+extern kgid_t grsec_symlinkown_gid;
73902+extern int grsec_enable_tpe;
73903+extern kgid_t grsec_tpe_gid;
73904+extern int grsec_enable_tpe_all;
73905+extern int grsec_enable_tpe_invert;
73906+extern int grsec_enable_socket_all;
73907+extern kgid_t grsec_socket_all_gid;
73908+extern int grsec_enable_socket_client;
73909+extern kgid_t grsec_socket_client_gid;
73910+extern int grsec_enable_socket_server;
73911+extern kgid_t grsec_socket_server_gid;
73912+extern kgid_t grsec_audit_gid;
73913+extern int grsec_enable_group;
73914+extern int grsec_enable_log_rwxmaps;
73915+extern int grsec_enable_mount;
73916+extern int grsec_enable_chdir;
73917+extern int grsec_resource_logging;
73918+extern int grsec_enable_blackhole;
73919+extern int grsec_lastack_retries;
73920+extern int grsec_enable_brute;
73921+extern int grsec_lock;
73922+
73923+extern spinlock_t grsec_alert_lock;
73924+extern unsigned long grsec_alert_wtime;
73925+extern unsigned long grsec_alert_fyet;
73926+
73927+extern spinlock_t grsec_audit_lock;
73928+
73929+extern rwlock_t grsec_exec_file_lock;
73930+
73931+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
73932+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
73933+ (tsk)->exec_file->f_path.mnt) : "/")
73934+
73935+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
73936+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
73937+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
73938+
73939+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
73940+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
73941+ (tsk)->exec_file->f_path.mnt) : "/")
73942+
73943+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
73944+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
73945+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
73946+
73947+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
73948+
73949+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
73950+
73951+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
73952+{
73953+ if (file1 && file2) {
73954+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
73955+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
73956+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
73957+ return true;
73958+ }
73959+
73960+ return false;
73961+}
73962+
73963+#define GR_CHROOT_CAPS {{ \
73964+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
73965+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
73966+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
73967+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
73968+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
73969+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
73970+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
73971+
73972+#define security_learn(normal_msg,args...) \
73973+({ \
73974+ read_lock(&grsec_exec_file_lock); \
73975+ gr_add_learn_entry(normal_msg "\n", ## args); \
73976+ read_unlock(&grsec_exec_file_lock); \
73977+})
73978+
73979+enum {
73980+ GR_DO_AUDIT,
73981+ GR_DONT_AUDIT,
73982+ /* used for non-audit messages that we shouldn't kill the task on */
73983+ GR_DONT_AUDIT_GOOD
73984+};
73985+
73986+enum {
73987+ GR_TTYSNIFF,
73988+ GR_RBAC,
73989+ GR_RBAC_STR,
73990+ GR_STR_RBAC,
73991+ GR_RBAC_MODE2,
73992+ GR_RBAC_MODE3,
73993+ GR_FILENAME,
73994+ GR_SYSCTL_HIDDEN,
73995+ GR_NOARGS,
73996+ GR_ONE_INT,
73997+ GR_ONE_INT_TWO_STR,
73998+ GR_ONE_STR,
73999+ GR_STR_INT,
74000+ GR_TWO_STR_INT,
74001+ GR_TWO_INT,
74002+ GR_TWO_U64,
74003+ GR_THREE_INT,
74004+ GR_FIVE_INT_TWO_STR,
74005+ GR_TWO_STR,
74006+ GR_THREE_STR,
74007+ GR_FOUR_STR,
74008+ GR_STR_FILENAME,
74009+ GR_FILENAME_STR,
74010+ GR_FILENAME_TWO_INT,
74011+ GR_FILENAME_TWO_INT_STR,
74012+ GR_TEXTREL,
74013+ GR_PTRACE,
74014+ GR_RESOURCE,
74015+ GR_CAP,
74016+ GR_SIG,
74017+ GR_SIG2,
74018+ GR_CRASH1,
74019+ GR_CRASH2,
74020+ GR_PSACCT,
74021+ GR_RWXMAP,
74022+ GR_RWXMAPVMA
74023+};
74024+
74025+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
74026+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
74027+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
74028+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
74029+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
74030+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
74031+#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)
74032+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
74033+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
74034+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
74035+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
74036+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
74037+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
74038+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
74039+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
74040+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
74041+#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)
74042+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
74043+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
74044+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
74045+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
74046+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
74047+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
74048+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
74049+#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)
74050+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
74051+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
74052+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
74053+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
74054+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
74055+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
74056+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
74057+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
74058+#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)
74059+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
74060+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
74061+
74062+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
74063+
74064+#endif
74065+
74066+#endif
74067diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
74068new file mode 100644
74069index 0000000..a4396b5
74070--- /dev/null
74071+++ b/include/linux/grmsg.h
74072@@ -0,0 +1,113 @@
74073+#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"
74074+#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"
74075+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
74076+#define GR_STOPMOD_MSG "denied modification of module state by "
74077+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
74078+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
74079+#define GR_IOPERM_MSG "denied use of ioperm() by "
74080+#define GR_IOPL_MSG "denied use of iopl() by "
74081+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
74082+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
74083+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
74084+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
74085+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
74086+#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"
74087+#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"
74088+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
74089+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
74090+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
74091+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
74092+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
74093+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
74094+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
74095+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
74096+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
74097+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
74098+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
74099+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
74100+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
74101+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
74102+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
74103+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
74104+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
74105+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
74106+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
74107+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
74108+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
74109+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
74110+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
74111+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
74112+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
74113+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
74114+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
74115+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
74116+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
74117+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
74118+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
74119+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
74120+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
74121+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
74122+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
74123+#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"
74124+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
74125+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
74126+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
74127+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
74128+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
74129+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
74130+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
74131+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
74132+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
74133+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
74134+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
74135+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
74136+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
74137+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
74138+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
74139+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
74140+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
74141+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
74142+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
74143+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
74144+#define GR_FAILFORK_MSG "failed fork with errno %s by "
74145+#define GR_NICE_CHROOT_MSG "denied priority change by "
74146+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
74147+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
74148+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
74149+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
74150+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
74151+#define GR_TIME_MSG "time set by "
74152+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
74153+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
74154+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
74155+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
74156+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
74157+#define GR_BIND_MSG "denied bind() by "
74158+#define GR_CONNECT_MSG "denied connect() by "
74159+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
74160+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
74161+#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"
74162+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
74163+#define GR_CAP_ACL_MSG "use of %s denied for "
74164+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
74165+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
74166+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
74167+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
74168+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
74169+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
74170+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
74171+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
74172+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
74173+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
74174+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
74175+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
74176+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
74177+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
74178+#define GR_VM86_MSG "denied use of vm86 by "
74179+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
74180+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
74181+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
74182+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
74183+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
74184+#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 "
74185+#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 "
74186diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
74187new file mode 100644
74188index 0000000..d6f5a21
74189--- /dev/null
74190+++ b/include/linux/grsecurity.h
74191@@ -0,0 +1,244 @@
74192+#ifndef GR_SECURITY_H
74193+#define GR_SECURITY_H
74194+#include <linux/fs.h>
74195+#include <linux/fs_struct.h>
74196+#include <linux/binfmts.h>
74197+#include <linux/gracl.h>
74198+
74199+/* notify of brain-dead configs */
74200+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
74201+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
74202+#endif
74203+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
74204+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
74205+#endif
74206+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
74207+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
74208+#endif
74209+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
74210+#error "CONFIG_PAX enabled, but no PaX options are enabled."
74211+#endif
74212+
74213+int gr_handle_new_usb(void);
74214+
74215+void gr_handle_brute_attach(unsigned long mm_flags);
74216+void gr_handle_brute_check(void);
74217+void gr_handle_kernel_exploit(void);
74218+
74219+char gr_roletype_to_char(void);
74220+
74221+int gr_acl_enable_at_secure(void);
74222+
74223+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
74224+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
74225+
74226+void gr_del_task_from_ip_table(struct task_struct *p);
74227+
74228+int gr_pid_is_chrooted(struct task_struct *p);
74229+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
74230+int gr_handle_chroot_nice(void);
74231+int gr_handle_chroot_sysctl(const int op);
74232+int gr_handle_chroot_setpriority(struct task_struct *p,
74233+ const int niceval);
74234+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
74235+int gr_handle_chroot_chroot(const struct dentry *dentry,
74236+ const struct vfsmount *mnt);
74237+void gr_handle_chroot_chdir(const struct path *path);
74238+int gr_handle_chroot_chmod(const struct dentry *dentry,
74239+ const struct vfsmount *mnt, const int mode);
74240+int gr_handle_chroot_mknod(const struct dentry *dentry,
74241+ const struct vfsmount *mnt, const int mode);
74242+int gr_handle_chroot_mount(const struct dentry *dentry,
74243+ const struct vfsmount *mnt,
74244+ const char *dev_name);
74245+int gr_handle_chroot_pivot(void);
74246+int gr_handle_chroot_unix(const pid_t pid);
74247+
74248+int gr_handle_rawio(const struct inode *inode);
74249+
74250+void gr_handle_ioperm(void);
74251+void gr_handle_iopl(void);
74252+
74253+umode_t gr_acl_umask(void);
74254+
74255+int gr_tpe_allow(const struct file *file);
74256+
74257+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
74258+void gr_clear_chroot_entries(struct task_struct *task);
74259+
74260+void gr_log_forkfail(const int retval);
74261+void gr_log_timechange(void);
74262+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
74263+void gr_log_chdir(const struct dentry *dentry,
74264+ const struct vfsmount *mnt);
74265+void gr_log_chroot_exec(const struct dentry *dentry,
74266+ const struct vfsmount *mnt);
74267+void gr_log_remount(const char *devname, const int retval);
74268+void gr_log_unmount(const char *devname, const int retval);
74269+void gr_log_mount(const char *from, const char *to, const int retval);
74270+void gr_log_textrel(struct vm_area_struct *vma);
74271+void gr_log_ptgnustack(struct file *file);
74272+void gr_log_rwxmmap(struct file *file);
74273+void gr_log_rwxmprotect(struct vm_area_struct *vma);
74274+
74275+int gr_handle_follow_link(const struct inode *parent,
74276+ const struct inode *inode,
74277+ const struct dentry *dentry,
74278+ const struct vfsmount *mnt);
74279+int gr_handle_fifo(const struct dentry *dentry,
74280+ const struct vfsmount *mnt,
74281+ const struct dentry *dir, const int flag,
74282+ const int acc_mode);
74283+int gr_handle_hardlink(const struct dentry *dentry,
74284+ const struct vfsmount *mnt,
74285+ struct inode *inode,
74286+ const int mode, const struct filename *to);
74287+
74288+int gr_is_capable(const int cap);
74289+int gr_is_capable_nolog(const int cap);
74290+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74291+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
74292+
74293+void gr_copy_label(struct task_struct *tsk);
74294+void gr_handle_crash(struct task_struct *task, const int sig);
74295+int gr_handle_signal(const struct task_struct *p, const int sig);
74296+int gr_check_crash_uid(const kuid_t uid);
74297+int gr_check_protected_task(const struct task_struct *task);
74298+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
74299+int gr_acl_handle_mmap(const struct file *file,
74300+ const unsigned long prot);
74301+int gr_acl_handle_mprotect(const struct file *file,
74302+ const unsigned long prot);
74303+int gr_check_hidden_task(const struct task_struct *tsk);
74304+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
74305+ const struct vfsmount *mnt);
74306+__u32 gr_acl_handle_utime(const struct dentry *dentry,
74307+ const struct vfsmount *mnt);
74308+__u32 gr_acl_handle_access(const struct dentry *dentry,
74309+ const struct vfsmount *mnt, const int fmode);
74310+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
74311+ const struct vfsmount *mnt, umode_t *mode);
74312+__u32 gr_acl_handle_chown(const struct dentry *dentry,
74313+ const struct vfsmount *mnt);
74314+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
74315+ const struct vfsmount *mnt);
74316+int gr_handle_ptrace(struct task_struct *task, const long request);
74317+int gr_handle_proc_ptrace(struct task_struct *task);
74318+__u32 gr_acl_handle_execve(const struct dentry *dentry,
74319+ const struct vfsmount *mnt);
74320+int gr_check_crash_exec(const struct file *filp);
74321+int gr_acl_is_enabled(void);
74322+void gr_set_kernel_label(struct task_struct *task);
74323+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
74324+ const kgid_t gid);
74325+int gr_set_proc_label(const struct dentry *dentry,
74326+ const struct vfsmount *mnt,
74327+ const int unsafe_flags);
74328+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
74329+ const struct vfsmount *mnt);
74330+__u32 gr_acl_handle_open(const struct dentry *dentry,
74331+ const struct vfsmount *mnt, int acc_mode);
74332+__u32 gr_acl_handle_creat(const struct dentry *dentry,
74333+ const struct dentry *p_dentry,
74334+ const struct vfsmount *p_mnt,
74335+ int open_flags, int acc_mode, const int imode);
74336+void gr_handle_create(const struct dentry *dentry,
74337+ const struct vfsmount *mnt);
74338+void gr_handle_proc_create(const struct dentry *dentry,
74339+ const struct inode *inode);
74340+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
74341+ const struct dentry *parent_dentry,
74342+ const struct vfsmount *parent_mnt,
74343+ const int mode);
74344+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
74345+ const struct dentry *parent_dentry,
74346+ const struct vfsmount *parent_mnt);
74347+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
74348+ const struct vfsmount *mnt);
74349+void gr_handle_delete(const ino_t ino, const dev_t dev);
74350+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
74351+ const struct vfsmount *mnt);
74352+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
74353+ const struct dentry *parent_dentry,
74354+ const struct vfsmount *parent_mnt,
74355+ const struct filename *from);
74356+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
74357+ const struct dentry *parent_dentry,
74358+ const struct vfsmount *parent_mnt,
74359+ const struct dentry *old_dentry,
74360+ const struct vfsmount *old_mnt, const struct filename *to);
74361+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
74362+int gr_acl_handle_rename(struct dentry *new_dentry,
74363+ struct dentry *parent_dentry,
74364+ const struct vfsmount *parent_mnt,
74365+ struct dentry *old_dentry,
74366+ struct inode *old_parent_inode,
74367+ struct vfsmount *old_mnt, const struct filename *newname);
74368+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74369+ struct dentry *old_dentry,
74370+ struct dentry *new_dentry,
74371+ struct vfsmount *mnt, const __u8 replace);
74372+__u32 gr_check_link(const struct dentry *new_dentry,
74373+ const struct dentry *parent_dentry,
74374+ const struct vfsmount *parent_mnt,
74375+ const struct dentry *old_dentry,
74376+ const struct vfsmount *old_mnt);
74377+int gr_acl_handle_filldir(const struct file *file, const char *name,
74378+ const unsigned int namelen, const ino_t ino);
74379+
74380+__u32 gr_acl_handle_unix(const struct dentry *dentry,
74381+ const struct vfsmount *mnt);
74382+void gr_acl_handle_exit(void);
74383+void gr_acl_handle_psacct(struct task_struct *task, const long code);
74384+int gr_acl_handle_procpidmem(const struct task_struct *task);
74385+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
74386+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
74387+void gr_audit_ptrace(struct task_struct *task);
74388+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
74389+void gr_put_exec_file(struct task_struct *task);
74390+
74391+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
74392+
74393+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
74394+extern void gr_learn_resource(const struct task_struct *task, const int res,
74395+ const unsigned long wanted, const int gt);
74396+#else
74397+static inline void gr_learn_resource(const struct task_struct *task, const int res,
74398+ const unsigned long wanted, const int gt)
74399+{
74400+}
74401+#endif
74402+
74403+#ifdef CONFIG_GRKERNSEC_RESLOG
74404+extern void gr_log_resource(const struct task_struct *task, const int res,
74405+ const unsigned long wanted, const int gt);
74406+#else
74407+static inline void gr_log_resource(const struct task_struct *task, const int res,
74408+ const unsigned long wanted, const int gt)
74409+{
74410+}
74411+#endif
74412+
74413+#ifdef CONFIG_GRKERNSEC
74414+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
74415+void gr_handle_vm86(void);
74416+void gr_handle_mem_readwrite(u64 from, u64 to);
74417+
74418+void gr_log_badprocpid(const char *entry);
74419+
74420+extern int grsec_enable_dmesg;
74421+extern int grsec_disable_privio;
74422+
74423+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74424+extern kgid_t grsec_proc_gid;
74425+#endif
74426+
74427+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74428+extern int grsec_enable_chroot_findtask;
74429+#endif
74430+#ifdef CONFIG_GRKERNSEC_SETXID
74431+extern int grsec_enable_setxid;
74432+#endif
74433+#endif
74434+
74435+#endif
74436diff --git a/include/linux/grsock.h b/include/linux/grsock.h
74437new file mode 100644
74438index 0000000..e7ffaaf
74439--- /dev/null
74440+++ b/include/linux/grsock.h
74441@@ -0,0 +1,19 @@
74442+#ifndef __GRSOCK_H
74443+#define __GRSOCK_H
74444+
74445+extern void gr_attach_curr_ip(const struct sock *sk);
74446+extern int gr_handle_sock_all(const int family, const int type,
74447+ const int protocol);
74448+extern int gr_handle_sock_server(const struct sockaddr *sck);
74449+extern int gr_handle_sock_server_other(const struct sock *sck);
74450+extern int gr_handle_sock_client(const struct sockaddr *sck);
74451+extern int gr_search_connect(struct socket * sock,
74452+ struct sockaddr_in * addr);
74453+extern int gr_search_bind(struct socket * sock,
74454+ struct sockaddr_in * addr);
74455+extern int gr_search_listen(struct socket * sock);
74456+extern int gr_search_accept(struct socket * sock);
74457+extern int gr_search_socket(const int domain, const int type,
74458+ const int protocol);
74459+
74460+#endif
74461diff --git a/include/linux/hid.h b/include/linux/hid.h
74462index 0c48991..76e41d8 100644
74463--- a/include/linux/hid.h
74464+++ b/include/linux/hid.h
74465@@ -393,10 +393,12 @@ struct hid_report {
74466 struct hid_device *device; /* associated device */
74467 };
74468
74469+#define HID_MAX_IDS 256
74470+
74471 struct hid_report_enum {
74472 unsigned numbered;
74473 struct list_head report_list;
74474- struct hid_report *report_id_hash[256];
74475+ struct hid_report *report_id_hash[HID_MAX_IDS];
74476 };
74477
74478 #define HID_REPORT_TYPES 3
74479@@ -747,6 +749,10 @@ void hid_output_report(struct hid_report *report, __u8 *data);
74480 struct hid_device *hid_allocate_device(void);
74481 struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id);
74482 int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size);
74483+struct hid_report *hid_validate_report(struct hid_device *hid,
74484+ unsigned int type, unsigned int id,
74485+ unsigned int fields,
74486+ unsigned int report_counts);
74487 int hid_open_report(struct hid_device *device);
74488 int hid_check_keys_pressed(struct hid_device *hid);
74489 int hid_connect(struct hid_device *hid, unsigned int connect_mask);
74490diff --git a/include/linux/highmem.h b/include/linux/highmem.h
74491index 7fb31da..08b5114 100644
74492--- a/include/linux/highmem.h
74493+++ b/include/linux/highmem.h
74494@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
74495 kunmap_atomic(kaddr);
74496 }
74497
74498+static inline void sanitize_highpage(struct page *page)
74499+{
74500+ void *kaddr;
74501+ unsigned long flags;
74502+
74503+ local_irq_save(flags);
74504+ kaddr = kmap_atomic(page);
74505+ clear_page(kaddr);
74506+ kunmap_atomic(kaddr);
74507+ local_irq_restore(flags);
74508+}
74509+
74510 static inline void zero_user_segments(struct page *page,
74511 unsigned start1, unsigned end1,
74512 unsigned start2, unsigned end2)
74513diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
74514index 1c7b89a..7f52502 100644
74515--- a/include/linux/hwmon-sysfs.h
74516+++ b/include/linux/hwmon-sysfs.h
74517@@ -25,7 +25,8 @@
74518 struct sensor_device_attribute{
74519 struct device_attribute dev_attr;
74520 int index;
74521-};
74522+} __do_const;
74523+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
74524 #define to_sensor_dev_attr(_dev_attr) \
74525 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
74526
74527@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
74528 struct device_attribute dev_attr;
74529 u8 index;
74530 u8 nr;
74531-};
74532+} __do_const;
74533 #define to_sensor_dev_attr_2(_dev_attr) \
74534 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
74535
74536diff --git a/include/linux/i2c.h b/include/linux/i2c.h
74537index e988fa9..ff9f17e 100644
74538--- a/include/linux/i2c.h
74539+++ b/include/linux/i2c.h
74540@@ -366,6 +366,7 @@ struct i2c_algorithm {
74541 /* To determine what the adapter supports */
74542 u32 (*functionality) (struct i2c_adapter *);
74543 };
74544+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
74545
74546 /**
74547 * struct i2c_bus_recovery_info - I2C bus recovery information
74548diff --git a/include/linux/i2o.h b/include/linux/i2o.h
74549index d23c3c2..eb63c81 100644
74550--- a/include/linux/i2o.h
74551+++ b/include/linux/i2o.h
74552@@ -565,7 +565,7 @@ struct i2o_controller {
74553 struct i2o_device *exec; /* Executive */
74554 #if BITS_PER_LONG == 64
74555 spinlock_t context_list_lock; /* lock for context_list */
74556- atomic_t context_list_counter; /* needed for unique contexts */
74557+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
74558 struct list_head context_list; /* list of context id's
74559 and pointers */
74560 #endif
74561diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
74562index aff7ad8..3942bbd 100644
74563--- a/include/linux/if_pppox.h
74564+++ b/include/linux/if_pppox.h
74565@@ -76,7 +76,7 @@ struct pppox_proto {
74566 int (*ioctl)(struct socket *sock, unsigned int cmd,
74567 unsigned long arg);
74568 struct module *owner;
74569-};
74570+} __do_const;
74571
74572 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
74573 extern void unregister_pppox_proto(int proto_num);
74574diff --git a/include/linux/init.h b/include/linux/init.h
74575index e73f2b7..3a5082b 100644
74576--- a/include/linux/init.h
74577+++ b/include/linux/init.h
74578@@ -39,9 +39,22 @@
74579 * Also note, that this data cannot be "const".
74580 */
74581
74582+#ifdef MODULE
74583+#define add_init_latent_entropy
74584+#define add_meminit_latent_entropy
74585+#else
74586+#define add_init_latent_entropy __latent_entropy
74587+
74588+#ifdef CONFIG_MEMORY_HOTPLUG
74589+#define add_meminit_latent_entropy
74590+#else
74591+#define add_meminit_latent_entropy __latent_entropy
74592+#endif
74593+#endif
74594+
74595 /* These are for everybody (although not all archs will actually
74596 discard it in modules) */
74597-#define __init __section(.init.text) __cold notrace
74598+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
74599 #define __initdata __section(.init.data)
74600 #define __initconst __constsection(.init.rodata)
74601 #define __exitdata __section(.exit.data)
74602@@ -102,7 +115,7 @@
74603 #define __cpuexitconst
74604
74605 /* Used for MEMORY_HOTPLUG */
74606-#define __meminit __section(.meminit.text) __cold notrace
74607+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
74608 #define __meminitdata __section(.meminit.data)
74609 #define __meminitconst __constsection(.meminit.rodata)
74610 #define __memexit __section(.memexit.text) __exitused __cold notrace
74611diff --git a/include/linux/init_task.h b/include/linux/init_task.h
74612index 5cd0f09..c9f67cc 100644
74613--- a/include/linux/init_task.h
74614+++ b/include/linux/init_task.h
74615@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
74616
74617 #define INIT_TASK_COMM "swapper"
74618
74619+#ifdef CONFIG_X86
74620+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
74621+#else
74622+#define INIT_TASK_THREAD_INFO
74623+#endif
74624+
74625 /*
74626 * INIT_TASK is used to set up the first task table, touch at
74627 * your own risk!. Base=0, limit=0x1fffff (=2MB)
74628@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
74629 RCU_POINTER_INITIALIZER(cred, &init_cred), \
74630 .comm = INIT_TASK_COMM, \
74631 .thread = INIT_THREAD, \
74632+ INIT_TASK_THREAD_INFO \
74633 .fs = &init_fs, \
74634 .files = &init_files, \
74635 .signal = &init_signals, \
74636diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
74637index 5fa5afe..ac55b25 100644
74638--- a/include/linux/interrupt.h
74639+++ b/include/linux/interrupt.h
74640@@ -430,7 +430,7 @@ enum
74641 /* map softirq index to softirq name. update 'softirq_to_name' in
74642 * kernel/softirq.c when adding a new softirq.
74643 */
74644-extern char *softirq_to_name[NR_SOFTIRQS];
74645+extern const char * const softirq_to_name[NR_SOFTIRQS];
74646
74647 /* softirq mask and active fields moved to irq_cpustat_t in
74648 * asm/hardirq.h to get better cache usage. KAO
74649@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
74650
74651 struct softirq_action
74652 {
74653- void (*action)(struct softirq_action *);
74654-};
74655+ void (*action)(void);
74656+} __no_const;
74657
74658 asmlinkage void do_softirq(void);
74659 asmlinkage void __do_softirq(void);
74660-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
74661+extern void open_softirq(int nr, void (*action)(void));
74662 extern void softirq_init(void);
74663 extern void __raise_softirq_irqoff(unsigned int nr);
74664
74665diff --git a/include/linux/iommu.h b/include/linux/iommu.h
74666index 3aeb730..2177f39 100644
74667--- a/include/linux/iommu.h
74668+++ b/include/linux/iommu.h
74669@@ -113,7 +113,7 @@ struct iommu_ops {
74670 u32 (*domain_get_windows)(struct iommu_domain *domain);
74671
74672 unsigned long pgsize_bitmap;
74673-};
74674+} __do_const;
74675
74676 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
74677 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
74678diff --git a/include/linux/ioport.h b/include/linux/ioport.h
74679index 89b7c24..382af74 100644
74680--- a/include/linux/ioport.h
74681+++ b/include/linux/ioport.h
74682@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
74683 int adjust_resource(struct resource *res, resource_size_t start,
74684 resource_size_t size);
74685 resource_size_t resource_alignment(struct resource *res);
74686-static inline resource_size_t resource_size(const struct resource *res)
74687+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
74688 {
74689 return res->end - res->start + 1;
74690 }
74691diff --git a/include/linux/irq.h b/include/linux/irq.h
74692index f04d3ba..bcf2cfb 100644
74693--- a/include/linux/irq.h
74694+++ b/include/linux/irq.h
74695@@ -333,7 +333,8 @@ struct irq_chip {
74696 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
74697
74698 unsigned long flags;
74699-};
74700+} __do_const;
74701+typedef struct irq_chip __no_const irq_chip_no_const;
74702
74703 /*
74704 * irq_chip specific flags
74705diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
74706index 3e203eb..3fe68d0 100644
74707--- a/include/linux/irqchip/arm-gic.h
74708+++ b/include/linux/irqchip/arm-gic.h
74709@@ -59,9 +59,11 @@
74710
74711 #ifndef __ASSEMBLY__
74712
74713+#include <linux/irq.h>
74714+
74715 struct device_node;
74716
74717-extern struct irq_chip gic_arch_extn;
74718+extern irq_chip_no_const gic_arch_extn;
74719
74720 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
74721 u32 offset, struct device_node *);
74722diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
74723index 6883e19..e854fcb 100644
74724--- a/include/linux/kallsyms.h
74725+++ b/include/linux/kallsyms.h
74726@@ -15,7 +15,8 @@
74727
74728 struct module;
74729
74730-#ifdef CONFIG_KALLSYMS
74731+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
74732+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
74733 /* Lookup the address for a symbol. Returns 0 if not found. */
74734 unsigned long kallsyms_lookup_name(const char *name);
74735
74736@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
74737 /* Stupid that this does nothing, but I didn't create this mess. */
74738 #define __print_symbol(fmt, addr)
74739 #endif /*CONFIG_KALLSYMS*/
74740+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
74741+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
74742+extern unsigned long kallsyms_lookup_name(const char *name);
74743+extern void __print_symbol(const char *fmt, unsigned long address);
74744+extern int sprint_backtrace(char *buffer, unsigned long address);
74745+extern int sprint_symbol(char *buffer, unsigned long address);
74746+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
74747+const char *kallsyms_lookup(unsigned long addr,
74748+ unsigned long *symbolsize,
74749+ unsigned long *offset,
74750+ char **modname, char *namebuf);
74751+extern int kallsyms_lookup_size_offset(unsigned long addr,
74752+ unsigned long *symbolsize,
74753+ unsigned long *offset);
74754+#endif
74755
74756 /* This macro allows us to keep printk typechecking */
74757 static __printf(1, 2)
74758diff --git a/include/linux/key-type.h b/include/linux/key-type.h
74759index 518a53a..5e28358 100644
74760--- a/include/linux/key-type.h
74761+++ b/include/linux/key-type.h
74762@@ -125,7 +125,7 @@ struct key_type {
74763 /* internal fields */
74764 struct list_head link; /* link in types list */
74765 struct lock_class_key lock_class; /* key->sem lock class */
74766-};
74767+} __do_const;
74768
74769 extern struct key_type key_type_keyring;
74770
74771diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
74772index c6e091b..a940adf 100644
74773--- a/include/linux/kgdb.h
74774+++ b/include/linux/kgdb.h
74775@@ -52,7 +52,7 @@ extern int kgdb_connected;
74776 extern int kgdb_io_module_registered;
74777
74778 extern atomic_t kgdb_setting_breakpoint;
74779-extern atomic_t kgdb_cpu_doing_single_step;
74780+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
74781
74782 extern struct task_struct *kgdb_usethread;
74783 extern struct task_struct *kgdb_contthread;
74784@@ -254,7 +254,7 @@ struct kgdb_arch {
74785 void (*correct_hw_break)(void);
74786
74787 void (*enable_nmi)(bool on);
74788-};
74789+} __do_const;
74790
74791 /**
74792 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
74793@@ -279,7 +279,7 @@ struct kgdb_io {
74794 void (*pre_exception) (void);
74795 void (*post_exception) (void);
74796 int is_console;
74797-};
74798+} __do_const;
74799
74800 extern struct kgdb_arch arch_kgdb_ops;
74801
74802diff --git a/include/linux/kmod.h b/include/linux/kmod.h
74803index 0555cc6..b16a7a4 100644
74804--- a/include/linux/kmod.h
74805+++ b/include/linux/kmod.h
74806@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
74807 * usually useless though. */
74808 extern __printf(2, 3)
74809 int __request_module(bool wait, const char *name, ...);
74810+extern __printf(3, 4)
74811+int ___request_module(bool wait, char *param_name, const char *name, ...);
74812 #define request_module(mod...) __request_module(true, mod)
74813 #define request_module_nowait(mod...) __request_module(false, mod)
74814 #define try_then_request_module(x, mod...) \
74815diff --git a/include/linux/kobject.h b/include/linux/kobject.h
74816index 939b112..ed6ed51 100644
74817--- a/include/linux/kobject.h
74818+++ b/include/linux/kobject.h
74819@@ -111,7 +111,7 @@ struct kobj_type {
74820 struct attribute **default_attrs;
74821 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
74822 const void *(*namespace)(struct kobject *kobj);
74823-};
74824+} __do_const;
74825
74826 struct kobj_uevent_env {
74827 char *envp[UEVENT_NUM_ENVP];
74828@@ -134,6 +134,7 @@ struct kobj_attribute {
74829 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
74830 const char *buf, size_t count);
74831 };
74832+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
74833
74834 extern const struct sysfs_ops kobj_sysfs_ops;
74835
74836diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
74837index f66b065..c2c29b4 100644
74838--- a/include/linux/kobject_ns.h
74839+++ b/include/linux/kobject_ns.h
74840@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
74841 const void *(*netlink_ns)(struct sock *sk);
74842 const void *(*initial_ns)(void);
74843 void (*drop_ns)(void *);
74844-};
74845+} __do_const;
74846
74847 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
74848 int kobj_ns_type_registered(enum kobj_ns_type type);
74849diff --git a/include/linux/kref.h b/include/linux/kref.h
74850index 484604d..0f6c5b6 100644
74851--- a/include/linux/kref.h
74852+++ b/include/linux/kref.h
74853@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
74854 static inline int kref_sub(struct kref *kref, unsigned int count,
74855 void (*release)(struct kref *kref))
74856 {
74857- WARN_ON(release == NULL);
74858+ BUG_ON(release == NULL);
74859
74860 if (atomic_sub_and_test((int) count, &kref->refcount)) {
74861 release(kref);
74862diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
74863index a63d83e..77fd685 100644
74864--- a/include/linux/kvm_host.h
74865+++ b/include/linux/kvm_host.h
74866@@ -446,7 +446,7 @@ static inline void kvm_irqfd_exit(void)
74867 {
74868 }
74869 #endif
74870-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
74871+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
74872 struct module *module);
74873 void kvm_exit(void);
74874
74875@@ -618,7 +618,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
74876 struct kvm_guest_debug *dbg);
74877 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
74878
74879-int kvm_arch_init(void *opaque);
74880+int kvm_arch_init(const void *opaque);
74881 void kvm_arch_exit(void);
74882
74883 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
74884diff --git a/include/linux/libata.h b/include/linux/libata.h
74885index 4ea55bb..dcd2601 100644
74886--- a/include/linux/libata.h
74887+++ b/include/linux/libata.h
74888@@ -924,7 +924,7 @@ struct ata_port_operations {
74889 * fields must be pointers.
74890 */
74891 const struct ata_port_operations *inherits;
74892-};
74893+} __do_const;
74894
74895 struct ata_port_info {
74896 unsigned long flags;
74897diff --git a/include/linux/linkage.h b/include/linux/linkage.h
74898index d3e8ad2..a949f68 100644
74899--- a/include/linux/linkage.h
74900+++ b/include/linux/linkage.h
74901@@ -31,6 +31,7 @@
74902 #endif
74903
74904 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
74905+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
74906 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
74907
74908 /*
74909diff --git a/include/linux/list.h b/include/linux/list.h
74910index f4d8a2f..38e6e46 100644
74911--- a/include/linux/list.h
74912+++ b/include/linux/list.h
74913@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
74914 extern void list_del(struct list_head *entry);
74915 #endif
74916
74917+extern void __pax_list_add(struct list_head *new,
74918+ struct list_head *prev,
74919+ struct list_head *next);
74920+static inline void pax_list_add(struct list_head *new, struct list_head *head)
74921+{
74922+ __pax_list_add(new, head, head->next);
74923+}
74924+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
74925+{
74926+ __pax_list_add(new, head->prev, head);
74927+}
74928+extern void pax_list_del(struct list_head *entry);
74929+
74930 /**
74931 * list_replace - replace old entry by new one
74932 * @old : the element to be replaced
74933@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
74934 INIT_LIST_HEAD(entry);
74935 }
74936
74937+extern void pax_list_del_init(struct list_head *entry);
74938+
74939 /**
74940 * list_move - delete from one list and add as another's head
74941 * @list: the entry to move
74942diff --git a/include/linux/math64.h b/include/linux/math64.h
74943index 2913b86..8dcbb1e 100644
74944--- a/include/linux/math64.h
74945+++ b/include/linux/math64.h
74946@@ -15,7 +15,7 @@
74947 * This is commonly provided by 32bit archs to provide an optimized 64bit
74948 * divide.
74949 */
74950-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74951+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74952 {
74953 *remainder = dividend % divisor;
74954 return dividend / divisor;
74955@@ -33,7 +33,7 @@ static inline s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
74956 /**
74957 * div64_u64 - unsigned 64bit divide with 64bit divisor
74958 */
74959-static inline u64 div64_u64(u64 dividend, u64 divisor)
74960+static inline u64 __intentional_overflow(0) div64_u64(u64 dividend, u64 divisor)
74961 {
74962 return dividend / divisor;
74963 }
74964@@ -52,7 +52,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
74965 #define div64_ul(x, y) div_u64((x), (y))
74966
74967 #ifndef div_u64_rem
74968-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74969+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74970 {
74971 *remainder = do_div(dividend, divisor);
74972 return dividend;
74973@@ -81,7 +81,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
74974 * divide.
74975 */
74976 #ifndef div_u64
74977-static inline u64 div_u64(u64 dividend, u32 divisor)
74978+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
74979 {
74980 u32 remainder;
74981 return div_u64_rem(dividend, divisor, &remainder);
74982diff --git a/include/linux/mm.h b/include/linux/mm.h
74983index f022460..6ecf4f9 100644
74984--- a/include/linux/mm.h
74985+++ b/include/linux/mm.h
74986@@ -113,6 +113,11 @@ extern unsigned int kobjsize(const void *objp);
74987 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
74988 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
74989 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
74990+
74991+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
74992+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
74993+#endif
74994+
74995 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
74996
74997 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
74998@@ -208,8 +213,8 @@ struct vm_operations_struct {
74999 /* called by access_process_vm when get_user_pages() fails, typically
75000 * for use by special VMAs that can switch between memory and hardware
75001 */
75002- int (*access)(struct vm_area_struct *vma, unsigned long addr,
75003- void *buf, int len, int write);
75004+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
75005+ void *buf, size_t len, int write);
75006 #ifdef CONFIG_NUMA
75007 /*
75008 * set_policy() op must add a reference to any non-NULL @new mempolicy
75009@@ -239,6 +244,7 @@ struct vm_operations_struct {
75010 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
75011 unsigned long size, pgoff_t pgoff);
75012 };
75013+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
75014
75015 struct mmu_gather;
75016 struct inode;
75017@@ -983,8 +989,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
75018 unsigned long *pfn);
75019 int follow_phys(struct vm_area_struct *vma, unsigned long address,
75020 unsigned int flags, unsigned long *prot, resource_size_t *phys);
75021-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
75022- void *buf, int len, int write);
75023+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
75024+ void *buf, size_t len, int write);
75025
75026 static inline void unmap_shared_mapping_range(struct address_space *mapping,
75027 loff_t const holebegin, loff_t const holelen)
75028@@ -1023,9 +1029,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
75029 }
75030 #endif
75031
75032-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
75033-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
75034- void *buf, int len, int write);
75035+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
75036+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
75037+ void *buf, size_t len, int write);
75038
75039 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75040 unsigned long start, unsigned long nr_pages,
75041@@ -1057,34 +1063,6 @@ int set_page_dirty(struct page *page);
75042 int set_page_dirty_lock(struct page *page);
75043 int clear_page_dirty_for_io(struct page *page);
75044
75045-/* Is the vma a continuation of the stack vma above it? */
75046-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
75047-{
75048- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
75049-}
75050-
75051-static inline int stack_guard_page_start(struct vm_area_struct *vma,
75052- unsigned long addr)
75053-{
75054- return (vma->vm_flags & VM_GROWSDOWN) &&
75055- (vma->vm_start == addr) &&
75056- !vma_growsdown(vma->vm_prev, addr);
75057-}
75058-
75059-/* Is the vma a continuation of the stack vma below it? */
75060-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
75061-{
75062- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
75063-}
75064-
75065-static inline int stack_guard_page_end(struct vm_area_struct *vma,
75066- unsigned long addr)
75067-{
75068- return (vma->vm_flags & VM_GROWSUP) &&
75069- (vma->vm_end == addr) &&
75070- !vma_growsup(vma->vm_next, addr);
75071-}
75072-
75073 extern pid_t
75074 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
75075
75076@@ -1184,6 +1162,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
75077 }
75078 #endif
75079
75080+#ifdef CONFIG_MMU
75081+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
75082+#else
75083+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
75084+{
75085+ return __pgprot(0);
75086+}
75087+#endif
75088+
75089 int vma_wants_writenotify(struct vm_area_struct *vma);
75090
75091 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
75092@@ -1202,8 +1189,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
75093 {
75094 return 0;
75095 }
75096+
75097+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
75098+ unsigned long address)
75099+{
75100+ return 0;
75101+}
75102 #else
75103 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
75104+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
75105 #endif
75106
75107 #ifdef __PAGETABLE_PMD_FOLDED
75108@@ -1212,8 +1206,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
75109 {
75110 return 0;
75111 }
75112+
75113+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
75114+ unsigned long address)
75115+{
75116+ return 0;
75117+}
75118 #else
75119 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
75120+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
75121 #endif
75122
75123 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
75124@@ -1231,11 +1232,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
75125 NULL: pud_offset(pgd, address);
75126 }
75127
75128+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
75129+{
75130+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
75131+ NULL: pud_offset(pgd, address);
75132+}
75133+
75134 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
75135 {
75136 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
75137 NULL: pmd_offset(pud, address);
75138 }
75139+
75140+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
75141+{
75142+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
75143+ NULL: pmd_offset(pud, address);
75144+}
75145 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
75146
75147 #if USE_SPLIT_PTLOCKS
75148@@ -1531,6 +1544,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75149 unsigned long len, unsigned long prot, unsigned long flags,
75150 unsigned long pgoff, unsigned long *populate);
75151 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
75152+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
75153
75154 #ifdef CONFIG_MMU
75155 extern int __mm_populate(unsigned long addr, unsigned long len,
75156@@ -1559,10 +1573,11 @@ struct vm_unmapped_area_info {
75157 unsigned long high_limit;
75158 unsigned long align_mask;
75159 unsigned long align_offset;
75160+ unsigned long threadstack_offset;
75161 };
75162
75163-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
75164-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
75165+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
75166+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
75167
75168 /*
75169 * Search for an unmapped address range.
75170@@ -1574,7 +1589,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
75171 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
75172 */
75173 static inline unsigned long
75174-vm_unmapped_area(struct vm_unmapped_area_info *info)
75175+vm_unmapped_area(const struct vm_unmapped_area_info *info)
75176 {
75177 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
75178 return unmapped_area(info);
75179@@ -1637,6 +1652,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
75180 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
75181 struct vm_area_struct **pprev);
75182
75183+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
75184+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
75185+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
75186+
75187 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
75188 NULL if none. Assume start_addr < end_addr. */
75189 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
75190@@ -1665,15 +1684,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
75191 return vma;
75192 }
75193
75194-#ifdef CONFIG_MMU
75195-pgprot_t vm_get_page_prot(unsigned long vm_flags);
75196-#else
75197-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
75198-{
75199- return __pgprot(0);
75200-}
75201-#endif
75202-
75203 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
75204 unsigned long change_prot_numa(struct vm_area_struct *vma,
75205 unsigned long start, unsigned long end);
75206@@ -1725,6 +1735,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
75207 static inline void vm_stat_account(struct mm_struct *mm,
75208 unsigned long flags, struct file *file, long pages)
75209 {
75210+
75211+#ifdef CONFIG_PAX_RANDMMAP
75212+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
75213+#endif
75214+
75215 mm->total_vm += pages;
75216 }
75217 #endif /* CONFIG_PROC_FS */
75218@@ -1805,7 +1820,7 @@ extern int unpoison_memory(unsigned long pfn);
75219 extern int sysctl_memory_failure_early_kill;
75220 extern int sysctl_memory_failure_recovery;
75221 extern void shake_page(struct page *p, int access);
75222-extern atomic_long_t num_poisoned_pages;
75223+extern atomic_long_unchecked_t num_poisoned_pages;
75224 extern int soft_offline_page(struct page *page, int flags);
75225
75226 extern void dump_page(struct page *page);
75227@@ -1842,5 +1857,11 @@ void __init setup_nr_node_ids(void);
75228 static inline void setup_nr_node_ids(void) {}
75229 #endif
75230
75231+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
75232+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
75233+#else
75234+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
75235+#endif
75236+
75237 #endif /* __KERNEL__ */
75238 #endif /* _LINUX_MM_H */
75239diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
75240index faf4b7c..1e70c6e 100644
75241--- a/include/linux/mm_types.h
75242+++ b/include/linux/mm_types.h
75243@@ -289,6 +289,8 @@ struct vm_area_struct {
75244 #ifdef CONFIG_NUMA
75245 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
75246 #endif
75247+
75248+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
75249 };
75250
75251 struct core_thread {
75252@@ -435,6 +437,24 @@ struct mm_struct {
75253 int first_nid;
75254 #endif
75255 struct uprobes_state uprobes_state;
75256+
75257+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
75258+ unsigned long pax_flags;
75259+#endif
75260+
75261+#ifdef CONFIG_PAX_DLRESOLVE
75262+ unsigned long call_dl_resolve;
75263+#endif
75264+
75265+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
75266+ unsigned long call_syscall;
75267+#endif
75268+
75269+#ifdef CONFIG_PAX_ASLR
75270+ unsigned long delta_mmap; /* randomized offset */
75271+ unsigned long delta_stack; /* randomized offset */
75272+#endif
75273+
75274 };
75275
75276 /* first nid will either be a valid NID or one of these values */
75277diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
75278index c5d5278..f0b68c8 100644
75279--- a/include/linux/mmiotrace.h
75280+++ b/include/linux/mmiotrace.h
75281@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
75282 /* Called from ioremap.c */
75283 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
75284 void __iomem *addr);
75285-extern void mmiotrace_iounmap(volatile void __iomem *addr);
75286+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
75287
75288 /* For anyone to insert markers. Remember trailing newline. */
75289 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
75290@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
75291 {
75292 }
75293
75294-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
75295+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
75296 {
75297 }
75298
75299diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
75300index af4a3b7..9ad8889 100644
75301--- a/include/linux/mmzone.h
75302+++ b/include/linux/mmzone.h
75303@@ -396,7 +396,7 @@ struct zone {
75304 unsigned long flags; /* zone flags, see below */
75305
75306 /* Zone statistics */
75307- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75308+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75309
75310 /*
75311 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
75312diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
75313index 45e9214..a7227d6 100644
75314--- a/include/linux/mod_devicetable.h
75315+++ b/include/linux/mod_devicetable.h
75316@@ -13,7 +13,7 @@
75317 typedef unsigned long kernel_ulong_t;
75318 #endif
75319
75320-#define PCI_ANY_ID (~0)
75321+#define PCI_ANY_ID ((__u16)~0)
75322
75323 struct pci_device_id {
75324 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
75325@@ -139,7 +139,7 @@ struct usb_device_id {
75326 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
75327 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
75328
75329-#define HID_ANY_ID (~0)
75330+#define HID_ANY_ID (~0U)
75331 #define HID_BUS_ANY 0xffff
75332 #define HID_GROUP_ANY 0x0000
75333
75334@@ -467,7 +467,7 @@ struct dmi_system_id {
75335 const char *ident;
75336 struct dmi_strmatch matches[4];
75337 void *driver_data;
75338-};
75339+} __do_const;
75340 /*
75341 * struct dmi_device_id appears during expansion of
75342 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
75343diff --git a/include/linux/module.h b/include/linux/module.h
75344index 46f1ea0..a34ca37 100644
75345--- a/include/linux/module.h
75346+++ b/include/linux/module.h
75347@@ -17,9 +17,11 @@
75348 #include <linux/moduleparam.h>
75349 #include <linux/tracepoint.h>
75350 #include <linux/export.h>
75351+#include <linux/fs.h>
75352
75353 #include <linux/percpu.h>
75354 #include <asm/module.h>
75355+#include <asm/pgtable.h>
75356
75357 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
75358 #define MODULE_SIG_STRING "~Module signature appended~\n"
75359@@ -54,12 +56,13 @@ struct module_attribute {
75360 int (*test)(struct module *);
75361 void (*free)(struct module *);
75362 };
75363+typedef struct module_attribute __no_const module_attribute_no_const;
75364
75365 struct module_version_attribute {
75366 struct module_attribute mattr;
75367 const char *module_name;
75368 const char *version;
75369-} __attribute__ ((__aligned__(sizeof(void *))));
75370+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
75371
75372 extern ssize_t __modver_version_show(struct module_attribute *,
75373 struct module_kobject *, char *);
75374@@ -232,7 +235,7 @@ struct module
75375
75376 /* Sysfs stuff. */
75377 struct module_kobject mkobj;
75378- struct module_attribute *modinfo_attrs;
75379+ module_attribute_no_const *modinfo_attrs;
75380 const char *version;
75381 const char *srcversion;
75382 struct kobject *holders_dir;
75383@@ -281,19 +284,16 @@ struct module
75384 int (*init)(void);
75385
75386 /* If this is non-NULL, vfree after init() returns */
75387- void *module_init;
75388+ void *module_init_rx, *module_init_rw;
75389
75390 /* Here is the actual code + data, vfree'd on unload. */
75391- void *module_core;
75392+ void *module_core_rx, *module_core_rw;
75393
75394 /* Here are the sizes of the init and core sections */
75395- unsigned int init_size, core_size;
75396+ unsigned int init_size_rw, core_size_rw;
75397
75398 /* The size of the executable code in each section. */
75399- unsigned int init_text_size, core_text_size;
75400-
75401- /* Size of RO sections of the module (text+rodata) */
75402- unsigned int init_ro_size, core_ro_size;
75403+ unsigned int init_size_rx, core_size_rx;
75404
75405 /* Arch-specific module values */
75406 struct mod_arch_specific arch;
75407@@ -349,6 +349,10 @@ struct module
75408 #ifdef CONFIG_EVENT_TRACING
75409 struct ftrace_event_call **trace_events;
75410 unsigned int num_trace_events;
75411+ struct file_operations trace_id;
75412+ struct file_operations trace_enable;
75413+ struct file_operations trace_format;
75414+ struct file_operations trace_filter;
75415 #endif
75416 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
75417 unsigned int num_ftrace_callsites;
75418@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
75419 bool is_module_percpu_address(unsigned long addr);
75420 bool is_module_text_address(unsigned long addr);
75421
75422+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
75423+{
75424+
75425+#ifdef CONFIG_PAX_KERNEXEC
75426+ if (ktla_ktva(addr) >= (unsigned long)start &&
75427+ ktla_ktva(addr) < (unsigned long)start + size)
75428+ return 1;
75429+#endif
75430+
75431+ return ((void *)addr >= start && (void *)addr < start + size);
75432+}
75433+
75434+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
75435+{
75436+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
75437+}
75438+
75439+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
75440+{
75441+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
75442+}
75443+
75444+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
75445+{
75446+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
75447+}
75448+
75449+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
75450+{
75451+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
75452+}
75453+
75454 static inline int within_module_core(unsigned long addr, const struct module *mod)
75455 {
75456- return (unsigned long)mod->module_core <= addr &&
75457- addr < (unsigned long)mod->module_core + mod->core_size;
75458+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
75459 }
75460
75461 static inline int within_module_init(unsigned long addr, const struct module *mod)
75462 {
75463- return (unsigned long)mod->module_init <= addr &&
75464- addr < (unsigned long)mod->module_init + mod->init_size;
75465+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
75466 }
75467
75468 /* Search for module by name: must hold module_mutex. */
75469diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
75470index 560ca53..ef621ef 100644
75471--- a/include/linux/moduleloader.h
75472+++ b/include/linux/moduleloader.h
75473@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
75474 sections. Returns NULL on failure. */
75475 void *module_alloc(unsigned long size);
75476
75477+#ifdef CONFIG_PAX_KERNEXEC
75478+void *module_alloc_exec(unsigned long size);
75479+#else
75480+#define module_alloc_exec(x) module_alloc(x)
75481+#endif
75482+
75483 /* Free memory returned from module_alloc. */
75484 void module_free(struct module *mod, void *module_region);
75485
75486+#ifdef CONFIG_PAX_KERNEXEC
75487+void module_free_exec(struct module *mod, void *module_region);
75488+#else
75489+#define module_free_exec(x, y) module_free((x), (y))
75490+#endif
75491+
75492 /*
75493 * Apply the given relocation to the (simplified) ELF. Return -error
75494 * or 0.
75495@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
75496 unsigned int relsec,
75497 struct module *me)
75498 {
75499+#ifdef CONFIG_MODULES
75500 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75501+#endif
75502 return -ENOEXEC;
75503 }
75504 #endif
75505@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
75506 unsigned int relsec,
75507 struct module *me)
75508 {
75509+#ifdef CONFIG_MODULES
75510 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75511+#endif
75512 return -ENOEXEC;
75513 }
75514 #endif
75515diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
75516index 27d9da3..5d94aa3 100644
75517--- a/include/linux/moduleparam.h
75518+++ b/include/linux/moduleparam.h
75519@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
75520 * @len is usually just sizeof(string).
75521 */
75522 #define module_param_string(name, string, len, perm) \
75523- static const struct kparam_string __param_string_##name \
75524+ static const struct kparam_string __param_string_##name __used \
75525 = { len, string }; \
75526 __module_param_call(MODULE_PARAM_PREFIX, name, \
75527 &param_ops_string, \
75528@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
75529 */
75530 #define module_param_array_named(name, array, type, nump, perm) \
75531 param_check_##type(name, &(array)[0]); \
75532- static const struct kparam_array __param_arr_##name \
75533+ static const struct kparam_array __param_arr_##name __used \
75534 = { .max = ARRAY_SIZE(array), .num = nump, \
75535 .ops = &param_ops_##type, \
75536 .elemsize = sizeof(array[0]), .elem = array }; \
75537diff --git a/include/linux/namei.h b/include/linux/namei.h
75538index 5a5ff57..5ae5070 100644
75539--- a/include/linux/namei.h
75540+++ b/include/linux/namei.h
75541@@ -19,7 +19,7 @@ struct nameidata {
75542 unsigned seq;
75543 int last_type;
75544 unsigned depth;
75545- char *saved_names[MAX_NESTED_LINKS + 1];
75546+ const char *saved_names[MAX_NESTED_LINKS + 1];
75547 };
75548
75549 /*
75550@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
75551
75552 extern void nd_jump_link(struct nameidata *nd, struct path *path);
75553
75554-static inline void nd_set_link(struct nameidata *nd, char *path)
75555+static inline void nd_set_link(struct nameidata *nd, const char *path)
75556 {
75557 nd->saved_names[nd->depth] = path;
75558 }
75559
75560-static inline char *nd_get_link(struct nameidata *nd)
75561+static inline const char *nd_get_link(const struct nameidata *nd)
75562 {
75563 return nd->saved_names[nd->depth];
75564 }
75565diff --git a/include/linux/net.h b/include/linux/net.h
75566index 4f27575..fc8a65f 100644
75567--- a/include/linux/net.h
75568+++ b/include/linux/net.h
75569@@ -183,7 +183,7 @@ struct net_proto_family {
75570 int (*create)(struct net *net, struct socket *sock,
75571 int protocol, int kern);
75572 struct module *owner;
75573-};
75574+} __do_const;
75575
75576 struct iovec;
75577 struct kvec;
75578diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
75579index 9a41568..203d903 100644
75580--- a/include/linux/netdevice.h
75581+++ b/include/linux/netdevice.h
75582@@ -1061,6 +1061,7 @@ struct net_device_ops {
75583 int (*ndo_change_carrier)(struct net_device *dev,
75584 bool new_carrier);
75585 };
75586+typedef struct net_device_ops __no_const net_device_ops_no_const;
75587
75588 /*
75589 * The DEVICE structure.
75590@@ -1131,7 +1132,7 @@ struct net_device {
75591 int iflink;
75592
75593 struct net_device_stats stats;
75594- atomic_long_t rx_dropped; /* dropped packets by core network
75595+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
75596 * Do not use this in drivers.
75597 */
75598
75599diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
75600index de70f7b..2675e91 100644
75601--- a/include/linux/netfilter.h
75602+++ b/include/linux/netfilter.h
75603@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
75604 #endif
75605 /* Use the module struct to lock set/get code in place */
75606 struct module *owner;
75607-};
75608+} __do_const;
75609
75610 /* Function to register/unregister hook points. */
75611 int nf_register_hook(struct nf_hook_ops *reg);
75612diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
75613index d80e275..c3510b8 100644
75614--- a/include/linux/netfilter/ipset/ip_set.h
75615+++ b/include/linux/netfilter/ipset/ip_set.h
75616@@ -124,7 +124,7 @@ struct ip_set_type_variant {
75617 /* Return true if "b" set is the same as "a"
75618 * according to the create set parameters */
75619 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
75620-};
75621+} __do_const;
75622
75623 /* The core set type structure */
75624 struct ip_set_type {
75625diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
75626index cadb740..d7c37c0 100644
75627--- a/include/linux/netfilter/nfnetlink.h
75628+++ b/include/linux/netfilter/nfnetlink.h
75629@@ -16,7 +16,7 @@ struct nfnl_callback {
75630 const struct nlattr * const cda[]);
75631 const struct nla_policy *policy; /* netlink attribute policy */
75632 const u_int16_t attr_count; /* number of nlattr's */
75633-};
75634+} __do_const;
75635
75636 struct nfnetlink_subsystem {
75637 const char *name;
75638diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
75639new file mode 100644
75640index 0000000..33f4af8
75641--- /dev/null
75642+++ b/include/linux/netfilter/xt_gradm.h
75643@@ -0,0 +1,9 @@
75644+#ifndef _LINUX_NETFILTER_XT_GRADM_H
75645+#define _LINUX_NETFILTER_XT_GRADM_H 1
75646+
75647+struct xt_gradm_mtinfo {
75648+ __u16 flags;
75649+ __u16 invflags;
75650+};
75651+
75652+#endif
75653diff --git a/include/linux/nls.h b/include/linux/nls.h
75654index 5dc635f..35f5e11 100644
75655--- a/include/linux/nls.h
75656+++ b/include/linux/nls.h
75657@@ -31,7 +31,7 @@ struct nls_table {
75658 const unsigned char *charset2upper;
75659 struct module *owner;
75660 struct nls_table *next;
75661-};
75662+} __do_const;
75663
75664 /* this value hold the maximum octet of charset */
75665 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
75666diff --git a/include/linux/notifier.h b/include/linux/notifier.h
75667index d14a4c3..a078786 100644
75668--- a/include/linux/notifier.h
75669+++ b/include/linux/notifier.h
75670@@ -54,7 +54,8 @@ struct notifier_block {
75671 notifier_fn_t notifier_call;
75672 struct notifier_block __rcu *next;
75673 int priority;
75674-};
75675+} __do_const;
75676+typedef struct notifier_block __no_const notifier_block_no_const;
75677
75678 struct atomic_notifier_head {
75679 spinlock_t lock;
75680diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
75681index a4c5624..79d6d88 100644
75682--- a/include/linux/oprofile.h
75683+++ b/include/linux/oprofile.h
75684@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
75685 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
75686 char const * name, ulong * val);
75687
75688-/** Create a file for read-only access to an atomic_t. */
75689+/** Create a file for read-only access to an atomic_unchecked_t. */
75690 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
75691- char const * name, atomic_t * val);
75692+ char const * name, atomic_unchecked_t * val);
75693
75694 /** create a directory */
75695 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
75696diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
75697index 8db71dc..a76bf2c 100644
75698--- a/include/linux/pci_hotplug.h
75699+++ b/include/linux/pci_hotplug.h
75700@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
75701 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
75702 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
75703 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
75704-};
75705+} __do_const;
75706+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
75707
75708 /**
75709 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
75710diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
75711index c43f6ea..2d4416f 100644
75712--- a/include/linux/perf_event.h
75713+++ b/include/linux/perf_event.h
75714@@ -328,8 +328,8 @@ struct perf_event {
75715
75716 enum perf_event_active_state state;
75717 unsigned int attach_state;
75718- local64_t count;
75719- atomic64_t child_count;
75720+ local64_t count; /* PaX: fix it one day */
75721+ atomic64_unchecked_t child_count;
75722
75723 /*
75724 * These are the total time in nanoseconds that the event
75725@@ -380,8 +380,8 @@ struct perf_event {
75726 * These accumulate total time (in nanoseconds) that children
75727 * events have been enabled and running, respectively.
75728 */
75729- atomic64_t child_total_time_enabled;
75730- atomic64_t child_total_time_running;
75731+ atomic64_unchecked_t child_total_time_enabled;
75732+ atomic64_unchecked_t child_total_time_running;
75733
75734 /*
75735 * Protect attach/detach and child_list:
75736@@ -703,7 +703,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
75737 entry->ip[entry->nr++] = ip;
75738 }
75739
75740-extern int sysctl_perf_event_paranoid;
75741+extern int sysctl_perf_event_legitimately_concerned;
75742 extern int sysctl_perf_event_mlock;
75743 extern int sysctl_perf_event_sample_rate;
75744 extern int sysctl_perf_cpu_time_max_percent;
75745@@ -718,19 +718,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
75746 loff_t *ppos);
75747
75748
75749+static inline bool perf_paranoid_any(void)
75750+{
75751+ return sysctl_perf_event_legitimately_concerned > 2;
75752+}
75753+
75754 static inline bool perf_paranoid_tracepoint_raw(void)
75755 {
75756- return sysctl_perf_event_paranoid > -1;
75757+ return sysctl_perf_event_legitimately_concerned > -1;
75758 }
75759
75760 static inline bool perf_paranoid_cpu(void)
75761 {
75762- return sysctl_perf_event_paranoid > 0;
75763+ return sysctl_perf_event_legitimately_concerned > 0;
75764 }
75765
75766 static inline bool perf_paranoid_kernel(void)
75767 {
75768- return sysctl_perf_event_paranoid > 1;
75769+ return sysctl_perf_event_legitimately_concerned > 1;
75770 }
75771
75772 extern void perf_event_init(void);
75773@@ -846,7 +851,7 @@ struct perf_pmu_events_attr {
75774 struct device_attribute attr;
75775 u64 id;
75776 const char *event_str;
75777-};
75778+} __do_const;
75779
75780 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
75781 static struct perf_pmu_events_attr _var = { \
75782diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
75783index b8809fe..ae4ccd0 100644
75784--- a/include/linux/pipe_fs_i.h
75785+++ b/include/linux/pipe_fs_i.h
75786@@ -47,10 +47,10 @@ struct pipe_inode_info {
75787 struct mutex mutex;
75788 wait_queue_head_t wait;
75789 unsigned int nrbufs, curbuf, buffers;
75790- unsigned int readers;
75791- unsigned int writers;
75792- unsigned int files;
75793- unsigned int waiting_writers;
75794+ atomic_t readers;
75795+ atomic_t writers;
75796+ atomic_t files;
75797+ atomic_t waiting_writers;
75798 unsigned int r_counter;
75799 unsigned int w_counter;
75800 struct page *tmp_page;
75801diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
75802index 5f28cae..3d23723 100644
75803--- a/include/linux/platform_data/usb-ehci-s5p.h
75804+++ b/include/linux/platform_data/usb-ehci-s5p.h
75805@@ -14,7 +14,7 @@
75806 struct s5p_ehci_platdata {
75807 int (*phy_init)(struct platform_device *pdev, int type);
75808 int (*phy_exit)(struct platform_device *pdev, int type);
75809-};
75810+} __no_const;
75811
75812 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
75813
75814diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
75815index c256c59..8ea94c7 100644
75816--- a/include/linux/platform_data/usb-ohci-exynos.h
75817+++ b/include/linux/platform_data/usb-ohci-exynos.h
75818@@ -14,7 +14,7 @@
75819 struct exynos4_ohci_platdata {
75820 int (*phy_init)(struct platform_device *pdev, int type);
75821 int (*phy_exit)(struct platform_device *pdev, int type);
75822-};
75823+} __no_const;
75824
75825 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
75826
75827diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
75828index 7c1d252..c5c773e 100644
75829--- a/include/linux/pm_domain.h
75830+++ b/include/linux/pm_domain.h
75831@@ -48,7 +48,7 @@ struct gpd_dev_ops {
75832
75833 struct gpd_cpu_data {
75834 unsigned int saved_exit_latency;
75835- struct cpuidle_state *idle_state;
75836+ cpuidle_state_no_const *idle_state;
75837 };
75838
75839 struct generic_pm_domain {
75840diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
75841index 6fa7cea..7bf6415 100644
75842--- a/include/linux/pm_runtime.h
75843+++ b/include/linux/pm_runtime.h
75844@@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
75845
75846 static inline void pm_runtime_mark_last_busy(struct device *dev)
75847 {
75848- ACCESS_ONCE(dev->power.last_busy) = jiffies;
75849+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
75850 }
75851
75852 #else /* !CONFIG_PM_RUNTIME */
75853diff --git a/include/linux/pnp.h b/include/linux/pnp.h
75854index 195aafc..49a7bc2 100644
75855--- a/include/linux/pnp.h
75856+++ b/include/linux/pnp.h
75857@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
75858 struct pnp_fixup {
75859 char id[7];
75860 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
75861-};
75862+} __do_const;
75863
75864 /* config parameters */
75865 #define PNP_CONFIG_NORMAL 0x0001
75866diff --git a/include/linux/poison.h b/include/linux/poison.h
75867index 2110a81..13a11bb 100644
75868--- a/include/linux/poison.h
75869+++ b/include/linux/poison.h
75870@@ -19,8 +19,8 @@
75871 * under normal circumstances, used to verify that nobody uses
75872 * non-initialized list entries.
75873 */
75874-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
75875-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
75876+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
75877+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
75878
75879 /********** include/linux/timer.h **********/
75880 /*
75881diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
75882index d8b187c3..9a9257a 100644
75883--- a/include/linux/power/smartreflex.h
75884+++ b/include/linux/power/smartreflex.h
75885@@ -238,7 +238,7 @@ struct omap_sr_class_data {
75886 int (*notify)(struct omap_sr *sr, u32 status);
75887 u8 notify_flags;
75888 u8 class_type;
75889-};
75890+} __do_const;
75891
75892 /**
75893 * struct omap_sr_nvalue_table - Smartreflex n-target value info
75894diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
75895index 4ea1d37..80f4b33 100644
75896--- a/include/linux/ppp-comp.h
75897+++ b/include/linux/ppp-comp.h
75898@@ -84,7 +84,7 @@ struct compressor {
75899 struct module *owner;
75900 /* Extra skb space needed by the compressor algorithm */
75901 unsigned int comp_extra;
75902-};
75903+} __do_const;
75904
75905 /*
75906 * The return value from decompress routine is the length of the
75907diff --git a/include/linux/preempt.h b/include/linux/preempt.h
75908index f5d4723..a6ea2fa 100644
75909--- a/include/linux/preempt.h
75910+++ b/include/linux/preempt.h
75911@@ -18,8 +18,13 @@
75912 # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
75913 #endif
75914
75915+#define raw_add_preempt_count(val) do { preempt_count() += (val); } while (0)
75916+#define raw_sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
75917+
75918 #define inc_preempt_count() add_preempt_count(1)
75919+#define raw_inc_preempt_count() raw_add_preempt_count(1)
75920 #define dec_preempt_count() sub_preempt_count(1)
75921+#define raw_dec_preempt_count() raw_sub_preempt_count(1)
75922
75923 #define preempt_count() (current_thread_info()->preempt_count)
75924
75925@@ -64,6 +69,12 @@ do { \
75926 barrier(); \
75927 } while (0)
75928
75929+#define raw_preempt_disable() \
75930+do { \
75931+ raw_inc_preempt_count(); \
75932+ barrier(); \
75933+} while (0)
75934+
75935 #define sched_preempt_enable_no_resched() \
75936 do { \
75937 barrier(); \
75938@@ -72,6 +83,12 @@ do { \
75939
75940 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
75941
75942+#define raw_preempt_enable_no_resched() \
75943+do { \
75944+ barrier(); \
75945+ raw_dec_preempt_count(); \
75946+} while (0)
75947+
75948 #define preempt_enable() \
75949 do { \
75950 preempt_enable_no_resched(); \
75951@@ -116,8 +133,10 @@ do { \
75952 * region.
75953 */
75954 #define preempt_disable() barrier()
75955+#define raw_preempt_disable() barrier()
75956 #define sched_preempt_enable_no_resched() barrier()
75957 #define preempt_enable_no_resched() barrier()
75958+#define raw_preempt_enable_no_resched() barrier()
75959 #define preempt_enable() barrier()
75960
75961 #define preempt_disable_notrace() barrier()
75962diff --git a/include/linux/printk.h b/include/linux/printk.h
75963index 22c7052..ad3fa0a 100644
75964--- a/include/linux/printk.h
75965+++ b/include/linux/printk.h
75966@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
75967 void early_printk(const char *s, ...) { }
75968 #endif
75969
75970+extern int kptr_restrict;
75971+
75972 #ifdef CONFIG_PRINTK
75973 asmlinkage __printf(5, 0)
75974 int vprintk_emit(int facility, int level,
75975@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
75976
75977 extern int printk_delay_msec;
75978 extern int dmesg_restrict;
75979-extern int kptr_restrict;
75980
75981 extern void wake_up_klogd(void);
75982
75983diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
75984index 608e60a..c26f864 100644
75985--- a/include/linux/proc_fs.h
75986+++ b/include/linux/proc_fs.h
75987@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
75988 return proc_create_data(name, mode, parent, proc_fops, NULL);
75989 }
75990
75991+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
75992+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
75993+{
75994+#ifdef CONFIG_GRKERNSEC_PROC_USER
75995+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
75996+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75997+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
75998+#else
75999+ return proc_create_data(name, mode, parent, proc_fops, NULL);
76000+#endif
76001+}
76002+
76003+
76004 extern void proc_set_size(struct proc_dir_entry *, loff_t);
76005 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
76006 extern void *PDE_DATA(const struct inode *);
76007diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
76008index 34a1e10..03a6d03 100644
76009--- a/include/linux/proc_ns.h
76010+++ b/include/linux/proc_ns.h
76011@@ -14,7 +14,7 @@ struct proc_ns_operations {
76012 void (*put)(void *ns);
76013 int (*install)(struct nsproxy *nsproxy, void *ns);
76014 unsigned int (*inum)(void *ns);
76015-};
76016+} __do_const;
76017
76018 struct proc_ns {
76019 void *ns;
76020diff --git a/include/linux/random.h b/include/linux/random.h
76021index 3b9377d..943ad4a 100644
76022--- a/include/linux/random.h
76023+++ b/include/linux/random.h
76024@@ -10,6 +10,16 @@
76025
76026
76027 extern void add_device_randomness(const void *, unsigned int);
76028+
76029+static inline void add_latent_entropy(void)
76030+{
76031+
76032+#ifdef LATENT_ENTROPY_PLUGIN
76033+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
76034+#endif
76035+
76036+}
76037+
76038 extern void add_input_randomness(unsigned int type, unsigned int code,
76039 unsigned int value);
76040 extern void add_interrupt_randomness(int irq, int irq_flags);
76041@@ -32,6 +42,11 @@ void prandom_seed(u32 seed);
76042 u32 prandom_u32_state(struct rnd_state *);
76043 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
76044
76045+static inline unsigned long pax_get_random_long(void)
76046+{
76047+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
76048+}
76049+
76050 /*
76051 * Handle minimum values for seeds
76052 */
76053diff --git a/include/linux/rculist.h b/include/linux/rculist.h
76054index f4b1001..8ddb2b6 100644
76055--- a/include/linux/rculist.h
76056+++ b/include/linux/rculist.h
76057@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
76058 struct list_head *prev, struct list_head *next);
76059 #endif
76060
76061+extern void __pax_list_add_rcu(struct list_head *new,
76062+ struct list_head *prev, struct list_head *next);
76063+
76064 /**
76065 * list_add_rcu - add a new entry to rcu-protected list
76066 * @new: new entry to be added
76067@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
76068 __list_add_rcu(new, head, head->next);
76069 }
76070
76071+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
76072+{
76073+ __pax_list_add_rcu(new, head, head->next);
76074+}
76075+
76076 /**
76077 * list_add_tail_rcu - add a new entry to rcu-protected list
76078 * @new: new entry to be added
76079@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
76080 __list_add_rcu(new, head->prev, head);
76081 }
76082
76083+static inline void pax_list_add_tail_rcu(struct list_head *new,
76084+ struct list_head *head)
76085+{
76086+ __pax_list_add_rcu(new, head->prev, head);
76087+}
76088+
76089 /**
76090 * list_del_rcu - deletes entry from list without re-initialization
76091 * @entry: the element to delete from the list.
76092@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
76093 entry->prev = LIST_POISON2;
76094 }
76095
76096+extern void pax_list_del_rcu(struct list_head *entry);
76097+
76098 /**
76099 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
76100 * @n: the element to delete from the hash list.
76101diff --git a/include/linux/reboot.h b/include/linux/reboot.h
76102index 8e00f9f..9449b55 100644
76103--- a/include/linux/reboot.h
76104+++ b/include/linux/reboot.h
76105@@ -43,9 +43,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
76106 * Architecture-specific implementations of sys_reboot commands.
76107 */
76108
76109-extern void machine_restart(char *cmd);
76110-extern void machine_halt(void);
76111-extern void machine_power_off(void);
76112+extern void machine_restart(char *cmd) __noreturn;
76113+extern void machine_halt(void) __noreturn;
76114+extern void machine_power_off(void) __noreturn;
76115
76116 extern void machine_shutdown(void);
76117 struct pt_regs;
76118@@ -56,9 +56,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
76119 */
76120
76121 extern void kernel_restart_prepare(char *cmd);
76122-extern void kernel_restart(char *cmd);
76123-extern void kernel_halt(void);
76124-extern void kernel_power_off(void);
76125+extern void kernel_restart(char *cmd) __noreturn;
76126+extern void kernel_halt(void) __noreturn;
76127+extern void kernel_power_off(void) __noreturn;
76128
76129 extern int C_A_D; /* for sysctl */
76130 void ctrl_alt_del(void);
76131@@ -72,7 +72,7 @@ extern int orderly_poweroff(bool force);
76132 * Emergency restart, callable from an interrupt handler.
76133 */
76134
76135-extern void emergency_restart(void);
76136+extern void emergency_restart(void) __noreturn;
76137 #include <asm/emergency-restart.h>
76138
76139 #endif /* _LINUX_REBOOT_H */
76140diff --git a/include/linux/regset.h b/include/linux/regset.h
76141index 8e0c9fe..ac4d221 100644
76142--- a/include/linux/regset.h
76143+++ b/include/linux/regset.h
76144@@ -161,7 +161,8 @@ struct user_regset {
76145 unsigned int align;
76146 unsigned int bias;
76147 unsigned int core_note_type;
76148-};
76149+} __do_const;
76150+typedef struct user_regset __no_const user_regset_no_const;
76151
76152 /**
76153 * struct user_regset_view - available regsets
76154diff --git a/include/linux/relay.h b/include/linux/relay.h
76155index d7c8359..818daf5 100644
76156--- a/include/linux/relay.h
76157+++ b/include/linux/relay.h
76158@@ -157,7 +157,7 @@ struct rchan_callbacks
76159 * The callback should return 0 if successful, negative if not.
76160 */
76161 int (*remove_buf_file)(struct dentry *dentry);
76162-};
76163+} __no_const;
76164
76165 /*
76166 * CONFIG_RELAY kernel API, kernel/relay.c
76167diff --git a/include/linux/rio.h b/include/linux/rio.h
76168index b71d573..2f940bd 100644
76169--- a/include/linux/rio.h
76170+++ b/include/linux/rio.h
76171@@ -355,7 +355,7 @@ struct rio_ops {
76172 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
76173 u64 rstart, u32 size, u32 flags);
76174 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
76175-};
76176+} __no_const;
76177
76178 #define RIO_RESOURCE_MEM 0x00000100
76179 #define RIO_RESOURCE_DOORBELL 0x00000200
76180diff --git a/include/linux/rmap.h b/include/linux/rmap.h
76181index 6dacb93..6174423 100644
76182--- a/include/linux/rmap.h
76183+++ b/include/linux/rmap.h
76184@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
76185 void anon_vma_init(void); /* create anon_vma_cachep */
76186 int anon_vma_prepare(struct vm_area_struct *);
76187 void unlink_anon_vmas(struct vm_area_struct *);
76188-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
76189-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
76190+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
76191+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
76192
76193 static inline void anon_vma_merge(struct vm_area_struct *vma,
76194 struct vm_area_struct *next)
76195diff --git a/include/linux/sched.h b/include/linux/sched.h
76196index 078066d..4090b3b 100644
76197--- a/include/linux/sched.h
76198+++ b/include/linux/sched.h
76199@@ -62,6 +62,7 @@ struct bio_list;
76200 struct fs_struct;
76201 struct perf_event_context;
76202 struct blk_plug;
76203+struct linux_binprm;
76204
76205 /*
76206 * List of flags we want to share for kernel threads,
76207@@ -303,7 +304,7 @@ extern char __sched_text_start[], __sched_text_end[];
76208 extern int in_sched_functions(unsigned long addr);
76209
76210 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
76211-extern signed long schedule_timeout(signed long timeout);
76212+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
76213 extern signed long schedule_timeout_interruptible(signed long timeout);
76214 extern signed long schedule_timeout_killable(signed long timeout);
76215 extern signed long schedule_timeout_uninterruptible(signed long timeout);
76216@@ -314,6 +315,19 @@ struct nsproxy;
76217 struct user_namespace;
76218
76219 #ifdef CONFIG_MMU
76220+
76221+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
76222+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
76223+#else
76224+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
76225+{
76226+ return 0;
76227+}
76228+#endif
76229+
76230+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
76231+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
76232+
76233 extern void arch_pick_mmap_layout(struct mm_struct *mm);
76234 extern unsigned long
76235 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
76236@@ -589,6 +603,17 @@ struct signal_struct {
76237 #ifdef CONFIG_TASKSTATS
76238 struct taskstats *stats;
76239 #endif
76240+
76241+#ifdef CONFIG_GRKERNSEC
76242+ u32 curr_ip;
76243+ u32 saved_ip;
76244+ u32 gr_saddr;
76245+ u32 gr_daddr;
76246+ u16 gr_sport;
76247+ u16 gr_dport;
76248+ u8 used_accept:1;
76249+#endif
76250+
76251 #ifdef CONFIG_AUDIT
76252 unsigned audit_tty;
76253 unsigned audit_tty_log_passwd;
76254@@ -669,6 +694,14 @@ struct user_struct {
76255 struct key *session_keyring; /* UID's default session keyring */
76256 #endif
76257
76258+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76259+ unsigned char kernel_banned;
76260+#endif
76261+#ifdef CONFIG_GRKERNSEC_BRUTE
76262+ unsigned char suid_banned;
76263+ unsigned long suid_ban_expires;
76264+#endif
76265+
76266 /* Hash table maintenance information */
76267 struct hlist_node uidhash_node;
76268 kuid_t uid;
76269@@ -1151,8 +1184,8 @@ struct task_struct {
76270 struct list_head thread_group;
76271
76272 struct completion *vfork_done; /* for vfork() */
76273- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
76274- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
76275+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
76276+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
76277
76278 cputime_t utime, stime, utimescaled, stimescaled;
76279 cputime_t gtime;
76280@@ -1177,11 +1210,6 @@ struct task_struct {
76281 struct task_cputime cputime_expires;
76282 struct list_head cpu_timers[3];
76283
76284-/* process credentials */
76285- const struct cred __rcu *real_cred; /* objective and real subjective task
76286- * credentials (COW) */
76287- const struct cred __rcu *cred; /* effective (overridable) subjective task
76288- * credentials (COW) */
76289 char comm[TASK_COMM_LEN]; /* executable name excluding path
76290 - access with [gs]et_task_comm (which lock
76291 it with task_lock())
76292@@ -1198,6 +1226,10 @@ struct task_struct {
76293 #endif
76294 /* CPU-specific state of this task */
76295 struct thread_struct thread;
76296+/* thread_info moved to task_struct */
76297+#ifdef CONFIG_X86
76298+ struct thread_info tinfo;
76299+#endif
76300 /* filesystem information */
76301 struct fs_struct *fs;
76302 /* open file information */
76303@@ -1271,6 +1303,10 @@ struct task_struct {
76304 gfp_t lockdep_reclaim_gfp;
76305 #endif
76306
76307+/* process credentials */
76308+ const struct cred __rcu *real_cred; /* objective and real subjective task
76309+ * credentials (COW) */
76310+
76311 /* journalling filesystem info */
76312 void *journal_info;
76313
76314@@ -1309,6 +1345,10 @@ struct task_struct {
76315 /* cg_list protected by css_set_lock and tsk->alloc_lock */
76316 struct list_head cg_list;
76317 #endif
76318+
76319+ const struct cred __rcu *cred; /* effective (overridable) subjective task
76320+ * credentials (COW) */
76321+
76322 #ifdef CONFIG_FUTEX
76323 struct robust_list_head __user *robust_list;
76324 #ifdef CONFIG_COMPAT
76325@@ -1406,8 +1446,76 @@ struct task_struct {
76326 unsigned int sequential_io;
76327 unsigned int sequential_io_avg;
76328 #endif
76329+
76330+#ifdef CONFIG_GRKERNSEC
76331+ /* grsecurity */
76332+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76333+ u64 exec_id;
76334+#endif
76335+#ifdef CONFIG_GRKERNSEC_SETXID
76336+ const struct cred *delayed_cred;
76337+#endif
76338+ struct dentry *gr_chroot_dentry;
76339+ struct acl_subject_label *acl;
76340+ struct acl_role_label *role;
76341+ struct file *exec_file;
76342+ unsigned long brute_expires;
76343+ u16 acl_role_id;
76344+ /* is this the task that authenticated to the special role */
76345+ u8 acl_sp_role;
76346+ u8 is_writable;
76347+ u8 brute;
76348+ u8 gr_is_chrooted;
76349+#endif
76350+
76351 };
76352
76353+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
76354+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
76355+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
76356+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
76357+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
76358+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
76359+
76360+#ifdef CONFIG_PAX_SOFTMODE
76361+extern int pax_softmode;
76362+#endif
76363+
76364+extern int pax_check_flags(unsigned long *);
76365+
76366+/* if tsk != current then task_lock must be held on it */
76367+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
76368+static inline unsigned long pax_get_flags(struct task_struct *tsk)
76369+{
76370+ if (likely(tsk->mm))
76371+ return tsk->mm->pax_flags;
76372+ else
76373+ return 0UL;
76374+}
76375+
76376+/* if tsk != current then task_lock must be held on it */
76377+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
76378+{
76379+ if (likely(tsk->mm)) {
76380+ tsk->mm->pax_flags = flags;
76381+ return 0;
76382+ }
76383+ return -EINVAL;
76384+}
76385+#endif
76386+
76387+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76388+extern void pax_set_initial_flags(struct linux_binprm *bprm);
76389+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
76390+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
76391+#endif
76392+
76393+struct path;
76394+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
76395+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
76396+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
76397+extern void pax_report_refcount_overflow(struct pt_regs *regs);
76398+
76399 /* Future-safe accessor for struct task_struct's cpus_allowed. */
76400 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
76401
76402@@ -1466,7 +1574,7 @@ struct pid_namespace;
76403 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
76404 struct pid_namespace *ns);
76405
76406-static inline pid_t task_pid_nr(struct task_struct *tsk)
76407+static inline pid_t task_pid_nr(const struct task_struct *tsk)
76408 {
76409 return tsk->pid;
76410 }
76411@@ -1916,7 +2024,9 @@ void yield(void);
76412 extern struct exec_domain default_exec_domain;
76413
76414 union thread_union {
76415+#ifndef CONFIG_X86
76416 struct thread_info thread_info;
76417+#endif
76418 unsigned long stack[THREAD_SIZE/sizeof(long)];
76419 };
76420
76421@@ -1949,6 +2059,7 @@ extern struct pid_namespace init_pid_ns;
76422 */
76423
76424 extern struct task_struct *find_task_by_vpid(pid_t nr);
76425+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
76426 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
76427 struct pid_namespace *ns);
76428
76429@@ -2113,7 +2224,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
76430 extern void exit_itimers(struct signal_struct *);
76431 extern void flush_itimer_signals(void);
76432
76433-extern void do_group_exit(int);
76434+extern __noreturn void do_group_exit(int);
76435
76436 extern int allow_signal(int);
76437 extern int disallow_signal(int);
76438@@ -2304,9 +2415,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
76439
76440 #endif
76441
76442-static inline int object_is_on_stack(void *obj)
76443+static inline int object_starts_on_stack(void *obj)
76444 {
76445- void *stack = task_stack_page(current);
76446+ const void *stack = task_stack_page(current);
76447
76448 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
76449 }
76450diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
76451index bf8086b..962b035 100644
76452--- a/include/linux/sched/sysctl.h
76453+++ b/include/linux/sched/sysctl.h
76454@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
76455 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
76456
76457 extern int sysctl_max_map_count;
76458+extern unsigned long sysctl_heap_stack_gap;
76459
76460 extern unsigned int sysctl_sched_latency;
76461 extern unsigned int sysctl_sched_min_granularity;
76462diff --git a/include/linux/security.h b/include/linux/security.h
76463index 7ce53ae..e64e2fb 100644
76464--- a/include/linux/security.h
76465+++ b/include/linux/security.h
76466@@ -27,6 +27,7 @@
76467 #include <linux/slab.h>
76468 #include <linux/err.h>
76469 #include <linux/string.h>
76470+#include <linux/grsecurity.h>
76471
76472 struct linux_binprm;
76473 struct cred;
76474@@ -116,7 +117,7 @@ struct seq_file;
76475
76476 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
76477
76478-void reset_security_ops(void);
76479+extern struct security_operations default_security_ops;
76480
76481 #ifdef CONFIG_MMU
76482 extern unsigned long mmap_min_addr;
76483diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
76484index 4e32edc..f8f2d18 100644
76485--- a/include/linux/seq_file.h
76486+++ b/include/linux/seq_file.h
76487@@ -26,6 +26,9 @@ struct seq_file {
76488 struct mutex lock;
76489 const struct seq_operations *op;
76490 int poll_event;
76491+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76492+ u64 exec_id;
76493+#endif
76494 #ifdef CONFIG_USER_NS
76495 struct user_namespace *user_ns;
76496 #endif
76497@@ -38,6 +41,7 @@ struct seq_operations {
76498 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
76499 int (*show) (struct seq_file *m, void *v);
76500 };
76501+typedef struct seq_operations __no_const seq_operations_no_const;
76502
76503 #define SEQ_SKIP 1
76504
76505diff --git a/include/linux/shm.h b/include/linux/shm.h
76506index 429c199..4d42e38 100644
76507--- a/include/linux/shm.h
76508+++ b/include/linux/shm.h
76509@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
76510
76511 /* The task created the shm object. NULL if the task is dead. */
76512 struct task_struct *shm_creator;
76513+#ifdef CONFIG_GRKERNSEC
76514+ time_t shm_createtime;
76515+ pid_t shm_lapid;
76516+#endif
76517 };
76518
76519 /* shm_mode upper byte flags */
76520diff --git a/include/linux/signal.h b/include/linux/signal.h
76521index d897484..323ba98 100644
76522--- a/include/linux/signal.h
76523+++ b/include/linux/signal.h
76524@@ -433,6 +433,7 @@ void signals_init(void);
76525
76526 int restore_altstack(const stack_t __user *);
76527 int __save_altstack(stack_t __user *, unsigned long);
76528+void __save_altstack_ex(stack_t __user *, unsigned long);
76529
76530 #ifdef CONFIG_PROC_FS
76531 struct seq_file;
76532diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
76533index 3b71a4e..5c9f309 100644
76534--- a/include/linux/skbuff.h
76535+++ b/include/linux/skbuff.h
76536@@ -648,7 +648,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
76537 extern struct sk_buff *__alloc_skb(unsigned int size,
76538 gfp_t priority, int flags, int node);
76539 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
76540-static inline struct sk_buff *alloc_skb(unsigned int size,
76541+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
76542 gfp_t priority)
76543 {
76544 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
76545@@ -764,7 +764,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
76546 */
76547 static inline int skb_queue_empty(const struct sk_buff_head *list)
76548 {
76549- return list->next == (struct sk_buff *)list;
76550+ return list->next == (const struct sk_buff *)list;
76551 }
76552
76553 /**
76554@@ -777,7 +777,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
76555 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76556 const struct sk_buff *skb)
76557 {
76558- return skb->next == (struct sk_buff *)list;
76559+ return skb->next == (const struct sk_buff *)list;
76560 }
76561
76562 /**
76563@@ -790,7 +790,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76564 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
76565 const struct sk_buff *skb)
76566 {
76567- return skb->prev == (struct sk_buff *)list;
76568+ return skb->prev == (const struct sk_buff *)list;
76569 }
76570
76571 /**
76572@@ -1750,7 +1750,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
76573 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
76574 */
76575 #ifndef NET_SKB_PAD
76576-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
76577+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
76578 #endif
76579
76580 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
76581@@ -2345,7 +2345,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
76582 int noblock, int *err);
76583 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
76584 struct poll_table_struct *wait);
76585-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
76586+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
76587 int offset, struct iovec *to,
76588 int size);
76589 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
76590@@ -2636,6 +2636,9 @@ static inline void nf_reset(struct sk_buff *skb)
76591 nf_bridge_put(skb->nf_bridge);
76592 skb->nf_bridge = NULL;
76593 #endif
76594+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
76595+ skb->nf_trace = 0;
76596+#endif
76597 }
76598
76599 static inline void nf_reset_trace(struct sk_buff *skb)
76600diff --git a/include/linux/slab.h b/include/linux/slab.h
76601index 6c5cc0e..9ca0fd6 100644
76602--- a/include/linux/slab.h
76603+++ b/include/linux/slab.h
76604@@ -12,15 +12,29 @@
76605 #include <linux/gfp.h>
76606 #include <linux/types.h>
76607 #include <linux/workqueue.h>
76608-
76609+#include <linux/err.h>
76610
76611 /*
76612 * Flags to pass to kmem_cache_create().
76613 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
76614 */
76615 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
76616+
76617+#ifdef CONFIG_PAX_USERCOPY_SLABS
76618+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
76619+#else
76620+#define SLAB_USERCOPY 0x00000000UL
76621+#endif
76622+
76623 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
76624 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
76625+
76626+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76627+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
76628+#else
76629+#define SLAB_NO_SANITIZE 0x00000000UL
76630+#endif
76631+
76632 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
76633 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
76634 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
76635@@ -89,10 +103,13 @@
76636 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
76637 * Both make kfree a no-op.
76638 */
76639-#define ZERO_SIZE_PTR ((void *)16)
76640+#define ZERO_SIZE_PTR \
76641+({ \
76642+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
76643+ (void *)(-MAX_ERRNO-1L); \
76644+})
76645
76646-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
76647- (unsigned long)ZERO_SIZE_PTR)
76648+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
76649
76650
76651 struct mem_cgroup;
76652@@ -132,6 +149,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
76653 void kfree(const void *);
76654 void kzfree(const void *);
76655 size_t ksize(const void *);
76656+const char *check_heap_object(const void *ptr, unsigned long n);
76657+bool is_usercopy_object(const void *ptr);
76658
76659 /*
76660 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
76661@@ -164,7 +183,7 @@ struct kmem_cache {
76662 unsigned int align; /* Alignment as calculated */
76663 unsigned long flags; /* Active flags on the slab */
76664 const char *name; /* Slab name for sysfs */
76665- int refcount; /* Use counter */
76666+ atomic_t refcount; /* Use counter */
76667 void (*ctor)(void *); /* Called on object slot creation */
76668 struct list_head list; /* List of all slab caches on the system */
76669 };
76670@@ -238,6 +257,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
76671 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76672 #endif
76673
76674+#ifdef CONFIG_PAX_USERCOPY_SLABS
76675+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
76676+#endif
76677+
76678 /*
76679 * Figure out which kmalloc slab an allocation of a certain size
76680 * belongs to.
76681@@ -246,7 +269,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76682 * 2 = 120 .. 192 bytes
76683 * n = 2^(n-1) .. 2^n -1
76684 */
76685-static __always_inline int kmalloc_index(size_t size)
76686+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
76687 {
76688 if (!size)
76689 return 0;
76690@@ -492,7 +515,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
76691 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76692 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76693 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76694-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76695+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
76696 #define kmalloc_track_caller(size, flags) \
76697 __kmalloc_track_caller(size, flags, _RET_IP_)
76698 #else
76699@@ -512,7 +535,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76700 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76701 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76702 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76703-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
76704+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
76705 #define kmalloc_node_track_caller(size, flags, node) \
76706 __kmalloc_node_track_caller(size, flags, node, \
76707 _RET_IP_)
76708diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
76709index cd40158..4e2f7af 100644
76710--- a/include/linux/slab_def.h
76711+++ b/include/linux/slab_def.h
76712@@ -50,7 +50,7 @@ struct kmem_cache {
76713 /* 4) cache creation/removal */
76714 const char *name;
76715 struct list_head list;
76716- int refcount;
76717+ atomic_t refcount;
76718 int object_size;
76719 int align;
76720
76721@@ -66,10 +66,14 @@ struct kmem_cache {
76722 unsigned long node_allocs;
76723 unsigned long node_frees;
76724 unsigned long node_overflow;
76725- atomic_t allochit;
76726- atomic_t allocmiss;
76727- atomic_t freehit;
76728- atomic_t freemiss;
76729+ atomic_unchecked_t allochit;
76730+ atomic_unchecked_t allocmiss;
76731+ atomic_unchecked_t freehit;
76732+ atomic_unchecked_t freemiss;
76733+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76734+ atomic_unchecked_t sanitized;
76735+ atomic_unchecked_t not_sanitized;
76736+#endif
76737
76738 /*
76739 * If debugging is enabled, then the allocator can add additional
76740@@ -103,7 +107,7 @@ struct kmem_cache {
76741 };
76742
76743 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76744-void *__kmalloc(size_t size, gfp_t flags);
76745+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
76746
76747 #ifdef CONFIG_TRACING
76748 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
76749@@ -136,6 +140,13 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76750 cachep = kmalloc_dma_caches[i];
76751 else
76752 #endif
76753+
76754+#ifdef CONFIG_PAX_USERCOPY_SLABS
76755+ if (flags & GFP_USERCOPY)
76756+ cachep = kmalloc_usercopy_caches[i];
76757+ else
76758+#endif
76759+
76760 cachep = kmalloc_caches[i];
76761
76762 ret = kmem_cache_alloc_trace(cachep, flags, size);
76763@@ -146,7 +157,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76764 }
76765
76766 #ifdef CONFIG_NUMA
76767-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
76768+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76769 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76770
76771 #ifdef CONFIG_TRACING
76772@@ -185,6 +196,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76773 cachep = kmalloc_dma_caches[i];
76774 else
76775 #endif
76776+
76777+#ifdef CONFIG_PAX_USERCOPY_SLABS
76778+ if (flags & GFP_USERCOPY)
76779+ cachep = kmalloc_usercopy_caches[i];
76780+ else
76781+#endif
76782+
76783 cachep = kmalloc_caches[i];
76784
76785 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
76786diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
76787index 095a5a4..4b82027 100644
76788--- a/include/linux/slob_def.h
76789+++ b/include/linux/slob_def.h
76790@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
76791 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
76792 }
76793
76794-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76795+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76796
76797 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76798 {
76799@@ -23,7 +23,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76800 return __kmalloc_node(size, flags, NUMA_NO_NODE);
76801 }
76802
76803-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
76804+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
76805 {
76806 return kmalloc(size, flags);
76807 }
76808diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
76809index 027276f..092bfe8 100644
76810--- a/include/linux/slub_def.h
76811+++ b/include/linux/slub_def.h
76812@@ -80,7 +80,7 @@ struct kmem_cache {
76813 struct kmem_cache_order_objects max;
76814 struct kmem_cache_order_objects min;
76815 gfp_t allocflags; /* gfp flags to use on each alloc */
76816- int refcount; /* Refcount for slab cache destroy */
76817+ atomic_t refcount; /* Refcount for slab cache destroy */
76818 void (*ctor)(void *);
76819 int inuse; /* Offset to metadata */
76820 int align; /* Alignment */
76821@@ -105,7 +105,7 @@ struct kmem_cache {
76822 };
76823
76824 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76825-void *__kmalloc(size_t size, gfp_t flags);
76826+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
76827
76828 static __always_inline void *
76829 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
76830@@ -149,7 +149,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
76831 }
76832 #endif
76833
76834-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
76835+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
76836 {
76837 unsigned int order = get_order(size);
76838 return kmalloc_order_trace(size, flags, order);
76839@@ -175,7 +175,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76840 }
76841
76842 #ifdef CONFIG_NUMA
76843-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76844+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76845 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76846
76847 #ifdef CONFIG_TRACING
76848diff --git a/include/linux/smp.h b/include/linux/smp.h
76849index c181399..09d7b92 100644
76850--- a/include/linux/smp.h
76851+++ b/include/linux/smp.h
76852@@ -217,7 +217,9 @@ static inline void kick_all_cpus_sync(void) { }
76853 #endif
76854
76855 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
76856+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
76857 #define put_cpu() preempt_enable()
76858+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
76859
76860 /*
76861 * Callback to arch code if there's nosmp or maxcpus=0 on the
76862diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
76863index 54f91d3..be2c379 100644
76864--- a/include/linux/sock_diag.h
76865+++ b/include/linux/sock_diag.h
76866@@ -11,7 +11,7 @@ struct sock;
76867 struct sock_diag_handler {
76868 __u8 family;
76869 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
76870-};
76871+} __do_const;
76872
76873 int sock_diag_register(const struct sock_diag_handler *h);
76874 void sock_diag_unregister(const struct sock_diag_handler *h);
76875diff --git a/include/linux/sonet.h b/include/linux/sonet.h
76876index 680f9a3..f13aeb0 100644
76877--- a/include/linux/sonet.h
76878+++ b/include/linux/sonet.h
76879@@ -7,7 +7,7 @@
76880 #include <uapi/linux/sonet.h>
76881
76882 struct k_sonet_stats {
76883-#define __HANDLE_ITEM(i) atomic_t i
76884+#define __HANDLE_ITEM(i) atomic_unchecked_t i
76885 __SONET_ITEMS
76886 #undef __HANDLE_ITEM
76887 };
76888diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
76889index 07d8e53..dc934c9 100644
76890--- a/include/linux/sunrpc/addr.h
76891+++ b/include/linux/sunrpc/addr.h
76892@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
76893 {
76894 switch (sap->sa_family) {
76895 case AF_INET:
76896- return ntohs(((struct sockaddr_in *)sap)->sin_port);
76897+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
76898 case AF_INET6:
76899- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
76900+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
76901 }
76902 return 0;
76903 }
76904@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
76905 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
76906 const struct sockaddr *src)
76907 {
76908- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
76909+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
76910 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
76911
76912 dsin->sin_family = ssin->sin_family;
76913@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
76914 if (sa->sa_family != AF_INET6)
76915 return 0;
76916
76917- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
76918+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
76919 }
76920
76921 #endif /* _LINUX_SUNRPC_ADDR_H */
76922diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
76923index bfe11be..12bc8c4 100644
76924--- a/include/linux/sunrpc/clnt.h
76925+++ b/include/linux/sunrpc/clnt.h
76926@@ -96,7 +96,7 @@ struct rpc_procinfo {
76927 unsigned int p_timer; /* Which RTT timer to use */
76928 u32 p_statidx; /* Which procedure to account */
76929 const char * p_name; /* name of procedure */
76930-};
76931+} __do_const;
76932
76933 #ifdef __KERNEL__
76934
76935diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
76936index 1f0216b..6a4fa50 100644
76937--- a/include/linux/sunrpc/svc.h
76938+++ b/include/linux/sunrpc/svc.h
76939@@ -411,7 +411,7 @@ struct svc_procedure {
76940 unsigned int pc_count; /* call count */
76941 unsigned int pc_cachetype; /* cache info (NFS) */
76942 unsigned int pc_xdrressize; /* maximum size of XDR reply */
76943-};
76944+} __do_const;
76945
76946 /*
76947 * Function prototypes.
76948diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
76949index 0b8e3e6..33e0a01 100644
76950--- a/include/linux/sunrpc/svc_rdma.h
76951+++ b/include/linux/sunrpc/svc_rdma.h
76952@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
76953 extern unsigned int svcrdma_max_requests;
76954 extern unsigned int svcrdma_max_req_size;
76955
76956-extern atomic_t rdma_stat_recv;
76957-extern atomic_t rdma_stat_read;
76958-extern atomic_t rdma_stat_write;
76959-extern atomic_t rdma_stat_sq_starve;
76960-extern atomic_t rdma_stat_rq_starve;
76961-extern atomic_t rdma_stat_rq_poll;
76962-extern atomic_t rdma_stat_rq_prod;
76963-extern atomic_t rdma_stat_sq_poll;
76964-extern atomic_t rdma_stat_sq_prod;
76965+extern atomic_unchecked_t rdma_stat_recv;
76966+extern atomic_unchecked_t rdma_stat_read;
76967+extern atomic_unchecked_t rdma_stat_write;
76968+extern atomic_unchecked_t rdma_stat_sq_starve;
76969+extern atomic_unchecked_t rdma_stat_rq_starve;
76970+extern atomic_unchecked_t rdma_stat_rq_poll;
76971+extern atomic_unchecked_t rdma_stat_rq_prod;
76972+extern atomic_unchecked_t rdma_stat_sq_poll;
76973+extern atomic_unchecked_t rdma_stat_sq_prod;
76974
76975 #define RPCRDMA_VERSION 1
76976
76977diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
76978index 8d71d65..f79586e 100644
76979--- a/include/linux/sunrpc/svcauth.h
76980+++ b/include/linux/sunrpc/svcauth.h
76981@@ -120,7 +120,7 @@ struct auth_ops {
76982 int (*release)(struct svc_rqst *rq);
76983 void (*domain_release)(struct auth_domain *);
76984 int (*set_client)(struct svc_rqst *rq);
76985-};
76986+} __do_const;
76987
76988 #define SVC_GARBAGE 1
76989 #define SVC_SYSERR 2
76990diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
76991index a5ffd32..0935dea 100644
76992--- a/include/linux/swiotlb.h
76993+++ b/include/linux/swiotlb.h
76994@@ -60,7 +60,8 @@ extern void
76995
76996 extern void
76997 swiotlb_free_coherent(struct device *hwdev, size_t size,
76998- void *vaddr, dma_addr_t dma_handle);
76999+ void *vaddr, dma_addr_t dma_handle,
77000+ struct dma_attrs *attrs);
77001
77002 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
77003 unsigned long offset, size_t size,
77004diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
77005index 84662ec..5271947 100644
77006--- a/include/linux/syscalls.h
77007+++ b/include/linux/syscalls.h
77008@@ -97,8 +97,14 @@ struct sigaltstack;
77009 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
77010
77011 #define __SC_DECL(t, a) t a
77012+#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))
77013 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
77014-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
77015+#define __SC_LONG(t, a) __typeof( \
77016+ __builtin_choose_expr( \
77017+ sizeof(t) > sizeof(int), \
77018+ (t) 0, \
77019+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
77020+ )) a
77021 #define __SC_CAST(t, a) (t) a
77022 #define __SC_ARGS(t, a) a
77023 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
77024@@ -362,11 +368,11 @@ asmlinkage long sys_sync(void);
77025 asmlinkage long sys_fsync(unsigned int fd);
77026 asmlinkage long sys_fdatasync(unsigned int fd);
77027 asmlinkage long sys_bdflush(int func, long data);
77028-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
77029- char __user *type, unsigned long flags,
77030+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
77031+ const char __user *type, unsigned long flags,
77032 void __user *data);
77033-asmlinkage long sys_umount(char __user *name, int flags);
77034-asmlinkage long sys_oldumount(char __user *name);
77035+asmlinkage long sys_umount(const char __user *name, int flags);
77036+asmlinkage long sys_oldumount(const char __user *name);
77037 asmlinkage long sys_truncate(const char __user *path, long length);
77038 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
77039 asmlinkage long sys_stat(const char __user *filename,
77040@@ -578,7 +584,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
77041 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
77042 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
77043 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
77044- struct sockaddr __user *, int);
77045+ struct sockaddr __user *, int) __intentional_overflow(0);
77046 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
77047 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
77048 unsigned int vlen, unsigned flags);
77049diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
77050index 27b3b0b..e093dd9 100644
77051--- a/include/linux/syscore_ops.h
77052+++ b/include/linux/syscore_ops.h
77053@@ -16,7 +16,7 @@ struct syscore_ops {
77054 int (*suspend)(void);
77055 void (*resume)(void);
77056 void (*shutdown)(void);
77057-};
77058+} __do_const;
77059
77060 extern void register_syscore_ops(struct syscore_ops *ops);
77061 extern void unregister_syscore_ops(struct syscore_ops *ops);
77062diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
77063index 14a8ff2..af52bad 100644
77064--- a/include/linux/sysctl.h
77065+++ b/include/linux/sysctl.h
77066@@ -34,13 +34,13 @@ struct ctl_table_root;
77067 struct ctl_table_header;
77068 struct ctl_dir;
77069
77070-typedef struct ctl_table ctl_table;
77071-
77072 typedef int proc_handler (struct ctl_table *ctl, int write,
77073 void __user *buffer, size_t *lenp, loff_t *ppos);
77074
77075 extern int proc_dostring(struct ctl_table *, int,
77076 void __user *, size_t *, loff_t *);
77077+extern int proc_dostring_modpriv(struct ctl_table *, int,
77078+ void __user *, size_t *, loff_t *);
77079 extern int proc_dointvec(struct ctl_table *, int,
77080 void __user *, size_t *, loff_t *);
77081 extern int proc_dointvec_minmax(struct ctl_table *, int,
77082@@ -115,7 +115,9 @@ struct ctl_table
77083 struct ctl_table_poll *poll;
77084 void *extra1;
77085 void *extra2;
77086-};
77087+} __do_const;
77088+typedef struct ctl_table __no_const ctl_table_no_const;
77089+typedef struct ctl_table ctl_table;
77090
77091 struct ctl_node {
77092 struct rb_node node;
77093diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
77094index 9e8a9b5..753de68 100644
77095--- a/include/linux/sysfs.h
77096+++ b/include/linux/sysfs.h
77097@@ -33,7 +33,8 @@ struct attribute {
77098 struct lock_class_key *key;
77099 struct lock_class_key skey;
77100 #endif
77101-};
77102+} __do_const;
77103+typedef struct attribute __no_const attribute_no_const;
77104
77105 /**
77106 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
77107@@ -62,7 +63,8 @@ struct attribute_group {
77108 struct attribute *, int);
77109 struct attribute **attrs;
77110 struct bin_attribute **bin_attrs;
77111-};
77112+} __do_const;
77113+typedef struct attribute_group __no_const attribute_group_no_const;
77114
77115 /**
77116 * Use these macros to make defining attributes easier. See include/linux/device.h
77117@@ -123,7 +125,8 @@ struct bin_attribute {
77118 char *, loff_t, size_t);
77119 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
77120 struct vm_area_struct *vma);
77121-};
77122+} __do_const;
77123+typedef struct bin_attribute __no_const bin_attribute_no_const;
77124
77125 /**
77126 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
77127diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
77128index 7faf933..9b85a0c 100644
77129--- a/include/linux/sysrq.h
77130+++ b/include/linux/sysrq.h
77131@@ -16,6 +16,7 @@
77132
77133 #include <linux/errno.h>
77134 #include <linux/types.h>
77135+#include <linux/compiler.h>
77136
77137 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
77138 #define SYSRQ_DEFAULT_ENABLE 1
77139@@ -36,7 +37,7 @@ struct sysrq_key_op {
77140 char *help_msg;
77141 char *action_msg;
77142 int enable_mask;
77143-};
77144+} __do_const;
77145
77146 #ifdef CONFIG_MAGIC_SYSRQ
77147
77148diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
77149index e7e0473..7989295 100644
77150--- a/include/linux/thread_info.h
77151+++ b/include/linux/thread_info.h
77152@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
77153 #error "no set_restore_sigmask() provided and default one won't work"
77154 #endif
77155
77156+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
77157+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
77158+{
77159+#ifndef CONFIG_PAX_USERCOPY_DEBUG
77160+ if (!__builtin_constant_p(n))
77161+#endif
77162+ __check_object_size(ptr, n, to_user);
77163+}
77164+
77165 #endif /* __KERNEL__ */
77166
77167 #endif /* _LINUX_THREAD_INFO_H */
77168diff --git a/include/linux/tty.h b/include/linux/tty.h
77169index 01ac30e..bf18a71 100644
77170--- a/include/linux/tty.h
77171+++ b/include/linux/tty.h
77172@@ -194,7 +194,7 @@ struct tty_port {
77173 const struct tty_port_operations *ops; /* Port operations */
77174 spinlock_t lock; /* Lock protecting tty field */
77175 int blocked_open; /* Waiting to open */
77176- int count; /* Usage count */
77177+ atomic_t count; /* Usage count */
77178 wait_queue_head_t open_wait; /* Open waiters */
77179 wait_queue_head_t close_wait; /* Close waiters */
77180 wait_queue_head_t delta_msr_wait; /* Modem status change */
77181@@ -547,7 +547,7 @@ extern int tty_port_open(struct tty_port *port,
77182 struct tty_struct *tty, struct file *filp);
77183 static inline int tty_port_users(struct tty_port *port)
77184 {
77185- return port->count + port->blocked_open;
77186+ return atomic_read(&port->count) + port->blocked_open;
77187 }
77188
77189 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
77190diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
77191index 756a609..b302dd6 100644
77192--- a/include/linux/tty_driver.h
77193+++ b/include/linux/tty_driver.h
77194@@ -285,7 +285,7 @@ struct tty_operations {
77195 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
77196 #endif
77197 const struct file_operations *proc_fops;
77198-};
77199+} __do_const;
77200
77201 struct tty_driver {
77202 int magic; /* magic number for this structure */
77203diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
77204index a1b0489..f02e17c 100644
77205--- a/include/linux/tty_ldisc.h
77206+++ b/include/linux/tty_ldisc.h
77207@@ -198,7 +198,7 @@ struct tty_ldisc_ops {
77208
77209 struct module *owner;
77210
77211- int refcount;
77212+ atomic_t refcount;
77213 };
77214
77215 struct tty_ldisc {
77216diff --git a/include/linux/types.h b/include/linux/types.h
77217index 4d118ba..c3ee9bf 100644
77218--- a/include/linux/types.h
77219+++ b/include/linux/types.h
77220@@ -176,10 +176,26 @@ typedef struct {
77221 int counter;
77222 } atomic_t;
77223
77224+#ifdef CONFIG_PAX_REFCOUNT
77225+typedef struct {
77226+ int counter;
77227+} atomic_unchecked_t;
77228+#else
77229+typedef atomic_t atomic_unchecked_t;
77230+#endif
77231+
77232 #ifdef CONFIG_64BIT
77233 typedef struct {
77234 long counter;
77235 } atomic64_t;
77236+
77237+#ifdef CONFIG_PAX_REFCOUNT
77238+typedef struct {
77239+ long counter;
77240+} atomic64_unchecked_t;
77241+#else
77242+typedef atomic64_t atomic64_unchecked_t;
77243+#endif
77244 #endif
77245
77246 struct list_head {
77247diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
77248index 5ca0951..ab496a5 100644
77249--- a/include/linux/uaccess.h
77250+++ b/include/linux/uaccess.h
77251@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
77252 long ret; \
77253 mm_segment_t old_fs = get_fs(); \
77254 \
77255- set_fs(KERNEL_DS); \
77256 pagefault_disable(); \
77257- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
77258- pagefault_enable(); \
77259+ set_fs(KERNEL_DS); \
77260+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
77261 set_fs(old_fs); \
77262+ pagefault_enable(); \
77263 ret; \
77264 })
77265
77266diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
77267index 8e522cbc..aa8572d 100644
77268--- a/include/linux/uidgid.h
77269+++ b/include/linux/uidgid.h
77270@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
77271
77272 #endif /* CONFIG_USER_NS */
77273
77274+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
77275+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
77276+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
77277+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
77278+
77279 #endif /* _LINUX_UIDGID_H */
77280diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
77281index 99c1b4d..562e6f3 100644
77282--- a/include/linux/unaligned/access_ok.h
77283+++ b/include/linux/unaligned/access_ok.h
77284@@ -4,34 +4,34 @@
77285 #include <linux/kernel.h>
77286 #include <asm/byteorder.h>
77287
77288-static inline u16 get_unaligned_le16(const void *p)
77289+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
77290 {
77291- return le16_to_cpup((__le16 *)p);
77292+ return le16_to_cpup((const __le16 *)p);
77293 }
77294
77295-static inline u32 get_unaligned_le32(const void *p)
77296+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
77297 {
77298- return le32_to_cpup((__le32 *)p);
77299+ return le32_to_cpup((const __le32 *)p);
77300 }
77301
77302-static inline u64 get_unaligned_le64(const void *p)
77303+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
77304 {
77305- return le64_to_cpup((__le64 *)p);
77306+ return le64_to_cpup((const __le64 *)p);
77307 }
77308
77309-static inline u16 get_unaligned_be16(const void *p)
77310+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
77311 {
77312- return be16_to_cpup((__be16 *)p);
77313+ return be16_to_cpup((const __be16 *)p);
77314 }
77315
77316-static inline u32 get_unaligned_be32(const void *p)
77317+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
77318 {
77319- return be32_to_cpup((__be32 *)p);
77320+ return be32_to_cpup((const __be32 *)p);
77321 }
77322
77323-static inline u64 get_unaligned_be64(const void *p)
77324+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
77325 {
77326- return be64_to_cpup((__be64 *)p);
77327+ return be64_to_cpup((const __be64 *)p);
77328 }
77329
77330 static inline void put_unaligned_le16(u16 val, void *p)
77331diff --git a/include/linux/usb.h b/include/linux/usb.h
77332index 0eec268..4496526 100644
77333--- a/include/linux/usb.h
77334+++ b/include/linux/usb.h
77335@@ -560,7 +560,7 @@ struct usb_device {
77336 int maxchild;
77337
77338 u32 quirks;
77339- atomic_t urbnum;
77340+ atomic_unchecked_t urbnum;
77341
77342 unsigned long active_duration;
77343
77344@@ -1617,7 +1617,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
77345
77346 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
77347 __u8 request, __u8 requesttype, __u16 value, __u16 index,
77348- void *data, __u16 size, int timeout);
77349+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
77350 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
77351 void *data, int len, int *actual_length, int timeout);
77352 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
77353diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
77354index e452ba6..78f8e80 100644
77355--- a/include/linux/usb/renesas_usbhs.h
77356+++ b/include/linux/usb/renesas_usbhs.h
77357@@ -39,7 +39,7 @@ enum {
77358 */
77359 struct renesas_usbhs_driver_callback {
77360 int (*notify_hotplug)(struct platform_device *pdev);
77361-};
77362+} __no_const;
77363
77364 /*
77365 * callback functions for platform
77366diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
77367index 6f8fbcf..8259001 100644
77368--- a/include/linux/vermagic.h
77369+++ b/include/linux/vermagic.h
77370@@ -25,9 +25,35 @@
77371 #define MODULE_ARCH_VERMAGIC ""
77372 #endif
77373
77374+#ifdef CONFIG_PAX_REFCOUNT
77375+#define MODULE_PAX_REFCOUNT "REFCOUNT "
77376+#else
77377+#define MODULE_PAX_REFCOUNT ""
77378+#endif
77379+
77380+#ifdef CONSTIFY_PLUGIN
77381+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
77382+#else
77383+#define MODULE_CONSTIFY_PLUGIN ""
77384+#endif
77385+
77386+#ifdef STACKLEAK_PLUGIN
77387+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
77388+#else
77389+#define MODULE_STACKLEAK_PLUGIN ""
77390+#endif
77391+
77392+#ifdef CONFIG_GRKERNSEC
77393+#define MODULE_GRSEC "GRSEC "
77394+#else
77395+#define MODULE_GRSEC ""
77396+#endif
77397+
77398 #define VERMAGIC_STRING \
77399 UTS_RELEASE " " \
77400 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
77401 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
77402- MODULE_ARCH_VERMAGIC
77403+ MODULE_ARCH_VERMAGIC \
77404+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
77405+ MODULE_GRSEC
77406
77407diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
77408index 4b8a891..c20e936 100644
77409--- a/include/linux/vmalloc.h
77410+++ b/include/linux/vmalloc.h
77411@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
77412 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
77413 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
77414 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
77415+
77416+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
77417+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
77418+#endif
77419+
77420 /* bits [20..32] reserved for arch specific ioremap internals */
77421
77422 /*
77423@@ -75,7 +80,7 @@ extern void *vmalloc_32_user(unsigned long size);
77424 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
77425 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
77426 unsigned long start, unsigned long end, gfp_t gfp_mask,
77427- pgprot_t prot, int node, const void *caller);
77428+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
77429 extern void vfree(const void *addr);
77430
77431 extern void *vmap(struct page **pages, unsigned int count,
77432@@ -141,8 +146,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
77433 extern void free_vm_area(struct vm_struct *area);
77434
77435 /* for /dev/kmem */
77436-extern long vread(char *buf, char *addr, unsigned long count);
77437-extern long vwrite(char *buf, char *addr, unsigned long count);
77438+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
77439+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
77440
77441 /*
77442 * Internals. Dont't use..
77443diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
77444index c586679..f06b389 100644
77445--- a/include/linux/vmstat.h
77446+++ b/include/linux/vmstat.h
77447@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
77448 /*
77449 * Zone based page accounting with per cpu differentials.
77450 */
77451-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77452+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77453
77454 static inline void zone_page_state_add(long x, struct zone *zone,
77455 enum zone_stat_item item)
77456 {
77457- atomic_long_add(x, &zone->vm_stat[item]);
77458- atomic_long_add(x, &vm_stat[item]);
77459+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
77460+ atomic_long_add_unchecked(x, &vm_stat[item]);
77461 }
77462
77463 static inline unsigned long global_page_state(enum zone_stat_item item)
77464 {
77465- long x = atomic_long_read(&vm_stat[item]);
77466+ long x = atomic_long_read_unchecked(&vm_stat[item]);
77467 #ifdef CONFIG_SMP
77468 if (x < 0)
77469 x = 0;
77470@@ -112,7 +112,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
77471 static inline unsigned long zone_page_state(struct zone *zone,
77472 enum zone_stat_item item)
77473 {
77474- long x = atomic_long_read(&zone->vm_stat[item]);
77475+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77476 #ifdef CONFIG_SMP
77477 if (x < 0)
77478 x = 0;
77479@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
77480 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
77481 enum zone_stat_item item)
77482 {
77483- long x = atomic_long_read(&zone->vm_stat[item]);
77484+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77485
77486 #ifdef CONFIG_SMP
77487 int cpu;
77488@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
77489
77490 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
77491 {
77492- atomic_long_inc(&zone->vm_stat[item]);
77493- atomic_long_inc(&vm_stat[item]);
77494+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
77495+ atomic_long_inc_unchecked(&vm_stat[item]);
77496 }
77497
77498 static inline void __inc_zone_page_state(struct page *page,
77499@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
77500
77501 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
77502 {
77503- atomic_long_dec(&zone->vm_stat[item]);
77504- atomic_long_dec(&vm_stat[item]);
77505+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
77506+ atomic_long_dec_unchecked(&vm_stat[item]);
77507 }
77508
77509 static inline void __dec_zone_page_state(struct page *page,
77510diff --git a/include/linux/xattr.h b/include/linux/xattr.h
77511index fdbafc6..49dfe4f 100644
77512--- a/include/linux/xattr.h
77513+++ b/include/linux/xattr.h
77514@@ -28,7 +28,7 @@ struct xattr_handler {
77515 size_t size, int handler_flags);
77516 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
77517 size_t size, int flags, int handler_flags);
77518-};
77519+} __do_const;
77520
77521 struct xattr {
77522 char *name;
77523@@ -37,6 +37,9 @@ struct xattr {
77524 };
77525
77526 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
77527+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77528+ssize_t pax_getxattr(struct dentry *, void *, size_t);
77529+#endif
77530 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
77531 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
77532 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
77533diff --git a/include/linux/zlib.h b/include/linux/zlib.h
77534index 9c5a6b4..09c9438 100644
77535--- a/include/linux/zlib.h
77536+++ b/include/linux/zlib.h
77537@@ -31,6 +31,7 @@
77538 #define _ZLIB_H
77539
77540 #include <linux/zconf.h>
77541+#include <linux/compiler.h>
77542
77543 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
77544 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
77545@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
77546
77547 /* basic functions */
77548
77549-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
77550+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
77551 /*
77552 Returns the number of bytes that needs to be allocated for a per-
77553 stream workspace with the specified parameters. A pointer to this
77554diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
77555index c768c9f..bdcaa5a 100644
77556--- a/include/media/v4l2-dev.h
77557+++ b/include/media/v4l2-dev.h
77558@@ -76,7 +76,7 @@ struct v4l2_file_operations {
77559 int (*mmap) (struct file *, struct vm_area_struct *);
77560 int (*open) (struct file *);
77561 int (*release) (struct file *);
77562-};
77563+} __do_const;
77564
77565 /*
77566 * Newer version of video_device, handled by videodev2.c
77567diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
77568index c9b1593..a572459 100644
77569--- a/include/media/v4l2-device.h
77570+++ b/include/media/v4l2-device.h
77571@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
77572 this function returns 0. If the name ends with a digit (e.g. cx18),
77573 then the name will be set to cx18-0 since cx180 looks really odd. */
77574 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
77575- atomic_t *instance);
77576+ atomic_unchecked_t *instance);
77577
77578 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
77579 Since the parent disappears this ensures that v4l2_dev doesn't have an
77580diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
77581index d9fa68f..45c88d1 100644
77582--- a/include/net/9p/transport.h
77583+++ b/include/net/9p/transport.h
77584@@ -63,7 +63,7 @@ struct p9_trans_module {
77585 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
77586 int (*zc_request)(struct p9_client *, struct p9_req_t *,
77587 char *, char *, int , int, int, int);
77588-};
77589+} __do_const;
77590
77591 void v9fs_register_trans(struct p9_trans_module *m);
77592 void v9fs_unregister_trans(struct p9_trans_module *m);
77593diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
77594index 1a966af..2767cf6 100644
77595--- a/include/net/bluetooth/l2cap.h
77596+++ b/include/net/bluetooth/l2cap.h
77597@@ -551,7 +551,7 @@ struct l2cap_ops {
77598 void (*defer) (struct l2cap_chan *chan);
77599 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
77600 unsigned long len, int nb);
77601-};
77602+} __do_const;
77603
77604 struct l2cap_conn {
77605 struct hci_conn *hcon;
77606diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
77607index f2ae33d..c457cf0 100644
77608--- a/include/net/caif/cfctrl.h
77609+++ b/include/net/caif/cfctrl.h
77610@@ -52,7 +52,7 @@ struct cfctrl_rsp {
77611 void (*radioset_rsp)(void);
77612 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
77613 struct cflayer *client_layer);
77614-};
77615+} __no_const;
77616
77617 /* Link Setup Parameters for CAIF-Links. */
77618 struct cfctrl_link_param {
77619@@ -101,8 +101,8 @@ struct cfctrl_request_info {
77620 struct cfctrl {
77621 struct cfsrvl serv;
77622 struct cfctrl_rsp res;
77623- atomic_t req_seq_no;
77624- atomic_t rsp_seq_no;
77625+ atomic_unchecked_t req_seq_no;
77626+ atomic_unchecked_t rsp_seq_no;
77627 struct list_head list;
77628 /* Protects from simultaneous access to first_req list */
77629 spinlock_t info_list_lock;
77630diff --git a/include/net/flow.h b/include/net/flow.h
77631index 628e11b..4c475df 100644
77632--- a/include/net/flow.h
77633+++ b/include/net/flow.h
77634@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
77635
77636 extern void flow_cache_flush(void);
77637 extern void flow_cache_flush_deferred(void);
77638-extern atomic_t flow_cache_genid;
77639+extern atomic_unchecked_t flow_cache_genid;
77640
77641 #endif
77642diff --git a/include/net/genetlink.h b/include/net/genetlink.h
77643index 8e0b6c8..73cf605 100644
77644--- a/include/net/genetlink.h
77645+++ b/include/net/genetlink.h
77646@@ -120,7 +120,7 @@ struct genl_ops {
77647 struct netlink_callback *cb);
77648 int (*done)(struct netlink_callback *cb);
77649 struct list_head ops_list;
77650-};
77651+} __do_const;
77652
77653 extern int __genl_register_family(struct genl_family *family);
77654
77655diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
77656index 734d9b5..48a9a4b 100644
77657--- a/include/net/gro_cells.h
77658+++ b/include/net/gro_cells.h
77659@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
77660 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
77661
77662 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
77663- atomic_long_inc(&dev->rx_dropped);
77664+ atomic_long_inc_unchecked(&dev->rx_dropped);
77665 kfree_skb(skb);
77666 return;
77667 }
77668diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
77669index de2c785..0588a6b 100644
77670--- a/include/net/inet_connection_sock.h
77671+++ b/include/net/inet_connection_sock.h
77672@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
77673 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
77674 int (*bind_conflict)(const struct sock *sk,
77675 const struct inet_bind_bucket *tb, bool relax);
77676-};
77677+} __do_const;
77678
77679 /** inet_connection_sock - INET connection oriented sock
77680 *
77681diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
77682index 53f464d..0bd0b49 100644
77683--- a/include/net/inetpeer.h
77684+++ b/include/net/inetpeer.h
77685@@ -47,8 +47,8 @@ struct inet_peer {
77686 */
77687 union {
77688 struct {
77689- atomic_t rid; /* Frag reception counter */
77690- atomic_t ip_id_count; /* IP ID for the next packet */
77691+ atomic_unchecked_t rid; /* Frag reception counter */
77692+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
77693 };
77694 struct rcu_head rcu;
77695 struct inet_peer *gc_next;
77696@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
77697 /* can be called with or without local BH being disabled */
77698 static inline int inet_getid(struct inet_peer *p, int more)
77699 {
77700- int old, new;
77701+ int id;
77702 more++;
77703 inet_peer_refcheck(p);
77704- do {
77705- old = atomic_read(&p->ip_id_count);
77706- new = old + more;
77707- if (!new)
77708- new = 1;
77709- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
77710- return new;
77711+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
77712+ if (!id)
77713+ id = atomic_inc_return_unchecked(&p->ip_id_count);
77714+ return id;
77715 }
77716
77717 #endif /* _NET_INETPEER_H */
77718diff --git a/include/net/ip.h b/include/net/ip.h
77719index a68f838..74518ab 100644
77720--- a/include/net/ip.h
77721+++ b/include/net/ip.h
77722@@ -202,7 +202,7 @@ extern struct local_ports {
77723 } sysctl_local_ports;
77724 extern void inet_get_local_port_range(int *low, int *high);
77725
77726-extern unsigned long *sysctl_local_reserved_ports;
77727+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
77728 static inline int inet_is_reserved_local_port(int port)
77729 {
77730 return test_bit(port, sysctl_local_reserved_ports);
77731diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
77732index cbf2be3..3683f6d 100644
77733--- a/include/net/ip_fib.h
77734+++ b/include/net/ip_fib.h
77735@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
77736
77737 #define FIB_RES_SADDR(net, res) \
77738 ((FIB_RES_NH(res).nh_saddr_genid == \
77739- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
77740+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
77741 FIB_RES_NH(res).nh_saddr : \
77742 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
77743 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
77744diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
77745index f0d70f0..185f15b 100644
77746--- a/include/net/ip_vs.h
77747+++ b/include/net/ip_vs.h
77748@@ -588,7 +588,7 @@ struct ip_vs_conn {
77749 struct ip_vs_conn *control; /* Master control connection */
77750 atomic_t n_control; /* Number of controlled ones */
77751 struct ip_vs_dest *dest; /* real server */
77752- atomic_t in_pkts; /* incoming packet counter */
77753+ atomic_unchecked_t in_pkts; /* incoming packet counter */
77754
77755 /* packet transmitter for different forwarding methods. If it
77756 mangles the packet, it must return NF_DROP or better NF_STOLEN,
77757@@ -737,7 +737,7 @@ struct ip_vs_dest {
77758 __be16 port; /* port number of the server */
77759 union nf_inet_addr addr; /* IP address of the server */
77760 volatile unsigned int flags; /* dest status flags */
77761- atomic_t conn_flags; /* flags to copy to conn */
77762+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
77763 atomic_t weight; /* server weight */
77764
77765 atomic_t refcnt; /* reference counter */
77766@@ -993,11 +993,11 @@ struct netns_ipvs {
77767 /* ip_vs_lblc */
77768 int sysctl_lblc_expiration;
77769 struct ctl_table_header *lblc_ctl_header;
77770- struct ctl_table *lblc_ctl_table;
77771+ ctl_table_no_const *lblc_ctl_table;
77772 /* ip_vs_lblcr */
77773 int sysctl_lblcr_expiration;
77774 struct ctl_table_header *lblcr_ctl_header;
77775- struct ctl_table *lblcr_ctl_table;
77776+ ctl_table_no_const *lblcr_ctl_table;
77777 /* ip_vs_est */
77778 struct list_head est_list; /* estimator list */
77779 spinlock_t est_lock;
77780diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
77781index 80ffde3..968b0f4 100644
77782--- a/include/net/irda/ircomm_tty.h
77783+++ b/include/net/irda/ircomm_tty.h
77784@@ -35,6 +35,7 @@
77785 #include <linux/termios.h>
77786 #include <linux/timer.h>
77787 #include <linux/tty.h> /* struct tty_struct */
77788+#include <asm/local.h>
77789
77790 #include <net/irda/irias_object.h>
77791 #include <net/irda/ircomm_core.h>
77792diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
77793index 714cc9a..ea05f3e 100644
77794--- a/include/net/iucv/af_iucv.h
77795+++ b/include/net/iucv/af_iucv.h
77796@@ -149,7 +149,7 @@ struct iucv_skb_cb {
77797 struct iucv_sock_list {
77798 struct hlist_head head;
77799 rwlock_t lock;
77800- atomic_t autobind_name;
77801+ atomic_unchecked_t autobind_name;
77802 };
77803
77804 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
77805diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
77806index df83f69..9b640b8 100644
77807--- a/include/net/llc_c_ac.h
77808+++ b/include/net/llc_c_ac.h
77809@@ -87,7 +87,7 @@
77810 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
77811 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
77812
77813-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77814+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77815
77816 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
77817 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
77818diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
77819index 6ca3113..f8026dd 100644
77820--- a/include/net/llc_c_ev.h
77821+++ b/include/net/llc_c_ev.h
77822@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
77823 return (struct llc_conn_state_ev *)skb->cb;
77824 }
77825
77826-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77827-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77828+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77829+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77830
77831 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
77832 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
77833diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
77834index 0e79cfb..f46db31 100644
77835--- a/include/net/llc_c_st.h
77836+++ b/include/net/llc_c_st.h
77837@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
77838 u8 next_state;
77839 llc_conn_ev_qfyr_t *ev_qualifiers;
77840 llc_conn_action_t *ev_actions;
77841-};
77842+} __do_const;
77843
77844 struct llc_conn_state {
77845 u8 current_state;
77846diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
77847index 37a3bbd..55a4241 100644
77848--- a/include/net/llc_s_ac.h
77849+++ b/include/net/llc_s_ac.h
77850@@ -23,7 +23,7 @@
77851 #define SAP_ACT_TEST_IND 9
77852
77853 /* All action functions must look like this */
77854-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
77855+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
77856
77857 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
77858 struct sk_buff *skb);
77859diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
77860index 567c681..cd73ac0 100644
77861--- a/include/net/llc_s_st.h
77862+++ b/include/net/llc_s_st.h
77863@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
77864 llc_sap_ev_t ev;
77865 u8 next_state;
77866 llc_sap_action_t *ev_actions;
77867-};
77868+} __do_const;
77869
77870 struct llc_sap_state {
77871 u8 curr_state;
77872diff --git a/include/net/mac80211.h b/include/net/mac80211.h
77873index 551ba6a..11c99c1 100644
77874--- a/include/net/mac80211.h
77875+++ b/include/net/mac80211.h
77876@@ -4221,7 +4221,7 @@ struct rate_control_ops {
77877 void (*add_sta_debugfs)(void *priv, void *priv_sta,
77878 struct dentry *dir);
77879 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
77880-};
77881+} __do_const;
77882
77883 static inline int rate_supported(struct ieee80211_sta *sta,
77884 enum ieee80211_band band,
77885diff --git a/include/net/neighbour.h b/include/net/neighbour.h
77886index 7e748ad..5c6229b 100644
77887--- a/include/net/neighbour.h
77888+++ b/include/net/neighbour.h
77889@@ -123,7 +123,7 @@ struct neigh_ops {
77890 void (*error_report)(struct neighbour *, struct sk_buff *);
77891 int (*output)(struct neighbour *, struct sk_buff *);
77892 int (*connected_output)(struct neighbour *, struct sk_buff *);
77893-};
77894+} __do_const;
77895
77896 struct pneigh_entry {
77897 struct pneigh_entry *next;
77898diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
77899index 84e37b1..8eba19a 100644
77900--- a/include/net/net_namespace.h
77901+++ b/include/net/net_namespace.h
77902@@ -119,8 +119,8 @@ struct net {
77903 struct netns_ipvs *ipvs;
77904 #endif
77905 struct sock *diag_nlsk;
77906- atomic_t rt_genid;
77907- atomic_t fnhe_genid;
77908+ atomic_unchecked_t rt_genid;
77909+ atomic_unchecked_t fnhe_genid;
77910 };
77911
77912 /*
77913@@ -277,7 +277,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
77914 #define __net_init __init
77915 #define __net_exit __exit_refok
77916 #define __net_initdata __initdata
77917+#ifdef CONSTIFY_PLUGIN
77918 #define __net_initconst __initconst
77919+#else
77920+#define __net_initconst __initdata
77921+#endif
77922 #endif
77923
77924 struct pernet_operations {
77925@@ -287,7 +291,7 @@ struct pernet_operations {
77926 void (*exit_batch)(struct list_head *net_exit_list);
77927 int *id;
77928 size_t size;
77929-};
77930+} __do_const;
77931
77932 /*
77933 * Use these carefully. If you implement a network device and it
77934@@ -335,22 +339,22 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
77935
77936 static inline int rt_genid(struct net *net)
77937 {
77938- return atomic_read(&net->rt_genid);
77939+ return atomic_read_unchecked(&net->rt_genid);
77940 }
77941
77942 static inline void rt_genid_bump(struct net *net)
77943 {
77944- atomic_inc(&net->rt_genid);
77945+ atomic_inc_unchecked(&net->rt_genid);
77946 }
77947
77948 static inline int fnhe_genid(struct net *net)
77949 {
77950- return atomic_read(&net->fnhe_genid);
77951+ return atomic_read_unchecked(&net->fnhe_genid);
77952 }
77953
77954 static inline void fnhe_genid_bump(struct net *net)
77955 {
77956- atomic_inc(&net->fnhe_genid);
77957+ atomic_inc_unchecked(&net->fnhe_genid);
77958 }
77959
77960 #endif /* __NET_NET_NAMESPACE_H */
77961diff --git a/include/net/netdma.h b/include/net/netdma.h
77962index 8ba8ce2..99b7fff 100644
77963--- a/include/net/netdma.h
77964+++ b/include/net/netdma.h
77965@@ -24,7 +24,7 @@
77966 #include <linux/dmaengine.h>
77967 #include <linux/skbuff.h>
77968
77969-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
77970+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
77971 struct sk_buff *skb, int offset, struct iovec *to,
77972 size_t len, struct dma_pinned_list *pinned_list);
77973
77974diff --git a/include/net/netlink.h b/include/net/netlink.h
77975index 9690b0f..87aded7 100644
77976--- a/include/net/netlink.h
77977+++ b/include/net/netlink.h
77978@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
77979 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
77980 {
77981 if (mark)
77982- skb_trim(skb, (unsigned char *) mark - skb->data);
77983+ skb_trim(skb, (const unsigned char *) mark - skb->data);
77984 }
77985
77986 /**
77987diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
77988index c9c0c53..53f24c3 100644
77989--- a/include/net/netns/conntrack.h
77990+++ b/include/net/netns/conntrack.h
77991@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
77992 struct nf_proto_net {
77993 #ifdef CONFIG_SYSCTL
77994 struct ctl_table_header *ctl_table_header;
77995- struct ctl_table *ctl_table;
77996+ ctl_table_no_const *ctl_table;
77997 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
77998 struct ctl_table_header *ctl_compat_header;
77999- struct ctl_table *ctl_compat_table;
78000+ ctl_table_no_const *ctl_compat_table;
78001 #endif
78002 #endif
78003 unsigned int users;
78004@@ -58,7 +58,7 @@ struct nf_ip_net {
78005 struct nf_icmp_net icmpv6;
78006 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
78007 struct ctl_table_header *ctl_table_header;
78008- struct ctl_table *ctl_table;
78009+ ctl_table_no_const *ctl_table;
78010 #endif
78011 };
78012
78013diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
78014index 2ba9de8..47bd6c7 100644
78015--- a/include/net/netns/ipv4.h
78016+++ b/include/net/netns/ipv4.h
78017@@ -67,7 +67,7 @@ struct netns_ipv4 {
78018 kgid_t sysctl_ping_group_range[2];
78019 long sysctl_tcp_mem[3];
78020
78021- atomic_t dev_addr_genid;
78022+ atomic_unchecked_t dev_addr_genid;
78023
78024 #ifdef CONFIG_IP_MROUTE
78025 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
78026diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
78027index 005e2c2..023d340 100644
78028--- a/include/net/netns/ipv6.h
78029+++ b/include/net/netns/ipv6.h
78030@@ -71,7 +71,7 @@ struct netns_ipv6 {
78031 struct fib_rules_ops *mr6_rules_ops;
78032 #endif
78033 #endif
78034- atomic_t dev_addr_genid;
78035+ atomic_unchecked_t dev_addr_genid;
78036 };
78037
78038 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
78039diff --git a/include/net/ping.h b/include/net/ping.h
78040index 5db0224..0d65365 100644
78041--- a/include/net/ping.h
78042+++ b/include/net/ping.h
78043@@ -55,7 +55,7 @@ struct ping_iter_state {
78044 extern struct proto ping_prot;
78045 extern struct ping_table ping_table;
78046 #if IS_ENABLED(CONFIG_IPV6)
78047-extern struct pingv6_ops pingv6_ops;
78048+extern struct pingv6_ops *pingv6_ops;
78049 #endif
78050
78051 struct pingfakehdr {
78052diff --git a/include/net/protocol.h b/include/net/protocol.h
78053index 047c047..b9dad15 100644
78054--- a/include/net/protocol.h
78055+++ b/include/net/protocol.h
78056@@ -44,7 +44,7 @@ struct net_protocol {
78057 void (*err_handler)(struct sk_buff *skb, u32 info);
78058 unsigned int no_policy:1,
78059 netns_ok:1;
78060-};
78061+} __do_const;
78062
78063 #if IS_ENABLED(CONFIG_IPV6)
78064 struct inet6_protocol {
78065@@ -57,7 +57,7 @@ struct inet6_protocol {
78066 u8 type, u8 code, int offset,
78067 __be32 info);
78068 unsigned int flags; /* INET6_PROTO_xxx */
78069-};
78070+} __do_const;
78071
78072 #define INET6_PROTO_NOPOLICY 0x1
78073 #define INET6_PROTO_FINAL 0x2
78074diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
78075index 7026648..584cc8c 100644
78076--- a/include/net/rtnetlink.h
78077+++ b/include/net/rtnetlink.h
78078@@ -81,7 +81,7 @@ struct rtnl_link_ops {
78079 const struct net_device *dev);
78080 unsigned int (*get_num_tx_queues)(void);
78081 unsigned int (*get_num_rx_queues)(void);
78082-};
78083+} __do_const;
78084
78085 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
78086 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
78087diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
78088index 2a82d13..62a31c2 100644
78089--- a/include/net/sctp/sm.h
78090+++ b/include/net/sctp/sm.h
78091@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
78092 typedef struct {
78093 sctp_state_fn_t *fn;
78094 const char *name;
78095-} sctp_sm_table_entry_t;
78096+} __do_const sctp_sm_table_entry_t;
78097
78098 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
78099 * currently in use.
78100@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
78101 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
78102
78103 /* Extern declarations for major data structures. */
78104-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
78105+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
78106
78107
78108 /* Get the size of a DATA chunk payload. */
78109diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
78110index e745c92..3641448 100644
78111--- a/include/net/sctp/structs.h
78112+++ b/include/net/sctp/structs.h
78113@@ -516,7 +516,7 @@ struct sctp_pf {
78114 struct sctp_association *asoc);
78115 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
78116 struct sctp_af *af;
78117-};
78118+} __do_const;
78119
78120
78121 /* Structure to track chunk fragments that have been acked, but peer
78122diff --git a/include/net/sock.h b/include/net/sock.h
78123index 31d5cfb..9ee0602 100644
78124--- a/include/net/sock.h
78125+++ b/include/net/sock.h
78126@@ -331,7 +331,7 @@ struct sock {
78127 unsigned int sk_napi_id;
78128 unsigned int sk_ll_usec;
78129 #endif
78130- atomic_t sk_drops;
78131+ atomic_unchecked_t sk_drops;
78132 int sk_rcvbuf;
78133
78134 struct sk_filter __rcu *sk_filter;
78135@@ -1803,7 +1803,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
78136 }
78137
78138 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
78139- char __user *from, char *to,
78140+ char __user *from, unsigned char *to,
78141 int copy, int offset)
78142 {
78143 if (skb->ip_summed == CHECKSUM_NONE) {
78144@@ -2065,7 +2065,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
78145 }
78146 }
78147
78148-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
78149+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
78150
78151 /**
78152 * sk_page_frag - return an appropriate page_frag
78153diff --git a/include/net/tcp.h b/include/net/tcp.h
78154index d198005..c974a393 100644
78155--- a/include/net/tcp.h
78156+++ b/include/net/tcp.h
78157@@ -521,7 +521,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
78158 extern void tcp_xmit_retransmit_queue(struct sock *);
78159 extern void tcp_simple_retransmit(struct sock *);
78160 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
78161-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
78162+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
78163
78164 extern void tcp_send_probe0(struct sock *);
78165 extern void tcp_send_partial(struct sock *);
78166@@ -694,8 +694,8 @@ struct tcp_skb_cb {
78167 struct inet6_skb_parm h6;
78168 #endif
78169 } header; /* For incoming frames */
78170- __u32 seq; /* Starting sequence number */
78171- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
78172+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
78173+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
78174 __u32 when; /* used to compute rtt's */
78175 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
78176
78177@@ -709,7 +709,7 @@ struct tcp_skb_cb {
78178
78179 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
78180 /* 1 byte hole */
78181- __u32 ack_seq; /* Sequence number ACK'd */
78182+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
78183 };
78184
78185 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
78186diff --git a/include/net/xfrm.h b/include/net/xfrm.h
78187index e823786..55bf641 100644
78188--- a/include/net/xfrm.h
78189+++ b/include/net/xfrm.h
78190@@ -305,7 +305,7 @@ struct xfrm_policy_afinfo {
78191 struct net_device *dev,
78192 const struct flowi *fl);
78193 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
78194-};
78195+} __do_const;
78196
78197 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
78198 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
78199@@ -342,7 +342,7 @@ struct xfrm_state_afinfo {
78200 int (*transport_finish)(struct sk_buff *skb,
78201 int async);
78202 void (*local_error)(struct sk_buff *skb, u32 mtu);
78203-};
78204+} __do_const;
78205
78206 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
78207 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
78208@@ -427,7 +427,7 @@ struct xfrm_mode {
78209 struct module *owner;
78210 unsigned int encap;
78211 int flags;
78212-};
78213+} __do_const;
78214
78215 /* Flags for xfrm_mode. */
78216 enum {
78217@@ -524,7 +524,7 @@ struct xfrm_policy {
78218 struct timer_list timer;
78219
78220 struct flow_cache_object flo;
78221- atomic_t genid;
78222+ atomic_unchecked_t genid;
78223 u32 priority;
78224 u32 index;
78225 struct xfrm_mark mark;
78226diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
78227index 1a046b1..ee0bef0 100644
78228--- a/include/rdma/iw_cm.h
78229+++ b/include/rdma/iw_cm.h
78230@@ -122,7 +122,7 @@ struct iw_cm_verbs {
78231 int backlog);
78232
78233 int (*destroy_listen)(struct iw_cm_id *cm_id);
78234-};
78235+} __no_const;
78236
78237 /**
78238 * iw_create_cm_id - Create an IW CM identifier.
78239diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
78240index e1379b4..67eafbe 100644
78241--- a/include/scsi/libfc.h
78242+++ b/include/scsi/libfc.h
78243@@ -762,6 +762,7 @@ struct libfc_function_template {
78244 */
78245 void (*disc_stop_final) (struct fc_lport *);
78246 };
78247+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
78248
78249 /**
78250 * struct fc_disc - Discovery context
78251@@ -866,7 +867,7 @@ struct fc_lport {
78252 struct fc_vport *vport;
78253
78254 /* Operational Information */
78255- struct libfc_function_template tt;
78256+ libfc_function_template_no_const tt;
78257 u8 link_up;
78258 u8 qfull;
78259 enum fc_lport_state state;
78260diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
78261index a44954c..5da04b2 100644
78262--- a/include/scsi/scsi_device.h
78263+++ b/include/scsi/scsi_device.h
78264@@ -172,9 +172,9 @@ struct scsi_device {
78265 unsigned int max_device_blocked; /* what device_blocked counts down from */
78266 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
78267
78268- atomic_t iorequest_cnt;
78269- atomic_t iodone_cnt;
78270- atomic_t ioerr_cnt;
78271+ atomic_unchecked_t iorequest_cnt;
78272+ atomic_unchecked_t iodone_cnt;
78273+ atomic_unchecked_t ioerr_cnt;
78274
78275 struct device sdev_gendev,
78276 sdev_dev;
78277diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
78278index b797e8f..8e2c3aa 100644
78279--- a/include/scsi/scsi_transport_fc.h
78280+++ b/include/scsi/scsi_transport_fc.h
78281@@ -751,7 +751,8 @@ struct fc_function_template {
78282 unsigned long show_host_system_hostname:1;
78283
78284 unsigned long disable_target_scan:1;
78285-};
78286+} __do_const;
78287+typedef struct fc_function_template __no_const fc_function_template_no_const;
78288
78289
78290 /**
78291diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
78292index 9031a26..750d592 100644
78293--- a/include/sound/compress_driver.h
78294+++ b/include/sound/compress_driver.h
78295@@ -128,7 +128,7 @@ struct snd_compr_ops {
78296 struct snd_compr_caps *caps);
78297 int (*get_codec_caps) (struct snd_compr_stream *stream,
78298 struct snd_compr_codec_caps *codec);
78299-};
78300+} __no_const;
78301
78302 /**
78303 * struct snd_compr: Compressed device
78304diff --git a/include/sound/soc.h b/include/sound/soc.h
78305index 6eabee7..58afb50 100644
78306--- a/include/sound/soc.h
78307+++ b/include/sound/soc.h
78308@@ -783,7 +783,7 @@ struct snd_soc_codec_driver {
78309 /* probe ordering - for components with runtime dependencies */
78310 int probe_order;
78311 int remove_order;
78312-};
78313+} __do_const;
78314
78315 /* SoC platform interface */
78316 struct snd_soc_platform_driver {
78317@@ -829,7 +829,7 @@ struct snd_soc_platform_driver {
78318 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
78319 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
78320 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
78321-};
78322+} __do_const;
78323
78324 struct snd_soc_platform {
78325 const char *name;
78326diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
78327index e34fc90..ecefa2c 100644
78328--- a/include/target/target_core_base.h
78329+++ b/include/target/target_core_base.h
78330@@ -643,7 +643,7 @@ struct se_device {
78331 spinlock_t stats_lock;
78332 /* Active commands on this virtual SE device */
78333 atomic_t simple_cmds;
78334- atomic_t dev_ordered_id;
78335+ atomic_unchecked_t dev_ordered_id;
78336 atomic_t dev_ordered_sync;
78337 atomic_t dev_qf_count;
78338 int export_count;
78339diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
78340new file mode 100644
78341index 0000000..fb634b7
78342--- /dev/null
78343+++ b/include/trace/events/fs.h
78344@@ -0,0 +1,53 @@
78345+#undef TRACE_SYSTEM
78346+#define TRACE_SYSTEM fs
78347+
78348+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
78349+#define _TRACE_FS_H
78350+
78351+#include <linux/fs.h>
78352+#include <linux/tracepoint.h>
78353+
78354+TRACE_EVENT(do_sys_open,
78355+
78356+ TP_PROTO(const char *filename, int flags, int mode),
78357+
78358+ TP_ARGS(filename, flags, mode),
78359+
78360+ TP_STRUCT__entry(
78361+ __string( filename, filename )
78362+ __field( int, flags )
78363+ __field( int, mode )
78364+ ),
78365+
78366+ TP_fast_assign(
78367+ __assign_str(filename, filename);
78368+ __entry->flags = flags;
78369+ __entry->mode = mode;
78370+ ),
78371+
78372+ TP_printk("\"%s\" %x %o",
78373+ __get_str(filename), __entry->flags, __entry->mode)
78374+);
78375+
78376+TRACE_EVENT(open_exec,
78377+
78378+ TP_PROTO(const char *filename),
78379+
78380+ TP_ARGS(filename),
78381+
78382+ TP_STRUCT__entry(
78383+ __string( filename, filename )
78384+ ),
78385+
78386+ TP_fast_assign(
78387+ __assign_str(filename, filename);
78388+ ),
78389+
78390+ TP_printk("\"%s\"",
78391+ __get_str(filename))
78392+);
78393+
78394+#endif /* _TRACE_FS_H */
78395+
78396+/* This part must be outside protection */
78397+#include <trace/define_trace.h>
78398diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
78399index 1c09820..7f5ec79 100644
78400--- a/include/trace/events/irq.h
78401+++ b/include/trace/events/irq.h
78402@@ -36,7 +36,7 @@ struct softirq_action;
78403 */
78404 TRACE_EVENT(irq_handler_entry,
78405
78406- TP_PROTO(int irq, struct irqaction *action),
78407+ TP_PROTO(int irq, const struct irqaction *action),
78408
78409 TP_ARGS(irq, action),
78410
78411@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
78412 */
78413 TRACE_EVENT(irq_handler_exit,
78414
78415- TP_PROTO(int irq, struct irqaction *action, int ret),
78416+ TP_PROTO(int irq, const struct irqaction *action, int ret),
78417
78418 TP_ARGS(irq, action, ret),
78419
78420diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
78421index 7caf44c..23c6f27 100644
78422--- a/include/uapi/linux/a.out.h
78423+++ b/include/uapi/linux/a.out.h
78424@@ -39,6 +39,14 @@ enum machine_type {
78425 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
78426 };
78427
78428+/* Constants for the N_FLAGS field */
78429+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78430+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
78431+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
78432+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
78433+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78434+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78435+
78436 #if !defined (N_MAGIC)
78437 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
78438 #endif
78439diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
78440index d876736..ccce5c0 100644
78441--- a/include/uapi/linux/byteorder/little_endian.h
78442+++ b/include/uapi/linux/byteorder/little_endian.h
78443@@ -42,51 +42,51 @@
78444
78445 static inline __le64 __cpu_to_le64p(const __u64 *p)
78446 {
78447- return (__force __le64)*p;
78448+ return (__force const __le64)*p;
78449 }
78450-static inline __u64 __le64_to_cpup(const __le64 *p)
78451+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
78452 {
78453- return (__force __u64)*p;
78454+ return (__force const __u64)*p;
78455 }
78456 static inline __le32 __cpu_to_le32p(const __u32 *p)
78457 {
78458- return (__force __le32)*p;
78459+ return (__force const __le32)*p;
78460 }
78461 static inline __u32 __le32_to_cpup(const __le32 *p)
78462 {
78463- return (__force __u32)*p;
78464+ return (__force const __u32)*p;
78465 }
78466 static inline __le16 __cpu_to_le16p(const __u16 *p)
78467 {
78468- return (__force __le16)*p;
78469+ return (__force const __le16)*p;
78470 }
78471 static inline __u16 __le16_to_cpup(const __le16 *p)
78472 {
78473- return (__force __u16)*p;
78474+ return (__force const __u16)*p;
78475 }
78476 static inline __be64 __cpu_to_be64p(const __u64 *p)
78477 {
78478- return (__force __be64)__swab64p(p);
78479+ return (__force const __be64)__swab64p(p);
78480 }
78481 static inline __u64 __be64_to_cpup(const __be64 *p)
78482 {
78483- return __swab64p((__u64 *)p);
78484+ return __swab64p((const __u64 *)p);
78485 }
78486 static inline __be32 __cpu_to_be32p(const __u32 *p)
78487 {
78488- return (__force __be32)__swab32p(p);
78489+ return (__force const __be32)__swab32p(p);
78490 }
78491-static inline __u32 __be32_to_cpup(const __be32 *p)
78492+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
78493 {
78494- return __swab32p((__u32 *)p);
78495+ return __swab32p((const __u32 *)p);
78496 }
78497 static inline __be16 __cpu_to_be16p(const __u16 *p)
78498 {
78499- return (__force __be16)__swab16p(p);
78500+ return (__force const __be16)__swab16p(p);
78501 }
78502 static inline __u16 __be16_to_cpup(const __be16 *p)
78503 {
78504- return __swab16p((__u16 *)p);
78505+ return __swab16p((const __u16 *)p);
78506 }
78507 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
78508 #define __le64_to_cpus(x) do { (void)(x); } while (0)
78509diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
78510index ef6103b..d4e65dd 100644
78511--- a/include/uapi/linux/elf.h
78512+++ b/include/uapi/linux/elf.h
78513@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
78514 #define PT_GNU_EH_FRAME 0x6474e550
78515
78516 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
78517+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
78518+
78519+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
78520+
78521+/* Constants for the e_flags field */
78522+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78523+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
78524+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
78525+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
78526+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78527+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78528
78529 /*
78530 * Extended Numbering
78531@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
78532 #define DT_DEBUG 21
78533 #define DT_TEXTREL 22
78534 #define DT_JMPREL 23
78535+#define DT_FLAGS 30
78536+ #define DF_TEXTREL 0x00000004
78537 #define DT_ENCODING 32
78538 #define OLD_DT_LOOS 0x60000000
78539 #define DT_LOOS 0x6000000d
78540@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
78541 #define PF_W 0x2
78542 #define PF_X 0x1
78543
78544+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
78545+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
78546+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
78547+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
78548+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
78549+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
78550+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
78551+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
78552+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
78553+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
78554+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
78555+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
78556+
78557 typedef struct elf32_phdr{
78558 Elf32_Word p_type;
78559 Elf32_Off p_offset;
78560@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
78561 #define EI_OSABI 7
78562 #define EI_PAD 8
78563
78564+#define EI_PAX 14
78565+
78566 #define ELFMAG0 0x7f /* EI_MAG */
78567 #define ELFMAG1 'E'
78568 #define ELFMAG2 'L'
78569diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
78570index aa169c4..6a2771d 100644
78571--- a/include/uapi/linux/personality.h
78572+++ b/include/uapi/linux/personality.h
78573@@ -30,6 +30,7 @@ enum {
78574 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
78575 ADDR_NO_RANDOMIZE | \
78576 ADDR_COMPAT_LAYOUT | \
78577+ ADDR_LIMIT_3GB | \
78578 MMAP_PAGE_ZERO)
78579
78580 /*
78581diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
78582index 7530e74..e714828 100644
78583--- a/include/uapi/linux/screen_info.h
78584+++ b/include/uapi/linux/screen_info.h
78585@@ -43,7 +43,8 @@ struct screen_info {
78586 __u16 pages; /* 0x32 */
78587 __u16 vesa_attributes; /* 0x34 */
78588 __u32 capabilities; /* 0x36 */
78589- __u8 _reserved[6]; /* 0x3a */
78590+ __u16 vesapm_size; /* 0x3a */
78591+ __u8 _reserved[4]; /* 0x3c */
78592 } __attribute__((packed));
78593
78594 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
78595diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
78596index 0e011eb..82681b1 100644
78597--- a/include/uapi/linux/swab.h
78598+++ b/include/uapi/linux/swab.h
78599@@ -43,7 +43,7 @@
78600 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
78601 */
78602
78603-static inline __attribute_const__ __u16 __fswab16(__u16 val)
78604+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
78605 {
78606 #ifdef __HAVE_BUILTIN_BSWAP16__
78607 return __builtin_bswap16(val);
78608@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
78609 #endif
78610 }
78611
78612-static inline __attribute_const__ __u32 __fswab32(__u32 val)
78613+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
78614 {
78615 #ifdef __HAVE_BUILTIN_BSWAP32__
78616 return __builtin_bswap32(val);
78617@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
78618 #endif
78619 }
78620
78621-static inline __attribute_const__ __u64 __fswab64(__u64 val)
78622+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
78623 {
78624 #ifdef __HAVE_BUILTIN_BSWAP64__
78625 return __builtin_bswap64(val);
78626diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
78627index 6d67213..8dab561 100644
78628--- a/include/uapi/linux/sysctl.h
78629+++ b/include/uapi/linux/sysctl.h
78630@@ -155,7 +155,11 @@ enum
78631 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
78632 };
78633
78634-
78635+#ifdef CONFIG_PAX_SOFTMODE
78636+enum {
78637+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
78638+};
78639+#endif
78640
78641 /* CTL_VM names: */
78642 enum
78643diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
78644index e4629b9..6958086 100644
78645--- a/include/uapi/linux/xattr.h
78646+++ b/include/uapi/linux/xattr.h
78647@@ -63,5 +63,9 @@
78648 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
78649 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
78650
78651+/* User namespace */
78652+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
78653+#define XATTR_PAX_FLAGS_SUFFIX "flags"
78654+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
78655
78656 #endif /* _UAPI_LINUX_XATTR_H */
78657diff --git a/include/video/udlfb.h b/include/video/udlfb.h
78658index f9466fa..f4e2b81 100644
78659--- a/include/video/udlfb.h
78660+++ b/include/video/udlfb.h
78661@@ -53,10 +53,10 @@ struct dlfb_data {
78662 u32 pseudo_palette[256];
78663 int blank_mode; /*one of FB_BLANK_ */
78664 /* blit-only rendering path metrics, exposed through sysfs */
78665- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78666- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
78667- atomic_t bytes_sent; /* to usb, after compression including overhead */
78668- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
78669+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78670+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
78671+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
78672+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
78673 };
78674
78675 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
78676diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
78677index 30f5362..8ed8ac9 100644
78678--- a/include/video/uvesafb.h
78679+++ b/include/video/uvesafb.h
78680@@ -122,6 +122,7 @@ struct uvesafb_par {
78681 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
78682 u8 pmi_setpal; /* PMI for palette changes */
78683 u16 *pmi_base; /* protected mode interface location */
78684+ u8 *pmi_code; /* protected mode code location */
78685 void *pmi_start;
78686 void *pmi_pal;
78687 u8 *vbe_state_orig; /*
78688diff --git a/init/Kconfig b/init/Kconfig
78689index fed81b5..0d3b964 100644
78690--- a/init/Kconfig
78691+++ b/init/Kconfig
78692@@ -1069,6 +1069,7 @@ endif # CGROUPS
78693
78694 config CHECKPOINT_RESTORE
78695 bool "Checkpoint/restore support" if EXPERT
78696+ depends on !GRKERNSEC
78697 default n
78698 help
78699 Enables additional kernel features in a sake of checkpoint/restore.
78700@@ -1553,7 +1554,7 @@ config SLUB_DEBUG
78701
78702 config COMPAT_BRK
78703 bool "Disable heap randomization"
78704- default y
78705+ default n
78706 help
78707 Randomizing heap placement makes heap exploits harder, but it
78708 also breaks ancient binaries (including anything libc5 based).
78709@@ -1827,7 +1828,7 @@ config INIT_ALL_POSSIBLE
78710 config STOP_MACHINE
78711 bool
78712 default y
78713- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
78714+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
78715 help
78716 Need stop_machine() primitive.
78717
78718diff --git a/init/Makefile b/init/Makefile
78719index 7bc47ee..6da2dc7 100644
78720--- a/init/Makefile
78721+++ b/init/Makefile
78722@@ -2,6 +2,9 @@
78723 # Makefile for the linux kernel.
78724 #
78725
78726+ccflags-y := $(GCC_PLUGINS_CFLAGS)
78727+asflags-y := $(GCC_PLUGINS_AFLAGS)
78728+
78729 obj-y := main.o version.o mounts.o
78730 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
78731 obj-y += noinitramfs.o
78732diff --git a/init/do_mounts.c b/init/do_mounts.c
78733index 816014c..c2054db 100644
78734--- a/init/do_mounts.c
78735+++ b/init/do_mounts.c
78736@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
78737 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
78738 {
78739 struct super_block *s;
78740- int err = sys_mount(name, "/root", fs, flags, data);
78741+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
78742 if (err)
78743 return err;
78744
78745- sys_chdir("/root");
78746+ sys_chdir((const char __force_user *)"/root");
78747 s = current->fs->pwd.dentry->d_sb;
78748 ROOT_DEV = s->s_dev;
78749 printk(KERN_INFO
78750@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
78751 va_start(args, fmt);
78752 vsprintf(buf, fmt, args);
78753 va_end(args);
78754- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
78755+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
78756 if (fd >= 0) {
78757 sys_ioctl(fd, FDEJECT, 0);
78758 sys_close(fd);
78759 }
78760 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
78761- fd = sys_open("/dev/console", O_RDWR, 0);
78762+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
78763 if (fd >= 0) {
78764 sys_ioctl(fd, TCGETS, (long)&termios);
78765 termios.c_lflag &= ~ICANON;
78766 sys_ioctl(fd, TCSETSF, (long)&termios);
78767- sys_read(fd, &c, 1);
78768+ sys_read(fd, (char __user *)&c, 1);
78769 termios.c_lflag |= ICANON;
78770 sys_ioctl(fd, TCSETSF, (long)&termios);
78771 sys_close(fd);
78772@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
78773 mount_root();
78774 out:
78775 devtmpfs_mount("dev");
78776- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78777- sys_chroot(".");
78778+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78779+ sys_chroot((const char __force_user *)".");
78780 }
78781diff --git a/init/do_mounts.h b/init/do_mounts.h
78782index f5b978a..69dbfe8 100644
78783--- a/init/do_mounts.h
78784+++ b/init/do_mounts.h
78785@@ -15,15 +15,15 @@ extern int root_mountflags;
78786
78787 static inline int create_dev(char *name, dev_t dev)
78788 {
78789- sys_unlink(name);
78790- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
78791+ sys_unlink((char __force_user *)name);
78792+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
78793 }
78794
78795 #if BITS_PER_LONG == 32
78796 static inline u32 bstat(char *name)
78797 {
78798 struct stat64 stat;
78799- if (sys_stat64(name, &stat) != 0)
78800+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
78801 return 0;
78802 if (!S_ISBLK(stat.st_mode))
78803 return 0;
78804@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
78805 static inline u32 bstat(char *name)
78806 {
78807 struct stat stat;
78808- if (sys_newstat(name, &stat) != 0)
78809+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
78810 return 0;
78811 if (!S_ISBLK(stat.st_mode))
78812 return 0;
78813diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
78814index 3e0878e..8a9d7a0 100644
78815--- a/init/do_mounts_initrd.c
78816+++ b/init/do_mounts_initrd.c
78817@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
78818 {
78819 sys_unshare(CLONE_FS | CLONE_FILES);
78820 /* stdin/stdout/stderr for /linuxrc */
78821- sys_open("/dev/console", O_RDWR, 0);
78822+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
78823 sys_dup(0);
78824 sys_dup(0);
78825 /* move initrd over / and chdir/chroot in initrd root */
78826- sys_chdir("/root");
78827- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78828- sys_chroot(".");
78829+ sys_chdir((const char __force_user *)"/root");
78830+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78831+ sys_chroot((const char __force_user *)".");
78832 sys_setsid();
78833 return 0;
78834 }
78835@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
78836 create_dev("/dev/root.old", Root_RAM0);
78837 /* mount initrd on rootfs' /root */
78838 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
78839- sys_mkdir("/old", 0700);
78840- sys_chdir("/old");
78841+ sys_mkdir((const char __force_user *)"/old", 0700);
78842+ sys_chdir((const char __force_user *)"/old");
78843
78844 /* try loading default modules from initrd */
78845 load_default_modules();
78846@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
78847 current->flags &= ~PF_FREEZER_SKIP;
78848
78849 /* move initrd to rootfs' /old */
78850- sys_mount("..", ".", NULL, MS_MOVE, NULL);
78851+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
78852 /* switch root and cwd back to / of rootfs */
78853- sys_chroot("..");
78854+ sys_chroot((const char __force_user *)"..");
78855
78856 if (new_decode_dev(real_root_dev) == Root_RAM0) {
78857- sys_chdir("/old");
78858+ sys_chdir((const char __force_user *)"/old");
78859 return;
78860 }
78861
78862- sys_chdir("/");
78863+ sys_chdir((const char __force_user *)"/");
78864 ROOT_DEV = new_decode_dev(real_root_dev);
78865 mount_root();
78866
78867 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
78868- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
78869+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
78870 if (!error)
78871 printk("okay\n");
78872 else {
78873- int fd = sys_open("/dev/root.old", O_RDWR, 0);
78874+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
78875 if (error == -ENOENT)
78876 printk("/initrd does not exist. Ignored.\n");
78877 else
78878 printk("failed\n");
78879 printk(KERN_NOTICE "Unmounting old root\n");
78880- sys_umount("/old", MNT_DETACH);
78881+ sys_umount((char __force_user *)"/old", MNT_DETACH);
78882 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
78883 if (fd < 0) {
78884 error = fd;
78885@@ -127,11 +127,11 @@ int __init initrd_load(void)
78886 * mounted in the normal path.
78887 */
78888 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
78889- sys_unlink("/initrd.image");
78890+ sys_unlink((const char __force_user *)"/initrd.image");
78891 handle_initrd();
78892 return 1;
78893 }
78894 }
78895- sys_unlink("/initrd.image");
78896+ sys_unlink((const char __force_user *)"/initrd.image");
78897 return 0;
78898 }
78899diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
78900index 8cb6db5..d729f50 100644
78901--- a/init/do_mounts_md.c
78902+++ b/init/do_mounts_md.c
78903@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
78904 partitioned ? "_d" : "", minor,
78905 md_setup_args[ent].device_names);
78906
78907- fd = sys_open(name, 0, 0);
78908+ fd = sys_open((char __force_user *)name, 0, 0);
78909 if (fd < 0) {
78910 printk(KERN_ERR "md: open failed - cannot start "
78911 "array %s\n", name);
78912@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
78913 * array without it
78914 */
78915 sys_close(fd);
78916- fd = sys_open(name, 0, 0);
78917+ fd = sys_open((char __force_user *)name, 0, 0);
78918 sys_ioctl(fd, BLKRRPART, 0);
78919 }
78920 sys_close(fd);
78921@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
78922
78923 wait_for_device_probe();
78924
78925- fd = sys_open("/dev/md0", 0, 0);
78926+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
78927 if (fd >= 0) {
78928 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
78929 sys_close(fd);
78930diff --git a/init/init_task.c b/init/init_task.c
78931index ba0a7f36..2bcf1d5 100644
78932--- a/init/init_task.c
78933+++ b/init/init_task.c
78934@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
78935 * Initial thread structure. Alignment of this is handled by a special
78936 * linker map entry.
78937 */
78938+#ifdef CONFIG_X86
78939+union thread_union init_thread_union __init_task_data;
78940+#else
78941 union thread_union init_thread_union __init_task_data =
78942 { INIT_THREAD_INFO(init_task) };
78943+#endif
78944diff --git a/init/initramfs.c b/init/initramfs.c
78945index a67ef9d..2d17ed9 100644
78946--- a/init/initramfs.c
78947+++ b/init/initramfs.c
78948@@ -84,7 +84,7 @@ static void __init free_hash(void)
78949 }
78950 }
78951
78952-static long __init do_utime(char *filename, time_t mtime)
78953+static long __init do_utime(char __force_user *filename, time_t mtime)
78954 {
78955 struct timespec t[2];
78956
78957@@ -119,7 +119,7 @@ static void __init dir_utime(void)
78958 struct dir_entry *de, *tmp;
78959 list_for_each_entry_safe(de, tmp, &dir_list, list) {
78960 list_del(&de->list);
78961- do_utime(de->name, de->mtime);
78962+ do_utime((char __force_user *)de->name, de->mtime);
78963 kfree(de->name);
78964 kfree(de);
78965 }
78966@@ -281,7 +281,7 @@ static int __init maybe_link(void)
78967 if (nlink >= 2) {
78968 char *old = find_link(major, minor, ino, mode, collected);
78969 if (old)
78970- return (sys_link(old, collected) < 0) ? -1 : 1;
78971+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
78972 }
78973 return 0;
78974 }
78975@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
78976 {
78977 struct stat st;
78978
78979- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
78980+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
78981 if (S_ISDIR(st.st_mode))
78982- sys_rmdir(path);
78983+ sys_rmdir((char __force_user *)path);
78984 else
78985- sys_unlink(path);
78986+ sys_unlink((char __force_user *)path);
78987 }
78988 }
78989
78990@@ -315,7 +315,7 @@ static int __init do_name(void)
78991 int openflags = O_WRONLY|O_CREAT;
78992 if (ml != 1)
78993 openflags |= O_TRUNC;
78994- wfd = sys_open(collected, openflags, mode);
78995+ wfd = sys_open((char __force_user *)collected, openflags, mode);
78996
78997 if (wfd >= 0) {
78998 sys_fchown(wfd, uid, gid);
78999@@ -327,17 +327,17 @@ static int __init do_name(void)
79000 }
79001 }
79002 } else if (S_ISDIR(mode)) {
79003- sys_mkdir(collected, mode);
79004- sys_chown(collected, uid, gid);
79005- sys_chmod(collected, mode);
79006+ sys_mkdir((char __force_user *)collected, mode);
79007+ sys_chown((char __force_user *)collected, uid, gid);
79008+ sys_chmod((char __force_user *)collected, mode);
79009 dir_add(collected, mtime);
79010 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
79011 S_ISFIFO(mode) || S_ISSOCK(mode)) {
79012 if (maybe_link() == 0) {
79013- sys_mknod(collected, mode, rdev);
79014- sys_chown(collected, uid, gid);
79015- sys_chmod(collected, mode);
79016- do_utime(collected, mtime);
79017+ sys_mknod((char __force_user *)collected, mode, rdev);
79018+ sys_chown((char __force_user *)collected, uid, gid);
79019+ sys_chmod((char __force_user *)collected, mode);
79020+ do_utime((char __force_user *)collected, mtime);
79021 }
79022 }
79023 return 0;
79024@@ -346,15 +346,15 @@ static int __init do_name(void)
79025 static int __init do_copy(void)
79026 {
79027 if (count >= body_len) {
79028- sys_write(wfd, victim, body_len);
79029+ sys_write(wfd, (char __force_user *)victim, body_len);
79030 sys_close(wfd);
79031- do_utime(vcollected, mtime);
79032+ do_utime((char __force_user *)vcollected, mtime);
79033 kfree(vcollected);
79034 eat(body_len);
79035 state = SkipIt;
79036 return 0;
79037 } else {
79038- sys_write(wfd, victim, count);
79039+ sys_write(wfd, (char __force_user *)victim, count);
79040 body_len -= count;
79041 eat(count);
79042 return 1;
79043@@ -365,9 +365,9 @@ static int __init do_symlink(void)
79044 {
79045 collected[N_ALIGN(name_len) + body_len] = '\0';
79046 clean_path(collected, 0);
79047- sys_symlink(collected + N_ALIGN(name_len), collected);
79048- sys_lchown(collected, uid, gid);
79049- do_utime(collected, mtime);
79050+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
79051+ sys_lchown((char __force_user *)collected, uid, gid);
79052+ do_utime((char __force_user *)collected, mtime);
79053 state = SkipIt;
79054 next_state = Reset;
79055 return 0;
79056@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
79057 {
79058 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
79059 if (err)
79060- panic(err); /* Failed to decompress INTERNAL initramfs */
79061+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
79062 if (initrd_start) {
79063 #ifdef CONFIG_BLK_DEV_RAM
79064 int fd;
79065diff --git a/init/main.c b/init/main.c
79066index d03d2ec..665fac3 100644
79067--- a/init/main.c
79068+++ b/init/main.c
79069@@ -101,6 +101,8 @@ static inline void mark_rodata_ro(void) { }
79070 extern void tc_init(void);
79071 #endif
79072
79073+extern void grsecurity_init(void);
79074+
79075 /*
79076 * Debug helper: via this flag we know that we are in 'early bootup code'
79077 * where only the boot processor is running with IRQ disabled. This means
79078@@ -154,6 +156,74 @@ static int __init set_reset_devices(char *str)
79079
79080 __setup("reset_devices", set_reset_devices);
79081
79082+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79083+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
79084+static int __init setup_grsec_proc_gid(char *str)
79085+{
79086+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
79087+ return 1;
79088+}
79089+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
79090+#endif
79091+
79092+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
79093+unsigned long pax_user_shadow_base __read_only;
79094+EXPORT_SYMBOL(pax_user_shadow_base);
79095+extern char pax_enter_kernel_user[];
79096+extern char pax_exit_kernel_user[];
79097+#endif
79098+
79099+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
79100+static int __init setup_pax_nouderef(char *str)
79101+{
79102+#ifdef CONFIG_X86_32
79103+ unsigned int cpu;
79104+ struct desc_struct *gdt;
79105+
79106+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
79107+ gdt = get_cpu_gdt_table(cpu);
79108+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
79109+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
79110+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
79111+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
79112+ }
79113+ loadsegment(ds, __KERNEL_DS);
79114+ loadsegment(es, __KERNEL_DS);
79115+ loadsegment(ss, __KERNEL_DS);
79116+#else
79117+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
79118+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
79119+ clone_pgd_mask = ~(pgdval_t)0UL;
79120+ pax_user_shadow_base = 0UL;
79121+ setup_clear_cpu_cap(X86_FEATURE_PCID);
79122+#endif
79123+
79124+ return 0;
79125+}
79126+early_param("pax_nouderef", setup_pax_nouderef);
79127+
79128+#ifdef CONFIG_X86_64
79129+static int __init setup_pax_weakuderef(char *str)
79130+{
79131+ if (clone_pgd_mask != ~(pgdval_t)0UL)
79132+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
79133+ return 1;
79134+}
79135+__setup("pax_weakuderef", setup_pax_weakuderef);
79136+#endif
79137+#endif
79138+
79139+#ifdef CONFIG_PAX_SOFTMODE
79140+int pax_softmode;
79141+
79142+static int __init setup_pax_softmode(char *str)
79143+{
79144+ get_option(&str, &pax_softmode);
79145+ return 1;
79146+}
79147+__setup("pax_softmode=", setup_pax_softmode);
79148+#endif
79149+
79150 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
79151 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
79152 static const char *panic_later, *panic_param;
79153@@ -679,24 +749,22 @@ int __init_or_module do_one_initcall(initcall_t fn)
79154 {
79155 int count = preempt_count();
79156 int ret;
79157- char msgbuf[64];
79158+ const char *msg1 = "", *msg2 = "";
79159
79160 if (initcall_debug)
79161 ret = do_one_initcall_debug(fn);
79162 else
79163 ret = fn();
79164
79165- msgbuf[0] = 0;
79166-
79167 if (preempt_count() != count) {
79168- sprintf(msgbuf, "preemption imbalance ");
79169+ msg1 = " preemption imbalance";
79170 preempt_count() = count;
79171 }
79172 if (irqs_disabled()) {
79173- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
79174+ msg2 = " disabled interrupts";
79175 local_irq_enable();
79176 }
79177- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
79178+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
79179
79180 return ret;
79181 }
79182@@ -749,8 +817,10 @@ static void __init do_initcall_level(int level)
79183 level, level,
79184 &repair_env_string);
79185
79186- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
79187+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
79188 do_one_initcall(*fn);
79189+ add_latent_entropy();
79190+ }
79191 }
79192
79193 static void __init do_initcalls(void)
79194@@ -784,8 +854,10 @@ static void __init do_pre_smp_initcalls(void)
79195 {
79196 initcall_t *fn;
79197
79198- for (fn = __initcall_start; fn < __initcall0_start; fn++)
79199+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
79200 do_one_initcall(*fn);
79201+ add_latent_entropy();
79202+ }
79203 }
79204
79205 /*
79206@@ -803,8 +875,8 @@ static int run_init_process(const char *init_filename)
79207 {
79208 argv_init[0] = init_filename;
79209 return do_execve(init_filename,
79210- (const char __user *const __user *)argv_init,
79211- (const char __user *const __user *)envp_init);
79212+ (const char __user *const __force_user *)argv_init,
79213+ (const char __user *const __force_user *)envp_init);
79214 }
79215
79216 static noinline void __init kernel_init_freeable(void);
79217@@ -881,7 +953,7 @@ static noinline void __init kernel_init_freeable(void)
79218 do_basic_setup();
79219
79220 /* Open the /dev/console on the rootfs, this should never fail */
79221- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
79222+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
79223 pr_err("Warning: unable to open an initial console.\n");
79224
79225 (void) sys_dup(0);
79226@@ -894,11 +966,13 @@ static noinline void __init kernel_init_freeable(void)
79227 if (!ramdisk_execute_command)
79228 ramdisk_execute_command = "/init";
79229
79230- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
79231+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
79232 ramdisk_execute_command = NULL;
79233 prepare_namespace();
79234 }
79235
79236+ grsecurity_init();
79237+
79238 /*
79239 * Ok, we have completed the initial bootup, and
79240 * we're essentially up and running. Get rid of the
79241diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
79242index 130dfec..cc88451 100644
79243--- a/ipc/ipc_sysctl.c
79244+++ b/ipc/ipc_sysctl.c
79245@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
79246 static int proc_ipc_dointvec(ctl_table *table, int write,
79247 void __user *buffer, size_t *lenp, loff_t *ppos)
79248 {
79249- struct ctl_table ipc_table;
79250+ ctl_table_no_const ipc_table;
79251
79252 memcpy(&ipc_table, table, sizeof(ipc_table));
79253 ipc_table.data = get_ipc(table);
79254@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
79255 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
79256 void __user *buffer, size_t *lenp, loff_t *ppos)
79257 {
79258- struct ctl_table ipc_table;
79259+ ctl_table_no_const ipc_table;
79260
79261 memcpy(&ipc_table, table, sizeof(ipc_table));
79262 ipc_table.data = get_ipc(table);
79263@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
79264 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
79265 void __user *buffer, size_t *lenp, loff_t *ppos)
79266 {
79267- struct ctl_table ipc_table;
79268+ ctl_table_no_const ipc_table;
79269 size_t lenp_bef = *lenp;
79270 int rc;
79271
79272@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
79273 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
79274 void __user *buffer, size_t *lenp, loff_t *ppos)
79275 {
79276- struct ctl_table ipc_table;
79277+ ctl_table_no_const ipc_table;
79278 memcpy(&ipc_table, table, sizeof(ipc_table));
79279 ipc_table.data = get_ipc(table);
79280
79281@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
79282 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
79283 void __user *buffer, size_t *lenp, loff_t *ppos)
79284 {
79285- struct ctl_table ipc_table;
79286+ ctl_table_no_const ipc_table;
79287 size_t lenp_bef = *lenp;
79288 int oldval;
79289 int rc;
79290diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
79291index 383d638..943fdbb 100644
79292--- a/ipc/mq_sysctl.c
79293+++ b/ipc/mq_sysctl.c
79294@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
79295 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
79296 void __user *buffer, size_t *lenp, loff_t *ppos)
79297 {
79298- struct ctl_table mq_table;
79299+ ctl_table_no_const mq_table;
79300 memcpy(&mq_table, table, sizeof(mq_table));
79301 mq_table.data = get_mq(table);
79302
79303diff --git a/ipc/mqueue.c b/ipc/mqueue.c
79304index ae1996d..a35f2cc 100644
79305--- a/ipc/mqueue.c
79306+++ b/ipc/mqueue.c
79307@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
79308 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
79309 info->attr.mq_msgsize);
79310
79311+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
79312 spin_lock(&mq_lock);
79313 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
79314 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
79315diff --git a/ipc/msg.c b/ipc/msg.c
79316index 9f29d9e..8f284e0 100644
79317--- a/ipc/msg.c
79318+++ b/ipc/msg.c
79319@@ -291,18 +291,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
79320 return security_msg_queue_associate(msq, msgflg);
79321 }
79322
79323+static struct ipc_ops msg_ops = {
79324+ .getnew = newque,
79325+ .associate = msg_security,
79326+ .more_checks = NULL
79327+};
79328+
79329 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
79330 {
79331 struct ipc_namespace *ns;
79332- struct ipc_ops msg_ops;
79333 struct ipc_params msg_params;
79334
79335 ns = current->nsproxy->ipc_ns;
79336
79337- msg_ops.getnew = newque;
79338- msg_ops.associate = msg_security;
79339- msg_ops.more_checks = NULL;
79340-
79341 msg_params.key = key;
79342 msg_params.flg = msgflg;
79343
79344diff --git a/ipc/sem.c b/ipc/sem.c
79345index 4108889..511ada1 100644
79346--- a/ipc/sem.c
79347+++ b/ipc/sem.c
79348@@ -517,10 +517,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
79349 return 0;
79350 }
79351
79352+static struct ipc_ops sem_ops = {
79353+ .getnew = newary,
79354+ .associate = sem_security,
79355+ .more_checks = sem_more_checks
79356+};
79357+
79358 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
79359 {
79360 struct ipc_namespace *ns;
79361- struct ipc_ops sem_ops;
79362 struct ipc_params sem_params;
79363
79364 ns = current->nsproxy->ipc_ns;
79365@@ -528,10 +533,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
79366 if (nsems < 0 || nsems > ns->sc_semmsl)
79367 return -EINVAL;
79368
79369- sem_ops.getnew = newary;
79370- sem_ops.associate = sem_security;
79371- sem_ops.more_checks = sem_more_checks;
79372-
79373 sem_params.key = key;
79374 sem_params.flg = semflg;
79375 sem_params.u.nsems = nsems;
79376diff --git a/ipc/shm.c b/ipc/shm.c
79377index c6b4ad5..3ec3254 100644
79378--- a/ipc/shm.c
79379+++ b/ipc/shm.c
79380@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
79381 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
79382 #endif
79383
79384+#ifdef CONFIG_GRKERNSEC
79385+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79386+ const time_t shm_createtime, const kuid_t cuid,
79387+ const int shmid);
79388+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79389+ const time_t shm_createtime);
79390+#endif
79391+
79392 void shm_init_ns(struct ipc_namespace *ns)
79393 {
79394 ns->shm_ctlmax = SHMMAX;
79395@@ -531,6 +539,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
79396 shp->shm_lprid = 0;
79397 shp->shm_atim = shp->shm_dtim = 0;
79398 shp->shm_ctim = get_seconds();
79399+#ifdef CONFIG_GRKERNSEC
79400+ {
79401+ struct timespec timeval;
79402+ do_posix_clock_monotonic_gettime(&timeval);
79403+
79404+ shp->shm_createtime = timeval.tv_sec;
79405+ }
79406+#endif
79407 shp->shm_segsz = size;
79408 shp->shm_nattch = 0;
79409 shp->shm_file = file;
79410@@ -585,18 +601,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
79411 return 0;
79412 }
79413
79414+static struct ipc_ops shm_ops = {
79415+ .getnew = newseg,
79416+ .associate = shm_security,
79417+ .more_checks = shm_more_checks
79418+};
79419+
79420 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
79421 {
79422 struct ipc_namespace *ns;
79423- struct ipc_ops shm_ops;
79424 struct ipc_params shm_params;
79425
79426 ns = current->nsproxy->ipc_ns;
79427
79428- shm_ops.getnew = newseg;
79429- shm_ops.associate = shm_security;
79430- shm_ops.more_checks = shm_more_checks;
79431-
79432 shm_params.key = key;
79433 shm_params.flg = shmflg;
79434 shm_params.u.size = size;
79435@@ -1028,6 +1045,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79436 f_mode = FMODE_READ | FMODE_WRITE;
79437 }
79438 if (shmflg & SHM_EXEC) {
79439+
79440+#ifdef CONFIG_PAX_MPROTECT
79441+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
79442+ goto out;
79443+#endif
79444+
79445 prot |= PROT_EXEC;
79446 acc_mode |= S_IXUGO;
79447 }
79448@@ -1051,9 +1074,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79449 if (err)
79450 goto out_unlock;
79451
79452+#ifdef CONFIG_GRKERNSEC
79453+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
79454+ shp->shm_perm.cuid, shmid) ||
79455+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
79456+ err = -EACCES;
79457+ goto out_unlock;
79458+ }
79459+#endif
79460+
79461 path = shp->shm_file->f_path;
79462 path_get(&path);
79463 shp->shm_nattch++;
79464+#ifdef CONFIG_GRKERNSEC
79465+ shp->shm_lapid = current->pid;
79466+#endif
79467 size = i_size_read(path.dentry->d_inode);
79468 shm_unlock(shp);
79469
79470diff --git a/kernel/acct.c b/kernel/acct.c
79471index 8d6e145..33e0b1e 100644
79472--- a/kernel/acct.c
79473+++ b/kernel/acct.c
79474@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
79475 */
79476 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
79477 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
79478- file->f_op->write(file, (char *)&ac,
79479+ file->f_op->write(file, (char __force_user *)&ac,
79480 sizeof(acct_t), &file->f_pos);
79481 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
79482 set_fs(fs);
79483diff --git a/kernel/audit.c b/kernel/audit.c
79484index 91e53d0..d9e3ec4 100644
79485--- a/kernel/audit.c
79486+++ b/kernel/audit.c
79487@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
79488 3) suppressed due to audit_rate_limit
79489 4) suppressed due to audit_backlog_limit
79490 */
79491-static atomic_t audit_lost = ATOMIC_INIT(0);
79492+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
79493
79494 /* The netlink socket. */
79495 static struct sock *audit_sock;
79496@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
79497 unsigned long now;
79498 int print;
79499
79500- atomic_inc(&audit_lost);
79501+ atomic_inc_unchecked(&audit_lost);
79502
79503 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
79504
79505@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
79506 printk(KERN_WARNING
79507 "audit: audit_lost=%d audit_rate_limit=%d "
79508 "audit_backlog_limit=%d\n",
79509- atomic_read(&audit_lost),
79510+ atomic_read_unchecked(&audit_lost),
79511 audit_rate_limit,
79512 audit_backlog_limit);
79513 audit_panic(message);
79514@@ -664,7 +664,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
79515 status_set.pid = audit_pid;
79516 status_set.rate_limit = audit_rate_limit;
79517 status_set.backlog_limit = audit_backlog_limit;
79518- status_set.lost = atomic_read(&audit_lost);
79519+ status_set.lost = atomic_read_unchecked(&audit_lost);
79520 status_set.backlog = skb_queue_len(&audit_skb_queue);
79521 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
79522 &status_set, sizeof(status_set));
79523diff --git a/kernel/auditsc.c b/kernel/auditsc.c
79524index 9845cb3..3ec9369 100644
79525--- a/kernel/auditsc.c
79526+++ b/kernel/auditsc.c
79527@@ -1962,7 +1962,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
79528 }
79529
79530 /* global counter which is incremented every time something logs in */
79531-static atomic_t session_id = ATOMIC_INIT(0);
79532+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
79533
79534 /**
79535 * audit_set_loginuid - set current task's audit_context loginuid
79536@@ -1986,7 +1986,7 @@ int audit_set_loginuid(kuid_t loginuid)
79537 return -EPERM;
79538 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
79539
79540- sessionid = atomic_inc_return(&session_id);
79541+ sessionid = atomic_inc_return_unchecked(&session_id);
79542 if (context && context->in_syscall) {
79543 struct audit_buffer *ab;
79544
79545diff --git a/kernel/capability.c b/kernel/capability.c
79546index f6c2ce5..982c0f9 100644
79547--- a/kernel/capability.c
79548+++ b/kernel/capability.c
79549@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
79550 * before modification is attempted and the application
79551 * fails.
79552 */
79553+ if (tocopy > ARRAY_SIZE(kdata))
79554+ return -EFAULT;
79555+
79556 if (copy_to_user(dataptr, kdata, tocopy
79557 * sizeof(struct __user_cap_data_struct))) {
79558 return -EFAULT;
79559@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
79560 int ret;
79561
79562 rcu_read_lock();
79563- ret = security_capable(__task_cred(t), ns, cap);
79564+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
79565+ gr_task_is_capable(t, __task_cred(t), cap);
79566 rcu_read_unlock();
79567
79568- return (ret == 0);
79569+ return ret;
79570 }
79571
79572 /**
79573@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
79574 int ret;
79575
79576 rcu_read_lock();
79577- ret = security_capable_noaudit(__task_cred(t), ns, cap);
79578+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
79579 rcu_read_unlock();
79580
79581- return (ret == 0);
79582+ return ret;
79583 }
79584
79585 /**
79586@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
79587 BUG();
79588 }
79589
79590- if (security_capable(current_cred(), ns, cap) == 0) {
79591+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
79592 current->flags |= PF_SUPERPRIV;
79593 return true;
79594 }
79595@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
79596 }
79597 EXPORT_SYMBOL(ns_capable);
79598
79599+bool ns_capable_nolog(struct user_namespace *ns, int cap)
79600+{
79601+ if (unlikely(!cap_valid(cap))) {
79602+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
79603+ BUG();
79604+ }
79605+
79606+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
79607+ current->flags |= PF_SUPERPRIV;
79608+ return true;
79609+ }
79610+ return false;
79611+}
79612+EXPORT_SYMBOL(ns_capable_nolog);
79613+
79614 /**
79615 * file_ns_capable - Determine if the file's opener had a capability in effect
79616 * @file: The file we want to check
79617@@ -432,6 +451,12 @@ bool capable(int cap)
79618 }
79619 EXPORT_SYMBOL(capable);
79620
79621+bool capable_nolog(int cap)
79622+{
79623+ return ns_capable_nolog(&init_user_ns, cap);
79624+}
79625+EXPORT_SYMBOL(capable_nolog);
79626+
79627 /**
79628 * nsown_capable - Check superior capability to one's own user_ns
79629 * @cap: The capability in question
79630@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
79631
79632 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79633 }
79634+
79635+bool inode_capable_nolog(const struct inode *inode, int cap)
79636+{
79637+ struct user_namespace *ns = current_user_ns();
79638+
79639+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79640+}
79641diff --git a/kernel/cgroup.c b/kernel/cgroup.c
79642index e919633..f46b08f 100644
79643--- a/kernel/cgroup.c
79644+++ b/kernel/cgroup.c
79645@@ -5623,7 +5623,7 @@ static int cgroup_css_links_read(struct cgroup *cgrp,
79646 struct css_set *cset = link->cset;
79647 struct task_struct *task;
79648 int count = 0;
79649- seq_printf(seq, "css_set %p\n", cset);
79650+ seq_printf(seq, "css_set %pK\n", cset);
79651 list_for_each_entry(task, &cset->tasks, cg_list) {
79652 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
79653 seq_puts(seq, " ...\n");
79654diff --git a/kernel/compat.c b/kernel/compat.c
79655index 0a09e48..f44f3f0 100644
79656--- a/kernel/compat.c
79657+++ b/kernel/compat.c
79658@@ -13,6 +13,7 @@
79659
79660 #include <linux/linkage.h>
79661 #include <linux/compat.h>
79662+#include <linux/module.h>
79663 #include <linux/errno.h>
79664 #include <linux/time.h>
79665 #include <linux/signal.h>
79666@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
79667 mm_segment_t oldfs;
79668 long ret;
79669
79670- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
79671+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
79672 oldfs = get_fs();
79673 set_fs(KERNEL_DS);
79674 ret = hrtimer_nanosleep_restart(restart);
79675@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
79676 oldfs = get_fs();
79677 set_fs(KERNEL_DS);
79678 ret = hrtimer_nanosleep(&tu,
79679- rmtp ? (struct timespec __user *)&rmt : NULL,
79680+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
79681 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
79682 set_fs(oldfs);
79683
79684@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
79685 mm_segment_t old_fs = get_fs();
79686
79687 set_fs(KERNEL_DS);
79688- ret = sys_sigpending((old_sigset_t __user *) &s);
79689+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
79690 set_fs(old_fs);
79691 if (ret == 0)
79692 ret = put_user(s, set);
79693@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
79694 mm_segment_t old_fs = get_fs();
79695
79696 set_fs(KERNEL_DS);
79697- ret = sys_old_getrlimit(resource, &r);
79698+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
79699 set_fs(old_fs);
79700
79701 if (!ret) {
79702@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
79703 set_fs (KERNEL_DS);
79704 ret = sys_wait4(pid,
79705 (stat_addr ?
79706- (unsigned int __user *) &status : NULL),
79707- options, (struct rusage __user *) &r);
79708+ (unsigned int __force_user *) &status : NULL),
79709+ options, (struct rusage __force_user *) &r);
79710 set_fs (old_fs);
79711
79712 if (ret > 0) {
79713@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
79714 memset(&info, 0, sizeof(info));
79715
79716 set_fs(KERNEL_DS);
79717- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
79718- uru ? (struct rusage __user *)&ru : NULL);
79719+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
79720+ uru ? (struct rusage __force_user *)&ru : NULL);
79721 set_fs(old_fs);
79722
79723 if ((ret < 0) || (info.si_signo == 0))
79724@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
79725 oldfs = get_fs();
79726 set_fs(KERNEL_DS);
79727 err = sys_timer_settime(timer_id, flags,
79728- (struct itimerspec __user *) &newts,
79729- (struct itimerspec __user *) &oldts);
79730+ (struct itimerspec __force_user *) &newts,
79731+ (struct itimerspec __force_user *) &oldts);
79732 set_fs(oldfs);
79733 if (!err && old && put_compat_itimerspec(old, &oldts))
79734 return -EFAULT;
79735@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
79736 oldfs = get_fs();
79737 set_fs(KERNEL_DS);
79738 err = sys_timer_gettime(timer_id,
79739- (struct itimerspec __user *) &ts);
79740+ (struct itimerspec __force_user *) &ts);
79741 set_fs(oldfs);
79742 if (!err && put_compat_itimerspec(setting, &ts))
79743 return -EFAULT;
79744@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
79745 oldfs = get_fs();
79746 set_fs(KERNEL_DS);
79747 err = sys_clock_settime(which_clock,
79748- (struct timespec __user *) &ts);
79749+ (struct timespec __force_user *) &ts);
79750 set_fs(oldfs);
79751 return err;
79752 }
79753@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
79754 oldfs = get_fs();
79755 set_fs(KERNEL_DS);
79756 err = sys_clock_gettime(which_clock,
79757- (struct timespec __user *) &ts);
79758+ (struct timespec __force_user *) &ts);
79759 set_fs(oldfs);
79760 if (!err && put_compat_timespec(&ts, tp))
79761 return -EFAULT;
79762@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
79763
79764 oldfs = get_fs();
79765 set_fs(KERNEL_DS);
79766- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
79767+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
79768 set_fs(oldfs);
79769
79770 err = compat_put_timex(utp, &txc);
79771@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
79772 oldfs = get_fs();
79773 set_fs(KERNEL_DS);
79774 err = sys_clock_getres(which_clock,
79775- (struct timespec __user *) &ts);
79776+ (struct timespec __force_user *) &ts);
79777 set_fs(oldfs);
79778 if (!err && tp && put_compat_timespec(&ts, tp))
79779 return -EFAULT;
79780@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
79781 long err;
79782 mm_segment_t oldfs;
79783 struct timespec tu;
79784- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
79785+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
79786
79787- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
79788+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
79789 oldfs = get_fs();
79790 set_fs(KERNEL_DS);
79791 err = clock_nanosleep_restart(restart);
79792@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
79793 oldfs = get_fs();
79794 set_fs(KERNEL_DS);
79795 err = sys_clock_nanosleep(which_clock, flags,
79796- (struct timespec __user *) &in,
79797- (struct timespec __user *) &out);
79798+ (struct timespec __force_user *) &in,
79799+ (struct timespec __force_user *) &out);
79800 set_fs(oldfs);
79801
79802 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
79803diff --git a/kernel/configs.c b/kernel/configs.c
79804index c18b1f1..b9a0132 100644
79805--- a/kernel/configs.c
79806+++ b/kernel/configs.c
79807@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
79808 struct proc_dir_entry *entry;
79809
79810 /* create the current config file */
79811+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
79812+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
79813+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
79814+ &ikconfig_file_ops);
79815+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79816+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
79817+ &ikconfig_file_ops);
79818+#endif
79819+#else
79820 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
79821 &ikconfig_file_ops);
79822+#endif
79823+
79824 if (!entry)
79825 return -ENOMEM;
79826
79827diff --git a/kernel/cred.c b/kernel/cred.c
79828index e0573a4..3874e41 100644
79829--- a/kernel/cred.c
79830+++ b/kernel/cred.c
79831@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
79832 validate_creds(cred);
79833 alter_cred_subscribers(cred, -1);
79834 put_cred(cred);
79835+
79836+#ifdef CONFIG_GRKERNSEC_SETXID
79837+ cred = (struct cred *) tsk->delayed_cred;
79838+ if (cred != NULL) {
79839+ tsk->delayed_cred = NULL;
79840+ validate_creds(cred);
79841+ alter_cred_subscribers(cred, -1);
79842+ put_cred(cred);
79843+ }
79844+#endif
79845 }
79846
79847 /**
79848@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
79849 * Always returns 0 thus allowing this function to be tail-called at the end
79850 * of, say, sys_setgid().
79851 */
79852-int commit_creds(struct cred *new)
79853+static int __commit_creds(struct cred *new)
79854 {
79855 struct task_struct *task = current;
79856 const struct cred *old = task->real_cred;
79857@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
79858
79859 get_cred(new); /* we will require a ref for the subj creds too */
79860
79861+ gr_set_role_label(task, new->uid, new->gid);
79862+
79863 /* dumpability changes */
79864 if (!uid_eq(old->euid, new->euid) ||
79865 !gid_eq(old->egid, new->egid) ||
79866@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
79867 put_cred(old);
79868 return 0;
79869 }
79870+#ifdef CONFIG_GRKERNSEC_SETXID
79871+extern int set_user(struct cred *new);
79872+
79873+void gr_delayed_cred_worker(void)
79874+{
79875+ const struct cred *new = current->delayed_cred;
79876+ struct cred *ncred;
79877+
79878+ current->delayed_cred = NULL;
79879+
79880+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
79881+ // from doing get_cred on it when queueing this
79882+ put_cred(new);
79883+ return;
79884+ } else if (new == NULL)
79885+ return;
79886+
79887+ ncred = prepare_creds();
79888+ if (!ncred)
79889+ goto die;
79890+ // uids
79891+ ncred->uid = new->uid;
79892+ ncred->euid = new->euid;
79893+ ncred->suid = new->suid;
79894+ ncred->fsuid = new->fsuid;
79895+ // gids
79896+ ncred->gid = new->gid;
79897+ ncred->egid = new->egid;
79898+ ncred->sgid = new->sgid;
79899+ ncred->fsgid = new->fsgid;
79900+ // groups
79901+ if (set_groups(ncred, new->group_info) < 0) {
79902+ abort_creds(ncred);
79903+ goto die;
79904+ }
79905+ // caps
79906+ ncred->securebits = new->securebits;
79907+ ncred->cap_inheritable = new->cap_inheritable;
79908+ ncred->cap_permitted = new->cap_permitted;
79909+ ncred->cap_effective = new->cap_effective;
79910+ ncred->cap_bset = new->cap_bset;
79911+
79912+ if (set_user(ncred)) {
79913+ abort_creds(ncred);
79914+ goto die;
79915+ }
79916+
79917+ // from doing get_cred on it when queueing this
79918+ put_cred(new);
79919+
79920+ __commit_creds(ncred);
79921+ return;
79922+die:
79923+ // from doing get_cred on it when queueing this
79924+ put_cred(new);
79925+ do_group_exit(SIGKILL);
79926+}
79927+#endif
79928+
79929+int commit_creds(struct cred *new)
79930+{
79931+#ifdef CONFIG_GRKERNSEC_SETXID
79932+ int ret;
79933+ int schedule_it = 0;
79934+ struct task_struct *t;
79935+
79936+ /* we won't get called with tasklist_lock held for writing
79937+ and interrupts disabled as the cred struct in that case is
79938+ init_cred
79939+ */
79940+ if (grsec_enable_setxid && !current_is_single_threaded() &&
79941+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
79942+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
79943+ schedule_it = 1;
79944+ }
79945+ ret = __commit_creds(new);
79946+ if (schedule_it) {
79947+ rcu_read_lock();
79948+ read_lock(&tasklist_lock);
79949+ for (t = next_thread(current); t != current;
79950+ t = next_thread(t)) {
79951+ if (t->delayed_cred == NULL) {
79952+ t->delayed_cred = get_cred(new);
79953+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
79954+ set_tsk_need_resched(t);
79955+ }
79956+ }
79957+ read_unlock(&tasklist_lock);
79958+ rcu_read_unlock();
79959+ }
79960+ return ret;
79961+#else
79962+ return __commit_creds(new);
79963+#endif
79964+}
79965+
79966 EXPORT_SYMBOL(commit_creds);
79967
79968 /**
79969diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
79970index 0506d44..2c20034 100644
79971--- a/kernel/debug/debug_core.c
79972+++ b/kernel/debug/debug_core.c
79973@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
79974 */
79975 static atomic_t masters_in_kgdb;
79976 static atomic_t slaves_in_kgdb;
79977-static atomic_t kgdb_break_tasklet_var;
79978+static atomic_unchecked_t kgdb_break_tasklet_var;
79979 atomic_t kgdb_setting_breakpoint;
79980
79981 struct task_struct *kgdb_usethread;
79982@@ -133,7 +133,7 @@ int kgdb_single_step;
79983 static pid_t kgdb_sstep_pid;
79984
79985 /* to keep track of the CPU which is doing the single stepping*/
79986-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
79987+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
79988
79989 /*
79990 * If you are debugging a problem where roundup (the collection of
79991@@ -541,7 +541,7 @@ return_normal:
79992 * kernel will only try for the value of sstep_tries before
79993 * giving up and continuing on.
79994 */
79995- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
79996+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
79997 (kgdb_info[cpu].task &&
79998 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
79999 atomic_set(&kgdb_active, -1);
80000@@ -635,8 +635,8 @@ cpu_master_loop:
80001 }
80002
80003 kgdb_restore:
80004- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
80005- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
80006+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
80007+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
80008 if (kgdb_info[sstep_cpu].task)
80009 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
80010 else
80011@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
80012 static void kgdb_tasklet_bpt(unsigned long ing)
80013 {
80014 kgdb_breakpoint();
80015- atomic_set(&kgdb_break_tasklet_var, 0);
80016+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
80017 }
80018
80019 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
80020
80021 void kgdb_schedule_breakpoint(void)
80022 {
80023- if (atomic_read(&kgdb_break_tasklet_var) ||
80024+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
80025 atomic_read(&kgdb_active) != -1 ||
80026 atomic_read(&kgdb_setting_breakpoint))
80027 return;
80028- atomic_inc(&kgdb_break_tasklet_var);
80029+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
80030 tasklet_schedule(&kgdb_tasklet_breakpoint);
80031 }
80032 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
80033diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
80034index 00eb8f7..d7e3244 100644
80035--- a/kernel/debug/kdb/kdb_main.c
80036+++ b/kernel/debug/kdb/kdb_main.c
80037@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
80038 continue;
80039
80040 kdb_printf("%-20s%8u 0x%p ", mod->name,
80041- mod->core_size, (void *)mod);
80042+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
80043 #ifdef CONFIG_MODULE_UNLOAD
80044 kdb_printf("%4ld ", module_refcount(mod));
80045 #endif
80046@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
80047 kdb_printf(" (Loading)");
80048 else
80049 kdb_printf(" (Live)");
80050- kdb_printf(" 0x%p", mod->module_core);
80051+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
80052
80053 #ifdef CONFIG_MODULE_UNLOAD
80054 {
80055diff --git a/kernel/events/core.c b/kernel/events/core.c
80056index f86599e..b18b180 100644
80057--- a/kernel/events/core.c
80058+++ b/kernel/events/core.c
80059@@ -156,8 +156,15 @@ static struct srcu_struct pmus_srcu;
80060 * 0 - disallow raw tracepoint access for unpriv
80061 * 1 - disallow cpu events for unpriv
80062 * 2 - disallow kernel profiling for unpriv
80063+ * 3 - disallow all unpriv perf event use
80064 */
80065-int sysctl_perf_event_paranoid __read_mostly = 1;
80066+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
80067+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
80068+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
80069+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
80070+#else
80071+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
80072+#endif
80073
80074 /* Minimum for 512 kiB + 1 user control page */
80075 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
80076@@ -270,7 +277,7 @@ void perf_sample_event_took(u64 sample_len_ns)
80077 update_perf_cpu_limits();
80078 }
80079
80080-static atomic64_t perf_event_id;
80081+static atomic64_unchecked_t perf_event_id;
80082
80083 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
80084 enum event_type_t event_type);
80085@@ -2936,7 +2943,7 @@ static void __perf_event_read(void *info)
80086
80087 static inline u64 perf_event_count(struct perf_event *event)
80088 {
80089- return local64_read(&event->count) + atomic64_read(&event->child_count);
80090+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
80091 }
80092
80093 static u64 perf_event_read(struct perf_event *event)
80094@@ -3282,9 +3289,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
80095 mutex_lock(&event->child_mutex);
80096 total += perf_event_read(event);
80097 *enabled += event->total_time_enabled +
80098- atomic64_read(&event->child_total_time_enabled);
80099+ atomic64_read_unchecked(&event->child_total_time_enabled);
80100 *running += event->total_time_running +
80101- atomic64_read(&event->child_total_time_running);
80102+ atomic64_read_unchecked(&event->child_total_time_running);
80103
80104 list_for_each_entry(child, &event->child_list, child_list) {
80105 total += perf_event_read(child);
80106@@ -3670,10 +3677,10 @@ void perf_event_update_userpage(struct perf_event *event)
80107 userpg->offset -= local64_read(&event->hw.prev_count);
80108
80109 userpg->time_enabled = enabled +
80110- atomic64_read(&event->child_total_time_enabled);
80111+ atomic64_read_unchecked(&event->child_total_time_enabled);
80112
80113 userpg->time_running = running +
80114- atomic64_read(&event->child_total_time_running);
80115+ atomic64_read_unchecked(&event->child_total_time_running);
80116
80117 arch_perf_update_userpage(userpg, now);
80118
80119@@ -4223,7 +4230,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
80120
80121 /* Data. */
80122 sp = perf_user_stack_pointer(regs);
80123- rem = __output_copy_user(handle, (void *) sp, dump_size);
80124+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
80125 dyn_size = dump_size - rem;
80126
80127 perf_output_skip(handle, rem);
80128@@ -4311,11 +4318,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
80129 values[n++] = perf_event_count(event);
80130 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
80131 values[n++] = enabled +
80132- atomic64_read(&event->child_total_time_enabled);
80133+ atomic64_read_unchecked(&event->child_total_time_enabled);
80134 }
80135 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
80136 values[n++] = running +
80137- atomic64_read(&event->child_total_time_running);
80138+ atomic64_read_unchecked(&event->child_total_time_running);
80139 }
80140 if (read_format & PERF_FORMAT_ID)
80141 values[n++] = primary_event_id(event);
80142@@ -5024,12 +5031,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
80143 * need to add enough zero bytes after the string to handle
80144 * the 64bit alignment we do later.
80145 */
80146- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
80147+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
80148 if (!buf) {
80149 name = strncpy(tmp, "//enomem", sizeof(tmp));
80150 goto got_name;
80151 }
80152- name = d_path(&file->f_path, buf, PATH_MAX);
80153+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
80154 if (IS_ERR(name)) {
80155 name = strncpy(tmp, "//toolong", sizeof(tmp));
80156 goto got_name;
80157@@ -6498,7 +6505,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
80158 event->parent = parent_event;
80159
80160 event->ns = get_pid_ns(task_active_pid_ns(current));
80161- event->id = atomic64_inc_return(&perf_event_id);
80162+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
80163
80164 event->state = PERF_EVENT_STATE_INACTIVE;
80165
80166@@ -6807,6 +6814,11 @@ SYSCALL_DEFINE5(perf_event_open,
80167 if (flags & ~PERF_FLAG_ALL)
80168 return -EINVAL;
80169
80170+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
80171+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
80172+ return -EACCES;
80173+#endif
80174+
80175 err = perf_copy_attr(attr_uptr, &attr);
80176 if (err)
80177 return err;
80178@@ -7139,10 +7151,10 @@ static void sync_child_event(struct perf_event *child_event,
80179 /*
80180 * Add back the child's count to the parent's count:
80181 */
80182- atomic64_add(child_val, &parent_event->child_count);
80183- atomic64_add(child_event->total_time_enabled,
80184+ atomic64_add_unchecked(child_val, &parent_event->child_count);
80185+ atomic64_add_unchecked(child_event->total_time_enabled,
80186 &parent_event->child_total_time_enabled);
80187- atomic64_add(child_event->total_time_running,
80188+ atomic64_add_unchecked(child_event->total_time_running,
80189 &parent_event->child_total_time_running);
80190
80191 /*
80192diff --git a/kernel/events/internal.h b/kernel/events/internal.h
80193index ca65997..60df03d 100644
80194--- a/kernel/events/internal.h
80195+++ b/kernel/events/internal.h
80196@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
80197 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
80198 }
80199
80200-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
80201-static inline unsigned int \
80202+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
80203+static inline unsigned long \
80204 func_name(struct perf_output_handle *handle, \
80205- const void *buf, unsigned int len) \
80206+ const void user *buf, unsigned long len) \
80207 { \
80208 unsigned long size, written; \
80209 \
80210@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
80211 return n;
80212 }
80213
80214-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
80215+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
80216
80217 #define MEMCPY_SKIP(dst, src, n) (n)
80218
80219-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
80220+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
80221
80222 #ifndef arch_perf_out_copy_user
80223 #define arch_perf_out_copy_user __copy_from_user_inatomic
80224 #endif
80225
80226-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
80227+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
80228
80229 /* Callchain handling */
80230 extern struct perf_callchain_entry *
80231diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
80232index f356974..cb8c570 100644
80233--- a/kernel/events/uprobes.c
80234+++ b/kernel/events/uprobes.c
80235@@ -1556,7 +1556,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
80236 {
80237 struct page *page;
80238 uprobe_opcode_t opcode;
80239- int result;
80240+ long result;
80241
80242 pagefault_disable();
80243 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
80244diff --git a/kernel/exit.c b/kernel/exit.c
80245index a949819..a5f127d 100644
80246--- a/kernel/exit.c
80247+++ b/kernel/exit.c
80248@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
80249 struct task_struct *leader;
80250 int zap_leader;
80251 repeat:
80252+#ifdef CONFIG_NET
80253+ gr_del_task_from_ip_table(p);
80254+#endif
80255+
80256 /* don't need to get the RCU readlock here - the process is dead and
80257 * can't be modifying its own credentials. But shut RCU-lockdep up */
80258 rcu_read_lock();
80259@@ -329,7 +333,7 @@ int allow_signal(int sig)
80260 * know it'll be handled, so that they don't get converted to
80261 * SIGKILL or just silently dropped.
80262 */
80263- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
80264+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
80265 recalc_sigpending();
80266 spin_unlock_irq(&current->sighand->siglock);
80267 return 0;
80268@@ -698,6 +702,8 @@ void do_exit(long code)
80269 struct task_struct *tsk = current;
80270 int group_dead;
80271
80272+ set_fs(USER_DS);
80273+
80274 profile_task_exit(tsk);
80275
80276 WARN_ON(blk_needs_flush_plug(tsk));
80277@@ -714,7 +720,6 @@ void do_exit(long code)
80278 * mm_release()->clear_child_tid() from writing to a user-controlled
80279 * kernel address.
80280 */
80281- set_fs(USER_DS);
80282
80283 ptrace_event(PTRACE_EVENT_EXIT, code);
80284
80285@@ -773,6 +778,9 @@ void do_exit(long code)
80286 tsk->exit_code = code;
80287 taskstats_exit(tsk, group_dead);
80288
80289+ gr_acl_handle_psacct(tsk, code);
80290+ gr_acl_handle_exit();
80291+
80292 exit_mm(tsk);
80293
80294 if (group_dead)
80295@@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
80296 * Take down every thread in the group. This is called by fatal signals
80297 * as well as by sys_exit_group (below).
80298 */
80299-void
80300+__noreturn void
80301 do_group_exit(int exit_code)
80302 {
80303 struct signal_struct *sig = current->signal;
80304diff --git a/kernel/fork.c b/kernel/fork.c
80305index bf46287..2af185d 100644
80306--- a/kernel/fork.c
80307+++ b/kernel/fork.c
80308@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
80309 *stackend = STACK_END_MAGIC; /* for overflow detection */
80310
80311 #ifdef CONFIG_CC_STACKPROTECTOR
80312- tsk->stack_canary = get_random_int();
80313+ tsk->stack_canary = pax_get_random_long();
80314 #endif
80315
80316 /*
80317@@ -345,13 +345,81 @@ free_tsk:
80318 }
80319
80320 #ifdef CONFIG_MMU
80321-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80322+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
80323 {
80324- struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80325- struct rb_node **rb_link, *rb_parent;
80326- int retval;
80327+ struct vm_area_struct *tmp;
80328 unsigned long charge;
80329 struct mempolicy *pol;
80330+ struct file *file;
80331+
80332+ charge = 0;
80333+ if (mpnt->vm_flags & VM_ACCOUNT) {
80334+ unsigned long len = vma_pages(mpnt);
80335+
80336+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80337+ goto fail_nomem;
80338+ charge = len;
80339+ }
80340+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80341+ if (!tmp)
80342+ goto fail_nomem;
80343+ *tmp = *mpnt;
80344+ tmp->vm_mm = mm;
80345+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
80346+ pol = mpol_dup(vma_policy(mpnt));
80347+ if (IS_ERR(pol))
80348+ goto fail_nomem_policy;
80349+ vma_set_policy(tmp, pol);
80350+ if (anon_vma_fork(tmp, mpnt))
80351+ goto fail_nomem_anon_vma_fork;
80352+ tmp->vm_flags &= ~VM_LOCKED;
80353+ tmp->vm_next = tmp->vm_prev = NULL;
80354+ tmp->vm_mirror = NULL;
80355+ file = tmp->vm_file;
80356+ if (file) {
80357+ struct inode *inode = file_inode(file);
80358+ struct address_space *mapping = file->f_mapping;
80359+
80360+ get_file(file);
80361+ if (tmp->vm_flags & VM_DENYWRITE)
80362+ atomic_dec(&inode->i_writecount);
80363+ mutex_lock(&mapping->i_mmap_mutex);
80364+ if (tmp->vm_flags & VM_SHARED)
80365+ mapping->i_mmap_writable++;
80366+ flush_dcache_mmap_lock(mapping);
80367+ /* insert tmp into the share list, just after mpnt */
80368+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80369+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
80370+ else
80371+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
80372+ flush_dcache_mmap_unlock(mapping);
80373+ mutex_unlock(&mapping->i_mmap_mutex);
80374+ }
80375+
80376+ /*
80377+ * Clear hugetlb-related page reserves for children. This only
80378+ * affects MAP_PRIVATE mappings. Faults generated by the child
80379+ * are not guaranteed to succeed, even if read-only
80380+ */
80381+ if (is_vm_hugetlb_page(tmp))
80382+ reset_vma_resv_huge_pages(tmp);
80383+
80384+ return tmp;
80385+
80386+fail_nomem_anon_vma_fork:
80387+ mpol_put(pol);
80388+fail_nomem_policy:
80389+ kmem_cache_free(vm_area_cachep, tmp);
80390+fail_nomem:
80391+ vm_unacct_memory(charge);
80392+ return NULL;
80393+}
80394+
80395+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80396+{
80397+ struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80398+ struct rb_node **rb_link, *rb_parent;
80399+ int retval;
80400
80401 uprobe_start_dup_mmap();
80402 down_write(&oldmm->mmap_sem);
80403@@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80404
80405 prev = NULL;
80406 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
80407- struct file *file;
80408-
80409 if (mpnt->vm_flags & VM_DONTCOPY) {
80410 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
80411 -vma_pages(mpnt));
80412 continue;
80413 }
80414- charge = 0;
80415- if (mpnt->vm_flags & VM_ACCOUNT) {
80416- unsigned long len = vma_pages(mpnt);
80417-
80418- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80419- goto fail_nomem;
80420- charge = len;
80421- }
80422- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80423- if (!tmp)
80424- goto fail_nomem;
80425- *tmp = *mpnt;
80426- INIT_LIST_HEAD(&tmp->anon_vma_chain);
80427- pol = mpol_dup(vma_policy(mpnt));
80428- retval = PTR_ERR(pol);
80429- if (IS_ERR(pol))
80430- goto fail_nomem_policy;
80431- vma_set_policy(tmp, pol);
80432- tmp->vm_mm = mm;
80433- if (anon_vma_fork(tmp, mpnt))
80434- goto fail_nomem_anon_vma_fork;
80435- tmp->vm_flags &= ~VM_LOCKED;
80436- tmp->vm_next = tmp->vm_prev = NULL;
80437- file = tmp->vm_file;
80438- if (file) {
80439- struct inode *inode = file_inode(file);
80440- struct address_space *mapping = file->f_mapping;
80441-
80442- get_file(file);
80443- if (tmp->vm_flags & VM_DENYWRITE)
80444- atomic_dec(&inode->i_writecount);
80445- mutex_lock(&mapping->i_mmap_mutex);
80446- if (tmp->vm_flags & VM_SHARED)
80447- mapping->i_mmap_writable++;
80448- flush_dcache_mmap_lock(mapping);
80449- /* insert tmp into the share list, just after mpnt */
80450- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80451- vma_nonlinear_insert(tmp,
80452- &mapping->i_mmap_nonlinear);
80453- else
80454- vma_interval_tree_insert_after(tmp, mpnt,
80455- &mapping->i_mmap);
80456- flush_dcache_mmap_unlock(mapping);
80457- mutex_unlock(&mapping->i_mmap_mutex);
80458+ tmp = dup_vma(mm, oldmm, mpnt);
80459+ if (!tmp) {
80460+ retval = -ENOMEM;
80461+ goto out;
80462 }
80463
80464 /*
80465@@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80466 if (retval)
80467 goto out;
80468 }
80469+
80470+#ifdef CONFIG_PAX_SEGMEXEC
80471+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
80472+ struct vm_area_struct *mpnt_m;
80473+
80474+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
80475+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
80476+
80477+ if (!mpnt->vm_mirror)
80478+ continue;
80479+
80480+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
80481+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
80482+ mpnt->vm_mirror = mpnt_m;
80483+ } else {
80484+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
80485+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
80486+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
80487+ mpnt->vm_mirror->vm_mirror = mpnt;
80488+ }
80489+ }
80490+ BUG_ON(mpnt_m);
80491+ }
80492+#endif
80493+
80494 /* a new mm has just been created */
80495 arch_dup_mmap(oldmm, mm);
80496 retval = 0;
80497@@ -471,14 +522,6 @@ out:
80498 up_write(&oldmm->mmap_sem);
80499 uprobe_end_dup_mmap();
80500 return retval;
80501-fail_nomem_anon_vma_fork:
80502- mpol_put(pol);
80503-fail_nomem_policy:
80504- kmem_cache_free(vm_area_cachep, tmp);
80505-fail_nomem:
80506- retval = -ENOMEM;
80507- vm_unacct_memory(charge);
80508- goto out;
80509 }
80510
80511 static inline int mm_alloc_pgd(struct mm_struct *mm)
80512@@ -691,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
80513 return ERR_PTR(err);
80514
80515 mm = get_task_mm(task);
80516- if (mm && mm != current->mm &&
80517- !ptrace_may_access(task, mode)) {
80518+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
80519+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
80520 mmput(mm);
80521 mm = ERR_PTR(-EACCES);
80522 }
80523@@ -914,13 +957,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
80524 spin_unlock(&fs->lock);
80525 return -EAGAIN;
80526 }
80527- fs->users++;
80528+ atomic_inc(&fs->users);
80529 spin_unlock(&fs->lock);
80530 return 0;
80531 }
80532 tsk->fs = copy_fs_struct(fs);
80533 if (!tsk->fs)
80534 return -ENOMEM;
80535+ /* Carry through gr_chroot_dentry and is_chrooted instead
80536+ of recomputing it here. Already copied when the task struct
80537+ is duplicated. This allows pivot_root to not be treated as
80538+ a chroot
80539+ */
80540+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
80541+
80542 return 0;
80543 }
80544
80545@@ -1131,7 +1181,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
80546 * parts of the process environment (as per the clone
80547 * flags). The actual kick-off is left to the caller.
80548 */
80549-static struct task_struct *copy_process(unsigned long clone_flags,
80550+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
80551 unsigned long stack_start,
80552 unsigned long stack_size,
80553 int __user *child_tidptr,
80554@@ -1200,6 +1250,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80555 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
80556 #endif
80557 retval = -EAGAIN;
80558+
80559+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
80560+
80561 if (atomic_read(&p->real_cred->user->processes) >=
80562 task_rlimit(p, RLIMIT_NPROC)) {
80563 if (p->real_cred->user != INIT_USER &&
80564@@ -1449,6 +1502,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80565 goto bad_fork_free_pid;
80566 }
80567
80568+ /* synchronizes with gr_set_acls()
80569+ we need to call this past the point of no return for fork()
80570+ */
80571+ gr_copy_label(p);
80572+
80573 if (likely(p->pid)) {
80574 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
80575
80576@@ -1534,6 +1592,8 @@ bad_fork_cleanup_count:
80577 bad_fork_free:
80578 free_task(p);
80579 fork_out:
80580+ gr_log_forkfail(retval);
80581+
80582 return ERR_PTR(retval);
80583 }
80584
80585@@ -1604,6 +1664,7 @@ long do_fork(unsigned long clone_flags,
80586
80587 p = copy_process(clone_flags, stack_start, stack_size,
80588 child_tidptr, NULL, trace);
80589+ add_latent_entropy();
80590 /*
80591 * Do this prior waking up the new thread - the thread pointer
80592 * might get invalid after that point, if the thread exits quickly.
80593@@ -1618,6 +1679,8 @@ long do_fork(unsigned long clone_flags,
80594 if (clone_flags & CLONE_PARENT_SETTID)
80595 put_user(nr, parent_tidptr);
80596
80597+ gr_handle_brute_check();
80598+
80599 if (clone_flags & CLONE_VFORK) {
80600 p->vfork_done = &vfork;
80601 init_completion(&vfork);
80602@@ -1734,7 +1797,7 @@ void __init proc_caches_init(void)
80603 mm_cachep = kmem_cache_create("mm_struct",
80604 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
80605 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
80606- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
80607+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
80608 mmap_init();
80609 nsproxy_cache_init();
80610 }
80611@@ -1774,7 +1837,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
80612 return 0;
80613
80614 /* don't need lock here; in the worst case we'll do useless copy */
80615- if (fs->users == 1)
80616+ if (atomic_read(&fs->users) == 1)
80617 return 0;
80618
80619 *new_fsp = copy_fs_struct(fs);
80620@@ -1886,7 +1949,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
80621 fs = current->fs;
80622 spin_lock(&fs->lock);
80623 current->fs = new_fs;
80624- if (--fs->users)
80625+ gr_set_chroot_entries(current, &current->fs->root);
80626+ if (atomic_dec_return(&fs->users))
80627 new_fs = NULL;
80628 else
80629 new_fs = fs;
80630diff --git a/kernel/futex.c b/kernel/futex.c
80631index c3a1a55..e32b4a98 100644
80632--- a/kernel/futex.c
80633+++ b/kernel/futex.c
80634@@ -54,6 +54,7 @@
80635 #include <linux/mount.h>
80636 #include <linux/pagemap.h>
80637 #include <linux/syscalls.h>
80638+#include <linux/ptrace.h>
80639 #include <linux/signal.h>
80640 #include <linux/export.h>
80641 #include <linux/magic.h>
80642@@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
80643 struct page *page, *page_head;
80644 int err, ro = 0;
80645
80646+#ifdef CONFIG_PAX_SEGMEXEC
80647+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
80648+ return -EFAULT;
80649+#endif
80650+
80651 /*
80652 * The futex address must be "naturally" aligned.
80653 */
80654@@ -441,7 +447,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
80655
80656 static int get_futex_value_locked(u32 *dest, u32 __user *from)
80657 {
80658- int ret;
80659+ unsigned long ret;
80660
80661 pagefault_disable();
80662 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
80663@@ -2734,6 +2740,7 @@ static int __init futex_init(void)
80664 {
80665 u32 curval;
80666 int i;
80667+ mm_segment_t oldfs;
80668
80669 /*
80670 * This will fail and we want it. Some arch implementations do
80671@@ -2745,8 +2752,11 @@ static int __init futex_init(void)
80672 * implementation, the non-functional ones will return
80673 * -ENOSYS.
80674 */
80675+ oldfs = get_fs();
80676+ set_fs(USER_DS);
80677 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
80678 futex_cmpxchg_enabled = 1;
80679+ set_fs(oldfs);
80680
80681 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
80682 plist_head_init(&futex_queues[i].chain);
80683diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
80684index f9f44fd..29885e4 100644
80685--- a/kernel/futex_compat.c
80686+++ b/kernel/futex_compat.c
80687@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
80688 return 0;
80689 }
80690
80691-static void __user *futex_uaddr(struct robust_list __user *entry,
80692+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
80693 compat_long_t futex_offset)
80694 {
80695 compat_uptr_t base = ptr_to_compat(entry);
80696diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
80697index 9b22d03..6295b62 100644
80698--- a/kernel/gcov/base.c
80699+++ b/kernel/gcov/base.c
80700@@ -102,11 +102,6 @@ void gcov_enable_events(void)
80701 }
80702
80703 #ifdef CONFIG_MODULES
80704-static inline int within(void *addr, void *start, unsigned long size)
80705-{
80706- return ((addr >= start) && (addr < start + size));
80707-}
80708-
80709 /* Update list and generate events when modules are unloaded. */
80710 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80711 void *data)
80712@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80713 prev = NULL;
80714 /* Remove entries located in module from linked list. */
80715 for (info = gcov_info_head; info; info = info->next) {
80716- if (within(info, mod->module_core, mod->core_size)) {
80717+ if (within_module_core_rw((unsigned long)info, mod)) {
80718 if (prev)
80719 prev->next = info->next;
80720 else
80721diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
80722index 383319b..cd2b391 100644
80723--- a/kernel/hrtimer.c
80724+++ b/kernel/hrtimer.c
80725@@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
80726 local_irq_restore(flags);
80727 }
80728
80729-static void run_hrtimer_softirq(struct softirq_action *h)
80730+static void run_hrtimer_softirq(void)
80731 {
80732 hrtimer_peek_ahead_timers();
80733 }
80734diff --git a/kernel/irq_work.c b/kernel/irq_work.c
80735index 55fcce6..0e4cf34 100644
80736--- a/kernel/irq_work.c
80737+++ b/kernel/irq_work.c
80738@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
80739 return NOTIFY_OK;
80740 }
80741
80742-static struct notifier_block cpu_notify;
80743+static struct notifier_block cpu_notify = {
80744+ .notifier_call = irq_work_cpu_notify,
80745+ .priority = 0,
80746+};
80747
80748 static __init int irq_work_init_cpu_notifier(void)
80749 {
80750- cpu_notify.notifier_call = irq_work_cpu_notify;
80751- cpu_notify.priority = 0;
80752 register_cpu_notifier(&cpu_notify);
80753 return 0;
80754 }
80755diff --git a/kernel/jump_label.c b/kernel/jump_label.c
80756index 60f48fa..7f3a770 100644
80757--- a/kernel/jump_label.c
80758+++ b/kernel/jump_label.c
80759@@ -13,6 +13,7 @@
80760 #include <linux/sort.h>
80761 #include <linux/err.h>
80762 #include <linux/static_key.h>
80763+#include <linux/mm.h>
80764
80765 #ifdef HAVE_JUMP_LABEL
80766
80767@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
80768
80769 size = (((unsigned long)stop - (unsigned long)start)
80770 / sizeof(struct jump_entry));
80771+ pax_open_kernel();
80772 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
80773+ pax_close_kernel();
80774 }
80775
80776 static void jump_label_update(struct static_key *key, int enable);
80777@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
80778 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
80779 struct jump_entry *iter;
80780
80781+ pax_open_kernel();
80782 for (iter = iter_start; iter < iter_stop; iter++) {
80783 if (within_module_init(iter->code, mod))
80784 iter->code = 0;
80785 }
80786+ pax_close_kernel();
80787 }
80788
80789 static int
80790diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
80791index 3127ad5..159d880 100644
80792--- a/kernel/kallsyms.c
80793+++ b/kernel/kallsyms.c
80794@@ -11,6 +11,9 @@
80795 * Changed the compression method from stem compression to "table lookup"
80796 * compression (see scripts/kallsyms.c for a more complete description)
80797 */
80798+#ifdef CONFIG_GRKERNSEC_HIDESYM
80799+#define __INCLUDED_BY_HIDESYM 1
80800+#endif
80801 #include <linux/kallsyms.h>
80802 #include <linux/module.h>
80803 #include <linux/init.h>
80804@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
80805
80806 static inline int is_kernel_inittext(unsigned long addr)
80807 {
80808+ if (system_state != SYSTEM_BOOTING)
80809+ return 0;
80810+
80811 if (addr >= (unsigned long)_sinittext
80812 && addr <= (unsigned long)_einittext)
80813 return 1;
80814 return 0;
80815 }
80816
80817+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80818+#ifdef CONFIG_MODULES
80819+static inline int is_module_text(unsigned long addr)
80820+{
80821+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
80822+ return 1;
80823+
80824+ addr = ktla_ktva(addr);
80825+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
80826+}
80827+#else
80828+static inline int is_module_text(unsigned long addr)
80829+{
80830+ return 0;
80831+}
80832+#endif
80833+#endif
80834+
80835 static inline int is_kernel_text(unsigned long addr)
80836 {
80837 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
80838@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
80839
80840 static inline int is_kernel(unsigned long addr)
80841 {
80842+
80843+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80844+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
80845+ return 1;
80846+
80847+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
80848+#else
80849 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
80850+#endif
80851+
80852 return 1;
80853 return in_gate_area_no_mm(addr);
80854 }
80855
80856 static int is_ksym_addr(unsigned long addr)
80857 {
80858+
80859+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80860+ if (is_module_text(addr))
80861+ return 0;
80862+#endif
80863+
80864 if (all_var)
80865 return is_kernel(addr);
80866
80867@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
80868
80869 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
80870 {
80871- iter->name[0] = '\0';
80872 iter->nameoff = get_symbol_offset(new_pos);
80873 iter->pos = new_pos;
80874 }
80875@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
80876 {
80877 struct kallsym_iter *iter = m->private;
80878
80879+#ifdef CONFIG_GRKERNSEC_HIDESYM
80880+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
80881+ return 0;
80882+#endif
80883+
80884 /* Some debugging symbols have no name. Ignore them. */
80885 if (!iter->name[0])
80886 return 0;
80887@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
80888 */
80889 type = iter->exported ? toupper(iter->type) :
80890 tolower(iter->type);
80891+
80892 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
80893 type, iter->name, iter->module_name);
80894 } else
80895@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
80896 struct kallsym_iter *iter;
80897 int ret;
80898
80899- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
80900+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
80901 if (!iter)
80902 return -ENOMEM;
80903 reset_iter(iter, 0);
80904diff --git a/kernel/kcmp.c b/kernel/kcmp.c
80905index e30ac0f..3528cac 100644
80906--- a/kernel/kcmp.c
80907+++ b/kernel/kcmp.c
80908@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
80909 struct task_struct *task1, *task2;
80910 int ret;
80911
80912+#ifdef CONFIG_GRKERNSEC
80913+ return -ENOSYS;
80914+#endif
80915+
80916 rcu_read_lock();
80917
80918 /*
80919diff --git a/kernel/kexec.c b/kernel/kexec.c
80920index 59f7b55..4022f65 100644
80921--- a/kernel/kexec.c
80922+++ b/kernel/kexec.c
80923@@ -1041,7 +1041,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
80924 unsigned long flags)
80925 {
80926 struct compat_kexec_segment in;
80927- struct kexec_segment out, __user *ksegments;
80928+ struct kexec_segment out;
80929+ struct kexec_segment __user *ksegments;
80930 unsigned long i, result;
80931
80932 /* Don't allow clients that don't understand the native
80933diff --git a/kernel/kmod.c b/kernel/kmod.c
80934index fb32636..2fe8775 100644
80935--- a/kernel/kmod.c
80936+++ b/kernel/kmod.c
80937@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
80938 kfree(info->argv);
80939 }
80940
80941-static int call_modprobe(char *module_name, int wait)
80942+static int call_modprobe(char *module_name, char *module_param, int wait)
80943 {
80944 struct subprocess_info *info;
80945 static char *envp[] = {
80946@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
80947 NULL
80948 };
80949
80950- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
80951+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
80952 if (!argv)
80953 goto out;
80954
80955@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
80956 argv[1] = "-q";
80957 argv[2] = "--";
80958 argv[3] = module_name; /* check free_modprobe_argv() */
80959- argv[4] = NULL;
80960+ argv[4] = module_param;
80961+ argv[5] = NULL;
80962
80963 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
80964 NULL, free_modprobe_argv, NULL);
80965@@ -129,9 +130,8 @@ out:
80966 * If module auto-loading support is disabled then this function
80967 * becomes a no-operation.
80968 */
80969-int __request_module(bool wait, const char *fmt, ...)
80970+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
80971 {
80972- va_list args;
80973 char module_name[MODULE_NAME_LEN];
80974 unsigned int max_modprobes;
80975 int ret;
80976@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
80977 if (!modprobe_path[0])
80978 return 0;
80979
80980- va_start(args, fmt);
80981- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
80982- va_end(args);
80983+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
80984 if (ret >= MODULE_NAME_LEN)
80985 return -ENAMETOOLONG;
80986
80987@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
80988 if (ret)
80989 return ret;
80990
80991+#ifdef CONFIG_GRKERNSEC_MODHARDEN
80992+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
80993+ /* hack to workaround consolekit/udisks stupidity */
80994+ read_lock(&tasklist_lock);
80995+ if (!strcmp(current->comm, "mount") &&
80996+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
80997+ read_unlock(&tasklist_lock);
80998+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
80999+ return -EPERM;
81000+ }
81001+ read_unlock(&tasklist_lock);
81002+ }
81003+#endif
81004+
81005 /* If modprobe needs a service that is in a module, we get a recursive
81006 * loop. Limit the number of running kmod threads to max_threads/2 or
81007 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
81008@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
81009
81010 trace_module_request(module_name, wait, _RET_IP_);
81011
81012- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
81013+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
81014
81015 atomic_dec(&kmod_concurrent);
81016 return ret;
81017 }
81018+
81019+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
81020+{
81021+ va_list args;
81022+ int ret;
81023+
81024+ va_start(args, fmt);
81025+ ret = ____request_module(wait, module_param, fmt, args);
81026+ va_end(args);
81027+
81028+ return ret;
81029+}
81030+
81031+int __request_module(bool wait, const char *fmt, ...)
81032+{
81033+ va_list args;
81034+ int ret;
81035+
81036+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81037+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
81038+ char module_param[MODULE_NAME_LEN];
81039+
81040+ memset(module_param, 0, sizeof(module_param));
81041+
81042+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
81043+
81044+ va_start(args, fmt);
81045+ ret = ____request_module(wait, module_param, fmt, args);
81046+ va_end(args);
81047+
81048+ return ret;
81049+ }
81050+#endif
81051+
81052+ va_start(args, fmt);
81053+ ret = ____request_module(wait, NULL, fmt, args);
81054+ va_end(args);
81055+
81056+ return ret;
81057+}
81058+
81059 EXPORT_SYMBOL(__request_module);
81060 #endif /* CONFIG_MODULES */
81061
81062@@ -303,7 +356,7 @@ static int wait_for_helper(void *data)
81063 *
81064 * Thus the __user pointer cast is valid here.
81065 */
81066- sys_wait4(pid, (int __user *)&ret, 0, NULL);
81067+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
81068
81069 /*
81070 * If ret is 0, either ____call_usermodehelper failed and the
81071@@ -646,7 +699,7 @@ EXPORT_SYMBOL(call_usermodehelper);
81072 static int proc_cap_handler(struct ctl_table *table, int write,
81073 void __user *buffer, size_t *lenp, loff_t *ppos)
81074 {
81075- struct ctl_table t;
81076+ ctl_table_no_const t;
81077 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
81078 kernel_cap_t new_cap;
81079 int err, i;
81080diff --git a/kernel/kprobes.c b/kernel/kprobes.c
81081index 6e33498..3133bd3 100644
81082--- a/kernel/kprobes.c
81083+++ b/kernel/kprobes.c
81084@@ -31,6 +31,9 @@
81085 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
81086 * <prasanna@in.ibm.com> added function-return probes.
81087 */
81088+#ifdef CONFIG_GRKERNSEC_HIDESYM
81089+#define __INCLUDED_BY_HIDESYM 1
81090+#endif
81091 #include <linux/kprobes.h>
81092 #include <linux/hash.h>
81093 #include <linux/init.h>
81094@@ -185,7 +188,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
81095 * kernel image and loaded module images reside. This is required
81096 * so x86_64 can correctly handle the %rip-relative fixups.
81097 */
81098- kip->insns = module_alloc(PAGE_SIZE);
81099+ kip->insns = module_alloc_exec(PAGE_SIZE);
81100 if (!kip->insns) {
81101 kfree(kip);
81102 return NULL;
81103@@ -225,7 +228,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
81104 */
81105 if (!list_is_singular(&kip->list)) {
81106 list_del(&kip->list);
81107- module_free(NULL, kip->insns);
81108+ module_free_exec(NULL, kip->insns);
81109 kfree(kip);
81110 }
81111 return 1;
81112@@ -2083,7 +2086,7 @@ static int __init init_kprobes(void)
81113 {
81114 int i, err = 0;
81115 unsigned long offset = 0, size = 0;
81116- char *modname, namebuf[128];
81117+ char *modname, namebuf[KSYM_NAME_LEN];
81118 const char *symbol_name;
81119 void *addr;
81120 struct kprobe_blackpoint *kb;
81121@@ -2168,11 +2171,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
81122 kprobe_type = "k";
81123
81124 if (sym)
81125- seq_printf(pi, "%p %s %s+0x%x %s ",
81126+ seq_printf(pi, "%pK %s %s+0x%x %s ",
81127 p->addr, kprobe_type, sym, offset,
81128 (modname ? modname : " "));
81129 else
81130- seq_printf(pi, "%p %s %p ",
81131+ seq_printf(pi, "%pK %s %pK ",
81132 p->addr, kprobe_type, p->addr);
81133
81134 if (!pp)
81135@@ -2209,7 +2212,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
81136 const char *sym = NULL;
81137 unsigned int i = *(loff_t *) v;
81138 unsigned long offset = 0;
81139- char *modname, namebuf[128];
81140+ char *modname, namebuf[KSYM_NAME_LEN];
81141
81142 head = &kprobe_table[i];
81143 preempt_disable();
81144diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
81145index 6ada93c..dce7d5d 100644
81146--- a/kernel/ksysfs.c
81147+++ b/kernel/ksysfs.c
81148@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
81149 {
81150 if (count+1 > UEVENT_HELPER_PATH_LEN)
81151 return -ENOENT;
81152+ if (!capable(CAP_SYS_ADMIN))
81153+ return -EPERM;
81154 memcpy(uevent_helper, buf, count);
81155 uevent_helper[count] = '\0';
81156 if (count && uevent_helper[count-1] == '\n')
81157@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
81158 return count;
81159 }
81160
81161-static struct bin_attribute notes_attr = {
81162+static bin_attribute_no_const notes_attr __read_only = {
81163 .attr = {
81164 .name = "notes",
81165 .mode = S_IRUGO,
81166diff --git a/kernel/lockdep.c b/kernel/lockdep.c
81167index e16c45b..6f49c48 100644
81168--- a/kernel/lockdep.c
81169+++ b/kernel/lockdep.c
81170@@ -596,6 +596,10 @@ static int static_obj(void *obj)
81171 end = (unsigned long) &_end,
81172 addr = (unsigned long) obj;
81173
81174+#ifdef CONFIG_PAX_KERNEXEC
81175+ start = ktla_ktva(start);
81176+#endif
81177+
81178 /*
81179 * static variable?
81180 */
81181@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
81182 if (!static_obj(lock->key)) {
81183 debug_locks_off();
81184 printk("INFO: trying to register non-static key.\n");
81185+ printk("lock:%pS key:%pS.\n", lock, lock->key);
81186 printk("the code is fine but needs lockdep annotation.\n");
81187 printk("turning off the locking correctness validator.\n");
81188 dump_stack();
81189@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
81190 if (!class)
81191 return 0;
81192 }
81193- atomic_inc((atomic_t *)&class->ops);
81194+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
81195 if (very_verbose(class)) {
81196 printk("\nacquire class [%p] %s", class->key, class->name);
81197 if (class->name_version > 1)
81198diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
81199index b2c71c5..7b88d63 100644
81200--- a/kernel/lockdep_proc.c
81201+++ b/kernel/lockdep_proc.c
81202@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
81203 return 0;
81204 }
81205
81206- seq_printf(m, "%p", class->key);
81207+ seq_printf(m, "%pK", class->key);
81208 #ifdef CONFIG_DEBUG_LOCKDEP
81209 seq_printf(m, " OPS:%8ld", class->ops);
81210 #endif
81211@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
81212
81213 list_for_each_entry(entry, &class->locks_after, entry) {
81214 if (entry->distance == 1) {
81215- seq_printf(m, " -> [%p] ", entry->class->key);
81216+ seq_printf(m, " -> [%pK] ", entry->class->key);
81217 print_name(m, entry->class);
81218 seq_puts(m, "\n");
81219 }
81220@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
81221 if (!class->key)
81222 continue;
81223
81224- seq_printf(m, "[%p] ", class->key);
81225+ seq_printf(m, "[%pK] ", class->key);
81226 print_name(m, class);
81227 seq_puts(m, "\n");
81228 }
81229@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
81230 if (!i)
81231 seq_line(m, '-', 40-namelen, namelen);
81232
81233- snprintf(ip, sizeof(ip), "[<%p>]",
81234+ snprintf(ip, sizeof(ip), "[<%pK>]",
81235 (void *)class->contention_point[i]);
81236 seq_printf(m, "%40s %14lu %29s %pS\n",
81237 name, stats->contention_point[i],
81238@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
81239 if (!i)
81240 seq_line(m, '-', 40-namelen, namelen);
81241
81242- snprintf(ip, sizeof(ip), "[<%p>]",
81243+ snprintf(ip, sizeof(ip), "[<%pK>]",
81244 (void *)class->contending_point[i]);
81245 seq_printf(m, "%40s %14lu %29s %pS\n",
81246 name, stats->contending_point[i],
81247diff --git a/kernel/module.c b/kernel/module.c
81248index 2069158..71101bb 100644
81249--- a/kernel/module.c
81250+++ b/kernel/module.c
81251@@ -61,6 +61,7 @@
81252 #include <linux/pfn.h>
81253 #include <linux/bsearch.h>
81254 #include <linux/fips.h>
81255+#include <linux/grsecurity.h>
81256 #include <uapi/linux/module.h>
81257 #include "module-internal.h"
81258
81259@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
81260
81261 /* Bounds of module allocation, for speeding __module_address.
81262 * Protected by module_mutex. */
81263-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
81264+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
81265+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
81266
81267 int register_module_notifier(struct notifier_block * nb)
81268 {
81269@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
81270 return true;
81271
81272 list_for_each_entry_rcu(mod, &modules, list) {
81273- struct symsearch arr[] = {
81274+ struct symsearch modarr[] = {
81275 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
81276 NOT_GPL_ONLY, false },
81277 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
81278@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
81279 if (mod->state == MODULE_STATE_UNFORMED)
81280 continue;
81281
81282- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
81283+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
81284 return true;
81285 }
81286 return false;
81287@@ -490,7 +492,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
81288 if (!pcpusec->sh_size)
81289 return 0;
81290
81291- if (align > PAGE_SIZE) {
81292+ if (align-1 >= PAGE_SIZE) {
81293 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
81294 mod->name, align, PAGE_SIZE);
81295 align = PAGE_SIZE;
81296@@ -1096,7 +1098,7 @@ struct module_attribute module_uevent =
81297 static ssize_t show_coresize(struct module_attribute *mattr,
81298 struct module_kobject *mk, char *buffer)
81299 {
81300- return sprintf(buffer, "%u\n", mk->mod->core_size);
81301+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
81302 }
81303
81304 static struct module_attribute modinfo_coresize =
81305@@ -1105,7 +1107,7 @@ static struct module_attribute modinfo_coresize =
81306 static ssize_t show_initsize(struct module_attribute *mattr,
81307 struct module_kobject *mk, char *buffer)
81308 {
81309- return sprintf(buffer, "%u\n", mk->mod->init_size);
81310+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
81311 }
81312
81313 static struct module_attribute modinfo_initsize =
81314@@ -1320,7 +1322,7 @@ resolve_symbol_wait(struct module *mod,
81315 */
81316 #ifdef CONFIG_SYSFS
81317
81318-#ifdef CONFIG_KALLSYMS
81319+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
81320 static inline bool sect_empty(const Elf_Shdr *sect)
81321 {
81322 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
81323@@ -1460,7 +1462,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
81324 {
81325 unsigned int notes, loaded, i;
81326 struct module_notes_attrs *notes_attrs;
81327- struct bin_attribute *nattr;
81328+ bin_attribute_no_const *nattr;
81329
81330 /* failed to create section attributes, so can't create notes */
81331 if (!mod->sect_attrs)
81332@@ -1572,7 +1574,7 @@ static void del_usage_links(struct module *mod)
81333 static int module_add_modinfo_attrs(struct module *mod)
81334 {
81335 struct module_attribute *attr;
81336- struct module_attribute *temp_attr;
81337+ module_attribute_no_const *temp_attr;
81338 int error = 0;
81339 int i;
81340
81341@@ -1786,21 +1788,21 @@ static void set_section_ro_nx(void *base,
81342
81343 static void unset_module_core_ro_nx(struct module *mod)
81344 {
81345- set_page_attributes(mod->module_core + mod->core_text_size,
81346- mod->module_core + mod->core_size,
81347+ set_page_attributes(mod->module_core_rw,
81348+ mod->module_core_rw + mod->core_size_rw,
81349 set_memory_x);
81350- set_page_attributes(mod->module_core,
81351- mod->module_core + mod->core_ro_size,
81352+ set_page_attributes(mod->module_core_rx,
81353+ mod->module_core_rx + mod->core_size_rx,
81354 set_memory_rw);
81355 }
81356
81357 static void unset_module_init_ro_nx(struct module *mod)
81358 {
81359- set_page_attributes(mod->module_init + mod->init_text_size,
81360- mod->module_init + mod->init_size,
81361+ set_page_attributes(mod->module_init_rw,
81362+ mod->module_init_rw + mod->init_size_rw,
81363 set_memory_x);
81364- set_page_attributes(mod->module_init,
81365- mod->module_init + mod->init_ro_size,
81366+ set_page_attributes(mod->module_init_rx,
81367+ mod->module_init_rx + mod->init_size_rx,
81368 set_memory_rw);
81369 }
81370
81371@@ -1813,14 +1815,14 @@ void set_all_modules_text_rw(void)
81372 list_for_each_entry_rcu(mod, &modules, list) {
81373 if (mod->state == MODULE_STATE_UNFORMED)
81374 continue;
81375- if ((mod->module_core) && (mod->core_text_size)) {
81376- set_page_attributes(mod->module_core,
81377- mod->module_core + mod->core_text_size,
81378+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81379+ set_page_attributes(mod->module_core_rx,
81380+ mod->module_core_rx + mod->core_size_rx,
81381 set_memory_rw);
81382 }
81383- if ((mod->module_init) && (mod->init_text_size)) {
81384- set_page_attributes(mod->module_init,
81385- mod->module_init + mod->init_text_size,
81386+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81387+ set_page_attributes(mod->module_init_rx,
81388+ mod->module_init_rx + mod->init_size_rx,
81389 set_memory_rw);
81390 }
81391 }
81392@@ -1836,14 +1838,14 @@ void set_all_modules_text_ro(void)
81393 list_for_each_entry_rcu(mod, &modules, list) {
81394 if (mod->state == MODULE_STATE_UNFORMED)
81395 continue;
81396- if ((mod->module_core) && (mod->core_text_size)) {
81397- set_page_attributes(mod->module_core,
81398- mod->module_core + mod->core_text_size,
81399+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81400+ set_page_attributes(mod->module_core_rx,
81401+ mod->module_core_rx + mod->core_size_rx,
81402 set_memory_ro);
81403 }
81404- if ((mod->module_init) && (mod->init_text_size)) {
81405- set_page_attributes(mod->module_init,
81406- mod->module_init + mod->init_text_size,
81407+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81408+ set_page_attributes(mod->module_init_rx,
81409+ mod->module_init_rx + mod->init_size_rx,
81410 set_memory_ro);
81411 }
81412 }
81413@@ -1894,16 +1896,19 @@ static void free_module(struct module *mod)
81414
81415 /* This may be NULL, but that's OK */
81416 unset_module_init_ro_nx(mod);
81417- module_free(mod, mod->module_init);
81418+ module_free(mod, mod->module_init_rw);
81419+ module_free_exec(mod, mod->module_init_rx);
81420 kfree(mod->args);
81421 percpu_modfree(mod);
81422
81423 /* Free lock-classes: */
81424- lockdep_free_key_range(mod->module_core, mod->core_size);
81425+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
81426+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
81427
81428 /* Finally, free the core (containing the module structure) */
81429 unset_module_core_ro_nx(mod);
81430- module_free(mod, mod->module_core);
81431+ module_free_exec(mod, mod->module_core_rx);
81432+ module_free(mod, mod->module_core_rw);
81433
81434 #ifdef CONFIG_MPU
81435 update_protections(current->mm);
81436@@ -1973,9 +1978,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81437 int ret = 0;
81438 const struct kernel_symbol *ksym;
81439
81440+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81441+ int is_fs_load = 0;
81442+ int register_filesystem_found = 0;
81443+ char *p;
81444+
81445+ p = strstr(mod->args, "grsec_modharden_fs");
81446+ if (p) {
81447+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
81448+ /* copy \0 as well */
81449+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
81450+ is_fs_load = 1;
81451+ }
81452+#endif
81453+
81454 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
81455 const char *name = info->strtab + sym[i].st_name;
81456
81457+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81458+ /* it's a real shame this will never get ripped and copied
81459+ upstream! ;(
81460+ */
81461+ if (is_fs_load && !strcmp(name, "register_filesystem"))
81462+ register_filesystem_found = 1;
81463+#endif
81464+
81465 switch (sym[i].st_shndx) {
81466 case SHN_COMMON:
81467 /* We compiled with -fno-common. These are not
81468@@ -1996,7 +2023,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81469 ksym = resolve_symbol_wait(mod, info, name);
81470 /* Ok if resolved. */
81471 if (ksym && !IS_ERR(ksym)) {
81472+ pax_open_kernel();
81473 sym[i].st_value = ksym->value;
81474+ pax_close_kernel();
81475 break;
81476 }
81477
81478@@ -2015,11 +2044,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81479 secbase = (unsigned long)mod_percpu(mod);
81480 else
81481 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
81482+ pax_open_kernel();
81483 sym[i].st_value += secbase;
81484+ pax_close_kernel();
81485 break;
81486 }
81487 }
81488
81489+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81490+ if (is_fs_load && !register_filesystem_found) {
81491+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
81492+ ret = -EPERM;
81493+ }
81494+#endif
81495+
81496 return ret;
81497 }
81498
81499@@ -2103,22 +2141,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
81500 || s->sh_entsize != ~0UL
81501 || strstarts(sname, ".init"))
81502 continue;
81503- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
81504+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81505+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
81506+ else
81507+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
81508 pr_debug("\t%s\n", sname);
81509 }
81510- switch (m) {
81511- case 0: /* executable */
81512- mod->core_size = debug_align(mod->core_size);
81513- mod->core_text_size = mod->core_size;
81514- break;
81515- case 1: /* RO: text and ro-data */
81516- mod->core_size = debug_align(mod->core_size);
81517- mod->core_ro_size = mod->core_size;
81518- break;
81519- case 3: /* whole core */
81520- mod->core_size = debug_align(mod->core_size);
81521- break;
81522- }
81523 }
81524
81525 pr_debug("Init section allocation order:\n");
81526@@ -2132,23 +2160,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
81527 || s->sh_entsize != ~0UL
81528 || !strstarts(sname, ".init"))
81529 continue;
81530- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
81531- | INIT_OFFSET_MASK);
81532+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81533+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
81534+ else
81535+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
81536+ s->sh_entsize |= INIT_OFFSET_MASK;
81537 pr_debug("\t%s\n", sname);
81538 }
81539- switch (m) {
81540- case 0: /* executable */
81541- mod->init_size = debug_align(mod->init_size);
81542- mod->init_text_size = mod->init_size;
81543- break;
81544- case 1: /* RO: text and ro-data */
81545- mod->init_size = debug_align(mod->init_size);
81546- mod->init_ro_size = mod->init_size;
81547- break;
81548- case 3: /* whole init */
81549- mod->init_size = debug_align(mod->init_size);
81550- break;
81551- }
81552 }
81553 }
81554
81555@@ -2321,7 +2339,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81556
81557 /* Put symbol section at end of init part of module. */
81558 symsect->sh_flags |= SHF_ALLOC;
81559- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
81560+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
81561 info->index.sym) | INIT_OFFSET_MASK;
81562 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
81563
81564@@ -2338,13 +2356,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81565 }
81566
81567 /* Append room for core symbols at end of core part. */
81568- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
81569- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
81570- mod->core_size += strtab_size;
81571+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
81572+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
81573+ mod->core_size_rx += strtab_size;
81574
81575 /* Put string table section at end of init part of module. */
81576 strsect->sh_flags |= SHF_ALLOC;
81577- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
81578+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
81579 info->index.str) | INIT_OFFSET_MASK;
81580 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
81581 }
81582@@ -2362,12 +2380,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81583 /* Make sure we get permanent strtab: don't use info->strtab. */
81584 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
81585
81586+ pax_open_kernel();
81587+
81588 /* Set types up while we still have access to sections. */
81589 for (i = 0; i < mod->num_symtab; i++)
81590 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
81591
81592- mod->core_symtab = dst = mod->module_core + info->symoffs;
81593- mod->core_strtab = s = mod->module_core + info->stroffs;
81594+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
81595+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
81596 src = mod->symtab;
81597 for (ndst = i = 0; i < mod->num_symtab; i++) {
81598 if (i == 0 ||
81599@@ -2379,6 +2399,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81600 }
81601 }
81602 mod->core_num_syms = ndst;
81603+
81604+ pax_close_kernel();
81605 }
81606 #else
81607 static inline void layout_symtab(struct module *mod, struct load_info *info)
81608@@ -2412,17 +2434,33 @@ void * __weak module_alloc(unsigned long size)
81609 return vmalloc_exec(size);
81610 }
81611
81612-static void *module_alloc_update_bounds(unsigned long size)
81613+static void *module_alloc_update_bounds_rw(unsigned long size)
81614 {
81615 void *ret = module_alloc(size);
81616
81617 if (ret) {
81618 mutex_lock(&module_mutex);
81619 /* Update module bounds. */
81620- if ((unsigned long)ret < module_addr_min)
81621- module_addr_min = (unsigned long)ret;
81622- if ((unsigned long)ret + size > module_addr_max)
81623- module_addr_max = (unsigned long)ret + size;
81624+ if ((unsigned long)ret < module_addr_min_rw)
81625+ module_addr_min_rw = (unsigned long)ret;
81626+ if ((unsigned long)ret + size > module_addr_max_rw)
81627+ module_addr_max_rw = (unsigned long)ret + size;
81628+ mutex_unlock(&module_mutex);
81629+ }
81630+ return ret;
81631+}
81632+
81633+static void *module_alloc_update_bounds_rx(unsigned long size)
81634+{
81635+ void *ret = module_alloc_exec(size);
81636+
81637+ if (ret) {
81638+ mutex_lock(&module_mutex);
81639+ /* Update module bounds. */
81640+ if ((unsigned long)ret < module_addr_min_rx)
81641+ module_addr_min_rx = (unsigned long)ret;
81642+ if ((unsigned long)ret + size > module_addr_max_rx)
81643+ module_addr_max_rx = (unsigned long)ret + size;
81644 mutex_unlock(&module_mutex);
81645 }
81646 return ret;
81647@@ -2698,8 +2736,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
81648 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81649 {
81650 const char *modmagic = get_modinfo(info, "vermagic");
81651+ const char *license = get_modinfo(info, "license");
81652 int err;
81653
81654+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
81655+ if (!license || !license_is_gpl_compatible(license))
81656+ return -ENOEXEC;
81657+#endif
81658+
81659 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
81660 modmagic = NULL;
81661
81662@@ -2725,7 +2769,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81663 }
81664
81665 /* Set up license info based on the info section */
81666- set_license(mod, get_modinfo(info, "license"));
81667+ set_license(mod, license);
81668
81669 return 0;
81670 }
81671@@ -2806,7 +2850,7 @@ static int move_module(struct module *mod, struct load_info *info)
81672 void *ptr;
81673
81674 /* Do the allocs. */
81675- ptr = module_alloc_update_bounds(mod->core_size);
81676+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
81677 /*
81678 * The pointer to this block is stored in the module structure
81679 * which is inside the block. Just mark it as not being a
81680@@ -2816,11 +2860,11 @@ static int move_module(struct module *mod, struct load_info *info)
81681 if (!ptr)
81682 return -ENOMEM;
81683
81684- memset(ptr, 0, mod->core_size);
81685- mod->module_core = ptr;
81686+ memset(ptr, 0, mod->core_size_rw);
81687+ mod->module_core_rw = ptr;
81688
81689- if (mod->init_size) {
81690- ptr = module_alloc_update_bounds(mod->init_size);
81691+ if (mod->init_size_rw) {
81692+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
81693 /*
81694 * The pointer to this block is stored in the module structure
81695 * which is inside the block. This block doesn't need to be
81696@@ -2829,13 +2873,45 @@ static int move_module(struct module *mod, struct load_info *info)
81697 */
81698 kmemleak_ignore(ptr);
81699 if (!ptr) {
81700- module_free(mod, mod->module_core);
81701+ module_free(mod, mod->module_core_rw);
81702 return -ENOMEM;
81703 }
81704- memset(ptr, 0, mod->init_size);
81705- mod->module_init = ptr;
81706+ memset(ptr, 0, mod->init_size_rw);
81707+ mod->module_init_rw = ptr;
81708 } else
81709- mod->module_init = NULL;
81710+ mod->module_init_rw = NULL;
81711+
81712+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
81713+ kmemleak_not_leak(ptr);
81714+ if (!ptr) {
81715+ if (mod->module_init_rw)
81716+ module_free(mod, mod->module_init_rw);
81717+ module_free(mod, mod->module_core_rw);
81718+ return -ENOMEM;
81719+ }
81720+
81721+ pax_open_kernel();
81722+ memset(ptr, 0, mod->core_size_rx);
81723+ pax_close_kernel();
81724+ mod->module_core_rx = ptr;
81725+
81726+ if (mod->init_size_rx) {
81727+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
81728+ kmemleak_ignore(ptr);
81729+ if (!ptr && mod->init_size_rx) {
81730+ module_free_exec(mod, mod->module_core_rx);
81731+ if (mod->module_init_rw)
81732+ module_free(mod, mod->module_init_rw);
81733+ module_free(mod, mod->module_core_rw);
81734+ return -ENOMEM;
81735+ }
81736+
81737+ pax_open_kernel();
81738+ memset(ptr, 0, mod->init_size_rx);
81739+ pax_close_kernel();
81740+ mod->module_init_rx = ptr;
81741+ } else
81742+ mod->module_init_rx = NULL;
81743
81744 /* Transfer each section which specifies SHF_ALLOC */
81745 pr_debug("final section addresses:\n");
81746@@ -2846,16 +2922,45 @@ static int move_module(struct module *mod, struct load_info *info)
81747 if (!(shdr->sh_flags & SHF_ALLOC))
81748 continue;
81749
81750- if (shdr->sh_entsize & INIT_OFFSET_MASK)
81751- dest = mod->module_init
81752- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81753- else
81754- dest = mod->module_core + shdr->sh_entsize;
81755+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
81756+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81757+ dest = mod->module_init_rw
81758+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81759+ else
81760+ dest = mod->module_init_rx
81761+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81762+ } else {
81763+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81764+ dest = mod->module_core_rw + shdr->sh_entsize;
81765+ else
81766+ dest = mod->module_core_rx + shdr->sh_entsize;
81767+ }
81768+
81769+ if (shdr->sh_type != SHT_NOBITS) {
81770+
81771+#ifdef CONFIG_PAX_KERNEXEC
81772+#ifdef CONFIG_X86_64
81773+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
81774+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
81775+#endif
81776+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
81777+ pax_open_kernel();
81778+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81779+ pax_close_kernel();
81780+ } else
81781+#endif
81782
81783- if (shdr->sh_type != SHT_NOBITS)
81784 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81785+ }
81786 /* Update sh_addr to point to copy in image. */
81787- shdr->sh_addr = (unsigned long)dest;
81788+
81789+#ifdef CONFIG_PAX_KERNEXEC
81790+ if (shdr->sh_flags & SHF_EXECINSTR)
81791+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
81792+ else
81793+#endif
81794+
81795+ shdr->sh_addr = (unsigned long)dest;
81796 pr_debug("\t0x%lx %s\n",
81797 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
81798 }
81799@@ -2912,12 +3017,12 @@ static void flush_module_icache(const struct module *mod)
81800 * Do it before processing of module parameters, so the module
81801 * can provide parameter accessor functions of its own.
81802 */
81803- if (mod->module_init)
81804- flush_icache_range((unsigned long)mod->module_init,
81805- (unsigned long)mod->module_init
81806- + mod->init_size);
81807- flush_icache_range((unsigned long)mod->module_core,
81808- (unsigned long)mod->module_core + mod->core_size);
81809+ if (mod->module_init_rx)
81810+ flush_icache_range((unsigned long)mod->module_init_rx,
81811+ (unsigned long)mod->module_init_rx
81812+ + mod->init_size_rx);
81813+ flush_icache_range((unsigned long)mod->module_core_rx,
81814+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
81815
81816 set_fs(old_fs);
81817 }
81818@@ -2974,8 +3079,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
81819 static void module_deallocate(struct module *mod, struct load_info *info)
81820 {
81821 percpu_modfree(mod);
81822- module_free(mod, mod->module_init);
81823- module_free(mod, mod->module_core);
81824+ module_free_exec(mod, mod->module_init_rx);
81825+ module_free_exec(mod, mod->module_core_rx);
81826+ module_free(mod, mod->module_init_rw);
81827+ module_free(mod, mod->module_core_rw);
81828 }
81829
81830 int __weak module_finalize(const Elf_Ehdr *hdr,
81831@@ -2988,7 +3095,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
81832 static int post_relocation(struct module *mod, const struct load_info *info)
81833 {
81834 /* Sort exception table now relocations are done. */
81835+ pax_open_kernel();
81836 sort_extable(mod->extable, mod->extable + mod->num_exentries);
81837+ pax_close_kernel();
81838
81839 /* Copy relocated percpu area over. */
81840 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
81841@@ -3042,16 +3151,16 @@ static int do_init_module(struct module *mod)
81842 MODULE_STATE_COMING, mod);
81843
81844 /* Set RO and NX regions for core */
81845- set_section_ro_nx(mod->module_core,
81846- mod->core_text_size,
81847- mod->core_ro_size,
81848- mod->core_size);
81849+ set_section_ro_nx(mod->module_core_rx,
81850+ mod->core_size_rx,
81851+ mod->core_size_rx,
81852+ mod->core_size_rx);
81853
81854 /* Set RO and NX regions for init */
81855- set_section_ro_nx(mod->module_init,
81856- mod->init_text_size,
81857- mod->init_ro_size,
81858- mod->init_size);
81859+ set_section_ro_nx(mod->module_init_rx,
81860+ mod->init_size_rx,
81861+ mod->init_size_rx,
81862+ mod->init_size_rx);
81863
81864 do_mod_ctors(mod);
81865 /* Start the module */
81866@@ -3113,11 +3222,12 @@ static int do_init_module(struct module *mod)
81867 mod->strtab = mod->core_strtab;
81868 #endif
81869 unset_module_init_ro_nx(mod);
81870- module_free(mod, mod->module_init);
81871- mod->module_init = NULL;
81872- mod->init_size = 0;
81873- mod->init_ro_size = 0;
81874- mod->init_text_size = 0;
81875+ module_free(mod, mod->module_init_rw);
81876+ module_free_exec(mod, mod->module_init_rx);
81877+ mod->module_init_rw = NULL;
81878+ mod->module_init_rx = NULL;
81879+ mod->init_size_rw = 0;
81880+ mod->init_size_rx = 0;
81881 mutex_unlock(&module_mutex);
81882 wake_up_all(&module_wq);
81883
81884@@ -3261,9 +3371,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
81885 if (err)
81886 goto free_unload;
81887
81888+ /* Now copy in args */
81889+ mod->args = strndup_user(uargs, ~0UL >> 1);
81890+ if (IS_ERR(mod->args)) {
81891+ err = PTR_ERR(mod->args);
81892+ goto free_unload;
81893+ }
81894+
81895 /* Set up MODINFO_ATTR fields */
81896 setup_modinfo(mod, info);
81897
81898+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81899+ {
81900+ char *p, *p2;
81901+
81902+ if (strstr(mod->args, "grsec_modharden_netdev")) {
81903+ 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);
81904+ err = -EPERM;
81905+ goto free_modinfo;
81906+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
81907+ p += sizeof("grsec_modharden_normal") - 1;
81908+ p2 = strstr(p, "_");
81909+ if (p2) {
81910+ *p2 = '\0';
81911+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
81912+ *p2 = '_';
81913+ }
81914+ err = -EPERM;
81915+ goto free_modinfo;
81916+ }
81917+ }
81918+#endif
81919+
81920 /* Fix up syms, so that st_value is a pointer to location. */
81921 err = simplify_symbols(mod, info);
81922 if (err < 0)
81923@@ -3279,13 +3418,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
81924
81925 flush_module_icache(mod);
81926
81927- /* Now copy in args */
81928- mod->args = strndup_user(uargs, ~0UL >> 1);
81929- if (IS_ERR(mod->args)) {
81930- err = PTR_ERR(mod->args);
81931- goto free_arch_cleanup;
81932- }
81933-
81934 dynamic_debug_setup(info->debug, info->num_debug);
81935
81936 /* Finally it's fully formed, ready to start executing. */
81937@@ -3320,11 +3452,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
81938 ddebug_cleanup:
81939 dynamic_debug_remove(info->debug);
81940 synchronize_sched();
81941- kfree(mod->args);
81942- free_arch_cleanup:
81943 module_arch_cleanup(mod);
81944 free_modinfo:
81945 free_modinfo(mod);
81946+ kfree(mod->args);
81947 free_unload:
81948 module_unload_free(mod);
81949 unlink_mod:
81950@@ -3407,10 +3538,16 @@ static const char *get_ksymbol(struct module *mod,
81951 unsigned long nextval;
81952
81953 /* At worse, next value is at end of module */
81954- if (within_module_init(addr, mod))
81955- nextval = (unsigned long)mod->module_init+mod->init_text_size;
81956+ if (within_module_init_rx(addr, mod))
81957+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
81958+ else if (within_module_init_rw(addr, mod))
81959+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
81960+ else if (within_module_core_rx(addr, mod))
81961+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
81962+ else if (within_module_core_rw(addr, mod))
81963+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
81964 else
81965- nextval = (unsigned long)mod->module_core+mod->core_text_size;
81966+ return NULL;
81967
81968 /* Scan for closest preceding symbol, and next symbol. (ELF
81969 starts real symbols at 1). */
81970@@ -3661,7 +3798,7 @@ static int m_show(struct seq_file *m, void *p)
81971 return 0;
81972
81973 seq_printf(m, "%s %u",
81974- mod->name, mod->init_size + mod->core_size);
81975+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
81976 print_unload_info(m, mod);
81977
81978 /* Informative for users. */
81979@@ -3670,7 +3807,7 @@ static int m_show(struct seq_file *m, void *p)
81980 mod->state == MODULE_STATE_COMING ? "Loading":
81981 "Live");
81982 /* Used by oprofile and other similar tools. */
81983- seq_printf(m, " 0x%pK", mod->module_core);
81984+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
81985
81986 /* Taints info */
81987 if (mod->taints)
81988@@ -3706,7 +3843,17 @@ static const struct file_operations proc_modules_operations = {
81989
81990 static int __init proc_modules_init(void)
81991 {
81992+#ifndef CONFIG_GRKERNSEC_HIDESYM
81993+#ifdef CONFIG_GRKERNSEC_PROC_USER
81994+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
81995+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81996+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
81997+#else
81998 proc_create("modules", 0, NULL, &proc_modules_operations);
81999+#endif
82000+#else
82001+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
82002+#endif
82003 return 0;
82004 }
82005 module_init(proc_modules_init);
82006@@ -3767,14 +3914,14 @@ struct module *__module_address(unsigned long addr)
82007 {
82008 struct module *mod;
82009
82010- if (addr < module_addr_min || addr > module_addr_max)
82011+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
82012+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
82013 return NULL;
82014
82015 list_for_each_entry_rcu(mod, &modules, list) {
82016 if (mod->state == MODULE_STATE_UNFORMED)
82017 continue;
82018- if (within_module_core(addr, mod)
82019- || within_module_init(addr, mod))
82020+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
82021 return mod;
82022 }
82023 return NULL;
82024@@ -3809,11 +3956,20 @@ bool is_module_text_address(unsigned long addr)
82025 */
82026 struct module *__module_text_address(unsigned long addr)
82027 {
82028- struct module *mod = __module_address(addr);
82029+ struct module *mod;
82030+
82031+#ifdef CONFIG_X86_32
82032+ addr = ktla_ktva(addr);
82033+#endif
82034+
82035+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
82036+ return NULL;
82037+
82038+ mod = __module_address(addr);
82039+
82040 if (mod) {
82041 /* Make sure it's within the text section. */
82042- if (!within(addr, mod->module_init, mod->init_text_size)
82043- && !within(addr, mod->module_core, mod->core_text_size))
82044+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
82045 mod = NULL;
82046 }
82047 return mod;
82048diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
82049index 7e3443f..b2a1e6b 100644
82050--- a/kernel/mutex-debug.c
82051+++ b/kernel/mutex-debug.c
82052@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
82053 }
82054
82055 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82056- struct thread_info *ti)
82057+ struct task_struct *task)
82058 {
82059 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
82060
82061 /* Mark the current thread as blocked on the lock: */
82062- ti->task->blocked_on = waiter;
82063+ task->blocked_on = waiter;
82064 }
82065
82066 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82067- struct thread_info *ti)
82068+ struct task_struct *task)
82069 {
82070 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
82071- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
82072- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
82073- ti->task->blocked_on = NULL;
82074+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
82075+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
82076+ task->blocked_on = NULL;
82077
82078 list_del_init(&waiter->list);
82079 waiter->task = NULL;
82080diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
82081index 0799fd3..d06ae3b 100644
82082--- a/kernel/mutex-debug.h
82083+++ b/kernel/mutex-debug.h
82084@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
82085 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
82086 extern void debug_mutex_add_waiter(struct mutex *lock,
82087 struct mutex_waiter *waiter,
82088- struct thread_info *ti);
82089+ struct task_struct *task);
82090 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82091- struct thread_info *ti);
82092+ struct task_struct *task);
82093 extern void debug_mutex_unlock(struct mutex *lock);
82094 extern void debug_mutex_init(struct mutex *lock, const char *name,
82095 struct lock_class_key *key);
82096diff --git a/kernel/mutex.c b/kernel/mutex.c
82097index a52ee7bb..f361f16 100644
82098--- a/kernel/mutex.c
82099+++ b/kernel/mutex.c
82100@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
82101 node->locked = 1;
82102 return;
82103 }
82104- ACCESS_ONCE(prev->next) = node;
82105+ ACCESS_ONCE_RW(prev->next) = node;
82106 smp_wmb();
82107 /* Wait until the lock holder passes the lock down */
82108 while (!ACCESS_ONCE(node->locked))
82109@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
82110 while (!(next = ACCESS_ONCE(node->next)))
82111 arch_mutex_cpu_relax();
82112 }
82113- ACCESS_ONCE(next->locked) = 1;
82114+ ACCESS_ONCE_RW(next->locked) = 1;
82115 smp_wmb();
82116 }
82117
82118@@ -514,7 +514,7 @@ slowpath:
82119 spin_lock_mutex(&lock->wait_lock, flags);
82120
82121 debug_mutex_lock_common(lock, &waiter);
82122- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
82123+ debug_mutex_add_waiter(lock, &waiter, task);
82124
82125 /* add waiting tasks to the end of the waitqueue (FIFO): */
82126 list_add_tail(&waiter.list, &lock->wait_list);
82127@@ -565,7 +565,7 @@ slowpath:
82128 done:
82129 lock_acquired(&lock->dep_map, ip);
82130 /* got the lock - rejoice! */
82131- mutex_remove_waiter(lock, &waiter, current_thread_info());
82132+ mutex_remove_waiter(lock, &waiter, task);
82133 mutex_set_owner(lock);
82134
82135 if (!__builtin_constant_p(ww_ctx == NULL)) {
82136@@ -604,7 +604,7 @@ done:
82137 return 0;
82138
82139 err:
82140- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
82141+ mutex_remove_waiter(lock, &waiter, task);
82142 spin_unlock_mutex(&lock->wait_lock, flags);
82143 debug_mutex_free_waiter(&waiter);
82144 mutex_release(&lock->dep_map, 1, ip);
82145diff --git a/kernel/notifier.c b/kernel/notifier.c
82146index 2d5cc4c..d9ea600 100644
82147--- a/kernel/notifier.c
82148+++ b/kernel/notifier.c
82149@@ -5,6 +5,7 @@
82150 #include <linux/rcupdate.h>
82151 #include <linux/vmalloc.h>
82152 #include <linux/reboot.h>
82153+#include <linux/mm.h>
82154
82155 /*
82156 * Notifier list for kernel code which wants to be called
82157@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
82158 while ((*nl) != NULL) {
82159 if (n->priority > (*nl)->priority)
82160 break;
82161- nl = &((*nl)->next);
82162+ nl = (struct notifier_block **)&((*nl)->next);
82163 }
82164- n->next = *nl;
82165+ pax_open_kernel();
82166+ *(const void **)&n->next = *nl;
82167 rcu_assign_pointer(*nl, n);
82168+ pax_close_kernel();
82169 return 0;
82170 }
82171
82172@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
82173 return 0;
82174 if (n->priority > (*nl)->priority)
82175 break;
82176- nl = &((*nl)->next);
82177+ nl = (struct notifier_block **)&((*nl)->next);
82178 }
82179- n->next = *nl;
82180+ pax_open_kernel();
82181+ *(const void **)&n->next = *nl;
82182 rcu_assign_pointer(*nl, n);
82183+ pax_close_kernel();
82184 return 0;
82185 }
82186
82187@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
82188 {
82189 while ((*nl) != NULL) {
82190 if ((*nl) == n) {
82191+ pax_open_kernel();
82192 rcu_assign_pointer(*nl, n->next);
82193+ pax_close_kernel();
82194 return 0;
82195 }
82196- nl = &((*nl)->next);
82197+ nl = (struct notifier_block **)&((*nl)->next);
82198 }
82199 return -ENOENT;
82200 }
82201diff --git a/kernel/panic.c b/kernel/panic.c
82202index 8018646..b6a5b4f 100644
82203--- a/kernel/panic.c
82204+++ b/kernel/panic.c
82205@@ -403,7 +403,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
82206 disable_trace_on_warning();
82207
82208 pr_warn("------------[ cut here ]------------\n");
82209- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
82210+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
82211 raw_smp_processor_id(), current->pid, file, line, caller);
82212
82213 if (args)
82214@@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
82215 */
82216 void __stack_chk_fail(void)
82217 {
82218- panic("stack-protector: Kernel stack is corrupted in: %p\n",
82219+ dump_stack();
82220+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
82221 __builtin_return_address(0));
82222 }
82223 EXPORT_SYMBOL(__stack_chk_fail);
82224diff --git a/kernel/pid.c b/kernel/pid.c
82225index 66505c1..87af12c 100644
82226--- a/kernel/pid.c
82227+++ b/kernel/pid.c
82228@@ -33,6 +33,7 @@
82229 #include <linux/rculist.h>
82230 #include <linux/bootmem.h>
82231 #include <linux/hash.h>
82232+#include <linux/security.h>
82233 #include <linux/pid_namespace.h>
82234 #include <linux/init_task.h>
82235 #include <linux/syscalls.h>
82236@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
82237
82238 int pid_max = PID_MAX_DEFAULT;
82239
82240-#define RESERVED_PIDS 300
82241+#define RESERVED_PIDS 500
82242
82243 int pid_max_min = RESERVED_PIDS + 1;
82244 int pid_max_max = PID_MAX_LIMIT;
82245@@ -439,10 +440,18 @@ EXPORT_SYMBOL(pid_task);
82246 */
82247 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
82248 {
82249+ struct task_struct *task;
82250+
82251 rcu_lockdep_assert(rcu_read_lock_held(),
82252 "find_task_by_pid_ns() needs rcu_read_lock()"
82253 " protection");
82254- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
82255+
82256+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
82257+
82258+ if (gr_pid_is_chrooted(task))
82259+ return NULL;
82260+
82261+ return task;
82262 }
82263
82264 struct task_struct *find_task_by_vpid(pid_t vnr)
82265@@ -450,6 +459,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
82266 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
82267 }
82268
82269+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
82270+{
82271+ rcu_lockdep_assert(rcu_read_lock_held(),
82272+ "find_task_by_pid_ns() needs rcu_read_lock()"
82273+ " protection");
82274+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
82275+}
82276+
82277 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
82278 {
82279 struct pid *pid;
82280diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
82281index 601bb36..f7e6f34 100644
82282--- a/kernel/pid_namespace.c
82283+++ b/kernel/pid_namespace.c
82284@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
82285 void __user *buffer, size_t *lenp, loff_t *ppos)
82286 {
82287 struct pid_namespace *pid_ns = task_active_pid_ns(current);
82288- struct ctl_table tmp = *table;
82289+ ctl_table_no_const tmp = *table;
82290
82291 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
82292 return -EPERM;
82293diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
82294index c7f31aa..2b44977 100644
82295--- a/kernel/posix-cpu-timers.c
82296+++ b/kernel/posix-cpu-timers.c
82297@@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
82298
82299 static __init int init_posix_cpu_timers(void)
82300 {
82301- struct k_clock process = {
82302+ static struct k_clock process = {
82303 .clock_getres = process_cpu_clock_getres,
82304 .clock_get = process_cpu_clock_get,
82305 .timer_create = process_cpu_timer_create,
82306 .nsleep = process_cpu_nsleep,
82307 .nsleep_restart = process_cpu_nsleep_restart,
82308 };
82309- struct k_clock thread = {
82310+ static struct k_clock thread = {
82311 .clock_getres = thread_cpu_clock_getres,
82312 .clock_get = thread_cpu_clock_get,
82313 .timer_create = thread_cpu_timer_create,
82314diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
82315index 424c2d4..679242f 100644
82316--- a/kernel/posix-timers.c
82317+++ b/kernel/posix-timers.c
82318@@ -43,6 +43,7 @@
82319 #include <linux/hash.h>
82320 #include <linux/posix-clock.h>
82321 #include <linux/posix-timers.h>
82322+#include <linux/grsecurity.h>
82323 #include <linux/syscalls.h>
82324 #include <linux/wait.h>
82325 #include <linux/workqueue.h>
82326@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
82327 * which we beg off on and pass to do_sys_settimeofday().
82328 */
82329
82330-static struct k_clock posix_clocks[MAX_CLOCKS];
82331+static struct k_clock *posix_clocks[MAX_CLOCKS];
82332
82333 /*
82334 * These ones are defined below.
82335@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
82336 */
82337 static __init int init_posix_timers(void)
82338 {
82339- struct k_clock clock_realtime = {
82340+ static struct k_clock clock_realtime = {
82341 .clock_getres = hrtimer_get_res,
82342 .clock_get = posix_clock_realtime_get,
82343 .clock_set = posix_clock_realtime_set,
82344@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
82345 .timer_get = common_timer_get,
82346 .timer_del = common_timer_del,
82347 };
82348- struct k_clock clock_monotonic = {
82349+ static struct k_clock clock_monotonic = {
82350 .clock_getres = hrtimer_get_res,
82351 .clock_get = posix_ktime_get_ts,
82352 .nsleep = common_nsleep,
82353@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
82354 .timer_get = common_timer_get,
82355 .timer_del = common_timer_del,
82356 };
82357- struct k_clock clock_monotonic_raw = {
82358+ static struct k_clock clock_monotonic_raw = {
82359 .clock_getres = hrtimer_get_res,
82360 .clock_get = posix_get_monotonic_raw,
82361 };
82362- struct k_clock clock_realtime_coarse = {
82363+ static struct k_clock clock_realtime_coarse = {
82364 .clock_getres = posix_get_coarse_res,
82365 .clock_get = posix_get_realtime_coarse,
82366 };
82367- struct k_clock clock_monotonic_coarse = {
82368+ static struct k_clock clock_monotonic_coarse = {
82369 .clock_getres = posix_get_coarse_res,
82370 .clock_get = posix_get_monotonic_coarse,
82371 };
82372- struct k_clock clock_tai = {
82373+ static struct k_clock clock_tai = {
82374 .clock_getres = hrtimer_get_res,
82375 .clock_get = posix_get_tai,
82376 .nsleep = common_nsleep,
82377@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
82378 .timer_get = common_timer_get,
82379 .timer_del = common_timer_del,
82380 };
82381- struct k_clock clock_boottime = {
82382+ static struct k_clock clock_boottime = {
82383 .clock_getres = hrtimer_get_res,
82384 .clock_get = posix_get_boottime,
82385 .nsleep = common_nsleep,
82386@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
82387 return;
82388 }
82389
82390- posix_clocks[clock_id] = *new_clock;
82391+ posix_clocks[clock_id] = new_clock;
82392 }
82393 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
82394
82395@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
82396 return (id & CLOCKFD_MASK) == CLOCKFD ?
82397 &clock_posix_dynamic : &clock_posix_cpu;
82398
82399- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
82400+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
82401 return NULL;
82402- return &posix_clocks[id];
82403+ return posix_clocks[id];
82404 }
82405
82406 static int common_timer_create(struct k_itimer *new_timer)
82407@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
82408 struct k_clock *kc = clockid_to_kclock(which_clock);
82409 struct k_itimer *new_timer;
82410 int error, new_timer_id;
82411- sigevent_t event;
82412+ sigevent_t event = { };
82413 int it_id_set = IT_ID_NOT_SET;
82414
82415 if (!kc)
82416@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
82417 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
82418 return -EFAULT;
82419
82420+ /* only the CLOCK_REALTIME clock can be set, all other clocks
82421+ have their clock_set fptr set to a nosettime dummy function
82422+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
82423+ call common_clock_set, which calls do_sys_settimeofday, which
82424+ we hook
82425+ */
82426+
82427 return kc->clock_set(which_clock, &new_tp);
82428 }
82429
82430diff --git a/kernel/power/process.c b/kernel/power/process.c
82431index 06ec886..9dba35e 100644
82432--- a/kernel/power/process.c
82433+++ b/kernel/power/process.c
82434@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
82435 unsigned int elapsed_msecs;
82436 bool wakeup = false;
82437 int sleep_usecs = USEC_PER_MSEC;
82438+ bool timedout = false;
82439
82440 do_gettimeofday(&start);
82441
82442@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
82443
82444 while (true) {
82445 todo = 0;
82446+ if (time_after(jiffies, end_time))
82447+ timedout = true;
82448 read_lock(&tasklist_lock);
82449 do_each_thread(g, p) {
82450 if (p == current || !freeze_task(p))
82451 continue;
82452
82453- if (!freezer_should_skip(p))
82454+ if (!freezer_should_skip(p)) {
82455 todo++;
82456+ if (timedout) {
82457+ printk(KERN_ERR "Task refusing to freeze:\n");
82458+ sched_show_task(p);
82459+ }
82460+ }
82461 } while_each_thread(g, p);
82462 read_unlock(&tasklist_lock);
82463
82464@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
82465 todo += wq_busy;
82466 }
82467
82468- if (!todo || time_after(jiffies, end_time))
82469+ if (!todo || timedout)
82470 break;
82471
82472 if (pm_wakeup_pending()) {
82473diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
82474index 5b5a708..ec7637e 100644
82475--- a/kernel/printk/printk.c
82476+++ b/kernel/printk/printk.c
82477@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
82478 if (from_file && type != SYSLOG_ACTION_OPEN)
82479 return 0;
82480
82481+#ifdef CONFIG_GRKERNSEC_DMESG
82482+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
82483+ return -EPERM;
82484+#endif
82485+
82486 if (syslog_action_restricted(type)) {
82487 if (capable(CAP_SYSLOG))
82488 return 0;
82489diff --git a/kernel/profile.c b/kernel/profile.c
82490index 6631e1e..310c266 100644
82491--- a/kernel/profile.c
82492+++ b/kernel/profile.c
82493@@ -37,7 +37,7 @@ struct profile_hit {
82494 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
82495 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
82496
82497-static atomic_t *prof_buffer;
82498+static atomic_unchecked_t *prof_buffer;
82499 static unsigned long prof_len, prof_shift;
82500
82501 int prof_on __read_mostly;
82502@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
82503 hits[i].pc = 0;
82504 continue;
82505 }
82506- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82507+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82508 hits[i].hits = hits[i].pc = 0;
82509 }
82510 }
82511@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82512 * Add the current hit(s) and flush the write-queue out
82513 * to the global buffer:
82514 */
82515- atomic_add(nr_hits, &prof_buffer[pc]);
82516+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
82517 for (i = 0; i < NR_PROFILE_HIT; ++i) {
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].pc = hits[i].hits = 0;
82521 }
82522 out:
82523@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82524 {
82525 unsigned long pc;
82526 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
82527- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82528+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82529 }
82530 #endif /* !CONFIG_SMP */
82531
82532@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
82533 return -EFAULT;
82534 buf++; p++; count--; read++;
82535 }
82536- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
82537+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
82538 if (copy_to_user(buf, (void *)pnt, count))
82539 return -EFAULT;
82540 read += count;
82541@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
82542 }
82543 #endif
82544 profile_discard_flip_buffers();
82545- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
82546+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
82547 return count;
82548 }
82549
82550diff --git a/kernel/ptrace.c b/kernel/ptrace.c
82551index a146ee3..ffed4c3 100644
82552--- a/kernel/ptrace.c
82553+++ b/kernel/ptrace.c
82554@@ -326,7 +326,7 @@ static int ptrace_attach(struct task_struct *task, long request,
82555 if (seize)
82556 flags |= PT_SEIZED;
82557 rcu_read_lock();
82558- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82559+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82560 flags |= PT_PTRACE_CAP;
82561 rcu_read_unlock();
82562 task->ptrace = flags;
82563@@ -537,7 +537,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
82564 break;
82565 return -EIO;
82566 }
82567- if (copy_to_user(dst, buf, retval))
82568+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
82569 return -EFAULT;
82570 copied += retval;
82571 src += retval;
82572@@ -805,7 +805,7 @@ int ptrace_request(struct task_struct *child, long request,
82573 bool seized = child->ptrace & PT_SEIZED;
82574 int ret = -EIO;
82575 siginfo_t siginfo, *si;
82576- void __user *datavp = (void __user *) data;
82577+ void __user *datavp = (__force void __user *) data;
82578 unsigned long __user *datalp = datavp;
82579 unsigned long flags;
82580
82581@@ -1051,14 +1051,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
82582 goto out;
82583 }
82584
82585+ if (gr_handle_ptrace(child, request)) {
82586+ ret = -EPERM;
82587+ goto out_put_task_struct;
82588+ }
82589+
82590 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82591 ret = ptrace_attach(child, request, addr, data);
82592 /*
82593 * Some architectures need to do book-keeping after
82594 * a ptrace attach.
82595 */
82596- if (!ret)
82597+ if (!ret) {
82598 arch_ptrace_attach(child);
82599+ gr_audit_ptrace(child);
82600+ }
82601 goto out_put_task_struct;
82602 }
82603
82604@@ -1086,7 +1093,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
82605 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
82606 if (copied != sizeof(tmp))
82607 return -EIO;
82608- return put_user(tmp, (unsigned long __user *)data);
82609+ return put_user(tmp, (__force unsigned long __user *)data);
82610 }
82611
82612 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
82613@@ -1180,7 +1187,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
82614 }
82615
82616 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82617- compat_long_t addr, compat_long_t data)
82618+ compat_ulong_t addr, compat_ulong_t data)
82619 {
82620 struct task_struct *child;
82621 long ret;
82622@@ -1196,14 +1203,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82623 goto out;
82624 }
82625
82626+ if (gr_handle_ptrace(child, request)) {
82627+ ret = -EPERM;
82628+ goto out_put_task_struct;
82629+ }
82630+
82631 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82632 ret = ptrace_attach(child, request, addr, data);
82633 /*
82634 * Some architectures need to do book-keeping after
82635 * a ptrace attach.
82636 */
82637- if (!ret)
82638+ if (!ret) {
82639 arch_ptrace_attach(child);
82640+ gr_audit_ptrace(child);
82641+ }
82642 goto out_put_task_struct;
82643 }
82644
82645diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
82646index cce6ba8..7c758b1f 100644
82647--- a/kernel/rcupdate.c
82648+++ b/kernel/rcupdate.c
82649@@ -412,10 +412,10 @@ int rcu_jiffies_till_stall_check(void)
82650 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
82651 */
82652 if (till_stall_check < 3) {
82653- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
82654+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
82655 till_stall_check = 3;
82656 } else if (till_stall_check > 300) {
82657- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
82658+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
82659 till_stall_check = 300;
82660 }
82661 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
82662diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
82663index aa34411..78e5ccb 100644
82664--- a/kernel/rcutiny.c
82665+++ b/kernel/rcutiny.c
82666@@ -45,7 +45,7 @@
82667 /* Forward declarations for rcutiny_plugin.h. */
82668 struct rcu_ctrlblk;
82669 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
82670-static void rcu_process_callbacks(struct softirq_action *unused);
82671+static void rcu_process_callbacks(void);
82672 static void __call_rcu(struct rcu_head *head,
82673 void (*func)(struct rcu_head *rcu),
82674 struct rcu_ctrlblk *rcp);
82675@@ -309,7 +309,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
82676 false));
82677 }
82678
82679-static void rcu_process_callbacks(struct softirq_action *unused)
82680+static void rcu_process_callbacks(void)
82681 {
82682 __rcu_process_callbacks(&rcu_sched_ctrlblk);
82683 __rcu_process_callbacks(&rcu_bh_ctrlblk);
82684diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
82685index f4871e5..8ef5741 100644
82686--- a/kernel/rcutorture.c
82687+++ b/kernel/rcutorture.c
82688@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
82689 { 0 };
82690 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
82691 { 0 };
82692-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82693-static atomic_t n_rcu_torture_alloc;
82694-static atomic_t n_rcu_torture_alloc_fail;
82695-static atomic_t n_rcu_torture_free;
82696-static atomic_t n_rcu_torture_mberror;
82697-static atomic_t n_rcu_torture_error;
82698+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82699+static atomic_unchecked_t n_rcu_torture_alloc;
82700+static atomic_unchecked_t n_rcu_torture_alloc_fail;
82701+static atomic_unchecked_t n_rcu_torture_free;
82702+static atomic_unchecked_t n_rcu_torture_mberror;
82703+static atomic_unchecked_t n_rcu_torture_error;
82704 static long n_rcu_torture_barrier_error;
82705 static long n_rcu_torture_boost_ktrerror;
82706 static long n_rcu_torture_boost_rterror;
82707@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
82708
82709 spin_lock_bh(&rcu_torture_lock);
82710 if (list_empty(&rcu_torture_freelist)) {
82711- atomic_inc(&n_rcu_torture_alloc_fail);
82712+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
82713 spin_unlock_bh(&rcu_torture_lock);
82714 return NULL;
82715 }
82716- atomic_inc(&n_rcu_torture_alloc);
82717+ atomic_inc_unchecked(&n_rcu_torture_alloc);
82718 p = rcu_torture_freelist.next;
82719 list_del_init(p);
82720 spin_unlock_bh(&rcu_torture_lock);
82721@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
82722 static void
82723 rcu_torture_free(struct rcu_torture *p)
82724 {
82725- atomic_inc(&n_rcu_torture_free);
82726+ atomic_inc_unchecked(&n_rcu_torture_free);
82727 spin_lock_bh(&rcu_torture_lock);
82728 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
82729 spin_unlock_bh(&rcu_torture_lock);
82730@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
82731 i = rp->rtort_pipe_count;
82732 if (i > RCU_TORTURE_PIPE_LEN)
82733 i = RCU_TORTURE_PIPE_LEN;
82734- atomic_inc(&rcu_torture_wcount[i]);
82735+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82736 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82737 rp->rtort_mbtest = 0;
82738 rcu_torture_free(rp);
82739@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
82740 i = rp->rtort_pipe_count;
82741 if (i > RCU_TORTURE_PIPE_LEN)
82742 i = RCU_TORTURE_PIPE_LEN;
82743- atomic_inc(&rcu_torture_wcount[i]);
82744+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82745 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82746 rp->rtort_mbtest = 0;
82747 list_del(&rp->rtort_free);
82748@@ -952,7 +952,7 @@ rcu_torture_writer(void *arg)
82749 i = old_rp->rtort_pipe_count;
82750 if (i > RCU_TORTURE_PIPE_LEN)
82751 i = RCU_TORTURE_PIPE_LEN;
82752- atomic_inc(&rcu_torture_wcount[i]);
82753+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82754 old_rp->rtort_pipe_count++;
82755 cur_ops->deferred_free(old_rp);
82756 }
82757@@ -1038,7 +1038,7 @@ static void rcu_torture_timer(unsigned long unused)
82758 return;
82759 }
82760 if (p->rtort_mbtest == 0)
82761- atomic_inc(&n_rcu_torture_mberror);
82762+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82763 spin_lock(&rand_lock);
82764 cur_ops->read_delay(&rand);
82765 n_rcu_torture_timers++;
82766@@ -1108,7 +1108,7 @@ rcu_torture_reader(void *arg)
82767 continue;
82768 }
82769 if (p->rtort_mbtest == 0)
82770- atomic_inc(&n_rcu_torture_mberror);
82771+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82772 cur_ops->read_delay(&rand);
82773 preempt_disable();
82774 pipe_count = p->rtort_pipe_count;
82775@@ -1171,11 +1171,11 @@ rcu_torture_printk(char *page)
82776 rcu_torture_current,
82777 rcu_torture_current_version,
82778 list_empty(&rcu_torture_freelist),
82779- atomic_read(&n_rcu_torture_alloc),
82780- atomic_read(&n_rcu_torture_alloc_fail),
82781- atomic_read(&n_rcu_torture_free));
82782+ atomic_read_unchecked(&n_rcu_torture_alloc),
82783+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
82784+ atomic_read_unchecked(&n_rcu_torture_free));
82785 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
82786- atomic_read(&n_rcu_torture_mberror),
82787+ atomic_read_unchecked(&n_rcu_torture_mberror),
82788 n_rcu_torture_boost_ktrerror,
82789 n_rcu_torture_boost_rterror);
82790 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
82791@@ -1194,14 +1194,14 @@ rcu_torture_printk(char *page)
82792 n_barrier_attempts,
82793 n_rcu_torture_barrier_error);
82794 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
82795- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
82796+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
82797 n_rcu_torture_barrier_error != 0 ||
82798 n_rcu_torture_boost_ktrerror != 0 ||
82799 n_rcu_torture_boost_rterror != 0 ||
82800 n_rcu_torture_boost_failure != 0 ||
82801 i > 1) {
82802 cnt += sprintf(&page[cnt], "!!! ");
82803- atomic_inc(&n_rcu_torture_error);
82804+ atomic_inc_unchecked(&n_rcu_torture_error);
82805 WARN_ON_ONCE(1);
82806 }
82807 cnt += sprintf(&page[cnt], "Reader Pipe: ");
82808@@ -1215,7 +1215,7 @@ rcu_torture_printk(char *page)
82809 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
82810 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82811 cnt += sprintf(&page[cnt], " %d",
82812- atomic_read(&rcu_torture_wcount[i]));
82813+ atomic_read_unchecked(&rcu_torture_wcount[i]));
82814 }
82815 cnt += sprintf(&page[cnt], "\n");
82816 if (cur_ops->stats)
82817@@ -1924,7 +1924,7 @@ rcu_torture_cleanup(void)
82818
82819 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
82820
82821- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82822+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82823 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
82824 else if (n_online_successes != n_online_attempts ||
82825 n_offline_successes != n_offline_attempts)
82826@@ -1992,18 +1992,18 @@ rcu_torture_init(void)
82827
82828 rcu_torture_current = NULL;
82829 rcu_torture_current_version = 0;
82830- atomic_set(&n_rcu_torture_alloc, 0);
82831- atomic_set(&n_rcu_torture_alloc_fail, 0);
82832- atomic_set(&n_rcu_torture_free, 0);
82833- atomic_set(&n_rcu_torture_mberror, 0);
82834- atomic_set(&n_rcu_torture_error, 0);
82835+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
82836+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
82837+ atomic_set_unchecked(&n_rcu_torture_free, 0);
82838+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
82839+ atomic_set_unchecked(&n_rcu_torture_error, 0);
82840 n_rcu_torture_barrier_error = 0;
82841 n_rcu_torture_boost_ktrerror = 0;
82842 n_rcu_torture_boost_rterror = 0;
82843 n_rcu_torture_boost_failure = 0;
82844 n_rcu_torture_boosts = 0;
82845 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
82846- atomic_set(&rcu_torture_wcount[i], 0);
82847+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
82848 for_each_possible_cpu(cpu) {
82849 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82850 per_cpu(rcu_torture_count, cpu)[i] = 0;
82851diff --git a/kernel/rcutree.c b/kernel/rcutree.c
82852index 068de3a..df7da65 100644
82853--- a/kernel/rcutree.c
82854+++ b/kernel/rcutree.c
82855@@ -358,9 +358,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
82856 rcu_prepare_for_idle(smp_processor_id());
82857 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
82858 smp_mb__before_atomic_inc(); /* See above. */
82859- atomic_inc(&rdtp->dynticks);
82860+ atomic_inc_unchecked(&rdtp->dynticks);
82861 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
82862- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
82863+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
82864
82865 /*
82866 * It is illegal to enter an extended quiescent state while
82867@@ -496,10 +496,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
82868 int user)
82869 {
82870 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
82871- atomic_inc(&rdtp->dynticks);
82872+ atomic_inc_unchecked(&rdtp->dynticks);
82873 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
82874 smp_mb__after_atomic_inc(); /* See above. */
82875- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
82876+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
82877 rcu_cleanup_after_idle(smp_processor_id());
82878 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
82879 if (!user && !is_idle_task(current)) {
82880@@ -638,14 +638,14 @@ void rcu_nmi_enter(void)
82881 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
82882
82883 if (rdtp->dynticks_nmi_nesting == 0 &&
82884- (atomic_read(&rdtp->dynticks) & 0x1))
82885+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
82886 return;
82887 rdtp->dynticks_nmi_nesting++;
82888 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
82889- atomic_inc(&rdtp->dynticks);
82890+ atomic_inc_unchecked(&rdtp->dynticks);
82891 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
82892 smp_mb__after_atomic_inc(); /* See above. */
82893- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
82894+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
82895 }
82896
82897 /**
82898@@ -664,9 +664,9 @@ void rcu_nmi_exit(void)
82899 return;
82900 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
82901 smp_mb__before_atomic_inc(); /* See above. */
82902- atomic_inc(&rdtp->dynticks);
82903+ atomic_inc_unchecked(&rdtp->dynticks);
82904 smp_mb__after_atomic_inc(); /* Force delay to next write. */
82905- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
82906+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
82907 }
82908
82909 /**
82910@@ -680,7 +680,7 @@ int rcu_is_cpu_idle(void)
82911 int ret;
82912
82913 preempt_disable();
82914- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
82915+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
82916 preempt_enable();
82917 return ret;
82918 }
82919@@ -748,7 +748,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
82920 */
82921 static int dyntick_save_progress_counter(struct rcu_data *rdp)
82922 {
82923- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
82924+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
82925 return (rdp->dynticks_snap & 0x1) == 0;
82926 }
82927
82928@@ -763,7 +763,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
82929 unsigned int curr;
82930 unsigned int snap;
82931
82932- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
82933+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
82934 snap = (unsigned int)rdp->dynticks_snap;
82935
82936 /*
82937@@ -1351,9 +1351,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
82938 rdp = this_cpu_ptr(rsp->rda);
82939 rcu_preempt_check_blocked_tasks(rnp);
82940 rnp->qsmask = rnp->qsmaskinit;
82941- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
82942+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
82943 WARN_ON_ONCE(rnp->completed != rsp->completed);
82944- ACCESS_ONCE(rnp->completed) = rsp->completed;
82945+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
82946 if (rnp == rdp->mynode)
82947 __note_gp_changes(rsp, rnp, rdp);
82948 rcu_preempt_boost_start_gp(rnp);
82949@@ -1435,7 +1435,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
82950 */
82951 rcu_for_each_node_breadth_first(rsp, rnp) {
82952 raw_spin_lock_irq(&rnp->lock);
82953- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
82954+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
82955 rdp = this_cpu_ptr(rsp->rda);
82956 if (rnp == rdp->mynode)
82957 __note_gp_changes(rsp, rnp, rdp);
82958@@ -1765,7 +1765,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
82959 rsp->qlen += rdp->qlen;
82960 rdp->n_cbs_orphaned += rdp->qlen;
82961 rdp->qlen_lazy = 0;
82962- ACCESS_ONCE(rdp->qlen) = 0;
82963+ ACCESS_ONCE_RW(rdp->qlen) = 0;
82964 }
82965
82966 /*
82967@@ -2011,7 +2011,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
82968 }
82969 smp_mb(); /* List handling before counting for rcu_barrier(). */
82970 rdp->qlen_lazy -= count_lazy;
82971- ACCESS_ONCE(rdp->qlen) -= count;
82972+ ACCESS_ONCE_RW(rdp->qlen) -= count;
82973 rdp->n_cbs_invoked += count;
82974
82975 /* Reinstate batch limit if we have worked down the excess. */
82976@@ -2202,7 +2202,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
82977 /*
82978 * Do RCU core processing for the current CPU.
82979 */
82980-static void rcu_process_callbacks(struct softirq_action *unused)
82981+static void rcu_process_callbacks(void)
82982 {
82983 struct rcu_state *rsp;
82984
82985@@ -2325,7 +2325,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
82986 local_irq_restore(flags);
82987 return;
82988 }
82989- ACCESS_ONCE(rdp->qlen)++;
82990+ ACCESS_ONCE_RW(rdp->qlen)++;
82991 if (lazy)
82992 rdp->qlen_lazy++;
82993 else
82994@@ -2534,11 +2534,11 @@ void synchronize_sched_expedited(void)
82995 * counter wrap on a 32-bit system. Quite a few more CPUs would of
82996 * course be required on a 64-bit system.
82997 */
82998- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
82999+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
83000 (ulong)atomic_long_read(&rsp->expedited_done) +
83001 ULONG_MAX / 8)) {
83002 synchronize_sched();
83003- atomic_long_inc(&rsp->expedited_wrap);
83004+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
83005 return;
83006 }
83007
83008@@ -2546,7 +2546,7 @@ void synchronize_sched_expedited(void)
83009 * Take a ticket. Note that atomic_inc_return() implies a
83010 * full memory barrier.
83011 */
83012- snap = atomic_long_inc_return(&rsp->expedited_start);
83013+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
83014 firstsnap = snap;
83015 get_online_cpus();
83016 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
83017@@ -2559,14 +2559,14 @@ void synchronize_sched_expedited(void)
83018 synchronize_sched_expedited_cpu_stop,
83019 NULL) == -EAGAIN) {
83020 put_online_cpus();
83021- atomic_long_inc(&rsp->expedited_tryfail);
83022+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
83023
83024 /* Check to see if someone else did our work for us. */
83025 s = atomic_long_read(&rsp->expedited_done);
83026 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
83027 /* ensure test happens before caller kfree */
83028 smp_mb__before_atomic_inc(); /* ^^^ */
83029- atomic_long_inc(&rsp->expedited_workdone1);
83030+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
83031 return;
83032 }
83033
83034@@ -2575,7 +2575,7 @@ void synchronize_sched_expedited(void)
83035 udelay(trycount * num_online_cpus());
83036 } else {
83037 wait_rcu_gp(call_rcu_sched);
83038- atomic_long_inc(&rsp->expedited_normal);
83039+ atomic_long_inc_unchecked(&rsp->expedited_normal);
83040 return;
83041 }
83042
83043@@ -2584,7 +2584,7 @@ void synchronize_sched_expedited(void)
83044 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
83045 /* ensure test happens before caller kfree */
83046 smp_mb__before_atomic_inc(); /* ^^^ */
83047- atomic_long_inc(&rsp->expedited_workdone2);
83048+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
83049 return;
83050 }
83051
83052@@ -2596,10 +2596,10 @@ void synchronize_sched_expedited(void)
83053 * period works for us.
83054 */
83055 get_online_cpus();
83056- snap = atomic_long_read(&rsp->expedited_start);
83057+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
83058 smp_mb(); /* ensure read is before try_stop_cpus(). */
83059 }
83060- atomic_long_inc(&rsp->expedited_stoppedcpus);
83061+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
83062
83063 /*
83064 * Everyone up to our most recent fetch is covered by our grace
83065@@ -2608,16 +2608,16 @@ void synchronize_sched_expedited(void)
83066 * than we did already did their update.
83067 */
83068 do {
83069- atomic_long_inc(&rsp->expedited_done_tries);
83070+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
83071 s = atomic_long_read(&rsp->expedited_done);
83072 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
83073 /* ensure test happens before caller kfree */
83074 smp_mb__before_atomic_inc(); /* ^^^ */
83075- atomic_long_inc(&rsp->expedited_done_lost);
83076+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
83077 break;
83078 }
83079 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
83080- atomic_long_inc(&rsp->expedited_done_exit);
83081+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
83082
83083 put_online_cpus();
83084 }
83085@@ -2799,7 +2799,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
83086 * ACCESS_ONCE() to prevent the compiler from speculating
83087 * the increment to precede the early-exit check.
83088 */
83089- ACCESS_ONCE(rsp->n_barrier_done)++;
83090+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
83091 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
83092 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
83093 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
83094@@ -2849,7 +2849,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
83095
83096 /* Increment ->n_barrier_done to prevent duplicate work. */
83097 smp_mb(); /* Keep increment after above mechanism. */
83098- ACCESS_ONCE(rsp->n_barrier_done)++;
83099+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
83100 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
83101 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
83102 smp_mb(); /* Keep increment before caller's subsequent code. */
83103@@ -2894,10 +2894,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
83104 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
83105 init_callback_list(rdp);
83106 rdp->qlen_lazy = 0;
83107- ACCESS_ONCE(rdp->qlen) = 0;
83108+ ACCESS_ONCE_RW(rdp->qlen) = 0;
83109 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
83110 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
83111- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
83112+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
83113 rdp->cpu = cpu;
83114 rdp->rsp = rsp;
83115 rcu_boot_init_nocb_percpu_data(rdp);
83116@@ -2930,8 +2930,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
83117 rdp->blimit = blimit;
83118 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
83119 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
83120- atomic_set(&rdp->dynticks->dynticks,
83121- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
83122+ atomic_set_unchecked(&rdp->dynticks->dynticks,
83123+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
83124 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
83125
83126 /* Add CPU to rcu_node bitmasks. */
83127diff --git a/kernel/rcutree.h b/kernel/rcutree.h
83128index b383258..2440c1e 100644
83129--- a/kernel/rcutree.h
83130+++ b/kernel/rcutree.h
83131@@ -87,7 +87,7 @@ struct rcu_dynticks {
83132 long long dynticks_nesting; /* Track irq/process nesting level. */
83133 /* Process level is worth LLONG_MAX/2. */
83134 int dynticks_nmi_nesting; /* Track NMI nesting level. */
83135- atomic_t dynticks; /* Even value for idle, else odd. */
83136+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
83137 #ifdef CONFIG_RCU_FAST_NO_HZ
83138 bool all_lazy; /* Are all CPU's CBs lazy? */
83139 unsigned long nonlazy_posted;
83140@@ -419,17 +419,17 @@ struct rcu_state {
83141 /* _rcu_barrier(). */
83142 /* End of fields guarded by barrier_mutex. */
83143
83144- atomic_long_t expedited_start; /* Starting ticket. */
83145- atomic_long_t expedited_done; /* Done ticket. */
83146- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
83147- atomic_long_t expedited_tryfail; /* # acquisition failures. */
83148- atomic_long_t expedited_workdone1; /* # done by others #1. */
83149- atomic_long_t expedited_workdone2; /* # done by others #2. */
83150- atomic_long_t expedited_normal; /* # fallbacks to normal. */
83151- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
83152- atomic_long_t expedited_done_tries; /* # tries to update _done. */
83153- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
83154- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
83155+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
83156+ atomic_long_t expedited_done; /* Done ticket. */
83157+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
83158+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
83159+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
83160+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
83161+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
83162+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
83163+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
83164+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
83165+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
83166
83167 unsigned long jiffies_force_qs; /* Time at which to invoke */
83168 /* force_quiescent_state(). */
83169diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
83170index 769e12e..7b2139b 100644
83171--- a/kernel/rcutree_plugin.h
83172+++ b/kernel/rcutree_plugin.h
83173@@ -902,7 +902,7 @@ void synchronize_rcu_expedited(void)
83174
83175 /* Clean up and exit. */
83176 smp_mb(); /* ensure expedited GP seen before counter increment. */
83177- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
83178+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
83179 unlock_mb_ret:
83180 mutex_unlock(&sync_rcu_preempt_exp_mutex);
83181 mb_ret:
83182@@ -1476,7 +1476,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
83183 free_cpumask_var(cm);
83184 }
83185
83186-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
83187+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
83188 .store = &rcu_cpu_kthread_task,
83189 .thread_should_run = rcu_cpu_kthread_should_run,
83190 .thread_fn = rcu_cpu_kthread,
83191@@ -1941,7 +1941,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
83192 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
83193 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
83194 cpu, ticks_value, ticks_title,
83195- atomic_read(&rdtp->dynticks) & 0xfff,
83196+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
83197 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
83198 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
83199 fast_no_hz);
83200@@ -2104,7 +2104,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
83201
83202 /* Enqueue the callback on the nocb list and update counts. */
83203 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
83204- ACCESS_ONCE(*old_rhpp) = rhp;
83205+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
83206 atomic_long_add(rhcount, &rdp->nocb_q_count);
83207 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
83208
83209@@ -2244,12 +2244,12 @@ static int rcu_nocb_kthread(void *arg)
83210 * Extract queued callbacks, update counts, and wait
83211 * for a grace period to elapse.
83212 */
83213- ACCESS_ONCE(rdp->nocb_head) = NULL;
83214+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
83215 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
83216 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
83217 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
83218- ACCESS_ONCE(rdp->nocb_p_count) += c;
83219- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
83220+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
83221+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
83222 rcu_nocb_wait_gp(rdp);
83223
83224 /* Each pass through the following loop invokes a callback. */
83225@@ -2271,8 +2271,8 @@ static int rcu_nocb_kthread(void *arg)
83226 list = next;
83227 }
83228 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
83229- ACCESS_ONCE(rdp->nocb_p_count) -= c;
83230- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
83231+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
83232+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
83233 rdp->n_nocbs_invoked += c;
83234 }
83235 return 0;
83236@@ -2299,7 +2299,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
83237 t = kthread_run(rcu_nocb_kthread, rdp,
83238 "rcuo%c/%d", rsp->abbr, cpu);
83239 BUG_ON(IS_ERR(t));
83240- ACCESS_ONCE(rdp->nocb_kthread) = t;
83241+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
83242 }
83243 }
83244
83245diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
83246index cf6c174..a8f4b50 100644
83247--- a/kernel/rcutree_trace.c
83248+++ b/kernel/rcutree_trace.c
83249@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
83250 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
83251 rdp->passed_quiesce, rdp->qs_pending);
83252 seq_printf(m, " dt=%d/%llx/%d df=%lu",
83253- atomic_read(&rdp->dynticks->dynticks),
83254+ atomic_read_unchecked(&rdp->dynticks->dynticks),
83255 rdp->dynticks->dynticks_nesting,
83256 rdp->dynticks->dynticks_nmi_nesting,
83257 rdp->dynticks_fqs);
83258@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
83259 struct rcu_state *rsp = (struct rcu_state *)m->private;
83260
83261 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",
83262- atomic_long_read(&rsp->expedited_start),
83263+ atomic_long_read_unchecked(&rsp->expedited_start),
83264 atomic_long_read(&rsp->expedited_done),
83265- atomic_long_read(&rsp->expedited_wrap),
83266- atomic_long_read(&rsp->expedited_tryfail),
83267- atomic_long_read(&rsp->expedited_workdone1),
83268- atomic_long_read(&rsp->expedited_workdone2),
83269- atomic_long_read(&rsp->expedited_normal),
83270- atomic_long_read(&rsp->expedited_stoppedcpus),
83271- atomic_long_read(&rsp->expedited_done_tries),
83272- atomic_long_read(&rsp->expedited_done_lost),
83273- atomic_long_read(&rsp->expedited_done_exit));
83274+ atomic_long_read_unchecked(&rsp->expedited_wrap),
83275+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
83276+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
83277+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
83278+ atomic_long_read_unchecked(&rsp->expedited_normal),
83279+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
83280+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
83281+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
83282+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
83283 return 0;
83284 }
83285
83286diff --git a/kernel/resource.c b/kernel/resource.c
83287index 3f285dc..5755f62 100644
83288--- a/kernel/resource.c
83289+++ b/kernel/resource.c
83290@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
83291
83292 static int __init ioresources_init(void)
83293 {
83294+#ifdef CONFIG_GRKERNSEC_PROC_ADD
83295+#ifdef CONFIG_GRKERNSEC_PROC_USER
83296+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
83297+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
83298+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83299+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
83300+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
83301+#endif
83302+#else
83303 proc_create("ioports", 0, NULL, &proc_ioports_operations);
83304 proc_create("iomem", 0, NULL, &proc_iomem_operations);
83305+#endif
83306 return 0;
83307 }
83308 __initcall(ioresources_init);
83309diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
83310index 1d96dd0..994ff19 100644
83311--- a/kernel/rtmutex-tester.c
83312+++ b/kernel/rtmutex-tester.c
83313@@ -22,7 +22,7 @@
83314 #define MAX_RT_TEST_MUTEXES 8
83315
83316 static spinlock_t rttest_lock;
83317-static atomic_t rttest_event;
83318+static atomic_unchecked_t rttest_event;
83319
83320 struct test_thread_data {
83321 int opcode;
83322@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83323
83324 case RTTEST_LOCKCONT:
83325 td->mutexes[td->opdata] = 1;
83326- td->event = atomic_add_return(1, &rttest_event);
83327+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83328 return 0;
83329
83330 case RTTEST_RESET:
83331@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83332 return 0;
83333
83334 case RTTEST_RESETEVENT:
83335- atomic_set(&rttest_event, 0);
83336+ atomic_set_unchecked(&rttest_event, 0);
83337 return 0;
83338
83339 default:
83340@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83341 return ret;
83342
83343 td->mutexes[id] = 1;
83344- td->event = atomic_add_return(1, &rttest_event);
83345+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83346 rt_mutex_lock(&mutexes[id]);
83347- td->event = atomic_add_return(1, &rttest_event);
83348+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83349 td->mutexes[id] = 4;
83350 return 0;
83351
83352@@ -106,9 +106,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 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
83359- td->event = atomic_add_return(1, &rttest_event);
83360+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83361 td->mutexes[id] = ret ? 0 : 4;
83362 return ret ? -EINTR : 0;
83363
83364@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83365 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
83366 return ret;
83367
83368- td->event = atomic_add_return(1, &rttest_event);
83369+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83370 rt_mutex_unlock(&mutexes[id]);
83371- td->event = atomic_add_return(1, &rttest_event);
83372+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83373 td->mutexes[id] = 0;
83374 return 0;
83375
83376@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83377 break;
83378
83379 td->mutexes[dat] = 2;
83380- td->event = atomic_add_return(1, &rttest_event);
83381+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83382 break;
83383
83384 default:
83385@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83386 return;
83387
83388 td->mutexes[dat] = 3;
83389- td->event = atomic_add_return(1, &rttest_event);
83390+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83391 break;
83392
83393 case RTTEST_LOCKNOWAIT:
83394@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83395 return;
83396
83397 td->mutexes[dat] = 1;
83398- td->event = atomic_add_return(1, &rttest_event);
83399+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83400 return;
83401
83402 default:
83403diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
83404index 4a07353..66b5291 100644
83405--- a/kernel/sched/auto_group.c
83406+++ b/kernel/sched/auto_group.c
83407@@ -11,7 +11,7 @@
83408
83409 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
83410 static struct autogroup autogroup_default;
83411-static atomic_t autogroup_seq_nr;
83412+static atomic_unchecked_t autogroup_seq_nr;
83413
83414 void __init autogroup_init(struct task_struct *init_task)
83415 {
83416@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
83417
83418 kref_init(&ag->kref);
83419 init_rwsem(&ag->lock);
83420- ag->id = atomic_inc_return(&autogroup_seq_nr);
83421+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
83422 ag->tg = tg;
83423 #ifdef CONFIG_RT_GROUP_SCHED
83424 /*
83425diff --git a/kernel/sched/core.c b/kernel/sched/core.c
83426index 05c39f0..442e6fe 100644
83427--- a/kernel/sched/core.c
83428+++ b/kernel/sched/core.c
83429@@ -2885,7 +2885,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
83430 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83431 * or number of jiffies left till timeout) if completed.
83432 */
83433-long __sched
83434+long __sched __intentional_overflow(-1)
83435 wait_for_completion_interruptible_timeout(struct completion *x,
83436 unsigned long timeout)
83437 {
83438@@ -2902,7 +2902,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
83439 *
83440 * Return: -ERESTARTSYS if interrupted, 0 if completed.
83441 */
83442-int __sched wait_for_completion_killable(struct completion *x)
83443+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
83444 {
83445 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
83446 if (t == -ERESTARTSYS)
83447@@ -2923,7 +2923,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
83448 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83449 * or number of jiffies left till timeout) if completed.
83450 */
83451-long __sched
83452+long __sched __intentional_overflow(-1)
83453 wait_for_completion_killable_timeout(struct completion *x,
83454 unsigned long timeout)
83455 {
83456@@ -3149,6 +3149,8 @@ int can_nice(const struct task_struct *p, const int nice)
83457 /* convert nice value [19,-20] to rlimit style value [1,40] */
83458 int nice_rlim = 20 - nice;
83459
83460+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
83461+
83462 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
83463 capable(CAP_SYS_NICE));
83464 }
83465@@ -3182,7 +3184,8 @@ SYSCALL_DEFINE1(nice, int, increment)
83466 if (nice > 19)
83467 nice = 19;
83468
83469- if (increment < 0 && !can_nice(current, nice))
83470+ if (increment < 0 && (!can_nice(current, nice) ||
83471+ gr_handle_chroot_nice()))
83472 return -EPERM;
83473
83474 retval = security_task_setnice(current, nice);
83475@@ -3344,6 +3347,7 @@ recheck:
83476 unsigned long rlim_rtprio =
83477 task_rlimit(p, RLIMIT_RTPRIO);
83478
83479+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
83480 /* can't set/change the rt policy */
83481 if (policy != p->policy && !rlim_rtprio)
83482 return -EPERM;
83483@@ -4473,7 +4477,7 @@ static void migrate_tasks(unsigned int dead_cpu)
83484
83485 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
83486
83487-static struct ctl_table sd_ctl_dir[] = {
83488+static ctl_table_no_const sd_ctl_dir[] __read_only = {
83489 {
83490 .procname = "sched_domain",
83491 .mode = 0555,
83492@@ -4490,17 +4494,17 @@ static struct ctl_table sd_ctl_root[] = {
83493 {}
83494 };
83495
83496-static struct ctl_table *sd_alloc_ctl_entry(int n)
83497+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
83498 {
83499- struct ctl_table *entry =
83500+ ctl_table_no_const *entry =
83501 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
83502
83503 return entry;
83504 }
83505
83506-static void sd_free_ctl_entry(struct ctl_table **tablep)
83507+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
83508 {
83509- struct ctl_table *entry;
83510+ ctl_table_no_const *entry;
83511
83512 /*
83513 * In the intermediate directories, both the child directory and
83514@@ -4508,22 +4512,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
83515 * will always be set. In the lowest directory the names are
83516 * static strings and all have proc handlers.
83517 */
83518- for (entry = *tablep; entry->mode; entry++) {
83519- if (entry->child)
83520- sd_free_ctl_entry(&entry->child);
83521+ for (entry = tablep; entry->mode; entry++) {
83522+ if (entry->child) {
83523+ sd_free_ctl_entry(entry->child);
83524+ pax_open_kernel();
83525+ entry->child = NULL;
83526+ pax_close_kernel();
83527+ }
83528 if (entry->proc_handler == NULL)
83529 kfree(entry->procname);
83530 }
83531
83532- kfree(*tablep);
83533- *tablep = NULL;
83534+ kfree(tablep);
83535 }
83536
83537 static int min_load_idx = 0;
83538 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
83539
83540 static void
83541-set_table_entry(struct ctl_table *entry,
83542+set_table_entry(ctl_table_no_const *entry,
83543 const char *procname, void *data, int maxlen,
83544 umode_t mode, proc_handler *proc_handler,
83545 bool load_idx)
83546@@ -4543,7 +4550,7 @@ set_table_entry(struct ctl_table *entry,
83547 static struct ctl_table *
83548 sd_alloc_ctl_domain_table(struct sched_domain *sd)
83549 {
83550- struct ctl_table *table = sd_alloc_ctl_entry(13);
83551+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
83552
83553 if (table == NULL)
83554 return NULL;
83555@@ -4578,9 +4585,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
83556 return table;
83557 }
83558
83559-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
83560+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
83561 {
83562- struct ctl_table *entry, *table;
83563+ ctl_table_no_const *entry, *table;
83564 struct sched_domain *sd;
83565 int domain_num = 0, i;
83566 char buf[32];
83567@@ -4607,11 +4614,13 @@ static struct ctl_table_header *sd_sysctl_header;
83568 static void register_sched_domain_sysctl(void)
83569 {
83570 int i, cpu_num = num_possible_cpus();
83571- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
83572+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
83573 char buf[32];
83574
83575 WARN_ON(sd_ctl_dir[0].child);
83576+ pax_open_kernel();
83577 sd_ctl_dir[0].child = entry;
83578+ pax_close_kernel();
83579
83580 if (entry == NULL)
83581 return;
83582@@ -4634,8 +4643,12 @@ static void unregister_sched_domain_sysctl(void)
83583 if (sd_sysctl_header)
83584 unregister_sysctl_table(sd_sysctl_header);
83585 sd_sysctl_header = NULL;
83586- if (sd_ctl_dir[0].child)
83587- sd_free_ctl_entry(&sd_ctl_dir[0].child);
83588+ if (sd_ctl_dir[0].child) {
83589+ sd_free_ctl_entry(sd_ctl_dir[0].child);
83590+ pax_open_kernel();
83591+ sd_ctl_dir[0].child = NULL;
83592+ pax_close_kernel();
83593+ }
83594 }
83595 #else
83596 static void register_sched_domain_sysctl(void)
83597diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
83598index 68f1609..640ba13 100644
83599--- a/kernel/sched/fair.c
83600+++ b/kernel/sched/fair.c
83601@@ -869,7 +869,7 @@ void task_numa_fault(int node, int pages, bool migrated)
83602
83603 static void reset_ptenuma_scan(struct task_struct *p)
83604 {
83605- ACCESS_ONCE(p->mm->numa_scan_seq)++;
83606+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
83607 p->mm->numa_scan_offset = 0;
83608 }
83609
83610@@ -5727,7 +5727,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
83611 * run_rebalance_domains is triggered when needed from the scheduler tick.
83612 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
83613 */
83614-static void run_rebalance_domains(struct softirq_action *h)
83615+static void run_rebalance_domains(void)
83616 {
83617 int this_cpu = smp_processor_id();
83618 struct rq *this_rq = cpu_rq(this_cpu);
83619diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
83620index ef0a7b2..1b728c1 100644
83621--- a/kernel/sched/sched.h
83622+++ b/kernel/sched/sched.h
83623@@ -1004,7 +1004,7 @@ struct sched_class {
83624 #ifdef CONFIG_FAIR_GROUP_SCHED
83625 void (*task_move_group) (struct task_struct *p, int on_rq);
83626 #endif
83627-};
83628+} __do_const;
83629
83630 #define sched_class_highest (&stop_sched_class)
83631 #define for_each_class(class) \
83632diff --git a/kernel/signal.c b/kernel/signal.c
83633index 50e4107..08bcb94 100644
83634--- a/kernel/signal.c
83635+++ b/kernel/signal.c
83636@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
83637
83638 int print_fatal_signals __read_mostly;
83639
83640-static void __user *sig_handler(struct task_struct *t, int sig)
83641+static __sighandler_t sig_handler(struct task_struct *t, int sig)
83642 {
83643 return t->sighand->action[sig - 1].sa.sa_handler;
83644 }
83645
83646-static int sig_handler_ignored(void __user *handler, int sig)
83647+static int sig_handler_ignored(__sighandler_t handler, int sig)
83648 {
83649 /* Is it explicitly or implicitly ignored? */
83650 return handler == SIG_IGN ||
83651@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
83652
83653 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
83654 {
83655- void __user *handler;
83656+ __sighandler_t handler;
83657
83658 handler = sig_handler(t, sig);
83659
83660@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
83661 atomic_inc(&user->sigpending);
83662 rcu_read_unlock();
83663
83664+ if (!override_rlimit)
83665+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
83666+
83667 if (override_rlimit ||
83668 atomic_read(&user->sigpending) <=
83669 task_rlimit(t, RLIMIT_SIGPENDING)) {
83670@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
83671
83672 int unhandled_signal(struct task_struct *tsk, int sig)
83673 {
83674- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
83675+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
83676 if (is_global_init(tsk))
83677 return 1;
83678 if (handler != SIG_IGN && handler != SIG_DFL)
83679@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
83680 }
83681 }
83682
83683+ /* allow glibc communication via tgkill to other threads in our
83684+ thread group */
83685+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
83686+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
83687+ && gr_handle_signal(t, sig))
83688+ return -EPERM;
83689+
83690 return security_task_kill(t, info, sig, 0);
83691 }
83692
83693@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83694 return send_signal(sig, info, p, 1);
83695 }
83696
83697-static int
83698+int
83699 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83700 {
83701 return send_signal(sig, info, t, 0);
83702@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83703 unsigned long int flags;
83704 int ret, blocked, ignored;
83705 struct k_sigaction *action;
83706+ int is_unhandled = 0;
83707
83708 spin_lock_irqsave(&t->sighand->siglock, flags);
83709 action = &t->sighand->action[sig-1];
83710@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83711 }
83712 if (action->sa.sa_handler == SIG_DFL)
83713 t->signal->flags &= ~SIGNAL_UNKILLABLE;
83714+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
83715+ is_unhandled = 1;
83716 ret = specific_send_sig_info(sig, info, t);
83717 spin_unlock_irqrestore(&t->sighand->siglock, flags);
83718
83719+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
83720+ normal operation */
83721+ if (is_unhandled) {
83722+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
83723+ gr_handle_crash(t, sig);
83724+ }
83725+
83726 return ret;
83727 }
83728
83729@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83730 ret = check_kill_permission(sig, info, p);
83731 rcu_read_unlock();
83732
83733- if (!ret && sig)
83734+ if (!ret && sig) {
83735 ret = do_send_sig_info(sig, info, p, true);
83736+ if (!ret)
83737+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
83738+ }
83739
83740 return ret;
83741 }
83742@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
83743 int error = -ESRCH;
83744
83745 rcu_read_lock();
83746- p = find_task_by_vpid(pid);
83747+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
83748+ /* allow glibc communication via tgkill to other threads in our
83749+ thread group */
83750+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
83751+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
83752+ p = find_task_by_vpid_unrestricted(pid);
83753+ else
83754+#endif
83755+ p = find_task_by_vpid(pid);
83756 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
83757 error = check_kill_permission(sig, info, p);
83758 /*
83759@@ -3219,6 +3250,16 @@ int __save_altstack(stack_t __user *uss, unsigned long sp)
83760 __put_user(t->sas_ss_size, &uss->ss_size);
83761 }
83762
83763+#ifdef CONFIG_X86
83764+void __save_altstack_ex(stack_t __user *uss, unsigned long sp)
83765+{
83766+ struct task_struct *t = current;
83767+ put_user_ex((void __user *)t->sas_ss_sp, &uss->ss_sp);
83768+ put_user_ex(sas_ss_flags(sp), &uss->ss_flags);
83769+ put_user_ex(t->sas_ss_size, &uss->ss_size);
83770+}
83771+#endif
83772+
83773 #ifdef CONFIG_COMPAT
83774 COMPAT_SYSCALL_DEFINE2(sigaltstack,
83775 const compat_stack_t __user *, uss_ptr,
83776@@ -3240,8 +3281,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
83777 }
83778 seg = get_fs();
83779 set_fs(KERNEL_DS);
83780- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
83781- (stack_t __force __user *) &uoss,
83782+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
83783+ (stack_t __force_user *) &uoss,
83784 compat_user_stack_pointer());
83785 set_fs(seg);
83786 if (ret >= 0 && uoss_ptr) {
83787@@ -3268,6 +3309,16 @@ int __compat_save_altstack(compat_stack_t __user *uss, unsigned long sp)
83788 __put_user(sas_ss_flags(sp), &uss->ss_flags) |
83789 __put_user(t->sas_ss_size, &uss->ss_size);
83790 }
83791+
83792+#ifdef CONFIG_X86
83793+void __compat_save_altstack_ex(compat_stack_t __user *uss, unsigned long sp)
83794+{
83795+ struct task_struct *t = current;
83796+ put_user_ex(ptr_to_compat((void __user *)t->sas_ss_sp), &uss->ss_sp);
83797+ put_user_ex(sas_ss_flags(sp), &uss->ss_flags);
83798+ put_user_ex(t->sas_ss_size, &uss->ss_size);
83799+}
83800+#endif
83801 #endif
83802
83803 #ifdef __ARCH_WANT_SYS_SIGPENDING
83804diff --git a/kernel/smpboot.c b/kernel/smpboot.c
83805index eb89e18..a4e6792 100644
83806--- a/kernel/smpboot.c
83807+++ b/kernel/smpboot.c
83808@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
83809 }
83810 smpboot_unpark_thread(plug_thread, cpu);
83811 }
83812- list_add(&plug_thread->list, &hotplug_threads);
83813+ pax_list_add(&plug_thread->list, &hotplug_threads);
83814 out:
83815 mutex_unlock(&smpboot_threads_lock);
83816 return ret;
83817@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
83818 {
83819 get_online_cpus();
83820 mutex_lock(&smpboot_threads_lock);
83821- list_del(&plug_thread->list);
83822+ pax_list_del(&plug_thread->list);
83823 smpboot_destroy_threads(plug_thread);
83824 mutex_unlock(&smpboot_threads_lock);
83825 put_online_cpus();
83826diff --git a/kernel/softirq.c b/kernel/softirq.c
83827index be3d351..9e4d5f2 100644
83828--- a/kernel/softirq.c
83829+++ b/kernel/softirq.c
83830@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
83831 EXPORT_SYMBOL(irq_stat);
83832 #endif
83833
83834-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
83835+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
83836
83837 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
83838
83839-char *softirq_to_name[NR_SOFTIRQS] = {
83840+const char * const softirq_to_name[NR_SOFTIRQS] = {
83841 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
83842 "TASKLET", "SCHED", "HRTIMER", "RCU"
83843 };
83844@@ -248,7 +248,7 @@ restart:
83845 kstat_incr_softirqs_this_cpu(vec_nr);
83846
83847 trace_softirq_entry(vec_nr);
83848- h->action(h);
83849+ h->action();
83850 trace_softirq_exit(vec_nr);
83851 if (unlikely(prev_count != preempt_count())) {
83852 printk(KERN_ERR "huh, entered softirq %u %s %p"
83853@@ -403,7 +403,7 @@ void __raise_softirq_irqoff(unsigned int nr)
83854 or_softirq_pending(1UL << nr);
83855 }
83856
83857-void open_softirq(int nr, void (*action)(struct softirq_action *))
83858+void __init open_softirq(int nr, void (*action)(void))
83859 {
83860 softirq_vec[nr].action = action;
83861 }
83862@@ -459,7 +459,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
83863
83864 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
83865
83866-static void tasklet_action(struct softirq_action *a)
83867+static void tasklet_action(void)
83868 {
83869 struct tasklet_struct *list;
83870
83871@@ -494,7 +494,7 @@ static void tasklet_action(struct softirq_action *a)
83872 }
83873 }
83874
83875-static void tasklet_hi_action(struct softirq_action *a)
83876+static void tasklet_hi_action(void)
83877 {
83878 struct tasklet_struct *list;
83879
83880@@ -849,7 +849,7 @@ static struct notifier_block cpu_nfb = {
83881 .notifier_call = cpu_callback
83882 };
83883
83884-static struct smp_hotplug_thread softirq_threads = {
83885+static struct smp_hotplug_thread softirq_threads __read_only = {
83886 .store = &ksoftirqd,
83887 .thread_should_run = ksoftirqd_should_run,
83888 .thread_fn = run_ksoftirqd,
83889diff --git a/kernel/srcu.c b/kernel/srcu.c
83890index 01d5ccb..cdcbee6 100644
83891--- a/kernel/srcu.c
83892+++ b/kernel/srcu.c
83893@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
83894
83895 idx = ACCESS_ONCE(sp->completed) & 0x1;
83896 preempt_disable();
83897- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
83898+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
83899 smp_mb(); /* B */ /* Avoid leaking the critical section. */
83900- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
83901+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
83902 preempt_enable();
83903 return idx;
83904 }
83905diff --git a/kernel/sys.c b/kernel/sys.c
83906index 771129b..dc0c7e3 100644
83907--- a/kernel/sys.c
83908+++ b/kernel/sys.c
83909@@ -149,6 +149,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
83910 error = -EACCES;
83911 goto out;
83912 }
83913+
83914+ if (gr_handle_chroot_setpriority(p, niceval)) {
83915+ error = -EACCES;
83916+ goto out;
83917+ }
83918+
83919 no_nice = security_task_setnice(p, niceval);
83920 if (no_nice) {
83921 error = no_nice;
83922@@ -352,6 +358,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
83923 goto error;
83924 }
83925
83926+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
83927+ goto error;
83928+
83929 if (rgid != (gid_t) -1 ||
83930 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
83931 new->sgid = new->egid;
83932@@ -387,6 +396,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
83933 old = current_cred();
83934
83935 retval = -EPERM;
83936+
83937+ if (gr_check_group_change(kgid, kgid, kgid))
83938+ goto error;
83939+
83940 if (nsown_capable(CAP_SETGID))
83941 new->gid = new->egid = new->sgid = new->fsgid = kgid;
83942 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
83943@@ -404,7 +417,7 @@ error:
83944 /*
83945 * change the user struct in a credentials set to match the new UID
83946 */
83947-static int set_user(struct cred *new)
83948+int set_user(struct cred *new)
83949 {
83950 struct user_struct *new_user;
83951
83952@@ -484,6 +497,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
83953 goto error;
83954 }
83955
83956+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
83957+ goto error;
83958+
83959 if (!uid_eq(new->uid, old->uid)) {
83960 retval = set_user(new);
83961 if (retval < 0)
83962@@ -534,6 +550,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
83963 old = current_cred();
83964
83965 retval = -EPERM;
83966+
83967+ if (gr_check_crash_uid(kuid))
83968+ goto error;
83969+ if (gr_check_user_change(kuid, kuid, kuid))
83970+ goto error;
83971+
83972 if (nsown_capable(CAP_SETUID)) {
83973 new->suid = new->uid = kuid;
83974 if (!uid_eq(kuid, old->uid)) {
83975@@ -603,6 +625,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
83976 goto error;
83977 }
83978
83979+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
83980+ goto error;
83981+
83982 if (ruid != (uid_t) -1) {
83983 new->uid = kruid;
83984 if (!uid_eq(kruid, old->uid)) {
83985@@ -685,6 +710,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
83986 goto error;
83987 }
83988
83989+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
83990+ goto error;
83991+
83992 if (rgid != (gid_t) -1)
83993 new->gid = krgid;
83994 if (egid != (gid_t) -1)
83995@@ -746,12 +774,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
83996 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
83997 nsown_capable(CAP_SETUID)) {
83998 if (!uid_eq(kuid, old->fsuid)) {
83999+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
84000+ goto error;
84001+
84002 new->fsuid = kuid;
84003 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
84004 goto change_okay;
84005 }
84006 }
84007
84008+error:
84009 abort_creds(new);
84010 return old_fsuid;
84011
84012@@ -784,12 +816,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
84013 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
84014 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
84015 nsown_capable(CAP_SETGID)) {
84016+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
84017+ goto error;
84018+
84019 if (!gid_eq(kgid, old->fsgid)) {
84020 new->fsgid = kgid;
84021 goto change_okay;
84022 }
84023 }
84024
84025+error:
84026 abort_creds(new);
84027 return old_fsgid;
84028
84029@@ -1169,19 +1205,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
84030 return -EFAULT;
84031
84032 down_read(&uts_sem);
84033- error = __copy_to_user(&name->sysname, &utsname()->sysname,
84034+ error = __copy_to_user(name->sysname, &utsname()->sysname,
84035 __OLD_UTS_LEN);
84036 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
84037- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
84038+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
84039 __OLD_UTS_LEN);
84040 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
84041- error |= __copy_to_user(&name->release, &utsname()->release,
84042+ error |= __copy_to_user(name->release, &utsname()->release,
84043 __OLD_UTS_LEN);
84044 error |= __put_user(0, name->release + __OLD_UTS_LEN);
84045- error |= __copy_to_user(&name->version, &utsname()->version,
84046+ error |= __copy_to_user(name->version, &utsname()->version,
84047 __OLD_UTS_LEN);
84048 error |= __put_user(0, name->version + __OLD_UTS_LEN);
84049- error |= __copy_to_user(&name->machine, &utsname()->machine,
84050+ error |= __copy_to_user(name->machine, &utsname()->machine,
84051 __OLD_UTS_LEN);
84052 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
84053 up_read(&uts_sem);
84054@@ -1383,6 +1419,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
84055 */
84056 new_rlim->rlim_cur = 1;
84057 }
84058+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
84059+ is changed to a lower value. Since tasks can be created by the same
84060+ user in between this limit change and an execve by this task, force
84061+ a recheck only for this task by setting PF_NPROC_EXCEEDED
84062+ */
84063+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
84064+ tsk->flags |= PF_NPROC_EXCEEDED;
84065 }
84066 if (!retval) {
84067 if (old_rlim)
84068diff --git a/kernel/sysctl.c b/kernel/sysctl.c
84069index 07f6fc4..65fb3d4 100644
84070--- a/kernel/sysctl.c
84071+++ b/kernel/sysctl.c
84072@@ -93,7 +93,6 @@
84073
84074
84075 #if defined(CONFIG_SYSCTL)
84076-
84077 /* External variables not in a header file. */
84078 extern int sysctl_overcommit_memory;
84079 extern int sysctl_overcommit_ratio;
84080@@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
84081
84082 /* Constants used for minimum and maximum */
84083 #ifdef CONFIG_LOCKUP_DETECTOR
84084-static int sixty = 60;
84085+static int sixty __read_only = 60;
84086 #endif
84087
84088-static int zero;
84089-static int __maybe_unused one = 1;
84090-static int __maybe_unused two = 2;
84091-static int __maybe_unused three = 3;
84092-static unsigned long one_ul = 1;
84093-static int one_hundred = 100;
84094+static int neg_one __read_only = -1;
84095+static int zero __read_only = 0;
84096+static int __maybe_unused one __read_only = 1;
84097+static int __maybe_unused two __read_only = 2;
84098+static int __maybe_unused three __read_only = 3;
84099+static unsigned long one_ul __read_only = 1;
84100+static int one_hundred __read_only = 100;
84101 #ifdef CONFIG_PRINTK
84102-static int ten_thousand = 10000;
84103+static int ten_thousand __read_only = 10000;
84104 #endif
84105
84106 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
84107@@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
84108 void __user *buffer, size_t *lenp, loff_t *ppos);
84109 #endif
84110
84111-#ifdef CONFIG_PRINTK
84112 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84113 void __user *buffer, size_t *lenp, loff_t *ppos);
84114-#endif
84115
84116 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
84117 void __user *buffer, size_t *lenp, loff_t *ppos);
84118@@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
84119
84120 #endif
84121
84122+extern struct ctl_table grsecurity_table[];
84123+
84124 static struct ctl_table kern_table[];
84125 static struct ctl_table vm_table[];
84126 static struct ctl_table fs_table[];
84127@@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
84128 int sysctl_legacy_va_layout;
84129 #endif
84130
84131+#ifdef CONFIG_PAX_SOFTMODE
84132+static ctl_table pax_table[] = {
84133+ {
84134+ .procname = "softmode",
84135+ .data = &pax_softmode,
84136+ .maxlen = sizeof(unsigned int),
84137+ .mode = 0600,
84138+ .proc_handler = &proc_dointvec,
84139+ },
84140+
84141+ { }
84142+};
84143+#endif
84144+
84145 /* The default sysctl tables: */
84146
84147 static struct ctl_table sysctl_base_table[] = {
84148@@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
84149 #endif
84150
84151 static struct ctl_table kern_table[] = {
84152+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
84153+ {
84154+ .procname = "grsecurity",
84155+ .mode = 0500,
84156+ .child = grsecurity_table,
84157+ },
84158+#endif
84159+
84160+#ifdef CONFIG_PAX_SOFTMODE
84161+ {
84162+ .procname = "pax",
84163+ .mode = 0500,
84164+ .child = pax_table,
84165+ },
84166+#endif
84167+
84168 {
84169 .procname = "sched_child_runs_first",
84170 .data = &sysctl_sched_child_runs_first,
84171@@ -613,7 +643,7 @@ static struct ctl_table kern_table[] = {
84172 .data = &modprobe_path,
84173 .maxlen = KMOD_PATH_LEN,
84174 .mode = 0644,
84175- .proc_handler = proc_dostring,
84176+ .proc_handler = proc_dostring_modpriv,
84177 },
84178 {
84179 .procname = "modules_disabled",
84180@@ -780,16 +810,20 @@ static struct ctl_table kern_table[] = {
84181 .extra1 = &zero,
84182 .extra2 = &one,
84183 },
84184+#endif
84185 {
84186 .procname = "kptr_restrict",
84187 .data = &kptr_restrict,
84188 .maxlen = sizeof(int),
84189 .mode = 0644,
84190 .proc_handler = proc_dointvec_minmax_sysadmin,
84191+#ifdef CONFIG_GRKERNSEC_HIDESYM
84192+ .extra1 = &two,
84193+#else
84194 .extra1 = &zero,
84195+#endif
84196 .extra2 = &two,
84197 },
84198-#endif
84199 {
84200 .procname = "ngroups_max",
84201 .data = &ngroups_max,
84202@@ -1031,10 +1065,17 @@ static struct ctl_table kern_table[] = {
84203 */
84204 {
84205 .procname = "perf_event_paranoid",
84206- .data = &sysctl_perf_event_paranoid,
84207- .maxlen = sizeof(sysctl_perf_event_paranoid),
84208+ .data = &sysctl_perf_event_legitimately_concerned,
84209+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
84210 .mode = 0644,
84211- .proc_handler = proc_dointvec,
84212+ /* go ahead, be a hero */
84213+ .proc_handler = proc_dointvec_minmax_sysadmin,
84214+ .extra1 = &neg_one,
84215+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
84216+ .extra2 = &three,
84217+#else
84218+ .extra2 = &two,
84219+#endif
84220 },
84221 {
84222 .procname = "perf_event_mlock_kb",
84223@@ -1297,6 +1338,13 @@ static struct ctl_table vm_table[] = {
84224 .proc_handler = proc_dointvec_minmax,
84225 .extra1 = &zero,
84226 },
84227+ {
84228+ .procname = "heap_stack_gap",
84229+ .data = &sysctl_heap_stack_gap,
84230+ .maxlen = sizeof(sysctl_heap_stack_gap),
84231+ .mode = 0644,
84232+ .proc_handler = proc_doulongvec_minmax,
84233+ },
84234 #else
84235 {
84236 .procname = "nr_trim_pages",
84237@@ -1761,6 +1809,16 @@ int proc_dostring(struct ctl_table *table, int write,
84238 buffer, lenp, ppos);
84239 }
84240
84241+int proc_dostring_modpriv(struct ctl_table *table, int write,
84242+ void __user *buffer, size_t *lenp, loff_t *ppos)
84243+{
84244+ if (write && !capable(CAP_SYS_MODULE))
84245+ return -EPERM;
84246+
84247+ return _proc_do_string(table->data, table->maxlen, write,
84248+ buffer, lenp, ppos);
84249+}
84250+
84251 static size_t proc_skip_spaces(char **buf)
84252 {
84253 size_t ret;
84254@@ -1866,6 +1924,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
84255 len = strlen(tmp);
84256 if (len > *size)
84257 len = *size;
84258+ if (len > sizeof(tmp))
84259+ len = sizeof(tmp);
84260 if (copy_to_user(*buf, tmp, len))
84261 return -EFAULT;
84262 *size -= len;
84263@@ -2030,7 +2090,7 @@ int proc_dointvec(struct ctl_table *table, int write,
84264 static int proc_taint(struct ctl_table *table, int write,
84265 void __user *buffer, size_t *lenp, loff_t *ppos)
84266 {
84267- struct ctl_table t;
84268+ ctl_table_no_const t;
84269 unsigned long tmptaint = get_taint();
84270 int err;
84271
84272@@ -2058,7 +2118,6 @@ static int proc_taint(struct ctl_table *table, int write,
84273 return err;
84274 }
84275
84276-#ifdef CONFIG_PRINTK
84277 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84278 void __user *buffer, size_t *lenp, loff_t *ppos)
84279 {
84280@@ -2067,7 +2126,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84281
84282 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
84283 }
84284-#endif
84285
84286 struct do_proc_dointvec_minmax_conv_param {
84287 int *min;
84288@@ -2214,8 +2272,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
84289 *i = val;
84290 } else {
84291 val = convdiv * (*i) / convmul;
84292- if (!first)
84293+ if (!first) {
84294 err = proc_put_char(&buffer, &left, '\t');
84295+ if (err)
84296+ break;
84297+ }
84298 err = proc_put_long(&buffer, &left, val, false);
84299 if (err)
84300 break;
84301@@ -2611,6 +2672,12 @@ int proc_dostring(struct ctl_table *table, int write,
84302 return -ENOSYS;
84303 }
84304
84305+int proc_dostring_modpriv(struct ctl_table *table, int write,
84306+ void __user *buffer, size_t *lenp, loff_t *ppos)
84307+{
84308+ return -ENOSYS;
84309+}
84310+
84311 int proc_dointvec(struct ctl_table *table, int write,
84312 void __user *buffer, size_t *lenp, loff_t *ppos)
84313 {
84314@@ -2667,5 +2734,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
84315 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
84316 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
84317 EXPORT_SYMBOL(proc_dostring);
84318+EXPORT_SYMBOL(proc_dostring_modpriv);
84319 EXPORT_SYMBOL(proc_doulongvec_minmax);
84320 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
84321diff --git a/kernel/taskstats.c b/kernel/taskstats.c
84322index 145bb4d..b2aa969 100644
84323--- a/kernel/taskstats.c
84324+++ b/kernel/taskstats.c
84325@@ -28,9 +28,12 @@
84326 #include <linux/fs.h>
84327 #include <linux/file.h>
84328 #include <linux/pid_namespace.h>
84329+#include <linux/grsecurity.h>
84330 #include <net/genetlink.h>
84331 #include <linux/atomic.h>
84332
84333+extern int gr_is_taskstats_denied(int pid);
84334+
84335 /*
84336 * Maximum length of a cpumask that can be specified in
84337 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
84338@@ -570,6 +573,9 @@ err:
84339
84340 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
84341 {
84342+ if (gr_is_taskstats_denied(current->pid))
84343+ return -EACCES;
84344+
84345 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
84346 return cmd_attr_register_cpumask(info);
84347 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
84348diff --git a/kernel/time.c b/kernel/time.c
84349index 7c7964c..784a599 100644
84350--- a/kernel/time.c
84351+++ b/kernel/time.c
84352@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
84353 return error;
84354
84355 if (tz) {
84356+ /* we log in do_settimeofday called below, so don't log twice
84357+ */
84358+ if (!tv)
84359+ gr_log_timechange();
84360+
84361 sys_tz = *tz;
84362 update_vsyscall_tz();
84363 if (firsttime) {
84364@@ -502,7 +507,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
84365 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
84366 * value to a scaled second value.
84367 */
84368-unsigned long
84369+unsigned long __intentional_overflow(-1)
84370 timespec_to_jiffies(const struct timespec *value)
84371 {
84372 unsigned long sec = value->tv_sec;
84373diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
84374index eec50fc..65e5df6 100644
84375--- a/kernel/time/alarmtimer.c
84376+++ b/kernel/time/alarmtimer.c
84377@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
84378 struct platform_device *pdev;
84379 int error = 0;
84380 int i;
84381- struct k_clock alarm_clock = {
84382+ static struct k_clock alarm_clock = {
84383 .clock_getres = alarm_clock_getres,
84384 .clock_get = alarm_clock_get,
84385 .timer_create = alarm_timer_create,
84386diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
84387index 48b9fff..9e07e5f 100644
84388--- a/kernel/time/timekeeping.c
84389+++ b/kernel/time/timekeeping.c
84390@@ -15,6 +15,7 @@
84391 #include <linux/init.h>
84392 #include <linux/mm.h>
84393 #include <linux/sched.h>
84394+#include <linux/grsecurity.h>
84395 #include <linux/syscore_ops.h>
84396 #include <linux/clocksource.h>
84397 #include <linux/jiffies.h>
84398@@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
84399 if (!timespec_valid_strict(tv))
84400 return -EINVAL;
84401
84402+ gr_log_timechange();
84403+
84404 raw_spin_lock_irqsave(&timekeeper_lock, flags);
84405 write_seqcount_begin(&timekeeper_seq);
84406
84407diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
84408index 61ed862..3b52c65 100644
84409--- a/kernel/time/timer_list.c
84410+++ b/kernel/time/timer_list.c
84411@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
84412
84413 static void print_name_offset(struct seq_file *m, void *sym)
84414 {
84415+#ifdef CONFIG_GRKERNSEC_HIDESYM
84416+ SEQ_printf(m, "<%p>", NULL);
84417+#else
84418 char symname[KSYM_NAME_LEN];
84419
84420 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
84421 SEQ_printf(m, "<%pK>", sym);
84422 else
84423 SEQ_printf(m, "%s", symname);
84424+#endif
84425 }
84426
84427 static void
84428@@ -119,7 +123,11 @@ next_one:
84429 static void
84430 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
84431 {
84432+#ifdef CONFIG_GRKERNSEC_HIDESYM
84433+ SEQ_printf(m, " .base: %p\n", NULL);
84434+#else
84435 SEQ_printf(m, " .base: %pK\n", base);
84436+#endif
84437 SEQ_printf(m, " .index: %d\n",
84438 base->index);
84439 SEQ_printf(m, " .resolution: %Lu nsecs\n",
84440@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
84441 {
84442 struct proc_dir_entry *pe;
84443
84444+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84445+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
84446+#else
84447 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
84448+#endif
84449 if (!pe)
84450 return -ENOMEM;
84451 return 0;
84452diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
84453index 0b537f2..40d6c20 100644
84454--- a/kernel/time/timer_stats.c
84455+++ b/kernel/time/timer_stats.c
84456@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
84457 static unsigned long nr_entries;
84458 static struct entry entries[MAX_ENTRIES];
84459
84460-static atomic_t overflow_count;
84461+static atomic_unchecked_t overflow_count;
84462
84463 /*
84464 * The entries are in a hash-table, for fast lookup:
84465@@ -140,7 +140,7 @@ static void reset_entries(void)
84466 nr_entries = 0;
84467 memset(entries, 0, sizeof(entries));
84468 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
84469- atomic_set(&overflow_count, 0);
84470+ atomic_set_unchecked(&overflow_count, 0);
84471 }
84472
84473 static struct entry *alloc_entry(void)
84474@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84475 if (likely(entry))
84476 entry->count++;
84477 else
84478- atomic_inc(&overflow_count);
84479+ atomic_inc_unchecked(&overflow_count);
84480
84481 out_unlock:
84482 raw_spin_unlock_irqrestore(lock, flags);
84483@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84484
84485 static void print_name_offset(struct seq_file *m, unsigned long addr)
84486 {
84487+#ifdef CONFIG_GRKERNSEC_HIDESYM
84488+ seq_printf(m, "<%p>", NULL);
84489+#else
84490 char symname[KSYM_NAME_LEN];
84491
84492 if (lookup_symbol_name(addr, symname) < 0)
84493- seq_printf(m, "<%p>", (void *)addr);
84494+ seq_printf(m, "<%pK>", (void *)addr);
84495 else
84496 seq_printf(m, "%s", symname);
84497+#endif
84498 }
84499
84500 static int tstats_show(struct seq_file *m, void *v)
84501@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
84502
84503 seq_puts(m, "Timer Stats Version: v0.2\n");
84504 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
84505- if (atomic_read(&overflow_count))
84506+ if (atomic_read_unchecked(&overflow_count))
84507 seq_printf(m, "Overflow: %d entries\n",
84508- atomic_read(&overflow_count));
84509+ atomic_read_unchecked(&overflow_count));
84510
84511 for (i = 0; i < nr_entries; i++) {
84512 entry = entries + i;
84513@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
84514 {
84515 struct proc_dir_entry *pe;
84516
84517+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84518+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
84519+#else
84520 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
84521+#endif
84522 if (!pe)
84523 return -ENOMEM;
84524 return 0;
84525diff --git a/kernel/timer.c b/kernel/timer.c
84526index 4296d13..8998609 100644
84527--- a/kernel/timer.c
84528+++ b/kernel/timer.c
84529@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
84530 /*
84531 * This function runs timers and the timer-tq in bottom half context.
84532 */
84533-static void run_timer_softirq(struct softirq_action *h)
84534+static void run_timer_softirq(void)
84535 {
84536 struct tvec_base *base = __this_cpu_read(tvec_bases);
84537
84538@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
84539 *
84540 * In all cases the return value is guaranteed to be non-negative.
84541 */
84542-signed long __sched schedule_timeout(signed long timeout)
84543+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
84544 {
84545 struct timer_list timer;
84546 unsigned long expire;
84547diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
84548index b8b8560..75b1a09 100644
84549--- a/kernel/trace/blktrace.c
84550+++ b/kernel/trace/blktrace.c
84551@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
84552 struct blk_trace *bt = filp->private_data;
84553 char buf[16];
84554
84555- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
84556+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
84557
84558 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
84559 }
84560@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
84561 return 1;
84562
84563 bt = buf->chan->private_data;
84564- atomic_inc(&bt->dropped);
84565+ atomic_inc_unchecked(&bt->dropped);
84566 return 0;
84567 }
84568
84569@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
84570
84571 bt->dir = dir;
84572 bt->dev = dev;
84573- atomic_set(&bt->dropped, 0);
84574+ atomic_set_unchecked(&bt->dropped, 0);
84575
84576 ret = -EIO;
84577 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
84578diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
84579index a6d098c..bb8cf65 100644
84580--- a/kernel/trace/ftrace.c
84581+++ b/kernel/trace/ftrace.c
84582@@ -1950,12 +1950,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
84583 if (unlikely(ftrace_disabled))
84584 return 0;
84585
84586+ ret = ftrace_arch_code_modify_prepare();
84587+ FTRACE_WARN_ON(ret);
84588+ if (ret)
84589+ return 0;
84590+
84591 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
84592+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
84593 if (ret) {
84594 ftrace_bug(ret, ip);
84595- return 0;
84596 }
84597- return 1;
84598+ return ret ? 0 : 1;
84599 }
84600
84601 /*
84602@@ -4028,8 +4033,10 @@ static int ftrace_process_locs(struct module *mod,
84603 if (!count)
84604 return 0;
84605
84606+ pax_open_kernel();
84607 sort(start, count, sizeof(*start),
84608 ftrace_cmp_ips, ftrace_swap_ips);
84609+ pax_close_kernel();
84610
84611 start_pg = ftrace_allocate_pages(count);
84612 if (!start_pg)
84613@@ -4752,8 +4759,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
84614 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
84615
84616 static int ftrace_graph_active;
84617-static struct notifier_block ftrace_suspend_notifier;
84618-
84619 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
84620 {
84621 return 0;
84622@@ -4897,6 +4902,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
84623 return NOTIFY_DONE;
84624 }
84625
84626+static struct notifier_block ftrace_suspend_notifier = {
84627+ .notifier_call = ftrace_suspend_notifier_call
84628+};
84629+
84630 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84631 trace_func_graph_ent_t entryfunc)
84632 {
84633@@ -4910,7 +4919,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84634 goto out;
84635 }
84636
84637- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
84638 register_pm_notifier(&ftrace_suspend_notifier);
84639
84640 ftrace_graph_active++;
84641diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
84642index cc2f66f..05edd54 100644
84643--- a/kernel/trace/ring_buffer.c
84644+++ b/kernel/trace/ring_buffer.c
84645@@ -352,9 +352,9 @@ struct buffer_data_page {
84646 */
84647 struct buffer_page {
84648 struct list_head list; /* list of buffer pages */
84649- local_t write; /* index for next write */
84650+ local_unchecked_t write; /* index for next write */
84651 unsigned read; /* index for next read */
84652- local_t entries; /* entries on this page */
84653+ local_unchecked_t entries; /* entries on this page */
84654 unsigned long real_end; /* real end of data */
84655 struct buffer_data_page *page; /* Actual data page */
84656 };
84657@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
84658 unsigned long last_overrun;
84659 local_t entries_bytes;
84660 local_t entries;
84661- local_t overrun;
84662- local_t commit_overrun;
84663+ local_unchecked_t overrun;
84664+ local_unchecked_t commit_overrun;
84665 local_t dropped_events;
84666 local_t committing;
84667 local_t commits;
84668@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84669 *
84670 * We add a counter to the write field to denote this.
84671 */
84672- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
84673- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
84674+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
84675+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
84676
84677 /*
84678 * Just make sure we have seen our old_write and synchronize
84679@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84680 * cmpxchg to only update if an interrupt did not already
84681 * do it for us. If the cmpxchg fails, we don't care.
84682 */
84683- (void)local_cmpxchg(&next_page->write, old_write, val);
84684- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
84685+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
84686+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
84687
84688 /*
84689 * No need to worry about races with clearing out the commit.
84690@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
84691
84692 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
84693 {
84694- return local_read(&bpage->entries) & RB_WRITE_MASK;
84695+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
84696 }
84697
84698 static inline unsigned long rb_page_write(struct buffer_page *bpage)
84699 {
84700- return local_read(&bpage->write) & RB_WRITE_MASK;
84701+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
84702 }
84703
84704 static int
84705@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
84706 * bytes consumed in ring buffer from here.
84707 * Increment overrun to account for the lost events.
84708 */
84709- local_add(page_entries, &cpu_buffer->overrun);
84710+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
84711 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84712 }
84713
84714@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
84715 * it is our responsibility to update
84716 * the counters.
84717 */
84718- local_add(entries, &cpu_buffer->overrun);
84719+ local_add_unchecked(entries, &cpu_buffer->overrun);
84720 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84721
84722 /*
84723@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84724 if (tail == BUF_PAGE_SIZE)
84725 tail_page->real_end = 0;
84726
84727- local_sub(length, &tail_page->write);
84728+ local_sub_unchecked(length, &tail_page->write);
84729 return;
84730 }
84731
84732@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84733 rb_event_set_padding(event);
84734
84735 /* Set the write back to the previous setting */
84736- local_sub(length, &tail_page->write);
84737+ local_sub_unchecked(length, &tail_page->write);
84738 return;
84739 }
84740
84741@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84742
84743 /* Set write to end of buffer */
84744 length = (tail + length) - BUF_PAGE_SIZE;
84745- local_sub(length, &tail_page->write);
84746+ local_sub_unchecked(length, &tail_page->write);
84747 }
84748
84749 /*
84750@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84751 * about it.
84752 */
84753 if (unlikely(next_page == commit_page)) {
84754- local_inc(&cpu_buffer->commit_overrun);
84755+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84756 goto out_reset;
84757 }
84758
84759@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84760 cpu_buffer->tail_page) &&
84761 (cpu_buffer->commit_page ==
84762 cpu_buffer->reader_page))) {
84763- local_inc(&cpu_buffer->commit_overrun);
84764+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84765 goto out_reset;
84766 }
84767 }
84768@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84769 length += RB_LEN_TIME_EXTEND;
84770
84771 tail_page = cpu_buffer->tail_page;
84772- write = local_add_return(length, &tail_page->write);
84773+ write = local_add_return_unchecked(length, &tail_page->write);
84774
84775 /* set write to only the index of the write */
84776 write &= RB_WRITE_MASK;
84777@@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84778 kmemcheck_annotate_bitfield(event, bitfield);
84779 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
84780
84781- local_inc(&tail_page->entries);
84782+ local_inc_unchecked(&tail_page->entries);
84783
84784 /*
84785 * If this is the first commit on the page, then update
84786@@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84787
84788 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
84789 unsigned long write_mask =
84790- local_read(&bpage->write) & ~RB_WRITE_MASK;
84791+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
84792 unsigned long event_length = rb_event_length(event);
84793 /*
84794 * This is on the tail page. It is possible that
84795@@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84796 */
84797 old_index += write_mask;
84798 new_index += write_mask;
84799- index = local_cmpxchg(&bpage->write, old_index, new_index);
84800+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
84801 if (index == old_index) {
84802 /* update counters */
84803 local_sub(event_length, &cpu_buffer->entries_bytes);
84804@@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84805
84806 /* Do the likely case first */
84807 if (likely(bpage->page == (void *)addr)) {
84808- local_dec(&bpage->entries);
84809+ local_dec_unchecked(&bpage->entries);
84810 return;
84811 }
84812
84813@@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84814 start = bpage;
84815 do {
84816 if (bpage->page == (void *)addr) {
84817- local_dec(&bpage->entries);
84818+ local_dec_unchecked(&bpage->entries);
84819 return;
84820 }
84821 rb_inc_page(cpu_buffer, &bpage);
84822@@ -3139,7 +3139,7 @@ static inline unsigned long
84823 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
84824 {
84825 return local_read(&cpu_buffer->entries) -
84826- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
84827+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
84828 }
84829
84830 /**
84831@@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
84832 return 0;
84833
84834 cpu_buffer = buffer->buffers[cpu];
84835- ret = local_read(&cpu_buffer->overrun);
84836+ ret = local_read_unchecked(&cpu_buffer->overrun);
84837
84838 return ret;
84839 }
84840@@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
84841 return 0;
84842
84843 cpu_buffer = buffer->buffers[cpu];
84844- ret = local_read(&cpu_buffer->commit_overrun);
84845+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
84846
84847 return ret;
84848 }
84849@@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
84850 /* if you care about this being correct, lock the buffer */
84851 for_each_buffer_cpu(buffer, cpu) {
84852 cpu_buffer = buffer->buffers[cpu];
84853- overruns += local_read(&cpu_buffer->overrun);
84854+ overruns += local_read_unchecked(&cpu_buffer->overrun);
84855 }
84856
84857 return overruns;
84858@@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
84859 /*
84860 * Reset the reader page to size zero.
84861 */
84862- local_set(&cpu_buffer->reader_page->write, 0);
84863- local_set(&cpu_buffer->reader_page->entries, 0);
84864+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
84865+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
84866 local_set(&cpu_buffer->reader_page->page->commit, 0);
84867 cpu_buffer->reader_page->real_end = 0;
84868
84869@@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
84870 * want to compare with the last_overrun.
84871 */
84872 smp_mb();
84873- overwrite = local_read(&(cpu_buffer->overrun));
84874+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
84875
84876 /*
84877 * Here's the tricky part.
84878@@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
84879
84880 cpu_buffer->head_page
84881 = list_entry(cpu_buffer->pages, struct buffer_page, list);
84882- local_set(&cpu_buffer->head_page->write, 0);
84883- local_set(&cpu_buffer->head_page->entries, 0);
84884+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
84885+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
84886 local_set(&cpu_buffer->head_page->page->commit, 0);
84887
84888 cpu_buffer->head_page->read = 0;
84889@@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
84890
84891 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
84892 INIT_LIST_HEAD(&cpu_buffer->new_pages);
84893- local_set(&cpu_buffer->reader_page->write, 0);
84894- local_set(&cpu_buffer->reader_page->entries, 0);
84895+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
84896+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
84897 local_set(&cpu_buffer->reader_page->page->commit, 0);
84898 cpu_buffer->reader_page->read = 0;
84899
84900 local_set(&cpu_buffer->entries_bytes, 0);
84901- local_set(&cpu_buffer->overrun, 0);
84902- local_set(&cpu_buffer->commit_overrun, 0);
84903+ local_set_unchecked(&cpu_buffer->overrun, 0);
84904+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
84905 local_set(&cpu_buffer->dropped_events, 0);
84906 local_set(&cpu_buffer->entries, 0);
84907 local_set(&cpu_buffer->committing, 0);
84908@@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
84909 rb_init_page(bpage);
84910 bpage = reader->page;
84911 reader->page = *data_page;
84912- local_set(&reader->write, 0);
84913- local_set(&reader->entries, 0);
84914+ local_set_unchecked(&reader->write, 0);
84915+ local_set_unchecked(&reader->entries, 0);
84916 reader->read = 0;
84917 *data_page = bpage;
84918
84919diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
84920index 496f94d..754aeea 100644
84921--- a/kernel/trace/trace.c
84922+++ b/kernel/trace/trace.c
84923@@ -3335,7 +3335,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
84924 return 0;
84925 }
84926
84927-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
84928+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
84929 {
84930 /* do nothing if flag is already set */
84931 if (!!(trace_flags & mask) == !!enabled)
84932diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
84933index afaae41..64871f8 100644
84934--- a/kernel/trace/trace.h
84935+++ b/kernel/trace/trace.h
84936@@ -1025,7 +1025,7 @@ extern const char *__stop___trace_bprintk_fmt[];
84937 void trace_printk_init_buffers(void);
84938 void trace_printk_start_comm(void);
84939 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
84940-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
84941+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
84942
84943 /*
84944 * Normal trace_printk() and friends allocates special buffers
84945diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
84946index 26dc348..8708ca7 100644
84947--- a/kernel/trace/trace_clock.c
84948+++ b/kernel/trace/trace_clock.c
84949@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
84950 return now;
84951 }
84952
84953-static atomic64_t trace_counter;
84954+static atomic64_unchecked_t trace_counter;
84955
84956 /*
84957 * trace_clock_counter(): simply an atomic counter.
84958@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
84959 */
84960 u64 notrace trace_clock_counter(void)
84961 {
84962- return atomic64_add_return(1, &trace_counter);
84963+ return atomic64_inc_return_unchecked(&trace_counter);
84964 }
84965diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
84966index 29a7ebc..eb473cf 100644
84967--- a/kernel/trace/trace_events.c
84968+++ b/kernel/trace/trace_events.c
84969@@ -1778,10 +1778,6 @@ static LIST_HEAD(ftrace_module_file_list);
84970 struct ftrace_module_file_ops {
84971 struct list_head list;
84972 struct module *mod;
84973- struct file_operations id;
84974- struct file_operations enable;
84975- struct file_operations format;
84976- struct file_operations filter;
84977 };
84978
84979 static struct ftrace_module_file_ops *
84980@@ -1822,17 +1818,12 @@ trace_create_file_ops(struct module *mod)
84981
84982 file_ops->mod = mod;
84983
84984- file_ops->id = ftrace_event_id_fops;
84985- file_ops->id.owner = mod;
84986-
84987- file_ops->enable = ftrace_enable_fops;
84988- file_ops->enable.owner = mod;
84989-
84990- file_ops->filter = ftrace_event_filter_fops;
84991- file_ops->filter.owner = mod;
84992-
84993- file_ops->format = ftrace_event_format_fops;
84994- file_ops->format.owner = mod;
84995+ pax_open_kernel();
84996+ mod->trace_id.owner = mod;
84997+ mod->trace_enable.owner = mod;
84998+ mod->trace_filter.owner = mod;
84999+ mod->trace_format.owner = mod;
85000+ pax_close_kernel();
85001
85002 list_add(&file_ops->list, &ftrace_module_file_list);
85003
85004@@ -1925,8 +1916,8 @@ __trace_add_new_mod_event(struct ftrace_event_call *call,
85005 struct ftrace_module_file_ops *file_ops)
85006 {
85007 return __trace_add_new_event(call, tr,
85008- &file_ops->id, &file_ops->enable,
85009- &file_ops->filter, &file_ops->format);
85010+ &file_ops->mod->trace_id, &file_ops->mod->trace_enable,
85011+ &file_ops->mod->trace_filter, &file_ops->mod->trace_format);
85012 }
85013
85014 #else
85015diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
85016index b3dcfb2..ebee344 100644
85017--- a/kernel/trace/trace_mmiotrace.c
85018+++ b/kernel/trace/trace_mmiotrace.c
85019@@ -24,7 +24,7 @@ struct header_iter {
85020 static struct trace_array *mmio_trace_array;
85021 static bool overrun_detected;
85022 static unsigned long prev_overruns;
85023-static atomic_t dropped_count;
85024+static atomic_unchecked_t dropped_count;
85025
85026 static void mmio_reset_data(struct trace_array *tr)
85027 {
85028@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
85029
85030 static unsigned long count_overruns(struct trace_iterator *iter)
85031 {
85032- unsigned long cnt = atomic_xchg(&dropped_count, 0);
85033+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
85034 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
85035
85036 if (over > prev_overruns)
85037@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
85038 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
85039 sizeof(*entry), 0, pc);
85040 if (!event) {
85041- atomic_inc(&dropped_count);
85042+ atomic_inc_unchecked(&dropped_count);
85043 return;
85044 }
85045 entry = ring_buffer_event_data(event);
85046@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
85047 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
85048 sizeof(*entry), 0, pc);
85049 if (!event) {
85050- atomic_inc(&dropped_count);
85051+ atomic_inc_unchecked(&dropped_count);
85052 return;
85053 }
85054 entry = ring_buffer_event_data(event);
85055diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
85056index 34e7cba..6f9a729 100644
85057--- a/kernel/trace/trace_output.c
85058+++ b/kernel/trace/trace_output.c
85059@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
85060
85061 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
85062 if (!IS_ERR(p)) {
85063- p = mangle_path(s->buffer + s->len, p, "\n");
85064+ p = mangle_path(s->buffer + s->len, p, "\n\\");
85065 if (p) {
85066 s->len = p - s->buffer;
85067 return 1;
85068@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
85069 goto out;
85070 }
85071
85072+ pax_open_kernel();
85073 if (event->funcs->trace == NULL)
85074- event->funcs->trace = trace_nop_print;
85075+ *(void **)&event->funcs->trace = trace_nop_print;
85076 if (event->funcs->raw == NULL)
85077- event->funcs->raw = trace_nop_print;
85078+ *(void **)&event->funcs->raw = trace_nop_print;
85079 if (event->funcs->hex == NULL)
85080- event->funcs->hex = trace_nop_print;
85081+ *(void **)&event->funcs->hex = trace_nop_print;
85082 if (event->funcs->binary == NULL)
85083- event->funcs->binary = trace_nop_print;
85084+ *(void **)&event->funcs->binary = trace_nop_print;
85085+ pax_close_kernel();
85086
85087 key = event->type & (EVENT_HASHSIZE - 1);
85088
85089diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
85090index b20428c..4845a10 100644
85091--- a/kernel/trace/trace_stack.c
85092+++ b/kernel/trace/trace_stack.c
85093@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
85094 return;
85095
85096 /* we do not handle interrupt stacks yet */
85097- if (!object_is_on_stack(stack))
85098+ if (!object_starts_on_stack(stack))
85099 return;
85100
85101 local_irq_save(flags);
85102diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
85103index 9064b91..1f5d2f8 100644
85104--- a/kernel/user_namespace.c
85105+++ b/kernel/user_namespace.c
85106@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
85107 !kgid_has_mapping(parent_ns, group))
85108 return -EPERM;
85109
85110+#ifdef CONFIG_GRKERNSEC
85111+ /*
85112+ * This doesn't really inspire confidence:
85113+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
85114+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
85115+ * Increases kernel attack surface in areas developers
85116+ * previously cared little about ("low importance due
85117+ * to requiring "root" capability")
85118+ * To be removed when this code receives *proper* review
85119+ */
85120+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
85121+ !capable(CAP_SETGID))
85122+ return -EPERM;
85123+#endif
85124+
85125 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
85126 if (!ns)
85127 return -ENOMEM;
85128@@ -862,7 +877,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
85129 if (atomic_read(&current->mm->mm_users) > 1)
85130 return -EINVAL;
85131
85132- if (current->fs->users != 1)
85133+ if (atomic_read(&current->fs->users) != 1)
85134 return -EINVAL;
85135
85136 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
85137diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
85138index 4f69f9a..7c6f8f8 100644
85139--- a/kernel/utsname_sysctl.c
85140+++ b/kernel/utsname_sysctl.c
85141@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
85142 static int proc_do_uts_string(ctl_table *table, int write,
85143 void __user *buffer, size_t *lenp, loff_t *ppos)
85144 {
85145- struct ctl_table uts_table;
85146+ ctl_table_no_const uts_table;
85147 int r;
85148 memcpy(&uts_table, table, sizeof(uts_table));
85149 uts_table.data = get_uts(table, write);
85150diff --git a/kernel/watchdog.c b/kernel/watchdog.c
85151index 1241d8c..d5cfc28 100644
85152--- a/kernel/watchdog.c
85153+++ b/kernel/watchdog.c
85154@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
85155 static void watchdog_nmi_disable(unsigned int cpu) { return; }
85156 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
85157
85158-static struct smp_hotplug_thread watchdog_threads = {
85159+static struct smp_hotplug_thread watchdog_threads __read_only = {
85160 .store = &softlockup_watchdog,
85161 .thread_should_run = watchdog_should_run,
85162 .thread_fn = watchdog,
85163diff --git a/kernel/workqueue.c b/kernel/workqueue.c
85164index e93f7b9..989fcd7 100644
85165--- a/kernel/workqueue.c
85166+++ b/kernel/workqueue.c
85167@@ -4627,7 +4627,7 @@ static void rebind_workers(struct worker_pool *pool)
85168 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
85169 worker_flags |= WORKER_REBOUND;
85170 worker_flags &= ~WORKER_UNBOUND;
85171- ACCESS_ONCE(worker->flags) = worker_flags;
85172+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
85173 }
85174
85175 spin_unlock_irq(&pool->lock);
85176diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
85177index 1501aa5..e771896 100644
85178--- a/lib/Kconfig.debug
85179+++ b/lib/Kconfig.debug
85180@@ -836,7 +836,7 @@ config DEBUG_MUTEXES
85181
85182 config DEBUG_WW_MUTEX_SLOWPATH
85183 bool "Wait/wound mutex debugging: Slowpath testing"
85184- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85185+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85186 select DEBUG_LOCK_ALLOC
85187 select DEBUG_SPINLOCK
85188 select DEBUG_MUTEXES
85189@@ -849,7 +849,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
85190
85191 config DEBUG_LOCK_ALLOC
85192 bool "Lock debugging: detect incorrect freeing of live locks"
85193- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85194+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85195 select DEBUG_SPINLOCK
85196 select DEBUG_MUTEXES
85197 select LOCKDEP
85198@@ -863,7 +863,7 @@ config DEBUG_LOCK_ALLOC
85199
85200 config PROVE_LOCKING
85201 bool "Lock debugging: prove locking correctness"
85202- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85203+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85204 select LOCKDEP
85205 select DEBUG_SPINLOCK
85206 select DEBUG_MUTEXES
85207@@ -914,7 +914,7 @@ config LOCKDEP
85208
85209 config LOCK_STAT
85210 bool "Lock usage statistics"
85211- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85212+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85213 select LOCKDEP
85214 select DEBUG_SPINLOCK
85215 select DEBUG_MUTEXES
85216@@ -1357,6 +1357,7 @@ config LATENCYTOP
85217 depends on DEBUG_KERNEL
85218 depends on STACKTRACE_SUPPORT
85219 depends on PROC_FS
85220+ depends on !GRKERNSEC_HIDESYM
85221 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
85222 select KALLSYMS
85223 select KALLSYMS_ALL
85224@@ -1373,7 +1374,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
85225 config DEBUG_STRICT_USER_COPY_CHECKS
85226 bool "Strict user copy size checks"
85227 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
85228- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
85229+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
85230 help
85231 Enabling this option turns a certain set of sanity checks for user
85232 copy operations into compile time failures.
85233@@ -1483,7 +1484,7 @@ endmenu # runtime tests
85234
85235 config PROVIDE_OHCI1394_DMA_INIT
85236 bool "Remote debugging over FireWire early on boot"
85237- depends on PCI && X86
85238+ depends on PCI && X86 && !GRKERNSEC
85239 help
85240 If you want to debug problems which hang or crash the kernel early
85241 on boot and the crashing machine has a FireWire port, you can use
85242@@ -1512,7 +1513,7 @@ config PROVIDE_OHCI1394_DMA_INIT
85243
85244 config FIREWIRE_OHCI_REMOTE_DMA
85245 bool "Remote debugging over FireWire with firewire-ohci"
85246- depends on FIREWIRE_OHCI
85247+ depends on FIREWIRE_OHCI && !GRKERNSEC
85248 help
85249 This option lets you use the FireWire bus for remote debugging
85250 with help of the firewire-ohci driver. It enables unfiltered
85251diff --git a/lib/Makefile b/lib/Makefile
85252index 7baccfd..3ceb95f 100644
85253--- a/lib/Makefile
85254+++ b/lib/Makefile
85255@@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
85256
85257 obj-$(CONFIG_BTREE) += btree.o
85258 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
85259-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
85260+obj-y += list_debug.o
85261 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
85262
85263 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
85264diff --git a/lib/bitmap.c b/lib/bitmap.c
85265index 06f7e4f..f3cf2b0 100644
85266--- a/lib/bitmap.c
85267+++ b/lib/bitmap.c
85268@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
85269 {
85270 int c, old_c, totaldigits, ndigits, nchunks, nbits;
85271 u32 chunk;
85272- const char __user __force *ubuf = (const char __user __force *)buf;
85273+ const char __user *ubuf = (const char __force_user *)buf;
85274
85275 bitmap_zero(maskp, nmaskbits);
85276
85277@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
85278 {
85279 if (!access_ok(VERIFY_READ, ubuf, ulen))
85280 return -EFAULT;
85281- return __bitmap_parse((const char __force *)ubuf,
85282+ return __bitmap_parse((const char __force_kernel *)ubuf,
85283 ulen, 1, maskp, nmaskbits);
85284
85285 }
85286@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
85287 {
85288 unsigned a, b;
85289 int c, old_c, totaldigits;
85290- const char __user __force *ubuf = (const char __user __force *)buf;
85291+ const char __user *ubuf = (const char __force_user *)buf;
85292 int exp_digit, in_range;
85293
85294 totaldigits = c = 0;
85295@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
85296 {
85297 if (!access_ok(VERIFY_READ, ubuf, ulen))
85298 return -EFAULT;
85299- return __bitmap_parselist((const char __force *)ubuf,
85300+ return __bitmap_parselist((const char __force_kernel *)ubuf,
85301 ulen, 1, maskp, nmaskbits);
85302 }
85303 EXPORT_SYMBOL(bitmap_parselist_user);
85304diff --git a/lib/bug.c b/lib/bug.c
85305index 1686034..a9c00c8 100644
85306--- a/lib/bug.c
85307+++ b/lib/bug.c
85308@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
85309 return BUG_TRAP_TYPE_NONE;
85310
85311 bug = find_bug(bugaddr);
85312+ if (!bug)
85313+ return BUG_TRAP_TYPE_NONE;
85314
85315 file = NULL;
85316 line = 0;
85317diff --git a/lib/debugobjects.c b/lib/debugobjects.c
85318index 37061ed..da83f48 100644
85319--- a/lib/debugobjects.c
85320+++ b/lib/debugobjects.c
85321@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
85322 if (limit > 4)
85323 return;
85324
85325- is_on_stack = object_is_on_stack(addr);
85326+ is_on_stack = object_starts_on_stack(addr);
85327 if (is_on_stack == onstack)
85328 return;
85329
85330diff --git a/lib/devres.c b/lib/devres.c
85331index 8235331..5881053 100644
85332--- a/lib/devres.c
85333+++ b/lib/devres.c
85334@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
85335 void devm_iounmap(struct device *dev, void __iomem *addr)
85336 {
85337 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
85338- (void *)addr));
85339+ (void __force *)addr));
85340 iounmap(addr);
85341 }
85342 EXPORT_SYMBOL(devm_iounmap);
85343@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
85344 {
85345 ioport_unmap(addr);
85346 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
85347- devm_ioport_map_match, (void *)addr));
85348+ devm_ioport_map_match, (void __force *)addr));
85349 }
85350 EXPORT_SYMBOL(devm_ioport_unmap);
85351 #endif /* CONFIG_HAS_IOPORT */
85352diff --git a/lib/div64.c b/lib/div64.c
85353index a163b6c..9618fa5 100644
85354--- a/lib/div64.c
85355+++ b/lib/div64.c
85356@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
85357 EXPORT_SYMBOL(__div64_32);
85358
85359 #ifndef div_s64_rem
85360-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
85361+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
85362 {
85363 u64 quotient;
85364
85365@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
85366 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
85367 */
85368 #ifndef div64_u64
85369-u64 div64_u64(u64 dividend, u64 divisor)
85370+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
85371 {
85372 u32 high = divisor >> 32;
85373 u64 quot;
85374diff --git a/lib/dma-debug.c b/lib/dma-debug.c
85375index d87a17a..ac0d79a 100644
85376--- a/lib/dma-debug.c
85377+++ b/lib/dma-debug.c
85378@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
85379
85380 void dma_debug_add_bus(struct bus_type *bus)
85381 {
85382- struct notifier_block *nb;
85383+ notifier_block_no_const *nb;
85384
85385 if (global_disable)
85386 return;
85387@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
85388
85389 static void check_for_stack(struct device *dev, void *addr)
85390 {
85391- if (object_is_on_stack(addr))
85392+ if (object_starts_on_stack(addr))
85393 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
85394 "stack [addr=%p]\n", addr);
85395 }
85396diff --git a/lib/inflate.c b/lib/inflate.c
85397index 013a761..c28f3fc 100644
85398--- a/lib/inflate.c
85399+++ b/lib/inflate.c
85400@@ -269,7 +269,7 @@ static void free(void *where)
85401 malloc_ptr = free_mem_ptr;
85402 }
85403 #else
85404-#define malloc(a) kmalloc(a, GFP_KERNEL)
85405+#define malloc(a) kmalloc((a), GFP_KERNEL)
85406 #define free(a) kfree(a)
85407 #endif
85408
85409diff --git a/lib/ioremap.c b/lib/ioremap.c
85410index 0c9216c..863bd89 100644
85411--- a/lib/ioremap.c
85412+++ b/lib/ioremap.c
85413@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
85414 unsigned long next;
85415
85416 phys_addr -= addr;
85417- pmd = pmd_alloc(&init_mm, pud, addr);
85418+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
85419 if (!pmd)
85420 return -ENOMEM;
85421 do {
85422@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
85423 unsigned long next;
85424
85425 phys_addr -= addr;
85426- pud = pud_alloc(&init_mm, pgd, addr);
85427+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
85428 if (!pud)
85429 return -ENOMEM;
85430 do {
85431diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
85432index bd2bea9..6b3c95e 100644
85433--- a/lib/is_single_threaded.c
85434+++ b/lib/is_single_threaded.c
85435@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
85436 struct task_struct *p, *t;
85437 bool ret;
85438
85439+ if (!mm)
85440+ return true;
85441+
85442 if (atomic_read(&task->signal->live) != 1)
85443 return false;
85444
85445diff --git a/lib/kobject.c b/lib/kobject.c
85446index 4a1f33d..2f3ca75 100644
85447--- a/lib/kobject.c
85448+++ b/lib/kobject.c
85449@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
85450
85451
85452 static DEFINE_SPINLOCK(kobj_ns_type_lock);
85453-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
85454+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
85455
85456-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85457+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85458 {
85459 enum kobj_ns_type type = ops->type;
85460 int error;
85461diff --git a/lib/list_debug.c b/lib/list_debug.c
85462index c24c2f7..06e070b 100644
85463--- a/lib/list_debug.c
85464+++ b/lib/list_debug.c
85465@@ -11,7 +11,9 @@
85466 #include <linux/bug.h>
85467 #include <linux/kernel.h>
85468 #include <linux/rculist.h>
85469+#include <linux/mm.h>
85470
85471+#ifdef CONFIG_DEBUG_LIST
85472 /*
85473 * Insert a new entry between two known consecutive entries.
85474 *
85475@@ -19,21 +21,32 @@
85476 * the prev/next entries already!
85477 */
85478
85479-void __list_add(struct list_head *new,
85480- struct list_head *prev,
85481- struct list_head *next)
85482+static bool __list_add_debug(struct list_head *new,
85483+ struct list_head *prev,
85484+ struct list_head *next)
85485 {
85486- WARN(next->prev != prev,
85487+ if (WARN(next->prev != prev,
85488 "list_add corruption. next->prev should be "
85489 "prev (%p), but was %p. (next=%p).\n",
85490- prev, next->prev, next);
85491- WARN(prev->next != next,
85492+ prev, next->prev, next) ||
85493+ WARN(prev->next != next,
85494 "list_add corruption. prev->next should be "
85495 "next (%p), but was %p. (prev=%p).\n",
85496- next, prev->next, prev);
85497- WARN(new == prev || new == next,
85498- "list_add double add: new=%p, prev=%p, next=%p.\n",
85499- new, prev, next);
85500+ next, prev->next, prev) ||
85501+ WARN(new == prev || new == next,
85502+ "list_add double add: new=%p, prev=%p, next=%p.\n",
85503+ new, prev, next))
85504+ return false;
85505+ return true;
85506+}
85507+
85508+void __list_add(struct list_head *new,
85509+ struct list_head *prev,
85510+ struct list_head *next)
85511+{
85512+ if (!__list_add_debug(new, prev, next))
85513+ return;
85514+
85515 next->prev = new;
85516 new->next = next;
85517 new->prev = prev;
85518@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
85519 }
85520 EXPORT_SYMBOL(__list_add);
85521
85522-void __list_del_entry(struct list_head *entry)
85523+static bool __list_del_entry_debug(struct list_head *entry)
85524 {
85525 struct list_head *prev, *next;
85526
85527@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
85528 WARN(next->prev != entry,
85529 "list_del corruption. next->prev should be %p, "
85530 "but was %p\n", entry, next->prev))
85531+ return false;
85532+ return true;
85533+}
85534+
85535+void __list_del_entry(struct list_head *entry)
85536+{
85537+ if (!__list_del_entry_debug(entry))
85538 return;
85539
85540- __list_del(prev, next);
85541+ __list_del(entry->prev, entry->next);
85542 }
85543 EXPORT_SYMBOL(__list_del_entry);
85544
85545@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
85546 void __list_add_rcu(struct list_head *new,
85547 struct list_head *prev, struct list_head *next)
85548 {
85549- WARN(next->prev != prev,
85550- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
85551- prev, next->prev, next);
85552- WARN(prev->next != next,
85553- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
85554- next, prev->next, prev);
85555+ if (!__list_add_debug(new, prev, next))
85556+ return;
85557+
85558 new->next = next;
85559 new->prev = prev;
85560 rcu_assign_pointer(list_next_rcu(prev), new);
85561 next->prev = new;
85562 }
85563 EXPORT_SYMBOL(__list_add_rcu);
85564+#endif
85565+
85566+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
85567+{
85568+#ifdef CONFIG_DEBUG_LIST
85569+ if (!__list_add_debug(new, prev, next))
85570+ return;
85571+#endif
85572+
85573+ pax_open_kernel();
85574+ next->prev = new;
85575+ new->next = next;
85576+ new->prev = prev;
85577+ prev->next = new;
85578+ pax_close_kernel();
85579+}
85580+EXPORT_SYMBOL(__pax_list_add);
85581+
85582+void pax_list_del(struct list_head *entry)
85583+{
85584+#ifdef CONFIG_DEBUG_LIST
85585+ if (!__list_del_entry_debug(entry))
85586+ return;
85587+#endif
85588+
85589+ pax_open_kernel();
85590+ __list_del(entry->prev, entry->next);
85591+ entry->next = LIST_POISON1;
85592+ entry->prev = LIST_POISON2;
85593+ pax_close_kernel();
85594+}
85595+EXPORT_SYMBOL(pax_list_del);
85596+
85597+void pax_list_del_init(struct list_head *entry)
85598+{
85599+ pax_open_kernel();
85600+ __list_del(entry->prev, entry->next);
85601+ INIT_LIST_HEAD(entry);
85602+ pax_close_kernel();
85603+}
85604+EXPORT_SYMBOL(pax_list_del_init);
85605+
85606+void __pax_list_add_rcu(struct list_head *new,
85607+ struct list_head *prev, struct list_head *next)
85608+{
85609+#ifdef CONFIG_DEBUG_LIST
85610+ if (!__list_add_debug(new, prev, next))
85611+ return;
85612+#endif
85613+
85614+ pax_open_kernel();
85615+ new->next = next;
85616+ new->prev = prev;
85617+ rcu_assign_pointer(list_next_rcu(prev), new);
85618+ next->prev = new;
85619+ pax_close_kernel();
85620+}
85621+EXPORT_SYMBOL(__pax_list_add_rcu);
85622+
85623+void pax_list_del_rcu(struct list_head *entry)
85624+{
85625+#ifdef CONFIG_DEBUG_LIST
85626+ if (!__list_del_entry_debug(entry))
85627+ return;
85628+#endif
85629+
85630+ pax_open_kernel();
85631+ __list_del(entry->prev, entry->next);
85632+ entry->next = LIST_POISON1;
85633+ entry->prev = LIST_POISON2;
85634+ pax_close_kernel();
85635+}
85636+EXPORT_SYMBOL(pax_list_del_rcu);
85637diff --git a/lib/radix-tree.c b/lib/radix-tree.c
85638index e796429..6e38f9f 100644
85639--- a/lib/radix-tree.c
85640+++ b/lib/radix-tree.c
85641@@ -92,7 +92,7 @@ struct radix_tree_preload {
85642 int nr;
85643 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
85644 };
85645-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
85646+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
85647
85648 static inline void *ptr_to_indirect(void *ptr)
85649 {
85650diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
85651index bb2b201..46abaf9 100644
85652--- a/lib/strncpy_from_user.c
85653+++ b/lib/strncpy_from_user.c
85654@@ -21,7 +21,7 @@
85655 */
85656 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
85657 {
85658- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85659+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85660 long res = 0;
85661
85662 /*
85663diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
85664index a28df52..3d55877 100644
85665--- a/lib/strnlen_user.c
85666+++ b/lib/strnlen_user.c
85667@@ -26,7 +26,7 @@
85668 */
85669 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
85670 {
85671- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85672+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85673 long align, res = 0;
85674 unsigned long c;
85675
85676diff --git a/lib/swiotlb.c b/lib/swiotlb.c
85677index d23762e..e21eab2 100644
85678--- a/lib/swiotlb.c
85679+++ b/lib/swiotlb.c
85680@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
85681
85682 void
85683 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
85684- dma_addr_t dev_addr)
85685+ dma_addr_t dev_addr, struct dma_attrs *attrs)
85686 {
85687 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
85688
85689diff --git a/lib/usercopy.c b/lib/usercopy.c
85690index 4f5b1dd..7cab418 100644
85691--- a/lib/usercopy.c
85692+++ b/lib/usercopy.c
85693@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
85694 WARN(1, "Buffer overflow detected!\n");
85695 }
85696 EXPORT_SYMBOL(copy_from_user_overflow);
85697+
85698+void copy_to_user_overflow(void)
85699+{
85700+ WARN(1, "Buffer overflow detected!\n");
85701+}
85702+EXPORT_SYMBOL(copy_to_user_overflow);
85703diff --git a/lib/vsprintf.c b/lib/vsprintf.c
85704index 739a363..aa668d7 100644
85705--- a/lib/vsprintf.c
85706+++ b/lib/vsprintf.c
85707@@ -16,6 +16,9 @@
85708 * - scnprintf and vscnprintf
85709 */
85710
85711+#ifdef CONFIG_GRKERNSEC_HIDESYM
85712+#define __INCLUDED_BY_HIDESYM 1
85713+#endif
85714 #include <stdarg.h>
85715 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
85716 #include <linux/types.h>
85717@@ -1078,7 +1081,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
85718 return number(buf, end, *(const netdev_features_t *)addr, spec);
85719 }
85720
85721+#ifdef CONFIG_GRKERNSEC_HIDESYM
85722+int kptr_restrict __read_mostly = 2;
85723+#else
85724 int kptr_restrict __read_mostly;
85725+#endif
85726
85727 /*
85728 * Show a '%p' thing. A kernel extension is that the '%p' is followed
85729@@ -1091,6 +1098,7 @@ int kptr_restrict __read_mostly;
85730 * - 'f' For simple symbolic function names without offset
85731 * - 'S' For symbolic direct pointers with offset
85732 * - 's' For symbolic direct pointers without offset
85733+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
85734 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
85735 * - 'B' For backtraced symbolic direct pointers with offset
85736 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
85737@@ -1155,12 +1163,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85738
85739 if (!ptr && *fmt != 'K') {
85740 /*
85741- * Print (null) with the same width as a pointer so it makes
85742+ * Print (nil) with the same width as a pointer so it makes
85743 * tabular output look nice.
85744 */
85745 if (spec.field_width == -1)
85746 spec.field_width = default_width;
85747- return string(buf, end, "(null)", spec);
85748+ return string(buf, end, "(nil)", spec);
85749 }
85750
85751 switch (*fmt) {
85752@@ -1170,6 +1178,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85753 /* Fallthrough */
85754 case 'S':
85755 case 's':
85756+#ifdef CONFIG_GRKERNSEC_HIDESYM
85757+ break;
85758+#else
85759+ return symbol_string(buf, end, ptr, spec, fmt);
85760+#endif
85761+ case 'A':
85762 case 'B':
85763 return symbol_string(buf, end, ptr, spec, fmt);
85764 case 'R':
85765@@ -1225,6 +1239,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85766 va_end(va);
85767 return buf;
85768 }
85769+ case 'P':
85770+ break;
85771 case 'K':
85772 /*
85773 * %pK cannot be used in IRQ context because its test
85774@@ -1254,6 +1270,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85775 return number(buf, end,
85776 (unsigned long long) *((phys_addr_t *)ptr), spec);
85777 }
85778+
85779+#ifdef CONFIG_GRKERNSEC_HIDESYM
85780+ /* 'P' = approved pointers to copy to userland,
85781+ as in the /proc/kallsyms case, as we make it display nothing
85782+ for non-root users, and the real contents for root users
85783+ Also ignore 'K' pointers, since we force their NULLing for non-root users
85784+ above
85785+ */
85786+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
85787+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
85788+ dump_stack();
85789+ ptr = NULL;
85790+ }
85791+#endif
85792+
85793 spec.flags |= SMALL;
85794 if (spec.field_width == -1) {
85795 spec.field_width = default_width;
85796@@ -1977,11 +2008,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85797 typeof(type) value; \
85798 if (sizeof(type) == 8) { \
85799 args = PTR_ALIGN(args, sizeof(u32)); \
85800- *(u32 *)&value = *(u32 *)args; \
85801- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
85802+ *(u32 *)&value = *(const u32 *)args; \
85803+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
85804 } else { \
85805 args = PTR_ALIGN(args, sizeof(type)); \
85806- value = *(typeof(type) *)args; \
85807+ value = *(const typeof(type) *)args; \
85808 } \
85809 args += sizeof(type); \
85810 value; \
85811@@ -2044,7 +2075,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85812 case FORMAT_TYPE_STR: {
85813 const char *str_arg = args;
85814 args += strlen(str_arg) + 1;
85815- str = string(str, end, (char *)str_arg, spec);
85816+ str = string(str, end, str_arg, spec);
85817 break;
85818 }
85819
85820diff --git a/localversion-grsec b/localversion-grsec
85821new file mode 100644
85822index 0000000..7cd6065
85823--- /dev/null
85824+++ b/localversion-grsec
85825@@ -0,0 +1 @@
85826+-grsec
85827diff --git a/mm/Kconfig b/mm/Kconfig
85828index 8028dcc..9a2dbe7 100644
85829--- a/mm/Kconfig
85830+++ b/mm/Kconfig
85831@@ -317,10 +317,10 @@ config KSM
85832 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
85833
85834 config DEFAULT_MMAP_MIN_ADDR
85835- int "Low address space to protect from user allocation"
85836+ int "Low address space to protect from user allocation"
85837 depends on MMU
85838- default 4096
85839- help
85840+ default 65536
85841+ help
85842 This is the portion of low virtual memory which should be protected
85843 from userspace allocation. Keeping a user from writing to low pages
85844 can help reduce the impact of kernel NULL pointer bugs.
85845@@ -351,7 +351,7 @@ config MEMORY_FAILURE
85846
85847 config HWPOISON_INJECT
85848 tristate "HWPoison pages injector"
85849- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
85850+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
85851 select PROC_PAGE_MONITOR
85852
85853 config NOMMU_INITIAL_TRIM_EXCESS
85854diff --git a/mm/backing-dev.c b/mm/backing-dev.c
85855index e04454c..ca5be3e 100644
85856--- a/mm/backing-dev.c
85857+++ b/mm/backing-dev.c
85858@@ -12,7 +12,7 @@
85859 #include <linux/device.h>
85860 #include <trace/events/writeback.h>
85861
85862-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
85863+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
85864
85865 struct backing_dev_info default_backing_dev_info = {
85866 .name = "default",
85867@@ -522,7 +522,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
85868 return err;
85869
85870 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
85871- atomic_long_inc_return(&bdi_seq));
85872+ atomic_long_inc_return_unchecked(&bdi_seq));
85873 if (err) {
85874 bdi_destroy(bdi);
85875 return err;
85876diff --git a/mm/filemap.c b/mm/filemap.c
85877index 4b51ac1..5aa90ff 100644
85878--- a/mm/filemap.c
85879+++ b/mm/filemap.c
85880@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
85881 struct address_space *mapping = file->f_mapping;
85882
85883 if (!mapping->a_ops->readpage)
85884- return -ENOEXEC;
85885+ return -ENODEV;
85886 file_accessed(file);
85887 vma->vm_ops = &generic_file_vm_ops;
85888 return 0;
85889@@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
85890
85891 while (bytes) {
85892 char __user *buf = iov->iov_base + base;
85893- int copy = min(bytes, iov->iov_len - base);
85894+ size_t copy = min(bytes, iov->iov_len - base);
85895
85896 base = 0;
85897 left = __copy_from_user_inatomic(vaddr, buf, copy);
85898@@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
85899 BUG_ON(!in_atomic());
85900 kaddr = kmap_atomic(page);
85901 if (likely(i->nr_segs == 1)) {
85902- int left;
85903+ size_t left;
85904 char __user *buf = i->iov->iov_base + i->iov_offset;
85905 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
85906 copied = bytes - left;
85907@@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
85908
85909 kaddr = kmap(page);
85910 if (likely(i->nr_segs == 1)) {
85911- int left;
85912+ size_t left;
85913 char __user *buf = i->iov->iov_base + i->iov_offset;
85914 left = __copy_from_user(kaddr + offset, buf, bytes);
85915 copied = bytes - left;
85916@@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
85917 * zero-length segments (without overruning the iovec).
85918 */
85919 while (bytes || unlikely(i->count && !iov->iov_len)) {
85920- int copy;
85921+ size_t copy;
85922
85923 copy = min(bytes, iov->iov_len - base);
85924 BUG_ON(!i->count || i->count < copy);
85925@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
85926 *pos = i_size_read(inode);
85927
85928 if (limit != RLIM_INFINITY) {
85929+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
85930 if (*pos >= limit) {
85931 send_sig(SIGXFSZ, current, 0);
85932 return -EFBIG;
85933diff --git a/mm/fremap.c b/mm/fremap.c
85934index 5bff081..d8189a9 100644
85935--- a/mm/fremap.c
85936+++ b/mm/fremap.c
85937@@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
85938 retry:
85939 vma = find_vma(mm, start);
85940
85941+#ifdef CONFIG_PAX_SEGMEXEC
85942+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
85943+ goto out;
85944+#endif
85945+
85946 /*
85947 * Make sure the vma is shared, that it supports prefaulting,
85948 * and that the remapped range is valid and fully within
85949diff --git a/mm/highmem.c b/mm/highmem.c
85950index b32b70c..e512eb0 100644
85951--- a/mm/highmem.c
85952+++ b/mm/highmem.c
85953@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
85954 * So no dangers, even with speculative execution.
85955 */
85956 page = pte_page(pkmap_page_table[i]);
85957+ pax_open_kernel();
85958 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
85959-
85960+ pax_close_kernel();
85961 set_page_address(page, NULL);
85962 need_flush = 1;
85963 }
85964@@ -198,9 +199,11 @@ start:
85965 }
85966 }
85967 vaddr = PKMAP_ADDR(last_pkmap_nr);
85968+
85969+ pax_open_kernel();
85970 set_pte_at(&init_mm, vaddr,
85971 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
85972-
85973+ pax_close_kernel();
85974 pkmap_count[last_pkmap_nr] = 1;
85975 set_page_address(page, (void *)vaddr);
85976
85977diff --git a/mm/hugetlb.c b/mm/hugetlb.c
85978index b60f330..ee7de7e 100644
85979--- a/mm/hugetlb.c
85980+++ b/mm/hugetlb.c
85981@@ -2022,15 +2022,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
85982 struct hstate *h = &default_hstate;
85983 unsigned long tmp;
85984 int ret;
85985+ ctl_table_no_const hugetlb_table;
85986
85987 tmp = h->max_huge_pages;
85988
85989 if (write && h->order >= MAX_ORDER)
85990 return -EINVAL;
85991
85992- table->data = &tmp;
85993- table->maxlen = sizeof(unsigned long);
85994- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
85995+ hugetlb_table = *table;
85996+ hugetlb_table.data = &tmp;
85997+ hugetlb_table.maxlen = sizeof(unsigned long);
85998+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
85999 if (ret)
86000 goto out;
86001
86002@@ -2087,15 +2089,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
86003 struct hstate *h = &default_hstate;
86004 unsigned long tmp;
86005 int ret;
86006+ ctl_table_no_const hugetlb_table;
86007
86008 tmp = h->nr_overcommit_huge_pages;
86009
86010 if (write && h->order >= MAX_ORDER)
86011 return -EINVAL;
86012
86013- table->data = &tmp;
86014- table->maxlen = sizeof(unsigned long);
86015- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
86016+ hugetlb_table = *table;
86017+ hugetlb_table.data = &tmp;
86018+ hugetlb_table.maxlen = sizeof(unsigned long);
86019+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
86020 if (ret)
86021 goto out;
86022
86023@@ -2545,6 +2549,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
86024 return 1;
86025 }
86026
86027+#ifdef CONFIG_PAX_SEGMEXEC
86028+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
86029+{
86030+ struct mm_struct *mm = vma->vm_mm;
86031+ struct vm_area_struct *vma_m;
86032+ unsigned long address_m;
86033+ pte_t *ptep_m;
86034+
86035+ vma_m = pax_find_mirror_vma(vma);
86036+ if (!vma_m)
86037+ return;
86038+
86039+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86040+ address_m = address + SEGMEXEC_TASK_SIZE;
86041+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
86042+ get_page(page_m);
86043+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
86044+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
86045+}
86046+#endif
86047+
86048 /*
86049 * Hugetlb_cow() should be called with page lock of the original hugepage held.
86050 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
86051@@ -2663,6 +2688,11 @@ retry_avoidcopy:
86052 make_huge_pte(vma, new_page, 1));
86053 page_remove_rmap(old_page);
86054 hugepage_add_new_anon_rmap(new_page, vma, address);
86055+
86056+#ifdef CONFIG_PAX_SEGMEXEC
86057+ pax_mirror_huge_pte(vma, address, new_page);
86058+#endif
86059+
86060 /* Make the old page be freed below */
86061 new_page = old_page;
86062 }
86063@@ -2821,6 +2851,10 @@ retry:
86064 && (vma->vm_flags & VM_SHARED)));
86065 set_huge_pte_at(mm, address, ptep, new_pte);
86066
86067+#ifdef CONFIG_PAX_SEGMEXEC
86068+ pax_mirror_huge_pte(vma, address, page);
86069+#endif
86070+
86071 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
86072 /* Optimization, do the COW without a second fault */
86073 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
86074@@ -2850,6 +2884,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86075 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
86076 struct hstate *h = hstate_vma(vma);
86077
86078+#ifdef CONFIG_PAX_SEGMEXEC
86079+ struct vm_area_struct *vma_m;
86080+#endif
86081+
86082 address &= huge_page_mask(h);
86083
86084 ptep = huge_pte_offset(mm, address);
86085@@ -2863,6 +2901,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86086 VM_FAULT_SET_HINDEX(hstate_index(h));
86087 }
86088
86089+#ifdef CONFIG_PAX_SEGMEXEC
86090+ vma_m = pax_find_mirror_vma(vma);
86091+ if (vma_m) {
86092+ unsigned long address_m;
86093+
86094+ if (vma->vm_start > vma_m->vm_start) {
86095+ address_m = address;
86096+ address -= SEGMEXEC_TASK_SIZE;
86097+ vma = vma_m;
86098+ h = hstate_vma(vma);
86099+ } else
86100+ address_m = address + SEGMEXEC_TASK_SIZE;
86101+
86102+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
86103+ return VM_FAULT_OOM;
86104+ address_m &= HPAGE_MASK;
86105+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
86106+ }
86107+#endif
86108+
86109 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
86110 if (!ptep)
86111 return VM_FAULT_OOM;
86112diff --git a/mm/internal.h b/mm/internal.h
86113index 4390ac6..fc60373c 100644
86114--- a/mm/internal.h
86115+++ b/mm/internal.h
86116@@ -95,6 +95,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
86117 * in mm/page_alloc.c
86118 */
86119 extern void __free_pages_bootmem(struct page *page, unsigned int order);
86120+extern void free_compound_page(struct page *page);
86121 extern void prep_compound_page(struct page *page, unsigned long order);
86122 #ifdef CONFIG_MEMORY_FAILURE
86123 extern bool is_free_buddy_page(struct page *page);
86124@@ -350,7 +351,7 @@ extern u32 hwpoison_filter_enable;
86125
86126 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
86127 unsigned long, unsigned long,
86128- unsigned long, unsigned long);
86129+ unsigned long, unsigned long) __intentional_overflow(-1);
86130
86131 extern void set_pageblock_order(void);
86132 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
86133diff --git a/mm/kmemleak.c b/mm/kmemleak.c
86134index c8d7f31..2dbeffd 100644
86135--- a/mm/kmemleak.c
86136+++ b/mm/kmemleak.c
86137@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
86138
86139 for (i = 0; i < object->trace_len; i++) {
86140 void *ptr = (void *)object->trace[i];
86141- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
86142+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
86143 }
86144 }
86145
86146@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
86147 return -ENOMEM;
86148 }
86149
86150- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
86151+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
86152 &kmemleak_fops);
86153 if (!dentry)
86154 pr_warning("Failed to create the debugfs kmemleak file\n");
86155diff --git a/mm/maccess.c b/mm/maccess.c
86156index d53adf9..03a24bf 100644
86157--- a/mm/maccess.c
86158+++ b/mm/maccess.c
86159@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
86160 set_fs(KERNEL_DS);
86161 pagefault_disable();
86162 ret = __copy_from_user_inatomic(dst,
86163- (__force const void __user *)src, size);
86164+ (const void __force_user *)src, size);
86165 pagefault_enable();
86166 set_fs(old_fs);
86167
86168@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
86169
86170 set_fs(KERNEL_DS);
86171 pagefault_disable();
86172- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
86173+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
86174 pagefault_enable();
86175 set_fs(old_fs);
86176
86177diff --git a/mm/madvise.c b/mm/madvise.c
86178index 7055883..aafb1ed 100644
86179--- a/mm/madvise.c
86180+++ b/mm/madvise.c
86181@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
86182 pgoff_t pgoff;
86183 unsigned long new_flags = vma->vm_flags;
86184
86185+#ifdef CONFIG_PAX_SEGMEXEC
86186+ struct vm_area_struct *vma_m;
86187+#endif
86188+
86189 switch (behavior) {
86190 case MADV_NORMAL:
86191 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
86192@@ -126,6 +130,13 @@ success:
86193 /*
86194 * vm_flags is protected by the mmap_sem held in write mode.
86195 */
86196+
86197+#ifdef CONFIG_PAX_SEGMEXEC
86198+ vma_m = pax_find_mirror_vma(vma);
86199+ if (vma_m)
86200+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
86201+#endif
86202+
86203 vma->vm_flags = new_flags;
86204
86205 out:
86206@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
86207 struct vm_area_struct ** prev,
86208 unsigned long start, unsigned long end)
86209 {
86210+
86211+#ifdef CONFIG_PAX_SEGMEXEC
86212+ struct vm_area_struct *vma_m;
86213+#endif
86214+
86215 *prev = vma;
86216 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
86217 return -EINVAL;
86218@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
86219 zap_page_range(vma, start, end - start, &details);
86220 } else
86221 zap_page_range(vma, start, end - start, NULL);
86222+
86223+#ifdef CONFIG_PAX_SEGMEXEC
86224+ vma_m = pax_find_mirror_vma(vma);
86225+ if (vma_m) {
86226+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
86227+ struct zap_details details = {
86228+ .nonlinear_vma = vma_m,
86229+ .last_index = ULONG_MAX,
86230+ };
86231+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
86232+ } else
86233+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
86234+ }
86235+#endif
86236+
86237 return 0;
86238 }
86239
86240@@ -485,6 +516,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
86241 if (end < start)
86242 return error;
86243
86244+#ifdef CONFIG_PAX_SEGMEXEC
86245+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
86246+ if (end > SEGMEXEC_TASK_SIZE)
86247+ return error;
86248+ } else
86249+#endif
86250+
86251+ if (end > TASK_SIZE)
86252+ return error;
86253+
86254 error = 0;
86255 if (end == start)
86256 return error;
86257diff --git a/mm/memory-failure.c b/mm/memory-failure.c
86258index 2c13aa7..64cbc3f 100644
86259--- a/mm/memory-failure.c
86260+++ b/mm/memory-failure.c
86261@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
86262
86263 int sysctl_memory_failure_recovery __read_mostly = 1;
86264
86265-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
86266+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
86267
86268 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
86269
86270@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
86271 pfn, t->comm, t->pid);
86272 si.si_signo = SIGBUS;
86273 si.si_errno = 0;
86274- si.si_addr = (void *)addr;
86275+ si.si_addr = (void __user *)addr;
86276 #ifdef __ARCH_SI_TRAPNO
86277 si.si_trapno = trapno;
86278 #endif
86279@@ -760,7 +760,7 @@ static struct page_state {
86280 unsigned long res;
86281 char *msg;
86282 int (*action)(struct page *p, unsigned long pfn);
86283-} error_states[] = {
86284+} __do_const error_states[] = {
86285 { reserved, reserved, "reserved kernel", me_kernel },
86286 /*
86287 * free pages are specially detected outside this table:
86288@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86289 nr_pages = 1 << compound_order(hpage);
86290 else /* normal page or thp */
86291 nr_pages = 1;
86292- atomic_long_add(nr_pages, &num_poisoned_pages);
86293+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
86294
86295 /*
86296 * We need/can do nothing about count=0 pages.
86297@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86298 if (!PageHWPoison(hpage)
86299 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
86300 || (p != hpage && TestSetPageHWPoison(hpage))) {
86301- atomic_long_sub(nr_pages, &num_poisoned_pages);
86302+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86303 return 0;
86304 }
86305 set_page_hwpoison_huge_page(hpage);
86306@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86307 }
86308 if (hwpoison_filter(p)) {
86309 if (TestClearPageHWPoison(p))
86310- atomic_long_sub(nr_pages, &num_poisoned_pages);
86311+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86312 unlock_page(hpage);
86313 put_page(hpage);
86314 return 0;
86315@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
86316 return 0;
86317 }
86318 if (TestClearPageHWPoison(p))
86319- atomic_long_sub(nr_pages, &num_poisoned_pages);
86320+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86321 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
86322 return 0;
86323 }
86324@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
86325 */
86326 if (TestClearPageHWPoison(page)) {
86327 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
86328- atomic_long_sub(nr_pages, &num_poisoned_pages);
86329+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86330 freeit = 1;
86331 if (PageHuge(page))
86332 clear_page_hwpoison_huge_page(page);
86333@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
86334 } else {
86335 set_page_hwpoison_huge_page(hpage);
86336 dequeue_hwpoisoned_huge_page(hpage);
86337- atomic_long_add(1 << compound_trans_order(hpage),
86338+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
86339 &num_poisoned_pages);
86340 }
86341 return ret;
86342@@ -1551,11 +1551,11 @@ int soft_offline_page(struct page *page, int flags)
86343 if (PageHuge(page)) {
86344 set_page_hwpoison_huge_page(hpage);
86345 dequeue_hwpoisoned_huge_page(hpage);
86346- atomic_long_add(1 << compound_trans_order(hpage),
86347+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
86348 &num_poisoned_pages);
86349 } else {
86350 SetPageHWPoison(page);
86351- atomic_long_inc(&num_poisoned_pages);
86352+ atomic_long_inc_unchecked(&num_poisoned_pages);
86353 }
86354 }
86355 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
86356@@ -1595,7 +1595,7 @@ static int __soft_offline_page(struct page *page, int flags)
86357 put_page(page);
86358 pr_info("soft_offline: %#lx: invalidated\n", pfn);
86359 SetPageHWPoison(page);
86360- atomic_long_inc(&num_poisoned_pages);
86361+ atomic_long_inc_unchecked(&num_poisoned_pages);
86362 return 0;
86363 }
86364
86365@@ -1640,7 +1640,7 @@ static int __soft_offline_page(struct page *page, int flags)
86366 if (!is_free_buddy_page(page))
86367 pr_info("soft offline: %#lx: page leaked\n",
86368 pfn);
86369- atomic_long_inc(&num_poisoned_pages);
86370+ atomic_long_inc_unchecked(&num_poisoned_pages);
86371 }
86372 } else {
86373 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
86374diff --git a/mm/memory.c b/mm/memory.c
86375index af84bc0..2ed0816 100644
86376--- a/mm/memory.c
86377+++ b/mm/memory.c
86378@@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
86379 free_pte_range(tlb, pmd, addr);
86380 } while (pmd++, addr = next, addr != end);
86381
86382+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
86383 start &= PUD_MASK;
86384 if (start < floor)
86385 return;
86386@@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
86387 pmd = pmd_offset(pud, start);
86388 pud_clear(pud);
86389 pmd_free_tlb(tlb, pmd, start);
86390+#endif
86391+
86392 }
86393
86394 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86395@@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86396 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
86397 } while (pud++, addr = next, addr != end);
86398
86399+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
86400 start &= PGDIR_MASK;
86401 if (start < floor)
86402 return;
86403@@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86404 pud = pud_offset(pgd, start);
86405 pgd_clear(pgd);
86406 pud_free_tlb(tlb, pud, start);
86407+#endif
86408+
86409 }
86410
86411 /*
86412@@ -1645,12 +1651,6 @@ no_page_table:
86413 return page;
86414 }
86415
86416-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
86417-{
86418- return stack_guard_page_start(vma, addr) ||
86419- stack_guard_page_end(vma, addr+PAGE_SIZE);
86420-}
86421-
86422 /**
86423 * __get_user_pages() - pin user pages in memory
86424 * @tsk: task_struct of target task
86425@@ -1737,10 +1737,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86426
86427 i = 0;
86428
86429- do {
86430+ while (nr_pages) {
86431 struct vm_area_struct *vma;
86432
86433- vma = find_extend_vma(mm, start);
86434+ vma = find_vma(mm, start);
86435 if (!vma && in_gate_area(mm, start)) {
86436 unsigned long pg = start & PAGE_MASK;
86437 pgd_t *pgd;
86438@@ -1789,7 +1789,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86439 goto next_page;
86440 }
86441
86442- if (!vma ||
86443+ if (!vma || start < vma->vm_start ||
86444 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
86445 !(vm_flags & vma->vm_flags))
86446 return i ? : -EFAULT;
86447@@ -1818,11 +1818,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86448 int ret;
86449 unsigned int fault_flags = 0;
86450
86451- /* For mlock, just skip the stack guard page. */
86452- if (foll_flags & FOLL_MLOCK) {
86453- if (stack_guard_page(vma, start))
86454- goto next_page;
86455- }
86456 if (foll_flags & FOLL_WRITE)
86457 fault_flags |= FAULT_FLAG_WRITE;
86458 if (nonblocking)
86459@@ -1902,7 +1897,7 @@ next_page:
86460 start += page_increm * PAGE_SIZE;
86461 nr_pages -= page_increm;
86462 } while (nr_pages && start < vma->vm_end);
86463- } while (nr_pages);
86464+ }
86465 return i;
86466 }
86467 EXPORT_SYMBOL(__get_user_pages);
86468@@ -2109,6 +2104,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
86469 page_add_file_rmap(page);
86470 set_pte_at(mm, addr, pte, mk_pte(page, prot));
86471
86472+#ifdef CONFIG_PAX_SEGMEXEC
86473+ pax_mirror_file_pte(vma, addr, page, ptl);
86474+#endif
86475+
86476 retval = 0;
86477 pte_unmap_unlock(pte, ptl);
86478 return retval;
86479@@ -2153,9 +2152,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
86480 if (!page_count(page))
86481 return -EINVAL;
86482 if (!(vma->vm_flags & VM_MIXEDMAP)) {
86483+
86484+#ifdef CONFIG_PAX_SEGMEXEC
86485+ struct vm_area_struct *vma_m;
86486+#endif
86487+
86488 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
86489 BUG_ON(vma->vm_flags & VM_PFNMAP);
86490 vma->vm_flags |= VM_MIXEDMAP;
86491+
86492+#ifdef CONFIG_PAX_SEGMEXEC
86493+ vma_m = pax_find_mirror_vma(vma);
86494+ if (vma_m)
86495+ vma_m->vm_flags |= VM_MIXEDMAP;
86496+#endif
86497+
86498 }
86499 return insert_page(vma, addr, page, vma->vm_page_prot);
86500 }
86501@@ -2238,6 +2249,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
86502 unsigned long pfn)
86503 {
86504 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
86505+ BUG_ON(vma->vm_mirror);
86506
86507 if (addr < vma->vm_start || addr >= vma->vm_end)
86508 return -EFAULT;
86509@@ -2485,7 +2497,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
86510
86511 BUG_ON(pud_huge(*pud));
86512
86513- pmd = pmd_alloc(mm, pud, addr);
86514+ pmd = (mm == &init_mm) ?
86515+ pmd_alloc_kernel(mm, pud, addr) :
86516+ pmd_alloc(mm, pud, addr);
86517 if (!pmd)
86518 return -ENOMEM;
86519 do {
86520@@ -2505,7 +2519,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
86521 unsigned long next;
86522 int err;
86523
86524- pud = pud_alloc(mm, pgd, addr);
86525+ pud = (mm == &init_mm) ?
86526+ pud_alloc_kernel(mm, pgd, addr) :
86527+ pud_alloc(mm, pgd, addr);
86528 if (!pud)
86529 return -ENOMEM;
86530 do {
86531@@ -2593,6 +2609,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
86532 copy_user_highpage(dst, src, va, vma);
86533 }
86534
86535+#ifdef CONFIG_PAX_SEGMEXEC
86536+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
86537+{
86538+ struct mm_struct *mm = vma->vm_mm;
86539+ spinlock_t *ptl;
86540+ pte_t *pte, entry;
86541+
86542+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
86543+ entry = *pte;
86544+ if (!pte_present(entry)) {
86545+ if (!pte_none(entry)) {
86546+ BUG_ON(pte_file(entry));
86547+ free_swap_and_cache(pte_to_swp_entry(entry));
86548+ pte_clear_not_present_full(mm, address, pte, 0);
86549+ }
86550+ } else {
86551+ struct page *page;
86552+
86553+ flush_cache_page(vma, address, pte_pfn(entry));
86554+ entry = ptep_clear_flush(vma, address, pte);
86555+ BUG_ON(pte_dirty(entry));
86556+ page = vm_normal_page(vma, address, entry);
86557+ if (page) {
86558+ update_hiwater_rss(mm);
86559+ if (PageAnon(page))
86560+ dec_mm_counter_fast(mm, MM_ANONPAGES);
86561+ else
86562+ dec_mm_counter_fast(mm, MM_FILEPAGES);
86563+ page_remove_rmap(page);
86564+ page_cache_release(page);
86565+ }
86566+ }
86567+ pte_unmap_unlock(pte, ptl);
86568+}
86569+
86570+/* PaX: if vma is mirrored, synchronize the mirror's PTE
86571+ *
86572+ * the ptl of the lower mapped page is held on entry and is not released on exit
86573+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
86574+ */
86575+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86576+{
86577+ struct mm_struct *mm = vma->vm_mm;
86578+ unsigned long address_m;
86579+ spinlock_t *ptl_m;
86580+ struct vm_area_struct *vma_m;
86581+ pmd_t *pmd_m;
86582+ pte_t *pte_m, entry_m;
86583+
86584+ BUG_ON(!page_m || !PageAnon(page_m));
86585+
86586+ vma_m = pax_find_mirror_vma(vma);
86587+ if (!vma_m)
86588+ return;
86589+
86590+ BUG_ON(!PageLocked(page_m));
86591+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86592+ address_m = address + SEGMEXEC_TASK_SIZE;
86593+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86594+ pte_m = pte_offset_map(pmd_m, address_m);
86595+ ptl_m = pte_lockptr(mm, pmd_m);
86596+ if (ptl != ptl_m) {
86597+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86598+ if (!pte_none(*pte_m))
86599+ goto out;
86600+ }
86601+
86602+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86603+ page_cache_get(page_m);
86604+ page_add_anon_rmap(page_m, vma_m, address_m);
86605+ inc_mm_counter_fast(mm, MM_ANONPAGES);
86606+ set_pte_at(mm, address_m, pte_m, entry_m);
86607+ update_mmu_cache(vma_m, address_m, pte_m);
86608+out:
86609+ if (ptl != ptl_m)
86610+ spin_unlock(ptl_m);
86611+ pte_unmap(pte_m);
86612+ unlock_page(page_m);
86613+}
86614+
86615+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86616+{
86617+ struct mm_struct *mm = vma->vm_mm;
86618+ unsigned long address_m;
86619+ spinlock_t *ptl_m;
86620+ struct vm_area_struct *vma_m;
86621+ pmd_t *pmd_m;
86622+ pte_t *pte_m, entry_m;
86623+
86624+ BUG_ON(!page_m || PageAnon(page_m));
86625+
86626+ vma_m = pax_find_mirror_vma(vma);
86627+ if (!vma_m)
86628+ return;
86629+
86630+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86631+ address_m = address + SEGMEXEC_TASK_SIZE;
86632+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86633+ pte_m = pte_offset_map(pmd_m, address_m);
86634+ ptl_m = pte_lockptr(mm, pmd_m);
86635+ if (ptl != ptl_m) {
86636+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86637+ if (!pte_none(*pte_m))
86638+ goto out;
86639+ }
86640+
86641+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86642+ page_cache_get(page_m);
86643+ page_add_file_rmap(page_m);
86644+ inc_mm_counter_fast(mm, MM_FILEPAGES);
86645+ set_pte_at(mm, address_m, pte_m, entry_m);
86646+ update_mmu_cache(vma_m, address_m, pte_m);
86647+out:
86648+ if (ptl != ptl_m)
86649+ spin_unlock(ptl_m);
86650+ pte_unmap(pte_m);
86651+}
86652+
86653+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
86654+{
86655+ struct mm_struct *mm = vma->vm_mm;
86656+ unsigned long address_m;
86657+ spinlock_t *ptl_m;
86658+ struct vm_area_struct *vma_m;
86659+ pmd_t *pmd_m;
86660+ pte_t *pte_m, entry_m;
86661+
86662+ vma_m = pax_find_mirror_vma(vma);
86663+ if (!vma_m)
86664+ return;
86665+
86666+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86667+ address_m = address + SEGMEXEC_TASK_SIZE;
86668+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86669+ pte_m = pte_offset_map(pmd_m, address_m);
86670+ ptl_m = pte_lockptr(mm, pmd_m);
86671+ if (ptl != ptl_m) {
86672+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86673+ if (!pte_none(*pte_m))
86674+ goto out;
86675+ }
86676+
86677+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
86678+ set_pte_at(mm, address_m, pte_m, entry_m);
86679+out:
86680+ if (ptl != ptl_m)
86681+ spin_unlock(ptl_m);
86682+ pte_unmap(pte_m);
86683+}
86684+
86685+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
86686+{
86687+ struct page *page_m;
86688+ pte_t entry;
86689+
86690+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
86691+ goto out;
86692+
86693+ entry = *pte;
86694+ page_m = vm_normal_page(vma, address, entry);
86695+ if (!page_m)
86696+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
86697+ else if (PageAnon(page_m)) {
86698+ if (pax_find_mirror_vma(vma)) {
86699+ pte_unmap_unlock(pte, ptl);
86700+ lock_page(page_m);
86701+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
86702+ if (pte_same(entry, *pte))
86703+ pax_mirror_anon_pte(vma, address, page_m, ptl);
86704+ else
86705+ unlock_page(page_m);
86706+ }
86707+ } else
86708+ pax_mirror_file_pte(vma, address, page_m, ptl);
86709+
86710+out:
86711+ pte_unmap_unlock(pte, ptl);
86712+}
86713+#endif
86714+
86715 /*
86716 * This routine handles present pages, when users try to write
86717 * to a shared page. It is done by copying the page to a new address
86718@@ -2809,6 +3005,12 @@ gotten:
86719 */
86720 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86721 if (likely(pte_same(*page_table, orig_pte))) {
86722+
86723+#ifdef CONFIG_PAX_SEGMEXEC
86724+ if (pax_find_mirror_vma(vma))
86725+ BUG_ON(!trylock_page(new_page));
86726+#endif
86727+
86728 if (old_page) {
86729 if (!PageAnon(old_page)) {
86730 dec_mm_counter_fast(mm, MM_FILEPAGES);
86731@@ -2860,6 +3062,10 @@ gotten:
86732 page_remove_rmap(old_page);
86733 }
86734
86735+#ifdef CONFIG_PAX_SEGMEXEC
86736+ pax_mirror_anon_pte(vma, address, new_page, ptl);
86737+#endif
86738+
86739 /* Free the old page.. */
86740 new_page = old_page;
86741 ret |= VM_FAULT_WRITE;
86742@@ -3137,6 +3343,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86743 swap_free(entry);
86744 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
86745 try_to_free_swap(page);
86746+
86747+#ifdef CONFIG_PAX_SEGMEXEC
86748+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
86749+#endif
86750+
86751 unlock_page(page);
86752 if (page != swapcache) {
86753 /*
86754@@ -3160,6 +3371,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86755
86756 /* No need to invalidate - it was non-present before */
86757 update_mmu_cache(vma, address, page_table);
86758+
86759+#ifdef CONFIG_PAX_SEGMEXEC
86760+ pax_mirror_anon_pte(vma, address, page, ptl);
86761+#endif
86762+
86763 unlock:
86764 pte_unmap_unlock(page_table, ptl);
86765 out:
86766@@ -3179,40 +3395,6 @@ out_release:
86767 }
86768
86769 /*
86770- * This is like a special single-page "expand_{down|up}wards()",
86771- * except we must first make sure that 'address{-|+}PAGE_SIZE'
86772- * doesn't hit another vma.
86773- */
86774-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
86775-{
86776- address &= PAGE_MASK;
86777- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
86778- struct vm_area_struct *prev = vma->vm_prev;
86779-
86780- /*
86781- * Is there a mapping abutting this one below?
86782- *
86783- * That's only ok if it's the same stack mapping
86784- * that has gotten split..
86785- */
86786- if (prev && prev->vm_end == address)
86787- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
86788-
86789- expand_downwards(vma, address - PAGE_SIZE);
86790- }
86791- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
86792- struct vm_area_struct *next = vma->vm_next;
86793-
86794- /* As VM_GROWSDOWN but s/below/above/ */
86795- if (next && next->vm_start == address + PAGE_SIZE)
86796- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
86797-
86798- expand_upwards(vma, address + PAGE_SIZE);
86799- }
86800- return 0;
86801-}
86802-
86803-/*
86804 * We enter with non-exclusive mmap_sem (to exclude vma changes,
86805 * but allow concurrent faults), and pte mapped but not yet locked.
86806 * We return with mmap_sem still held, but pte unmapped and unlocked.
86807@@ -3221,27 +3403,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86808 unsigned long address, pte_t *page_table, pmd_t *pmd,
86809 unsigned int flags)
86810 {
86811- struct page *page;
86812+ struct page *page = NULL;
86813 spinlock_t *ptl;
86814 pte_t entry;
86815
86816- pte_unmap(page_table);
86817-
86818- /* Check if we need to add a guard page to the stack */
86819- if (check_stack_guard_page(vma, address) < 0)
86820- return VM_FAULT_SIGBUS;
86821-
86822- /* Use the zero-page for reads */
86823 if (!(flags & FAULT_FLAG_WRITE)) {
86824 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
86825 vma->vm_page_prot));
86826- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86827+ ptl = pte_lockptr(mm, pmd);
86828+ spin_lock(ptl);
86829 if (!pte_none(*page_table))
86830 goto unlock;
86831 goto setpte;
86832 }
86833
86834 /* Allocate our own private page. */
86835+ pte_unmap(page_table);
86836+
86837 if (unlikely(anon_vma_prepare(vma)))
86838 goto oom;
86839 page = alloc_zeroed_user_highpage_movable(vma, address);
86840@@ -3265,6 +3443,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86841 if (!pte_none(*page_table))
86842 goto release;
86843
86844+#ifdef CONFIG_PAX_SEGMEXEC
86845+ if (pax_find_mirror_vma(vma))
86846+ BUG_ON(!trylock_page(page));
86847+#endif
86848+
86849 inc_mm_counter_fast(mm, MM_ANONPAGES);
86850 page_add_new_anon_rmap(page, vma, address);
86851 setpte:
86852@@ -3272,6 +3455,12 @@ setpte:
86853
86854 /* No need to invalidate - it was non-present before */
86855 update_mmu_cache(vma, address, page_table);
86856+
86857+#ifdef CONFIG_PAX_SEGMEXEC
86858+ if (page)
86859+ pax_mirror_anon_pte(vma, address, page, ptl);
86860+#endif
86861+
86862 unlock:
86863 pte_unmap_unlock(page_table, ptl);
86864 return 0;
86865@@ -3415,6 +3604,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86866 */
86867 /* Only go through if we didn't race with anybody else... */
86868 if (likely(pte_same(*page_table, orig_pte))) {
86869+
86870+#ifdef CONFIG_PAX_SEGMEXEC
86871+ if (anon && pax_find_mirror_vma(vma))
86872+ BUG_ON(!trylock_page(page));
86873+#endif
86874+
86875 flush_icache_page(vma, page);
86876 entry = mk_pte(page, vma->vm_page_prot);
86877 if (flags & FAULT_FLAG_WRITE)
86878@@ -3436,6 +3631,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86879
86880 /* no need to invalidate: a not-present page won't be cached */
86881 update_mmu_cache(vma, address, page_table);
86882+
86883+#ifdef CONFIG_PAX_SEGMEXEC
86884+ if (anon)
86885+ pax_mirror_anon_pte(vma, address, page, ptl);
86886+ else
86887+ pax_mirror_file_pte(vma, address, page, ptl);
86888+#endif
86889+
86890 } else {
86891 if (cow_page)
86892 mem_cgroup_uncharge_page(cow_page);
86893@@ -3757,6 +3960,12 @@ int handle_pte_fault(struct mm_struct *mm,
86894 if (flags & FAULT_FLAG_WRITE)
86895 flush_tlb_fix_spurious_fault(vma, address);
86896 }
86897+
86898+#ifdef CONFIG_PAX_SEGMEXEC
86899+ pax_mirror_pte(vma, address, pte, pmd, ptl);
86900+ return 0;
86901+#endif
86902+
86903 unlock:
86904 pte_unmap_unlock(pte, ptl);
86905 return 0;
86906@@ -3773,6 +3982,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86907 pmd_t *pmd;
86908 pte_t *pte;
86909
86910+#ifdef CONFIG_PAX_SEGMEXEC
86911+ struct vm_area_struct *vma_m;
86912+#endif
86913+
86914 __set_current_state(TASK_RUNNING);
86915
86916 count_vm_event(PGFAULT);
86917@@ -3784,6 +3997,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86918 if (unlikely(is_vm_hugetlb_page(vma)))
86919 return hugetlb_fault(mm, vma, address, flags);
86920
86921+#ifdef CONFIG_PAX_SEGMEXEC
86922+ vma_m = pax_find_mirror_vma(vma);
86923+ if (vma_m) {
86924+ unsigned long address_m;
86925+ pgd_t *pgd_m;
86926+ pud_t *pud_m;
86927+ pmd_t *pmd_m;
86928+
86929+ if (vma->vm_start > vma_m->vm_start) {
86930+ address_m = address;
86931+ address -= SEGMEXEC_TASK_SIZE;
86932+ vma = vma_m;
86933+ } else
86934+ address_m = address + SEGMEXEC_TASK_SIZE;
86935+
86936+ pgd_m = pgd_offset(mm, address_m);
86937+ pud_m = pud_alloc(mm, pgd_m, address_m);
86938+ if (!pud_m)
86939+ return VM_FAULT_OOM;
86940+ pmd_m = pmd_alloc(mm, pud_m, address_m);
86941+ if (!pmd_m)
86942+ return VM_FAULT_OOM;
86943+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
86944+ return VM_FAULT_OOM;
86945+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
86946+ }
86947+#endif
86948+
86949 retry:
86950 pgd = pgd_offset(mm, address);
86951 pud = pud_alloc(mm, pgd, address);
86952@@ -3882,6 +4123,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
86953 spin_unlock(&mm->page_table_lock);
86954 return 0;
86955 }
86956+
86957+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
86958+{
86959+ pud_t *new = pud_alloc_one(mm, address);
86960+ if (!new)
86961+ return -ENOMEM;
86962+
86963+ smp_wmb(); /* See comment in __pte_alloc */
86964+
86965+ spin_lock(&mm->page_table_lock);
86966+ if (pgd_present(*pgd)) /* Another has populated it */
86967+ pud_free(mm, new);
86968+ else
86969+ pgd_populate_kernel(mm, pgd, new);
86970+ spin_unlock(&mm->page_table_lock);
86971+ return 0;
86972+}
86973 #endif /* __PAGETABLE_PUD_FOLDED */
86974
86975 #ifndef __PAGETABLE_PMD_FOLDED
86976@@ -3912,6 +4170,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
86977 spin_unlock(&mm->page_table_lock);
86978 return 0;
86979 }
86980+
86981+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
86982+{
86983+ pmd_t *new = pmd_alloc_one(mm, address);
86984+ if (!new)
86985+ return -ENOMEM;
86986+
86987+ smp_wmb(); /* See comment in __pte_alloc */
86988+
86989+ spin_lock(&mm->page_table_lock);
86990+#ifndef __ARCH_HAS_4LEVEL_HACK
86991+ if (pud_present(*pud)) /* Another has populated it */
86992+ pmd_free(mm, new);
86993+ else
86994+ pud_populate_kernel(mm, pud, new);
86995+#else
86996+ if (pgd_present(*pud)) /* Another has populated it */
86997+ pmd_free(mm, new);
86998+ else
86999+ pgd_populate_kernel(mm, pud, new);
87000+#endif /* __ARCH_HAS_4LEVEL_HACK */
87001+ spin_unlock(&mm->page_table_lock);
87002+ return 0;
87003+}
87004 #endif /* __PAGETABLE_PMD_FOLDED */
87005
87006 #if !defined(__HAVE_ARCH_GATE_AREA)
87007@@ -3925,7 +4207,7 @@ static int __init gate_vma_init(void)
87008 gate_vma.vm_start = FIXADDR_USER_START;
87009 gate_vma.vm_end = FIXADDR_USER_END;
87010 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
87011- gate_vma.vm_page_prot = __P101;
87012+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
87013
87014 return 0;
87015 }
87016@@ -4059,8 +4341,8 @@ out:
87017 return ret;
87018 }
87019
87020-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
87021- void *buf, int len, int write)
87022+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
87023+ void *buf, size_t len, int write)
87024 {
87025 resource_size_t phys_addr;
87026 unsigned long prot = 0;
87027@@ -4085,8 +4367,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
87028 * Access another process' address space as given in mm. If non-NULL, use the
87029 * given task for page fault accounting.
87030 */
87031-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87032- unsigned long addr, void *buf, int len, int write)
87033+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87034+ unsigned long addr, void *buf, size_t len, int write)
87035 {
87036 struct vm_area_struct *vma;
87037 void *old_buf = buf;
87038@@ -4094,7 +4376,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87039 down_read(&mm->mmap_sem);
87040 /* ignore errors, just check how much was successfully transferred */
87041 while (len) {
87042- int bytes, ret, offset;
87043+ ssize_t bytes, ret, offset;
87044 void *maddr;
87045 struct page *page = NULL;
87046
87047@@ -4153,8 +4435,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87048 *
87049 * The caller must hold a reference on @mm.
87050 */
87051-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
87052- void *buf, int len, int write)
87053+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
87054+ void *buf, size_t len, int write)
87055 {
87056 return __access_remote_vm(NULL, mm, addr, buf, len, write);
87057 }
87058@@ -4164,11 +4446,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
87059 * Source/target buffer must be kernel space,
87060 * Do not walk the page table directly, use get_user_pages
87061 */
87062-int access_process_vm(struct task_struct *tsk, unsigned long addr,
87063- void *buf, int len, int write)
87064+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
87065+ void *buf, size_t len, int write)
87066 {
87067 struct mm_struct *mm;
87068- int ret;
87069+ ssize_t ret;
87070
87071 mm = get_task_mm(tsk);
87072 if (!mm)
87073diff --git a/mm/mempolicy.c b/mm/mempolicy.c
87074index 4baf12e..5497066 100644
87075--- a/mm/mempolicy.c
87076+++ b/mm/mempolicy.c
87077@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
87078 unsigned long vmstart;
87079 unsigned long vmend;
87080
87081+#ifdef CONFIG_PAX_SEGMEXEC
87082+ struct vm_area_struct *vma_m;
87083+#endif
87084+
87085 vma = find_vma(mm, start);
87086 if (!vma || vma->vm_start > start)
87087 return -EFAULT;
87088@@ -751,6 +755,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
87089 err = vma_replace_policy(vma, new_pol);
87090 if (err)
87091 goto out;
87092+
87093+#ifdef CONFIG_PAX_SEGMEXEC
87094+ vma_m = pax_find_mirror_vma(vma);
87095+ if (vma_m) {
87096+ err = vma_replace_policy(vma_m, new_pol);
87097+ if (err)
87098+ goto out;
87099+ }
87100+#endif
87101+
87102 }
87103
87104 out:
87105@@ -1206,6 +1220,17 @@ static long do_mbind(unsigned long start, unsigned long len,
87106
87107 if (end < start)
87108 return -EINVAL;
87109+
87110+#ifdef CONFIG_PAX_SEGMEXEC
87111+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
87112+ if (end > SEGMEXEC_TASK_SIZE)
87113+ return -EINVAL;
87114+ } else
87115+#endif
87116+
87117+ if (end > TASK_SIZE)
87118+ return -EINVAL;
87119+
87120 if (end == start)
87121 return 0;
87122
87123@@ -1434,8 +1459,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
87124 */
87125 tcred = __task_cred(task);
87126 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
87127- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
87128- !capable(CAP_SYS_NICE)) {
87129+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
87130 rcu_read_unlock();
87131 err = -EPERM;
87132 goto out_put;
87133@@ -1466,6 +1490,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
87134 goto out;
87135 }
87136
87137+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
87138+ if (mm != current->mm &&
87139+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
87140+ mmput(mm);
87141+ err = -EPERM;
87142+ goto out;
87143+ }
87144+#endif
87145+
87146 err = do_migrate_pages(mm, old, new,
87147 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
87148
87149diff --git a/mm/migrate.c b/mm/migrate.c
87150index 6f0c244..6d1ae32 100644
87151--- a/mm/migrate.c
87152+++ b/mm/migrate.c
87153@@ -1399,8 +1399,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
87154 */
87155 tcred = __task_cred(task);
87156 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
87157- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
87158- !capable(CAP_SYS_NICE)) {
87159+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
87160 rcu_read_unlock();
87161 err = -EPERM;
87162 goto out;
87163diff --git a/mm/mlock.c b/mm/mlock.c
87164index 79b7cf7..9944291 100644
87165--- a/mm/mlock.c
87166+++ b/mm/mlock.c
87167@@ -13,6 +13,7 @@
87168 #include <linux/pagemap.h>
87169 #include <linux/mempolicy.h>
87170 #include <linux/syscalls.h>
87171+#include <linux/security.h>
87172 #include <linux/sched.h>
87173 #include <linux/export.h>
87174 #include <linux/rmap.h>
87175@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
87176 {
87177 unsigned long nstart, end, tmp;
87178 struct vm_area_struct * vma, * prev;
87179- int error;
87180+ int error = 0;
87181
87182 VM_BUG_ON(start & ~PAGE_MASK);
87183 VM_BUG_ON(len != PAGE_ALIGN(len));
87184@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
87185 return -EINVAL;
87186 if (end == start)
87187 return 0;
87188+ if (end > TASK_SIZE)
87189+ return -EINVAL;
87190+
87191 vma = find_vma(current->mm, start);
87192 if (!vma || vma->vm_start > start)
87193 return -ENOMEM;
87194@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
87195 for (nstart = start ; ; ) {
87196 vm_flags_t newflags;
87197
87198+#ifdef CONFIG_PAX_SEGMEXEC
87199+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
87200+ break;
87201+#endif
87202+
87203 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
87204
87205 newflags = vma->vm_flags & ~VM_LOCKED;
87206@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
87207 lock_limit >>= PAGE_SHIFT;
87208
87209 /* check against resource limits */
87210+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
87211 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
87212 error = do_mlock(start, len, 1);
87213 up_write(&current->mm->mmap_sem);
87214@@ -500,6 +510,11 @@ static int do_mlockall(int flags)
87215 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
87216 vm_flags_t newflags;
87217
87218+#ifdef CONFIG_PAX_SEGMEXEC
87219+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
87220+ break;
87221+#endif
87222+
87223 newflags = vma->vm_flags & ~VM_LOCKED;
87224 if (flags & MCL_CURRENT)
87225 newflags |= VM_LOCKED;
87226@@ -532,6 +547,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
87227 lock_limit >>= PAGE_SHIFT;
87228
87229 ret = -ENOMEM;
87230+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
87231 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
87232 capable(CAP_IPC_LOCK))
87233 ret = do_mlockall(flags);
87234diff --git a/mm/mmap.c b/mm/mmap.c
87235index f9c97d1..3468d3b 100644
87236--- a/mm/mmap.c
87237+++ b/mm/mmap.c
87238@@ -36,6 +36,7 @@
87239 #include <linux/sched/sysctl.h>
87240 #include <linux/notifier.h>
87241 #include <linux/memory.h>
87242+#include <linux/random.h>
87243
87244 #include <asm/uaccess.h>
87245 #include <asm/cacheflush.h>
87246@@ -52,6 +53,16 @@
87247 #define arch_rebalance_pgtables(addr, len) (addr)
87248 #endif
87249
87250+static inline void verify_mm_writelocked(struct mm_struct *mm)
87251+{
87252+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
87253+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
87254+ up_read(&mm->mmap_sem);
87255+ BUG();
87256+ }
87257+#endif
87258+}
87259+
87260 static void unmap_region(struct mm_struct *mm,
87261 struct vm_area_struct *vma, struct vm_area_struct *prev,
87262 unsigned long start, unsigned long end);
87263@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
87264 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
87265 *
87266 */
87267-pgprot_t protection_map[16] = {
87268+pgprot_t protection_map[16] __read_only = {
87269 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
87270 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
87271 };
87272
87273-pgprot_t vm_get_page_prot(unsigned long vm_flags)
87274+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
87275 {
87276- return __pgprot(pgprot_val(protection_map[vm_flags &
87277+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
87278 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
87279 pgprot_val(arch_vm_get_page_prot(vm_flags)));
87280+
87281+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87282+ if (!(__supported_pte_mask & _PAGE_NX) &&
87283+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
87284+ (vm_flags & (VM_READ | VM_WRITE)))
87285+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
87286+#endif
87287+
87288+ return prot;
87289 }
87290 EXPORT_SYMBOL(vm_get_page_prot);
87291
87292@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
87293 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
87294 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
87295 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
87296+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
87297 /*
87298 * Make sure vm_committed_as in one cacheline and not cacheline shared with
87299 * other variables. It can be updated by several CPUs frequently.
87300@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
87301 struct vm_area_struct *next = vma->vm_next;
87302
87303 might_sleep();
87304+ BUG_ON(vma->vm_mirror);
87305 if (vma->vm_ops && vma->vm_ops->close)
87306 vma->vm_ops->close(vma);
87307 if (vma->vm_file)
87308@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
87309 * not page aligned -Ram Gupta
87310 */
87311 rlim = rlimit(RLIMIT_DATA);
87312+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
87313 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
87314 (mm->end_data - mm->start_data) > rlim)
87315 goto out;
87316@@ -933,6 +956,12 @@ static int
87317 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
87318 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
87319 {
87320+
87321+#ifdef CONFIG_PAX_SEGMEXEC
87322+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
87323+ return 0;
87324+#endif
87325+
87326 if (is_mergeable_vma(vma, file, vm_flags) &&
87327 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
87328 if (vma->vm_pgoff == vm_pgoff)
87329@@ -952,6 +981,12 @@ static int
87330 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
87331 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
87332 {
87333+
87334+#ifdef CONFIG_PAX_SEGMEXEC
87335+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
87336+ return 0;
87337+#endif
87338+
87339 if (is_mergeable_vma(vma, file, vm_flags) &&
87340 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
87341 pgoff_t vm_pglen;
87342@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
87343 struct vm_area_struct *vma_merge(struct mm_struct *mm,
87344 struct vm_area_struct *prev, unsigned long addr,
87345 unsigned long end, unsigned long vm_flags,
87346- struct anon_vma *anon_vma, struct file *file,
87347+ struct anon_vma *anon_vma, struct file *file,
87348 pgoff_t pgoff, struct mempolicy *policy)
87349 {
87350 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
87351 struct vm_area_struct *area, *next;
87352 int err;
87353
87354+#ifdef CONFIG_PAX_SEGMEXEC
87355+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
87356+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
87357+
87358+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
87359+#endif
87360+
87361 /*
87362 * We later require that vma->vm_flags == vm_flags,
87363 * so this tests vma->vm_flags & VM_SPECIAL, too.
87364@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87365 if (next && next->vm_end == end) /* cases 6, 7, 8 */
87366 next = next->vm_next;
87367
87368+#ifdef CONFIG_PAX_SEGMEXEC
87369+ if (prev)
87370+ prev_m = pax_find_mirror_vma(prev);
87371+ if (area)
87372+ area_m = pax_find_mirror_vma(area);
87373+ if (next)
87374+ next_m = pax_find_mirror_vma(next);
87375+#endif
87376+
87377 /*
87378 * Can it merge with the predecessor?
87379 */
87380@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87381 /* cases 1, 6 */
87382 err = vma_adjust(prev, prev->vm_start,
87383 next->vm_end, prev->vm_pgoff, NULL);
87384- } else /* cases 2, 5, 7 */
87385+
87386+#ifdef CONFIG_PAX_SEGMEXEC
87387+ if (!err && prev_m)
87388+ err = vma_adjust(prev_m, prev_m->vm_start,
87389+ next_m->vm_end, prev_m->vm_pgoff, NULL);
87390+#endif
87391+
87392+ } else { /* cases 2, 5, 7 */
87393 err = vma_adjust(prev, prev->vm_start,
87394 end, prev->vm_pgoff, NULL);
87395+
87396+#ifdef CONFIG_PAX_SEGMEXEC
87397+ if (!err && prev_m)
87398+ err = vma_adjust(prev_m, prev_m->vm_start,
87399+ end_m, prev_m->vm_pgoff, NULL);
87400+#endif
87401+
87402+ }
87403 if (err)
87404 return NULL;
87405 khugepaged_enter_vma_merge(prev);
87406@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87407 mpol_equal(policy, vma_policy(next)) &&
87408 can_vma_merge_before(next, vm_flags,
87409 anon_vma, file, pgoff+pglen)) {
87410- if (prev && addr < prev->vm_end) /* case 4 */
87411+ if (prev && addr < prev->vm_end) { /* case 4 */
87412 err = vma_adjust(prev, prev->vm_start,
87413 addr, prev->vm_pgoff, NULL);
87414- else /* cases 3, 8 */
87415+
87416+#ifdef CONFIG_PAX_SEGMEXEC
87417+ if (!err && prev_m)
87418+ err = vma_adjust(prev_m, prev_m->vm_start,
87419+ addr_m, prev_m->vm_pgoff, NULL);
87420+#endif
87421+
87422+ } else { /* cases 3, 8 */
87423 err = vma_adjust(area, addr, next->vm_end,
87424 next->vm_pgoff - pglen, NULL);
87425+
87426+#ifdef CONFIG_PAX_SEGMEXEC
87427+ if (!err && area_m)
87428+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
87429+ next_m->vm_pgoff - pglen, NULL);
87430+#endif
87431+
87432+ }
87433 if (err)
87434 return NULL;
87435 khugepaged_enter_vma_merge(area);
87436@@ -1165,8 +1246,10 @@ none:
87437 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87438 struct file *file, long pages)
87439 {
87440- const unsigned long stack_flags
87441- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
87442+
87443+#ifdef CONFIG_PAX_RANDMMAP
87444+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87445+#endif
87446
87447 mm->total_vm += pages;
87448
87449@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87450 mm->shared_vm += pages;
87451 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
87452 mm->exec_vm += pages;
87453- } else if (flags & stack_flags)
87454+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
87455 mm->stack_vm += pages;
87456 }
87457 #endif /* CONFIG_PROC_FS */
87458@@ -1213,7 +1296,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87459 * (the exception is when the underlying filesystem is noexec
87460 * mounted, in which case we dont add PROT_EXEC.)
87461 */
87462- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
87463+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
87464 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
87465 prot |= PROT_EXEC;
87466
87467@@ -1239,7 +1322,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87468 /* Obtain the address to map to. we verify (or select) it and ensure
87469 * that it represents a valid section of the address space.
87470 */
87471- addr = get_unmapped_area(file, addr, len, pgoff, flags);
87472+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
87473 if (addr & ~PAGE_MASK)
87474 return addr;
87475
87476@@ -1250,6 +1333,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87477 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
87478 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
87479
87480+#ifdef CONFIG_PAX_MPROTECT
87481+ if (mm->pax_flags & MF_PAX_MPROTECT) {
87482+
87483+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
87484+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
87485+ mm->binfmt->handle_mmap)
87486+ mm->binfmt->handle_mmap(file);
87487+#endif
87488+
87489+#ifndef CONFIG_PAX_MPROTECT_COMPAT
87490+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
87491+ gr_log_rwxmmap(file);
87492+
87493+#ifdef CONFIG_PAX_EMUPLT
87494+ vm_flags &= ~VM_EXEC;
87495+#else
87496+ return -EPERM;
87497+#endif
87498+
87499+ }
87500+
87501+ if (!(vm_flags & VM_EXEC))
87502+ vm_flags &= ~VM_MAYEXEC;
87503+#else
87504+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
87505+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
87506+#endif
87507+ else
87508+ vm_flags &= ~VM_MAYWRITE;
87509+ }
87510+#endif
87511+
87512+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87513+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
87514+ vm_flags &= ~VM_PAGEEXEC;
87515+#endif
87516+
87517 if (flags & MAP_LOCKED)
87518 if (!can_do_mlock())
87519 return -EPERM;
87520@@ -1261,6 +1381,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87521 locked += mm->locked_vm;
87522 lock_limit = rlimit(RLIMIT_MEMLOCK);
87523 lock_limit >>= PAGE_SHIFT;
87524+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
87525 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
87526 return -EAGAIN;
87527 }
87528@@ -1341,6 +1462,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87529 vm_flags |= VM_NORESERVE;
87530 }
87531
87532+ if (!gr_acl_handle_mmap(file, prot))
87533+ return -EACCES;
87534+
87535 addr = mmap_region(file, addr, len, vm_flags, pgoff);
87536 if (!IS_ERR_VALUE(addr) &&
87537 ((vm_flags & VM_LOCKED) ||
87538@@ -1434,7 +1558,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
87539 vm_flags_t vm_flags = vma->vm_flags;
87540
87541 /* If it was private or non-writable, the write bit is already clear */
87542- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
87543+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
87544 return 0;
87545
87546 /* The backer wishes to know when pages are first written to? */
87547@@ -1482,7 +1606,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87548 unsigned long charged = 0;
87549 struct inode *inode = file ? file_inode(file) : NULL;
87550
87551+#ifdef CONFIG_PAX_SEGMEXEC
87552+ struct vm_area_struct *vma_m = NULL;
87553+#endif
87554+
87555+ /*
87556+ * mm->mmap_sem is required to protect against another thread
87557+ * changing the mappings in case we sleep.
87558+ */
87559+ verify_mm_writelocked(mm);
87560+
87561 /* Check against address space limit. */
87562+
87563+#ifdef CONFIG_PAX_RANDMMAP
87564+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87565+#endif
87566+
87567 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
87568 unsigned long nr_pages;
87569
87570@@ -1501,11 +1640,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87571
87572 /* Clear old maps */
87573 error = -ENOMEM;
87574-munmap_back:
87575 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
87576 if (do_munmap(mm, addr, len))
87577 return -ENOMEM;
87578- goto munmap_back;
87579+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
87580 }
87581
87582 /*
87583@@ -1536,6 +1674,16 @@ munmap_back:
87584 goto unacct_error;
87585 }
87586
87587+#ifdef CONFIG_PAX_SEGMEXEC
87588+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
87589+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
87590+ if (!vma_m) {
87591+ error = -ENOMEM;
87592+ goto free_vma;
87593+ }
87594+ }
87595+#endif
87596+
87597 vma->vm_mm = mm;
87598 vma->vm_start = addr;
87599 vma->vm_end = addr + len;
87600@@ -1560,6 +1708,13 @@ munmap_back:
87601 if (error)
87602 goto unmap_and_free_vma;
87603
87604+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87605+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
87606+ vma->vm_flags |= VM_PAGEEXEC;
87607+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
87608+ }
87609+#endif
87610+
87611 /* Can addr have changed??
87612 *
87613 * Answer: Yes, several device drivers can do it in their
87614@@ -1598,6 +1753,11 @@ munmap_back:
87615 vma_link(mm, vma, prev, rb_link, rb_parent);
87616 file = vma->vm_file;
87617
87618+#ifdef CONFIG_PAX_SEGMEXEC
87619+ if (vma_m)
87620+ BUG_ON(pax_mirror_vma(vma_m, vma));
87621+#endif
87622+
87623 /* Once vma denies write, undo our temporary denial count */
87624 if (correct_wcount)
87625 atomic_inc(&inode->i_writecount);
87626@@ -1605,6 +1765,7 @@ out:
87627 perf_event_mmap(vma);
87628
87629 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
87630+ track_exec_limit(mm, addr, addr + len, vm_flags);
87631 if (vm_flags & VM_LOCKED) {
87632 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
87633 vma == get_gate_vma(current->mm)))
87634@@ -1628,6 +1789,12 @@ unmap_and_free_vma:
87635 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
87636 charged = 0;
87637 free_vma:
87638+
87639+#ifdef CONFIG_PAX_SEGMEXEC
87640+ if (vma_m)
87641+ kmem_cache_free(vm_area_cachep, vma_m);
87642+#endif
87643+
87644 kmem_cache_free(vm_area_cachep, vma);
87645 unacct_error:
87646 if (charged)
87647@@ -1635,7 +1802,63 @@ unacct_error:
87648 return error;
87649 }
87650
87651-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87652+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
87653+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
87654+{
87655+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
87656+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
87657+
87658+ return 0;
87659+}
87660+#endif
87661+
87662+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
87663+{
87664+ if (!vma) {
87665+#ifdef CONFIG_STACK_GROWSUP
87666+ if (addr > sysctl_heap_stack_gap)
87667+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
87668+ else
87669+ vma = find_vma(current->mm, 0);
87670+ if (vma && (vma->vm_flags & VM_GROWSUP))
87671+ return false;
87672+#endif
87673+ return true;
87674+ }
87675+
87676+ if (addr + len > vma->vm_start)
87677+ return false;
87678+
87679+ if (vma->vm_flags & VM_GROWSDOWN)
87680+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
87681+#ifdef CONFIG_STACK_GROWSUP
87682+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
87683+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
87684+#endif
87685+ else if (offset)
87686+ return offset <= vma->vm_start - addr - len;
87687+
87688+ return true;
87689+}
87690+
87691+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
87692+{
87693+ if (vma->vm_start < len)
87694+ return -ENOMEM;
87695+
87696+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
87697+ if (offset <= vma->vm_start - len)
87698+ return vma->vm_start - len - offset;
87699+ else
87700+ return -ENOMEM;
87701+ }
87702+
87703+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
87704+ return vma->vm_start - len - sysctl_heap_stack_gap;
87705+ return -ENOMEM;
87706+}
87707+
87708+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
87709 {
87710 /*
87711 * We implement the search by looking for an rbtree node that
87712@@ -1683,11 +1906,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87713 }
87714 }
87715
87716- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
87717+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
87718 check_current:
87719 /* Check if current node has a suitable gap */
87720 if (gap_start > high_limit)
87721 return -ENOMEM;
87722+
87723+ if (gap_end - gap_start > info->threadstack_offset)
87724+ gap_start += info->threadstack_offset;
87725+ else
87726+ gap_start = gap_end;
87727+
87728+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87729+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87730+ gap_start += sysctl_heap_stack_gap;
87731+ else
87732+ gap_start = gap_end;
87733+ }
87734+ if (vma->vm_flags & VM_GROWSDOWN) {
87735+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87736+ gap_end -= sysctl_heap_stack_gap;
87737+ else
87738+ gap_end = gap_start;
87739+ }
87740 if (gap_end >= low_limit && gap_end - gap_start >= length)
87741 goto found;
87742
87743@@ -1737,7 +1978,7 @@ found:
87744 return gap_start;
87745 }
87746
87747-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
87748+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
87749 {
87750 struct mm_struct *mm = current->mm;
87751 struct vm_area_struct *vma;
87752@@ -1791,6 +2032,24 @@ check_current:
87753 gap_end = vma->vm_start;
87754 if (gap_end < low_limit)
87755 return -ENOMEM;
87756+
87757+ if (gap_end - gap_start > info->threadstack_offset)
87758+ gap_end -= info->threadstack_offset;
87759+ else
87760+ gap_end = gap_start;
87761+
87762+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87763+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87764+ gap_start += sysctl_heap_stack_gap;
87765+ else
87766+ gap_start = gap_end;
87767+ }
87768+ if (vma->vm_flags & VM_GROWSDOWN) {
87769+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87770+ gap_end -= sysctl_heap_stack_gap;
87771+ else
87772+ gap_end = gap_start;
87773+ }
87774 if (gap_start <= high_limit && gap_end - gap_start >= length)
87775 goto found;
87776
87777@@ -1854,6 +2113,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87778 struct mm_struct *mm = current->mm;
87779 struct vm_area_struct *vma;
87780 struct vm_unmapped_area_info info;
87781+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87782
87783 if (len > TASK_SIZE)
87784 return -ENOMEM;
87785@@ -1861,19 +2121,29 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87786 if (flags & MAP_FIXED)
87787 return addr;
87788
87789+#ifdef CONFIG_PAX_RANDMMAP
87790+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87791+#endif
87792+
87793 if (addr) {
87794 addr = PAGE_ALIGN(addr);
87795 vma = find_vma(mm, addr);
87796- if (TASK_SIZE - len >= addr &&
87797- (!vma || addr + len <= vma->vm_start))
87798+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87799 return addr;
87800 }
87801
87802 info.flags = 0;
87803 info.length = len;
87804 info.low_limit = TASK_UNMAPPED_BASE;
87805+
87806+#ifdef CONFIG_PAX_RANDMMAP
87807+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87808+ info.low_limit += mm->delta_mmap;
87809+#endif
87810+
87811 info.high_limit = TASK_SIZE;
87812 info.align_mask = 0;
87813+ info.threadstack_offset = offset;
87814 return vm_unmapped_area(&info);
87815 }
87816 #endif
87817@@ -1892,6 +2162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87818 struct mm_struct *mm = current->mm;
87819 unsigned long addr = addr0;
87820 struct vm_unmapped_area_info info;
87821+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87822
87823 /* requested length too big for entire address space */
87824 if (len > TASK_SIZE)
87825@@ -1900,12 +2171,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87826 if (flags & MAP_FIXED)
87827 return addr;
87828
87829+#ifdef CONFIG_PAX_RANDMMAP
87830+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87831+#endif
87832+
87833 /* requesting a specific address */
87834 if (addr) {
87835 addr = PAGE_ALIGN(addr);
87836 vma = find_vma(mm, addr);
87837- if (TASK_SIZE - len >= addr &&
87838- (!vma || addr + len <= vma->vm_start))
87839+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87840 return addr;
87841 }
87842
87843@@ -1914,6 +2188,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87844 info.low_limit = PAGE_SIZE;
87845 info.high_limit = mm->mmap_base;
87846 info.align_mask = 0;
87847+ info.threadstack_offset = offset;
87848 addr = vm_unmapped_area(&info);
87849
87850 /*
87851@@ -1926,6 +2201,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87852 VM_BUG_ON(addr != -ENOMEM);
87853 info.flags = 0;
87854 info.low_limit = TASK_UNMAPPED_BASE;
87855+
87856+#ifdef CONFIG_PAX_RANDMMAP
87857+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87858+ info.low_limit += mm->delta_mmap;
87859+#endif
87860+
87861 info.high_limit = TASK_SIZE;
87862 addr = vm_unmapped_area(&info);
87863 }
87864@@ -2027,6 +2308,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
87865 return vma;
87866 }
87867
87868+#ifdef CONFIG_PAX_SEGMEXEC
87869+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
87870+{
87871+ struct vm_area_struct *vma_m;
87872+
87873+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
87874+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
87875+ BUG_ON(vma->vm_mirror);
87876+ return NULL;
87877+ }
87878+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
87879+ vma_m = vma->vm_mirror;
87880+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
87881+ BUG_ON(vma->vm_file != vma_m->vm_file);
87882+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
87883+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
87884+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
87885+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
87886+ return vma_m;
87887+}
87888+#endif
87889+
87890 /*
87891 * Verify that the stack growth is acceptable and
87892 * update accounting. This is shared with both the
87893@@ -2043,6 +2346,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87894 return -ENOMEM;
87895
87896 /* Stack limit test */
87897+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
87898 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
87899 return -ENOMEM;
87900
87901@@ -2053,6 +2357,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87902 locked = mm->locked_vm + grow;
87903 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
87904 limit >>= PAGE_SHIFT;
87905+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
87906 if (locked > limit && !capable(CAP_IPC_LOCK))
87907 return -ENOMEM;
87908 }
87909@@ -2082,37 +2387,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87910 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
87911 * vma is the last one with address > vma->vm_end. Have to extend vma.
87912 */
87913+#ifndef CONFIG_IA64
87914+static
87915+#endif
87916 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
87917 {
87918 int error;
87919+ bool locknext;
87920
87921 if (!(vma->vm_flags & VM_GROWSUP))
87922 return -EFAULT;
87923
87924+ /* Also guard against wrapping around to address 0. */
87925+ if (address < PAGE_ALIGN(address+1))
87926+ address = PAGE_ALIGN(address+1);
87927+ else
87928+ return -ENOMEM;
87929+
87930 /*
87931 * We must make sure the anon_vma is allocated
87932 * so that the anon_vma locking is not a noop.
87933 */
87934 if (unlikely(anon_vma_prepare(vma)))
87935 return -ENOMEM;
87936+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
87937+ if (locknext && anon_vma_prepare(vma->vm_next))
87938+ return -ENOMEM;
87939 vma_lock_anon_vma(vma);
87940+ if (locknext)
87941+ vma_lock_anon_vma(vma->vm_next);
87942
87943 /*
87944 * vma->vm_start/vm_end cannot change under us because the caller
87945 * is required to hold the mmap_sem in read mode. We need the
87946- * anon_vma lock to serialize against concurrent expand_stacks.
87947- * Also guard against wrapping around to address 0.
87948+ * anon_vma locks to serialize against concurrent expand_stacks
87949+ * and expand_upwards.
87950 */
87951- if (address < PAGE_ALIGN(address+4))
87952- address = PAGE_ALIGN(address+4);
87953- else {
87954- vma_unlock_anon_vma(vma);
87955- return -ENOMEM;
87956- }
87957 error = 0;
87958
87959 /* Somebody else might have raced and expanded it already */
87960- if (address > vma->vm_end) {
87961+ 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)
87962+ error = -ENOMEM;
87963+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
87964 unsigned long size, grow;
87965
87966 size = address - vma->vm_start;
87967@@ -2147,6 +2463,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
87968 }
87969 }
87970 }
87971+ if (locknext)
87972+ vma_unlock_anon_vma(vma->vm_next);
87973 vma_unlock_anon_vma(vma);
87974 khugepaged_enter_vma_merge(vma);
87975 validate_mm(vma->vm_mm);
87976@@ -2161,6 +2479,8 @@ int expand_downwards(struct vm_area_struct *vma,
87977 unsigned long address)
87978 {
87979 int error;
87980+ bool lockprev = false;
87981+ struct vm_area_struct *prev;
87982
87983 /*
87984 * We must make sure the anon_vma is allocated
87985@@ -2174,6 +2494,15 @@ int expand_downwards(struct vm_area_struct *vma,
87986 if (error)
87987 return error;
87988
87989+ prev = vma->vm_prev;
87990+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
87991+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
87992+#endif
87993+ if (lockprev && anon_vma_prepare(prev))
87994+ return -ENOMEM;
87995+ if (lockprev)
87996+ vma_lock_anon_vma(prev);
87997+
87998 vma_lock_anon_vma(vma);
87999
88000 /*
88001@@ -2183,9 +2512,17 @@ int expand_downwards(struct vm_area_struct *vma,
88002 */
88003
88004 /* Somebody else might have raced and expanded it already */
88005- if (address < vma->vm_start) {
88006+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
88007+ error = -ENOMEM;
88008+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
88009 unsigned long size, grow;
88010
88011+#ifdef CONFIG_PAX_SEGMEXEC
88012+ struct vm_area_struct *vma_m;
88013+
88014+ vma_m = pax_find_mirror_vma(vma);
88015+#endif
88016+
88017 size = vma->vm_end - address;
88018 grow = (vma->vm_start - address) >> PAGE_SHIFT;
88019
88020@@ -2210,13 +2547,27 @@ int expand_downwards(struct vm_area_struct *vma,
88021 vma->vm_pgoff -= grow;
88022 anon_vma_interval_tree_post_update_vma(vma);
88023 vma_gap_update(vma);
88024+
88025+#ifdef CONFIG_PAX_SEGMEXEC
88026+ if (vma_m) {
88027+ anon_vma_interval_tree_pre_update_vma(vma_m);
88028+ vma_m->vm_start -= grow << PAGE_SHIFT;
88029+ vma_m->vm_pgoff -= grow;
88030+ anon_vma_interval_tree_post_update_vma(vma_m);
88031+ vma_gap_update(vma_m);
88032+ }
88033+#endif
88034+
88035 spin_unlock(&vma->vm_mm->page_table_lock);
88036
88037+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
88038 perf_event_mmap(vma);
88039 }
88040 }
88041 }
88042 vma_unlock_anon_vma(vma);
88043+ if (lockprev)
88044+ vma_unlock_anon_vma(prev);
88045 khugepaged_enter_vma_merge(vma);
88046 validate_mm(vma->vm_mm);
88047 return error;
88048@@ -2314,6 +2665,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
88049 do {
88050 long nrpages = vma_pages(vma);
88051
88052+#ifdef CONFIG_PAX_SEGMEXEC
88053+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
88054+ vma = remove_vma(vma);
88055+ continue;
88056+ }
88057+#endif
88058+
88059 if (vma->vm_flags & VM_ACCOUNT)
88060 nr_accounted += nrpages;
88061 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
88062@@ -2358,6 +2716,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
88063 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
88064 vma->vm_prev = NULL;
88065 do {
88066+
88067+#ifdef CONFIG_PAX_SEGMEXEC
88068+ if (vma->vm_mirror) {
88069+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
88070+ vma->vm_mirror->vm_mirror = NULL;
88071+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
88072+ vma->vm_mirror = NULL;
88073+ }
88074+#endif
88075+
88076 vma_rb_erase(vma, &mm->mm_rb);
88077 mm->map_count--;
88078 tail_vma = vma;
88079@@ -2384,14 +2752,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88080 struct vm_area_struct *new;
88081 int err = -ENOMEM;
88082
88083+#ifdef CONFIG_PAX_SEGMEXEC
88084+ struct vm_area_struct *vma_m, *new_m = NULL;
88085+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
88086+#endif
88087+
88088 if (is_vm_hugetlb_page(vma) && (addr &
88089 ~(huge_page_mask(hstate_vma(vma)))))
88090 return -EINVAL;
88091
88092+#ifdef CONFIG_PAX_SEGMEXEC
88093+ vma_m = pax_find_mirror_vma(vma);
88094+#endif
88095+
88096 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88097 if (!new)
88098 goto out_err;
88099
88100+#ifdef CONFIG_PAX_SEGMEXEC
88101+ if (vma_m) {
88102+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88103+ if (!new_m) {
88104+ kmem_cache_free(vm_area_cachep, new);
88105+ goto out_err;
88106+ }
88107+ }
88108+#endif
88109+
88110 /* most fields are the same, copy all, and then fixup */
88111 *new = *vma;
88112
88113@@ -2404,6 +2791,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88114 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
88115 }
88116
88117+#ifdef CONFIG_PAX_SEGMEXEC
88118+ if (vma_m) {
88119+ *new_m = *vma_m;
88120+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
88121+ new_m->vm_mirror = new;
88122+ new->vm_mirror = new_m;
88123+
88124+ if (new_below)
88125+ new_m->vm_end = addr_m;
88126+ else {
88127+ new_m->vm_start = addr_m;
88128+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
88129+ }
88130+ }
88131+#endif
88132+
88133 pol = mpol_dup(vma_policy(vma));
88134 if (IS_ERR(pol)) {
88135 err = PTR_ERR(pol);
88136@@ -2426,6 +2829,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88137 else
88138 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
88139
88140+#ifdef CONFIG_PAX_SEGMEXEC
88141+ if (!err && vma_m) {
88142+ if (anon_vma_clone(new_m, vma_m))
88143+ goto out_free_mpol;
88144+
88145+ mpol_get(pol);
88146+ vma_set_policy(new_m, pol);
88147+
88148+ if (new_m->vm_file)
88149+ get_file(new_m->vm_file);
88150+
88151+ if (new_m->vm_ops && new_m->vm_ops->open)
88152+ new_m->vm_ops->open(new_m);
88153+
88154+ if (new_below)
88155+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
88156+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
88157+ else
88158+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
88159+
88160+ if (err) {
88161+ if (new_m->vm_ops && new_m->vm_ops->close)
88162+ new_m->vm_ops->close(new_m);
88163+ if (new_m->vm_file)
88164+ fput(new_m->vm_file);
88165+ mpol_put(pol);
88166+ }
88167+ }
88168+#endif
88169+
88170 /* Success. */
88171 if (!err)
88172 return 0;
88173@@ -2435,10 +2868,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88174 new->vm_ops->close(new);
88175 if (new->vm_file)
88176 fput(new->vm_file);
88177- unlink_anon_vmas(new);
88178 out_free_mpol:
88179 mpol_put(pol);
88180 out_free_vma:
88181+
88182+#ifdef CONFIG_PAX_SEGMEXEC
88183+ if (new_m) {
88184+ unlink_anon_vmas(new_m);
88185+ kmem_cache_free(vm_area_cachep, new_m);
88186+ }
88187+#endif
88188+
88189+ unlink_anon_vmas(new);
88190 kmem_cache_free(vm_area_cachep, new);
88191 out_err:
88192 return err;
88193@@ -2451,6 +2892,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88194 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88195 unsigned long addr, int new_below)
88196 {
88197+
88198+#ifdef CONFIG_PAX_SEGMEXEC
88199+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
88200+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
88201+ if (mm->map_count >= sysctl_max_map_count-1)
88202+ return -ENOMEM;
88203+ } else
88204+#endif
88205+
88206 if (mm->map_count >= sysctl_max_map_count)
88207 return -ENOMEM;
88208
88209@@ -2462,11 +2912,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88210 * work. This now handles partial unmappings.
88211 * Jeremy Fitzhardinge <jeremy@goop.org>
88212 */
88213+#ifdef CONFIG_PAX_SEGMEXEC
88214 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88215 {
88216+ int ret = __do_munmap(mm, start, len);
88217+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
88218+ return ret;
88219+
88220+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
88221+}
88222+
88223+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88224+#else
88225+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88226+#endif
88227+{
88228 unsigned long end;
88229 struct vm_area_struct *vma, *prev, *last;
88230
88231+ /*
88232+ * mm->mmap_sem is required to protect against another thread
88233+ * changing the mappings in case we sleep.
88234+ */
88235+ verify_mm_writelocked(mm);
88236+
88237 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
88238 return -EINVAL;
88239
88240@@ -2541,6 +3010,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88241 /* Fix up all other VM information */
88242 remove_vma_list(mm, vma);
88243
88244+ track_exec_limit(mm, start, end, 0UL);
88245+
88246 return 0;
88247 }
88248
88249@@ -2549,6 +3020,13 @@ int vm_munmap(unsigned long start, size_t len)
88250 int ret;
88251 struct mm_struct *mm = current->mm;
88252
88253+
88254+#ifdef CONFIG_PAX_SEGMEXEC
88255+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
88256+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
88257+ return -EINVAL;
88258+#endif
88259+
88260 down_write(&mm->mmap_sem);
88261 ret = do_munmap(mm, start, len);
88262 up_write(&mm->mmap_sem);
88263@@ -2562,16 +3040,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
88264 return vm_munmap(addr, len);
88265 }
88266
88267-static inline void verify_mm_writelocked(struct mm_struct *mm)
88268-{
88269-#ifdef CONFIG_DEBUG_VM
88270- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
88271- WARN_ON(1);
88272- up_read(&mm->mmap_sem);
88273- }
88274-#endif
88275-}
88276-
88277 /*
88278 * this is really a simplified "do_mmap". it only handles
88279 * anonymous maps. eventually we may be able to do some
88280@@ -2585,6 +3053,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88281 struct rb_node ** rb_link, * rb_parent;
88282 pgoff_t pgoff = addr >> PAGE_SHIFT;
88283 int error;
88284+ unsigned long charged;
88285
88286 len = PAGE_ALIGN(len);
88287 if (!len)
88288@@ -2592,16 +3061,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88289
88290 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
88291
88292+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
88293+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
88294+ flags &= ~VM_EXEC;
88295+
88296+#ifdef CONFIG_PAX_MPROTECT
88297+ if (mm->pax_flags & MF_PAX_MPROTECT)
88298+ flags &= ~VM_MAYEXEC;
88299+#endif
88300+
88301+ }
88302+#endif
88303+
88304 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
88305 if (error & ~PAGE_MASK)
88306 return error;
88307
88308+ charged = len >> PAGE_SHIFT;
88309+
88310 /*
88311 * mlock MCL_FUTURE?
88312 */
88313 if (mm->def_flags & VM_LOCKED) {
88314 unsigned long locked, lock_limit;
88315- locked = len >> PAGE_SHIFT;
88316+ locked = charged;
88317 locked += mm->locked_vm;
88318 lock_limit = rlimit(RLIMIT_MEMLOCK);
88319 lock_limit >>= PAGE_SHIFT;
88320@@ -2618,21 +3101,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88321 /*
88322 * Clear old maps. this also does some error checking for us
88323 */
88324- munmap_back:
88325 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
88326 if (do_munmap(mm, addr, len))
88327 return -ENOMEM;
88328- goto munmap_back;
88329+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
88330 }
88331
88332 /* Check against address space limits *after* clearing old maps... */
88333- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
88334+ if (!may_expand_vm(mm, charged))
88335 return -ENOMEM;
88336
88337 if (mm->map_count > sysctl_max_map_count)
88338 return -ENOMEM;
88339
88340- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
88341+ if (security_vm_enough_memory_mm(mm, charged))
88342 return -ENOMEM;
88343
88344 /* Can we just expand an old private anonymous mapping? */
88345@@ -2646,7 +3128,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88346 */
88347 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88348 if (!vma) {
88349- vm_unacct_memory(len >> PAGE_SHIFT);
88350+ vm_unacct_memory(charged);
88351 return -ENOMEM;
88352 }
88353
88354@@ -2660,9 +3142,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88355 vma_link(mm, vma, prev, rb_link, rb_parent);
88356 out:
88357 perf_event_mmap(vma);
88358- mm->total_vm += len >> PAGE_SHIFT;
88359+ mm->total_vm += charged;
88360 if (flags & VM_LOCKED)
88361- mm->locked_vm += (len >> PAGE_SHIFT);
88362+ mm->locked_vm += charged;
88363+ track_exec_limit(mm, addr, addr + len, flags);
88364 return addr;
88365 }
88366
88367@@ -2724,6 +3207,7 @@ void exit_mmap(struct mm_struct *mm)
88368 while (vma) {
88369 if (vma->vm_flags & VM_ACCOUNT)
88370 nr_accounted += vma_pages(vma);
88371+ vma->vm_mirror = NULL;
88372 vma = remove_vma(vma);
88373 }
88374 vm_unacct_memory(nr_accounted);
88375@@ -2740,6 +3224,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
88376 struct vm_area_struct *prev;
88377 struct rb_node **rb_link, *rb_parent;
88378
88379+#ifdef CONFIG_PAX_SEGMEXEC
88380+ struct vm_area_struct *vma_m = NULL;
88381+#endif
88382+
88383+ if (security_mmap_addr(vma->vm_start))
88384+ return -EPERM;
88385+
88386 /*
88387 * The vm_pgoff of a purely anonymous vma should be irrelevant
88388 * until its first write fault, when page's anon_vma and index
88389@@ -2763,7 +3254,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
88390 security_vm_enough_memory_mm(mm, vma_pages(vma)))
88391 return -ENOMEM;
88392
88393+#ifdef CONFIG_PAX_SEGMEXEC
88394+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
88395+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88396+ if (!vma_m)
88397+ return -ENOMEM;
88398+ }
88399+#endif
88400+
88401 vma_link(mm, vma, prev, rb_link, rb_parent);
88402+
88403+#ifdef CONFIG_PAX_SEGMEXEC
88404+ if (vma_m)
88405+ BUG_ON(pax_mirror_vma(vma_m, vma));
88406+#endif
88407+
88408 return 0;
88409 }
88410
88411@@ -2783,6 +3288,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88412 struct mempolicy *pol;
88413 bool faulted_in_anon_vma = true;
88414
88415+ BUG_ON(vma->vm_mirror);
88416+
88417 /*
88418 * If anonymous vma has not yet been faulted, update new pgoff
88419 * to match new location, to increase its chance of merging.
88420@@ -2849,6 +3356,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88421 return NULL;
88422 }
88423
88424+#ifdef CONFIG_PAX_SEGMEXEC
88425+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
88426+{
88427+ struct vm_area_struct *prev_m;
88428+ struct rb_node **rb_link_m, *rb_parent_m;
88429+ struct mempolicy *pol_m;
88430+
88431+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
88432+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
88433+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
88434+ *vma_m = *vma;
88435+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
88436+ if (anon_vma_clone(vma_m, vma))
88437+ return -ENOMEM;
88438+ pol_m = vma_policy(vma_m);
88439+ mpol_get(pol_m);
88440+ vma_set_policy(vma_m, pol_m);
88441+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
88442+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
88443+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
88444+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
88445+ if (vma_m->vm_file)
88446+ get_file(vma_m->vm_file);
88447+ if (vma_m->vm_ops && vma_m->vm_ops->open)
88448+ vma_m->vm_ops->open(vma_m);
88449+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
88450+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
88451+ vma_m->vm_mirror = vma;
88452+ vma->vm_mirror = vma_m;
88453+ return 0;
88454+}
88455+#endif
88456+
88457 /*
88458 * Return true if the calling process may expand its vm space by the passed
88459 * number of pages
88460@@ -2860,6 +3400,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
88461
88462 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
88463
88464+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
88465 if (cur + npages > lim)
88466 return 0;
88467 return 1;
88468@@ -2930,6 +3471,22 @@ int install_special_mapping(struct mm_struct *mm,
88469 vma->vm_start = addr;
88470 vma->vm_end = addr + len;
88471
88472+#ifdef CONFIG_PAX_MPROTECT
88473+ if (mm->pax_flags & MF_PAX_MPROTECT) {
88474+#ifndef CONFIG_PAX_MPROTECT_COMPAT
88475+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
88476+ return -EPERM;
88477+ if (!(vm_flags & VM_EXEC))
88478+ vm_flags &= ~VM_MAYEXEC;
88479+#else
88480+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
88481+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
88482+#endif
88483+ else
88484+ vm_flags &= ~VM_MAYWRITE;
88485+ }
88486+#endif
88487+
88488 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
88489 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
88490
88491diff --git a/mm/mprotect.c b/mm/mprotect.c
88492index 94722a4..e661e29 100644
88493--- a/mm/mprotect.c
88494+++ b/mm/mprotect.c
88495@@ -23,10 +23,18 @@
88496 #include <linux/mmu_notifier.h>
88497 #include <linux/migrate.h>
88498 #include <linux/perf_event.h>
88499+#include <linux/sched/sysctl.h>
88500+
88501+#ifdef CONFIG_PAX_MPROTECT
88502+#include <linux/elf.h>
88503+#include <linux/binfmts.h>
88504+#endif
88505+
88506 #include <asm/uaccess.h>
88507 #include <asm/pgtable.h>
88508 #include <asm/cacheflush.h>
88509 #include <asm/tlbflush.h>
88510+#include <asm/mmu_context.h>
88511
88512 #ifndef pgprot_modify
88513 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
88514@@ -233,6 +241,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
88515 return pages;
88516 }
88517
88518+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88519+/* called while holding the mmap semaphor for writing except stack expansion */
88520+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
88521+{
88522+ unsigned long oldlimit, newlimit = 0UL;
88523+
88524+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
88525+ return;
88526+
88527+ spin_lock(&mm->page_table_lock);
88528+ oldlimit = mm->context.user_cs_limit;
88529+ if ((prot & VM_EXEC) && oldlimit < end)
88530+ /* USER_CS limit moved up */
88531+ newlimit = end;
88532+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
88533+ /* USER_CS limit moved down */
88534+ newlimit = start;
88535+
88536+ if (newlimit) {
88537+ mm->context.user_cs_limit = newlimit;
88538+
88539+#ifdef CONFIG_SMP
88540+ wmb();
88541+ cpus_clear(mm->context.cpu_user_cs_mask);
88542+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
88543+#endif
88544+
88545+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
88546+ }
88547+ spin_unlock(&mm->page_table_lock);
88548+ if (newlimit == end) {
88549+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
88550+
88551+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
88552+ if (is_vm_hugetlb_page(vma))
88553+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
88554+ else
88555+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
88556+ }
88557+}
88558+#endif
88559+
88560 int
88561 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88562 unsigned long start, unsigned long end, unsigned long newflags)
88563@@ -245,11 +295,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88564 int error;
88565 int dirty_accountable = 0;
88566
88567+#ifdef CONFIG_PAX_SEGMEXEC
88568+ struct vm_area_struct *vma_m = NULL;
88569+ unsigned long start_m, end_m;
88570+
88571+ start_m = start + SEGMEXEC_TASK_SIZE;
88572+ end_m = end + SEGMEXEC_TASK_SIZE;
88573+#endif
88574+
88575 if (newflags == oldflags) {
88576 *pprev = vma;
88577 return 0;
88578 }
88579
88580+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
88581+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
88582+
88583+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
88584+ return -ENOMEM;
88585+
88586+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
88587+ return -ENOMEM;
88588+ }
88589+
88590 /*
88591 * If we make a private mapping writable we increase our commit;
88592 * but (without finer accounting) cannot reduce our commit if we
88593@@ -266,6 +334,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88594 }
88595 }
88596
88597+#ifdef CONFIG_PAX_SEGMEXEC
88598+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
88599+ if (start != vma->vm_start) {
88600+ error = split_vma(mm, vma, start, 1);
88601+ if (error)
88602+ goto fail;
88603+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
88604+ *pprev = (*pprev)->vm_next;
88605+ }
88606+
88607+ if (end != vma->vm_end) {
88608+ error = split_vma(mm, vma, end, 0);
88609+ if (error)
88610+ goto fail;
88611+ }
88612+
88613+ if (pax_find_mirror_vma(vma)) {
88614+ error = __do_munmap(mm, start_m, end_m - start_m);
88615+ if (error)
88616+ goto fail;
88617+ } else {
88618+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88619+ if (!vma_m) {
88620+ error = -ENOMEM;
88621+ goto fail;
88622+ }
88623+ vma->vm_flags = newflags;
88624+ error = pax_mirror_vma(vma_m, vma);
88625+ if (error) {
88626+ vma->vm_flags = oldflags;
88627+ goto fail;
88628+ }
88629+ }
88630+ }
88631+#endif
88632+
88633 /*
88634 * First try to merge with previous and/or next vma.
88635 */
88636@@ -296,9 +400,21 @@ success:
88637 * vm_flags and vm_page_prot are protected by the mmap_sem
88638 * held in write mode.
88639 */
88640+
88641+#ifdef CONFIG_PAX_SEGMEXEC
88642+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
88643+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
88644+#endif
88645+
88646 vma->vm_flags = newflags;
88647+
88648+#ifdef CONFIG_PAX_MPROTECT
88649+ if (mm->binfmt && mm->binfmt->handle_mprotect)
88650+ mm->binfmt->handle_mprotect(vma, newflags);
88651+#endif
88652+
88653 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
88654- vm_get_page_prot(newflags));
88655+ vm_get_page_prot(vma->vm_flags));
88656
88657 if (vma_wants_writenotify(vma)) {
88658 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
88659@@ -337,6 +453,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88660 end = start + len;
88661 if (end <= start)
88662 return -ENOMEM;
88663+
88664+#ifdef CONFIG_PAX_SEGMEXEC
88665+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
88666+ if (end > SEGMEXEC_TASK_SIZE)
88667+ return -EINVAL;
88668+ } else
88669+#endif
88670+
88671+ if (end > TASK_SIZE)
88672+ return -EINVAL;
88673+
88674 if (!arch_validate_prot(prot))
88675 return -EINVAL;
88676
88677@@ -344,7 +471,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88678 /*
88679 * Does the application expect PROT_READ to imply PROT_EXEC:
88680 */
88681- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
88682+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
88683 prot |= PROT_EXEC;
88684
88685 vm_flags = calc_vm_prot_bits(prot);
88686@@ -376,6 +503,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88687 if (start > vma->vm_start)
88688 prev = vma;
88689
88690+#ifdef CONFIG_PAX_MPROTECT
88691+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
88692+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
88693+#endif
88694+
88695 for (nstart = start ; ; ) {
88696 unsigned long newflags;
88697
88698@@ -386,6 +518,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88699
88700 /* newflags >> 4 shift VM_MAY% in place of VM_% */
88701 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
88702+ if (prot & (PROT_WRITE | PROT_EXEC))
88703+ gr_log_rwxmprotect(vma);
88704+
88705+ error = -EACCES;
88706+ goto out;
88707+ }
88708+
88709+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
88710 error = -EACCES;
88711 goto out;
88712 }
88713@@ -400,6 +540,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88714 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
88715 if (error)
88716 goto out;
88717+
88718+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
88719+
88720 nstart = tmp;
88721
88722 if (nstart < prev->vm_end)
88723diff --git a/mm/mremap.c b/mm/mremap.c
88724index 0843feb..5607f47 100644
88725--- a/mm/mremap.c
88726+++ b/mm/mremap.c
88727@@ -25,6 +25,7 @@
88728 #include <asm/uaccess.h>
88729 #include <asm/cacheflush.h>
88730 #include <asm/tlbflush.h>
88731+#include <asm/pgalloc.h>
88732
88733 #include "internal.h"
88734
88735@@ -62,8 +63,10 @@ static pmd_t *alloc_new_pmd(struct mm_struct *mm, struct vm_area_struct *vma,
88736 return NULL;
88737
88738 pmd = pmd_alloc(mm, pud, addr);
88739- if (!pmd)
88740+ if (!pmd) {
88741+ pud_free(mm, pud);
88742 return NULL;
88743+ }
88744
88745 VM_BUG_ON(pmd_trans_huge(*pmd));
88746
88747@@ -144,6 +147,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
88748 continue;
88749 pte = ptep_get_and_clear(mm, old_addr, old_pte);
88750 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
88751+
88752+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88753+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
88754+ pte = pte_exprotect(pte);
88755+#endif
88756+
88757 pte = move_soft_dirty_pte(pte);
88758 set_pte_at(mm, new_addr, new_pte, pte);
88759 }
88760@@ -337,6 +346,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
88761 if (is_vm_hugetlb_page(vma))
88762 goto Einval;
88763
88764+#ifdef CONFIG_PAX_SEGMEXEC
88765+ if (pax_find_mirror_vma(vma))
88766+ goto Einval;
88767+#endif
88768+
88769 /* We can't remap across vm area boundaries */
88770 if (old_len > vma->vm_end - addr)
88771 goto Efault;
88772@@ -392,20 +406,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
88773 unsigned long ret = -EINVAL;
88774 unsigned long charged = 0;
88775 unsigned long map_flags;
88776+ unsigned long pax_task_size = TASK_SIZE;
88777
88778 if (new_addr & ~PAGE_MASK)
88779 goto out;
88780
88781- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
88782+#ifdef CONFIG_PAX_SEGMEXEC
88783+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88784+ pax_task_size = SEGMEXEC_TASK_SIZE;
88785+#endif
88786+
88787+ pax_task_size -= PAGE_SIZE;
88788+
88789+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
88790 goto out;
88791
88792 /* Check if the location we're moving into overlaps the
88793 * old location at all, and fail if it does.
88794 */
88795- if ((new_addr <= addr) && (new_addr+new_len) > addr)
88796- goto out;
88797-
88798- if ((addr <= new_addr) && (addr+old_len) > new_addr)
88799+ if (addr + old_len > new_addr && new_addr + new_len > addr)
88800 goto out;
88801
88802 ret = do_munmap(mm, new_addr, new_len);
88803@@ -474,6 +493,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88804 unsigned long ret = -EINVAL;
88805 unsigned long charged = 0;
88806 bool locked = false;
88807+ unsigned long pax_task_size = TASK_SIZE;
88808
88809 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
88810 return ret;
88811@@ -495,6 +515,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88812 if (!new_len)
88813 return ret;
88814
88815+#ifdef CONFIG_PAX_SEGMEXEC
88816+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88817+ pax_task_size = SEGMEXEC_TASK_SIZE;
88818+#endif
88819+
88820+ pax_task_size -= PAGE_SIZE;
88821+
88822+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
88823+ old_len > pax_task_size || addr > pax_task_size-old_len)
88824+ return ret;
88825+
88826 down_write(&current->mm->mmap_sem);
88827
88828 if (flags & MREMAP_FIXED) {
88829@@ -545,6 +576,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88830 new_addr = addr;
88831 }
88832 ret = addr;
88833+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
88834 goto out;
88835 }
88836 }
88837@@ -568,7 +600,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88838 goto out;
88839 }
88840
88841+ map_flags = vma->vm_flags;
88842 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
88843+ if (!(ret & ~PAGE_MASK)) {
88844+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
88845+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
88846+ }
88847 }
88848 out:
88849 if (ret & ~PAGE_MASK)
88850diff --git a/mm/nommu.c b/mm/nommu.c
88851index ecd1f15..77039bd 100644
88852--- a/mm/nommu.c
88853+++ b/mm/nommu.c
88854@@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
88855 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
88856 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
88857 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
88858-int heap_stack_gap = 0;
88859
88860 atomic_long_t mmap_pages_allocated;
88861
88862@@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
88863 EXPORT_SYMBOL(find_vma);
88864
88865 /*
88866- * find a VMA
88867- * - we don't extend stack VMAs under NOMMU conditions
88868- */
88869-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
88870-{
88871- return find_vma(mm, addr);
88872-}
88873-
88874-/*
88875 * expand a stack to a given address
88876 * - not supported under NOMMU conditions
88877 */
88878@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88879
88880 /* most fields are the same, copy all, and then fixup */
88881 *new = *vma;
88882+ INIT_LIST_HEAD(&new->anon_vma_chain);
88883 *region = *vma->vm_region;
88884 new->vm_region = region;
88885
88886@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
88887 }
88888 EXPORT_SYMBOL(generic_file_remap_pages);
88889
88890-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88891- unsigned long addr, void *buf, int len, int write)
88892+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88893+ unsigned long addr, void *buf, size_t len, int write)
88894 {
88895 struct vm_area_struct *vma;
88896
88897@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88898 *
88899 * The caller must hold a reference on @mm.
88900 */
88901-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88902- void *buf, int len, int write)
88903+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
88904+ void *buf, size_t len, int write)
88905 {
88906 return __access_remote_vm(NULL, mm, addr, buf, len, write);
88907 }
88908@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88909 * Access another process' address space.
88910 * - source/target buffer must be kernel space
88911 */
88912-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
88913+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
88914 {
88915 struct mm_struct *mm;
88916
88917diff --git a/mm/page-writeback.c b/mm/page-writeback.c
88918index 3f0c895..60cd104 100644
88919--- a/mm/page-writeback.c
88920+++ b/mm/page-writeback.c
88921@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
88922 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
88923 * - the bdi dirty thresh drops quickly due to change of JBOD workload
88924 */
88925-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
88926+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
88927 unsigned long thresh,
88928 unsigned long bg_thresh,
88929 unsigned long dirty,
88930diff --git a/mm/page_alloc.c b/mm/page_alloc.c
88931index b100255..a59b444 100644
88932--- a/mm/page_alloc.c
88933+++ b/mm/page_alloc.c
88934@@ -60,6 +60,7 @@
88935 #include <linux/page-debug-flags.h>
88936 #include <linux/hugetlb.h>
88937 #include <linux/sched/rt.h>
88938+#include <linux/random.h>
88939
88940 #include <asm/sections.h>
88941 #include <asm/tlbflush.h>
88942@@ -353,7 +354,7 @@ out:
88943 * This usage means that zero-order pages may not be compound.
88944 */
88945
88946-static void free_compound_page(struct page *page)
88947+void free_compound_page(struct page *page)
88948 {
88949 __free_pages_ok(page, compound_order(page));
88950 }
88951@@ -710,6 +711,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
88952 int i;
88953 int bad = 0;
88954
88955+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88956+ unsigned long index = 1UL << order;
88957+#endif
88958+
88959 trace_mm_page_free(page, order);
88960 kmemcheck_free_shadow(page, order);
88961
88962@@ -725,6 +730,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
88963 debug_check_no_obj_freed(page_address(page),
88964 PAGE_SIZE << order);
88965 }
88966+
88967+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88968+ for (; index; --index)
88969+ sanitize_highpage(page + index - 1);
88970+#endif
88971+
88972 arch_free_page(page, order);
88973 kernel_map_pages(page, 1 << order, 0);
88974
88975@@ -747,6 +758,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
88976 local_irq_restore(flags);
88977 }
88978
88979+#ifdef CONFIG_PAX_LATENT_ENTROPY
88980+bool __meminitdata extra_latent_entropy;
88981+
88982+static int __init setup_pax_extra_latent_entropy(char *str)
88983+{
88984+ extra_latent_entropy = true;
88985+ return 0;
88986+}
88987+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
88988+
88989+volatile u64 latent_entropy;
88990+#endif
88991+
88992 void __init __free_pages_bootmem(struct page *page, unsigned int order)
88993 {
88994 unsigned int nr_pages = 1 << order;
88995@@ -762,6 +786,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
88996 set_page_count(p, 0);
88997 }
88998
88999+#ifdef CONFIG_PAX_LATENT_ENTROPY
89000+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
89001+ u64 hash = 0;
89002+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
89003+ const u64 *data = lowmem_page_address(page);
89004+
89005+ for (index = 0; index < end; index++)
89006+ hash ^= hash + data[index];
89007+ latent_entropy ^= hash;
89008+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
89009+ }
89010+#endif
89011+
89012 page_zone(page)->managed_pages += 1 << order;
89013 set_page_refcounted(page);
89014 __free_pages(page, order);
89015@@ -867,8 +904,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
89016 arch_alloc_page(page, order);
89017 kernel_map_pages(page, 1 << order, 1);
89018
89019+#ifndef CONFIG_PAX_MEMORY_SANITIZE
89020 if (gfp_flags & __GFP_ZERO)
89021 prep_zero_page(page, order, gfp_flags);
89022+#endif
89023
89024 if (order && (gfp_flags & __GFP_COMP))
89025 prep_compound_page(page, order);
89026diff --git a/mm/page_io.c b/mm/page_io.c
89027index ba05b64..ef2f314 100644
89028--- a/mm/page_io.c
89029+++ b/mm/page_io.c
89030@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
89031 struct file *swap_file = sis->swap_file;
89032 struct address_space *mapping = swap_file->f_mapping;
89033 struct iovec iov = {
89034- .iov_base = kmap(page),
89035+ .iov_base = (void __force_user *)kmap(page),
89036 .iov_len = PAGE_SIZE,
89037 };
89038
89039diff --git a/mm/percpu.c b/mm/percpu.c
89040index 8c8e08f..73a5cda 100644
89041--- a/mm/percpu.c
89042+++ b/mm/percpu.c
89043@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
89044 static unsigned int pcpu_high_unit_cpu __read_mostly;
89045
89046 /* the address of the first chunk which starts with the kernel static area */
89047-void *pcpu_base_addr __read_mostly;
89048+void *pcpu_base_addr __read_only;
89049 EXPORT_SYMBOL_GPL(pcpu_base_addr);
89050
89051 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
89052diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
89053index fd26d04..0cea1b0 100644
89054--- a/mm/process_vm_access.c
89055+++ b/mm/process_vm_access.c
89056@@ -13,6 +13,7 @@
89057 #include <linux/uio.h>
89058 #include <linux/sched.h>
89059 #include <linux/highmem.h>
89060+#include <linux/security.h>
89061 #include <linux/ptrace.h>
89062 #include <linux/slab.h>
89063 #include <linux/syscalls.h>
89064@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
89065 size_t iov_l_curr_offset = 0;
89066 ssize_t iov_len;
89067
89068+ return -ENOSYS; // PaX: until properly audited
89069+
89070 /*
89071 * Work out how many pages of struct pages we're going to need
89072 * when eventually calling get_user_pages
89073 */
89074 for (i = 0; i < riovcnt; i++) {
89075 iov_len = rvec[i].iov_len;
89076- if (iov_len > 0) {
89077- nr_pages_iov = ((unsigned long)rvec[i].iov_base
89078- + iov_len)
89079- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
89080- / PAGE_SIZE + 1;
89081- nr_pages = max(nr_pages, nr_pages_iov);
89082- }
89083+ if (iov_len <= 0)
89084+ continue;
89085+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
89086+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
89087+ nr_pages = max(nr_pages, nr_pages_iov);
89088 }
89089
89090 if (nr_pages == 0)
89091@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
89092 goto free_proc_pages;
89093 }
89094
89095+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
89096+ rc = -EPERM;
89097+ goto put_task_struct;
89098+ }
89099+
89100 mm = mm_access(task, PTRACE_MODE_ATTACH);
89101 if (!mm || IS_ERR(mm)) {
89102 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
89103diff --git a/mm/rmap.c b/mm/rmap.c
89104index b2e29ac..4168491 100644
89105--- a/mm/rmap.c
89106+++ b/mm/rmap.c
89107@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89108 struct anon_vma *anon_vma = vma->anon_vma;
89109 struct anon_vma_chain *avc;
89110
89111+#ifdef CONFIG_PAX_SEGMEXEC
89112+ struct anon_vma_chain *avc_m = NULL;
89113+#endif
89114+
89115 might_sleep();
89116 if (unlikely(!anon_vma)) {
89117 struct mm_struct *mm = vma->vm_mm;
89118@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89119 if (!avc)
89120 goto out_enomem;
89121
89122+#ifdef CONFIG_PAX_SEGMEXEC
89123+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
89124+ if (!avc_m)
89125+ goto out_enomem_free_avc;
89126+#endif
89127+
89128 anon_vma = find_mergeable_anon_vma(vma);
89129 allocated = NULL;
89130 if (!anon_vma) {
89131@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89132 /* page_table_lock to protect against threads */
89133 spin_lock(&mm->page_table_lock);
89134 if (likely(!vma->anon_vma)) {
89135+
89136+#ifdef CONFIG_PAX_SEGMEXEC
89137+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
89138+
89139+ if (vma_m) {
89140+ BUG_ON(vma_m->anon_vma);
89141+ vma_m->anon_vma = anon_vma;
89142+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
89143+ avc_m = NULL;
89144+ }
89145+#endif
89146+
89147 vma->anon_vma = anon_vma;
89148 anon_vma_chain_link(vma, avc, anon_vma);
89149 allocated = NULL;
89150@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89151
89152 if (unlikely(allocated))
89153 put_anon_vma(allocated);
89154+
89155+#ifdef CONFIG_PAX_SEGMEXEC
89156+ if (unlikely(avc_m))
89157+ anon_vma_chain_free(avc_m);
89158+#endif
89159+
89160 if (unlikely(avc))
89161 anon_vma_chain_free(avc);
89162 }
89163 return 0;
89164
89165 out_enomem_free_avc:
89166+
89167+#ifdef CONFIG_PAX_SEGMEXEC
89168+ if (avc_m)
89169+ anon_vma_chain_free(avc_m);
89170+#endif
89171+
89172 anon_vma_chain_free(avc);
89173 out_enomem:
89174 return -ENOMEM;
89175@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
89176 * Attach the anon_vmas from src to dst.
89177 * Returns 0 on success, -ENOMEM on failure.
89178 */
89179-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
89180+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
89181 {
89182 struct anon_vma_chain *avc, *pavc;
89183 struct anon_vma *root = NULL;
89184@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
89185 * the corresponding VMA in the parent process is attached to.
89186 * Returns 0 on success, non-zero on failure.
89187 */
89188-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
89189+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
89190 {
89191 struct anon_vma_chain *avc;
89192 struct anon_vma *anon_vma;
89193@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
89194 void __init anon_vma_init(void)
89195 {
89196 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
89197- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
89198- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
89199+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
89200+ anon_vma_ctor);
89201+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
89202+ SLAB_PANIC|SLAB_NO_SANITIZE);
89203 }
89204
89205 /*
89206diff --git a/mm/shmem.c b/mm/shmem.c
89207index e43dc55..930e3a2 100644
89208--- a/mm/shmem.c
89209+++ b/mm/shmem.c
89210@@ -33,7 +33,7 @@
89211 #include <linux/swap.h>
89212 #include <linux/aio.h>
89213
89214-static struct vfsmount *shm_mnt;
89215+struct vfsmount *shm_mnt;
89216
89217 #ifdef CONFIG_SHMEM
89218 /*
89219@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
89220 #define BOGO_DIRENT_SIZE 20
89221
89222 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
89223-#define SHORT_SYMLINK_LEN 128
89224+#define SHORT_SYMLINK_LEN 64
89225
89226 /*
89227 * shmem_fallocate and shmem_writepage communicate via inode->i_private
89228@@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
89229 static int shmem_xattr_validate(const char *name)
89230 {
89231 struct { const char *prefix; size_t len; } arr[] = {
89232+
89233+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
89234+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
89235+#endif
89236+
89237 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
89238 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
89239 };
89240@@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
89241 if (err)
89242 return err;
89243
89244+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
89245+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
89246+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
89247+ return -EOPNOTSUPP;
89248+ if (size > 8)
89249+ return -EINVAL;
89250+ }
89251+#endif
89252+
89253 return simple_xattr_set(&info->xattrs, name, value, size, flags);
89254 }
89255
89256@@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
89257 int err = -ENOMEM;
89258
89259 /* Round up to L1_CACHE_BYTES to resist false sharing */
89260- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
89261- L1_CACHE_BYTES), GFP_KERNEL);
89262+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
89263 if (!sbinfo)
89264 return -ENOMEM;
89265
89266diff --git a/mm/slab.c b/mm/slab.c
89267index 2580db0..0523956 100644
89268--- a/mm/slab.c
89269+++ b/mm/slab.c
89270@@ -366,10 +366,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
89271 if ((x)->max_freeable < i) \
89272 (x)->max_freeable = i; \
89273 } while (0)
89274-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
89275-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
89276-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
89277-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
89278+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
89279+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
89280+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
89281+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
89282+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
89283+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
89284 #else
89285 #define STATS_INC_ACTIVE(x) do { } while (0)
89286 #define STATS_DEC_ACTIVE(x) do { } while (0)
89287@@ -386,6 +388,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
89288 #define STATS_INC_ALLOCMISS(x) do { } while (0)
89289 #define STATS_INC_FREEHIT(x) do { } while (0)
89290 #define STATS_INC_FREEMISS(x) do { } while (0)
89291+#define STATS_INC_SANITIZED(x) do { } while (0)
89292+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
89293 #endif
89294
89295 #if DEBUG
89296@@ -477,7 +481,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
89297 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
89298 */
89299 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
89300- const struct slab *slab, void *obj)
89301+ const struct slab *slab, const void *obj)
89302 {
89303 u32 offset = (obj - slab->s_mem);
89304 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
89305@@ -1571,12 +1575,12 @@ void __init kmem_cache_init(void)
89306 */
89307
89308 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
89309- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
89310+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
89311
89312 if (INDEX_AC != INDEX_NODE)
89313 kmalloc_caches[INDEX_NODE] =
89314 create_kmalloc_cache("kmalloc-node",
89315- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
89316+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
89317
89318 slab_early_init = 0;
89319
89320@@ -3577,6 +3581,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
89321 struct array_cache *ac = cpu_cache_get(cachep);
89322
89323 check_irq_off();
89324+
89325+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89326+ if (pax_sanitize_slab) {
89327+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
89328+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
89329+
89330+ if (cachep->ctor)
89331+ cachep->ctor(objp);
89332+
89333+ STATS_INC_SANITIZED(cachep);
89334+ } else
89335+ STATS_INC_NOT_SANITIZED(cachep);
89336+ }
89337+#endif
89338+
89339 kmemleak_free_recursive(objp, cachep->flags);
89340 objp = cache_free_debugcheck(cachep, objp, caller);
89341
89342@@ -3805,6 +3824,7 @@ void kfree(const void *objp)
89343
89344 if (unlikely(ZERO_OR_NULL_PTR(objp)))
89345 return;
89346+ VM_BUG_ON(!virt_addr_valid(objp));
89347 local_irq_save(flags);
89348 kfree_debugcheck(objp);
89349 c = virt_to_cache(objp);
89350@@ -4246,14 +4266,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
89351 }
89352 /* cpu stats */
89353 {
89354- unsigned long allochit = atomic_read(&cachep->allochit);
89355- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
89356- unsigned long freehit = atomic_read(&cachep->freehit);
89357- unsigned long freemiss = atomic_read(&cachep->freemiss);
89358+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
89359+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
89360+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
89361+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
89362
89363 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
89364 allochit, allocmiss, freehit, freemiss);
89365 }
89366+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89367+ {
89368+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
89369+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
89370+
89371+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
89372+ }
89373+#endif
89374 #endif
89375 }
89376
89377@@ -4471,13 +4499,71 @@ static const struct file_operations proc_slabstats_operations = {
89378 static int __init slab_proc_init(void)
89379 {
89380 #ifdef CONFIG_DEBUG_SLAB_LEAK
89381- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
89382+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
89383 #endif
89384 return 0;
89385 }
89386 module_init(slab_proc_init);
89387 #endif
89388
89389+bool is_usercopy_object(const void *ptr)
89390+{
89391+ struct page *page;
89392+ struct kmem_cache *cachep;
89393+
89394+ if (ZERO_OR_NULL_PTR(ptr))
89395+ return false;
89396+
89397+ if (!slab_is_available())
89398+ return false;
89399+
89400+ if (!virt_addr_valid(ptr))
89401+ return false;
89402+
89403+ page = virt_to_head_page(ptr);
89404+
89405+ if (!PageSlab(page))
89406+ return false;
89407+
89408+ cachep = page->slab_cache;
89409+ return cachep->flags & SLAB_USERCOPY;
89410+}
89411+
89412+#ifdef CONFIG_PAX_USERCOPY
89413+const char *check_heap_object(const void *ptr, unsigned long n)
89414+{
89415+ struct page *page;
89416+ struct kmem_cache *cachep;
89417+ struct slab *slabp;
89418+ unsigned int objnr;
89419+ unsigned long offset;
89420+
89421+ if (ZERO_OR_NULL_PTR(ptr))
89422+ return "<null>";
89423+
89424+ if (!virt_addr_valid(ptr))
89425+ return NULL;
89426+
89427+ page = virt_to_head_page(ptr);
89428+
89429+ if (!PageSlab(page))
89430+ return NULL;
89431+
89432+ cachep = page->slab_cache;
89433+ if (!(cachep->flags & SLAB_USERCOPY))
89434+ return cachep->name;
89435+
89436+ slabp = page->slab_page;
89437+ objnr = obj_to_index(cachep, slabp, ptr);
89438+ BUG_ON(objnr >= cachep->num);
89439+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
89440+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
89441+ return NULL;
89442+
89443+ return cachep->name;
89444+}
89445+#endif
89446+
89447 /**
89448 * ksize - get the actual amount of memory allocated for a given object
89449 * @objp: Pointer to the object
89450diff --git a/mm/slab.h b/mm/slab.h
89451index a535033..2f98fe5 100644
89452--- a/mm/slab.h
89453+++ b/mm/slab.h
89454@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
89455 /* The slab cache that manages slab cache information */
89456 extern struct kmem_cache *kmem_cache;
89457
89458+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89459+#ifdef CONFIG_X86_64
89460+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
89461+#else
89462+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
89463+#endif
89464+extern bool pax_sanitize_slab;
89465+#endif
89466+
89467 unsigned long calculate_alignment(unsigned long flags,
89468 unsigned long align, unsigned long size);
89469
89470@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
89471
89472 /* Legal flag mask for kmem_cache_create(), for various configurations */
89473 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
89474- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
89475+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
89476+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
89477
89478 #if defined(CONFIG_DEBUG_SLAB)
89479 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
89480@@ -231,6 +241,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
89481 return s;
89482
89483 page = virt_to_head_page(x);
89484+
89485+ BUG_ON(!PageSlab(page));
89486+
89487 cachep = page->slab_cache;
89488 if (slab_equal_or_root(cachep, s))
89489 return cachep;
89490diff --git a/mm/slab_common.c b/mm/slab_common.c
89491index 538bade..36fed99 100644
89492--- a/mm/slab_common.c
89493+++ b/mm/slab_common.c
89494@@ -22,11 +22,22 @@
89495
89496 #include "slab.h"
89497
89498-enum slab_state slab_state;
89499+enum slab_state slab_state __read_only;
89500 LIST_HEAD(slab_caches);
89501 DEFINE_MUTEX(slab_mutex);
89502 struct kmem_cache *kmem_cache;
89503
89504+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89505+bool pax_sanitize_slab __read_only = true;
89506+static int __init pax_sanitize_slab_setup(char *str)
89507+{
89508+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
89509+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
89510+ return 1;
89511+}
89512+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
89513+#endif
89514+
89515 #ifdef CONFIG_DEBUG_VM
89516 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
89517 size_t size)
89518@@ -209,7 +220,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
89519
89520 err = __kmem_cache_create(s, flags);
89521 if (!err) {
89522- s->refcount = 1;
89523+ atomic_set(&s->refcount, 1);
89524 list_add(&s->list, &slab_caches);
89525 memcg_cache_list_add(memcg, s);
89526 } else {
89527@@ -255,8 +266,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
89528
89529 get_online_cpus();
89530 mutex_lock(&slab_mutex);
89531- s->refcount--;
89532- if (!s->refcount) {
89533+ if (atomic_dec_and_test(&s->refcount)) {
89534 list_del(&s->list);
89535
89536 if (!__kmem_cache_shutdown(s)) {
89537@@ -302,7 +312,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
89538 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
89539 name, size, err);
89540
89541- s->refcount = -1; /* Exempt from merging for now */
89542+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
89543 }
89544
89545 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89546@@ -315,7 +325,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89547
89548 create_boot_cache(s, name, size, flags);
89549 list_add(&s->list, &slab_caches);
89550- s->refcount = 1;
89551+ atomic_set(&s->refcount, 1);
89552 return s;
89553 }
89554
89555@@ -327,6 +337,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
89556 EXPORT_SYMBOL(kmalloc_dma_caches);
89557 #endif
89558
89559+#ifdef CONFIG_PAX_USERCOPY_SLABS
89560+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
89561+EXPORT_SYMBOL(kmalloc_usercopy_caches);
89562+#endif
89563+
89564 /*
89565 * Conversion table for small slabs sizes / 8 to the index in the
89566 * kmalloc array. This is necessary for slabs < 192 since we have non power
89567@@ -391,6 +406,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
89568 return kmalloc_dma_caches[index];
89569
89570 #endif
89571+
89572+#ifdef CONFIG_PAX_USERCOPY_SLABS
89573+ if (unlikely((flags & GFP_USERCOPY)))
89574+ return kmalloc_usercopy_caches[index];
89575+
89576+#endif
89577+
89578 return kmalloc_caches[index];
89579 }
89580
89581@@ -447,7 +469,7 @@ void __init create_kmalloc_caches(unsigned long flags)
89582 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
89583 if (!kmalloc_caches[i]) {
89584 kmalloc_caches[i] = create_kmalloc_cache(NULL,
89585- 1 << i, flags);
89586+ 1 << i, SLAB_USERCOPY | flags);
89587 }
89588
89589 /*
89590@@ -456,10 +478,10 @@ void __init create_kmalloc_caches(unsigned long flags)
89591 * earlier power of two caches
89592 */
89593 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
89594- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
89595+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
89596
89597 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
89598- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
89599+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
89600 }
89601
89602 /* Kmalloc array is now usable */
89603@@ -492,6 +514,23 @@ void __init create_kmalloc_caches(unsigned long flags)
89604 }
89605 }
89606 #endif
89607+
89608+#ifdef CONFIG_PAX_USERCOPY_SLABS
89609+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
89610+ struct kmem_cache *s = kmalloc_caches[i];
89611+
89612+ if (s) {
89613+ int size = kmalloc_size(i);
89614+ char *n = kasprintf(GFP_NOWAIT,
89615+ "usercopy-kmalloc-%d", size);
89616+
89617+ BUG_ON(!n);
89618+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
89619+ size, SLAB_USERCOPY | flags);
89620+ }
89621+ }
89622+#endif
89623+
89624 }
89625 #endif /* !CONFIG_SLOB */
89626
89627@@ -523,6 +562,9 @@ void print_slabinfo_header(struct seq_file *m)
89628 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
89629 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
89630 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
89631+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89632+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
89633+#endif
89634 #endif
89635 seq_putc(m, '\n');
89636 }
89637diff --git a/mm/slob.c b/mm/slob.c
89638index 91bd3f2..e2f549e 100644
89639--- a/mm/slob.c
89640+++ b/mm/slob.c
89641@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
89642 /*
89643 * Return the size of a slob block.
89644 */
89645-static slobidx_t slob_units(slob_t *s)
89646+static slobidx_t slob_units(const slob_t *s)
89647 {
89648 if (s->units > 0)
89649 return s->units;
89650@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
89651 /*
89652 * Return the next free slob block pointer after this one.
89653 */
89654-static slob_t *slob_next(slob_t *s)
89655+static slob_t *slob_next(const slob_t *s)
89656 {
89657 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
89658 slobidx_t next;
89659@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
89660 /*
89661 * Returns true if s is the last free block in its page.
89662 */
89663-static int slob_last(slob_t *s)
89664+static int slob_last(const slob_t *s)
89665 {
89666 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
89667 }
89668
89669-static void *slob_new_pages(gfp_t gfp, int order, int node)
89670+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
89671 {
89672- void *page;
89673+ struct page *page;
89674
89675 #ifdef CONFIG_NUMA
89676 if (node != NUMA_NO_NODE)
89677@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
89678 if (!page)
89679 return NULL;
89680
89681- return page_address(page);
89682+ __SetPageSlab(page);
89683+ return page;
89684 }
89685
89686-static void slob_free_pages(void *b, int order)
89687+static void slob_free_pages(struct page *sp, int order)
89688 {
89689 if (current->reclaim_state)
89690 current->reclaim_state->reclaimed_slab += 1 << order;
89691- free_pages((unsigned long)b, order);
89692+ __ClearPageSlab(sp);
89693+ page_mapcount_reset(sp);
89694+ sp->private = 0;
89695+ __free_pages(sp, order);
89696 }
89697
89698 /*
89699@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
89700
89701 /* Not enough space: must allocate a new page */
89702 if (!b) {
89703- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89704- if (!b)
89705+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89706+ if (!sp)
89707 return NULL;
89708- sp = virt_to_page(b);
89709- __SetPageSlab(sp);
89710+ b = page_address(sp);
89711
89712 spin_lock_irqsave(&slob_lock, flags);
89713 sp->units = SLOB_UNITS(PAGE_SIZE);
89714 sp->freelist = b;
89715+ sp->private = 0;
89716 INIT_LIST_HEAD(&sp->list);
89717 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
89718 set_slob_page_free(sp, slob_list);
89719@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
89720 if (slob_page_free(sp))
89721 clear_slob_page_free(sp);
89722 spin_unlock_irqrestore(&slob_lock, flags);
89723- __ClearPageSlab(sp);
89724- page_mapcount_reset(sp);
89725- slob_free_pages(b, 0);
89726+ slob_free_pages(sp, 0);
89727 return;
89728 }
89729
89730+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89731+ if (pax_sanitize_slab)
89732+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
89733+#endif
89734+
89735 if (!slob_page_free(sp)) {
89736 /* This slob page is about to become partially free. Easy! */
89737 sp->units = units;
89738@@ -424,11 +431,10 @@ out:
89739 */
89740
89741 static __always_inline void *
89742-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89743+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
89744 {
89745- unsigned int *m;
89746- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89747- void *ret;
89748+ slob_t *m;
89749+ void *ret = NULL;
89750
89751 gfp &= gfp_allowed_mask;
89752
89753@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89754
89755 if (!m)
89756 return NULL;
89757- *m = size;
89758+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
89759+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
89760+ m[0].units = size;
89761+ m[1].units = align;
89762 ret = (void *)m + align;
89763
89764 trace_kmalloc_node(caller, ret,
89765 size, size + align, gfp, node);
89766 } else {
89767 unsigned int order = get_order(size);
89768+ struct page *page;
89769
89770 if (likely(order))
89771 gfp |= __GFP_COMP;
89772- ret = slob_new_pages(gfp, order, node);
89773+ page = slob_new_pages(gfp, order, node);
89774+ if (page) {
89775+ ret = page_address(page);
89776+ page->private = size;
89777+ }
89778
89779 trace_kmalloc_node(caller, ret,
89780 size, PAGE_SIZE << order, gfp, node);
89781 }
89782
89783- kmemleak_alloc(ret, size, 1, gfp);
89784+ return ret;
89785+}
89786+
89787+static __always_inline void *
89788+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89789+{
89790+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89791+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
89792+
89793+ if (!ZERO_OR_NULL_PTR(ret))
89794+ kmemleak_alloc(ret, size, 1, gfp);
89795 return ret;
89796 }
89797
89798@@ -493,34 +517,112 @@ void kfree(const void *block)
89799 return;
89800 kmemleak_free(block);
89801
89802+ VM_BUG_ON(!virt_addr_valid(block));
89803 sp = virt_to_page(block);
89804- if (PageSlab(sp)) {
89805+ VM_BUG_ON(!PageSlab(sp));
89806+ if (!sp->private) {
89807 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89808- unsigned int *m = (unsigned int *)(block - align);
89809- slob_free(m, *m + align);
89810- } else
89811+ slob_t *m = (slob_t *)(block - align);
89812+ slob_free(m, m[0].units + align);
89813+ } else {
89814+ __ClearPageSlab(sp);
89815+ page_mapcount_reset(sp);
89816+ sp->private = 0;
89817 __free_pages(sp, compound_order(sp));
89818+ }
89819 }
89820 EXPORT_SYMBOL(kfree);
89821
89822+bool is_usercopy_object(const void *ptr)
89823+{
89824+ if (!slab_is_available())
89825+ return false;
89826+
89827+ // PAX: TODO
89828+
89829+ return false;
89830+}
89831+
89832+#ifdef CONFIG_PAX_USERCOPY
89833+const char *check_heap_object(const void *ptr, unsigned long n)
89834+{
89835+ struct page *page;
89836+ const slob_t *free;
89837+ const void *base;
89838+ unsigned long flags;
89839+
89840+ if (ZERO_OR_NULL_PTR(ptr))
89841+ return "<null>";
89842+
89843+ if (!virt_addr_valid(ptr))
89844+ return NULL;
89845+
89846+ page = virt_to_head_page(ptr);
89847+ if (!PageSlab(page))
89848+ return NULL;
89849+
89850+ if (page->private) {
89851+ base = page;
89852+ if (base <= ptr && n <= page->private - (ptr - base))
89853+ return NULL;
89854+ return "<slob>";
89855+ }
89856+
89857+ /* some tricky double walking to find the chunk */
89858+ spin_lock_irqsave(&slob_lock, flags);
89859+ base = (void *)((unsigned long)ptr & PAGE_MASK);
89860+ free = page->freelist;
89861+
89862+ while (!slob_last(free) && (void *)free <= ptr) {
89863+ base = free + slob_units(free);
89864+ free = slob_next(free);
89865+ }
89866+
89867+ while (base < (void *)free) {
89868+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
89869+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
89870+ int offset;
89871+
89872+ if (ptr < base + align)
89873+ break;
89874+
89875+ offset = ptr - base - align;
89876+ if (offset >= m) {
89877+ base += size;
89878+ continue;
89879+ }
89880+
89881+ if (n > m - offset)
89882+ break;
89883+
89884+ spin_unlock_irqrestore(&slob_lock, flags);
89885+ return NULL;
89886+ }
89887+
89888+ spin_unlock_irqrestore(&slob_lock, flags);
89889+ return "<slob>";
89890+}
89891+#endif
89892+
89893 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
89894 size_t ksize(const void *block)
89895 {
89896 struct page *sp;
89897 int align;
89898- unsigned int *m;
89899+ slob_t *m;
89900
89901 BUG_ON(!block);
89902 if (unlikely(block == ZERO_SIZE_PTR))
89903 return 0;
89904
89905 sp = virt_to_page(block);
89906- if (unlikely(!PageSlab(sp)))
89907- return PAGE_SIZE << compound_order(sp);
89908+ VM_BUG_ON(!PageSlab(sp));
89909+ if (sp->private)
89910+ return sp->private;
89911
89912 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89913- m = (unsigned int *)(block - align);
89914- return SLOB_UNITS(*m) * SLOB_UNIT;
89915+ m = (slob_t *)(block - align);
89916+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
89917 }
89918 EXPORT_SYMBOL(ksize);
89919
89920@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
89921
89922 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
89923 {
89924- void *b;
89925+ void *b = NULL;
89926
89927 flags &= gfp_allowed_mask;
89928
89929 lockdep_trace_alloc(flags);
89930
89931+#ifdef CONFIG_PAX_USERCOPY_SLABS
89932+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
89933+#else
89934 if (c->size < PAGE_SIZE) {
89935 b = slob_alloc(c->size, flags, c->align, node);
89936 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
89937 SLOB_UNITS(c->size) * SLOB_UNIT,
89938 flags, node);
89939 } else {
89940- b = slob_new_pages(flags, get_order(c->size), node);
89941+ struct page *sp;
89942+
89943+ sp = slob_new_pages(flags, get_order(c->size), node);
89944+ if (sp) {
89945+ b = page_address(sp);
89946+ sp->private = c->size;
89947+ }
89948 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
89949 PAGE_SIZE << get_order(c->size),
89950 flags, node);
89951 }
89952+#endif
89953
89954 if (b && c->ctor)
89955 c->ctor(b);
89956@@ -564,10 +676,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
89957
89958 static void __kmem_cache_free(void *b, int size)
89959 {
89960- if (size < PAGE_SIZE)
89961+ struct page *sp;
89962+
89963+ sp = virt_to_page(b);
89964+ BUG_ON(!PageSlab(sp));
89965+ if (!sp->private)
89966 slob_free(b, size);
89967 else
89968- slob_free_pages(b, get_order(size));
89969+ slob_free_pages(sp, get_order(size));
89970 }
89971
89972 static void kmem_rcu_free(struct rcu_head *head)
89973@@ -580,17 +696,31 @@ static void kmem_rcu_free(struct rcu_head *head)
89974
89975 void kmem_cache_free(struct kmem_cache *c, void *b)
89976 {
89977+ int size = c->size;
89978+
89979+#ifdef CONFIG_PAX_USERCOPY_SLABS
89980+ if (size + c->align < PAGE_SIZE) {
89981+ size += c->align;
89982+ b -= c->align;
89983+ }
89984+#endif
89985+
89986 kmemleak_free_recursive(b, c->flags);
89987 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
89988 struct slob_rcu *slob_rcu;
89989- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
89990- slob_rcu->size = c->size;
89991+ slob_rcu = b + (size - sizeof(struct slob_rcu));
89992+ slob_rcu->size = size;
89993 call_rcu(&slob_rcu->head, kmem_rcu_free);
89994 } else {
89995- __kmem_cache_free(b, c->size);
89996+ __kmem_cache_free(b, size);
89997 }
89998
89999+#ifdef CONFIG_PAX_USERCOPY_SLABS
90000+ trace_kfree(_RET_IP_, b);
90001+#else
90002 trace_kmem_cache_free(_RET_IP_, b);
90003+#endif
90004+
90005 }
90006 EXPORT_SYMBOL(kmem_cache_free);
90007
90008diff --git a/mm/slub.c b/mm/slub.c
90009index e3ba1f2..bd45dac 100644
90010--- a/mm/slub.c
90011+++ b/mm/slub.c
90012@@ -207,7 +207,7 @@ struct track {
90013
90014 enum track_item { TRACK_ALLOC, TRACK_FREE };
90015
90016-#ifdef CONFIG_SYSFS
90017+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90018 static int sysfs_slab_add(struct kmem_cache *);
90019 static int sysfs_slab_alias(struct kmem_cache *, const char *);
90020 static void sysfs_slab_remove(struct kmem_cache *);
90021@@ -528,7 +528,7 @@ static void print_track(const char *s, struct track *t)
90022 if (!t->addr)
90023 return;
90024
90025- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
90026+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
90027 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
90028 #ifdef CONFIG_STACKTRACE
90029 {
90030@@ -2609,6 +2609,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
90031
90032 slab_free_hook(s, x);
90033
90034+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90035+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
90036+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
90037+ if (s->ctor)
90038+ s->ctor(x);
90039+ }
90040+#endif
90041+
90042 redo:
90043 /*
90044 * Determine the currently cpus per cpu slab.
90045@@ -2676,7 +2684,7 @@ static int slub_min_objects;
90046 * Merge control. If this is set then no merging of slab caches will occur.
90047 * (Could be removed. This was introduced to pacify the merge skeptics.)
90048 */
90049-static int slub_nomerge;
90050+static int slub_nomerge = 1;
90051
90052 /*
90053 * Calculate the order of allocation given an slab object size.
90054@@ -2953,6 +2961,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
90055 s->inuse = size;
90056
90057 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
90058+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90059+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
90060+#endif
90061 s->ctor)) {
90062 /*
90063 * Relocate free pointer after the object if it is not
90064@@ -3298,6 +3309,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
90065 EXPORT_SYMBOL(__kmalloc_node);
90066 #endif
90067
90068+bool is_usercopy_object(const void *ptr)
90069+{
90070+ struct page *page;
90071+ struct kmem_cache *s;
90072+
90073+ if (ZERO_OR_NULL_PTR(ptr))
90074+ return false;
90075+
90076+ if (!slab_is_available())
90077+ return false;
90078+
90079+ if (!virt_addr_valid(ptr))
90080+ return false;
90081+
90082+ page = virt_to_head_page(ptr);
90083+
90084+ if (!PageSlab(page))
90085+ return false;
90086+
90087+ s = page->slab_cache;
90088+ return s->flags & SLAB_USERCOPY;
90089+}
90090+
90091+#ifdef CONFIG_PAX_USERCOPY
90092+const char *check_heap_object(const void *ptr, unsigned long n)
90093+{
90094+ struct page *page;
90095+ struct kmem_cache *s;
90096+ unsigned long offset;
90097+
90098+ if (ZERO_OR_NULL_PTR(ptr))
90099+ return "<null>";
90100+
90101+ if (!virt_addr_valid(ptr))
90102+ return NULL;
90103+
90104+ page = virt_to_head_page(ptr);
90105+
90106+ if (!PageSlab(page))
90107+ return NULL;
90108+
90109+ s = page->slab_cache;
90110+ if (!(s->flags & SLAB_USERCOPY))
90111+ return s->name;
90112+
90113+ offset = (ptr - page_address(page)) % s->size;
90114+ if (offset <= s->object_size && n <= s->object_size - offset)
90115+ return NULL;
90116+
90117+ return s->name;
90118+}
90119+#endif
90120+
90121 size_t ksize(const void *object)
90122 {
90123 struct page *page;
90124@@ -3362,6 +3426,7 @@ void kfree(const void *x)
90125 if (unlikely(ZERO_OR_NULL_PTR(x)))
90126 return;
90127
90128+ VM_BUG_ON(!virt_addr_valid(x));
90129 page = virt_to_head_page(x);
90130 if (unlikely(!PageSlab(page))) {
90131 BUG_ON(!PageCompound(page));
90132@@ -3667,7 +3732,7 @@ static int slab_unmergeable(struct kmem_cache *s)
90133 /*
90134 * We may have set a slab to be unmergeable during bootstrap.
90135 */
90136- if (s->refcount < 0)
90137+ if (atomic_read(&s->refcount) < 0)
90138 return 1;
90139
90140 return 0;
90141@@ -3725,7 +3790,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90142
90143 s = find_mergeable(memcg, size, align, flags, name, ctor);
90144 if (s) {
90145- s->refcount++;
90146+ atomic_inc(&s->refcount);
90147 /*
90148 * Adjust the object sizes so that we clear
90149 * the complete object on kzalloc.
90150@@ -3734,7 +3799,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90151 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
90152
90153 if (sysfs_slab_alias(s, name)) {
90154- s->refcount--;
90155+ atomic_dec(&s->refcount);
90156 s = NULL;
90157 }
90158 }
90159@@ -3854,7 +3919,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
90160 }
90161 #endif
90162
90163-#ifdef CONFIG_SYSFS
90164+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90165 static int count_inuse(struct page *page)
90166 {
90167 return page->inuse;
90168@@ -4241,12 +4306,12 @@ static void resiliency_test(void)
90169 validate_slab_cache(kmalloc_caches[9]);
90170 }
90171 #else
90172-#ifdef CONFIG_SYSFS
90173+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90174 static void resiliency_test(void) {};
90175 #endif
90176 #endif
90177
90178-#ifdef CONFIG_SYSFS
90179+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90180 enum slab_stat_type {
90181 SL_ALL, /* All slabs */
90182 SL_PARTIAL, /* Only partially allocated slabs */
90183@@ -4490,7 +4555,7 @@ SLAB_ATTR_RO(ctor);
90184
90185 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
90186 {
90187- return sprintf(buf, "%d\n", s->refcount - 1);
90188+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
90189 }
90190 SLAB_ATTR_RO(aliases);
90191
90192@@ -4578,6 +4643,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
90193 SLAB_ATTR_RO(cache_dma);
90194 #endif
90195
90196+#ifdef CONFIG_PAX_USERCOPY_SLABS
90197+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
90198+{
90199+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
90200+}
90201+SLAB_ATTR_RO(usercopy);
90202+#endif
90203+
90204 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
90205 {
90206 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
90207@@ -4912,6 +4985,9 @@ static struct attribute *slab_attrs[] = {
90208 #ifdef CONFIG_ZONE_DMA
90209 &cache_dma_attr.attr,
90210 #endif
90211+#ifdef CONFIG_PAX_USERCOPY_SLABS
90212+ &usercopy_attr.attr,
90213+#endif
90214 #ifdef CONFIG_NUMA
90215 &remote_node_defrag_ratio_attr.attr,
90216 #endif
90217@@ -5143,6 +5219,7 @@ static char *create_unique_id(struct kmem_cache *s)
90218 return name;
90219 }
90220
90221+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90222 static int sysfs_slab_add(struct kmem_cache *s)
90223 {
90224 int err;
90225@@ -5166,7 +5243,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
90226 }
90227
90228 s->kobj.kset = slab_kset;
90229- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
90230+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
90231 if (err) {
90232 kobject_put(&s->kobj);
90233 return err;
90234@@ -5200,6 +5277,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
90235 kobject_del(&s->kobj);
90236 kobject_put(&s->kobj);
90237 }
90238+#endif
90239
90240 /*
90241 * Need to buffer aliases during bootup until sysfs becomes
90242@@ -5213,6 +5291,7 @@ struct saved_alias {
90243
90244 static struct saved_alias *alias_list;
90245
90246+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90247 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
90248 {
90249 struct saved_alias *al;
90250@@ -5235,6 +5314,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
90251 alias_list = al;
90252 return 0;
90253 }
90254+#endif
90255
90256 static int __init slab_sysfs_init(void)
90257 {
90258diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
90259index 27eeab3..7c3f7f2 100644
90260--- a/mm/sparse-vmemmap.c
90261+++ b/mm/sparse-vmemmap.c
90262@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
90263 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
90264 if (!p)
90265 return NULL;
90266- pud_populate(&init_mm, pud, p);
90267+ pud_populate_kernel(&init_mm, pud, p);
90268 }
90269 return pud;
90270 }
90271@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
90272 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
90273 if (!p)
90274 return NULL;
90275- pgd_populate(&init_mm, pgd, p);
90276+ pgd_populate_kernel(&init_mm, pgd, p);
90277 }
90278 return pgd;
90279 }
90280diff --git a/mm/sparse.c b/mm/sparse.c
90281index 308d503..3dbbd04 100644
90282--- a/mm/sparse.c
90283+++ b/mm/sparse.c
90284@@ -764,7 +764,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
90285
90286 for (i = 0; i < PAGES_PER_SECTION; i++) {
90287 if (PageHWPoison(&memmap[i])) {
90288- atomic_long_sub(1, &num_poisoned_pages);
90289+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
90290 ClearPageHWPoison(&memmap[i]);
90291 }
90292 }
90293diff --git a/mm/swap.c b/mm/swap.c
90294index 62b78a6..0bcf28f 100644
90295--- a/mm/swap.c
90296+++ b/mm/swap.c
90297@@ -31,6 +31,7 @@
90298 #include <linux/memcontrol.h>
90299 #include <linux/gfp.h>
90300 #include <linux/uio.h>
90301+#include <linux/hugetlb.h>
90302
90303 #include "internal.h"
90304
90305@@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
90306
90307 __page_cache_release(page);
90308 dtor = get_compound_page_dtor(page);
90309+ if (!PageHuge(page))
90310+ BUG_ON(dtor != free_compound_page);
90311 (*dtor)(page);
90312 }
90313
90314diff --git a/mm/swapfile.c b/mm/swapfile.c
90315index 6cf2e60..d204b3e 100644
90316--- a/mm/swapfile.c
90317+++ b/mm/swapfile.c
90318@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
90319
90320 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
90321 /* Activity counter to indicate that a swapon or swapoff has occurred */
90322-static atomic_t proc_poll_event = ATOMIC_INIT(0);
90323+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
90324
90325 static inline unsigned char swap_count(unsigned char ent)
90326 {
90327@@ -1699,7 +1699,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
90328 }
90329 filp_close(swap_file, NULL);
90330 err = 0;
90331- atomic_inc(&proc_poll_event);
90332+ atomic_inc_unchecked(&proc_poll_event);
90333 wake_up_interruptible(&proc_poll_wait);
90334
90335 out_dput:
90336@@ -1716,8 +1716,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
90337
90338 poll_wait(file, &proc_poll_wait, wait);
90339
90340- if (seq->poll_event != atomic_read(&proc_poll_event)) {
90341- seq->poll_event = atomic_read(&proc_poll_event);
90342+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
90343+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
90344 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
90345 }
90346
90347@@ -1815,7 +1815,7 @@ static int swaps_open(struct inode *inode, struct file *file)
90348 return ret;
90349
90350 seq = file->private_data;
90351- seq->poll_event = atomic_read(&proc_poll_event);
90352+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
90353 return 0;
90354 }
90355
90356@@ -2203,7 +2203,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
90357 (frontswap_map) ? "FS" : "");
90358
90359 mutex_unlock(&swapon_mutex);
90360- atomic_inc(&proc_poll_event);
90361+ atomic_inc_unchecked(&proc_poll_event);
90362 wake_up_interruptible(&proc_poll_wait);
90363
90364 if (S_ISREG(inode->i_mode))
90365diff --git a/mm/util.c b/mm/util.c
90366index 7441c41..c3de793 100644
90367--- a/mm/util.c
90368+++ b/mm/util.c
90369@@ -294,6 +294,12 @@ done:
90370 void arch_pick_mmap_layout(struct mm_struct *mm)
90371 {
90372 mm->mmap_base = TASK_UNMAPPED_BASE;
90373+
90374+#ifdef CONFIG_PAX_RANDMMAP
90375+ if (mm->pax_flags & MF_PAX_RANDMMAP)
90376+ mm->mmap_base += mm->delta_mmap;
90377+#endif
90378+
90379 mm->get_unmapped_area = arch_get_unmapped_area;
90380 }
90381 #endif
90382diff --git a/mm/vmalloc.c b/mm/vmalloc.c
90383index 13a5495..6707d97 100644
90384--- a/mm/vmalloc.c
90385+++ b/mm/vmalloc.c
90386@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
90387
90388 pte = pte_offset_kernel(pmd, addr);
90389 do {
90390- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
90391- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90392+
90393+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90394+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
90395+ BUG_ON(!pte_exec(*pte));
90396+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
90397+ continue;
90398+ }
90399+#endif
90400+
90401+ {
90402+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
90403+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90404+ }
90405 } while (pte++, addr += PAGE_SIZE, addr != end);
90406 }
90407
90408@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
90409 pte = pte_alloc_kernel(pmd, addr);
90410 if (!pte)
90411 return -ENOMEM;
90412+
90413+ pax_open_kernel();
90414 do {
90415 struct page *page = pages[*nr];
90416
90417- if (WARN_ON(!pte_none(*pte)))
90418+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90419+ if (pgprot_val(prot) & _PAGE_NX)
90420+#endif
90421+
90422+ if (!pte_none(*pte)) {
90423+ pax_close_kernel();
90424+ WARN_ON(1);
90425 return -EBUSY;
90426- if (WARN_ON(!page))
90427+ }
90428+ if (!page) {
90429+ pax_close_kernel();
90430+ WARN_ON(1);
90431 return -ENOMEM;
90432+ }
90433 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
90434 (*nr)++;
90435 } while (pte++, addr += PAGE_SIZE, addr != end);
90436+ pax_close_kernel();
90437 return 0;
90438 }
90439
90440@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
90441 pmd_t *pmd;
90442 unsigned long next;
90443
90444- pmd = pmd_alloc(&init_mm, pud, addr);
90445+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
90446 if (!pmd)
90447 return -ENOMEM;
90448 do {
90449@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
90450 pud_t *pud;
90451 unsigned long next;
90452
90453- pud = pud_alloc(&init_mm, pgd, addr);
90454+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
90455 if (!pud)
90456 return -ENOMEM;
90457 do {
90458@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
90459 if (addr >= MODULES_VADDR && addr < MODULES_END)
90460 return 1;
90461 #endif
90462+
90463+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90464+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
90465+ return 1;
90466+#endif
90467+
90468 return is_vmalloc_addr(x);
90469 }
90470
90471@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
90472
90473 if (!pgd_none(*pgd)) {
90474 pud_t *pud = pud_offset(pgd, addr);
90475+#ifdef CONFIG_X86
90476+ if (!pud_large(*pud))
90477+#endif
90478 if (!pud_none(*pud)) {
90479 pmd_t *pmd = pmd_offset(pud, addr);
90480+#ifdef CONFIG_X86
90481+ if (!pmd_large(*pmd))
90482+#endif
90483 if (!pmd_none(*pmd)) {
90484 pte_t *ptep, pte;
90485
90486@@ -339,7 +375,7 @@ static void purge_vmap_area_lazy(void);
90487 * Allocate a region of KVA of the specified size and alignment, within the
90488 * vstart and vend.
90489 */
90490-static struct vmap_area *alloc_vmap_area(unsigned long size,
90491+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
90492 unsigned long align,
90493 unsigned long vstart, unsigned long vend,
90494 int node, gfp_t gfp_mask)
90495@@ -1308,6 +1344,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
90496 struct vm_struct *area;
90497
90498 BUG_ON(in_interrupt());
90499+
90500+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90501+ if (flags & VM_KERNEXEC) {
90502+ if (start != VMALLOC_START || end != VMALLOC_END)
90503+ return NULL;
90504+ start = (unsigned long)MODULES_EXEC_VADDR;
90505+ end = (unsigned long)MODULES_EXEC_END;
90506+ }
90507+#endif
90508+
90509 if (flags & VM_IOREMAP)
90510 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
90511
90512@@ -1533,6 +1579,11 @@ void *vmap(struct page **pages, unsigned int count,
90513 if (count > totalram_pages)
90514 return NULL;
90515
90516+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90517+ if (!(pgprot_val(prot) & _PAGE_NX))
90518+ flags |= VM_KERNEXEC;
90519+#endif
90520+
90521 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
90522 __builtin_return_address(0));
90523 if (!area)
90524@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
90525 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
90526 goto fail;
90527
90528+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90529+ if (!(pgprot_val(prot) & _PAGE_NX))
90530+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
90531+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
90532+ else
90533+#endif
90534+
90535 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
90536 start, end, node, gfp_mask, caller);
90537 if (!area)
90538@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
90539 * For tight control over page level allocator and protection flags
90540 * use __vmalloc() instead.
90541 */
90542-
90543 void *vmalloc_exec(unsigned long size)
90544 {
90545- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
90546+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
90547 NUMA_NO_NODE, __builtin_return_address(0));
90548 }
90549
90550@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
90551 {
90552 struct vm_struct *area;
90553
90554+ BUG_ON(vma->vm_mirror);
90555+
90556 size = PAGE_ALIGN(size);
90557
90558 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
90559@@ -2605,7 +2664,11 @@ static int s_show(struct seq_file *m, void *p)
90560 v->addr, v->addr + v->size, v->size);
90561
90562 if (v->caller)
90563+#ifdef CONFIG_GRKERNSEC_HIDESYM
90564+ seq_printf(m, " %pK", v->caller);
90565+#else
90566 seq_printf(m, " %pS", v->caller);
90567+#endif
90568
90569 if (v->nr_pages)
90570 seq_printf(m, " pages=%d", v->nr_pages);
90571diff --git a/mm/vmstat.c b/mm/vmstat.c
90572index 20c2ef4..15e7ab7 100644
90573--- a/mm/vmstat.c
90574+++ b/mm/vmstat.c
90575@@ -76,7 +76,7 @@ void vm_events_fold_cpu(int cpu)
90576 *
90577 * vm_stat contains the global counters
90578 */
90579-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90580+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90581 EXPORT_SYMBOL(vm_stat);
90582
90583 #ifdef CONFIG_SMP
90584@@ -452,7 +452,7 @@ void refresh_cpu_vm_stats(int cpu)
90585 v = p->vm_stat_diff[i];
90586 p->vm_stat_diff[i] = 0;
90587 local_irq_restore(flags);
90588- atomic_long_add(v, &zone->vm_stat[i]);
90589+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90590 global_diff[i] += v;
90591 #ifdef CONFIG_NUMA
90592 /* 3 seconds idle till flush */
90593@@ -490,7 +490,7 @@ void refresh_cpu_vm_stats(int cpu)
90594
90595 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
90596 if (global_diff[i])
90597- atomic_long_add(global_diff[i], &vm_stat[i]);
90598+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
90599 }
90600
90601 /*
90602@@ -505,8 +505,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
90603 if (pset->vm_stat_diff[i]) {
90604 int v = pset->vm_stat_diff[i];
90605 pset->vm_stat_diff[i] = 0;
90606- atomic_long_add(v, &zone->vm_stat[i]);
90607- atomic_long_add(v, &vm_stat[i]);
90608+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90609+ atomic_long_add_unchecked(v, &vm_stat[i]);
90610 }
90611 }
90612 #endif
90613@@ -1241,10 +1241,20 @@ static int __init setup_vmstat(void)
90614 start_cpu_timer(cpu);
90615 #endif
90616 #ifdef CONFIG_PROC_FS
90617- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
90618- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
90619- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
90620- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
90621+ {
90622+ mode_t gr_mode = S_IRUGO;
90623+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90624+ gr_mode = S_IRUSR;
90625+#endif
90626+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
90627+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
90628+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
90629+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
90630+#else
90631+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
90632+#endif
90633+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
90634+ }
90635 #endif
90636 return 0;
90637 }
90638diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
90639index 2fb2d88..8c06e40 100644
90640--- a/net/8021q/vlan.c
90641+++ b/net/8021q/vlan.c
90642@@ -469,7 +469,7 @@ out:
90643 return NOTIFY_DONE;
90644 }
90645
90646-static struct notifier_block vlan_notifier_block __read_mostly = {
90647+static struct notifier_block vlan_notifier_block = {
90648 .notifier_call = vlan_device_event,
90649 };
90650
90651@@ -544,8 +544,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
90652 err = -EPERM;
90653 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
90654 break;
90655- if ((args.u.name_type >= 0) &&
90656- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
90657+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
90658 struct vlan_net *vn;
90659
90660 vn = net_generic(net, vlan_net_id);
90661diff --git a/net/9p/mod.c b/net/9p/mod.c
90662index 6ab36ae..6f1841b 100644
90663--- a/net/9p/mod.c
90664+++ b/net/9p/mod.c
90665@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
90666 void v9fs_register_trans(struct p9_trans_module *m)
90667 {
90668 spin_lock(&v9fs_trans_lock);
90669- list_add_tail(&m->list, &v9fs_trans_list);
90670+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
90671 spin_unlock(&v9fs_trans_lock);
90672 }
90673 EXPORT_SYMBOL(v9fs_register_trans);
90674@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
90675 void v9fs_unregister_trans(struct p9_trans_module *m)
90676 {
90677 spin_lock(&v9fs_trans_lock);
90678- list_del_init(&m->list);
90679+ pax_list_del_init((struct list_head *)&m->list);
90680 spin_unlock(&v9fs_trans_lock);
90681 }
90682 EXPORT_SYMBOL(v9fs_unregister_trans);
90683diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
90684index 3ffda1b..fceac96 100644
90685--- a/net/9p/trans_fd.c
90686+++ b/net/9p/trans_fd.c
90687@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
90688 oldfs = get_fs();
90689 set_fs(get_ds());
90690 /* The cast to a user pointer is valid due to the set_fs() */
90691- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
90692+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
90693 set_fs(oldfs);
90694
90695 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
90696diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
90697index 876fbe8..8bbea9f 100644
90698--- a/net/atm/atm_misc.c
90699+++ b/net/atm/atm_misc.c
90700@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
90701 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
90702 return 1;
90703 atm_return(vcc, truesize);
90704- atomic_inc(&vcc->stats->rx_drop);
90705+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90706 return 0;
90707 }
90708 EXPORT_SYMBOL(atm_charge);
90709@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
90710 }
90711 }
90712 atm_return(vcc, guess);
90713- atomic_inc(&vcc->stats->rx_drop);
90714+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90715 return NULL;
90716 }
90717 EXPORT_SYMBOL(atm_alloc_charge);
90718@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
90719
90720 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90721 {
90722-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90723+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90724 __SONET_ITEMS
90725 #undef __HANDLE_ITEM
90726 }
90727@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
90728
90729 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90730 {
90731-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90732+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
90733 __SONET_ITEMS
90734 #undef __HANDLE_ITEM
90735 }
90736diff --git a/net/atm/lec.h b/net/atm/lec.h
90737index 4149db1..f2ab682 100644
90738--- a/net/atm/lec.h
90739+++ b/net/atm/lec.h
90740@@ -48,7 +48,7 @@ struct lane2_ops {
90741 const u8 *tlvs, u32 sizeoftlvs);
90742 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
90743 const u8 *tlvs, u32 sizeoftlvs);
90744-};
90745+} __no_const;
90746
90747 /*
90748 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
90749diff --git a/net/atm/proc.c b/net/atm/proc.c
90750index bbb6461..cf04016 100644
90751--- a/net/atm/proc.c
90752+++ b/net/atm/proc.c
90753@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
90754 const struct k_atm_aal_stats *stats)
90755 {
90756 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
90757- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
90758- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
90759- atomic_read(&stats->rx_drop));
90760+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
90761+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
90762+ atomic_read_unchecked(&stats->rx_drop));
90763 }
90764
90765 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
90766diff --git a/net/atm/resources.c b/net/atm/resources.c
90767index 0447d5d..3cf4728 100644
90768--- a/net/atm/resources.c
90769+++ b/net/atm/resources.c
90770@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
90771 static void copy_aal_stats(struct k_atm_aal_stats *from,
90772 struct atm_aal_stats *to)
90773 {
90774-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90775+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90776 __AAL_STAT_ITEMS
90777 #undef __HANDLE_ITEM
90778 }
90779@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
90780 static void subtract_aal_stats(struct k_atm_aal_stats *from,
90781 struct atm_aal_stats *to)
90782 {
90783-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90784+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
90785 __AAL_STAT_ITEMS
90786 #undef __HANDLE_ITEM
90787 }
90788diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
90789index 919a5ce..cc6b444 100644
90790--- a/net/ax25/sysctl_net_ax25.c
90791+++ b/net/ax25/sysctl_net_ax25.c
90792@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
90793 {
90794 char path[sizeof("net/ax25/") + IFNAMSIZ];
90795 int k;
90796- struct ctl_table *table;
90797+ ctl_table_no_const *table;
90798
90799 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
90800 if (!table)
90801diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
90802index 62da527..aa27535 100644
90803--- a/net/batman-adv/bat_iv_ogm.c
90804+++ b/net/batman-adv/bat_iv_ogm.c
90805@@ -120,7 +120,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
90806
90807 /* randomize initial seqno to avoid collision */
90808 get_random_bytes(&random_seqno, sizeof(random_seqno));
90809- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90810+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90811
90812 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
90813 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
90814@@ -701,9 +701,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
90815 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
90816
90817 /* change sequence number to network order */
90818- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
90819+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
90820 batadv_ogm_packet->seqno = htonl(seqno);
90821- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
90822+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
90823
90824 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
90825 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
90826@@ -1109,7 +1109,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
90827 return;
90828
90829 /* could be changed by schedule_own_packet() */
90830- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
90831+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
90832
90833 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
90834 has_directlink_flag = 1;
90835diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
90836index c478e6b..469fd2f 100644
90837--- a/net/batman-adv/hard-interface.c
90838+++ b/net/batman-adv/hard-interface.c
90839@@ -453,7 +453,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
90840 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
90841 dev_add_pack(&hard_iface->batman_adv_ptype);
90842
90843- atomic_set(&hard_iface->frag_seqno, 1);
90844+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
90845 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
90846 hard_iface->net_dev->name);
90847
90848diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
90849index 0f04e1c..9c0ac11 100644
90850--- a/net/batman-adv/soft-interface.c
90851+++ b/net/batman-adv/soft-interface.c
90852@@ -260,7 +260,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
90853 primary_if->net_dev->dev_addr, ETH_ALEN);
90854
90855 /* set broadcast sequence number */
90856- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
90857+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
90858 bcast_packet->seqno = htonl(seqno);
90859
90860 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
90861@@ -479,7 +479,7 @@ static int batadv_softif_init_late(struct net_device *dev)
90862 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
90863
90864 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
90865- atomic_set(&bat_priv->bcast_seqno, 1);
90866+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
90867 atomic_set(&bat_priv->tt.vn, 0);
90868 atomic_set(&bat_priv->tt.local_changes, 0);
90869 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
90870diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
90871index b2c94e1..3d47e07 100644
90872--- a/net/batman-adv/types.h
90873+++ b/net/batman-adv/types.h
90874@@ -51,7 +51,7 @@
90875 struct batadv_hard_iface_bat_iv {
90876 unsigned char *ogm_buff;
90877 int ogm_buff_len;
90878- atomic_t ogm_seqno;
90879+ atomic_unchecked_t ogm_seqno;
90880 };
90881
90882 /**
90883@@ -76,7 +76,7 @@ struct batadv_hard_iface {
90884 int16_t if_num;
90885 char if_status;
90886 struct net_device *net_dev;
90887- atomic_t frag_seqno;
90888+ atomic_unchecked_t frag_seqno;
90889 uint8_t num_bcasts;
90890 struct kobject *hardif_obj;
90891 atomic_t refcount;
90892@@ -560,7 +560,7 @@ struct batadv_priv {
90893 #ifdef CONFIG_BATMAN_ADV_DEBUG
90894 atomic_t log_level;
90895 #endif
90896- atomic_t bcast_seqno;
90897+ atomic_unchecked_t bcast_seqno;
90898 atomic_t bcast_queue_left;
90899 atomic_t batman_queue_left;
90900 char num_ifaces;
90901diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
90902index 857e1b8..5ad07b2 100644
90903--- a/net/batman-adv/unicast.c
90904+++ b/net/batman-adv/unicast.c
90905@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
90906 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
90907 frag2->flags = large_tail;
90908
90909- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
90910+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
90911 frag1->seqno = htons(seqno - 1);
90912 frag2->seqno = htons(seqno);
90913
90914diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
90915index 9bd7d95..6c4884f 100644
90916--- a/net/bluetooth/hci_sock.c
90917+++ b/net/bluetooth/hci_sock.c
90918@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
90919 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
90920 }
90921
90922- len = min_t(unsigned int, len, sizeof(uf));
90923+ len = min((size_t)len, sizeof(uf));
90924 if (copy_from_user(&uf, optval, len)) {
90925 err = -EFAULT;
90926 break;
90927diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
90928index 8c3499b..2661c6a 100644
90929--- a/net/bluetooth/l2cap_core.c
90930+++ b/net/bluetooth/l2cap_core.c
90931@@ -3510,8 +3510,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
90932 break;
90933
90934 case L2CAP_CONF_RFC:
90935- if (olen == sizeof(rfc))
90936- memcpy(&rfc, (void *)val, olen);
90937+ if (olen != sizeof(rfc))
90938+ break;
90939+
90940+ memcpy(&rfc, (void *)val, olen);
90941
90942 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
90943 rfc.mode != chan->mode)
90944diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
90945index 0098af8..fb5a31f 100644
90946--- a/net/bluetooth/l2cap_sock.c
90947+++ b/net/bluetooth/l2cap_sock.c
90948@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
90949 struct sock *sk = sock->sk;
90950 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
90951 struct l2cap_options opts;
90952- int len, err = 0;
90953+ int err = 0;
90954+ size_t len = optlen;
90955 u32 opt;
90956
90957 BT_DBG("sk %p", sk);
90958@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
90959 opts.max_tx = chan->max_tx;
90960 opts.txwin_size = chan->tx_win;
90961
90962- len = min_t(unsigned int, sizeof(opts), optlen);
90963+ len = min(sizeof(opts), len);
90964 if (copy_from_user((char *) &opts, optval, len)) {
90965 err = -EFAULT;
90966 break;
90967@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90968 struct bt_security sec;
90969 struct bt_power pwr;
90970 struct l2cap_conn *conn;
90971- int len, err = 0;
90972+ int err = 0;
90973+ size_t len = optlen;
90974 u32 opt;
90975
90976 BT_DBG("sk %p", sk);
90977@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90978
90979 sec.level = BT_SECURITY_LOW;
90980
90981- len = min_t(unsigned int, sizeof(sec), optlen);
90982+ len = min(sizeof(sec), len);
90983 if (copy_from_user((char *) &sec, optval, len)) {
90984 err = -EFAULT;
90985 break;
90986@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90987
90988 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
90989
90990- len = min_t(unsigned int, sizeof(pwr), optlen);
90991+ len = min(sizeof(pwr), len);
90992 if (copy_from_user((char *) &pwr, optval, len)) {
90993 err = -EFAULT;
90994 break;
90995diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
90996index 30b3721..c1bd0a0 100644
90997--- a/net/bluetooth/rfcomm/sock.c
90998+++ b/net/bluetooth/rfcomm/sock.c
90999@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
91000 struct sock *sk = sock->sk;
91001 struct bt_security sec;
91002 int err = 0;
91003- size_t len;
91004+ size_t len = optlen;
91005 u32 opt;
91006
91007 BT_DBG("sk %p", sk);
91008@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
91009
91010 sec.level = BT_SECURITY_LOW;
91011
91012- len = min_t(unsigned int, sizeof(sec), optlen);
91013+ len = min(sizeof(sec), len);
91014 if (copy_from_user((char *) &sec, optval, len)) {
91015 err = -EFAULT;
91016 break;
91017diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
91018index b6e44ad..5b0d514 100644
91019--- a/net/bluetooth/rfcomm/tty.c
91020+++ b/net/bluetooth/rfcomm/tty.c
91021@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
91022 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
91023
91024 spin_lock_irqsave(&dev->port.lock, flags);
91025- if (dev->port.count > 0) {
91026+ if (atomic_read(&dev->port.count) > 0) {
91027 spin_unlock_irqrestore(&dev->port.lock, flags);
91028 return;
91029 }
91030@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
91031 return -ENODEV;
91032
91033 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
91034- dev->channel, dev->port.count);
91035+ dev->channel, atomic_read(&dev->port.count));
91036
91037 spin_lock_irqsave(&dev->port.lock, flags);
91038- if (++dev->port.count > 1) {
91039+ if (atomic_inc_return(&dev->port.count) > 1) {
91040 spin_unlock_irqrestore(&dev->port.lock, flags);
91041 return 0;
91042 }
91043@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
91044 return;
91045
91046 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
91047- dev->port.count);
91048+ atomic_read(&dev->port.count));
91049
91050 spin_lock_irqsave(&dev->port.lock, flags);
91051- if (!--dev->port.count) {
91052+ if (!atomic_dec_return(&dev->port.count)) {
91053 spin_unlock_irqrestore(&dev->port.lock, flags);
91054 if (dev->tty_dev->parent)
91055 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
91056diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
91057index ac78024..161a80c 100644
91058--- a/net/bridge/netfilter/ebtables.c
91059+++ b/net/bridge/netfilter/ebtables.c
91060@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
91061 tmp.valid_hooks = t->table->valid_hooks;
91062 }
91063 mutex_unlock(&ebt_mutex);
91064- if (copy_to_user(user, &tmp, *len) != 0){
91065+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
91066 BUGPRINT("c2u Didn't work\n");
91067 ret = -EFAULT;
91068 break;
91069@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
91070 goto out;
91071 tmp.valid_hooks = t->valid_hooks;
91072
91073- if (copy_to_user(user, &tmp, *len) != 0) {
91074+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
91075 ret = -EFAULT;
91076 break;
91077 }
91078@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
91079 tmp.entries_size = t->table->entries_size;
91080 tmp.valid_hooks = t->table->valid_hooks;
91081
91082- if (copy_to_user(user, &tmp, *len) != 0) {
91083+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
91084 ret = -EFAULT;
91085 break;
91086 }
91087diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
91088index 2bd4b58..0dc30a1 100644
91089--- a/net/caif/cfctrl.c
91090+++ b/net/caif/cfctrl.c
91091@@ -10,6 +10,7 @@
91092 #include <linux/spinlock.h>
91093 #include <linux/slab.h>
91094 #include <linux/pkt_sched.h>
91095+#include <linux/sched.h>
91096 #include <net/caif/caif_layer.h>
91097 #include <net/caif/cfpkt.h>
91098 #include <net/caif/cfctrl.h>
91099@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
91100 memset(&dev_info, 0, sizeof(dev_info));
91101 dev_info.id = 0xff;
91102 cfsrvl_init(&this->serv, 0, &dev_info, false);
91103- atomic_set(&this->req_seq_no, 1);
91104- atomic_set(&this->rsp_seq_no, 1);
91105+ atomic_set_unchecked(&this->req_seq_no, 1);
91106+ atomic_set_unchecked(&this->rsp_seq_no, 1);
91107 this->serv.layer.receive = cfctrl_recv;
91108 sprintf(this->serv.layer.name, "ctrl");
91109 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
91110@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
91111 struct cfctrl_request_info *req)
91112 {
91113 spin_lock_bh(&ctrl->info_list_lock);
91114- atomic_inc(&ctrl->req_seq_no);
91115- req->sequence_no = atomic_read(&ctrl->req_seq_no);
91116+ atomic_inc_unchecked(&ctrl->req_seq_no);
91117+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
91118 list_add_tail(&req->list, &ctrl->list);
91119 spin_unlock_bh(&ctrl->info_list_lock);
91120 }
91121@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
91122 if (p != first)
91123 pr_warn("Requests are not received in order\n");
91124
91125- atomic_set(&ctrl->rsp_seq_no,
91126+ atomic_set_unchecked(&ctrl->rsp_seq_no,
91127 p->sequence_no);
91128 list_del(&p->list);
91129 goto out;
91130diff --git a/net/can/af_can.c b/net/can/af_can.c
91131index 3ab8dd2..b9aef13 100644
91132--- a/net/can/af_can.c
91133+++ b/net/can/af_can.c
91134@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
91135 };
91136
91137 /* notifier block for netdevice event */
91138-static struct notifier_block can_netdev_notifier __read_mostly = {
91139+static struct notifier_block can_netdev_notifier = {
91140 .notifier_call = can_notifier,
91141 };
91142
91143diff --git a/net/can/gw.c b/net/can/gw.c
91144index 2f291f9..98c986a 100644
91145--- a/net/can/gw.c
91146+++ b/net/can/gw.c
91147@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
91148 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
91149
91150 static HLIST_HEAD(cgw_list);
91151-static struct notifier_block notifier;
91152
91153 static struct kmem_cache *cgw_cache __read_mostly;
91154
91155@@ -927,6 +926,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
91156 return err;
91157 }
91158
91159+static struct notifier_block notifier = {
91160+ .notifier_call = cgw_notifier
91161+};
91162+
91163 static __init int cgw_module_init(void)
91164 {
91165 /* sanitize given module parameter */
91166@@ -942,7 +945,6 @@ static __init int cgw_module_init(void)
91167 return -ENOMEM;
91168
91169 /* set notifier */
91170- notifier.notifier_call = cgw_notifier;
91171 register_netdevice_notifier(&notifier);
91172
91173 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
91174diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
91175index eb0a46a..5f3bae8 100644
91176--- a/net/ceph/messenger.c
91177+++ b/net/ceph/messenger.c
91178@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
91179 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
91180
91181 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
91182-static atomic_t addr_str_seq = ATOMIC_INIT(0);
91183+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
91184
91185 static struct page *zero_page; /* used in certain error cases */
91186
91187@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
91188 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
91189 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
91190
91191- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
91192+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
91193 s = addr_str[i];
91194
91195 switch (ss->ss_family) {
91196diff --git a/net/compat.c b/net/compat.c
91197index f0a1ba6..0541331 100644
91198--- a/net/compat.c
91199+++ b/net/compat.c
91200@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
91201 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
91202 __get_user(kmsg->msg_flags, &umsg->msg_flags))
91203 return -EFAULT;
91204- kmsg->msg_name = compat_ptr(tmp1);
91205- kmsg->msg_iov = compat_ptr(tmp2);
91206- kmsg->msg_control = compat_ptr(tmp3);
91207+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
91208+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
91209+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
91210 return 0;
91211 }
91212
91213@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91214
91215 if (kern_msg->msg_namelen) {
91216 if (mode == VERIFY_READ) {
91217- int err = move_addr_to_kernel(kern_msg->msg_name,
91218+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
91219 kern_msg->msg_namelen,
91220 kern_address);
91221 if (err < 0)
91222@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91223 kern_msg->msg_name = NULL;
91224
91225 tot_len = iov_from_user_compat_to_kern(kern_iov,
91226- (struct compat_iovec __user *)kern_msg->msg_iov,
91227+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
91228 kern_msg->msg_iovlen);
91229 if (tot_len >= 0)
91230 kern_msg->msg_iov = kern_iov;
91231@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91232
91233 #define CMSG_COMPAT_FIRSTHDR(msg) \
91234 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
91235- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
91236+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
91237 (struct compat_cmsghdr __user *)NULL)
91238
91239 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
91240 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
91241 (ucmlen) <= (unsigned long) \
91242 ((mhdr)->msg_controllen - \
91243- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
91244+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
91245
91246 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
91247 struct compat_cmsghdr __user *cmsg, int cmsg_len)
91248 {
91249 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
91250- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
91251+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
91252 msg->msg_controllen)
91253 return NULL;
91254 return (struct compat_cmsghdr __user *)ptr;
91255@@ -219,7 +219,7 @@ Efault:
91256
91257 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
91258 {
91259- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
91260+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
91261 struct compat_cmsghdr cmhdr;
91262 struct compat_timeval ctv;
91263 struct compat_timespec cts[3];
91264@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
91265
91266 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
91267 {
91268- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
91269+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
91270 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
91271 int fdnum = scm->fp->count;
91272 struct file **fp = scm->fp->fp;
91273@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
91274 return -EFAULT;
91275 old_fs = get_fs();
91276 set_fs(KERNEL_DS);
91277- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
91278+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
91279 set_fs(old_fs);
91280
91281 return err;
91282@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
91283 len = sizeof(ktime);
91284 old_fs = get_fs();
91285 set_fs(KERNEL_DS);
91286- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
91287+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
91288 set_fs(old_fs);
91289
91290 if (!err) {
91291@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91292 case MCAST_JOIN_GROUP:
91293 case MCAST_LEAVE_GROUP:
91294 {
91295- struct compat_group_req __user *gr32 = (void *)optval;
91296+ struct compat_group_req __user *gr32 = (void __user *)optval;
91297 struct group_req __user *kgr =
91298 compat_alloc_user_space(sizeof(struct group_req));
91299 u32 interface;
91300@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91301 case MCAST_BLOCK_SOURCE:
91302 case MCAST_UNBLOCK_SOURCE:
91303 {
91304- struct compat_group_source_req __user *gsr32 = (void *)optval;
91305+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
91306 struct group_source_req __user *kgsr = compat_alloc_user_space(
91307 sizeof(struct group_source_req));
91308 u32 interface;
91309@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91310 }
91311 case MCAST_MSFILTER:
91312 {
91313- struct compat_group_filter __user *gf32 = (void *)optval;
91314+ struct compat_group_filter __user *gf32 = (void __user *)optval;
91315 struct group_filter __user *kgf;
91316 u32 interface, fmode, numsrc;
91317
91318@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
91319 char __user *optval, int __user *optlen,
91320 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
91321 {
91322- struct compat_group_filter __user *gf32 = (void *)optval;
91323+ struct compat_group_filter __user *gf32 = (void __user *)optval;
91324 struct group_filter __user *kgf;
91325 int __user *koptlen;
91326 u32 interface, fmode, numsrc;
91327@@ -805,7 +805,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
91328
91329 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
91330 return -EINVAL;
91331- if (copy_from_user(a, args, nas[call]))
91332+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
91333 return -EFAULT;
91334 a0 = a[0];
91335 a1 = a[1];
91336diff --git a/net/core/datagram.c b/net/core/datagram.c
91337index 8ab48cd..57b1a80 100644
91338--- a/net/core/datagram.c
91339+++ b/net/core/datagram.c
91340@@ -300,7 +300,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
91341 }
91342
91343 kfree_skb(skb);
91344- atomic_inc(&sk->sk_drops);
91345+ atomic_inc_unchecked(&sk->sk_drops);
91346 sk_mem_reclaim_partial(sk);
91347
91348 return err;
91349diff --git a/net/core/dev.c b/net/core/dev.c
91350index 26755dd..5020ced 100644
91351--- a/net/core/dev.c
91352+++ b/net/core/dev.c
91353@@ -1680,14 +1680,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
91354 {
91355 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
91356 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
91357- atomic_long_inc(&dev->rx_dropped);
91358+ atomic_long_inc_unchecked(&dev->rx_dropped);
91359 kfree_skb(skb);
91360 return NET_RX_DROP;
91361 }
91362 }
91363
91364 if (unlikely(!is_skb_forwardable(dev, skb))) {
91365- atomic_long_inc(&dev->rx_dropped);
91366+ atomic_long_inc_unchecked(&dev->rx_dropped);
91367 kfree_skb(skb);
91368 return NET_RX_DROP;
91369 }
91370@@ -2431,7 +2431,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
91371
91372 struct dev_gso_cb {
91373 void (*destructor)(struct sk_buff *skb);
91374-};
91375+} __no_const;
91376
91377 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
91378
91379@@ -3206,7 +3206,7 @@ enqueue:
91380
91381 local_irq_restore(flags);
91382
91383- atomic_long_inc(&skb->dev->rx_dropped);
91384+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
91385 kfree_skb(skb);
91386 return NET_RX_DROP;
91387 }
91388@@ -3278,7 +3278,7 @@ int netif_rx_ni(struct sk_buff *skb)
91389 }
91390 EXPORT_SYMBOL(netif_rx_ni);
91391
91392-static void net_tx_action(struct softirq_action *h)
91393+static void net_tx_action(void)
91394 {
91395 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91396
91397@@ -3612,7 +3612,7 @@ ncls:
91398 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
91399 } else {
91400 drop:
91401- atomic_long_inc(&skb->dev->rx_dropped);
91402+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
91403 kfree_skb(skb);
91404 /* Jamal, now you will not able to escape explaining
91405 * me how you were going to use this. :-)
91406@@ -4272,7 +4272,7 @@ void netif_napi_del(struct napi_struct *napi)
91407 }
91408 EXPORT_SYMBOL(netif_napi_del);
91409
91410-static void net_rx_action(struct softirq_action *h)
91411+static void net_rx_action(void)
91412 {
91413 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91414 unsigned long time_limit = jiffies + 2;
91415@@ -5730,7 +5730,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
91416 } else {
91417 netdev_stats_to_stats64(storage, &dev->stats);
91418 }
91419- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
91420+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
91421 return storage;
91422 }
91423 EXPORT_SYMBOL(dev_get_stats);
91424diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
91425index 5b7d0e1..cb960fc 100644
91426--- a/net/core/dev_ioctl.c
91427+++ b/net/core/dev_ioctl.c
91428@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
91429 if (no_module && capable(CAP_NET_ADMIN))
91430 no_module = request_module("netdev-%s", name);
91431 if (no_module && capable(CAP_SYS_MODULE)) {
91432+#ifdef CONFIG_GRKERNSEC_MODHARDEN
91433+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
91434+#else
91435 if (!request_module("%s", name))
91436 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
91437 name);
91438+#endif
91439 }
91440 }
91441 EXPORT_SYMBOL(dev_load);
91442diff --git a/net/core/flow.c b/net/core/flow.c
91443index dfa602c..3103d88 100644
91444--- a/net/core/flow.c
91445+++ b/net/core/flow.c
91446@@ -61,7 +61,7 @@ struct flow_cache {
91447 struct timer_list rnd_timer;
91448 };
91449
91450-atomic_t flow_cache_genid = ATOMIC_INIT(0);
91451+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
91452 EXPORT_SYMBOL(flow_cache_genid);
91453 static struct flow_cache flow_cache_global;
91454 static struct kmem_cache *flow_cachep __read_mostly;
91455@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
91456
91457 static int flow_entry_valid(struct flow_cache_entry *fle)
91458 {
91459- if (atomic_read(&flow_cache_genid) != fle->genid)
91460+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
91461 return 0;
91462 if (fle->object && !fle->object->ops->check(fle->object))
91463 return 0;
91464@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
91465 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
91466 fcp->hash_count++;
91467 }
91468- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
91469+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
91470 flo = fle->object;
91471 if (!flo)
91472 goto ret_object;
91473@@ -279,7 +279,7 @@ nocache:
91474 }
91475 flo = resolver(net, key, family, dir, flo, ctx);
91476 if (fle) {
91477- fle->genid = atomic_read(&flow_cache_genid);
91478+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
91479 if (!IS_ERR(flo))
91480 fle->object = flo;
91481 else
91482diff --git a/net/core/iovec.c b/net/core/iovec.c
91483index de178e4..1dabd8b 100644
91484--- a/net/core/iovec.c
91485+++ b/net/core/iovec.c
91486@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91487 if (m->msg_namelen) {
91488 if (mode == VERIFY_READ) {
91489 void __user *namep;
91490- namep = (void __user __force *) m->msg_name;
91491+ namep = (void __force_user *) m->msg_name;
91492 err = move_addr_to_kernel(namep, m->msg_namelen,
91493 address);
91494 if (err < 0)
91495@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91496 }
91497
91498 size = m->msg_iovlen * sizeof(struct iovec);
91499- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
91500+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
91501 return -EFAULT;
91502
91503 m->msg_iov = iov;
91504diff --git a/net/core/neighbour.c b/net/core/neighbour.c
91505index 60533db..14842cc 100644
91506--- a/net/core/neighbour.c
91507+++ b/net/core/neighbour.c
91508@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
91509 void __user *buffer, size_t *lenp, loff_t *ppos)
91510 {
91511 int size, ret;
91512- struct ctl_table tmp = *ctl;
91513+ ctl_table_no_const tmp = *ctl;
91514
91515 tmp.extra1 = &zero;
91516 tmp.extra2 = &unres_qlen_max;
91517diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
91518index 2bf8329..7960607 100644
91519--- a/net/core/net-procfs.c
91520+++ b/net/core/net-procfs.c
91521@@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
91522 else
91523 seq_printf(seq, "%04x", ntohs(pt->type));
91524
91525+#ifdef CONFIG_GRKERNSEC_HIDESYM
91526+ seq_printf(seq, " %-8s %pf\n",
91527+ pt->dev ? pt->dev->name : "", NULL);
91528+#else
91529 seq_printf(seq, " %-8s %pf\n",
91530 pt->dev ? pt->dev->name : "", pt->func);
91531+#endif
91532 }
91533
91534 return 0;
91535diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
91536index 981fed3..536af34 100644
91537--- a/net/core/net-sysfs.c
91538+++ b/net/core/net-sysfs.c
91539@@ -1311,7 +1311,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
91540 }
91541 EXPORT_SYMBOL(netdev_class_remove_file);
91542
91543-int netdev_kobject_init(void)
91544+int __init netdev_kobject_init(void)
91545 {
91546 kobj_ns_type_register(&net_ns_type_operations);
91547 return class_register(&net_class);
91548diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
91549index f9765203..9feaef8 100644
91550--- a/net/core/net_namespace.c
91551+++ b/net/core/net_namespace.c
91552@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
91553 int error;
91554 LIST_HEAD(net_exit_list);
91555
91556- list_add_tail(&ops->list, list);
91557+ pax_list_add_tail((struct list_head *)&ops->list, list);
91558 if (ops->init || (ops->id && ops->size)) {
91559 for_each_net(net) {
91560 error = ops_init(ops, net);
91561@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
91562
91563 out_undo:
91564 /* If I have an error cleanup all namespaces I initialized */
91565- list_del(&ops->list);
91566+ pax_list_del((struct list_head *)&ops->list);
91567 ops_exit_list(ops, &net_exit_list);
91568 ops_free_list(ops, &net_exit_list);
91569 return error;
91570@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
91571 struct net *net;
91572 LIST_HEAD(net_exit_list);
91573
91574- list_del(&ops->list);
91575+ pax_list_del((struct list_head *)&ops->list);
91576 for_each_net(net)
91577 list_add_tail(&net->exit_list, &net_exit_list);
91578 ops_exit_list(ops, &net_exit_list);
91579@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
91580 mutex_lock(&net_mutex);
91581 error = register_pernet_operations(&pernet_list, ops);
91582 if (!error && (first_device == &pernet_list))
91583- first_device = &ops->list;
91584+ first_device = (struct list_head *)&ops->list;
91585 mutex_unlock(&net_mutex);
91586 return error;
91587 }
91588diff --git a/net/core/netpoll.c b/net/core/netpoll.c
91589index 2c637e9..68c9087 100644
91590--- a/net/core/netpoll.c
91591+++ b/net/core/netpoll.c
91592@@ -428,7 +428,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91593 struct udphdr *udph;
91594 struct iphdr *iph;
91595 struct ethhdr *eth;
91596- static atomic_t ip_ident;
91597+ static atomic_unchecked_t ip_ident;
91598 struct ipv6hdr *ip6h;
91599
91600 udp_len = len + sizeof(*udph);
91601@@ -499,7 +499,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91602 put_unaligned(0x45, (unsigned char *)iph);
91603 iph->tos = 0;
91604 put_unaligned(htons(ip_len), &(iph->tot_len));
91605- iph->id = htons(atomic_inc_return(&ip_ident));
91606+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
91607 iph->frag_off = 0;
91608 iph->ttl = 64;
91609 iph->protocol = IPPROTO_UDP;
91610diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
91611index ca198c1d1..125372f 100644
91612--- a/net/core/rtnetlink.c
91613+++ b/net/core/rtnetlink.c
91614@@ -58,7 +58,7 @@ struct rtnl_link {
91615 rtnl_doit_func doit;
91616 rtnl_dumpit_func dumpit;
91617 rtnl_calcit_func calcit;
91618-};
91619+} __no_const;
91620
91621 static DEFINE_MUTEX(rtnl_mutex);
91622
91623@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
91624 if (rtnl_link_ops_get(ops->kind))
91625 return -EEXIST;
91626
91627- if (!ops->dellink)
91628- ops->dellink = unregister_netdevice_queue;
91629+ if (!ops->dellink) {
91630+ pax_open_kernel();
91631+ *(void **)&ops->dellink = unregister_netdevice_queue;
91632+ pax_close_kernel();
91633+ }
91634
91635- list_add_tail(&ops->list, &link_ops);
91636+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
91637 return 0;
91638 }
91639 EXPORT_SYMBOL_GPL(__rtnl_link_register);
91640@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
91641 for_each_net(net) {
91642 __rtnl_kill_links(net, ops);
91643 }
91644- list_del(&ops->list);
91645+ pax_list_del((struct list_head *)&ops->list);
91646 }
91647 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
91648
91649diff --git a/net/core/scm.c b/net/core/scm.c
91650index b4da80b..98d6bdb 100644
91651--- a/net/core/scm.c
91652+++ b/net/core/scm.c
91653@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
91654 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91655 {
91656 struct cmsghdr __user *cm
91657- = (__force struct cmsghdr __user *)msg->msg_control;
91658+ = (struct cmsghdr __force_user *)msg->msg_control;
91659 struct cmsghdr cmhdr;
91660 int cmlen = CMSG_LEN(len);
91661 int err;
91662@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91663 err = -EFAULT;
91664 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
91665 goto out;
91666- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
91667+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
91668 goto out;
91669 cmlen = CMSG_SPACE(len);
91670 if (msg->msg_controllen < cmlen)
91671@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
91672 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91673 {
91674 struct cmsghdr __user *cm
91675- = (__force struct cmsghdr __user*)msg->msg_control;
91676+ = (struct cmsghdr __force_user *)msg->msg_control;
91677
91678 int fdmax = 0;
91679 int fdnum = scm->fp->count;
91680@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91681 if (fdnum < fdmax)
91682 fdmax = fdnum;
91683
91684- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
91685+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
91686 i++, cmfptr++)
91687 {
91688 struct socket *sock;
91689diff --git a/net/core/skbuff.c b/net/core/skbuff.c
91690index 2c3d0f5..f5a326f 100644
91691--- a/net/core/skbuff.c
91692+++ b/net/core/skbuff.c
91693@@ -3082,13 +3082,15 @@ void __init skb_init(void)
91694 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
91695 sizeof(struct sk_buff),
91696 0,
91697- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91698+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91699+ SLAB_NO_SANITIZE,
91700 NULL);
91701 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
91702 (2*sizeof(struct sk_buff)) +
91703 sizeof(atomic_t),
91704 0,
91705- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91706+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91707+ SLAB_NO_SANITIZE,
91708 NULL);
91709 }
91710
91711diff --git a/net/core/sock.c b/net/core/sock.c
91712index 2c097c5..bf72858 100644
91713--- a/net/core/sock.c
91714+++ b/net/core/sock.c
91715@@ -392,7 +392,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91716 struct sk_buff_head *list = &sk->sk_receive_queue;
91717
91718 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
91719- atomic_inc(&sk->sk_drops);
91720+ atomic_inc_unchecked(&sk->sk_drops);
91721 trace_sock_rcvqueue_full(sk, skb);
91722 return -ENOMEM;
91723 }
91724@@ -402,7 +402,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91725 return err;
91726
91727 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
91728- atomic_inc(&sk->sk_drops);
91729+ atomic_inc_unchecked(&sk->sk_drops);
91730 return -ENOBUFS;
91731 }
91732
91733@@ -422,7 +422,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91734 skb_dst_force(skb);
91735
91736 spin_lock_irqsave(&list->lock, flags);
91737- skb->dropcount = atomic_read(&sk->sk_drops);
91738+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
91739 __skb_queue_tail(list, skb);
91740 spin_unlock_irqrestore(&list->lock, flags);
91741
91742@@ -442,7 +442,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91743 skb->dev = NULL;
91744
91745 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
91746- atomic_inc(&sk->sk_drops);
91747+ atomic_inc_unchecked(&sk->sk_drops);
91748 goto discard_and_relse;
91749 }
91750 if (nested)
91751@@ -460,7 +460,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91752 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
91753 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
91754 bh_unlock_sock(sk);
91755- atomic_inc(&sk->sk_drops);
91756+ atomic_inc_unchecked(&sk->sk_drops);
91757 goto discard_and_relse;
91758 }
91759
91760@@ -948,12 +948,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91761 struct timeval tm;
91762 } v;
91763
91764- int lv = sizeof(int);
91765- int len;
91766+ unsigned int lv = sizeof(int);
91767+ unsigned int len;
91768
91769 if (get_user(len, optlen))
91770 return -EFAULT;
91771- if (len < 0)
91772+ if (len > INT_MAX)
91773 return -EINVAL;
91774
91775 memset(&v, 0, sizeof(v));
91776@@ -1105,11 +1105,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91777
91778 case SO_PEERNAME:
91779 {
91780- char address[128];
91781+ char address[_K_SS_MAXSIZE];
91782
91783 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
91784 return -ENOTCONN;
91785- if (lv < len)
91786+ if (lv < len || sizeof address < len)
91787 return -EINVAL;
91788 if (copy_to_user(optval, address, len))
91789 return -EFAULT;
91790@@ -1182,7 +1182,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91791
91792 if (len > lv)
91793 len = lv;
91794- if (copy_to_user(optval, &v, len))
91795+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
91796 return -EFAULT;
91797 lenout:
91798 if (put_user(len, optlen))
91799@@ -2303,7 +2303,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
91800 */
91801 smp_wmb();
91802 atomic_set(&sk->sk_refcnt, 1);
91803- atomic_set(&sk->sk_drops, 0);
91804+ atomic_set_unchecked(&sk->sk_drops, 0);
91805 }
91806 EXPORT_SYMBOL(sock_init_data);
91807
91808diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
91809index a0e9cf6..ef7f9ed 100644
91810--- a/net/core/sock_diag.c
91811+++ b/net/core/sock_diag.c
91812@@ -9,26 +9,33 @@
91813 #include <linux/inet_diag.h>
91814 #include <linux/sock_diag.h>
91815
91816-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
91817+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
91818 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
91819 static DEFINE_MUTEX(sock_diag_table_mutex);
91820
91821 int sock_diag_check_cookie(void *sk, __u32 *cookie)
91822 {
91823+#ifndef CONFIG_GRKERNSEC_HIDESYM
91824 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
91825 cookie[1] != INET_DIAG_NOCOOKIE) &&
91826 ((u32)(unsigned long)sk != cookie[0] ||
91827 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
91828 return -ESTALE;
91829 else
91830+#endif
91831 return 0;
91832 }
91833 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
91834
91835 void sock_diag_save_cookie(void *sk, __u32 *cookie)
91836 {
91837+#ifdef CONFIG_GRKERNSEC_HIDESYM
91838+ cookie[0] = 0;
91839+ cookie[1] = 0;
91840+#else
91841 cookie[0] = (u32)(unsigned long)sk;
91842 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
91843+#endif
91844 }
91845 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
91846
91847@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
91848 mutex_lock(&sock_diag_table_mutex);
91849 if (sock_diag_handlers[hndl->family])
91850 err = -EBUSY;
91851- else
91852+ else {
91853+ pax_open_kernel();
91854 sock_diag_handlers[hndl->family] = hndl;
91855+ pax_close_kernel();
91856+ }
91857 mutex_unlock(&sock_diag_table_mutex);
91858
91859 return err;
91860@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
91861
91862 mutex_lock(&sock_diag_table_mutex);
91863 BUG_ON(sock_diag_handlers[family] != hnld);
91864+ pax_open_kernel();
91865 sock_diag_handlers[family] = NULL;
91866+ pax_close_kernel();
91867 mutex_unlock(&sock_diag_table_mutex);
91868 }
91869 EXPORT_SYMBOL_GPL(sock_diag_unregister);
91870diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
91871index 31107ab..ae03d5a 100644
91872--- a/net/core/sysctl_net_core.c
91873+++ b/net/core/sysctl_net_core.c
91874@@ -31,7 +31,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
91875 {
91876 unsigned int orig_size, size;
91877 int ret, i;
91878- struct ctl_table tmp = {
91879+ ctl_table_no_const tmp = {
91880 .data = &size,
91881 .maxlen = sizeof(size),
91882 .mode = table->mode
91883@@ -350,13 +350,12 @@ static struct ctl_table netns_core_table[] = {
91884
91885 static __net_init int sysctl_core_net_init(struct net *net)
91886 {
91887- struct ctl_table *tbl;
91888+ ctl_table_no_const *tbl = NULL;
91889
91890 net->core.sysctl_somaxconn = SOMAXCONN;
91891
91892- tbl = netns_core_table;
91893 if (!net_eq(net, &init_net)) {
91894- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
91895+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
91896 if (tbl == NULL)
91897 goto err_dup;
91898
91899@@ -366,17 +365,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
91900 if (net->user_ns != &init_user_ns) {
91901 tbl[0].procname = NULL;
91902 }
91903- }
91904-
91905- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
91906+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
91907+ } else
91908+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
91909 if (net->core.sysctl_hdr == NULL)
91910 goto err_reg;
91911
91912 return 0;
91913
91914 err_reg:
91915- if (tbl != netns_core_table)
91916- kfree(tbl);
91917+ kfree(tbl);
91918 err_dup:
91919 return -ENOMEM;
91920 }
91921@@ -391,7 +389,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
91922 kfree(tbl);
91923 }
91924
91925-static __net_initdata struct pernet_operations sysctl_core_ops = {
91926+static __net_initconst struct pernet_operations sysctl_core_ops = {
91927 .init = sysctl_core_net_init,
91928 .exit = sysctl_core_net_exit,
91929 };
91930diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
91931index dd4d506..fb2fb87 100644
91932--- a/net/decnet/af_decnet.c
91933+++ b/net/decnet/af_decnet.c
91934@@ -465,6 +465,7 @@ static struct proto dn_proto = {
91935 .sysctl_rmem = sysctl_decnet_rmem,
91936 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
91937 .obj_size = sizeof(struct dn_sock),
91938+ .slab_flags = SLAB_USERCOPY,
91939 };
91940
91941 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
91942diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
91943index 5325b54..a0d4d69 100644
91944--- a/net/decnet/sysctl_net_decnet.c
91945+++ b/net/decnet/sysctl_net_decnet.c
91946@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
91947
91948 if (len > *lenp) len = *lenp;
91949
91950- if (copy_to_user(buffer, addr, len))
91951+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
91952 return -EFAULT;
91953
91954 *lenp = len;
91955@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
91956
91957 if (len > *lenp) len = *lenp;
91958
91959- if (copy_to_user(buffer, devname, len))
91960+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
91961 return -EFAULT;
91962
91963 *lenp = len;
91964diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
91965index 3b9d5f2..d7015c6 100644
91966--- a/net/ieee802154/6lowpan.c
91967+++ b/net/ieee802154/6lowpan.c
91968@@ -459,7 +459,7 @@ static int lowpan_header_create(struct sk_buff *skb,
91969 hc06_ptr += 3;
91970 } else {
91971 /* compress nothing */
91972- memcpy(hc06_ptr, &hdr, 4);
91973+ memcpy(hc06_ptr, hdr, 4);
91974 /* replace the top byte with new ECN | DSCP format */
91975 *hc06_ptr = tmp;
91976 hc06_ptr += 4;
91977diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
91978index b4d0be2..443d0f0 100644
91979--- a/net/ipv4/af_inet.c
91980+++ b/net/ipv4/af_inet.c
91981@@ -1689,13 +1689,9 @@ static int __init inet_init(void)
91982
91983 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
91984
91985- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
91986- if (!sysctl_local_reserved_ports)
91987- goto out;
91988-
91989 rc = proto_register(&tcp_prot, 1);
91990 if (rc)
91991- goto out_free_reserved_ports;
91992+ goto out;
91993
91994 rc = proto_register(&udp_prot, 1);
91995 if (rc)
91996@@ -1804,8 +1800,6 @@ out_unregister_udp_proto:
91997 proto_unregister(&udp_prot);
91998 out_unregister_tcp_proto:
91999 proto_unregister(&tcp_prot);
92000-out_free_reserved_ports:
92001- kfree(sysctl_local_reserved_ports);
92002 goto out;
92003 }
92004
92005diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
92006index 34ca6d5..b6421e8 100644
92007--- a/net/ipv4/devinet.c
92008+++ b/net/ipv4/devinet.c
92009@@ -1532,7 +1532,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
92010 idx = 0;
92011 head = &net->dev_index_head[h];
92012 rcu_read_lock();
92013- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
92014+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
92015 net->dev_base_seq;
92016 hlist_for_each_entry_rcu(dev, head, index_hlist) {
92017 if (idx < s_idx)
92018@@ -1843,7 +1843,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
92019 idx = 0;
92020 head = &net->dev_index_head[h];
92021 rcu_read_lock();
92022- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
92023+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
92024 net->dev_base_seq;
92025 hlist_for_each_entry_rcu(dev, head, index_hlist) {
92026 if (idx < s_idx)
92027@@ -2068,7 +2068,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
92028 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
92029 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
92030
92031-static struct devinet_sysctl_table {
92032+static const struct devinet_sysctl_table {
92033 struct ctl_table_header *sysctl_header;
92034 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
92035 } devinet_sysctl = {
92036@@ -2186,7 +2186,7 @@ static __net_init int devinet_init_net(struct net *net)
92037 int err;
92038 struct ipv4_devconf *all, *dflt;
92039 #ifdef CONFIG_SYSCTL
92040- struct ctl_table *tbl = ctl_forward_entry;
92041+ ctl_table_no_const *tbl = NULL;
92042 struct ctl_table_header *forw_hdr;
92043 #endif
92044
92045@@ -2204,7 +2204,7 @@ static __net_init int devinet_init_net(struct net *net)
92046 goto err_alloc_dflt;
92047
92048 #ifdef CONFIG_SYSCTL
92049- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
92050+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
92051 if (tbl == NULL)
92052 goto err_alloc_ctl;
92053
92054@@ -2224,7 +2224,10 @@ static __net_init int devinet_init_net(struct net *net)
92055 goto err_reg_dflt;
92056
92057 err = -ENOMEM;
92058- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
92059+ if (!net_eq(net, &init_net))
92060+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
92061+ else
92062+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
92063 if (forw_hdr == NULL)
92064 goto err_reg_ctl;
92065 net->ipv4.forw_hdr = forw_hdr;
92066@@ -2240,8 +2243,7 @@ err_reg_ctl:
92067 err_reg_dflt:
92068 __devinet_sysctl_unregister(all);
92069 err_reg_all:
92070- if (tbl != ctl_forward_entry)
92071- kfree(tbl);
92072+ kfree(tbl);
92073 err_alloc_ctl:
92074 #endif
92075 if (dflt != &ipv4_devconf_dflt)
92076diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
92077index b3f627a..b0f3e99 100644
92078--- a/net/ipv4/fib_frontend.c
92079+++ b/net/ipv4/fib_frontend.c
92080@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
92081 #ifdef CONFIG_IP_ROUTE_MULTIPATH
92082 fib_sync_up(dev);
92083 #endif
92084- atomic_inc(&net->ipv4.dev_addr_genid);
92085+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92086 rt_cache_flush(dev_net(dev));
92087 break;
92088 case NETDEV_DOWN:
92089 fib_del_ifaddr(ifa, NULL);
92090- atomic_inc(&net->ipv4.dev_addr_genid);
92091+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92092 if (ifa->ifa_dev->ifa_list == NULL) {
92093 /* Last address was deleted from this interface.
92094 * Disable IP.
92095@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
92096 #ifdef CONFIG_IP_ROUTE_MULTIPATH
92097 fib_sync_up(dev);
92098 #endif
92099- atomic_inc(&net->ipv4.dev_addr_genid);
92100+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92101 rt_cache_flush(net);
92102 break;
92103 case NETDEV_DOWN:
92104diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
92105index d5dbca5..6251d5f 100644
92106--- a/net/ipv4/fib_semantics.c
92107+++ b/net/ipv4/fib_semantics.c
92108@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
92109 nh->nh_saddr = inet_select_addr(nh->nh_dev,
92110 nh->nh_gw,
92111 nh->nh_parent->fib_scope);
92112- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
92113+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
92114
92115 return nh->nh_saddr;
92116 }
92117diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
92118index 6acb541..9ea617d 100644
92119--- a/net/ipv4/inet_connection_sock.c
92120+++ b/net/ipv4/inet_connection_sock.c
92121@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
92122 .range = { 32768, 61000 },
92123 };
92124
92125-unsigned long *sysctl_local_reserved_ports;
92126+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
92127 EXPORT_SYMBOL(sysctl_local_reserved_ports);
92128
92129 void inet_get_local_port_range(int *low, int *high)
92130diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
92131index 7bd8983..3abdcf6 100644
92132--- a/net/ipv4/inet_hashtables.c
92133+++ b/net/ipv4/inet_hashtables.c
92134@@ -18,12 +18,15 @@
92135 #include <linux/sched.h>
92136 #include <linux/slab.h>
92137 #include <linux/wait.h>
92138+#include <linux/security.h>
92139
92140 #include <net/inet_connection_sock.h>
92141 #include <net/inet_hashtables.h>
92142 #include <net/secure_seq.h>
92143 #include <net/ip.h>
92144
92145+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
92146+
92147 /*
92148 * Allocate and initialize a new local port bind bucket.
92149 * The bindhash mutex for snum's hash chain must be held here.
92150@@ -554,6 +557,8 @@ ok:
92151 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
92152 spin_unlock(&head->lock);
92153
92154+ gr_update_task_in_ip_table(current, inet_sk(sk));
92155+
92156 if (tw) {
92157 inet_twsk_deschedule(tw, death_row);
92158 while (twrefcnt) {
92159diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
92160index 000e3d2..5472da3 100644
92161--- a/net/ipv4/inetpeer.c
92162+++ b/net/ipv4/inetpeer.c
92163@@ -503,8 +503,8 @@ relookup:
92164 if (p) {
92165 p->daddr = *daddr;
92166 atomic_set(&p->refcnt, 1);
92167- atomic_set(&p->rid, 0);
92168- atomic_set(&p->ip_id_count,
92169+ atomic_set_unchecked(&p->rid, 0);
92170+ atomic_set_unchecked(&p->ip_id_count,
92171 (daddr->family == AF_INET) ?
92172 secure_ip_id(daddr->addr.a4) :
92173 secure_ipv6_id(daddr->addr.a6));
92174diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
92175index b66910a..cfe416e 100644
92176--- a/net/ipv4/ip_fragment.c
92177+++ b/net/ipv4/ip_fragment.c
92178@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
92179 return 0;
92180
92181 start = qp->rid;
92182- end = atomic_inc_return(&peer->rid);
92183+ end = atomic_inc_return_unchecked(&peer->rid);
92184 qp->rid = end;
92185
92186 rc = qp->q.fragments && (end - start) > max;
92187@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
92188
92189 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92190 {
92191- struct ctl_table *table;
92192+ ctl_table_no_const *table = NULL;
92193 struct ctl_table_header *hdr;
92194
92195- table = ip4_frags_ns_ctl_table;
92196 if (!net_eq(net, &init_net)) {
92197- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
92198+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
92199 if (table == NULL)
92200 goto err_alloc;
92201
92202@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92203 /* Don't export sysctls to unprivileged users */
92204 if (net->user_ns != &init_user_ns)
92205 table[0].procname = NULL;
92206- }
92207+ hdr = register_net_sysctl(net, "net/ipv4", table);
92208+ } else
92209+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
92210
92211- hdr = register_net_sysctl(net, "net/ipv4", table);
92212 if (hdr == NULL)
92213 goto err_reg;
92214
92215@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92216 return 0;
92217
92218 err_reg:
92219- if (!net_eq(net, &init_net))
92220- kfree(table);
92221+ kfree(table);
92222 err_alloc:
92223 return -ENOMEM;
92224 }
92225diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
92226index 8d6939e..19d0a95 100644
92227--- a/net/ipv4/ip_gre.c
92228+++ b/net/ipv4/ip_gre.c
92229@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
92230 module_param(log_ecn_error, bool, 0644);
92231 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
92232
92233-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
92234+static struct rtnl_link_ops ipgre_link_ops;
92235 static int ipgre_tunnel_init(struct net_device *dev);
92236
92237 static int ipgre_net_id __read_mostly;
92238@@ -731,7 +731,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
92239 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
92240 };
92241
92242-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
92243+static struct rtnl_link_ops ipgre_link_ops = {
92244 .kind = "gre",
92245 .maxtype = IFLA_GRE_MAX,
92246 .policy = ipgre_policy,
92247@@ -745,7 +745,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
92248 .fill_info = ipgre_fill_info,
92249 };
92250
92251-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
92252+static struct rtnl_link_ops ipgre_tap_ops = {
92253 .kind = "gretap",
92254 .maxtype = IFLA_GRE_MAX,
92255 .policy = ipgre_policy,
92256diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
92257index d9c4f11..02b82dbc 100644
92258--- a/net/ipv4/ip_sockglue.c
92259+++ b/net/ipv4/ip_sockglue.c
92260@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
92261 len = min_t(unsigned int, len, opt->optlen);
92262 if (put_user(len, optlen))
92263 return -EFAULT;
92264- if (copy_to_user(optval, opt->__data, len))
92265+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
92266+ copy_to_user(optval, opt->__data, len))
92267 return -EFAULT;
92268 return 0;
92269 }
92270@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
92271 if (sk->sk_type != SOCK_STREAM)
92272 return -ENOPROTOOPT;
92273
92274- msg.msg_control = optval;
92275+ msg.msg_control = (void __force_kernel *)optval;
92276 msg.msg_controllen = len;
92277 msg.msg_flags = flags;
92278
92279diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
92280index 17cc0ff..63856c4 100644
92281--- a/net/ipv4/ip_vti.c
92282+++ b/net/ipv4/ip_vti.c
92283@@ -47,7 +47,7 @@
92284 #define HASH_SIZE 16
92285 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
92286
92287-static struct rtnl_link_ops vti_link_ops __read_mostly;
92288+static struct rtnl_link_ops vti_link_ops;
92289
92290 static int vti_net_id __read_mostly;
92291 struct vti_net {
92292@@ -840,7 +840,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
92293 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
92294 };
92295
92296-static struct rtnl_link_ops vti_link_ops __read_mostly = {
92297+static struct rtnl_link_ops vti_link_ops = {
92298 .kind = "vti",
92299 .maxtype = IFLA_VTI_MAX,
92300 .policy = vti_policy,
92301diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
92302index efa1138..20dbba0 100644
92303--- a/net/ipv4/ipconfig.c
92304+++ b/net/ipv4/ipconfig.c
92305@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
92306
92307 mm_segment_t oldfs = get_fs();
92308 set_fs(get_ds());
92309- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
92310+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
92311 set_fs(oldfs);
92312 return res;
92313 }
92314@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
92315
92316 mm_segment_t oldfs = get_fs();
92317 set_fs(get_ds());
92318- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
92319+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
92320 set_fs(oldfs);
92321 return res;
92322 }
92323@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
92324
92325 mm_segment_t oldfs = get_fs();
92326 set_fs(get_ds());
92327- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
92328+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
92329 set_fs(oldfs);
92330 return res;
92331 }
92332diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
92333index b3ac3c3..ec6bd95 100644
92334--- a/net/ipv4/ipip.c
92335+++ b/net/ipv4/ipip.c
92336@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
92337 static int ipip_net_id __read_mostly;
92338
92339 static int ipip_tunnel_init(struct net_device *dev);
92340-static struct rtnl_link_ops ipip_link_ops __read_mostly;
92341+static struct rtnl_link_ops ipip_link_ops;
92342
92343 static int ipip_err(struct sk_buff *skb, u32 info)
92344 {
92345@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
92346 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
92347 };
92348
92349-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
92350+static struct rtnl_link_ops ipip_link_ops = {
92351 .kind = "ipip",
92352 .maxtype = IFLA_IPTUN_MAX,
92353 .policy = ipip_policy,
92354diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
92355index 85a4f21..1beb1f5 100644
92356--- a/net/ipv4/netfilter/arp_tables.c
92357+++ b/net/ipv4/netfilter/arp_tables.c
92358@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
92359 #endif
92360
92361 static int get_info(struct net *net, void __user *user,
92362- const int *len, int compat)
92363+ int len, int compat)
92364 {
92365 char name[XT_TABLE_MAXNAMELEN];
92366 struct xt_table *t;
92367 int ret;
92368
92369- if (*len != sizeof(struct arpt_getinfo)) {
92370- duprintf("length %u != %Zu\n", *len,
92371+ if (len != sizeof(struct arpt_getinfo)) {
92372+ duprintf("length %u != %Zu\n", len,
92373 sizeof(struct arpt_getinfo));
92374 return -EINVAL;
92375 }
92376@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
92377 info.size = private->size;
92378 strcpy(info.name, name);
92379
92380- if (copy_to_user(user, &info, *len) != 0)
92381+ if (copy_to_user(user, &info, len) != 0)
92382 ret = -EFAULT;
92383 else
92384 ret = 0;
92385@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
92386
92387 switch (cmd) {
92388 case ARPT_SO_GET_INFO:
92389- ret = get_info(sock_net(sk), user, len, 1);
92390+ ret = get_info(sock_net(sk), user, *len, 1);
92391 break;
92392 case ARPT_SO_GET_ENTRIES:
92393 ret = compat_get_entries(sock_net(sk), user, len);
92394@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
92395
92396 switch (cmd) {
92397 case ARPT_SO_GET_INFO:
92398- ret = get_info(sock_net(sk), user, len, 0);
92399+ ret = get_info(sock_net(sk), user, *len, 0);
92400 break;
92401
92402 case ARPT_SO_GET_ENTRIES:
92403diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
92404index d23118d..6ad7277 100644
92405--- a/net/ipv4/netfilter/ip_tables.c
92406+++ b/net/ipv4/netfilter/ip_tables.c
92407@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
92408 #endif
92409
92410 static int get_info(struct net *net, void __user *user,
92411- const int *len, int compat)
92412+ int len, int compat)
92413 {
92414 char name[XT_TABLE_MAXNAMELEN];
92415 struct xt_table *t;
92416 int ret;
92417
92418- if (*len != sizeof(struct ipt_getinfo)) {
92419- duprintf("length %u != %zu\n", *len,
92420+ if (len != sizeof(struct ipt_getinfo)) {
92421+ duprintf("length %u != %zu\n", len,
92422 sizeof(struct ipt_getinfo));
92423 return -EINVAL;
92424 }
92425@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
92426 info.size = private->size;
92427 strcpy(info.name, name);
92428
92429- if (copy_to_user(user, &info, *len) != 0)
92430+ if (copy_to_user(user, &info, len) != 0)
92431 ret = -EFAULT;
92432 else
92433 ret = 0;
92434@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92435
92436 switch (cmd) {
92437 case IPT_SO_GET_INFO:
92438- ret = get_info(sock_net(sk), user, len, 1);
92439+ ret = get_info(sock_net(sk), user, *len, 1);
92440 break;
92441 case IPT_SO_GET_ENTRIES:
92442 ret = compat_get_entries(sock_net(sk), user, len);
92443@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92444
92445 switch (cmd) {
92446 case IPT_SO_GET_INFO:
92447- ret = get_info(sock_net(sk), user, len, 0);
92448+ ret = get_info(sock_net(sk), user, *len, 0);
92449 break;
92450
92451 case IPT_SO_GET_ENTRIES:
92452diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
92453index 746427c..80eab72 100644
92454--- a/net/ipv4/ping.c
92455+++ b/net/ipv4/ping.c
92456@@ -55,7 +55,7 @@
92457
92458
92459 struct ping_table ping_table;
92460-struct pingv6_ops pingv6_ops;
92461+struct pingv6_ops *pingv6_ops;
92462 EXPORT_SYMBOL_GPL(pingv6_ops);
92463
92464 static u16 ping_port_rover;
92465@@ -335,7 +335,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
92466 return -ENODEV;
92467 }
92468 }
92469- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
92470+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
92471 scoped);
92472 rcu_read_unlock();
92473
92474@@ -541,7 +541,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92475 }
92476 #if IS_ENABLED(CONFIG_IPV6)
92477 } else if (skb->protocol == htons(ETH_P_IPV6)) {
92478- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
92479+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
92480 #endif
92481 }
92482
92483@@ -559,7 +559,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92484 info, (u8 *)icmph);
92485 #if IS_ENABLED(CONFIG_IPV6)
92486 } else if (family == AF_INET6) {
92487- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
92488+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
92489 info, (u8 *)icmph);
92490 #endif
92491 }
92492@@ -850,7 +850,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92493 return ip_recv_error(sk, msg, len);
92494 #if IS_ENABLED(CONFIG_IPV6)
92495 } else if (family == AF_INET6) {
92496- return pingv6_ops.ipv6_recv_error(sk, msg, len);
92497+ return pingv6_ops->ipv6_recv_error(sk, msg, len);
92498 #endif
92499 }
92500 }
92501@@ -900,7 +900,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92502 IP6CB(skb)->iif);
92503
92504 if (inet6_sk(sk)->rxopt.all)
92505- pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
92506+ pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
92507 #endif
92508 } else {
92509 BUG();
92510@@ -1090,7 +1090,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
92511 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
92512 0, sock_i_ino(sp),
92513 atomic_read(&sp->sk_refcnt), sp,
92514- atomic_read(&sp->sk_drops), len);
92515+ atomic_read_unchecked(&sp->sk_drops), len);
92516 }
92517
92518 static int ping_v4_seq_show(struct seq_file *seq, void *v)
92519diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
92520index 61e60d6..d6996cd 100644
92521--- a/net/ipv4/raw.c
92522+++ b/net/ipv4/raw.c
92523@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
92524 int raw_rcv(struct sock *sk, struct sk_buff *skb)
92525 {
92526 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
92527- atomic_inc(&sk->sk_drops);
92528+ atomic_inc_unchecked(&sk->sk_drops);
92529 kfree_skb(skb);
92530 return NET_RX_DROP;
92531 }
92532@@ -746,16 +746,20 @@ static int raw_init(struct sock *sk)
92533
92534 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
92535 {
92536+ struct icmp_filter filter;
92537+
92538 if (optlen > sizeof(struct icmp_filter))
92539 optlen = sizeof(struct icmp_filter);
92540- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
92541+ if (copy_from_user(&filter, optval, optlen))
92542 return -EFAULT;
92543+ raw_sk(sk)->filter = filter;
92544 return 0;
92545 }
92546
92547 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
92548 {
92549 int len, ret = -EFAULT;
92550+ struct icmp_filter filter;
92551
92552 if (get_user(len, optlen))
92553 goto out;
92554@@ -765,8 +769,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
92555 if (len > sizeof(struct icmp_filter))
92556 len = sizeof(struct icmp_filter);
92557 ret = -EFAULT;
92558- if (put_user(len, optlen) ||
92559- copy_to_user(optval, &raw_sk(sk)->filter, len))
92560+ filter = raw_sk(sk)->filter;
92561+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
92562 goto out;
92563 ret = 0;
92564 out: return ret;
92565@@ -995,7 +999,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
92566 0, 0L, 0,
92567 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
92568 0, sock_i_ino(sp),
92569- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
92570+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
92571 }
92572
92573 static int raw_seq_show(struct seq_file *seq, void *v)
92574diff --git a/net/ipv4/route.c b/net/ipv4/route.c
92575index a9a54a2..647316e 100644
92576--- a/net/ipv4/route.c
92577+++ b/net/ipv4/route.c
92578@@ -2615,34 +2615,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
92579 .maxlen = sizeof(int),
92580 .mode = 0200,
92581 .proc_handler = ipv4_sysctl_rtcache_flush,
92582+ .extra1 = &init_net,
92583 },
92584 { },
92585 };
92586
92587 static __net_init int sysctl_route_net_init(struct net *net)
92588 {
92589- struct ctl_table *tbl;
92590+ ctl_table_no_const *tbl = NULL;
92591
92592- tbl = ipv4_route_flush_table;
92593 if (!net_eq(net, &init_net)) {
92594- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92595+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92596 if (tbl == NULL)
92597 goto err_dup;
92598
92599 /* Don't export sysctls to unprivileged users */
92600 if (net->user_ns != &init_user_ns)
92601 tbl[0].procname = NULL;
92602- }
92603- tbl[0].extra1 = net;
92604+ tbl[0].extra1 = net;
92605+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92606+ } else
92607+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
92608
92609- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92610 if (net->ipv4.route_hdr == NULL)
92611 goto err_reg;
92612 return 0;
92613
92614 err_reg:
92615- if (tbl != ipv4_route_flush_table)
92616- kfree(tbl);
92617+ kfree(tbl);
92618 err_dup:
92619 return -ENOMEM;
92620 }
92621@@ -2665,8 +2665,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
92622
92623 static __net_init int rt_genid_init(struct net *net)
92624 {
92625- atomic_set(&net->rt_genid, 0);
92626- atomic_set(&net->fnhe_genid, 0);
92627+ atomic_set_unchecked(&net->rt_genid, 0);
92628+ atomic_set_unchecked(&net->fnhe_genid, 0);
92629 get_random_bytes(&net->ipv4.dev_addr_genid,
92630 sizeof(net->ipv4.dev_addr_genid));
92631 return 0;
92632diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
92633index 610e324..fd42e75 100644
92634--- a/net/ipv4/sysctl_net_ipv4.c
92635+++ b/net/ipv4/sysctl_net_ipv4.c
92636@@ -57,7 +57,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
92637 {
92638 int ret;
92639 int range[2];
92640- struct ctl_table tmp = {
92641+ ctl_table_no_const tmp = {
92642 .data = &range,
92643 .maxlen = sizeof(range),
92644 .mode = table->mode,
92645@@ -110,7 +110,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
92646 int ret;
92647 gid_t urange[2];
92648 kgid_t low, high;
92649- struct ctl_table tmp = {
92650+ ctl_table_no_const tmp = {
92651 .data = &urange,
92652 .maxlen = sizeof(urange),
92653 .mode = table->mode,
92654@@ -141,7 +141,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
92655 void __user *buffer, size_t *lenp, loff_t *ppos)
92656 {
92657 char val[TCP_CA_NAME_MAX];
92658- struct ctl_table tbl = {
92659+ ctl_table_no_const tbl = {
92660 .data = val,
92661 .maxlen = TCP_CA_NAME_MAX,
92662 };
92663@@ -160,7 +160,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
92664 void __user *buffer, size_t *lenp,
92665 loff_t *ppos)
92666 {
92667- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
92668+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
92669 int ret;
92670
92671 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92672@@ -177,7 +177,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
92673 void __user *buffer, size_t *lenp,
92674 loff_t *ppos)
92675 {
92676- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
92677+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
92678 int ret;
92679
92680 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92681@@ -203,15 +203,17 @@ static int ipv4_tcp_mem(struct ctl_table *ctl, int write,
92682 struct mem_cgroup *memcg;
92683 #endif
92684
92685- struct ctl_table tmp = {
92686+ ctl_table_no_const tmp = {
92687 .data = &vec,
92688 .maxlen = sizeof(vec),
92689 .mode = ctl->mode,
92690 };
92691
92692 if (!write) {
92693- ctl->data = &net->ipv4.sysctl_tcp_mem;
92694- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
92695+ ctl_table_no_const tcp_mem = *ctl;
92696+
92697+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
92698+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
92699 }
92700
92701 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
92702@@ -239,7 +241,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
92703 void __user *buffer, size_t *lenp,
92704 loff_t *ppos)
92705 {
92706- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92707+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92708 struct tcp_fastopen_context *ctxt;
92709 int ret;
92710 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
92711@@ -482,7 +484,7 @@ static struct ctl_table ipv4_table[] = {
92712 },
92713 {
92714 .procname = "ip_local_reserved_ports",
92715- .data = NULL, /* initialized in sysctl_ipv4_init */
92716+ .data = sysctl_local_reserved_ports,
92717 .maxlen = 65536,
92718 .mode = 0644,
92719 .proc_handler = proc_do_large_bitmap,
92720@@ -847,11 +849,10 @@ static struct ctl_table ipv4_net_table[] = {
92721
92722 static __net_init int ipv4_sysctl_init_net(struct net *net)
92723 {
92724- struct ctl_table *table;
92725+ ctl_table_no_const *table = NULL;
92726
92727- table = ipv4_net_table;
92728 if (!net_eq(net, &init_net)) {
92729- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
92730+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
92731 if (table == NULL)
92732 goto err_alloc;
92733
92734@@ -886,15 +887,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
92735
92736 tcp_init_mem(net);
92737
92738- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92739+ if (!net_eq(net, &init_net))
92740+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92741+ else
92742+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
92743 if (net->ipv4.ipv4_hdr == NULL)
92744 goto err_reg;
92745
92746 return 0;
92747
92748 err_reg:
92749- if (!net_eq(net, &init_net))
92750- kfree(table);
92751+ kfree(table);
92752 err_alloc:
92753 return -ENOMEM;
92754 }
92755@@ -916,16 +919,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
92756 static __init int sysctl_ipv4_init(void)
92757 {
92758 struct ctl_table_header *hdr;
92759- struct ctl_table *i;
92760-
92761- for (i = ipv4_table; i->procname; i++) {
92762- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
92763- i->data = sysctl_local_reserved_ports;
92764- break;
92765- }
92766- }
92767- if (!i->procname)
92768- return -EINVAL;
92769
92770 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
92771 if (hdr == NULL)
92772diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
92773index 3ca2139..c4cc060 100644
92774--- a/net/ipv4/tcp_input.c
92775+++ b/net/ipv4/tcp_input.c
92776@@ -4379,7 +4379,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
92777 * simplifies code)
92778 */
92779 static void
92780-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92781+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92782 struct sk_buff *head, struct sk_buff *tail,
92783 u32 start, u32 end)
92784 {
92785@@ -5465,6 +5465,7 @@ discard:
92786 tcp_paws_reject(&tp->rx_opt, 0))
92787 goto discard_and_undo;
92788
92789+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
92790 if (th->syn) {
92791 /* We see SYN without ACK. It is attempt of
92792 * simultaneous connect with crossed SYNs.
92793@@ -5515,6 +5516,7 @@ discard:
92794 goto discard;
92795 #endif
92796 }
92797+#endif
92798 /* "fifth, if neither of the SYN or RST bits is set then
92799 * drop the segment and return."
92800 */
92801@@ -5560,7 +5562,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
92802 goto discard;
92803
92804 if (th->syn) {
92805- if (th->fin)
92806+ if (th->fin || th->urg || th->psh)
92807 goto discard;
92808 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
92809 return 1;
92810diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
92811index b299da5..097db06 100644
92812--- a/net/ipv4/tcp_ipv4.c
92813+++ b/net/ipv4/tcp_ipv4.c
92814@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
92815 EXPORT_SYMBOL(sysctl_tcp_low_latency);
92816
92817
92818+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92819+extern int grsec_enable_blackhole;
92820+#endif
92821+
92822 #ifdef CONFIG_TCP_MD5SIG
92823 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
92824 __be32 daddr, __be32 saddr, const struct tcphdr *th);
92825@@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
92826 return 0;
92827
92828 reset:
92829+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92830+ if (!grsec_enable_blackhole)
92831+#endif
92832 tcp_v4_send_reset(rsk, skb);
92833 discard:
92834 kfree_skb(skb);
92835@@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
92836 TCP_SKB_CB(skb)->sacked = 0;
92837
92838 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
92839- if (!sk)
92840+ if (!sk) {
92841+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92842+ ret = 1;
92843+#endif
92844 goto no_tcp_socket;
92845-
92846+ }
92847 process:
92848- if (sk->sk_state == TCP_TIME_WAIT)
92849+ if (sk->sk_state == TCP_TIME_WAIT) {
92850+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92851+ ret = 2;
92852+#endif
92853 goto do_time_wait;
92854+ }
92855
92856 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
92857 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
92858@@ -2034,6 +2048,10 @@ csum_error:
92859 bad_packet:
92860 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
92861 } else {
92862+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92863+ if (!grsec_enable_blackhole || (ret == 1 &&
92864+ (skb->dev->flags & IFF_LOOPBACK)))
92865+#endif
92866 tcp_v4_send_reset(NULL, skb);
92867 }
92868
92869diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
92870index ab1c086..2a8d76b 100644
92871--- a/net/ipv4/tcp_minisocks.c
92872+++ b/net/ipv4/tcp_minisocks.c
92873@@ -27,6 +27,10 @@
92874 #include <net/inet_common.h>
92875 #include <net/xfrm.h>
92876
92877+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92878+extern int grsec_enable_blackhole;
92879+#endif
92880+
92881 int sysctl_tcp_syncookies __read_mostly = 1;
92882 EXPORT_SYMBOL(sysctl_tcp_syncookies);
92883
92884@@ -715,7 +719,10 @@ embryonic_reset:
92885 * avoid becoming vulnerable to outside attack aiming at
92886 * resetting legit local connections.
92887 */
92888- req->rsk_ops->send_reset(sk, skb);
92889+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92890+ if (!grsec_enable_blackhole)
92891+#endif
92892+ req->rsk_ops->send_reset(sk, skb);
92893 } else if (fastopen) { /* received a valid RST pkt */
92894 reqsk_fastopen_remove(sk, req, true);
92895 tcp_reset(sk);
92896diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
92897index d4943f6..e7a74a5 100644
92898--- a/net/ipv4/tcp_probe.c
92899+++ b/net/ipv4/tcp_probe.c
92900@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
92901 if (cnt + width >= len)
92902 break;
92903
92904- if (copy_to_user(buf + cnt, tbuf, width))
92905+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
92906 return -EFAULT;
92907 cnt += width;
92908 }
92909diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
92910index 4b85e6f..22f9ac9 100644
92911--- a/net/ipv4/tcp_timer.c
92912+++ b/net/ipv4/tcp_timer.c
92913@@ -22,6 +22,10 @@
92914 #include <linux/gfp.h>
92915 #include <net/tcp.h>
92916
92917+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92918+extern int grsec_lastack_retries;
92919+#endif
92920+
92921 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
92922 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
92923 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
92924@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
92925 }
92926 }
92927
92928+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92929+ if ((sk->sk_state == TCP_LAST_ACK) &&
92930+ (grsec_lastack_retries > 0) &&
92931+ (grsec_lastack_retries < retry_until))
92932+ retry_until = grsec_lastack_retries;
92933+#endif
92934+
92935 if (retransmits_timed_out(sk, retry_until,
92936 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
92937 /* Has it gone just too far? */
92938diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
92939index 766e6ba..aff2f8d 100644
92940--- a/net/ipv4/udp.c
92941+++ b/net/ipv4/udp.c
92942@@ -87,6 +87,7 @@
92943 #include <linux/types.h>
92944 #include <linux/fcntl.h>
92945 #include <linux/module.h>
92946+#include <linux/security.h>
92947 #include <linux/socket.h>
92948 #include <linux/sockios.h>
92949 #include <linux/igmp.h>
92950@@ -112,6 +113,10 @@
92951 #include <net/busy_poll.h>
92952 #include "udp_impl.h"
92953
92954+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92955+extern int grsec_enable_blackhole;
92956+#endif
92957+
92958 struct udp_table udp_table __read_mostly;
92959 EXPORT_SYMBOL(udp_table);
92960
92961@@ -595,6 +600,9 @@ found:
92962 return s;
92963 }
92964
92965+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
92966+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
92967+
92968 /*
92969 * This routine is called by the ICMP module when it gets some
92970 * sort of error condition. If err < 0 then the socket should
92971@@ -891,9 +899,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92972 dport = usin->sin_port;
92973 if (dport == 0)
92974 return -EINVAL;
92975+
92976+ err = gr_search_udp_sendmsg(sk, usin);
92977+ if (err)
92978+ return err;
92979 } else {
92980 if (sk->sk_state != TCP_ESTABLISHED)
92981 return -EDESTADDRREQ;
92982+
92983+ err = gr_search_udp_sendmsg(sk, NULL);
92984+ if (err)
92985+ return err;
92986+
92987 daddr = inet->inet_daddr;
92988 dport = inet->inet_dport;
92989 /* Open fast path for connected socket.
92990@@ -1137,7 +1154,7 @@ static unsigned int first_packet_length(struct sock *sk)
92991 IS_UDPLITE(sk));
92992 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
92993 IS_UDPLITE(sk));
92994- atomic_inc(&sk->sk_drops);
92995+ atomic_inc_unchecked(&sk->sk_drops);
92996 __skb_unlink(skb, rcvq);
92997 __skb_queue_tail(&list_kill, skb);
92998 }
92999@@ -1223,6 +1240,10 @@ try_again:
93000 if (!skb)
93001 goto out;
93002
93003+ err = gr_search_udp_recvmsg(sk, skb);
93004+ if (err)
93005+ goto out_free;
93006+
93007 ulen = skb->len - sizeof(struct udphdr);
93008 copied = len;
93009 if (copied > ulen)
93010@@ -1256,7 +1277,7 @@ try_again:
93011 if (unlikely(err)) {
93012 trace_kfree_skb(skb, udp_recvmsg);
93013 if (!peeked) {
93014- atomic_inc(&sk->sk_drops);
93015+ atomic_inc_unchecked(&sk->sk_drops);
93016 UDP_INC_STATS_USER(sock_net(sk),
93017 UDP_MIB_INERRORS, is_udplite);
93018 }
93019@@ -1543,7 +1564,7 @@ csum_error:
93020 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
93021 drop:
93022 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
93023- atomic_inc(&sk->sk_drops);
93024+ atomic_inc_unchecked(&sk->sk_drops);
93025 kfree_skb(skb);
93026 return -1;
93027 }
93028@@ -1562,7 +1583,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
93029 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
93030
93031 if (!skb1) {
93032- atomic_inc(&sk->sk_drops);
93033+ atomic_inc_unchecked(&sk->sk_drops);
93034 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
93035 IS_UDPLITE(sk));
93036 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93037@@ -1734,6 +1755,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
93038 goto csum_error;
93039
93040 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
93041+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93042+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
93043+#endif
93044 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
93045
93046 /*
93047@@ -2166,7 +2190,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
93048 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
93049 0, sock_i_ino(sp),
93050 atomic_read(&sp->sk_refcnt), sp,
93051- atomic_read(&sp->sk_drops), len);
93052+ atomic_read_unchecked(&sp->sk_drops), len);
93053 }
93054
93055 int udp4_seq_show(struct seq_file *seq, void *v)
93056diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
93057index 9a459be..086b866 100644
93058--- a/net/ipv4/xfrm4_policy.c
93059+++ b/net/ipv4/xfrm4_policy.c
93060@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
93061
93062 static int __net_init xfrm4_net_init(struct net *net)
93063 {
93064- struct ctl_table *table;
93065+ ctl_table_no_const *table = NULL;
93066 struct ctl_table_header *hdr;
93067
93068- table = xfrm4_policy_table;
93069 if (!net_eq(net, &init_net)) {
93070- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
93071+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
93072 if (!table)
93073 goto err_alloc;
93074
93075 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
93076- }
93077-
93078- hdr = register_net_sysctl(net, "net/ipv4", table);
93079+ hdr = register_net_sysctl(net, "net/ipv4", table);
93080+ } else
93081+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
93082 if (!hdr)
93083 goto err_reg;
93084
93085@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
93086 return 0;
93087
93088 err_reg:
93089- if (!net_eq(net, &init_net))
93090- kfree(table);
93091+ kfree(table);
93092 err_alloc:
93093 return -ENOMEM;
93094 }
93095diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
93096index 498ea99..42501bc 100644
93097--- a/net/ipv6/addrconf.c
93098+++ b/net/ipv6/addrconf.c
93099@@ -618,7 +618,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
93100 idx = 0;
93101 head = &net->dev_index_head[h];
93102 rcu_read_lock();
93103- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
93104+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
93105 net->dev_base_seq;
93106 hlist_for_each_entry_rcu(dev, head, index_hlist) {
93107 if (idx < s_idx)
93108@@ -2381,7 +2381,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
93109 p.iph.ihl = 5;
93110 p.iph.protocol = IPPROTO_IPV6;
93111 p.iph.ttl = 64;
93112- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
93113+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
93114
93115 if (ops->ndo_do_ioctl) {
93116 mm_segment_t oldfs = get_fs();
93117@@ -4030,7 +4030,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
93118 s_ip_idx = ip_idx = cb->args[2];
93119
93120 rcu_read_lock();
93121- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
93122+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
93123 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
93124 idx = 0;
93125 head = &net->dev_index_head[h];
93126@@ -4651,7 +4651,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
93127 dst_free(&ifp->rt->dst);
93128 break;
93129 }
93130- atomic_inc(&net->ipv6.dev_addr_genid);
93131+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
93132 }
93133
93134 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
93135@@ -4671,7 +4671,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
93136 int *valp = ctl->data;
93137 int val = *valp;
93138 loff_t pos = *ppos;
93139- struct ctl_table lctl;
93140+ ctl_table_no_const lctl;
93141 int ret;
93142
93143 /*
93144@@ -4756,7 +4756,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
93145 int *valp = ctl->data;
93146 int val = *valp;
93147 loff_t pos = *ppos;
93148- struct ctl_table lctl;
93149+ ctl_table_no_const lctl;
93150 int ret;
93151
93152 /*
93153diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
93154index 197e6f4..16d8396 100644
93155--- a/net/ipv6/datagram.c
93156+++ b/net/ipv6/datagram.c
93157@@ -904,5 +904,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
93158 0,
93159 sock_i_ino(sp),
93160 atomic_read(&sp->sk_refcnt), sp,
93161- atomic_read(&sp->sk_drops));
93162+ atomic_read_unchecked(&sp->sk_drops));
93163 }
93164diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
93165index 7cfc8d2..c5394b6 100644
93166--- a/net/ipv6/icmp.c
93167+++ b/net/ipv6/icmp.c
93168@@ -989,7 +989,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
93169
93170 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
93171 {
93172- struct ctl_table *table;
93173+ ctl_table_no_const *table;
93174
93175 table = kmemdup(ipv6_icmp_table_template,
93176 sizeof(ipv6_icmp_table_template),
93177diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
93178index 90747f1..505320d 100644
93179--- a/net/ipv6/ip6_gre.c
93180+++ b/net/ipv6/ip6_gre.c
93181@@ -74,7 +74,7 @@ struct ip6gre_net {
93182 struct net_device *fb_tunnel_dev;
93183 };
93184
93185-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
93186+static struct rtnl_link_ops ip6gre_link_ops;
93187 static int ip6gre_tunnel_init(struct net_device *dev);
93188 static void ip6gre_tunnel_setup(struct net_device *dev);
93189 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
93190@@ -1288,7 +1288,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
93191 }
93192
93193
93194-static struct inet6_protocol ip6gre_protocol __read_mostly = {
93195+static struct inet6_protocol ip6gre_protocol = {
93196 .handler = ip6gre_rcv,
93197 .err_handler = ip6gre_err,
93198 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
93199@@ -1622,7 +1622,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
93200 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
93201 };
93202
93203-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
93204+static struct rtnl_link_ops ip6gre_link_ops = {
93205 .kind = "ip6gre",
93206 .maxtype = IFLA_GRE_MAX,
93207 .policy = ip6gre_policy,
93208@@ -1635,7 +1635,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
93209 .fill_info = ip6gre_fill_info,
93210 };
93211
93212-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
93213+static struct rtnl_link_ops ip6gre_tap_ops = {
93214 .kind = "ip6gretap",
93215 .maxtype = IFLA_GRE_MAX,
93216 .policy = ip6gre_policy,
93217diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
93218index 46ba243..576f50e 100644
93219--- a/net/ipv6/ip6_tunnel.c
93220+++ b/net/ipv6/ip6_tunnel.c
93221@@ -88,7 +88,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
93222
93223 static int ip6_tnl_dev_init(struct net_device *dev);
93224 static void ip6_tnl_dev_setup(struct net_device *dev);
93225-static struct rtnl_link_ops ip6_link_ops __read_mostly;
93226+static struct rtnl_link_ops ip6_link_ops;
93227
93228 static int ip6_tnl_net_id __read_mostly;
93229 struct ip6_tnl_net {
93230@@ -1678,7 +1678,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
93231 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
93232 };
93233
93234-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
93235+static struct rtnl_link_ops ip6_link_ops = {
93236 .kind = "ip6tnl",
93237 .maxtype = IFLA_IPTUN_MAX,
93238 .policy = ip6_tnl_policy,
93239diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
93240index d1e2e8e..51c19ae 100644
93241--- a/net/ipv6/ipv6_sockglue.c
93242+++ b/net/ipv6/ipv6_sockglue.c
93243@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
93244 if (sk->sk_type != SOCK_STREAM)
93245 return -ENOPROTOOPT;
93246
93247- msg.msg_control = optval;
93248+ msg.msg_control = (void __force_kernel *)optval;
93249 msg.msg_controllen = len;
93250 msg.msg_flags = flags;
93251
93252diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
93253index 44400c2..8e11f52 100644
93254--- a/net/ipv6/netfilter/ip6_tables.c
93255+++ b/net/ipv6/netfilter/ip6_tables.c
93256@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
93257 #endif
93258
93259 static int get_info(struct net *net, void __user *user,
93260- const int *len, int compat)
93261+ int len, int compat)
93262 {
93263 char name[XT_TABLE_MAXNAMELEN];
93264 struct xt_table *t;
93265 int ret;
93266
93267- if (*len != sizeof(struct ip6t_getinfo)) {
93268- duprintf("length %u != %zu\n", *len,
93269+ if (len != sizeof(struct ip6t_getinfo)) {
93270+ duprintf("length %u != %zu\n", len,
93271 sizeof(struct ip6t_getinfo));
93272 return -EINVAL;
93273 }
93274@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
93275 info.size = private->size;
93276 strcpy(info.name, name);
93277
93278- if (copy_to_user(user, &info, *len) != 0)
93279+ if (copy_to_user(user, &info, len) != 0)
93280 ret = -EFAULT;
93281 else
93282 ret = 0;
93283@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93284
93285 switch (cmd) {
93286 case IP6T_SO_GET_INFO:
93287- ret = get_info(sock_net(sk), user, len, 1);
93288+ ret = get_info(sock_net(sk), user, *len, 1);
93289 break;
93290 case IP6T_SO_GET_ENTRIES:
93291 ret = compat_get_entries(sock_net(sk), user, len);
93292@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93293
93294 switch (cmd) {
93295 case IP6T_SO_GET_INFO:
93296- ret = get_info(sock_net(sk), user, len, 0);
93297+ ret = get_info(sock_net(sk), user, *len, 0);
93298 break;
93299
93300 case IP6T_SO_GET_ENTRIES:
93301diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
93302index dffdc1a..ccc6678 100644
93303--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
93304+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
93305@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
93306
93307 static int nf_ct_frag6_sysctl_register(struct net *net)
93308 {
93309- struct ctl_table *table;
93310+ ctl_table_no_const *table = NULL;
93311 struct ctl_table_header *hdr;
93312
93313- table = nf_ct_frag6_sysctl_table;
93314 if (!net_eq(net, &init_net)) {
93315- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
93316+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
93317 GFP_KERNEL);
93318 if (table == NULL)
93319 goto err_alloc;
93320@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93321 table[0].data = &net->nf_frag.frags.timeout;
93322 table[1].data = &net->nf_frag.frags.low_thresh;
93323 table[2].data = &net->nf_frag.frags.high_thresh;
93324- }
93325-
93326- hdr = register_net_sysctl(net, "net/netfilter", table);
93327+ hdr = register_net_sysctl(net, "net/netfilter", table);
93328+ } else
93329+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
93330 if (hdr == NULL)
93331 goto err_reg;
93332
93333@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93334 return 0;
93335
93336 err_reg:
93337- if (!net_eq(net, &init_net))
93338- kfree(table);
93339+ kfree(table);
93340 err_alloc:
93341 return -ENOMEM;
93342 }
93343diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
93344index ab92a36..bb4a528 100644
93345--- a/net/ipv6/output_core.c
93346+++ b/net/ipv6/output_core.c
93347@@ -8,8 +8,8 @@
93348
93349 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93350 {
93351- static atomic_t ipv6_fragmentation_id;
93352- int old, new;
93353+ static atomic_unchecked_t ipv6_fragmentation_id;
93354+ int id;
93355
93356 #if IS_ENABLED(CONFIG_IPV6)
93357 if (rt && !(rt->dst.flags & DST_NOPEER)) {
93358@@ -25,13 +25,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93359 }
93360 }
93361 #endif
93362- do {
93363- old = atomic_read(&ipv6_fragmentation_id);
93364- new = old + 1;
93365- if (!new)
93366- new = 1;
93367- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
93368- fhdr->identification = htonl(new);
93369+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93370+ if (!id)
93371+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93372+ fhdr->identification = htonl(id);
93373 }
93374 EXPORT_SYMBOL(ipv6_select_ident);
93375
93376diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
93377index 18f19df..b46ada1 100644
93378--- a/net/ipv6/ping.c
93379+++ b/net/ipv6/ping.c
93380@@ -245,6 +245,22 @@ static struct pernet_operations ping_v6_net_ops = {
93381 };
93382 #endif
93383
93384+static struct pingv6_ops real_pingv6_ops = {
93385+ .ipv6_recv_error = ipv6_recv_error,
93386+ .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
93387+ .icmpv6_err_convert = icmpv6_err_convert,
93388+ .ipv6_icmp_error = ipv6_icmp_error,
93389+ .ipv6_chk_addr = ipv6_chk_addr,
93390+};
93391+
93392+static struct pingv6_ops dummy_pingv6_ops = {
93393+ .ipv6_recv_error = dummy_ipv6_recv_error,
93394+ .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
93395+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
93396+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
93397+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
93398+};
93399+
93400 int __init pingv6_init(void)
93401 {
93402 #ifdef CONFIG_PROC_FS
93403@@ -252,11 +268,7 @@ int __init pingv6_init(void)
93404 if (ret)
93405 return ret;
93406 #endif
93407- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
93408- pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
93409- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
93410- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
93411- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
93412+ pingv6_ops = &real_pingv6_ops;
93413 return inet6_register_protosw(&pingv6_protosw);
93414 }
93415
93416@@ -265,11 +277,7 @@ int __init pingv6_init(void)
93417 */
93418 void pingv6_exit(void)
93419 {
93420- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
93421- pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
93422- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
93423- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
93424- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
93425+ pingv6_ops = &dummy_pingv6_ops;
93426 #ifdef CONFIG_PROC_FS
93427 unregister_pernet_subsys(&ping_v6_net_ops);
93428 #endif
93429diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
93430index cdaed47..515edde9 100644
93431--- a/net/ipv6/raw.c
93432+++ b/net/ipv6/raw.c
93433@@ -108,7 +108,7 @@ found:
93434 */
93435 static int icmpv6_filter(const struct sock *sk, const struct sk_buff *skb)
93436 {
93437- struct icmp6hdr *_hdr;
93438+ struct icmp6hdr _hdr;
93439 const struct icmp6hdr *hdr;
93440
93441 hdr = skb_header_pointer(skb, skb_transport_offset(skb),
93442@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
93443 {
93444 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
93445 skb_checksum_complete(skb)) {
93446- atomic_inc(&sk->sk_drops);
93447+ atomic_inc_unchecked(&sk->sk_drops);
93448 kfree_skb(skb);
93449 return NET_RX_DROP;
93450 }
93451@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93452 struct raw6_sock *rp = raw6_sk(sk);
93453
93454 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
93455- atomic_inc(&sk->sk_drops);
93456+ atomic_inc_unchecked(&sk->sk_drops);
93457 kfree_skb(skb);
93458 return NET_RX_DROP;
93459 }
93460@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93461
93462 if (inet->hdrincl) {
93463 if (skb_checksum_complete(skb)) {
93464- atomic_inc(&sk->sk_drops);
93465+ atomic_inc_unchecked(&sk->sk_drops);
93466 kfree_skb(skb);
93467 return NET_RX_DROP;
93468 }
93469@@ -602,7 +602,7 @@ out:
93470 return err;
93471 }
93472
93473-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
93474+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
93475 struct flowi6 *fl6, struct dst_entry **dstp,
93476 unsigned int flags)
93477 {
93478@@ -915,12 +915,15 @@ do_confirm:
93479 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
93480 char __user *optval, int optlen)
93481 {
93482+ struct icmp6_filter filter;
93483+
93484 switch (optname) {
93485 case ICMPV6_FILTER:
93486 if (optlen > sizeof(struct icmp6_filter))
93487 optlen = sizeof(struct icmp6_filter);
93488- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
93489+ if (copy_from_user(&filter, optval, optlen))
93490 return -EFAULT;
93491+ raw6_sk(sk)->filter = filter;
93492 return 0;
93493 default:
93494 return -ENOPROTOOPT;
93495@@ -933,6 +936,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93496 char __user *optval, int __user *optlen)
93497 {
93498 int len;
93499+ struct icmp6_filter filter;
93500
93501 switch (optname) {
93502 case ICMPV6_FILTER:
93503@@ -944,7 +948,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93504 len = sizeof(struct icmp6_filter);
93505 if (put_user(len, optlen))
93506 return -EFAULT;
93507- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
93508+ filter = raw6_sk(sk)->filter;
93509+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
93510 return -EFAULT;
93511 return 0;
93512 default:
93513diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
93514index 1aeb473..bea761c 100644
93515--- a/net/ipv6/reassembly.c
93516+++ b/net/ipv6/reassembly.c
93517@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
93518
93519 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93520 {
93521- struct ctl_table *table;
93522+ ctl_table_no_const *table = NULL;
93523 struct ctl_table_header *hdr;
93524
93525- table = ip6_frags_ns_ctl_table;
93526 if (!net_eq(net, &init_net)) {
93527- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93528+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93529 if (table == NULL)
93530 goto err_alloc;
93531
93532@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93533 /* Don't export sysctls to unprivileged users */
93534 if (net->user_ns != &init_user_ns)
93535 table[0].procname = NULL;
93536- }
93537+ hdr = register_net_sysctl(net, "net/ipv6", table);
93538+ } else
93539+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
93540
93541- hdr = register_net_sysctl(net, "net/ipv6", table);
93542 if (hdr == NULL)
93543 goto err_reg;
93544
93545@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93546 return 0;
93547
93548 err_reg:
93549- if (!net_eq(net, &init_net))
93550- kfree(table);
93551+ kfree(table);
93552 err_alloc:
93553 return -ENOMEM;
93554 }
93555diff --git a/net/ipv6/route.c b/net/ipv6/route.c
93556index 8d9a93ed..cd89616 100644
93557--- a/net/ipv6/route.c
93558+++ b/net/ipv6/route.c
93559@@ -2926,7 +2926,7 @@ struct ctl_table ipv6_route_table_template[] = {
93560
93561 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
93562 {
93563- struct ctl_table *table;
93564+ ctl_table_no_const *table;
93565
93566 table = kmemdup(ipv6_route_table_template,
93567 sizeof(ipv6_route_table_template),
93568diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
93569index 21b25dd..9a43e37 100644
93570--- a/net/ipv6/sit.c
93571+++ b/net/ipv6/sit.c
93572@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
93573 static void ipip6_dev_free(struct net_device *dev);
93574 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
93575 __be32 *v4dst);
93576-static struct rtnl_link_ops sit_link_ops __read_mostly;
93577+static struct rtnl_link_ops sit_link_ops;
93578
93579 static int sit_net_id __read_mostly;
93580 struct sit_net {
93581@@ -1547,7 +1547,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
93582 #endif
93583 };
93584
93585-static struct rtnl_link_ops sit_link_ops __read_mostly = {
93586+static struct rtnl_link_ops sit_link_ops = {
93587 .kind = "sit",
93588 .maxtype = IFLA_IPTUN_MAX,
93589 .policy = ipip6_policy,
93590diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
93591index 107b2f1..72741a9 100644
93592--- a/net/ipv6/sysctl_net_ipv6.c
93593+++ b/net/ipv6/sysctl_net_ipv6.c
93594@@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
93595
93596 static int __net_init ipv6_sysctl_net_init(struct net *net)
93597 {
93598- struct ctl_table *ipv6_table;
93599+ ctl_table_no_const *ipv6_table;
93600 struct ctl_table *ipv6_route_table;
93601 struct ctl_table *ipv6_icmp_table;
93602 int err;
93603diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
93604index 6e1649d..75ddb4c 100644
93605--- a/net/ipv6/tcp_ipv6.c
93606+++ b/net/ipv6/tcp_ipv6.c
93607@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
93608 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
93609 }
93610
93611+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93612+extern int grsec_enable_blackhole;
93613+#endif
93614+
93615 static void tcp_v6_hash(struct sock *sk)
93616 {
93617 if (sk->sk_state != TCP_CLOSE) {
93618@@ -1399,6 +1403,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
93619 return 0;
93620
93621 reset:
93622+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93623+ if (!grsec_enable_blackhole)
93624+#endif
93625 tcp_v6_send_reset(sk, skb);
93626 discard:
93627 if (opt_skb)
93628@@ -1427,7 +1434,7 @@ ipv6_pktoptions:
93629 if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim)
93630 np->mcast_hops = ipv6_hdr(opt_skb)->hop_limit;
93631 if (np->rxopt.bits.rxtclass)
93632- np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));
93633+ np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(opt_skb));
93634 if (ipv6_opt_accepted(sk, opt_skb)) {
93635 skb_set_owner_r(opt_skb, sk);
93636 opt_skb = xchg(&np->pktoptions, opt_skb);
93637@@ -1481,12 +1488,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
93638 TCP_SKB_CB(skb)->sacked = 0;
93639
93640 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
93641- if (!sk)
93642+ if (!sk) {
93643+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93644+ ret = 1;
93645+#endif
93646 goto no_tcp_socket;
93647+ }
93648
93649 process:
93650- if (sk->sk_state == TCP_TIME_WAIT)
93651+ if (sk->sk_state == TCP_TIME_WAIT) {
93652+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93653+ ret = 2;
93654+#endif
93655 goto do_time_wait;
93656+ }
93657
93658 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
93659 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
93660@@ -1538,6 +1553,10 @@ csum_error:
93661 bad_packet:
93662 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
93663 } else {
93664+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93665+ if (!grsec_enable_blackhole || (ret == 1 &&
93666+ (skb->dev->flags & IFF_LOOPBACK)))
93667+#endif
93668 tcp_v6_send_reset(NULL, skb);
93669 }
93670
93671diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
93672index f405815..45a68a6 100644
93673--- a/net/ipv6/udp.c
93674+++ b/net/ipv6/udp.c
93675@@ -53,6 +53,10 @@
93676 #include <trace/events/skb.h>
93677 #include "udp_impl.h"
93678
93679+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93680+extern int grsec_enable_blackhole;
93681+#endif
93682+
93683 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
93684 {
93685 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
93686@@ -420,7 +424,7 @@ try_again:
93687 if (unlikely(err)) {
93688 trace_kfree_skb(skb, udpv6_recvmsg);
93689 if (!peeked) {
93690- atomic_inc(&sk->sk_drops);
93691+ atomic_inc_unchecked(&sk->sk_drops);
93692 if (is_udp4)
93693 UDP_INC_STATS_USER(sock_net(sk),
93694 UDP_MIB_INERRORS,
93695@@ -666,7 +670,7 @@ csum_error:
93696 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
93697 drop:
93698 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
93699- atomic_inc(&sk->sk_drops);
93700+ atomic_inc_unchecked(&sk->sk_drops);
93701 kfree_skb(skb);
93702 return -1;
93703 }
93704@@ -724,7 +728,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
93705 if (likely(skb1 == NULL))
93706 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
93707 if (!skb1) {
93708- atomic_inc(&sk->sk_drops);
93709+ atomic_inc_unchecked(&sk->sk_drops);
93710 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
93711 IS_UDPLITE(sk));
93712 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93713@@ -864,6 +868,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
93714 goto csum_error;
93715
93716 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
93717+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93718+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
93719+#endif
93720 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
93721
93722 kfree_skb(skb);
93723diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
93724index 23ed03d..465a71d 100644
93725--- a/net/ipv6/xfrm6_policy.c
93726+++ b/net/ipv6/xfrm6_policy.c
93727@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
93728
93729 static int __net_init xfrm6_net_init(struct net *net)
93730 {
93731- struct ctl_table *table;
93732+ ctl_table_no_const *table = NULL;
93733 struct ctl_table_header *hdr;
93734
93735- table = xfrm6_policy_table;
93736 if (!net_eq(net, &init_net)) {
93737- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93738+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93739 if (!table)
93740 goto err_alloc;
93741
93742 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
93743- }
93744+ hdr = register_net_sysctl(net, "net/ipv6", table);
93745+ } else
93746+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
93747
93748- hdr = register_net_sysctl(net, "net/ipv6", table);
93749 if (!hdr)
93750 goto err_reg;
93751
93752@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
93753 return 0;
93754
93755 err_reg:
93756- if (!net_eq(net, &init_net))
93757- kfree(table);
93758+ kfree(table);
93759 err_alloc:
93760 return -ENOMEM;
93761 }
93762diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
93763index 41ac7938..75e3bb1 100644
93764--- a/net/irda/ircomm/ircomm_tty.c
93765+++ b/net/irda/ircomm/ircomm_tty.c
93766@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93767 add_wait_queue(&port->open_wait, &wait);
93768
93769 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
93770- __FILE__, __LINE__, tty->driver->name, port->count);
93771+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93772
93773 spin_lock_irqsave(&port->lock, flags);
93774 if (!tty_hung_up_p(filp))
93775- port->count--;
93776+ atomic_dec(&port->count);
93777 port->blocked_open++;
93778 spin_unlock_irqrestore(&port->lock, flags);
93779
93780@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93781 }
93782
93783 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
93784- __FILE__, __LINE__, tty->driver->name, port->count);
93785+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93786
93787 schedule();
93788 }
93789@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93790
93791 spin_lock_irqsave(&port->lock, flags);
93792 if (!tty_hung_up_p(filp))
93793- port->count++;
93794+ atomic_inc(&port->count);
93795 port->blocked_open--;
93796 spin_unlock_irqrestore(&port->lock, flags);
93797
93798 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
93799- __FILE__, __LINE__, tty->driver->name, port->count);
93800+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93801
93802 if (!retval)
93803 port->flags |= ASYNC_NORMAL_ACTIVE;
93804@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
93805
93806 /* ++ is not atomic, so this should be protected - Jean II */
93807 spin_lock_irqsave(&self->port.lock, flags);
93808- self->port.count++;
93809+ atomic_inc(&self->port.count);
93810 spin_unlock_irqrestore(&self->port.lock, flags);
93811 tty_port_tty_set(&self->port, tty);
93812
93813 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
93814- self->line, self->port.count);
93815+ self->line, atomic_read(&self->port.count));
93816
93817 /* Not really used by us, but lets do it anyway */
93818 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
93819@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
93820 tty_kref_put(port->tty);
93821 }
93822 port->tty = NULL;
93823- port->count = 0;
93824+ atomic_set(&port->count, 0);
93825 spin_unlock_irqrestore(&port->lock, flags);
93826
93827 wake_up_interruptible(&port->open_wait);
93828@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
93829 seq_putc(m, '\n');
93830
93831 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
93832- seq_printf(m, "Open count: %d\n", self->port.count);
93833+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
93834 seq_printf(m, "Max data size: %d\n", self->max_data_size);
93835 seq_printf(m, "Max header size: %d\n", self->max_header_size);
93836
93837diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
93838index 168aff5..9d43132 100644
93839--- a/net/iucv/af_iucv.c
93840+++ b/net/iucv/af_iucv.c
93841@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
93842
93843 write_lock_bh(&iucv_sk_list.lock);
93844
93845- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
93846+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
93847 while (__iucv_get_sock_by_name(name)) {
93848 sprintf(name, "%08x",
93849- atomic_inc_return(&iucv_sk_list.autobind_name));
93850+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
93851 }
93852
93853 write_unlock_bh(&iucv_sk_list.lock);
93854diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
93855index cd5b8ec..f205e6b 100644
93856--- a/net/iucv/iucv.c
93857+++ b/net/iucv/iucv.c
93858@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
93859 return NOTIFY_OK;
93860 }
93861
93862-static struct notifier_block __refdata iucv_cpu_notifier = {
93863+static struct notifier_block iucv_cpu_notifier = {
93864 .notifier_call = iucv_cpu_notify,
93865 };
93866
93867diff --git a/net/key/af_key.c b/net/key/af_key.c
93868index ab8bd2c..cd2d641 100644
93869--- a/net/key/af_key.c
93870+++ b/net/key/af_key.c
93871@@ -3048,10 +3048,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
93872 static u32 get_acqseq(void)
93873 {
93874 u32 res;
93875- static atomic_t acqseq;
93876+ static atomic_unchecked_t acqseq;
93877
93878 do {
93879- res = atomic_inc_return(&acqseq);
93880+ res = atomic_inc_return_unchecked(&acqseq);
93881 } while (!res);
93882 return res;
93883 }
93884diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
93885index 43dd752..63a23bc 100644
93886--- a/net/mac80211/cfg.c
93887+++ b/net/mac80211/cfg.c
93888@@ -820,7 +820,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
93889 ret = ieee80211_vif_use_channel(sdata, chandef,
93890 IEEE80211_CHANCTX_EXCLUSIVE);
93891 }
93892- } else if (local->open_count == local->monitors) {
93893+ } else if (local_read(&local->open_count) == local->monitors) {
93894 local->_oper_chandef = *chandef;
93895 ieee80211_hw_config(local, 0);
93896 }
93897@@ -2941,7 +2941,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
93898 else
93899 local->probe_req_reg--;
93900
93901- if (!local->open_count)
93902+ if (!local_read(&local->open_count))
93903 break;
93904
93905 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
93906@@ -3404,8 +3404,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
93907 if (chanctx_conf) {
93908 *chandef = chanctx_conf->def;
93909 ret = 0;
93910- } else if (local->open_count > 0 &&
93911- local->open_count == local->monitors &&
93912+ } else if (local_read(&local->open_count) > 0 &&
93913+ local_read(&local->open_count) == local->monitors &&
93914 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
93915 if (local->use_chanctx)
93916 *chandef = local->monitor_chandef;
93917diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
93918index 8412a30..6e00181 100644
93919--- a/net/mac80211/ieee80211_i.h
93920+++ b/net/mac80211/ieee80211_i.h
93921@@ -28,6 +28,7 @@
93922 #include <net/ieee80211_radiotap.h>
93923 #include <net/cfg80211.h>
93924 #include <net/mac80211.h>
93925+#include <asm/local.h>
93926 #include "key.h"
93927 #include "sta_info.h"
93928 #include "debug.h"
93929@@ -907,7 +908,7 @@ struct ieee80211_local {
93930 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
93931 spinlock_t queue_stop_reason_lock;
93932
93933- int open_count;
93934+ local_t open_count;
93935 int monitors, cooked_mntrs;
93936 /* number of interfaces with corresponding FIF_ flags */
93937 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
93938diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
93939index cc11759..11d5541 100644
93940--- a/net/mac80211/iface.c
93941+++ b/net/mac80211/iface.c
93942@@ -511,7 +511,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
93943 break;
93944 }
93945
93946- if (local->open_count == 0) {
93947+ if (local_read(&local->open_count) == 0) {
93948 res = drv_start(local);
93949 if (res)
93950 goto err_del_bss;
93951@@ -558,7 +558,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
93952 res = drv_add_interface(local, sdata);
93953 if (res)
93954 goto err_stop;
93955- } else if (local->monitors == 0 && local->open_count == 0) {
93956+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
93957 res = ieee80211_add_virtual_monitor(local);
93958 if (res)
93959 goto err_stop;
93960@@ -666,7 +666,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
93961 atomic_inc(&local->iff_promiscs);
93962
93963 if (coming_up)
93964- local->open_count++;
93965+ local_inc(&local->open_count);
93966
93967 if (hw_reconf_flags)
93968 ieee80211_hw_config(local, hw_reconf_flags);
93969@@ -704,7 +704,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
93970 err_del_interface:
93971 drv_remove_interface(local, sdata);
93972 err_stop:
93973- if (!local->open_count)
93974+ if (!local_read(&local->open_count))
93975 drv_stop(local);
93976 err_del_bss:
93977 sdata->bss = NULL;
93978@@ -841,7 +841,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
93979 }
93980
93981 if (going_down)
93982- local->open_count--;
93983+ local_dec(&local->open_count);
93984
93985 switch (sdata->vif.type) {
93986 case NL80211_IFTYPE_AP_VLAN:
93987@@ -908,7 +908,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
93988 }
93989 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
93990
93991- if (local->open_count == 0)
93992+ if (local_read(&local->open_count) == 0)
93993 ieee80211_clear_tx_pending(local);
93994
93995 /*
93996@@ -948,7 +948,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
93997
93998 ieee80211_recalc_ps(local, -1);
93999
94000- if (local->open_count == 0) {
94001+ if (local_read(&local->open_count) == 0) {
94002 ieee80211_stop_device(local);
94003
94004 /* no reconfiguring after stop! */
94005@@ -959,7 +959,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94006 ieee80211_configure_filter(local);
94007 ieee80211_hw_config(local, hw_reconf_flags);
94008
94009- if (local->monitors == local->open_count)
94010+ if (local->monitors == local_read(&local->open_count))
94011 ieee80211_add_virtual_monitor(local);
94012 }
94013
94014diff --git a/net/mac80211/main.c b/net/mac80211/main.c
94015index 091088a..daf43c7 100644
94016--- a/net/mac80211/main.c
94017+++ b/net/mac80211/main.c
94018@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
94019 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
94020 IEEE80211_CONF_CHANGE_POWER);
94021
94022- if (changed && local->open_count) {
94023+ if (changed && local_read(&local->open_count)) {
94024 ret = drv_config(local, changed);
94025 /*
94026 * Goal:
94027diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
94028index 3401262..d5cd68d 100644
94029--- a/net/mac80211/pm.c
94030+++ b/net/mac80211/pm.c
94031@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94032 struct ieee80211_sub_if_data *sdata;
94033 struct sta_info *sta;
94034
94035- if (!local->open_count)
94036+ if (!local_read(&local->open_count))
94037 goto suspend;
94038
94039 ieee80211_scan_cancel(local);
94040@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94041 cancel_work_sync(&local->dynamic_ps_enable_work);
94042 del_timer_sync(&local->dynamic_ps_timer);
94043
94044- local->wowlan = wowlan && local->open_count;
94045+ local->wowlan = wowlan && local_read(&local->open_count);
94046 if (local->wowlan) {
94047 int err = drv_suspend(local, wowlan);
94048 if (err < 0) {
94049@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94050 WARN_ON(!list_empty(&local->chanctx_list));
94051
94052 /* stop hardware - this must stop RX */
94053- if (local->open_count)
94054+ if (local_read(&local->open_count))
94055 ieee80211_stop_device(local);
94056
94057 suspend:
94058diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
94059index 30d58d2..449ac8e 100644
94060--- a/net/mac80211/rate.c
94061+++ b/net/mac80211/rate.c
94062@@ -718,7 +718,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
94063
94064 ASSERT_RTNL();
94065
94066- if (local->open_count)
94067+ if (local_read(&local->open_count))
94068 return -EBUSY;
94069
94070 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
94071diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
94072index c97a065..ff61928 100644
94073--- a/net/mac80211/rc80211_pid_debugfs.c
94074+++ b/net/mac80211/rc80211_pid_debugfs.c
94075@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
94076
94077 spin_unlock_irqrestore(&events->lock, status);
94078
94079- if (copy_to_user(buf, pb, p))
94080+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
94081 return -EFAULT;
94082
94083 return p;
94084diff --git a/net/mac80211/util.c b/net/mac80211/util.c
94085index 2265445..ba14971 100644
94086--- a/net/mac80211/util.c
94087+++ b/net/mac80211/util.c
94088@@ -1452,7 +1452,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
94089 }
94090 #endif
94091 /* everything else happens only if HW was up & running */
94092- if (!local->open_count)
94093+ if (!local_read(&local->open_count))
94094 goto wake_up;
94095
94096 /*
94097@@ -1677,7 +1677,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
94098 local->in_reconfig = false;
94099 barrier();
94100
94101- if (local->monitors == local->open_count && local->monitors > 0)
94102+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
94103 ieee80211_add_virtual_monitor(local);
94104
94105 /*
94106diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
94107index 56d22ca..87c778f 100644
94108--- a/net/netfilter/Kconfig
94109+++ b/net/netfilter/Kconfig
94110@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
94111
94112 To compile it as a module, choose M here. If unsure, say N.
94113
94114+config NETFILTER_XT_MATCH_GRADM
94115+ tristate '"gradm" match support'
94116+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
94117+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
94118+ ---help---
94119+ The gradm match allows to match on grsecurity RBAC being enabled.
94120+ It is useful when iptables rules are applied early on bootup to
94121+ prevent connections to the machine (except from a trusted host)
94122+ while the RBAC system is disabled.
94123+
94124 config NETFILTER_XT_MATCH_HASHLIMIT
94125 tristate '"hashlimit" match support'
94126 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
94127diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
94128index a1abf87..dbcb7ee 100644
94129--- a/net/netfilter/Makefile
94130+++ b/net/netfilter/Makefile
94131@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
94132 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
94133 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
94134 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
94135+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
94136 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
94137 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
94138 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
94139diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
94140index f771390..145b765 100644
94141--- a/net/netfilter/ipset/ip_set_core.c
94142+++ b/net/netfilter/ipset/ip_set_core.c
94143@@ -1820,7 +1820,7 @@ done:
94144 return ret;
94145 }
94146
94147-static struct nf_sockopt_ops so_set __read_mostly = {
94148+static struct nf_sockopt_ops so_set = {
94149 .pf = PF_INET,
94150 .get_optmin = SO_IP_SET,
94151 .get_optmax = SO_IP_SET + 1,
94152diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
94153index 4c8e5c0..5a79b4d 100644
94154--- a/net/netfilter/ipvs/ip_vs_conn.c
94155+++ b/net/netfilter/ipvs/ip_vs_conn.c
94156@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
94157 /* Increase the refcnt counter of the dest */
94158 ip_vs_dest_hold(dest);
94159
94160- conn_flags = atomic_read(&dest->conn_flags);
94161+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
94162 if (cp->protocol != IPPROTO_UDP)
94163 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
94164 flags = cp->flags;
94165@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
94166
94167 cp->control = NULL;
94168 atomic_set(&cp->n_control, 0);
94169- atomic_set(&cp->in_pkts, 0);
94170+ atomic_set_unchecked(&cp->in_pkts, 0);
94171
94172 cp->packet_xmit = NULL;
94173 cp->app = NULL;
94174@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
94175
94176 /* Don't drop the entry if its number of incoming packets is not
94177 located in [0, 8] */
94178- i = atomic_read(&cp->in_pkts);
94179+ i = atomic_read_unchecked(&cp->in_pkts);
94180 if (i > 8 || i < 0) return 0;
94181
94182 if (!todrop_rate[i]) return 0;
94183diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
94184index 4f69e83..da2d8bf 100644
94185--- a/net/netfilter/ipvs/ip_vs_core.c
94186+++ b/net/netfilter/ipvs/ip_vs_core.c
94187@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
94188 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
94189 /* do not touch skb anymore */
94190
94191- atomic_inc(&cp->in_pkts);
94192+ atomic_inc_unchecked(&cp->in_pkts);
94193 ip_vs_conn_put(cp);
94194 return ret;
94195 }
94196@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
94197 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
94198 pkts = sysctl_sync_threshold(ipvs);
94199 else
94200- pkts = atomic_add_return(1, &cp->in_pkts);
94201+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94202
94203 if (ipvs->sync_state & IP_VS_STATE_MASTER)
94204 ip_vs_sync_conn(net, cp, pkts);
94205diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
94206index c8148e4..eff604f 100644
94207--- a/net/netfilter/ipvs/ip_vs_ctl.c
94208+++ b/net/netfilter/ipvs/ip_vs_ctl.c
94209@@ -789,7 +789,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
94210 */
94211 ip_vs_rs_hash(ipvs, dest);
94212 }
94213- atomic_set(&dest->conn_flags, conn_flags);
94214+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
94215
94216 /* bind the service */
94217 if (!dest->svc) {
94218@@ -1657,7 +1657,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
94219 * align with netns init in ip_vs_control_net_init()
94220 */
94221
94222-static struct ctl_table vs_vars[] = {
94223+static ctl_table_no_const vs_vars[] __read_only = {
94224 {
94225 .procname = "amemthresh",
94226 .maxlen = sizeof(int),
94227@@ -2078,7 +2078,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
94228 " %-7s %-6d %-10d %-10d\n",
94229 &dest->addr.in6,
94230 ntohs(dest->port),
94231- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
94232+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
94233 atomic_read(&dest->weight),
94234 atomic_read(&dest->activeconns),
94235 atomic_read(&dest->inactconns));
94236@@ -2089,7 +2089,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
94237 "%-7s %-6d %-10d %-10d\n",
94238 ntohl(dest->addr.ip),
94239 ntohs(dest->port),
94240- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
94241+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
94242 atomic_read(&dest->weight),
94243 atomic_read(&dest->activeconns),
94244 atomic_read(&dest->inactconns));
94245@@ -2567,7 +2567,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
94246
94247 entry.addr = dest->addr.ip;
94248 entry.port = dest->port;
94249- entry.conn_flags = atomic_read(&dest->conn_flags);
94250+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
94251 entry.weight = atomic_read(&dest->weight);
94252 entry.u_threshold = dest->u_threshold;
94253 entry.l_threshold = dest->l_threshold;
94254@@ -3110,7 +3110,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
94255 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
94256 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
94257 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
94258- (atomic_read(&dest->conn_flags) &
94259+ (atomic_read_unchecked(&dest->conn_flags) &
94260 IP_VS_CONN_F_FWD_MASK)) ||
94261 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
94262 atomic_read(&dest->weight)) ||
94263@@ -3700,7 +3700,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
94264 {
94265 int idx;
94266 struct netns_ipvs *ipvs = net_ipvs(net);
94267- struct ctl_table *tbl;
94268+ ctl_table_no_const *tbl;
94269
94270 atomic_set(&ipvs->dropentry, 0);
94271 spin_lock_init(&ipvs->dropentry_lock);
94272diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
94273index 1383b0e..91f68ae 100644
94274--- a/net/netfilter/ipvs/ip_vs_lblc.c
94275+++ b/net/netfilter/ipvs/ip_vs_lblc.c
94276@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
94277 * IPVS LBLC sysctl table
94278 */
94279 #ifdef CONFIG_SYSCTL
94280-static struct ctl_table vs_vars_table[] = {
94281+static struct ctl_table vs_vars_table[] __read_only = {
94282 {
94283 .procname = "lblc_expiration",
94284 .data = NULL,
94285diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
94286index 3cd85b2..b45b17e 100644
94287--- a/net/netfilter/ipvs/ip_vs_lblcr.c
94288+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
94289@@ -299,7 +299,7 @@ struct ip_vs_lblcr_table {
94290 * IPVS LBLCR sysctl table
94291 */
94292
94293-static struct ctl_table vs_vars_table[] = {
94294+static struct ctl_table vs_vars_table[] __read_only = {
94295 {
94296 .procname = "lblcr_expiration",
94297 .data = NULL,
94298diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
94299index f448471..995f131 100644
94300--- a/net/netfilter/ipvs/ip_vs_sync.c
94301+++ b/net/netfilter/ipvs/ip_vs_sync.c
94302@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
94303 cp = cp->control;
94304 if (cp) {
94305 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94306- pkts = atomic_add_return(1, &cp->in_pkts);
94307+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94308 else
94309 pkts = sysctl_sync_threshold(ipvs);
94310 ip_vs_sync_conn(net, cp->control, pkts);
94311@@ -771,7 +771,7 @@ control:
94312 if (!cp)
94313 return;
94314 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94315- pkts = atomic_add_return(1, &cp->in_pkts);
94316+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94317 else
94318 pkts = sysctl_sync_threshold(ipvs);
94319 goto sloop;
94320@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
94321
94322 if (opt)
94323 memcpy(&cp->in_seq, opt, sizeof(*opt));
94324- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94325+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94326 cp->state = state;
94327 cp->old_state = cp->state;
94328 /*
94329diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
94330index b75ff64..0c51bbe 100644
94331--- a/net/netfilter/ipvs/ip_vs_xmit.c
94332+++ b/net/netfilter/ipvs/ip_vs_xmit.c
94333@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
94334 else
94335 rc = NF_ACCEPT;
94336 /* do not touch skb anymore */
94337- atomic_inc(&cp->in_pkts);
94338+ atomic_inc_unchecked(&cp->in_pkts);
94339 goto out;
94340 }
94341
94342@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
94343 else
94344 rc = NF_ACCEPT;
94345 /* do not touch skb anymore */
94346- atomic_inc(&cp->in_pkts);
94347+ atomic_inc_unchecked(&cp->in_pkts);
94348 goto out;
94349 }
94350
94351diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
94352index 2d3030a..7ba1c0a 100644
94353--- a/net/netfilter/nf_conntrack_acct.c
94354+++ b/net/netfilter/nf_conntrack_acct.c
94355@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
94356 #ifdef CONFIG_SYSCTL
94357 static int nf_conntrack_acct_init_sysctl(struct net *net)
94358 {
94359- struct ctl_table *table;
94360+ ctl_table_no_const *table;
94361
94362 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
94363 GFP_KERNEL);
94364diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
94365index 0283bae..5febcb0 100644
94366--- a/net/netfilter/nf_conntrack_core.c
94367+++ b/net/netfilter/nf_conntrack_core.c
94368@@ -1614,6 +1614,10 @@ void nf_conntrack_init_end(void)
94369 #define DYING_NULLS_VAL ((1<<30)+1)
94370 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
94371
94372+#ifdef CONFIG_GRKERNSEC_HIDESYM
94373+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
94374+#endif
94375+
94376 int nf_conntrack_init_net(struct net *net)
94377 {
94378 int ret;
94379@@ -1628,7 +1632,11 @@ int nf_conntrack_init_net(struct net *net)
94380 goto err_stat;
94381 }
94382
94383+#ifdef CONFIG_GRKERNSEC_HIDESYM
94384+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
94385+#else
94386 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
94387+#endif
94388 if (!net->ct.slabname) {
94389 ret = -ENOMEM;
94390 goto err_slabname;
94391diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
94392index 1df1761..ce8b88a 100644
94393--- a/net/netfilter/nf_conntrack_ecache.c
94394+++ b/net/netfilter/nf_conntrack_ecache.c
94395@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
94396 #ifdef CONFIG_SYSCTL
94397 static int nf_conntrack_event_init_sysctl(struct net *net)
94398 {
94399- struct ctl_table *table;
94400+ ctl_table_no_const *table;
94401
94402 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
94403 GFP_KERNEL);
94404diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
94405index 974a2a4..52cc6ff 100644
94406--- a/net/netfilter/nf_conntrack_helper.c
94407+++ b/net/netfilter/nf_conntrack_helper.c
94408@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
94409
94410 static int nf_conntrack_helper_init_sysctl(struct net *net)
94411 {
94412- struct ctl_table *table;
94413+ ctl_table_no_const *table;
94414
94415 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
94416 GFP_KERNEL);
94417diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
94418index 0ab9636..cea3c6a 100644
94419--- a/net/netfilter/nf_conntrack_proto.c
94420+++ b/net/netfilter/nf_conntrack_proto.c
94421@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
94422
94423 static void
94424 nf_ct_unregister_sysctl(struct ctl_table_header **header,
94425- struct ctl_table **table,
94426+ ctl_table_no_const **table,
94427 unsigned int users)
94428 {
94429 if (users > 0)
94430diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
94431index a99b6c3..cb372f9 100644
94432--- a/net/netfilter/nf_conntrack_proto_dccp.c
94433+++ b/net/netfilter/nf_conntrack_proto_dccp.c
94434@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94435 const char *msg;
94436 u_int8_t state;
94437
94438- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94439+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94440 BUG_ON(dh == NULL);
94441
94442 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
94443@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94444 out_invalid:
94445 if (LOG_INVALID(net, IPPROTO_DCCP))
94446 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
94447- NULL, msg);
94448+ NULL, "%s", msg);
94449 return false;
94450 }
94451
94452@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
94453 u_int8_t type, old_state, new_state;
94454 enum ct_dccp_roles role;
94455
94456- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94457+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94458 BUG_ON(dh == NULL);
94459 type = dh->dccph_type;
94460
94461@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94462 unsigned int cscov;
94463 const char *msg;
94464
94465- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94466+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94467 if (dh == NULL) {
94468 msg = "nf_ct_dccp: short packet ";
94469 goto out_invalid;
94470@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94471
94472 out_invalid:
94473 if (LOG_INVALID(net, IPPROTO_DCCP))
94474- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
94475+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
94476 return -NF_ACCEPT;
94477 }
94478
94479diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
94480index f641751..d3c5b51 100644
94481--- a/net/netfilter/nf_conntrack_standalone.c
94482+++ b/net/netfilter/nf_conntrack_standalone.c
94483@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
94484
94485 static int nf_conntrack_standalone_init_sysctl(struct net *net)
94486 {
94487- struct ctl_table *table;
94488+ ctl_table_no_const *table;
94489
94490 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
94491 GFP_KERNEL);
94492diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
94493index 902fb0a..87f7fdb 100644
94494--- a/net/netfilter/nf_conntrack_timestamp.c
94495+++ b/net/netfilter/nf_conntrack_timestamp.c
94496@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
94497 #ifdef CONFIG_SYSCTL
94498 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
94499 {
94500- struct ctl_table *table;
94501+ ctl_table_no_const *table;
94502
94503 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
94504 GFP_KERNEL);
94505diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
94506index 85296d4..8becdec 100644
94507--- a/net/netfilter/nf_log.c
94508+++ b/net/netfilter/nf_log.c
94509@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
94510
94511 #ifdef CONFIG_SYSCTL
94512 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
94513-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
94514+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
94515
94516 static int nf_log_proc_dostring(struct ctl_table *table, int write,
94517 void __user *buffer, size_t *lenp, loff_t *ppos)
94518@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
94519 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
94520 mutex_unlock(&nf_log_mutex);
94521 } else {
94522+ ctl_table_no_const nf_log_table = *table;
94523+
94524 mutex_lock(&nf_log_mutex);
94525 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
94526 lockdep_is_held(&nf_log_mutex));
94527 if (!logger)
94528- table->data = "NONE";
94529+ nf_log_table.data = "NONE";
94530 else
94531- table->data = logger->name;
94532- r = proc_dostring(table, write, buffer, lenp, ppos);
94533+ nf_log_table.data = logger->name;
94534+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
94535 mutex_unlock(&nf_log_mutex);
94536 }
94537
94538diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
94539index f042ae5..30ea486 100644
94540--- a/net/netfilter/nf_sockopt.c
94541+++ b/net/netfilter/nf_sockopt.c
94542@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
94543 }
94544 }
94545
94546- list_add(&reg->list, &nf_sockopts);
94547+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
94548 out:
94549 mutex_unlock(&nf_sockopt_mutex);
94550 return ret;
94551@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
94552 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
94553 {
94554 mutex_lock(&nf_sockopt_mutex);
94555- list_del(&reg->list);
94556+ pax_list_del((struct list_head *)&reg->list);
94557 mutex_unlock(&nf_sockopt_mutex);
94558 }
94559 EXPORT_SYMBOL(nf_unregister_sockopt);
94560diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
94561index d92cc31..e46f350 100644
94562--- a/net/netfilter/nfnetlink_log.c
94563+++ b/net/netfilter/nfnetlink_log.c
94564@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
94565 struct nfnl_log_net {
94566 spinlock_t instances_lock;
94567 struct hlist_head instance_table[INSTANCE_BUCKETS];
94568- atomic_t global_seq;
94569+ atomic_unchecked_t global_seq;
94570 };
94571
94572 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
94573@@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
94574 /* global sequence number */
94575 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
94576 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
94577- htonl(atomic_inc_return(&log->global_seq))))
94578+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
94579 goto nla_put_failure;
94580
94581 if (data_len) {
94582diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
94583new file mode 100644
94584index 0000000..c566332
94585--- /dev/null
94586+++ b/net/netfilter/xt_gradm.c
94587@@ -0,0 +1,51 @@
94588+/*
94589+ * gradm match for netfilter
94590